demo: simplify demoreload.sh
[racktables-contribs] / tagRollerForObjects.php
1 <?php
2
3 $tab['depot']['tagroller'] = 'Tag roller';
4 $tabhandler['depot']['tagroller'] = 'renderTagRollerForObjects';
5 $ophandler['depot']['tagroller']['rollObjectTags'] = 'rollObjectTags';
6
7 function rollObjectTags () // see rollTags() in ophandlers.php
8 {
9 setFuncMessages (__FUNCTION__, array ('OK' => 67, 'ERR' => 149));
10 if (genericAssertion ('sum', 'string0') != genericAssertion ('realsum', 'uint'))
11 {
12 showFuncMessage (__FUNCTION__, 'ERR');
13 return;
14 }
15 // Even if the user requested an empty tag list, don't bail out, but process existing
16 // tag chains with "zero" extra. This will make sure, that the stuff processed will
17 // have its chains refined to "normal" form.
18 $extratags = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
19 $n_ok = 0;
20 // Minimizing the extra chain early, so that tag rebuilder doesn't have to
21 // filter out the same tag again and again. It will have own noise to cancel.
22 $extrachain = getExplicitTagsOnly (buildTagChainFromIds ($extratags));
23
24 $cellfilter = getCellFilter();
25 $objects = applyCellFilter ('object', $cellfilter);
26 foreach ($objects as $obj)
27 {
28 if (rebuildTagChainForEntity ('object', $obj['id'], $extrachain))
29 $n_ok++;
30 }
31 showFuncMessage (__FUNCTION__, 'OK', array ($n_ok));
32 }
33
34 function renderTagRollerForObjects ()
35 {
36 $a = rand (1, 20);
37 $b = rand (1, 20);
38 $sum = $a + $b;
39 echo "<p>";
40 printOpFormIntro ('rollObjectTags', array ('realsum' => $sum));
41 echo "<table border=1 align=center>";
42 echo "<tr><td colspan=2>This special tool allows assigning tags to objects as selected below.<br>";
43 echo "The tag(s) selected below will be appended to already assigned tag(s) of each particular entity.</td></tr>";
44 echo "<tr><th>Tags</th><td>";
45 printTagsPicker ();
46 echo "</td></tr>";
47 echo "<tr><th>Control question: the sum of ${a} and ${b}</th><td><input type=text name=sum></td></tr>";
48 echo "<tr><td colspan=2 align=center><input type=submit value='Go!'></td></tr>";
49 echo "</table></form>";
50 echo "<p>";
51 renderDepot();
52 }