Nouvelle version pour manipulation et utilisation des variables.
Interface de visualiastion OK TODO: * php -> interface de modification * sql -> finir migration (strata des truc presents) * sql -> faire installation
This commit is contained in:
		
							parent
							
								
									2583bc73f2
								
							
						
					
					
						commit
						2b8b5e0f67
					
				|  | @ -578,6 +578,7 @@ install/upgrades/3.0.3~b.sh -text | ||||||
| install/upgrades/3.1.0~a.sql -text | install/upgrades/3.1.0~a.sql -text | ||||||
| install/upgrades/3.1.0~b.php -text | install/upgrades/3.1.0~b.php -text | ||||||
| install/upgrades/3.2.1~a.sql -text | install/upgrades/3.2.1~a.sql -text | ||||||
|  | install/upgrades/3.3.0~a.sql -text | ||||||
| install/upgrades/README -text | install/upgrades/README -text | ||||||
| lang/.svnignore -text | lang/.svnignore -text | ||||||
| lang/README -text | lang/README -text | ||||||
|  |  | ||||||
|  | @ -33,6 +33,11 @@ if (!$admin->enabled) { | ||||||
| 	__("This page is restricted to authorized staff"); | 	__("This page is restricted to authorized staff"); | ||||||
| 	exit(); | 	exit(); | ||||||
| } | } | ||||||
|  | $fields = array ( | ||||||
|  |   "member_id"   => array ("post", "integer", null), | ||||||
|  |   "fqdn_id"     => array ("post", "integer", null), | ||||||
|  | ); | ||||||
|  | getFields($fields); | ||||||
| 
 | 
 | ||||||
| $conf = $variables->variable_init(); | $conf = $variables->variable_init(); | ||||||
| foreach ($conf as $name => $val) { | foreach ($conf as $name => $val) { | ||||||
|  | @ -54,18 +59,93 @@ include_once ("head.php"); | ||||||
| 
 | 
 | ||||||
| <form method="post" action="adm_variables.php"> | <form method="post" action="adm_variables.php"> | ||||||
| <table border="0" cellpadding="4" cellspacing="0" class='tlist'> | <table border="0" cellpadding="4" cellspacing="0" class='tlist'> | ||||||
| <tr><th><?php __("Names"); ?></th><th><?php __("Value"); ?></th><th><?php __("Comment"); ?></th></tr>
 | <thead> | ||||||
|  |   <tr> | ||||||
|  |     <th><?php __("Names"); ?></th>
 | ||||||
|  |     <th><?php __("Comment"); ?></th>
 | ||||||
|  |     <th><?php __("Default value"); ?></th>
 | ||||||
|  |     <th><?php __("Global value"); ?></th>
 | ||||||
|  |     <th><?php __("Actual value used"); ?></th>
 | ||||||
|  |   </tr> | ||||||
|  | </thead> | ||||||
| <?php | <?php | ||||||
| 
 | 
 | ||||||
| foreach( $variables->variables_list() as $vars) {  ?>
 | $allvars = $variables->variables_list(); | ||||||
|  | foreach( $variables->variables_list_name() as $varname => $varcomment) {  ?>
 | ||||||
| 
 | 
 | ||||||
|  <tr class="lst"> |  <tr class="lst"> | ||||||
|  <td><?php echo $vars['name']; ?></td>
 |  <td><?php echo $varname; ?></td>
 | ||||||
|  |  <td><?php echo $varcomment; ?></td>
 | ||||||
|  |  <td><?php echo $allvars['DEFAULT'][NULL][$varname]['value']; ?></td>
 | ||||||
|  |  <td><?php if (isset($allvars['GLOBAL'][NULL][$varname]['value'])) { echo $allvars['GLOBAL'][NULL][$varname]['value']; } ?></td>
 | ||||||
|  |  <td><?php echo variable_get($varname); ?></td>
 | ||||||
|  | 
 | ||||||
|  | <!-- | ||||||
|  <td><input type="text" name="<?php ehe($vars['name']); ?>" value="<?php ehe($vars['value']); ?>" /></td> |  <td><input type="text" name="<?php ehe($vars['name']); ?>" value="<?php ehe($vars['value']); ?>" /></td> | ||||||
|  <td><?php echo $vars['comment']; ?></td>
 | --> | ||||||
|  </tr> |  </tr> | ||||||
| <?php } ?>
 | <?php } ?>
 | ||||||
| </table> | </table> | ||||||
|  | <!-- | ||||||
| <p><input type="submit" class="inb" value="<?php __("Save variables"); ?>" /></p> | <p><input type="submit" class="inb" value="<?php __("Save variables"); ?>" /></p> | ||||||
|  | --> | ||||||
| </form> | </form> | ||||||
|  | 
 | ||||||
|  | <br/> <br/><br/> | ||||||
|  | 
 | ||||||
|  | <hr/> | ||||||
|  | <h3 id="overwrited_vars"><?php __("Overwrited vars"); ?></h3>
 | ||||||
|  | <form method="post" action="adm_variables.php#overwrited_vars"> | ||||||
|  | <?php | ||||||
|  | $creator=$mem->get_creator_by_uid($uid); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | $ml=array(); | ||||||
|  | foreach($admin->get_list() as $mid=>$mlogin) { | ||||||
|  |   $ml[$mid] = $mlogin['login']; | ||||||
|  | } | ||||||
|  | echo _("See the vars for the account")." "; | ||||||
|  | echo "<select name='member_id'>";eoption($ml, $member_id);echo "</select>"; | ||||||
|  | echo " "._("logged via")." "; | ||||||
|  | echo "<select name='fqdn_id'>";eoption($dom->get_panel_url_list(), $fqdn_id  );echo "</select> "; | ||||||
|  | echo "<input type='submit' class='ina' value=\""; echo ehe(_("View")); echo "\" />"; | ||||||
|  | 
 | ||||||
|  | ?>
 | ||||||
|  | </form> | ||||||
|  | <br/> | ||||||
|  | 
 | ||||||
|  | <?php  | ||||||
|  | $sub_infos=$dom->get_sub_domain_all($fqdn_id); | ||||||
|  | $fqdn=$dom->get_panel_url_list()[$fqdn_id]; | ||||||
|  | $impersonated_conf=$variables->get_impersonated($fqdn, $member_id); | ||||||
|  | 
 | ||||||
|  | echo sprintf(_("Here are values for members %s logged via %s"), '<b>'.$ml[$member_id].'</b>', "<b>$fqdn</b>") ;?>
 | ||||||
|  | <table class='tlist'> | ||||||
|  | <?php | ||||||
|  | echo "<thead><tr>"; | ||||||
|  | echo "<th>"._("Var")."</th>"; | ||||||
|  | foreach( $variables->strata_order as $st) {   | ||||||
|  |   echo "<th>$st</th>"; | ||||||
|  | } // foeach
 | ||||||
|  | echo "<th>"._("Used value")."</th>"; | ||||||
|  | echo "</tr></thead>"; | ||||||
|  | foreach( $variables->variables_list_name() as $varname => $varcomment) {  ?>
 | ||||||
|  |  <tr class="lst"> | ||||||
|  |    <td><?php echo $varname; ?></td>
 | ||||||
|  |    <td><?php echo $allvars['DEFAULT'][NULL][$varname]['value']; ?></td>
 | ||||||
|  |    <td><?php if (isset($allvars['GLOBAL'][NULL][$varname]['value'])) { echo $allvars['GLOBAL'][NULL][$varname]['value']; } ?></td>
 | ||||||
|  |    <td><?php if (isset($allvars['FQDN_CREATOR'][$sub_infos['member_id']][$varname]['value'])) { echo $allvars['FQDN_CREATOR'][$sub_infos['member_id']][$varname]['value']; } ?></td>
 | ||||||
|  |    <td><?php if (isset($allvars['FQDN'][$sub_infos['id']][$varname]['value'])) { echo $allvars['FQDN'][$sub_infos['id']][$varname]['value']; } ?></td>
 | ||||||
|  |    <td><?php if (isset($allvars['CREATOR'][$creator][$varname]['value'])) { echo $allvars['CREATOR'][$creator][$varname]['value']; } ?></td>
 | ||||||
|  |    <td><?php if (isset($allvars['MEMBER'][$member_id][$varname]['value'])) { echo $allvars['MEMBER'][$member_id][$varname]['value']; } ?></td>
 | ||||||
|  |    <td><?php if (isset($allvars['DOMAIN']['FIXME'][$varname]['value'])) { echo $allvars['DOMAIN']['FIXME'][$varname]['value']; } ?></td>
 | ||||||
|  |    <td><?php echo $impersonated_conf[$varname]['value']; ?></td>
 | ||||||
|  |  </tr> | ||||||
|  | <?php | ||||||
|  | } //foreach 
 | ||||||
|  | ?>
 | ||||||
|  | </table> | ||||||
|  | 
 | ||||||
|  | <br/> | ||||||
|  | 
 | ||||||
| <?php include_once("foot.php"); ?>
 | <?php include_once("foot.php"); ?>
 | ||||||
|  |  | ||||||
|  | @ -348,7 +348,7 @@ class m_admin { | ||||||
| 
 | 
 | ||||||
|     if ($db->num_rows()) { |     if ($db->num_rows()) { | ||||||
|       while ($db->next_record()) { |       while ($db->next_record()) { | ||||||
| 	$c[]=$this->get($db->f("uid")); | 	$c[$db->f("uid")]=$this->get($db->f("uid")); | ||||||
|       } |       } | ||||||
|       return $c; |       return $c; | ||||||
|     } else { |     } else { | ||||||
|  |  | ||||||
|  | @ -87,6 +87,26 @@ class m_dom { | ||||||
|     $this->tld_no_check_at_all = variable_get('tld_no_check_at_all', 0,'Set to 1 to disable ALL check on the TLD (users will be able to add any domain)'); |     $this->tld_no_check_at_all = variable_get('tld_no_check_at_all', 0,'Set to 1 to disable ALL check on the TLD (users will be able to add any domain)'); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   function get_panel_url_list() { | ||||||
|  |     global $db,$err; | ||||||
|  |     $err->log("dom","get_panel_url_list"); | ||||||
|  |     $db->query("SELECT sd.id as sub_id, if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine) as fqdn from sub_domaines sd where type = 'PANEL';"); | ||||||
|  |     $t=array(); | ||||||
|  |     while ($db->next_record()) { | ||||||
|  |       $t[intval($db->f('sub_id'))] = $db->f('fqdn'); | ||||||
|  |     } | ||||||
|  |     return $t; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   function get_sub_domain_id_and_member_by_name($fqdn) { | ||||||
|  |     global $db,$err,$cuid; | ||||||
|  |     $err->log("dom","get_sub_domain_by_name"); | ||||||
|  |     $fqdn=mysql_real_escape_string($fqdn); | ||||||
|  |     $db->query("select sd.* from sub_domaines sd where if(length(sd.sub)>0,concat_ws('.',sd.sub,sd.domaine),sd.domaine) = '$fqdn';"); | ||||||
|  |     if (! $db->next_record()) return false; | ||||||
|  |     return array('sub_id'=>intval($db->f('id')), 'member_id'=> intval($db->f('compte') )); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   function hook_menu() { |   function hook_menu() { | ||||||
|     global $quota; |     global $quota; | ||||||
|     $obj = array(  |     $obj = array(  | ||||||
|  |  | ||||||
|  | @ -586,6 +586,15 @@ Cordially. | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   function get_creator_by_uid($uid) { | ||||||
|  |     global $db,$err; | ||||||
|  |     $err->log("dom","get_creator_by_uid"); | ||||||
|  |     $uid=mysql_real_escape_string(intval($uid)); | ||||||
|  |     $db->query("select creator from membres where uid = '$uid';"); | ||||||
|  |     if (! $db->next_record()) return false; | ||||||
|  |     return intval($db->f('creator') ); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
|   /* ----------------------------------------------------------------- */ |   /* ----------------------------------------------------------------- */ | ||||||
|   /** |   /** | ||||||
|  |  | ||||||
|  | @ -34,129 +34,212 @@ | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| class m_variables { | class m_variables { | ||||||
| /** |   var $strata_order = array('DEFAULT','GLOBAL','FQDN_CREATOR','FQDN','CREATOR','MEMBER','DOMAIN'); | ||||||
|  * Load the persistent variable table. | 
 | ||||||
|  * |   // used by get_impersonated to merge array. Son value overwrite father's value
 | ||||||
|  * The variable table is composed of values that have been saved in the table |   private function variable_merge($father, $son) { | ||||||
|  * with variable_set() as well as those explicitly specified in the configuration |     if (! is_array($son)) return $father; | ||||||
|  * file. |     foreach ($son as $k=>$v) { | ||||||
|  */ |       $father[$k] = $v; | ||||||
| function variable_init($conf = array()) { |     } | ||||||
|   global $db; |     return $father; | ||||||
|   $result = $db->query('SELECT * FROM `variable`'); |   } | ||||||
|   while ($db->next_record($result)) { | 
 | ||||||
|     /* maybe the data is *not* serialized, in that case, take it verbatim */ |   /** | ||||||
|     $variable = $db->Record; |    * Load the persistent variable table. | ||||||
|     if (($variables[$variable['name']] = @unserialize($variable['value'])) === FALSE) { |    * | ||||||
|       $variables[$variable['name']] = $variable['value']; |    * The variable table is composed of values that have been saved in the table | ||||||
|  |    * with variable_set() as well as those explicitly specified in the configuration | ||||||
|  |    * file. | ||||||
|  |    */ | ||||||
|  |   function variable_init() { | ||||||
|  |     global $cuid; | ||||||
|  |     if ($cuid > 1999) { | ||||||
|  |       $mid = $cuid; | ||||||
|  |     } else { | ||||||
|  |       $mid = null; | ||||||
|  |     } | ||||||
|  |     return $this->get_impersonated($_SERVER['HTTP_HOST'], $mid); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |   function get_impersonated($fqdn, $uid=null, $var=null) { | ||||||
|  |     global $db, $err; | ||||||
|  | 
 | ||||||
|  |     $arr_var=$this->variables_list(); | ||||||
|  |    | ||||||
|  |     // Get some vars we are going to need.
 | ||||||
|  |     $sub_infos=m_dom::get_sub_domain_id_and_member_by_name( strtolower($fqdn) ); | ||||||
|  |     if ( $uid != NULL ) { | ||||||
|  |       $creator=m_mem::get_creator_by_uid($uid); | ||||||
|  |     } else { | ||||||
|  |       $creator=false; | ||||||
|  |     } | ||||||
|  |     | ||||||
|  |     $variables = array(); | ||||||
|  |     // Browse the array in the specific order of the strata
 | ||||||
|  |     foreach ( $this->strata_order as $strata) { | ||||||
|  |       if (! isset($arr_var[$strata]) || !is_array($arr_var[$strata])) continue; | ||||||
|  |       switch($strata) { | ||||||
|  |         case 'DEFAULT': | ||||||
|  |           $variables = $this->variable_merge(array(),$arr_var['DEFAULT'][NULL]); | ||||||
|  |           break; | ||||||
|  |         case 'GLOBAL': | ||||||
|  |           $variables = $this->variable_merge($variables, $arr_var['GLOBAL'][NULL]); | ||||||
|  |           break; | ||||||
|  |         case 'FQDN_CREATOR': | ||||||
|  |           if ( is_array($sub_infos) && isset($arr_var['FQDN_CREATOR'][$sub_infos['member_id']]) && is_array($arr_var['FQDN_CREATOR'][$sub_infos['member_id']])) { | ||||||
|  |             $variables = $this->variable_merge($variables, $arr_var['FQDN_CREATOR'][$sub_infos['member_id']]); | ||||||
|  |           } | ||||||
|  |           break; | ||||||
|  |         case 'FQDN': | ||||||
|  |           if ( is_array($sub_infos) && isset($arr_var['FQDN'][$sub_infos['sub_id']]) && is_array($arr_var['FQDN'][$sub_infos['sub_id']])) { | ||||||
|  |             $variables = $this->variable_merge($variables, $arr_var['FQDN'][$sub_infos['sub_id']]); | ||||||
|  |           } | ||||||
|  |           break; | ||||||
|  |         case 'CREATOR': | ||||||
|  |           if ( $creator && isset($arr_var['CREATOR'][$creator]) && is_array($arr_var['CREATOR'][$creator])) { | ||||||
|  |             $variables = $this->variable_merge($variables, $arr_var['CREATOR'][$creator] ); | ||||||
|  |           } | ||||||
|  |           break; | ||||||
|  |         case 'MEMBER': | ||||||
|  |           if ( $uid && isset($arr_var['MEMBER'][$uid]) && is_array($arr_var['MEMBER'][$uid])) { | ||||||
|  |             $variables = $this->variable_merge($variables, $arr_var['MEMBER'][$uid] ); | ||||||
|  |           } | ||||||
|  |           break; | ||||||
|  |         case 'MEMBER': | ||||||
|  |           //FIXME TODO
 | ||||||
|  |           break; | ||||||
|  |       } //switch
 | ||||||
|  | 
 | ||||||
|  |     } //foreach
 | ||||||
|  | 
 | ||||||
|  |   #printvar($variables);die();
 | ||||||
|  |     if ($var && isset($variables[$var])) { | ||||||
|  |       return $variables[$var]; | ||||||
|  |     } else { | ||||||
|  |        return $variables; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   foreach ($conf as $name => $value) { |   /** | ||||||
|     $variables[$name] = $value; |    * Initialize the global $conf array if necessary | ||||||
|  |    * | ||||||
|  |    * @global $conf the global conf array | ||||||
|  |    * @uses variable_init() | ||||||
|  |    */ | ||||||
|  |   function variable_init_maybe($force=false) { | ||||||
|  |     global $conf; | ||||||
|  |     if ($force || !isset($conf)) { | ||||||
|  |       $conf = $this->variable_init(); | ||||||
|  |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   return $variables; |   /** | ||||||
| } |    * Return a persistent variable. | ||||||
|  |    * | ||||||
|  |    * @param $name | ||||||
|  |    *   The name of the variable to return. | ||||||
|  |    * @param $default | ||||||
|  |    *   The default value to use if this variable has never been set. | ||||||
|  |    * @param $createit_comment  | ||||||
|  |    *   If variable doesn't exist, create it with the default value | ||||||
|  |    *   and createit_comment value as comment | ||||||
|  |    * @return | ||||||
|  |    *   The value of the variable. | ||||||
|  |    * @global $conf | ||||||
|  |    *   A cache of the configuration. | ||||||
|  |    */ | ||||||
|  |   function variable_get($name, $default = null, $createit_comment = null) { | ||||||
|  |     global $conf; | ||||||
|  |     $name=str_replace('.', '_', $name); // Php can't handle POST var with a '.'
 | ||||||
| 
 | 
 | ||||||
| /** |     $this->variable_init_maybe(); | ||||||
|  * Initialize the global $conf array if necessary |  | ||||||
|  * |  | ||||||
|  * @global $conf the global conf array |  | ||||||
|  * @uses variable_init() |  | ||||||
|  */ |  | ||||||
| function variable_init_maybe() { |  | ||||||
|   global $conf; |  | ||||||
|   if (!isset($conf)) { |  | ||||||
|     $conf = $this->variable_init(); |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| /** |     if (isset($conf[$name])) { | ||||||
|  * Return a persistent variable. |       return $conf[$name]['value']; | ||||||
|  * |     } elseif (!is_null($createit_comment)) { | ||||||
|  * @param $name |       $this->variable_set($name, $default, $createit_comment); | ||||||
|  *   The name of the variable to return. |     } | ||||||
|  * @param $default |     return $default; | ||||||
|  *   The default value to use if this variable has never been set. |  | ||||||
|  * @param $createit_comment  |  | ||||||
|  *   If variable doesn't exist, create it with the default value |  | ||||||
|  *   and createit_comment value as comment |  | ||||||
|  * @return |  | ||||||
|  *   The value of the variable. |  | ||||||
|  * @global $conf |  | ||||||
|  *   A cache of the configuration. |  | ||||||
|  */ |  | ||||||
| function variable_get($name, $default = null, $createit_comment = null) { |  | ||||||
|   global $conf; |  | ||||||
|   $name=str_replace('.', '_', $name); // Php can't handle POST var with a '.'
 |  | ||||||
| 
 |  | ||||||
|   $this->variable_init_maybe(); |  | ||||||
| 
 |  | ||||||
|   if (isset($conf[$name])) { |  | ||||||
|     return $conf[$name]; |  | ||||||
|   } elseif (!is_null($createit_comment)) { |  | ||||||
|     $this->variable_set($name, $default, $createit_comment); |  | ||||||
|   } |  | ||||||
|   return $default; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * Set a persistent variable. |  | ||||||
|  * |  | ||||||
|  * @param $name |  | ||||||
|  *   The name of the variable to set. |  | ||||||
|  * @param $value |  | ||||||
|  *   The value to set. This can be any PHP data type; these functions take care |  | ||||||
|  *   of serialization as necessary. |  | ||||||
|  */ |  | ||||||
| function variable_set($name, $value, $comment=null) { |  | ||||||
|   global $conf, $db, $err; |  | ||||||
|   $err->log('variable', 'variable_set', '+'.serialize($value).'+'.$comment.'+');  |  | ||||||
| 
 |  | ||||||
|   $name=str_replace('.', '_', $name); // Php can't handle POST var with a '.'
 |  | ||||||
| 
 |  | ||||||
|   $conf[$name] = $value; |  | ||||||
|   if (is_object($value) || is_array($value)) { |  | ||||||
|     $value = serialize($value); |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   if ( empty($comment) ) { |   /** | ||||||
|     $query = "INSERT INTO variable (name, value) values ('".$name."', '".$value."') on duplicate key update name='$name', value='$value';"; |    * Set a persistent variable. | ||||||
|   } else { |    * | ||||||
|     $comment=mysql_real_escape_string($comment); |    * @param $name | ||||||
|     $query = "INSERT INTO variable (name, value, comment) values ('".$name."', '".$value."', '$comment') on duplicate key update name='$name', value='$value', comment='$comment';"; |    *   The name of the variable to set. | ||||||
|  |    * @param $value | ||||||
|  |    *   The value to set. This can be any PHP data type; these functions take care | ||||||
|  |    *   of serialization as necessary. | ||||||
|  |    */ | ||||||
|  |   function variable_set($name, $value, $comment=null) { | ||||||
|  |     global $conf, $db, $err; | ||||||
|  |     $err->log('variable', 'variable_set', '+'.serialize($value).'+'.$comment.'+');  | ||||||
|  | 
 | ||||||
|  |     $name=str_replace('.', '_', $name); // Php can't handle POST var with a '.'
 | ||||||
|  | 
 | ||||||
|  |     $conf[$name] = $value; | ||||||
|  |     if (is_object($value) || is_array($value)) { | ||||||
|  |       $value = serialize($value); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if ( empty($comment) ) { | ||||||
|  |       $query = "INSERT INTO variable (name, value) values ('".$name."', '".$value."') on duplicate key update name='$name', value='$value';"; | ||||||
|  |     } else { | ||||||
|  |       $comment=mysql_real_escape_string($comment); | ||||||
|  |       $query = "INSERT INTO variable (name, value, comment) values ('".$name."', '".$value."', '$comment') on duplicate key update name='$name', value='$value', comment='$comment';"; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |   #  $db->query("$query");
 | ||||||
|  |     printvar($query); | ||||||
|  | 
 | ||||||
|  |     $this->variable_init(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   $db->query("$query"); |   /** | ||||||
| 
 |    * Unset a persistent variable. | ||||||
|   $this->variable_init(); |    * | ||||||
| } |    * @param $name | ||||||
| 
 |    *   The name of the variable to undefine. | ||||||
| /** |    */ | ||||||
|  * Unset a persistent variable. |   function variable_del($id) { | ||||||
|  * |     global $db; | ||||||
|  * @param $name |     $db->query("DELETE FROM `variable` WHERE id = '".intval($id)."'"); | ||||||
|  *   The name of the variable to undefine. |     $this->variable_init_maybe(true); | ||||||
|  */ |   } | ||||||
| function variable_del($name) { | 
 | ||||||
|   global $conf, $db; |   function variables_list_name() { | ||||||
|   $name=str_replace('.', '_', $name); // Php can't handle POST var with a '.'
 |     global $db; | ||||||
| 
 | 
 | ||||||
|   $db->query("DELETE FROM `variable` WHERE name = '".$name."'"); |     $result = $db->query('SELECT name, comment FROM `variable` order by name'); | ||||||
| 
 |     $t=array(); | ||||||
|   unset($conf[$name]); |     while ($db->next_record($result)) { | ||||||
| } |       $tname = $db->f('name'); | ||||||
| 
 |       // If not listed of if listed comment is shorter
 | ||||||
| function variables_list() { |       if ( ! isset( $t[$tname] ) || strlen($t[$tname]) < $db->f('comment') ) { | ||||||
|   global $db; |         $t[$db->f('name')] = $db->f('comment'); | ||||||
|   $t=array(); |       } | ||||||
|   $db->query("SELECT * FROM `variable` WHERE `comment` IS NOT NULL ORDER BY `name`"); |     } | ||||||
|   while ($db->next_record()) { |     return $t; | ||||||
|     $t[]=$db->Record; |   } | ||||||
|  | 
 | ||||||
|  |   function variables_list() { | ||||||
|  |     global $db; | ||||||
|  | 
 | ||||||
|  |     $result = $db->query('SELECT * FROM `variable`'); | ||||||
|  | 
 | ||||||
|  |     $arr_var=array(); | ||||||
|  |     while ($db->next_record($result)) { | ||||||
|  |       // Unserialize value if needed
 | ||||||
|  |       if ( ($value = @unserialize($db->f('value'))) === FALSE) { | ||||||
|  |         $value=$db->f('value'); | ||||||
|  |       } | ||||||
|  |       $arr_var[$db->f('strata')][$db->f('strata_id')][$db->f('name')] = array('id'=>$db->f('id') ,'name'=>$db->f('name'), 'value'=>$value, 'comment'=>$db->f('comment')); | ||||||
|  |     } | ||||||
|  |   | ||||||
|  |     return $arr_var; | ||||||
|   } |   } | ||||||
|   return $t; |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| } /* Class m_variables */ | } /* Class m_variables */ | ||||||
| ?>
 | ?>
 | ||||||
|  |  | ||||||
|  | @ -0,0 +1,8 @@ | ||||||
|  | 
 | ||||||
|  | ALTER TABLE variable DROP PRIMARY KEY; | ||||||
|  | ALTER TABLE variable ADD id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST; | ||||||
|  | ALTER TABLE variable ADD strata enum('DEFAULT','GLOBAL','FQDN', 'FQDN_CREATOR', 'CREATOR', 'MEMBER', 'DOMAIN') NOT NULL DEFAULT 'DEFAULT'; | ||||||
|  | ALTER TABLE variable ADD strata_id bigint DEFAULT NULL; | ||||||
|  | ALTER TABLE variable ADD UNIQUE (name, strata, strata_id); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
		Loading…
	
		Reference in New Issue
	
	 Alan Garcia
						Alan Garcia