Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Tue, Jun 24, 11:30 PM

in-portal

Index: branches/unlabeled/unlabeled-1.27.2/kernel/include/config.php
===================================================================
--- branches/unlabeled/unlabeled-1.27.2/kernel/include/config.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.27.2/kernel/include/config.php (revision 8063)
@@ -0,0 +1,480 @@
+<?php
+
+class clsConfig
+{
+ var $config;
+ var $m_dirty_session;
+ var $m_IsDirty;
+ var $m_DirtyFields;
+ var $m_VarType;
+ var $adodbConnection;
+
+ function clsConfig()
+ {
+ $this->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;
+ if (defined('DBG_SITE_PATH')) {
+ $this->config['Site_Path'] = DBG_SITE_PATH;
+ }
+ }
+
+ function Get($property)
+ {
+ if( isset($this->config[$property]) )
+ {
+ return $this->config[$property];
+ }
+ elseif( isset($this->config[ strtolower($property)] ) )
+ {
+ return $this->config[ strtolower($property) ];
+ }
+ else
+ {
+ return '';
+ }
+ }
+
+ 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."<br>\n";
+
+ $rs = $this->adodbConnection->execute($sql);
+ }
+ }
+ }
+ $this->m_IsDirty=FALSE;
+ unset($this->m_DirtyFields);
+ }
+
+ function TimeFormat()
+ {
+ return is12HourMode() ? 'g:i:s A' : 'H:i:s';
+ }
+
+ /* 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:
+ <option VALUE="[value]">[name]</option>
+
+ To add dynamic data to this list, enclose an SQL statement with <SQL></SQL> tags for example:
+ <SQL>SELECT FieldLabel as OptionName, FieldName as OptionValue FROM <prefix>CustomField WHERE <prefix>.CustomFieldType=3></SQL>
+
+ note the specific field labels OptionName and OptionValue. They are required by the parser.
+ use the <prefix> 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;
+
+ var $DisplayOrder = null;
+
+ var $TabIndex = 0;
+
+ /**
+ * Application instance
+ *
+ * @var kApplication
+ */
+ var $Application = null;
+
+ function clsConfigAdminItem($config_name=NULL)
+ {
+ $this->Application =& kApplication::Instance();
+ $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"];
+ $this->DisplayOrder = $rs->fields['DisplayOrder'];
+ }
+ }
+
+ function GetValues($string)
+ {
+ $cf_helper =& $this->Application->recallObject('InpCustomFieldsHelper');
+ /* @var $cf_helper InpCustomFieldsHelper */
+
+ return $cf_helper->GetValuesHash($string);
+ }
+
+ function ItemFormElement($StartFrom=1)
+ {
+ global $objConfig;
+
+ if(!$this->TabIndex) $this->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 .= '<input type="text" tabindex="'.($this->TabIndex++).'" name="'.$this->name.'" ';
+ $o .= 'value="'.$this->default_value.'">';
+ break;
+
+ case 'checkbox':
+ $o .= '<input type="checkbox" name="'.$this->name.'" tabindex="'.($this->TabIndex++).'"';
+ $o .= $this->default_value ? ' checked>' : '>';
+ break;
+
+ case 'password':
+ /* To exclude config form from populating with Root (md5) password */
+ if( $this->Section == 'in-portal:configure_users' ) $this->default_value = '';
+
+ $o .= '<input type="password" tabindex="'.($this->TabIndex++).'" name="'.$this->name.'" ';
+ $o .= 'value="'.$this->default_value.'">';
+ break;
+
+ case 'textarea':
+ $o .= '<textarea tabindex="'.($this->TabIndex++).'" '.$this->ValueList.' name="'.$this->name.'">'.$this->default_value.'</textarea>';
+ break;
+
+ case 'label':
+ if ($this->default_value) {
+ $tag_params = clsHtmlTag::ParseAttributes($this->ValueList);
+ if (isset($tag_params['cut_first'])) {
+ $cut_first = $tag_params['cut_first'];
+ if (strlen($this->default_value) > $cut_first) {
+ $o .= substr($this->default_value, 0, $cut_first).' ...';
+ }
+ else {
+ $o .= $this->default_value;
+ }
+ }
+ else {
+ $o .= $this->default_value;
+ }
+ }
+ break;
+
+ case 'radio':
+ $radioname = $this->name;
+ $this->TabIndex++;
+ $values = $this->GetValues($this->ValueList);
+ foreach ($values as $option_id => $option_name) {
+ $o .= '<input type="radio" tabindex="'.$this->TabIndex.'" name="'.$this->name.'" value="'.$option_id.'"';
+ $o .= ($this->default_value == $option_id) ? ' checked>' : '>';
+ $o .= $option_name;
+ }
+ $this->TabIndex++;
+ break;
+
+ case 'select':
+ $o .= '<select name="'.$this->name.'" tabindex="'.($this->TabIndex++).'">';
+ $values = $this->GetValues($this->ValueList);
+
+ foreach ($values as $option_id => $option_name) {
+ $selected = $this->default_value == $option_id ? ' selected' : '';
+ $o .= '<option value="'.$option_id.'" '.$selected.'>'.$option_name.'</option>';
+ }
+ $o .= '</select>';
+ break;
+
+ case 'multiselect':
+ $o .= '<select id="'.$this->name.'_select" tabindex="'.($this->TabIndex++).'" onchange="update_multiple_options(\''.$this->name.'\');" multiple>';
+ $values = $this->GetValues($this->ValueList);
+
+ $selected_values = explode('|', substr($this->default_value, 1, -1) );
+ foreach ($values as $option_id => $option_name) {
+ $selected = in_array($option_id, $selected_values) ? ' selected' : '';
+ $o .= '<option value="'.$option_id.'" '.$selected.'>'.$option_name.'</option>';
+ }
+ $o .= '</select><input type="hidden" id="'.$this->name.'" name="'.$this->name.'" value="'.$this->default_value.'"/>';
+ break;
+ }
+ 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."<br>\n";
+ $adodbConnection = &GetADODBConnection();
+ $rs = $adodbConnection->Execute($sql);
+ $i = null;
+ $last = '';
+ 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"];
+ $i->DisplayOrder = $data['DisplayOrder'];
+
+ 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
Property changes on: branches/unlabeled/unlabeled-1.27.2/kernel/include/config.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.27
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

Event Timeline