Index: trunk/kernel/include/config.php =================================================================== diff -u -r667 -r676 --- trunk/kernel/include/config.php (.../config.php) (revision 667) +++ trunk/kernel/include/config.php (.../config.php) (revision 676) @@ -1,1024 +1,513 @@ m_IsDirty=false; - $this->adodbConnection = &GetADODBConnection(); - $this->config = array(); - $this->m_IsDefault = array(); - $this->VarType = array(); - } - - function SetDebugLevel($value) - { - } - - - function Load() - { - if(is_object($this->adodbConnection)) - { - LogEntry("Config Load Start\n"); - $sql = "select VariableName, VariableValue from ".GetTablePrefix()."ConfigurationValues"; - $rs = $this->adodbConnection->Execute($sql); - unset($this->config); - #this->config=array(); - $count=0; - while($rs && !$rs->EOF) - { - $this->config[$rs->fields["VariableName"]] = $rs->fields["VariableValue"]; - $this->m_VarType[$rs->fields["VariableName"]] = 0; - // $this->Set($rs->fields["VariableName"],$rs->fields["VariableValue"],0); - if( defined('ADODB_EXTENSION') && constant('ADODB_EXTENSION') > 0 ) - { - adodb_movenext($rs); - } - else - $rs->MoveNext(); - $count++; - } - LogEntry("Config Load End - $count Variables\n"); - } - unset($this->m_DirtyFields); - $this->m_IsDirty=false; - } - - function Get($property) - { - return isset($this->config[$property]) ? $this->config[$property] : ''; - } - - function Set($property, $value,$type=0,$force=FALSE) - { - if(is_array($this->config) && strlen($property)>0) - { - if(array_key_exists($property,$this->config)) - { - $current = $this->config[$property]; - $changed = ($current != $value); - } - else - $changed = true; - } - else - $changed = false; - $this->config[$property]=$value; - $this->m_IsDirty = ($this->m_IsDirty or $changed or $force); - if($changed || $force) - { - $this->m_DirtyFields[$property] = $value; - } - $this->m_VarType[$property] = $type; - } - - function Save() - { - if($this->m_IsDirty==TRUE) - { - foreach($this->m_DirtyFields as $field=>$value) - { - if($this->m_VarType[$field]==0) - { - // $sql = sprintf("UPDATE ".GetTablePrefix()."ConfigurationValues SET VariableValue=%s WHERE VariableName=%s", $this->adodbConnection->qstr($value), $this->adodbConnection->qstr($field)); - $sql = 'UPDATE '.GetTablePrefix().'ConfigurationValues SET VariableValue="'.addslashes($value).'" WHERE VariableName="'.addslashes($field).'"'; - // echo $sql."
\n"; - - $rs = $this->adodbConnection->execute($sql); - } - } - } - $this->m_IsDirty=FALSE; - unset($this->m_DirtyFields); - } - - function TimeFormat() - { - if($this->Get("ampm_time")=="1") - { - $format = "g:i:s A"; - } - else - $format = "H:i:s"; - return $format; - } - - /* vartype should be either 1 or 2, 1 = perstant data, 2 = session data */ - function GetDirtySessionValues($VarType) - { - $result = array(); - - if(is_array($this->m_DirtyFields)) - { - foreach($this->m_DirtyFields as $property=>$values) - { - if($this->m_VarType[$property]==$VarType) - $result[$property] = $values; - } - } - return $result; - } - - function GetConfigValues($postfix = '') - { - // return only varibles, that match specified criteria - if(!$postfix) return $this->config; - $result = Array(); - $postfix_len = $postfix ? strlen($postfix) : 0; - foreach($this->config as $config_var => $var_value) - { - if( substr($config_var, - $postfix_len) == $postfix ) - $result[$config_var] = $var_value; - } - return $result; - } - }/* clsConfig */ - - /* - To create the configuration forms in the admin section, populate the table ConfigurationAdmin and - ConfigurationValues. - - The tables are fairly straight-forward. The fields of concern in the ConfigurationValues table is - ModuleOwner and Section. ModuleOwner should either be the module name or In-Portal for kernel related stuff. - (Items which should appear under 'System Configuration'). - - The Section field determines the NavMenu section the value is associated with. For example, - in-portal:configure_general refers to items listed under System Configuration->General. - - In the ConfigurationAdmin table, ensure the VariableName field is the same as the one in ConfigurationValues - (this is the field that creates the natural join.) The prompt field is the text displayed to the left of the form element - in the table. This should contain LANGUAGE ELEMENT IDENTIFIERS that are plugged into the Language function. - - The element_type field describes the type of form element is associated with this item. Possible values are: - - text : textbox - - checkbox : a simple checkbox - - select : creates a dropdown box. In this case, the ValueList field should be populated with a comma-separated list - in name=value,name=value format (each element is translated to: - - - To add dynamic data to this list, enclose an SQL statement with tags for example: - SELECT FieldLabel as OptionName, FieldName as OptionValue FROM CustomField WHERE .CustomFieldType=3> - - note the specific field labels OptionName and OptionValue. They are required by the parser. - use the tag to insert the system's table prefix into the sql statement as appropriate - - */ - class clsConfigAdminItem - { - var $name; - var $heading; - var $prompt; - var $ElementType; - var $ValueList; /* comma-separated list in name=value pair format*/ - var $ValidationRules; - var $default_value; - var $adodbConnection; - var $NextItem=NULL; - var $Section; - - function clsConfigAdminItem($config_name=NULL) - { - $this->adodbConnection = &GetADODBConnection(); - if($config_name) - $this->LoadSetting($config_name); - } - - function LoadSetting($config_name) - { - $sql = "SELECT * FROM ".GetTablePrefix()."ConfigurationAdmin INNER JOIN ".GetTablePrefix()."ConfigurationValues Using(VariableName) WHERE ".GetTablePrefix()."ConfigurationAdmin.VariableName='".$config_name."'"; - $rs = $this->adodbConnection->Execute($sql); - if($rs && !$rs->EOF) - { - $this->name = $rs->fields["VariableName"]; - $this->heading = $rs->fields["heading"]; - $this->prompt = $rs->fields["prompt"]; - $this->ElementType = $rs->fields["element_type"]; - $this->ValidationRules=$rs->fields["validation"]; - $this->default_value = $rs->fields["VariableValue"]; - $this->ValueList=$rs->fields["ValueList"]; - $this->Section = $rs->fields["Section"]; - } - } - - function explode_sql($sql) - { - $s = ""; - - $rs = $this->adodbConnection->Execute($sql); - - while ($rs && !$rs->EOF) - { - if(strlen(trim($rs->fields["OptionName"]))>0 && strlen(trim($rs->fields["OptionValue"]))>0) - { - if(strlen($s)) - $s .= ","; - $s .= $rs->fields["OptionName"]."="."+".$rs->fields["OptionValue"]; - } - $rs->MoveNext(); - } - return $s; - } - - function replace_sql($string) - { - $string = str_replace("",GetTablePrefix(),$string); - - $start = strpos($string,""); - - while($start) - { - $end = strpos($string,""); - if(!$end) - { - $end = strlen($string); - } - $len = $end - $start; - $sql = substr($string,$start+5,$len-5); - - $sql_val = $this->explode_sql($sql); - $s = substr($string,0,$start) . $sql_val . substr($string,$end+5); - - $string = $s; - $start = strpos($string,""); - } - return $string; - } - - function ItemFormElement($StartFrom=1) - { - global $objConfig; - static $TabIndex; - - if (empty($TabIndex)) - $TabIndex = $StartFrom; - - $o = ""; - if($objConfig->Get($this->name)!="") - $this->default_value = $objConfig->Get($this->name); - $this->default_value=inp_htmlize($this->default_value); - switch($this->ElementType) - { - case "text": - $o .= "name."\" "; - $o .= "VALUE=\"".$this->default_value."\">"; - break; - case "checkbox": - $o .= "name."\" tabindex=\"".($TabIndex++)."\""; - if($this->default_value) - { - $o .= " CHECKED>"; - } - else - $o .= ">"; - - break; - case "password": - - /* To exclude config form from populating with Root (md5) password */ - if ($this->Section == "in-portal:configure_users") - $this->default_value = ""; - - $o .= "name."\" "; - $o .= "VALUE=\"".$this->default_value."\">"; - break; - case "textarea": - $o .= ""; - break; - case "label": - if($this->default_value) - { - $o .= $this->default_value; - } - break; - case "radio": - $radioname = $this->name; - - $ValList = $this->replace_sql($this->ValueList); - - $TabIndex++; - $localTabIndex = $TabIndex; - $TabIndex++; - - $val = explode(",",$ValList); - for($i=0;$i<=count($val);$i++) - { - if(strlen($val[$i])) - { - $parts = explode("=",$val[$i]); - $s = $parts[1]; - if(strlen($s)==0) - $s=""; - - $o .= "name."\" VALUE=\"".$parts[0]."\""; - if($this->default_value==$parts[0]) - { - $o .= " CHECKED>"; - } - else - $o .= ">"; - if(substr($s,0,1)=="+") - { - $o .= $s; - } - else - $o .= prompt_language($s); - } - } - - break; - case "select": - $o .= ""; - } - return $o; - } - - function GetPrompt() - { - $ret = prompt_language($this->prompt); - return $ret; - } - } - - class clsConfigAdmin - { - var $module; - var $section; - var $Items; - - function clsConfigAdmin($module="",$section="",$Inst=FALSE) - { - $this->module = $module; - $this->section = $section; - $this->Items= array(); - if(strlen($module) && strlen($section)) - $this->LoadItems(TRUE,$Inst); - } - - function Clear() - { - unset($this->Items); - $this->Items = array(); - } - - function NumItems() - { - if(is_array($this->Items)) - { - return count($this->Items); - } - else - return 0; - } - - function LoadItems($CheckNextItems=TRUE, $inst=FALSE) - { - $this->Clear(); - if(!$inst) - { - $sql = "SELECT * FROM ".GetTablePrefix()."ConfigurationAdmin INNER JOIN ".GetTablePrefix()."ConfigurationValues Using(VariableName) - WHERE ModuleOwner='".$this->module."' AND Section='".$this->section."' ORDER BY DisplayOrder ASC"; - } - else - { - - $sql = "SELECT * FROM ".GetTablePrefix()."ConfigurationAdmin INNER JOIN ".GetTablePrefix()."ConfigurationValues Using(VariableName) - WHERE ModuleOwner='".$this->module."' AND Section='".$this->section."' AND Install=1 ORDER BY DisplayOrder ASC"; - } - if( $GLOBALS['debuglevel'] ) echo $sql."
\n"; - $adodbConnection = &GetADODBConnection(); - $rs = $adodbConnection->Execute($sql); - while($rs && !$rs->EOF) - { - $data = $rs->fields; - if(is_object($i) && $CheckNextItems) - { - $last = $i->prompt; - unset($i); - } - $i = new clsConfigAdminItem(NULL); - $i->name = $data["VariableName"]; - $i->default_value = $data["VariableValue"]; - $i->heading = $data["heading"]; - $i->prompt = $data["prompt"]; - $i->ElementType = $data["element_type"]; - $i->ValueList = $data["ValueList"]; - $i->ValidationRules = isset($data['validaton']) ? $data['validaton'] : ''; - $i->Section = $data["Section"]; - - if(strlen($last)>0) - { - if($i->prompt==$last) - { - $this->Items[count($this->Items)-1]->NextItem=$i; - } - else - { - $i->NextItem=NULL; - array_push($this->Items,$i); - } - } - else - { - $i->NextItem=NULL; - array_push($this->Items,$i); - } - //unset($i); - $rs->MoveNext(); - } - } - - function SaveItems($POSTVARS, $force=FALSE) - { - global $objConfig; - - foreach($this->Items as $i) - { - if($i->ElementType != "label") - { - if($i->ElementType != "checkbox") - { - $objConfig->Set($i->name,stripslashes($POSTVARS[$i->name])); - } - else - { - if($POSTVARS[$i->name]=="on") - { - $value=1; - } - else - $value = (int)$POSTVARS[$i->name]; - $objConfig->Set($i->name,stripslashes($value),0,$force); - } - } - } - $objConfig->Save(); - } - - function GetHeadingList() - { - $res = array(); - foreach($this->Items as $i) - { - $res[$i->heading]=1; - } - reset($res); - return array_keys($res); - } - - function GetHeadingItems($heading) - { - $res = array(); - foreach($this->Items as $i) - { - if($i->heading==$heading) - array_push($res,$i); - } - return $res; - } - } ?> \ No newline at end of file