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~b.php -text
|
||||
install/upgrades/3.2.1~a.sql -text
|
||||
install/upgrades/3.3.0~a.sql -text
|
||||
install/upgrades/README -text
|
||||
lang/.svnignore -text
|
||||
lang/README -text
|
||||
|
|
|
@ -33,6 +33,11 @@ if (!$admin->enabled) {
|
|||
__("This page is restricted to authorized staff");
|
||||
exit();
|
||||
}
|
||||
$fields = array (
|
||||
"member_id" => array ("post", "integer", null),
|
||||
"fqdn_id" => array ("post", "integer", null),
|
||||
);
|
||||
getFields($fields);
|
||||
|
||||
$conf = $variables->variable_init();
|
||||
foreach ($conf as $name => $val) {
|
||||
|
@ -54,18 +59,93 @@ include_once ("head.php");
|
|||
|
||||
<form method="post" action="adm_variables.php">
|
||||
<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
|
||||
|
||||
foreach( $variables->variables_list() as $vars) { ?>
|
||||
$allvars = $variables->variables_list();
|
||||
foreach( $variables->variables_list_name() as $varname => $varcomment) { ?>
|
||||
|
||||
<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><?php echo $vars['comment']; ?></td>
|
||||
-->
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</table>
|
||||
<!--
|
||||
<p><input type="submit" class="inb" value="<?php __("Save variables"); ?>" /></p>
|
||||
-->
|
||||
</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"); ?>
|
||||
|
|
|
@ -348,7 +348,7 @@ class m_admin {
|
|||
|
||||
if ($db->num_rows()) {
|
||||
while ($db->next_record()) {
|
||||
$c[]=$this->get($db->f("uid"));
|
||||
$c[$db->f("uid")]=$this->get($db->f("uid"));
|
||||
}
|
||||
return $c;
|
||||
} 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)');
|
||||
}
|
||||
|
||||
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() {
|
||||
global $quota;
|
||||
$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,6 +34,17 @@
|
|||
*/
|
||||
|
||||
class m_variables {
|
||||
var $strata_order = array('DEFAULT','GLOBAL','FQDN_CREATOR','FQDN','CREATOR','MEMBER','DOMAIN');
|
||||
|
||||
// used by get_impersonated to merge array. Son value overwrite father's value
|
||||
private function variable_merge($father, $son) {
|
||||
if (! is_array($son)) return $father;
|
||||
foreach ($son as $k=>$v) {
|
||||
$father[$k] = $v;
|
||||
}
|
||||
return $father;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the persistent variable table.
|
||||
*
|
||||
|
@ -41,23 +52,75 @@ class m_variables {
|
|||
* with variable_set() as well as those explicitly specified in the configuration
|
||||
* file.
|
||||
*/
|
||||
function variable_init($conf = array()) {
|
||||
global $db;
|
||||
$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;
|
||||
if (($variables[$variable['name']] = @unserialize($variable['value'])) === FALSE) {
|
||||
$variables[$variable['name']] = $variable['value'];
|
||||
function variable_init() {
|
||||
global $cuid;
|
||||
if ($cuid > 1999) {
|
||||
$mid = $cuid;
|
||||
} else {
|
||||
$mid = null;
|
||||
}
|
||||
return $this->get_impersonated($_SERVER['HTTP_HOST'], $mid);
|
||||
}
|
||||
|
||||
foreach ($conf as $name => $value) {
|
||||
$variables[$name] = $value;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the global $conf array if necessary
|
||||
|
@ -65,9 +128,9 @@ function variable_init($conf = array()) {
|
|||
* @global $conf the global conf array
|
||||
* @uses variable_init()
|
||||
*/
|
||||
function variable_init_maybe() {
|
||||
function variable_init_maybe($force=false) {
|
||||
global $conf;
|
||||
if (!isset($conf)) {
|
||||
if ($force || !isset($conf)) {
|
||||
$conf = $this->variable_init();
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +157,7 @@ function variable_get($name, $default = null, $createit_comment = null) {
|
|||
$this->variable_init_maybe();
|
||||
|
||||
if (isset($conf[$name])) {
|
||||
return $conf[$name];
|
||||
return $conf[$name]['value'];
|
||||
} elseif (!is_null($createit_comment)) {
|
||||
$this->variable_set($name, $default, $createit_comment);
|
||||
}
|
||||
|
@ -128,7 +191,8 @@ function variable_set($name, $value, $comment=null) {
|
|||
$query = "INSERT INTO variable (name, value, comment) values ('".$name."', '".$value."', '$comment') on duplicate key update name='$name', value='$value', comment='$comment';";
|
||||
}
|
||||
|
||||
$db->query("$query");
|
||||
# $db->query("$query");
|
||||
printvar($query);
|
||||
|
||||
$this->variable_init();
|
||||
}
|
||||
|
@ -139,24 +203,43 @@ function variable_set($name, $value, $comment=null) {
|
|||
* @param $name
|
||||
* The name of the variable to undefine.
|
||||
*/
|
||||
function variable_del($name) {
|
||||
global $conf, $db;
|
||||
$name=str_replace('.', '_', $name); // Php can't handle POST var with a '.'
|
||||
|
||||
$db->query("DELETE FROM `variable` WHERE name = '".$name."'");
|
||||
|
||||
unset($conf[$name]);
|
||||
function variable_del($id) {
|
||||
global $db;
|
||||
$db->query("DELETE FROM `variable` WHERE id = '".intval($id)."'");
|
||||
$this->variable_init_maybe(true);
|
||||
}
|
||||
|
||||
function variables_list() {
|
||||
function variables_list_name() {
|
||||
global $db;
|
||||
|
||||
$result = $db->query('SELECT name, comment FROM `variable` order by name');
|
||||
$t=array();
|
||||
$db->query("SELECT * FROM `variable` WHERE `comment` IS NOT NULL ORDER BY `name`");
|
||||
while ($db->next_record()) {
|
||||
$t[]=$db->Record;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
} /* 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