Merge branch '164-crash-on-patching-and-possibly-right-after-login' into 'main/atys...
[ryzomcore.git] / nelns / admin / public_html / custom_view.php
bloba53308f2fbe2fcc7866967c0cf9203723d5d3f1d
1 <?php
2 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
3 // Copyright (C) 2010 Winch Gate Property Limited
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Affero General Public License as
7 // published by the Free Software Foundation, either version 3 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Affero General Public License for more details.
15 // You should have received a copy of the GNU Affero General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 $publicAccess = true;
19 include('authenticate.php');
22 unset($error);
24 function reorderViews($uid)
26 $result = sqlquery("SELECT tid FROM view_table WHERE uid='$uid' ORDER BY ordering");
27 $i = 0;
28 while ($result && $arr = mysql_fetch_array($result))
30 sqlquery("UPDATE view_table SET ordering='$i' WHERE tid='".$arr["tid"]."'");
31 ++$i;
35 function swapView($uid, $ordering, $offs)
37 $result1 = sqlquery("SELECT tid FROM view_table WHERE uid='$uid' AND ordering='$ordering'");
38 if (!$result1 || mysql_num_rows($result1) != 1)
39 return;
40 $result1 = mysql_fetch_array($result1);
41 $tid1 = $result1["tid"];
43 $result2 = sqlquery("SELECT tid FROM view_table WHERE uid='$uid' AND ordering='".($ordering+$offs)."'");
44 if (!$result2 || mysql_num_rows($result2) != 1)
45 return;
46 $result2 = mysql_fetch_array($result2);
47 $tid2 = $result2["tid"];
49 sqlquery("UPDATE view_table SET ordering='".($ordering+$offs)."' WHERE uid='$uid' AND tid='$tid1'");
50 sqlquery("UPDATE view_table SET ordering='".($ordering)."' WHERE uid='$uid' AND tid='$tid2'");
53 function reorderRows($tid)
55 $result = sqlquery("SELECT vid, ordering FROM view_row WHERE tid='$tid' ORDER BY ordering");
56 $i = 0;
58 $rows = array();
60 while ($result && $arr = mysql_fetch_array($result))
61 $rows[] = array($arr['vid'], $arr['ordering']);
63 if (count($rows) > 0)
65 $i = 0;
66 foreach ($rows as $row)
68 sqlquery("UPDATE view_row SET ordering='".(-$i-1)."' WHERE tid='$tid' AND ordering='".$row[1]."'");
69 ++$i;
72 $i = 0;
73 for ($i=0; $i<count($rows); ++$i)
75 sqlquery("UPDATE view_row SET ordering='$i' WHERE tid='$tid' AND ordering='".(-$i-1)."'");
80 function swapRows($tid, $ordering, $offs)
83 $result1 = sqlquery("SELECT vid FROM view_row WHERE tid='$tid' AND ordering='$ordering'");
84 if (!$result1 || mysql_num_rows($result1) != 1)
85 return;
86 $result1 = mysql_fetch_array($result1);
87 $vid1 = $result1["vid"];
89 $result2 = sqlquery("SELECT vid FROM view_row WHERE tid='$tid' AND ordering='".($ordering+$offs)."'");
90 if (!$result2 || mysql_num_rows($result2) != 1)
91 return;
92 $result2 = mysql_fetch_array($result2);
93 $vid2 = $result2["vid"];
95 sqlquery("UPDATE view_row SET ordering='".($ordering+$offs)."' WHERE tid='$tid' AND vid='".($vid1)."'");
96 sqlquery("UPDATE view_row SET ordering='".($ordering)."' WHERE tid='$tid' AND vid='".($vid2)."'");
99 sqlquery("UPDATE view_row SET ordering='-1' WHERE tid='$tid' AND ordering='".($ordering)."'");
100 sqlquery("UPDATE view_row SET ordering='".($ordering)."' WHERE tid='$tid' AND ordering='".($ordering+$offs)."'");
101 sqlquery("UPDATE view_row SET ordering='".($ordering+$offs)."' WHERE tid='$tid' AND ordering='-1'");
105 // -----------------------------
106 // page commands
108 // create a view
109 if ($createview)
111 // create a table in view_table
112 $result = sqlquery("SELECT tid FROM view_table WHERE uid='$uid' AND name='$viewname'");
113 if ($result && mysql_num_rows($result) != 0)
115 $error = $error."Couldn't create view '$viewname', name already in use<br>\n";
117 else
119 $result = sqlquery("INSERT INTO view_table SET uid='$uid', name='$viewname', ordering='255'");
120 if (!$result)
122 $error = $error."Couldn't create view '$viewname', mySQL request failed<br>\n";
124 $result = sqlquery("SELECT tid FROM view_table WHERE uid='$uid' AND name='$viewname'");
125 $result = mysql_fetch_array($result);
126 $tid = $result["tid"];
128 reorderViews($uid);
132 // duplicate a view
133 else if (isset($dupView) && isset($tid))
135 $result = sqlquery("SELECT * FROM view_table WHERE tid='$tid'");
136 if ($result && ($arr = sqlfetch($result)))
138 sqlquery("INSERT INTO view_table SET uid='$uid', name='CopyOf_".$arr["name"]."', ordering='127', filter='".$arr["filter"]."'");
139 $res2 = sqlquery("SELECT tid FROM view_table WHERE uid='$uid' AND ordering='127'");
140 $arr=sqlfetch($res2);
141 $ntid = $arr["tid"];
143 $result = sqlquery("SELECT * FROM view_row WHERE tid='$tid'");
144 while ($result && ($arr=sqlfetch($result)))
146 sqlquery("INSERT INTO view_row SET tid='$ntid', vid='".$arr["vid"]."', name='".$arr["name"]."', ordering='".$arr["ordering"]."', filter='".$arr["filter"]."'");
149 reorderViews($uid);
151 $tid = $ntid;
154 // remove a view
155 else if (isset($removeView))
157 if (!($result = sqlquery("DELETE FROM view_table WHERE uid='$uid' AND tid='$removeView'"))
158 || mysql_affected_rows() < 1)
160 $error = $error."Couldn't remove view $removeView, missing or user doesn't own it<br>\n";
162 else
164 sqlquery("DELETE FROM view_row WHERE tid='$removeView'");
165 reorderViews($uid);
168 // change view name
169 else if (isset($chViewName))
171 sqlquery("UPDATE view_table SET name='$chViewName' WHERE tid='$tid'");
173 // change view state
174 else if (isset($chViewFilter))
176 sqlquery("UPDATE view_table SET filter='$chViewFilter' WHERE tid='$tid'");
178 // change view state
179 else if (isset($chViewDisplay))
181 sqlquery("UPDATE view_table SET display='$chViewDisplay' WHERE tid='$tid'");
183 // change view state
184 else if (isset($chViewAutoDisplay))
186 sqlquery("UPDATE view_table SET auto_display='$chViewAutoDisplay' WHERE tid='$tid'");
188 // change view state
189 else if (isset($chViewRefreshRate))
191 sqlquery("UPDATE view_table SET refresh_rate='$chViewRefreshRate' WHERE tid='$tid'");
193 // swap a view
194 else if (isset($moveView) && isset($offs))
196 swapView($uid, $moveView, $offs);
198 // add a variable to a view
199 else if (isset($addToView) && isset($tid))
201 if (hasAccessToVariable($addToView))
203 if (!($resultt = sqlquery("SELECT name FROM view_table WHERE uid='$uid' AND tid='$tid'"))
204 || mysql_num_rows($resultt) != 1)
206 $error = $error."Couldn't add variable $addToView to view $tid, view is missing or user doesn't own it<br>\n";
208 else
210 $resultt = mysql_fetch_array($resultt);
211 $result = sqlquery("INSERT INTO view_row SET tid='$tid', vid='$addToView', name='".$variableData[$addToView]["name"]."', ordering='255'");
212 if (!$result)
213 $error = $error."Couldn't add variable ".$variableData[addToView]["name"]." to view ".$resultt["name"].", query failed";
214 else
215 reorderRows($tid);
219 // remove a row
220 else if (isset($removeRow) && isset($tid))
222 $result = sqlquery("SELECT uid FROM view_table WHERE tid='$tid' AND uid='$uid'");
223 if ($result && mysql_num_rows($result)>0)
225 if (!($result = sqlquery("DELETE FROM view_row WHERE tid='$tid' AND ordering='$removeRow'"))
226 || mysql_affected_rows() < 1)
228 $error = $error."Couldn't remove row $removeRow, missing or user doesn't own it<br>\n";
230 else
232 reorderRows($tid);
236 // swap a row
237 else if (isset($moveRow) && isset($tid) && isset($offs))
239 $result = sqlquery("SELECT uid FROM view_table WHERE tid='$tid' AND uid='$uid'");
240 if ($result && mysql_num_rows($result)>0)
241 swapRows($tid, $moveRow, $offs);
243 // change a variable name
244 else if ($changeVarName && isset($vid) && isset($tid))
246 $result = sqlquery("SELECT uid FROM view_table WHERE tid='$tid' AND uid='$uid'");
247 if ($result && mysql_num_rows($result)>0)
249 $result = sqlquery("UPDATE view_row SET name='$changeVarName' WHERE vid='$vid' AND tid='$tid'");
252 // change a variable state
253 else if (isset($changeVarFilter) && isset($vid) && isset($tid))
255 $result = sqlquery("SELECT uid FROM view_table WHERE tid='$tid' AND uid='$uid'");
256 if ($result && mysql_num_rows($result)>0)
258 $result = sqlquery("UPDATE view_row SET filter='$changeVarFilter' WHERE vid='$vid' AND tid='$tid'");
261 // select a new default_view
262 else if (isset($default_view))
264 sqlquery("UPDATE user SET default_view='$default_view' WHERE uid='$uid'");
267 // change a command name
268 else if (isset($chViewCommandName) && isset($vcmd) && isset($tid))
270 sqlquery("UPDATE view_command SET name='$chViewCommandName' WHERE tid='$tid' AND name='$vcmd'");
272 else if (isset($chViewCommand) && isset($vcmd) && isset($tid))
274 sqlquery("UPDATE view_command SET command='$chViewCommand' WHERE tid='$tid' AND name='$vcmd'");
276 else if (isset($rmViewCommand) && isset($vcmd) && isset($tid))
278 sqlquery("DELETE FROM view_command WHERE tid='$tid' AND name='$vcmd'");
280 else if (isset($createViewCommand) && isset($nViewCommand) && isset($nViewCommandName) && isset($tid))
282 sqlquery("INSERT INTO view_command SET tid='$tid', name='$nViewCommandName', command='$nViewCommand'");
284 else if (isset($changeVidGraph) && isset($tid))
286 if (isset($graphState) && $graphState == "on")
288 sqlquery("UPDATE view_row SET graph='1' WHERE tid='$tid' AND vid='$changeVidGraph'");
290 else
292 sqlquery("UPDATE view_row SET graph='0' WHERE tid='$tid' AND vid='$changeVidGraph'");
296 // give a view to another user
297 else if (isset($giveTo) && isset($tid))
299 sqlquery("UPDATE view_table SET uid='$giveTo' WHERE tid='$tid'");
300 unset($tid);
303 // -----------------------------
304 // page display
306 htmlProlog($_SERVER['PHP_SELF'], "Customize views");
308 if ($error)
310 echo "<b>Reported errors:</b><br>$error<br>\n";
313 unset($vargroups);
314 $result = sqlquery("SELECT * FROM variable_group ORDER BY name");
315 while ($result && ($arr=sqlfetch($result)))
317 if ((!isset($sel_vgid) || $sel_vgid == "") && $arr["name"] == "NoGroup")
318 $sel_vgid = $arr["vgid"];
319 $vargroups[$arr["name"]] = $arr["vgid"];
324 // -----------------------------
325 // display customizable views
327 $res = sqlquery("SELECT default_view FROM user, view_table WHERE user.uid='$uid' AND (view_table.uid='$uid' OR view_table.uid='$gid') AND view_table.tid=user.default_view");
328 if ($res && ($arr=sqlfetch($res)))
329 $default_view = $arr["default_view"];
331 unset($availViews);
332 unset($userViews);
333 unset($groupViews);
334 $res = sqlquery("SELECT name, tid, ordering FROM view_table WHERE uid='$uid' ORDER BY ordering");
335 while ($res && ($arr=sqlfetch($res)))
337 $availViews[] = $arr;
338 $userViews[] = $arr;
340 $res = sqlquery("SELECT name, tid, ordering FROM view_table WHERE uid='$gid' ORDER BY ordering");
341 while ($res && ($arr=sqlfetch($res)))
343 $availViews[] = $arr;
344 $groupViews[] = $arr;
347 echo "<br>\n";
348 echo "<table border=0><tr>\n";
349 echo "<td><b>Your default view:</b></td>\n";
350 echo "<form method=post action='".$_SERVER['PHP_SELF']."?tid=$tid&sel_vgid=$sel_vgid'><td>\n";
351 echo "<select name='default_view' onChange='submit()'>\n";
352 $selected = false;
353 foreach ($availViews as $view)
355 $selectedView = ($view["tid"]==$default_view);
356 $selected |= $selectedView;
357 echo "<option value='".$view["tid"]."'".($selectedView ? " selected" : "").">".$view["name"]."\n";
359 echo "<option value='0'".(!$selected ? " selected" : "").">None\n";
360 echo "</select>\n";
361 echo "</td></form>\n";
362 echo "</tr></table><br>\n";
364 echo "<table><tr valign=top><td>\n";
365 echo "<b>Your current views: </b>".help("View")."<br><font size=0>(click name to view/edit table, click radio to select as default view)</font><br>\n";
366 echo "<table border=1>\n";
367 echo "<form method=post action='".$_SERVER['PHP_SELF']."?tid=$tid&sel_vgid=$sel_vgid'>";
368 echo "<tr><th>Index</th><th>[Default] View</th><th>Commands</th></tr>\n";
369 if (isset($userViews) && count($userViews)>0)
371 foreach ($userViews as $arr)
373 $_tname = $arr["name"];
374 $_tid = $arr["tid"];
375 $color = ($tid == $_tid ? " bgcolor=#eeeeee" : "");
376 echo "<tr><td$color>".$arr["ordering"]."</td>";
377 echo "<td$color><input type=radio name=default_view value='$_tid' onClick='submit()'".($_tid==$default_view ? " checked" : "")."><a href='".$_SERVER['PHP_SELF']."?tid=$_tid&sel_vgid=$sel_vgid'>$_tname</a></td>".
378 "<td$color><a href='".$_SERVER['PHP_SELF']."?removeView=$_tid&tid=$tid&sel_vgid=$sel_vgid' onClick=\"return confirm('You are about to delete a View')\">Delete</a> ".
379 "<a href='".$_SERVER['PHP_SELF']."?moveView=".$arr["ordering"]."&offs=+1&tid=$tid&sel_vgid=$sel_vgid'>-</a> ".
380 "<a href='".$_SERVER['PHP_SELF']."?moveView=".$arr["ordering"]."&offs=-1&tid=$tid&sel_vgid=$sel_vgid'>+</a> ".
381 "<a href='".$_SERVER['PHP_SELF']."?dupView=true&tid=$_tid&offs=-1&sel_vgid=$sel_vgid'>Duplicate</a></td></tr>\n";
384 echo "</form>\n";
385 echo "<tr><form method=post action='".basename($_SERVER['PHP_SELF'])."'><td></td>\n";
386 echo "<td><input type=text name=viewname maxlength=32 size=16></td>\n";
387 echo "<td><input type=submit name=createview value='Create new view'></td>\n";
388 echo "</form></tr>\n";
389 echo "</table><br>\n";
391 echo "</td>\n";
393 if (isset($groupViews) && count($groupViews)>0)
395 echo "<td width=40></td><td>\n";
396 echo "<b>$group views: </b>".help("View")."<br><font size=0>(click name to view table, click radio to select as default view)</font><br>\n";
397 echo "<table border=1>\n";
398 echo "<tr><th>Index</th><th>[Default] View</th><th>Commands</th></tr>\n";
399 echo "<form method=post action='".$_SERVER['PHP_SELF']."?tid=$tid&sel_vgid=$sel_vgid'>\n";
400 foreach ($groupViews as $arr)
402 $_tname = $arr["name"];
403 $_tid = $arr["tid"];
404 $color = ($tid == $_tid ? " bgcolor=#eeeeee" : "");
405 echo "<tr><td$color>".$arr["ordering"]."</td>".
406 "<td$color><input type=radio name=default_view value='$_tid' onClick='submit()'".($_tid==$default_view ? " checked" : "")."><a href='".$_SERVER['PHP_SELF']."?tid=$_tid&sel_vgid=$sel_vgid'>$_tname</a></td>".
407 "<td$color><a href='".$_SERVER['PHP_SELF']."?dupView=true&tid=$_tid&offs=-1&sel_vgid=$sel_vgid'>Duplicate</a></td></tr>\n";
409 echo "</form>\n";
410 echo "</table><br>\n";
411 echo "</td>\n";
414 echo "</tr></table>\n";
416 if (isset($tid))
418 $result = sqlquery("SELECT name, uid, filter, display, auto_display, refresh_rate FROM view_table WHERE (uid='$uid' OR uid='$gid') AND tid='$tid'");
419 if (!$result || mysql_num_rows($result) == 0)
421 echo "<br><b>Can't display table $tid</b><br>\n";
423 else
425 echo "<table cellpadding=0 cellspacing=0><tr valign=top><td>\n";
427 $result = mysql_fetch_array($result);
428 $viewName = $result["name"];
429 $viewFilter = $result["filter"];
430 $viewDisplay = $result["display"];
431 $viewAutoDisplay = $result["auto_display"];
432 $viewRefreshRate = $result["refresh_rate"];
434 $ownView = ($result["uid"] == $uid);
436 echo "<table border=1>\n";
437 echo "<tr><form method=post action='".$_SERVER['PHP_SELF']."?sel_vgid=$sel_vgid&tid=$tid'><td colspan=3><b>Content of ".($ownView ? "<input name=chViewName value='$viewName' size=32 maxlength=32>" : $viewName)."</b></td></form>";
438 if ($ownView && ($admlogin == "root" || $admlogin == $group || $IsNevrax))
440 echo "<form method=post action='".$_SERVER['PHP_SEL']."?sel_vgid=$sel_vgid&tid=$tid'><td colspan=4>Give view to <select name='giveTo' onChange='submit()'>";
441 $gresult = sqlquery("SELECT uid, login FROM user ORDER BY login");
442 while ($gresult && ($garr=sqlfetch($gresult)))
444 echo "<option value='".$garr["uid"]."'".($uid == $garr["uid"] ? " selected" : "").">".$garr["login"];
446 echo "</select>";
448 else
450 echo "<td colspan=3>";
452 echo "</td></tr>";
454 $result = sqlquery("SELECT view_row.name AS name, view_row.vid AS vid, view_row.ordering AS ordering, path, view_row.filter AS filter, graph ".
455 "FROM view_table, view_row, variable ".
456 "WHERE variable.command='variable' AND view_table.uid='$uid' AND view_table.tid='$tid' AND view_table.tid=view_row.tid AND ".
457 "view_row.vid=variable.vid ORDER BY ordering");
459 if (!$result)
460 die("rows select failed !");
462 unset($rows);
464 echo "<tr><th>Index</th><th><b>Variable</b></th><th>Path</th><th>Privilege</th><th>Filter</th><th>Graph</th><th>Commands</th></tr>\n";
465 while ($arr = mysql_fetch_array($result))
467 $vid = $arr["vid"];
469 if (!hasAccessToVariable($vid))
470 continue;
472 $priv = getVariableRight($vid);
474 $rows[$vid] = $arr["name"];
476 $ordering = $arr["ordering"];
477 if ($ownView)
479 echo "<tr>".
480 "<td>".$arr["ordering"]."</td>".
481 "<form method=post action='".$_SERVER['PHP_SELF']."?sel_vgid=$sel_vgid&vid=$vid&tid=$tid'><td><input type=text name=changeVarName maxlength=128 size=16 value='".$arr["name"]."'></td></form>".
482 "<td>".$arr["path"]."</td>".
483 "<td>$priv</td>".
484 "<form method=post action='".$_SERVER['PHP_SELF']."?sel_vgid=$sel_vgid&vid=$vid&tid=$tid'><td><input type=text name=changeVarFilter maxlength=64 size=16 value='".$arr["filter"]."'></td></form>".
485 "<form method=post action='".$_SERVER['PHP_SELF']."?sel_vgid=$sel_vgid&changeVidGraph=$vid&tid=$tid'><td><input type=checkBox name=graphState".($arr["graph"] != 0 ? " checked" : "")." onClick='submit()'></td></form>".
486 "<td><a href='".$_SERVER['PHP_SELF']."?removeRow=$ordering&tid=$tid&sel_vgid=$sel_vgid' onClick=\"return confirm('You are about to delete a Variable from a View')\">Delete</a> ".
487 "<a href='".$_SERVER['PHP_SELF']."?moveRow=$ordering&tid=$tid&offs=+1&sel_vgid=$sel_vgid'>-</a> ".
488 "<a href='".$_SERVER['PHP_SELF']."?moveRow=$ordering&tid=$tid&offs=-1&sel_vgid=$sel_vgid'>+</a></td></tr>\n";
490 else
492 echo "<tr>".
493 "<td>".$arr["ordering"]."</td>".
494 "<td>".$arr["name"]."</td>".
495 "<td>".$arr["path"]."</td>".
496 "<td>$priv</td>".
497 "<td>".$arr["filter"]."</td>".
498 "<td>".($arr["graph"] != 0 ? "Yes" : "No")."</td>".
499 "<td></td></tr>\n";
502 echo "<tr height=15><td colspan=7></td></tr>";
504 $result = sqlquery("SELECT view_row.name AS name, view_row.vid AS vid, view_row.ordering AS ordering, path, view_row.filter AS filter, graph ".
505 "FROM view_table, view_row, variable ".
506 "WHERE variable.command='command' AND view_table.uid='$uid' AND view_table.tid='$tid' AND view_table.tid=view_row.tid AND ".
507 "view_row.vid=variable.vid ORDER BY ordering");
509 if (!$result)
510 die("rows select failed !");
512 unset($rows);
514 echo "<tr><th>Index</th><th><b>Command</b></th><th colspan=2>Path</th><th colspan=2>Filter</th><th>Commands</th></tr>\n";
515 while ($arr = mysql_fetch_array($result))
517 $vid = $arr["vid"];
519 if (!hasAccessToVariable($vid))
520 continue;
522 $priv = getVariableRight($vid);
524 $rows[$vid] = $arr["name"];
526 $ordering = $arr["ordering"];
527 if ($ownView)
529 echo "<tr>".
530 "<td>".$arr["ordering"]."</td>".
531 "<form method=post action='".$_SERVER['PHP_SELF']."?sel_vgid=$sel_vgid&vid=$vid&tid=$tid'><td><input type=text name=changeVarName maxlength=128 size=16 value='".$arr["name"]."'></td></form>".
532 "<td colspan=2>".$arr["path"]."</td>".
533 "<form method=post action='".$_SERVER['PHP_SELF']."?sel_vgid=$sel_vgid&vid=$vid&tid=$tid'><td colspan=2><input type=text name=changeVarFilter maxlength=64 size=16 value='".$arr["filter"]."'></td></form>".
534 "<td><a href='".$_SERVER['PHP_SELF']."?removeRow=$ordering&tid=$tid&sel_vgid=$sel_vgid' onClick=\"return confirm('You are about to delete a Variable from a View')\">Delete</a> ".
535 "<a href='".$_SERVER['PHP_SELF']."?moveRow=$ordering&tid=$tid&offs=+1&sel_vgid=$sel_vgid'>-</a> ".
536 "<a href='".$_SERVER['PHP_SELF']."?moveRow=$ordering&tid=$tid&offs=-1&sel_vgid=$sel_vgid'>+</a></td></tr>\n";
538 else
540 echo "<tr>".
541 "<td>".$arr["ordering"]."</td>".
542 "<td>".$arr["name"]."</td>".
543 "<td>".$arr["path"]."</td>".
544 "<td>$priv</td>".
545 "<td>".$arr["filter"]."</td>".
546 "<td>".($arr["graph"] != 0 ? "Yes" : "No")."</td>".
547 "<td></td></tr>\n";
551 echo "<tr height=15><td colspan=7></td></tr>";
553 echo "<tr><td colspan=7>";
554 if ($ownView)
556 echo "<table>\n";
557 echo "<form method=post action='".$_SERVER['PHP_SELF']."?sel_vgid=$sel_vgid&tid=$tid'><tr><th>Filter</th><td><input name=chViewFilter value='$viewFilter' size=64 maxlength=64></td></tr></form>";
558 echo "<form method=post action='".$_SERVER['PHP_SELF']."?sel_vgid=$sel_vgid&tid=$tid'><tr><th>Display type</th><td><select name=chViewDisplay onChange='submit()'>";
559 echo "<option value='normal'".($viewDisplay=="normal" ? " selected" : "").">Normal display";
560 echo "<option value='condensed'".($viewDisplay=="condensed" ? " selected" : "").">Condensed display";
561 echo "</select></td></tr></form>\n";
562 echo "<form method=post action='".$_SERVER['PHP_SELF']."?sel_vgid=$sel_vgid&tid=$tid'><tr><th>Display automation</th><td><select name=chViewAutoDisplay onChange='submit()'>";
563 echo "<option value='auto'".($viewAutoDisplay=="auto" ? " selected" : "").">Automatic display";
564 echo "<option value='manual'".($viewAutoDisplay=="manual" ? " selected" : "").">Manual display";
565 echo "</select></td></tr></form>\n";
566 echo "<form method=post action='".$_SERVER['PHP_SELF']."?sel_vgid=$sel_vgid&tid=$tid'><tr><th>Refresh rate</th><td><input name=chViewRefreshRate value='$viewRefreshRate' size=5 maxlength=10> seconds</td></tr></form>\n";
567 echo "</table>\n";
569 else
571 echo "<b>Filter ".($ownView ? "<input name=chViewFilter value='$viewFilter' size=64 maxlength=64>" : $viewFilter)."</b><br>";
572 echo ($viewDisplay == "condensed" ? "Condensed" : "Normal")." display, ";
573 echo ($viewAutoDisplay == "auto" ? "Automatic" : "Manual")." display";
575 echo "</td></tr>";
576 echo "</table>\n";
578 echo "</td><td width=20>\n";
579 echo "</td><td>\n";
581 if ($ownView)
583 echo "<b>Available variables:</b><br><font size=0>(click a variable to add it to view $viewName)</font><br>\n";
585 echo "<table border=1 cellspacing=1>\n";
586 echo "<tr><th>Variable</th>";
587 echo "<form method=post action='".$_SERVER['PHP_SELF']."?tid=$tid'><th><select name=sel_vgid onChange='submit()'>\n";
588 foreach ($vargroups as $vargroup => $vgid)
589 echo "<option value='$vgid'".($sel_vgid == $vgid ? " selected" : "").">$vargroup\n";
590 echo "<option value='-1'".(!isset($sel_vgid) || $sel_vgid=='-1' ? " selected" : "").">All Groups\n";
591 echo "</select></th></form>\n";
592 echo "<th>Path</th><th>State</th><th>Privilege</th></tr>\n";
594 $result = sqlquery("SELECT command, variable.vid AS vid, variable.name AS name, path, state, variable.vgid AS vgid, variable_group.name AS group_name ".
595 "FROM variable, variable_group ".
596 "WHERE variable.vgid = variable_group.vgid".(isset($sel_vgid) && $sel_vgid!="-1" ? " AND variable.vgid='$sel_vgid'" : "")." ORDER BY variable.command, variable.vgid, variable.name");
597 if (!$result)
598 die("variable select failed !");
600 $prevvgid = "";
601 $prevvtype = "";
603 while ($arr = mysql_fetch_array($result))
605 $vid = $arr["vid"];
607 if (!hasAccessToVariable($vid))
608 continue;
610 $priv = getVariableRight($vid);
612 if ($prevvtype != "" && $prevvtype != $arr["command"])
614 echo "<tr height=15><td colspan=5></td></tr>\n";
615 echo "<tr><th>Command</th><th>Group</th><th>Path</th><th>State</th><th>Privilege</th></tr>\n";
617 $prevvgid = "";
620 if ($prevvgid != "" && $prevvgid != $arr["vgid"])
622 echo "<tr height=5><td colspan=5></td></tr>\n";
624 $prevvgid = $arr["vgid"];
625 $prevvtype = $arr["command"];
627 echo "<tr><td><b><a href='".$_SERVER['PHP_SELF']."?addToView=$vid&tid=$tid&sel_vgid=$sel_vgid'>".$arr["name"]."</a></b></td>".
628 "<td>".$arr["group_name"]."</td>".
629 "<td>".$arr["path"]."</td>".
630 "<td>".$arr["state"]."</td>".
631 "<td>$priv</td></tr>\n";
633 echo "</table>\n";
636 echo "</td></tr></table>\n";
638 //if ($admlogin == "root" || $group == $admlogin)
640 echo "<table><tr valign=top><td>\n";
642 echo "<br><br><b>View commands</b><br>\n";
643 echo "<table border=1><tr><th>Name</th><td align=center><b>Command</b> <font size=1>(with full parameter list)</font></td><th></th></tr>\n";
644 $result = sqlquery("SELECT name, command FROM view_command WHERE tid='$tid' ORDER BY name");
645 while ($result && ($arr = sqlfetch($result)))
647 echo "<tr><form method=post action='$_SERVER['PHP_SELF']?tid=$tid&vcmd=".$arr["name"]."'><td><input name=chViewCommandName value='".$arr["name"]."' size=16 maxlength=32></td></form><form method=post action='$_SERVER['PHP_SELF']?tid=$tid&vcmd=".$arr["name"]."'><td><input name=chViewCommand value='".$arr["command"]."' size=32 maxlength=32></td></form><form method=post action='$_SERVER['PHP_SELF']?tid=$tid&vcmd=".$arr["name"]."'><td><input type=submit name=rmViewCommand value='Delete' onClick=\"return confirm('You are about to delete a Command')\"></td></form></tr>\n";
649 echo "<tr><td colspan=3 height=5></td></th>\n";
650 echo "<tr><form method=post action='$_SERVER['PHP_SELF']?tid=$tid'><td><input name=nViewCommandName size=16 maxlength=32></td><td><input name=nViewCommand size=32 maxlength=32></td><td><input type=submit name=createViewCommand value='Create'></td></form></tr>\n";
651 echo "</table>\n";
653 echo "</table>\n";
655 echo "</td></tr></table><br>\n";
661 htmlEpilog();