From 53eabe7596877bf737864cc7b336af29faa37aa3 Mon Sep 17 00:00:00 2001 From: Alan Garcia Date: Tue, 21 Jan 2014 16:25:43 +0000 Subject: [PATCH] Page pour editer les variables --- .gitattributes | 2 +- bureau/admin/adm_editvar.php | 1 - bureau/admin/adm_var_edit.php | 191 +++++++++++++++++++++++++++++++++ bureau/admin/adm_variables.php | 6 +- bureau/class/m_variables.php | 30 +++++- 5 files changed, 222 insertions(+), 8 deletions(-) delete mode 100644 bureau/admin/adm_editvar.php create mode 100644 bureau/admin/adm_var_edit.php diff --git a/.gitattributes b/.gitattributes index 07a640ae..9b976ee2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -68,7 +68,6 @@ bureau/admin/adm_donosu.php -text bureau/admin/adm_dorenew.php -text bureau/admin/adm_dosu.php -text bureau/admin/adm_edit.php -text -bureau/admin/adm_editvar.php -text bureau/admin/adm_email.php -text bureau/admin/adm_list.php -text bureau/admin/adm_lockpanel.php -text @@ -85,6 +84,7 @@ bureau/admin/adm_tlddoadd.php -text bureau/admin/adm_tlddoedit.php -text bureau/admin/adm_tldedit.php -text bureau/admin/adm_update_domains.php -text +bureau/admin/adm_var_edit.php -text bureau/admin/adm_variables.php -text bureau/admin/aide/help.php -text bureau/admin/aide/help.png -text diff --git a/bureau/admin/adm_editvar.php b/bureau/admin/adm_editvar.php deleted file mode 100644 index 1333ed77..00000000 --- a/bureau/admin/adm_editvar.php +++ /dev/null @@ -1 +0,0 @@ -TODO diff --git a/bureau/admin/adm_var_edit.php b/bureau/admin/adm_var_edit.php new file mode 100644 index 00000000..a5179c28 --- /dev/null +++ b/bureau/admin/adm_var_edit.php @@ -0,0 +1,191 @@ + array ("get", "string", null), + "var_id" => array ("post", "integer", null), + "var_value" => array ("post", "string", null), + "var_name" => array ("post", "string", null), + "strata" => array ("post", "string", null), + "strata_id" => array ("post", "integer", null), + "delete" => array ("post", "boolean", false), +); +getFields($fields); + +if (empty($var)) { + echo "

";__("Missing var name");echo "

"; + include_once("foot.php"); +} + +if ( $var_id && $delete ) { + $variables->del($var_id); +} else if ( $strata && $var_name && $var_value ) { + $variables->variable_update_or_create($var_name, $var_value, $strata, $strata_id); +} else if ( $var_id && $var_value ) { + $variables->variable_update_or_create($var_name, $var_value, null, null, $var_id); +} + +echo "

";echo sprintf(_("Edition of var %s"), $var); echo "

"; + +$members = $admin->get_list(); +$panel_url = $fqdn=$dom->get_panel_url_list(); + +$allvars = $variables->variables_list(); + +$members_list=array(); +foreach($admin->get_list() as $mid=>$mlogin) { + $members_list[$mid] = $mlogin['login']; +} + +$creators_list=array(); +foreach($admin->get_creator_list() as $mid=>$mlogin) { + $creators_list[$mid] = $mlogin['login']; +} + +echo "
"._("Description").""; +echo "

".$variables->variables_list_name()[$var]."

"; +echo "
"; + +echo "
"; + +function edit_var($var_arr) { + echo "
"; + echo ""; + echo ""; + echo "
"; + echo ""; + echo ""; + echo ""; + echo "
"; + echo ""; + +} + +function add_var($stratatata, $stratatata_arr=null) { + global $var; + echo "
"; + echo ""; + echo ""; + if (is_array($stratatata_arr)) { + echo " "; + } + echo ""; + echo "
"; + echo ""; + echo ""; + echo "
"; + echo ""; + +} + +echo ""; + +foreach ( $variables->strata_order as $strata) { + echo ""; + echo ""; + switch($strata) { + case 'DEFAULT': + echo ""; + break; + case 'GLOBAL': + echo ""; + break; + case 'FQDN_CREATOR': + echo ""; + break; + case 'FQDN': + echo ""; + break; + case 'CREATOR': + echo ""; + break; + case 'MEMBER': + echo ""; + break; + case 'DOMAIN': + //FIXME TODO + echo ""; + break; + } //switch + + echo ""; +} //foreach +echo "
"; __($strata); echo "".$allvars['DEFAULT'][null][$var]['value'].""; + if ( isset($allvars['GLOBAL'][null][$var]) && is_array($allvars['GLOBAL'][null][$var])){ + echo "".$allvars['GLOBAL'][null][$var]['value'].""; + edit_var($allvars['GLOBAL'][null][$var]); + } else { + echo ""._("Add").""; + add_var($strata); + } + echo ""; + foreach ($allvars['FQDN_CREATOR'] as $ttk => $ttv ) { + if ( isset($ttv[$var]) && is_array( $ttv[$var])) { + echo sprintf(_("Overwritted by %s"), $members[$ttk]['login'])." → "; + echo "".$ttv[$var]['value'].""; + edit_var($ttv[$var]); + } + echo "
"; + } + echo ""._("Add").""; + add_var($strata, $members_list); + echo "
"; + foreach ($allvars['FQDN'] as $ttk => $ttv ) { + if ( isset($ttv[$var]) && is_array( $ttv[$var])) { + echo sprintf(_("Overwritted by %s"), $panel_url[$ttk])." → "; + echo "".$ttv[$var]['value'].""; + edit_var($ttv[$var]); + } + echo "
"; + } + echo ""._("Add").""; + add_var($strata, $panel_url); + echo "
"; + foreach ($allvars['CREATOR'] as $ttk => $ttv ) { + if ( isset($ttv[$var]) && is_array( $ttv[$var])) { + echo sprintf(_("Overwritted by %s"), $members[$ttk]['login'])." → "; + echo "".$ttv[$var]['value'].""; + edit_var($ttv[$var]); + } + echo "
"; + } + echo ""._("Add").""; + add_var($strata, $creators_list ); + echo "
"; + foreach ($allvars['MEMBER'] as $ttk => $ttv ) { + if ( isset($ttv[$var]) && is_array( $ttv[$var])) { + echo sprintf(_("Overwritted by %s"), $members[$ttk]['login'])." → "; + echo "".$ttv[$var]['value'].""; + edit_var($ttv[$var]); + } + echo "
"; + } + echo ""._("Add").""; + add_var($strata, $members_list); + echo "
Todo.
"; + +?> + +

+ + + diff --git a/bureau/admin/adm_variables.php b/bureau/admin/adm_variables.php index fc2e077a..8b7ee88b 100644 --- a/bureau/admin/adm_variables.php +++ b/bureau/admin/adm_variables.php @@ -67,12 +67,11 @@ $global_conf=$variables->get_impersonated(); foreach( $variables->variables_list_name() as $varname => $varcomment) { ?> - + - @@ -118,7 +117,7 @@ echo ""._("Used value").""; echo ""; foreach( $variables->variables_list_name() as $varname => $varcomment) { ?> - + @@ -127,7 +126,6 @@ foreach( $variables->variables_list_name() as $varname => $varcomment) { ?> - variable_merge($variables, $arr_var['MEMBER'][$uid] ); } break; - case 'MEMBER': + case 'DOMAIN': //FIXME TODO break; } //switch @@ -202,13 +202,39 @@ class m_variables { $this->variable_init(); } + function variable_update_or_create($var_name, $var_value, $strata=null, $strata_id=null, $var_id=null) { + global $db, $err; + $err->log('variable', 'variable_update_or_create'); + + if ($var_id) { + $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 + variable (name, value, strata, strata_id) + VALUES ( + '".mysql_real_escape_string($var_name)."', + '".mysql_real_escape_string($var_value)."', + '".mysql_real_escape_string($strata)."', + '".mysql_real_escape_string($strata_id)."' );"; + } + + $db->query("$sql"); + + $this->variable_init_maybe(true); + return true; + } + /** * Unset a persistent variable. * * @param $name * The name of the variable to undefine. */ - function variable_del($id) { + function del($id) { global $db; $db->query("DELETE FROM `variable` WHERE id = '".intval($id)."'"); $this->variable_init_maybe(true);