index









































































































































































































































































<?php
/*
    "If in the course of a lecture I stated an unsolved problem, the 
    chances were [John von Neumann would] come to me at the end of the 
    lecture with the complete solution scribbled on a slip of paper."
      -- Miodrag Petkovic, "Famous puzzles of great mathematicians"
*/

/* HTML.PHP - create the $html array for the web templates 

The $html array is created from to files in the config('htmdir') directory, 
HTML.INI which defines the HTML that dynamically create the menus as well as 
some very basic strings. The file TEMPLATES.PHP define all the web remplates.

See file HTML, see file TEMPLATES, see file THEMES.

*/


/* html - interface to the $html array */

// initializes on first use and then indexes into the $html array

function html($var NULL$val NULL) {
static 
$html = array();

    if (
$html == array()) {

// the default theme is always loaded; an additional theme, if set, is then
// loaded to overwrite existing data and append new data; if a theme is to 
// overwrite all items in the default theme, we can add a config setting to 
// not read the default theme...

        
$hd config('htmdir');
        
$td config('themedir'); if ($td$td $hd.$td;
        
$html configfile($hd.'html.ini');
        
$html['htmdir'] = $hd;
        
$html['themedir'] = $td;

// the function load_php_file() (DATA.PHP) does a basic eval() of the 
// template data to catch parse/syntax errors, but it's very minimal and the 
// function displayhtml (DISPLAY.PHP) will catch an assignment/print errors 
// eventually, the Admin template edit process will fully parse the data to
// catch any possible error before hand...

        
$h load_php_file($hd.'templates.php');
        if (
$h$html array_merge($html,$h);

        if (
$td) {
            
$html configfile($td.'html.ini',$html);
            
$h load_php_file($td.'templates.php');
            if (
$h$html array_merge($html,$h);
        }

        
$html['index'] = 'Index';
        
$html['title'] = config('sitename');
        
$html['name'] = config('name');
        
$html['version'] = $GLOBALS['VERSION'];

        
$section $html['section'] = config('section');
        if (isset(
$html[$section]))
            foreach (
$html[$section] as $k => $v)
                
$html[$k] = $v;            // see NOTE

        
_configmenu($html);
        
_configlogin($html);
        
_confignavmenu($html);

        
// final configuration; 

// slight disconnect here as we cannot know if the rules module has been 
// initialized yet so do not know if 'op' hase been validated (probably 
// not) - this will be fixed by the next version (it's not a security issue)

        
$op getvar('op');

        if (
config('hidenavmenu') && $op && $op != 'read')
            
$html['navmenu'] = '';

        if (
$op == 'help')
            
$html['title'] = 'Help - '.$html['title'];

        if (!
config('allowcomments'))
            
$html['gotocomments'] = '';
    }

    if (
$var === NULL)
        return 
$html;

    if (
$val !== NULL) {
        if (isset(
$html[$var]) && is_array($html[$var]))
            return 
$html[$var][] = $val;
        return 
$html[$var] = $val;
    }

    if (isset(
$html[$var]))
        return 
$html[$var];

    return 
'';
}
// NOTE that foreach loop is so that in the HTML.INI file there can be a 
// section for section overrides (see HTML.INI for example) and anything can 
// be overridden without checking


/* htmltempl - this is just an alias, used by DISPLAY.PHP, just some clarity */

// might do more though...

function htmltempl($name) {

    
$html html($name);
    return 
$html;
}


/*
Some HTML is dynamic, depending on the "operation" these form that HTML.
(There are getting to be too many $html member names and they are all 
different with no consistency... this may become problematic.)
*/

// the main menu is dynamically created by the number of sections (see 
// SECTIONS.INI) and the result is placed in $html['menu'] (which a theme 
// can pre-define if it wants) and it consists of a $html['menustr'] and a 
// $html['menuafter'] -- both defined in HTML.INI -- for each section

function _configmenu(&$html) {

    if (isset(
$html['menu']))        // already have one?
        
return;
    if (!
$html['menustr'])            // no makings?
        
return;

    
$op getvar('op');            // what we are doing
    
$arg getvar('arg');            // where we are doing it
    
$id getvar('id');            // who we are doing it to
    
$sections config('sections');

    
$html['query'] = "arg=$arg";
    if ((
$start getvar('start')) && $start 0)
        
$html['query'] .= "&amp;start=$start";

    if (
$id) {
        
$html['id'] = '#'.$id;
        
$html['query'] .= $html['id'];
    }

    if (
$op == 'page') {            // no menu at all for pages
        
$html['menu'] = '';
        return;
    }

    
$h = @$html[$op];            // possibly a sub-menu?

    
if (!$h) {                // no, so make the menu
        
$s $html['menustr'];
        
$a $html['menuafter'];
        
$h html_elements($sections,$s,$arg,$a);
    }

    
$html['menu'] = "<div id='menu'>$h</div>";
}

// okay, for this one we messed up a little and hopefully it will be 
// fixed soon... the navigation menu (or sidebar) is $html['navmenu'] and is
// defined in TEMPLATES.PHP and it has a dynamically created component, 
// $html['navstra'] (nav string links) which is comprised of a $html['navstr'] 
// for each section (not too confusing, is it?)

function _confignavmenu(&$html) {

    if (!
$html['navstr'] || !isset($html['navmenu']))
        return;
    if (isset(
$html['navstra']))
        return;

    
$arg getvar('arg');
    
$sections config('sections');

    
$s $html['navstr'];
    
$html['navstra'] = html_elements($sections,$s,$arg);
}


function 
_configlogin(&$html) {

    
$html['loginlink'] = '';
    
$html['loggedinstr'] = '';
    
$html['logoutlink'] = '';

    if (!
config('visitorcode'))
        return;

    
$html['redirect'] = htmlspecialchars($_SERVER['QUERY_STRING']);

    
$from visitor_check();        // is someone logged in?

    
if ($from !== '') {
        
$html['logoutstr'] = str_replace('$1',$from,$html['logoutstr']);
        
$html['loginout'] = $html['logoutform'];
    }
    else {
        
$html['loginout'] = $html['loginform'];
    }
}

/*
This is the one "produce HTML based on array data" function. It is used to 
eliminate having code in the templates (and therefore the need for anything 
like a "template engine").
*/


/* html_elements - form HTML based on array data */

function html_elements($data$html$sel ''$after '') {

    
$htm '';

    if (!
is_array(current($data))) {        // single array
        
foreach ($data as $key => $value) {
            
$str str_replace('$1',$key,$html);     // note '$html'
            
$str str_replace('$2',$value,$str);    // note '$str'
            
$htm .= $str.PHP_EOL;
        }

        return 
$htm;
    }

    
$i 0;
    
$c count($data);
    foreach (
$data as $key => $value) {
        
$names array_keys($value);
        if (++
$i == $c$after '';

        
$str str_replace('$key',$key,$html);

        
$selected = ($key == $sel) ? 'selected' '';
        
$str str_replace('$selected',$selected,$str);

// please ignore this
        
$x = (!$selected && isset($value['description'])) ? '*' '';
        
$str str_replace('$x',$x,$str);
// end of ignore this

        
foreach ($names as $n) {
            
$id '$'.$n;
            
$str str_replace($id,$value[$n],$str);
        }

        
$htm .= $str.$after;
    }

    return 
$htm;
}


/* the initialize functiton */

function _html() {
    
html();
}