<?

define
("MOD_MODULE",$name);
define("ALIAS_SEP",":");

include(
INCLUDE_DIR "/option.inc.php");

// This is probably not usefull, because Module is an interface class
//$modules[$name]= new Module; 

/**
 * Module ancestor
 *
 * This class is an interface which contains the minimum
 * function-set that is needed for a module to work with the form-handler
 * package.
 * @package   Modules
 * @author    Herman Suijs
 */
class Module extends ModuleBase {
  var 
$name "Module";
  var 
$options = array();
  var 
$execlevel;
  var 
$debuglevel DB_ALL;
  
//var $error_messages = array();

  
function Module() {
    
//global $error,$debug;
    
if (empty($this->execlevel)) {
      
$this->error(ERR_DEV_END,"No execlevel");

    } 
/* if (empty($this->execlevel)) */

    
if (empty($this->options)) {
      
$this->debug(DB_WARN,"No options defined (yet).");
    } 
//else { /* if (empty($this->options)) */
      //$this->check_options();
   /* if (empty($this->options)) { .... */  //}
    // Add options

    
$this->ModuleBase();
   
/* if (empty($this->options)) { .... */}

  function 
set_debuglevel($level=0) {
    
$this->debuglevel $level;
  }
      
  function 
debug($level,$message,$var1="",$var2="",$var3="",$var4="",$var5="",$var6="",$var7="",$var8="",$var9="",$var10="",$var11="",$var12="") {
    global 
$debug;
    if (
$level<$this->debuglevel) {
      
$debug->add($level,$this->name,$message,$var1,$var2,$var3,$var4,$var5,$var6,$var7,$var8,$var9,$var10,$var11,$var12);
    }
  } 
/* function debug($level,$message... */

  
function error($level,$message,$var1,$var2,$var3,$var4,$var5,$var6,$var7,$var8,$var9,$var10,$var11,$var12) {
    global 
$error;
    
$error->add($level,$this->name,$message,$var1,$var2,$var3,$var4,$var5,$var6,$var7,$var8,$var9,$var10,$var11,$var12);
  } 
/* function error($level,$message... */

  
function execlevel() {
    return 
$this->execlevel;
  } 
/* function execlevel() */

  
function set_execlevel($level) {
    
//global $debug;
    
$max_level STEP_EXECLEVEL*MAX_STEPS;
    if (
$level>=$max_level) {
      
$level $max_level;
      
$this->debug(DB_FLOW,"Execlevel %s>%s. Changed to %s.",$level,$max_level,$max_level);
    } 
/* if ($level>=$max_level) */
    
$this->execlevel $level;
  } 
/* function set_execlevel($level) */

  
function check_options() {
    global 
$debug,$formHandler;
    
//$vars = $formHandler->get_showvars();
    
$vars $formHandler->get_vars();
    
//echo "$this->name: ".fh_serialize($vars);
    
$thisname $this->name;
    
reset($this->options);
    
// This value needs to be set seperately, because the value of
    // count($this->options) changes by the unset statement.
    
$max count($this->options);
    
// This is needed, because $option needs to be a reference to the
    // array-element of $this->options. Otherwise the changes to the
    // specific options-object made in one of the methods (functions of the
    // option) is made in a copy and discarded after this routine.
    
for ($id=0$id $max$id++) {
      if (!empty(
$this->options[$id])) {
    
$option =& $this->options[$id];
    
//echo("Check option ".$option->name);
    
$this->debug(DB_XFLOW,$thisname,"Check option %s",$option->name);
    if(
$option->check_existence($vars)) {
      
$this->debug(DB_XFLOW,$thisname,"Check value option %s",$option->name);
      
$option->check_value($vars);
      
$this->debug(DB_XFLOW,$thisname,"Option(%s): %s %s",$id,$option->name,$option->value);
    } else { 
/* if($option->check_existence($v... */
      //echo "$thisname $optionname ". $option->enabled ."<br>";
      
if (!$option->enabled) {
        
$this->disable();
        
$this->debug(DB_XFLOW,$thisname,"Module %s is disabled",$this->name);
      } 
/* if (!$option->enabled) */
      
$this->debug(DB_XFLOW,$thisname,"Option %s is unset",$option->name);
      
// Just to be sure, first set to NULL, then unset
      
$this->options[$id] = NULL;
      unset(
$this->options[$id]);
      
//echo count($this->options) ." ".$id ."<br>";
    
/* if($option->check_existence($v... */
    //echo "Option($id): " . $option->name . " ". $option->value ."<br>";
  
    // Unset must be at the end, because otherwise the total option is
    // discarded when cleaning up this local variable.
    // Probably a bug in PHP at this time.
    
unset($option);
      } 
/* if (!empty($this->options[$id]... */
      
else $max++;
    } 
// end for /* for ($id=0; $id < $max; $id++) */
  
/* function check_options() */

  
function action() {
    
//global $debug,$error;
    //return (!$debug->noop()&&!$error->noop());
    
global $debug,$error;
    
$message$this->name " no action defined (yet) or super called: ";
    
$message.= "debug " fh_serialize($debug->noop());
    
$message.= "error " fh_serialize($error->noop());
    
//$message.= "<BR>";
    
$this->debug(DB_INFO,$this->name,$message);
    return (!(
$debug->noop()||$error->noop()));
  } 
/* function action() */

  
function clean_up() {
    global 
$modules;
    
reset($this->options);
    while (list(
$name,) = each($this->options)) {
      unset(
$options[$name]);
    } 
/* while (list($name,) = each($th... */
    
if (!$this->enabled) {
      unset(
$modules[$this->id]);
    } 
/* if (!$this->enabled) */
    
$this->wrap_up();
  } 
/* function clean_up() */

  //function return_error_message($number) {
  //} /* //function return_error_messag... */

// cla /* if (empty($this->options)) { .... */ss Module