<?

//include_once(INCLUDE_DIR."/modulebase.inc.php");

define("INC_VARS","vars");

/**
 * Vars object
 *
 * This object is used within the form-handler to store all variables and
 * configurations of the form and entered througout the application.
 *
 * @package   Include
 * @author    Herman Suijs
 */
class Vars_Array extends ModuleBase {
  var 
$name "IncludeVars";
  var 
$id INC_VARS;
  var 
$vars = array();
  var 
$index = array();

  function 
Vars_Array ($vars="") {
    global 
$debug;
    if (empty(
$vars)) {
      
$vars = array();
    } 
/* if (empty($vars)) */
    
$this->set_vars($vars);
    
$this->ModuleBase();
  } 
/* function Vars_Array ($vars="") */

  
function create_array($type) {
    
$return_array = array();
    if (
$type==ALL_VARS) {
      
$return_array $this->vars;
      while (list(
$name,$value)=each($this->vars)) {
    
$return_array[strtolower($name)] = $value;
      } 
/* while (list($name,$value)=each... */
      
return $return_array;
    } 
/* if ($type==ALL_VARS) */

    
if ($type==SHOW_VARS) {
      
$return_array=$this->create_array(USR_VARS);
    } 
/* if ($type==SHOW_VARS) */

    
while (list($name,$value) = each($this->index)) {
      if (
ereg($type,$value)) {
    
$return_array[$name] = $this->vars[$name];
    
$return_array[strtolower($name)] = $this->vars[$name];
      } 
/* if (ereg($type,$value)) */
    
/* while (list($name,$value) = ea... */

    
return $return_array;

  } 
/* function create_array($type) */

  
function get_vars($type=ALL_VARS) {
    
//return $this->vars; // return array
    //echo "Index: <br>".fh_serialize($this->index);
    
return $this->create_array($type);
  } 
/* function get_vars($type=ALL_VA... */

  // This function is only usefull when the constructor was called with an
  // empty parameter
  
function set_vars($vars) {
    if(
is_array($vars)) {
      
$this->vars $vars// set an array
      
$this->set_vartype(array_keys($vars),USR_VARS);
    } else { 
/* if(is_array($vars)) */
      
$debug->add(8,$this->name,"No array submitted to Vars_array");
   
/* if(is_array($vars)) { ... } el... */  }
  } 
/* function set_vars($vars) */

  
function set_vartype($vars,$type=ALL_VARS,$show=false) {
    if (
$type!=ALL_VARS) {
      if (!
strpos(VAR_NAME_SEP,$vars)===false) {
    
$vars split(VAR_NAME_SEP,$vars);
      } 
/* if (!strpos(VAR_NAME_SEP,$vars... */
      
if (!is_array($vars)) {
    
$error->add(2,$this->name ." set_vartype","No array submitted");
      } 
/* if (!is_array($vars)) */
      
if ($show$type .= SHOW_VARS;
      while (list(,
$value) = each($vars)) {
                
//echo "index[$value] = $type<br>";
                
$this->index[$value] .= $type;
      } 
/* while (list(,$value) = each($v... */
    
} else { /* if ($type!=ALL_VARS) */
      
$debug->add(8,$this->name." set_vartype","Type %s does not need to be set. Give type","ALL_VARS");
   
/* if ($type!=ALL_VARS) { ... } e... */  }
  } 
/* function set_vartype($vars,$ty... */

  /*
  function set_vars($all,$sys,$show) {
  }
  */

  
function addto_vars($vars$replace=true) {
    global 
$debug;
    if (
$replace) {
      
$this->vars=array_merge($this->vars,$vars);
    } else { 
/* if ($replace) */
      
$this->vars=array_merge($vars,$this->vars);
    } 
/* if ($replace) { ... } else */
    
$this->set_vartype(array_keys($vars),USR_VARS);

    
/*
    if (isset($this->vars[$name])&&$replace) {
      $debug->add(6,$this->name,"Value of vars[$name] changed to $value");
    }
    $this->vars[$name] = $value;
    */
  
/* function addto_vars($vars, $re... */

  /*
  function change_vars($name, $value) {
    $this->addto_vars($name, $value);
  }
  */

  
function del_var($key) {
    global 
$debug;
    if (!
$debug->enabled&&isset($this->vars[$key])) {
      unset(
$this->vars[$key]);
      if (isset(
$this->index[$key])) {
    unset(
$this->index[$key]);
      } 
/* if (isset($this->index[$key])) */
    
/* if (!$debug->enabled&&isset($t... */
    
$debug->add(DB_FLOW,$this->name,"Delete var %s",$key);
  } 
/* function del_var($key) */

  /*
  function key_to_lower() {
    reset($this->vars);
    $tmp_vars = $this->vars;
    unset($vars);
    while (list($name,$value) = each($tmp_vars)) {
      $this->vars[strtolower($name)] = $value;
    }
    unset($tmp_vars);
  }
  */
  
// end class Vars /* class Vars_Array extends Modul... */