AlternC/bureau/admin/adm_var_edit.php

342 lines
11 KiB
PHP
Raw Normal View History

2014-01-21 16:25:43 +00:00
<?php
require_once("../class/config.php");
include_once("head.php");
/*
Cette page est immonde.
Celui qui veux la refaire est courageux.
*/
$fields = array (
"var" => array ("get", "string", null),
"var_id" => array ("post", "integer", null),
"var_value" => array ("post", "string", null),
"var_value_arr" => array ("post", "array", null),
2014-01-21 16:25:43 +00:00
"var_name" => array ("post", "string", null),
"strata" => array ("post", "string", null),
"strata_id" => array ("post", "integer", null),
"delete" => array ("post", "boolean", false),
);
getFields($fields);
2014-01-31 18:12:34 +00:00
/* * /
// Variable pour test
variable_get("aaa_test3",
2014-01-31 17:46:09 +00:00
array(
"ns1"=>
array(
"ns"=>"ns1.%%FQDN%%",
"ip"=>"%%PUBLIC_IP%%",
"enabled"=>"%%ENABLED%%"),
"ns2"=>
array(
"ns"=>"fdsffsd",
"ip"=>"fdsfdfds",
"enabled"=>"fds"),
'ns55'=> 'arf'
),
"This is a test!",
2014-01-31 17:46:09 +00:00
array(
"ns1"=>
array(
"ns"=>
array(
'desc'=>"ns name",
'type'=>'string'),
"ip"=>
array(
'desc'=>"ip address",
'type'=>'ip'),
"enabled"=>
array(
'desc'=>"enabled",
'type'=>"boolean"),
),
"ns2"=>array(
"ns"=>
array(
'desc'=>"ns name",
'type'=>'string'),
"ip"=>
array(
'desc'=>"ip address",
'type'=>'ip'),
"enabled"=>
array(
'desc'=>"enabled",
'type'=>"boolean"),
),
"ns3"=>array(
"desc"=>"here another",
"type"=>"integer",
),
)
2014-01-31 18:12:34 +00:00
);
/* */
2014-01-31 17:46:09 +00:00
2014-01-21 16:25:43 +00:00
if (empty($var)) {
echo "<p class='error'>";__("Missing var name");echo "</p>";
include_once("foot.php");
2014-03-26 11:22:32 +00:00
die();
2014-01-21 16:25:43 +00:00
}
// Which one between var_value and var_value_arr ?
$var_v = null;
if (!is_null($var_value)) $var_v = $var_value;
if (!is_null($var_value_arr)) $var_v = $var_value_arr;
2014-01-21 16:25:43 +00:00
if ( $var_id && $delete ) {
$variables->del($var_id);
} else if ( $strata && $var_name && $var_v ) {
$variables->variable_update_or_create($var_name, $var_v, $strata, $strata_id);
} else if ( $var_id && $var_v ) {
$variables->variable_update_or_create($var_name, $var_v, null, null, $var_id);
2014-01-21 16:25:43 +00:00
}
echo "<h3>";echo sprintf(_("Edition of var %s"), $var); echo "</h3>";
$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'];
}
$variablesList = $variables->variables_list_name();
2014-01-21 16:25:43 +00:00
echo "<fieldset><legend>"._("Description")."</legend>";
echo "<p>".$variablesList[$var]."</p>";
2014-01-21 16:25:43 +00:00
echo "</fieldset>";
echo "<br/>";
2014-01-31 17:46:09 +00:00
function var_input($infotype, $name, $value='') {
$id = rand();
echo "<label for='add_$id'>".$infotype['desc']."</label>";
switch(strtolower($infotype['type'])) {
case "string":
2014-01-31 17:49:20 +00:00
echo "<input type='text' class='int' id='add_$id' name='$name' value='";ehe($value); echo "' size='30' />&nbsp;";
echo "<em>"._("Value expected: string")."</em>";
2014-01-31 17:46:09 +00:00
break;
case "integer":
2014-01-31 17:49:20 +00:00
echo "<input type='text' class='int' id='add_$id' name='$name' value='";ehe($value); echo "' size='10' pattern='[0-9]+'/>&nbsp;";
echo "<em>"._("Value expected: integer")."</em>";
2014-01-31 17:46:09 +00:00
break;
case "ip":
2014-01-31 17:49:20 +00:00
echo "<input type='text' class='int' id='add_$id' name='$name' value='";ehe($value); echo "' size='15' pattern='[0-9\.:]+' />&nbsp;";
echo "<em>"._("Value expected: IP address")."</em>";
2014-01-31 17:46:09 +00:00
break;
case "boolean":
echo "<input type='hidden' name='$name' value='0' />"; // This way, there is allways something send, even if checkbox is unchecked
2014-03-27 13:50:44 +00:00
echo "<input type='checkbox' id='add_$id' name='$name' value='1' ";cbox((bool)$value);echo " />";
2014-01-31 17:46:09 +00:00
break;
default:
echo "WTF ? Dunno what to do with a ".$infotype['type'];
break;
}
}
2014-01-21 16:25:43 +00:00
function edit_var($var_arr) {
global $allvars;
2014-01-21 16:25:43 +00:00
echo "<div id='edit_var_div_{$var_arr['id']}'><form method=post>";
echo "<input type='hidden' name='var_id' value='";ehe($var_arr['id']);echo "' />";
2014-03-28 11:37:36 +00:00
$infotype = $allvars['DEFAULT'][null][$var_arr['name']]['type'];
if (is_array( $infotype ) && ( isset($infotype['type']) && isset($infotype['desc']))) {
var_input($infotype, "var_value", $var_arr['value']);
} else if (is_array( $infotype )) {
echo "<ul>";
2014-01-31 17:46:09 +00:00
//foreach ($allvars['DEFAULT'][null][$var_arr['name']]['type'] as $kk => $vv) {
foreach ($var_arr['value'] as $kk => $vv) {
echo "<li>";
if ( is_array($vv)) {
echo $kk;
echo "<ul>";
foreach ($vv as $ll => $mm ) {
echo "<li>";
2014-01-31 17:46:09 +00:00
var_input($infotype[$kk][$ll], "var_value_arr[$kk][$ll]", $var_arr['value'][$kk][$ll] );
echo "</li>";
}
echo "</ul>";
} else {
2014-01-31 17:46:09 +00:00
var_input($infotype[$kk], "var_value_arr[$kk]", $var_arr['value'][$kk]);
}
echo "</li>";
}
echo "</ul>";
} else {
echo "<input type='text' class='int' name='var_value' value='";ehe($var_arr['value']); echo "' size='30' />";
}
2014-01-21 16:25:43 +00:00
echo "<br/>";
echo "<input type='button' class='inb cancel' name='cancel' value='"._('Cancel')."' onclick=\"$('#edit_var_div_{$var_arr['id']}').toggle();\" />";
echo "<input type='submit' class='inb ok' value='"._("Apply")."'/>";
2014-01-31 17:46:09 +00:00
echo "<input type='submit' class='inb delete' name='delete' value='"._("Delete")."' onclick=\"return confirm('"; ehe(_("Are you sure you want to delete it.")); echo "')\" />";
2014-01-21 16:25:43 +00:00
echo "</form></div>";
echo "<script type='text/javascript'>$('#edit_var_div_{$var_arr['id']}').toggle();</script>";
}
function add_var($stratatata, $stratatata_arr=null) {
global $var, $allvars;
2014-01-21 16:25:43 +00:00
echo "<div id='add_var_div_$stratatata'><form method=post>";
echo "<input type='hidden' name='strata' value='";ehe($stratatata);echo "' />";
echo "<input type='hidden' name='var_name' value='";ehe($var);echo "' />";
if (is_array($stratatata_arr)) {
echo "<select name='strata_id'>";
eoption($stratatata_arr, null);
echo "</select> ";
}
2014-01-31 17:46:09 +00:00
$infotype = $allvars['DEFAULT'][null][$var]['type'];
2014-03-28 11:37:36 +00:00
if (is_array( $infotype ) && (isset($infotype['desc']) && isset($infotype['type'])) ) {
var_input($infotype, "var_value");
} else if (is_array( $infotype ) && ! (isset($infotype['desc']) && isset($infotype['type'])) ) {
echo "<ul>";
foreach ($allvars['DEFAULT'][null][$var]['type'] as $kk => $vv) {
echo "<li>";
2014-01-31 17:46:09 +00:00
if ( is_array($vv) && ! (isset($vv['desc']) && isset($vv['type'])) ) { // if is an array but not the last array, used to contain DESC and TYPE
echo $kk;
echo "<ul>";
foreach ($vv as $ll => $mm ) {
echo "<li>";
2014-01-31 17:46:09 +00:00
var_input($infotype[$kk][$ll], "var_value_arr[$kk][$ll]" );
echo "</li>";
}
echo "</ul>";
} else {
2014-01-31 17:46:09 +00:00
var_input($infotype[$kk], "var_value_arr[$kk]" );
}
echo "</li>";
}
echo "</ul>";
} else {
echo "<input type='text' class='int' name='var_value' value='' size='30' />";
}
2014-01-21 16:25:43 +00:00
echo "<br/>";
echo "<input type='button' class='inb cancel' name='cancel' value='"._('Cancel')."' onclick=\"$('#add_var_div_$stratatata').toggle();\" />";
echo "<input type='submit' class='inb ok' value='"._("Apply")."'/>";
echo "</form></div>";
echo "<script type='text/javascript'>$('#add_var_div_$stratatata').toggle();</script>";
}
echo "<table class='tlist'>";
foreach ( $variables->strata_order as $strata) {
echo "<tr class='lst'>";
echo "<td>"; __($strata); echo "</td>";
switch($strata) {
case 'DEFAULT':
echo "<td>"; $variables->display_value_html($allvars, 'DEFAULT', null, $var); echo "</td>";
2014-01-21 16:25:43 +00:00
break;
case 'GLOBAL':
echo "<td>";
if ( isset($allvars['GLOBAL'][null][$var]) && is_array($allvars['GLOBAL'][null][$var])){
echo "<a href='javascript:edit_var(".$allvars['GLOBAL'][null][$var]['id'].");'>"; $variables->display_value_html($allvars, 'GLOBAL', null, $var); echo "</a>";
2014-01-21 16:25:43 +00:00
edit_var($allvars['GLOBAL'][null][$var]);
} else {
echo "<a href='javascript:add_var(\"$strata\");'>"._("Add")."</a>";
add_var($strata);
}
echo "</td>";
break;
case 'FQDN_CREATOR':
echo "<td>";
2014-01-21 17:24:27 +00:00
if (isset($allvars['FQDN_CREATOR']) && is_array($allvars['FQDN_CREATOR'])) {
foreach ($allvars['FQDN_CREATOR'] as $ttk => $ttv ) {
if ( isset($ttv[$var]) && is_array( $ttv[$var])) {
echo sprintf(_("Overwritted by %s"), $members[$ttk]['login'])." &rarr; ";
2014-03-27 10:03:48 +00:00
echo "<a href='javascript:edit_var(".$ttv[$var]['id'].");'>"; $variables->display_valueraw_html($ttv[$var]['value'], $var);echo "</a>";
2014-01-21 17:24:27 +00:00
edit_var($ttv[$var]);
}
echo "<br/>";
2014-01-21 16:25:43 +00:00
}
2014-01-21 17:24:27 +00:00
} // isset
2014-01-21 16:25:43 +00:00
echo "<a href='javascript:add_var(\"$strata\");'>"._("Add")."</a>";
add_var($strata, $members_list);
echo "</td>";
break;
case 'FQDN':
echo "<td>";
2014-01-21 17:24:27 +00:00
if ( isset($allvars['FQDN']) && is_array($allvars['FQDN'])) {
foreach ($allvars['FQDN'] as $ttk => $ttv ) {
if ( isset($ttv[$var]) && is_array( $ttv[$var])) {
echo sprintf(_("Overwritted by %s"), $panel_url[$ttk])." &rarr; ";
2014-03-27 10:03:48 +00:00
echo "<a href='javascript:edit_var(".$ttv[$var]['id'].");'>"; $variables->display_valueraw_html($ttv[$var]['value'], $var);echo "</a>";
2014-01-21 17:24:27 +00:00
edit_var($ttv[$var]);
}
echo "<br/>";
2014-01-21 16:25:43 +00:00
}
2014-01-21 17:24:27 +00:00
} //isset
2014-01-21 16:25:43 +00:00
echo "<a href='javascript:add_var(\"$strata\");'>"._("Add")."</a>";
add_var($strata, $panel_url);
echo "</td>";
break;
case 'CREATOR':
echo "<td>";
2014-01-21 17:24:27 +00:00
if (isset($allvars['CREATOR']) && is_array($allvars['CREATOR'])) {
foreach ($allvars['CREATOR'] as $ttk => $ttv ) {
if ( isset($ttv[$var]) && is_array( $ttv[$var])) {
echo sprintf(_("Overwritted by %s"), $members[$ttk]['login'])." &rarr; ";
2014-03-27 10:03:48 +00:00
echo "<a href='javascript:edit_var(".$ttv[$var]['id'].");'>"; $variables->display_valueraw_html($ttv[$var]['value'], $var);echo "</a>";
2014-01-21 17:24:27 +00:00
edit_var($ttv[$var]);
}
echo "<br/>";
2014-01-21 16:25:43 +00:00
}
2014-01-21 17:24:27 +00:00
} //isset
2014-01-21 16:25:43 +00:00
echo "<a href='javascript:add_var(\"$strata\");'>"._("Add")."</a>";
add_var($strata, $creators_list );
echo "</td>";
break;
case 'MEMBER':
echo "<td>";
2014-01-21 17:24:27 +00:00
if (isset($allvars['MEMBER']) && is_array($allvars['MEMBER'])) {
foreach ($allvars['MEMBER'] as $ttk => $ttv ) {
if ( isset($ttv[$var]) && is_array( $ttv[$var])) {
echo sprintf(_("Overwritted by %s"), $members[$ttk]['login'])." &rarr; ";
2014-03-27 10:03:48 +00:00
echo "<a href='javascript:edit_var(".$ttv[$var]['id'].");'>"; $variables->display_valueraw_html($ttv[$var]['value'], $var);echo "</a>";
2014-01-21 17:24:27 +00:00
edit_var($ttv[$var]);
}
echo "<br/>";
2014-01-21 16:25:43 +00:00
}
2014-01-21 17:24:27 +00:00
} //isset
2014-01-21 16:25:43 +00:00
echo "<a href='javascript:add_var(\"$strata\");'>"._("Add")."</a>";
add_var($strata, $members_list);
echo "</td>";
break;
case 'DOMAIN':
//FIXME TODO
echo "<td>Todo.</td>";
break;
} //switch
echo "</tr>";
} //foreach
echo "</table>";
?>
<p><span class="ina back"><a href="adm_variables.php"><?php __("Back to the var list"); ?></a></span></p>
<script type="text/javascript">
function edit_var(id) {
$('#edit_var_div_'+id).toggle();
}
function add_var(st) {
$('#add_var_div_'+st).toggle();
}
</script>
<?php
include_once("foot.php");
?>