2006-04-26 12:28:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* $Id: variables.php,v 1.8 2005/04/02 00:26:36 anarcat Exp $
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
AlternC - Web Hosting System
|
|
|
|
Copyright (C) 2002 by the AlternC Development Team.
|
|
|
|
http://alternc.org/
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
Based on:
|
|
|
|
Valentin Lacambre's web hosting softwares: http://altern.org/
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
LICENSE
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License (GPL)
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Persistent variable table
|
|
|
|
*
|
|
|
|
* @author Drupal Developpement Team
|
|
|
|
* @link http://cvs.drupal.org/viewcvs/drupal/drupal/includes/bootstrap.inc?rev=1.38&view=auto
|
2014-03-26 13:47:27 +00:00
|
|
|
* @
|
2006-04-26 12:28:53 +00:00
|
|
|
*/
|
2014-01-20 13:44:25 +00:00
|
|
|
class m_variables {
|
2014-01-21 12:57:18 +00:00
|
|
|
var $strata_order = array('DEFAULT','GLOBAL','FQDN_CREATOR','FQDN','CREATOR','MEMBER','DOMAIN');
|
2014-01-31 13:50:15 +00:00
|
|
|
var $cache_variable_list = false;
|
2014-03-20 13:27:33 +00:00
|
|
|
var $replace_array = array();
|
|
|
|
|
2014-03-22 14:47:14 +00:00
|
|
|
/**
|
|
|
|
*
|
2014-03-26 16:57:04 +00:00
|
|
|
* @global string $L_FQDN
|
2014-03-22 14:47:14 +00:00
|
|
|
*/
|
2014-03-20 13:27:33 +00:00
|
|
|
function m_variables() {
|
|
|
|
global $L_FQDN;
|
|
|
|
$this->replace_array = array(
|
|
|
|
"%%FQDN%%"=> $L_FQDN,
|
|
|
|
);
|
|
|
|
}
|
2014-01-21 12:57:18 +00:00
|
|
|
|
2014-03-22 14:47:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* used by get_impersonated to merge array. Son value overwrite father's value
|
|
|
|
*
|
|
|
|
* @param array $father
|
|
|
|
* @param array $son
|
|
|
|
* @return array
|
|
|
|
*/
|
2014-01-21 12:57:18 +00:00
|
|
|
private function variable_merge($father, $son) {
|
|
|
|
if (! is_array($son)) return $father;
|
|
|
|
foreach ($son as $k=>$v) {
|
|
|
|
$father[$k] = $v;
|
2006-04-26 12:28:53 +00:00
|
|
|
}
|
2014-01-21 12:57:18 +00:00
|
|
|
return $father;
|
2006-04-26 12:28:53 +00:00
|
|
|
}
|
2014-01-21 12:57:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the persistent variable table.
|
|
|
|
*
|
|
|
|
* 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.
|
2014-03-22 14:47:14 +00:00
|
|
|
*
|
|
|
|
* @global int $cuid
|
|
|
|
* @return array
|
2014-01-21 12:57:18 +00:00
|
|
|
*/
|
|
|
|
function variable_init() {
|
|
|
|
global $cuid;
|
|
|
|
if ($cuid > 1999) {
|
|
|
|
$mid = $cuid;
|
|
|
|
} else {
|
|
|
|
$mid = null;
|
|
|
|
}
|
2014-01-31 13:50:15 +00:00
|
|
|
|
|
|
|
// In case we launch it in a script, there is no $_SERVER
|
2014-01-30 17:34:20 +00:00
|
|
|
if (isset($_SERVER['HTTP_HOST'])) {
|
|
|
|
$host=$_SERVER['HTTP_HOST'];
|
|
|
|
} else {
|
|
|
|
$host=null;
|
|
|
|
}
|
|
|
|
return $this->get_impersonated($host, $mid);
|
2006-04-26 12:28:53 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 13:50:15 +00:00
|
|
|
/**
|
|
|
|
* Return the var for a specific environnement :
|
|
|
|
* * logged via $fqdn url
|
|
|
|
* * the user is $uid
|
|
|
|
* * $var if we want only 1 var instead of all of them
|
|
|
|
*
|
|
|
|
* If $fqdn and $uid aren't specified, return the default value
|
|
|
|
*
|
2014-03-26 10:59:59 +00:00
|
|
|
* @global m_mysql $db
|
|
|
|
* @global m_err $err
|
|
|
|
* @param string $fqdn
|
|
|
|
* @param int $uid
|
|
|
|
* @param string $var
|
2014-03-22 14:47:14 +00:00
|
|
|
* @return array
|
2014-01-31 13:50:15 +00:00
|
|
|
*/
|
2014-01-21 13:35:50 +00:00
|
|
|
function get_impersonated($fqdn=null, $uid=null, $var=null) {
|
2014-01-21 12:57:18 +00:00
|
|
|
global $db, $err;
|
2006-04-26 12:28:53 +00:00
|
|
|
|
2014-01-21 12:57:18 +00:00
|
|
|
$arr_var=$this->variables_list();
|
2014-01-31 09:50:20 +00:00
|
|
|
|
2014-01-21 12:57:18 +00:00
|
|
|
// Get some vars we are going to need.
|
2014-01-21 13:35:50 +00:00
|
|
|
if ($fqdn != NULL) {
|
|
|
|
$sub_infos=m_dom::get_sub_domain_id_and_member_by_name( strtolower($fqdn) );
|
|
|
|
} else {
|
|
|
|
$sub_infos=false;
|
|
|
|
}
|
|
|
|
|
2014-01-21 12:57:18 +00:00
|
|
|
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':
|
2014-03-22 14:47:14 +00:00
|
|
|
|
|
|
|
// $variables = $this->variable_merge(array(),$arr_var['DEFAULT'][NULL]);
|
2014-03-27 09:57:34 +00:00
|
|
|
$variablesList = current($arr_var["DEFAULT"]);
|
2014-03-22 14:47:14 +00:00
|
|
|
$variables = $this->variable_merge(array(),$variablesList);
|
2014-01-21 12:57:18 +00:00
|
|
|
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;
|
2014-01-21 16:25:43 +00:00
|
|
|
case 'DOMAIN':
|
2014-01-21 12:57:18 +00:00
|
|
|
//FIXME TODO
|
|
|
|
break;
|
|
|
|
} //switch
|
|
|
|
|
|
|
|
} //foreach
|
|
|
|
|
2014-03-20 13:27:33 +00:00
|
|
|
// Replace needed vars
|
|
|
|
foreach ($variables as $vv => $hh) {
|
2014-03-27 16:40:30 +00:00
|
|
|
if (!isset($hh['value']) || !empty($hh['value'])) {
|
2014-03-20 13:27:33 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$variables[$vv]['value'] = strtr($hh['value'], $this->replace_array );
|
|
|
|
}
|
|
|
|
|
2014-01-21 12:57:18 +00:00
|
|
|
if ($var && isset($variables[$var])) {
|
|
|
|
return $variables[$var];
|
|
|
|
} else {
|
|
|
|
return $variables;
|
|
|
|
}
|
|
|
|
}
|
2006-04-26 12:28:53 +00:00
|
|
|
|
2014-01-21 12:57:18 +00:00
|
|
|
/**
|
|
|
|
* Initialize the global $conf array if necessary
|
|
|
|
*
|
|
|
|
* @global $conf the global conf array
|
|
|
|
* @uses variable_init()
|
2014-03-26 10:59:59 +00:00
|
|
|
* @param boolean $force
|
2014-01-21 12:57:18 +00:00
|
|
|
*/
|
|
|
|
function variable_init_maybe($force=false) {
|
|
|
|
global $conf;
|
|
|
|
if ($force || !isset($conf)) {
|
2014-01-31 13:50:15 +00:00
|
|
|
$this->cache_variable_list = false;
|
2014-01-21 12:57:18 +00:00
|
|
|
$conf = $this->variable_init();
|
|
|
|
}
|
|
|
|
}
|
2012-10-18 09:03:26 +00:00
|
|
|
|
2014-01-21 12:57:18 +00:00
|
|
|
/**
|
|
|
|
* Return a persistent variable.
|
|
|
|
*
|
2014-03-26 10:59:59 +00:00
|
|
|
* @param string $name
|
2014-01-21 12:57:18 +00:00
|
|
|
* The name of the variable to return.
|
2014-03-26 10:59:59 +00:00
|
|
|
* @param mixed $default
|
2014-01-21 12:57:18 +00:00
|
|
|
* The default value to use if this variable has never been set.
|
2014-03-26 10:59:59 +00:00
|
|
|
* @param string $createit_comment
|
2014-01-21 12:57:18 +00:00
|
|
|
* If variable doesn't exist, create it with the default value
|
|
|
|
* and createit_comment value as comment
|
2014-03-26 10:59:59 +00:00
|
|
|
* @return mixed
|
2014-01-21 12:57:18 +00:00
|
|
|
* The value of the variable.
|
2014-03-26 10:59:59 +00:00
|
|
|
* @global array $conf
|
2014-01-21 12:57:18 +00:00
|
|
|
* A cache of the configuration.
|
|
|
|
*/
|
2014-01-31 13:50:15 +00:00
|
|
|
function variable_get($name, $default = null, $createit_comment = null, $type=null) {
|
2014-01-21 12:57:18 +00:00
|
|
|
global $conf;
|
|
|
|
|
|
|
|
$this->variable_init_maybe();
|
|
|
|
|
|
|
|
if (isset($conf[$name])) {
|
|
|
|
return $conf[$name]['value'];
|
|
|
|
} elseif (!is_null($createit_comment)) {
|
2014-01-31 13:50:15 +00:00
|
|
|
$this->variable_update_or_create($name, $default, 'DEFAULT', 'null', 'null', $createit_comment, $type);
|
2014-01-21 12:57:18 +00:00
|
|
|
}
|
|
|
|
return $default;
|
2012-10-18 09:03:26 +00:00
|
|
|
}
|
2006-04-26 12:28:53 +00:00
|
|
|
|
2014-03-22 14:47:14 +00:00
|
|
|
/**
|
|
|
|
* Create or update a variable
|
|
|
|
*
|
2014-03-26 10:59:59 +00:00
|
|
|
* @global m_mysql $db
|
|
|
|
* @global m_err $err
|
|
|
|
* @param string $var_name
|
|
|
|
* @param mixed $var_value
|
|
|
|
* @param string $strata
|
|
|
|
* @param int $strata_id
|
|
|
|
* @param int $var_id
|
|
|
|
* @param string $comment
|
|
|
|
* @param string $type
|
2014-03-22 14:47:14 +00:00
|
|
|
* @return boolean
|
|
|
|
*/
|
2014-01-31 13:50:15 +00:00
|
|
|
function variable_update_or_create($var_name, $var_value, $strata=null, $strata_id=null, $var_id=null, $comment=null, $type=null) {
|
2014-01-21 16:25:43 +00:00
|
|
|
global $db, $err;
|
|
|
|
$err->log('variable', 'variable_update_or_create');
|
2014-01-31 09:50:20 +00:00
|
|
|
if ( strtolower($var_id) == 'null' ) $var_id = null;
|
|
|
|
if ( strtolower($strata_id) == 'null' ) $strata_id = null;
|
|
|
|
|
2014-01-31 13:50:15 +00:00
|
|
|
if (is_object($type) || is_array($type)) {
|
|
|
|
$type = serialize($type);
|
|
|
|
}
|
2014-01-31 09:50:20 +00:00
|
|
|
if (is_object($var_value) || is_array($var_value)) {
|
|
|
|
$var_value = serialize($var_value);
|
|
|
|
}
|
2014-01-21 16:25:43 +00:00
|
|
|
|
2014-01-31 09:50:20 +00:00
|
|
|
if ( ! is_null($var_id) ) {
|
2014-01-21 16:25:43 +00:00
|
|
|
$sql="UPDATE variable SET value='".mysql_real_escape_string($var_value)."' WHERE id = ".intval($var_id);
|
|
|
|
} else {
|
|
|
|
if ( empty($strata) ) {
|
|
|
|
$err->raise('variables', _("Err: Missing strata when creating var"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$sql="INSERT INTO
|
2014-01-31 13:50:15 +00:00
|
|
|
variable (name, value, strata, strata_id, comment, type)
|
2014-01-21 16:25:43 +00:00
|
|
|
VALUES (
|
|
|
|
'".mysql_real_escape_string($var_name)."',
|
|
|
|
'".mysql_real_escape_string($var_value)."',
|
|
|
|
'".mysql_real_escape_string($strata)."',
|
2014-01-31 09:50:20 +00:00
|
|
|
".( is_null($strata_id)?'NULL':"'".mysql_real_escape_string($strata_id)."'").",
|
2014-01-31 13:50:15 +00:00
|
|
|
'".mysql_real_escape_string($comment)."',
|
|
|
|
'".mysql_real_escape_string($type)."' );";
|
2014-01-21 16:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$db->query("$sql");
|
|
|
|
|
|
|
|
$this->variable_init_maybe(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-21 12:57:18 +00:00
|
|
|
/**
|
|
|
|
* Unset a persistent variable.
|
2014-03-26 10:59:59 +00:00
|
|
|
*
|
|
|
|
* @global m_mysql $db
|
|
|
|
* @param int $id
|
|
|
|
* @return type
|
2014-01-21 12:57:18 +00:00
|
|
|
*/
|
2014-01-21 16:25:43 +00:00
|
|
|
function del($id) {
|
2014-01-21 12:57:18 +00:00
|
|
|
global $db;
|
2014-03-22 14:47:14 +00:00
|
|
|
$result = $db->query("DELETE FROM `variable` WHERE id = '".intval($id)."'");
|
2014-01-21 12:57:18 +00:00
|
|
|
$this->variable_init_maybe(true);
|
2014-03-22 14:47:14 +00:00
|
|
|
return $result;
|
2014-01-21 12:57:18 +00:00
|
|
|
}
|
2006-04-26 12:28:53 +00:00
|
|
|
|
2014-03-22 14:47:14 +00:00
|
|
|
/**
|
|
|
|
* echo HTML code to display a variable passed in parameters
|
|
|
|
*
|
2014-03-26 10:59:59 +00:00
|
|
|
* @param mixed $v
|
|
|
|
* @param string $varname
|
|
|
|
* @param boolean $echo
|
2014-03-26 13:59:41 +00:00
|
|
|
* @return string
|
2014-03-22 14:47:14 +00:00
|
|
|
*/
|
|
|
|
function display_valueraw_html($v,$varname,$echo = true) {
|
|
|
|
$output = "";
|
2014-03-26 13:47:27 +00:00
|
|
|
$varList = $this->variables_list();
|
2014-01-31 13:50:15 +00:00
|
|
|
if (is_array($v)) {
|
|
|
|
if (empty($v)) {
|
2014-03-22 14:47:14 +00:00
|
|
|
$output .= "<em>"._("Empty array")."</em>";
|
2014-01-31 13:50:15 +00:00
|
|
|
} else {
|
2014-03-22 14:47:14 +00:00
|
|
|
$output .= "<ul>";
|
2014-01-31 13:50:15 +00:00
|
|
|
foreach ( $v as $k=>$l) {
|
2014-03-22 14:47:14 +00:00
|
|
|
$output .= "<li>";
|
2014-01-31 13:50:15 +00:00
|
|
|
if (! is_numeric($k)) {
|
|
|
|
if (is_null($varname)) {
|
2014-03-22 14:47:14 +00:00
|
|
|
$output .= "$k";
|
2014-01-31 13:50:15 +00:00
|
|
|
} else {
|
2014-03-26 13:47:27 +00:00
|
|
|
if ( !isset($varList['DEFAULT'][null][$varname]['type'][$k]) || is_array( $varList['DEFAULT'][null][$varname]['type'][$k] ) ) {
|
|
|
|
if (isset($varList['DEFAULT'][null][$varname]['type'][$k]['desc'])) {
|
|
|
|
$output .= $varList['DEFAULT'][null][$varname]['type'][$k]['desc'];
|
2014-03-20 11:53:32 +00:00
|
|
|
} else {
|
2014-03-22 14:47:14 +00:00
|
|
|
$output .= $k;
|
2014-03-20 11:53:32 +00:00
|
|
|
}
|
2014-01-31 15:21:36 +00:00
|
|
|
} else {
|
2014-03-26 13:47:27 +00:00
|
|
|
$output .= $varList['DEFAULT'][null][$varname]['type'][$k];
|
2014-01-31 15:21:36 +00:00
|
|
|
}
|
2014-01-31 13:50:15 +00:00
|
|
|
}
|
2014-03-20 11:53:32 +00:00
|
|
|
} else {
|
2014-03-26 13:47:27 +00:00
|
|
|
if (isset($varList['DEFAULT'][null][$varname]['type'][$k]['desc'] )) {
|
|
|
|
$output .= $varList['DEFAULT'][null][$varname]['type'][$k]['desc'];
|
2014-03-20 11:53:32 +00:00
|
|
|
}
|
2014-01-31 13:50:15 +00:00
|
|
|
}
|
2014-01-31 15:21:36 +00:00
|
|
|
if (is_array($l)) {
|
2014-03-22 14:47:14 +00:00
|
|
|
$output .= "<ul>";
|
2014-01-31 15:21:36 +00:00
|
|
|
foreach ($l as $m => $n ) {
|
2014-03-22 14:47:14 +00:00
|
|
|
$output .= "<li>";
|
2014-01-31 15:21:36 +00:00
|
|
|
if ( is_numeric($m)) {
|
2014-03-22 14:47:14 +00:00
|
|
|
$output .= "$m";
|
2014-01-31 15:21:36 +00:00
|
|
|
} else {
|
2014-03-26 13:47:27 +00:00
|
|
|
$output .= $varList['DEFAULT'][null][$varname]['type'][$k][$m]['desc'];
|
2014-01-31 15:21:36 +00:00
|
|
|
}
|
2014-03-22 14:47:14 +00:00
|
|
|
$output .= " => $n";
|
|
|
|
$output .= "</li>";
|
2014-01-31 15:21:36 +00:00
|
|
|
}
|
2014-03-22 14:47:14 +00:00
|
|
|
$output .= "</ul>";
|
2014-01-31 15:21:36 +00:00
|
|
|
} else {
|
2014-03-22 14:47:14 +00:00
|
|
|
$output .= " => $l";
|
2014-01-31 15:21:36 +00:00
|
|
|
}
|
2014-03-22 14:47:14 +00:00
|
|
|
$output .= "</li>";
|
2014-01-31 13:50:15 +00:00
|
|
|
}
|
2014-03-22 14:47:14 +00:00
|
|
|
$output .= "</ul>";
|
2014-01-31 13:50:15 +00:00
|
|
|
} // empty $v
|
2014-03-20 11:53:32 +00:00
|
|
|
} else if (empty($v) && $v != '0') {
|
2014-03-22 14:47:14 +00:00
|
|
|
$output .= "<em>"._("Empty")."</em>";
|
2014-01-31 13:50:15 +00:00
|
|
|
} else {
|
2014-03-22 14:47:14 +00:00
|
|
|
$output .= $v;
|
|
|
|
}
|
|
|
|
if( $echo ){
|
|
|
|
echo $output;
|
2014-01-31 13:50:15 +00:00
|
|
|
}
|
2014-03-22 14:47:14 +00:00
|
|
|
return $output;
|
2014-01-31 13:50:15 +00:00
|
|
|
}
|
|
|
|
|
2014-03-22 14:47:14 +00:00
|
|
|
/**
|
|
|
|
* Display a variable if is set
|
|
|
|
*
|
2014-03-26 10:59:59 +00:00
|
|
|
* @param array $tab
|
|
|
|
* @param string $strata
|
|
|
|
* @param int $id
|
|
|
|
* @param string $varname
|
|
|
|
* @param boolean $echo
|
2014-03-22 14:47:14 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function display_value_html($tab, $strata, $id, $varname, $echo = TRUE) {
|
|
|
|
$output = "";
|
2014-01-31 13:50:15 +00:00
|
|
|
if (isset($tab[$strata][$id][$varname]['value'])) {
|
|
|
|
$v = $tab[$strata][$id][$varname]['value'];
|
2014-03-27 09:57:34 +00:00
|
|
|
$output .= $this->display_valueraw_html($v, $varname, false);
|
2014-01-31 13:50:15 +00:00
|
|
|
} else {
|
2014-03-22 14:47:14 +00:00
|
|
|
$output .= "<em>"._("None defined")."</em>";
|
2014-01-31 13:50:15 +00:00
|
|
|
}
|
2014-03-22 14:47:14 +00:00
|
|
|
if( $echo){
|
|
|
|
echo $output;
|
|
|
|
}
|
|
|
|
return $output;
|
2014-01-31 13:50:15 +00:00
|
|
|
}
|
|
|
|
|
2014-03-22 14:47:14 +00:00
|
|
|
/**
|
|
|
|
* return hashtable with variable_name => comment for all the vars
|
|
|
|
*
|
2014-03-26 10:59:59 +00:00
|
|
|
* @global m_mysql $db
|
2014-03-22 14:47:14 +00:00
|
|
|
* @return type
|
|
|
|
*/
|
2014-01-21 12:57:18 +00:00
|
|
|
function variables_list_name() {
|
|
|
|
global $db;
|
|
|
|
|
|
|
|
$result = $db->query('SELECT name, comment FROM `variable` order by name');
|
|
|
|
$t=array();
|
|
|
|
while ($db->next_record($result)) {
|
|
|
|
$tname = $db->f('name');
|
|
|
|
// If not listed of if listed comment is shorter
|
|
|
|
if ( ! isset( $t[$tname] ) || strlen($t[$tname]) < $db->f('comment') ) {
|
|
|
|
$t[$db->f('name')] = $db->f('comment');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $t;
|
|
|
|
}
|
2006-04-26 12:28:53 +00:00
|
|
|
|
2014-03-22 14:47:14 +00:00
|
|
|
/**
|
|
|
|
* return a multidimensionnal array used to build vars
|
|
|
|
*
|
2014-03-26 10:59:59 +00:00
|
|
|
* @global m_mysql $db
|
2014-03-22 14:47:14 +00:00
|
|
|
* @return type
|
|
|
|
*/
|
2014-01-21 12:57:18 +00:00
|
|
|
function variables_list() {
|
|
|
|
global $db;
|
2014-01-31 13:50:15 +00:00
|
|
|
if ( ! $this->cache_variable_list ) {
|
|
|
|
|
|
|
|
$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');
|
|
|
|
}
|
|
|
|
if ( ($type = @unserialize($db->f('type'))) === FALSE) {
|
|
|
|
$type=$db->f('type');
|
|
|
|
}
|
|
|
|
$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'), 'type'=>$type);
|
2014-01-21 12:57:18 +00:00
|
|
|
}
|
2014-01-31 13:50:15 +00:00
|
|
|
$this->cache_variable_list = $arr_var;
|
2014-01-21 12:57:18 +00:00
|
|
|
}
|
2014-01-31 13:50:15 +00:00
|
|
|
|
|
|
|
return $this->cache_variable_list;
|
2012-08-22 16:47:18 +00:00
|
|
|
}
|
|
|
|
|
2014-01-20 13:44:25 +00:00
|
|
|
} /* Class m_variables */
|