Alternc  3.2
Alternc logiel libre pour l'h├ębergement
 All Data Structures Namespaces Files Functions Variables Pages
adm_var_edit.php
Go to the documentation of this file.
1 <?php
2 require_once("../class/config.php");
3 include_once("head.php");
4 /*
5 
6 Cette page est immonde.
7 
8 Celui qui veux la refaire est courageux.
9 
10 */
11 
12 $fields = array (
13  "var" => array ("get", "string", null),
14  "var_id" => array ("post", "integer", null),
15  "var_value" => array ("post", "string", null),
16  "var_value_arr" => array ("post", "array", null),
17  "var_name" => array ("post", "string", null),
18  "strata" => array ("post", "string", null),
19  "strata_id" => array ("post", "integer", null),
20  "delete" => array ("post", "boolean", false),
21 );
23 
24 /* * /
25 // Variable pour test
26 variable_get("aaa_test3",
27 array(
28  "ns1"=>
29  array(
30  "ns"=>"ns1.%%FQDN%%",
31  "ip"=>"%%PUBLIC_IP%%",
32  "enabled"=>"%%ENABLED%%"),
33  "ns2"=>
34  array(
35  "ns"=>"fdsffsd",
36  "ip"=>"fdsfdfds",
37  "enabled"=>"fds"),
38  'ns55'=> 'arf'
39 ),
40 "This is a test!",
41 array(
42  "ns1"=>
43  array(
44  "ns"=>
45  array(
46  'desc'=>"ns name",
47  'type'=>'string'),
48  "ip"=>
49  array(
50  'desc'=>"ip address",
51  'type'=>'ip'),
52  "enabled"=>
53  array(
54  'desc'=>"enabled",
55  'type'=>"boolean"),
56  ),
57  "ns2"=>array(
58  "ns"=>
59  array(
60  'desc'=>"ns name",
61  'type'=>'string'),
62  "ip"=>
63  array(
64  'desc'=>"ip address",
65  'type'=>'ip'),
66  "enabled"=>
67  array(
68  'desc'=>"enabled",
69  'type'=>"boolean"),
70  ),
71  "ns3"=>array(
72  "desc"=>"here another",
73  "type"=>"integer",
74  ),
75 )
76 );
77 /* */
78 
79 
80 if (empty($var)) {
81  echo "<p class='error'>";__("Missing var name");echo "</p>";
82  include_once("foot.php");
83 }
84 
85 // Which one between var_value and var_value_arr ?
86 $var_v = null;
87 if (!is_null($var_value)) $var_v = $var_value;
88 if (!is_null($var_value_arr)) $var_v = $var_value_arr;
89 
90 
91 if ( $var_id && $delete ) {
92  $variables->del($var_id);
93 } else if ( $strata && $var_name && $var_v ) {
94  $variables->variable_update_or_create($var_name, $var_v, $strata, $strata_id);
95 } else if ( $var_id && $var_v ) {
96  $variables->variable_update_or_create($var_name, $var_v, null, null, $var_id);
97 }
98 
99 echo "<h3>";echo sprintf(_("Edition of var %s"), $var); echo "</h3>";
100 
101 $members = $admin->get_list();
102 $panel_url = $fqdn=$dom->get_panel_url_list();
103 
104 $allvars = $variables->variables_list();
105 
107 foreach($admin->get_list() as $mid=>$mlogin) {
108  $members_list[$mid] = $mlogin['login'];
109 }
110 
112 foreach($admin->get_creator_list() as $mid=>$mlogin) {
113  $creators_list[$mid] = $mlogin['login'];
114 }
115 
116 echo "<fieldset><legend>"._("Description")."</legend>";
117 echo "<p>".$variables->variables_list_name()[$var]."</p>";
118 echo "</fieldset>";
119 
120 echo "<br/>";
121 
122 function var_input($infotype, $name, $value='') {
123  $id = rand();
124  echo "<label for='add_$id'>".$infotype['desc']."</label>";
125  switch(strtolower($infotype['type'])) {
126  case "string":
127  echo "<input type='text' class='int' id='add_$id' name='$name' value='";ehe($value); echo "' size='30' />&nbsp;";
128  echo "<em>"._("Value expected: string")."</em>";
129  break;
130  case "integer":
131  echo "<input type='text' class='int' id='add_$id' name='$name' value='";ehe($value); echo "' size='10' pattern='[0-9]+'/>&nbsp;";
132  echo "<em>"._("Value expected: integer")."</em>";
133  break;
134  case "ip":
135  echo "<input type='text' class='int' id='add_$id' name='$name' value='";ehe($value); echo "' size='15' pattern='[0-9\.:]+' />&nbsp;";
136  echo "<em>"._("Value expected: IP address")."</em>";
137  break;
138  case "boolean":
139  echo "<input type='hidden' name='$name' value='0' />"; // This way, there is allways something send, even if checkbox is unchecked
140  echo "<input type='checkbox' id='add_$id' name='$name' value='1' ";cbox($value);echo " />";
141  break;
142  default:
143  echo "WTF ? Dunno what to do with a ".$infotype['type'];
144  break;
145  }
146 }
147 
148 function edit_var($var_arr) {
149  global $allvars;
150  echo "<div id='edit_var_div_{$var_arr['id']}'><form method=post>";
151  echo "<input type='hidden' name='var_id' value='";ehe($var_arr['id']);echo "' />";
152  if (is_array( $allvars['DEFAULT'][null][$var_arr['name']]['type'] )) {
153  echo "<ul>";
154  $infotype = $allvars['DEFAULT'][null][$var_arr['name']]['type'];
155  //foreach ($allvars['DEFAULT'][null][$var_arr['name']]['type'] as $kk => $vv) {
156  foreach ($var_arr['value'] as $kk => $vv) {
157  echo "<li>";
158  if ( is_array($vv)) {
159  echo $kk;
160  echo "<ul>";
161  foreach ($vv as $ll => $mm ) {
162  echo "<li>";
163  var_input($infotype[$kk][$ll], "var_value_arr[$kk][$ll]", $var_arr['value'][$kk][$ll] );
164  echo "</li>";
165  }
166  echo "</ul>";
167  } else {
168  var_input($infotype[$kk], "var_value_arr[$kk]", $var_arr['value'][$kk]);
169  }
170  echo "</li>";
171  }
172  echo "</ul>";
173  } else {
174  echo "<input type='text' class='int' name='var_value' value='";ehe($var_arr['value']); echo "' size='30' />";
175  }
176 
177  echo "<br/>";
178  echo "<input type='button' class='inb cancel' name='cancel' value='"._('Cancel')."' onclick=\"$('#edit_var_div_{$var_arr['id']}').toggle();\" />";
179  echo "<input type='submit' class='inb ok' value='"._("Apply")."'/>";
180  echo "<input type='submit' class='inb delete' name='delete' value='"._("Delete")."' onclick=\"return confirm('"; ehe(_("Are you sure you want to delete it.")); echo "')\" />";
181  echo "</form></div>";
182  echo "<script type='text/javascript'>$('#edit_var_div_{$var_arr['id']}').toggle();</script>";
183 
184 }
185 
186 function add_var($stratatata, $stratatata_arr=null) {
187  global $var, $allvars;
188  echo "<div id='add_var_div_$stratatata'><form method=post>";
189  echo "<input type='hidden' name='strata' value='";ehe($stratatata);echo "' />";
190  echo "<input type='hidden' name='var_name' value='";ehe($var);echo "' />";
191  if (is_array($stratatata_arr)) {
192  echo "<select name='strata_id'>";
193  eoption($stratatata_arr, null);
194  echo "</select> ";
195  }
196  $infotype = $allvars['DEFAULT'][null][$var]['type'];
197  if (is_array( $infotype )) {
198  echo "<ul>";
199  foreach ($allvars['DEFAULT'][null][$var]['type'] as $kk => $vv) {
200  echo "<li>";
201  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
202  echo $kk;
203  echo "<ul>";
204  foreach ($vv as $ll => $mm ) {
205  echo "<li>";
206  var_input($infotype[$kk][$ll], "var_value_arr[$kk][$ll]" );
207  echo "</li>";
208  }
209  echo "</ul>";
210  } else {
211  var_input($infotype[$kk], "var_value_arr[$kk]" );
212  }
213  echo "</li>";
214  }
215  echo "</ul>";
216  } else {
217  echo "<input type='text' class='int' name='var_value' value='' size='30' />";
218  }
219  echo "<br/>";
220  echo "<input type='button' class='inb cancel' name='cancel' value='"._('Cancel')."' onclick=\"$('#add_var_div_$stratatata').toggle();\" />";
221  echo "<input type='submit' class='inb ok' value='"._("Apply")."'/>";
222  echo "</form></div>";
223  echo "<script type='text/javascript'>$('#add_var_div_$stratatata').toggle();</script>";
224 
225 }
226 
227 echo "<table class='tlist'>";
228 
229 foreach ( $variables->strata_order as $strata) {
230  echo "<tr class='lst'>";
231  echo "<td>"; __($strata); echo "</td>";
232  switch($strata) {
233  case 'DEFAULT':
234  echo "<td>"; $variables->display_value_html($allvars, 'DEFAULT', null, $var); echo "</td>";
235  break;
236  case 'GLOBAL':
237  echo "<td>";
238  if ( isset($allvars['GLOBAL'][null][$var]) && is_array($allvars['GLOBAL'][null][$var])){
239  echo "<a href='javascript:edit_var(".$allvars['GLOBAL'][null][$var]['id'].");'>"; $variables->display_value_html($allvars, 'GLOBAL', null, $var); echo "</a>";
240  edit_var($allvars['GLOBAL'][null][$var]);
241  } else {
242  echo "<a href='javascript:add_var(\"$strata\");'>"._("Add")."</a>";
243  add_var($strata);
244  }
245  echo "</td>";
246  break;
247  case 'FQDN_CREATOR':
248  echo "<td>";
249  if (isset($allvars['FQDN_CREATOR']) && is_array($allvars['FQDN_CREATOR'])) {
250  foreach ($allvars['FQDN_CREATOR'] as $ttk => $ttv ) {
251  if ( isset($ttv[$var]) && is_array( $ttv[$var])) {
252  echo sprintf(_("Overwritted by %s"), $members[$ttk]['login'])." &rarr; ";
253  echo "<a href='javascript:edit_var(".$ttv[$var]['id'].");'>"; echo $variables->display_valueraw_html($ttv[$var]['value'], $var);echo "</a>";
254  edit_var($ttv[$var]);
255  }
256  echo "<br/>";
257  }
258  } // isset
259  echo "<a href='javascript:add_var(\"$strata\");'>"._("Add")."</a>";
260  add_var($strata, $members_list);
261  echo "</td>";
262  break;
263  case 'FQDN':
264  echo "<td>";
265  if ( isset($allvars['FQDN']) && is_array($allvars['FQDN'])) {
266  foreach ($allvars['FQDN'] as $ttk => $ttv ) {
267  if ( isset($ttv[$var]) && is_array( $ttv[$var])) {
268  echo sprintf(_("Overwritted by %s"), $panel_url[$ttk])." &rarr; ";
269  echo "<a href='javascript:edit_var(".$ttv[$var]['id'].");'>"; echo $variables->display_valueraw_html($ttv[$var]['value'], $var);echo "</a>";
270  edit_var($ttv[$var]);
271  }
272  echo "<br/>";
273  }
274  } //isset
275  echo "<a href='javascript:add_var(\"$strata\");'>"._("Add")."</a>";
276  add_var($strata, $panel_url);
277  echo "</td>";
278  break;
279  case 'CREATOR':
280  echo "<td>";
281  if (isset($allvars['CREATOR']) && is_array($allvars['CREATOR'])) {
282  foreach ($allvars['CREATOR'] as $ttk => $ttv ) {
283  if ( isset($ttv[$var]) && is_array( $ttv[$var])) {
284  echo sprintf(_("Overwritted by %s"), $members[$ttk]['login'])." &rarr; ";
285  echo "<a href='javascript:edit_var(".$ttv[$var]['id'].");'>"; echo $variables->display_valueraw_html($ttv[$var]['value'], $var);echo "</a>";
286  edit_var($ttv[$var]);
287  }
288  echo "<br/>";
289  }
290  } //isset
291  echo "<a href='javascript:add_var(\"$strata\");'>"._("Add")."</a>";
292  add_var($strata, $creators_list );
293  echo "</td>";
294  break;
295  case 'MEMBER':
296  echo "<td>";
297  if (isset($allvars['MEMBER']) && is_array($allvars['MEMBER'])) {
298  foreach ($allvars['MEMBER'] as $ttk => $ttv ) {
299  if ( isset($ttv[$var]) && is_array( $ttv[$var])) {
300  echo sprintf(_("Overwritted by %s"), $members[$ttk]['login'])." &rarr; ";
301  echo "<a href='javascript:edit_var(".$ttv[$var]['id'].");'>"; echo $variables->display_valueraw_html($ttv[$var]['value'], $var);echo "</a>";
302  edit_var($ttv[$var]);
303  }
304  echo "<br/>";
305  }
306  } //isset
307  echo "<a href='javascript:add_var(\"$strata\");'>"._("Add")."</a>";
308  add_var($strata, $members_list);
309  echo "</td>";
310  break;
311  case 'DOMAIN':
312  //FIXME TODO
313  echo "<td>Todo.</td>";
314  break;
315  } //switch
316 
317  echo "</tr>";
318 } //foreach
319 echo "</table>";
320 
321 ?>
322 
323 <p><span class="ina back"><a href="adm_variables.php"><?php __("Back to the var list"); ?></a></span></p>
324 
325 <script type="text/javascript">
326 function edit_var(id) {
327  $('#edit_var_div_'+id).toggle();
328 }
329 function add_var(st) {
330  $('#add_var_div_'+st).toggle();
331 }
332 </script>
333 <?php
334 include_once("foot.php");
335 ?>