r1209 + adding recent cool DB upgrade feature
[racktables] / inc / interface.php
CommitLineData
e673ee24
DO
1<?
2/*
3*
4* This file contains frontend functions for RackTables.
5*
6*/
7
9c0b0016
DO
8// Interface function's special.
9$nextorder['odd'] = 'even';
10$nextorder['even'] = 'odd';
11
e673ee24
DO
12// Main menu.
13function renderIndex ()
14{
15 global $root;
16?>
17<table border=0 cellpadding=0 cellspacing=0 width='100%'>
18 <tr>
19 <td>
20 <div style='text-align: center; margin: 10px; '>
21 <table width='100%' cellspacing=0 cellpadding=30 class=mainmenu border=0>
22 <tr>
23 <td>
24 <h1><a href='<? echo $root; ?>?page=rackspace'>Rackspace<br>
25 <? printImageHREF ('rackspace'); ?></a></h1>
26 </td>
27 <td>
28 <h1><a href='<? echo $root; ?>?page=objects'>Objects<br>
29 <? printImageHREF ('objects'); ?></a></h1>
30 </td>
31 <td>
32 <h1><a href='<? echo $root; ?>?page=ipv4space'>IPv4 space<br>
33 <? printImageHREF ('ipv4space'); ?></a></h1>
34 </td>
35 </tr>
36 </table>
37 <table width='100%' cellspacing=0 cellpadding=30 class=mainmenu border=0>
38 <tr>
39 <td>
40 <h1><a href='<? echo $root; ?>?page=config'>Configuration<br>
41 <? printImageHREF ('config'); ?></a></h1>
42 </td>
43 <td>
bb09cca0 44 <h1><a href='<? echo $root; ?>?page=reports'>[ Reports ]<br>
e673ee24
DO
45 <? printImageHREF ('reports'); ?></a></h1>
46 </td>
ae545907 47 <td>
0a1b1268 48 <h1><a href='<? echo $root; ?>?page=help'>Help<br>
ae545907
DO
49 <? printImageHREF ('help'); ?></a></h1>
50 </td>
e673ee24
DO
51 </tr>
52 </table>
53 </div>
54 </td>
55 </tr>
56</table>
57<?
58}
59
60function renderRackspace ()
61{
62?>
63 <table border=0 cellpadding=10 cellpadding=1>
64<?
65 // generate thumb gallery
66 $rackrowList = getRackRowInfo();
9c0b0016
DO
67 global $root, $nextorder;
68 $rackwidth = getConfigVar ('rtwidth_0') + getConfigVar ('rtwidth_1') + getConfigVar ('rtwidth_2');
e673ee24
DO
69 $order = 'odd';
70 foreach ($rackrowList as $rackrow)
71 {
72 echo "<tr class=row_${order}><th><a href='${root}?page=row&row_id=${rackrow['dict_key']}'>${rackrow['dict_value']}</a></th>";
73 $rackList = getRacksForRow ($rackrow['dict_key']);
74 echo "<td><table border=0 cellspacing=5><tr>";
75 foreach ($rackList as $dummy => $rack)
76 {
77 echo "<td align=center><a href='${root}?page=rack&rack_id=${rack['id']}'>";
78 echo "<img border=0 width=${rackwidth} height=";
79 echo 3 + 3 + $rack['height'] * 2;
80 echo " title='${rack['height']} units'";
81 echo "src='render_rack_thumb.php?rack_id=${rack['id']}'>";
82 echo "<br>${rack['name']}</a></td>";
83 }
84 echo "</tr></table></tr>\n";
85 $order = $nextorder[$order];
86 }
87 echo "</table>\n";
88}
89
90function renderRow ($row_id)
91{
92 if ($row_id == 0)
93 {
94 showError ('Invalid row_id in renderRow()');
95 return;
96 }
97 if (($rowInfo = getRackRowInfo ($row_id)) == NULL)
98 {
99 showError ('getRackRowInfo() failed in renderRow()');
100 return;
101 }
102 // Main layout starts.
103 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
104
105 // Left portlet with row information.
106 echo "<tr><td class=pcleft>";
107 startPortlet ('Row information');
108 echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
109 echo "<tr><th width='50%' class=tdright>Row name:</th><td class=tdleft>${rowInfo['dict_value']}</td></tr>\n";
110 echo "<tr><th width='50%' class=tdright>Racks:</th><td class=tdleft>${rowInfo['count']}</td></tr>\n";
111 echo "<tr><th width='50%' class=tdright>Units:</th><td class=tdleft>${rowInfo['sum']}</td></tr>\n";
112 echo "</table><br>\n";
113 finishPortlet();
114
115 echo "</td><td class=pcright>";
116
9c0b0016
DO
117 global $root, $nextorder;
118 $rackwidth = getConfigVar ('rtwidth_0') + getConfigVar ('rtwidth_1') + getConfigVar ('rtwidth_2');
e673ee24
DO
119 $rackList = getRacksForRow ($row_id);
120 $order = 'odd';
121 startPortlet ('Racks');
122 echo "<table border=0 cellspacing=5 align='center'><tr>";
123 foreach ($rackList as $dummy => $rack)
124 {
125 echo "<td align=center class=row_${order}><a href='${root}?page=rack&rack_id=${rack['id']}'>";
9c0b0016
DO
126 echo "<img border=0 width=" . $rackwidth * getConfigVar ('ROW_SCALE') . " height=";
127 echo (3 + 3 + $rack['height'] * 2) * getConfigVar ('ROW_SCALE');
e673ee24
DO
128 echo " title='${rack['height']} units'";
129 echo "src='render_rack_thumb.php?rack_id=${rack['id']}'>";
130 echo "<br>${rack['name']}</a></td>";
131 $order = $nextorder[$order];
132 }
133 echo "</tr></table>\n";
134 finishPortlet();
135
136 echo "</td></tr></table>";
137}
138
139function showError ($info = '')
140{
141 global $root;
142 echo '<div class=msg_error>An error has occured. ';
143 if (empty ($info))
144 echo 'No additional information is available.';
145 else
146 echo "Additional information:<br><p>\n<pre>\n${info}\n</pre></p>";
147 echo "Go back or try starting from <a href='${root}'>index page</a>.<br></div>\n";
148}
149
150// This function renders rack as HTML table.
151function renderRack ($rack_id = 0, $hl_obj_id = 0)
152{
153 if ($rack_id == 0)
154 {
155 showError ('Invalid rack_id in renderRack()');
156 return;
157 }
158 if (($rackData = getRackData ($rack_id)) == NULL)
159 {
160 showError ('getRackData() failed in renderRack()');
161 return;
162 }
163 global $root, $pageno, $tabno;
164 markAllSpans ($rackData);
165 if ($hl_obj_id > 0)
166 highlightObject ($rackData, $hl_obj_id);
167 markupObjectProblems ($rackData);
168 $prev_id = getPrevIDforRack ($rackData['row_id'], $rack_id);
169 $next_id = getNextIDforRack ($rackData['row_id'], $rack_id);
170 echo "<center>\n<h2><a href='${root}?page=row&row_id=${rackData['row_id']}'>${rackData['row_name']}</a> :";
171 // FIXME: use 'bypass'?
172 if ($prev_id != NULL)
173 echo " <a href='${root}?page=rack&rack_id=${prev_id}'>&lt; &lt; &lt;</a>";
174 echo " <a href='${root}?page=rack&rack_id=${rackData['id']}'>${rackData['name']}</a>";
175 if ($next_id != NULL)
176 echo " <a href='${root}?page=rack&rack_id=${next_id}'>&gt; &gt; &gt;</a>";
177 echo "</h2>\n";
178 echo "<table class=rack border=0 cellspacing=0 cellpadding=1>\n";
179 echo "<tr><th width='10%'>&nbsp;</th><th width='20%'>Front</th>";
180 echo "<th width='50%'>Interior</th><th width='20%'>Back</th></tr>\n";
181 for ($i = $rackData['height']; $i > 0; $i--)
182 {
183 echo "<tr><th>$i</th>";
184 for ($locidx = 0; $locidx < 3; $locidx++)
185 {
186 if (isset ($rackData[$i][$locidx]['skipped']))
187 continue;
188 $state = $rackData[$i][$locidx]['state'];
189 echo "<td class=state_${state}";
190 if (isset ($rackData[$i][$locidx]['hl']))
191 echo $rackData[$i][$locidx]['hl'];
192 if (isset ($rackData[$i][$locidx]['colspan']))
193 echo ' colspan=' . $rackData[$i][$locidx]['colspan'];
194 if (isset ($rackData[$i][$locidx]['rowspan']))
195 echo ' rowspan=' . $rackData[$i][$locidx]['rowspan'];
196 echo ">";
197 switch ($state)
198 {
199 case 'T':
200 $objectData = getObjectInfo ($rackData[$i][$locidx]['object_id']);
201 if (!empty ($objectData['asset_no']))
202 $prefix = "<div title='${objectData['asset_no']}";
203 else
204 $prefix = "<div title='no asset tag";
205 // Don't tell about label, if it matches common name.
206 if ($objectData['name'] != $objectData['label'] and !empty ($objectData['label']))
207 $suffix = ", visible label is \"${objectData['label']}\"'>";
208 else
209 $suffix = "'>";
210 echo $prefix . $suffix;
211 echo "<a href='${root}?page=object&object_id=${objectData['id']}'>${objectData['dname']}</a></div>";
212 break;
213 case 'A':
214 echo '<div title="This rackspace does not exist">&nbsp;</div>';
215 break;
216 case 'F':
217 echo '<div title="Free rackspace">&nbsp;</div>';
218 break;
219 case 'U':
220 echo '<div title="Problematic rackspace, you CAN\'T mount here">&nbsp;</div>';
221 break;
222 default:
223 echo '<div title="No data">&nbsp;</div>';
224 break;
225 }
226 echo '</td>';
227 }
228 echo "</tr>\n";
229 }
230 echo "</table></center>\n";
231}
232
233function renderNewObjectForm ()
234{
235 global $pageno, $tabno;
236
237 // Look for current submit.
238 if (isset ($_REQUEST['got_data']))
239 {
240 $log = array();
241 assertUIntArg ('object_type_id');
242 assertStringArg ('object_name', TRUE);
243 assertStringArg ('object_label', TRUE);
244 assertStringArg ('object_barcode', TRUE);
245 assertStringArg ('object_asset_no', TRUE);
246 $type_id = $_REQUEST['object_type_id'];
247 $name = $_REQUEST['object_name'];
248 $label = $_REQUEST['object_label'];
249 $asset_no = $_REQUEST['object_asset_no'];
250 $barcode = $_REQUEST['object_barcode'];
251
252 if (commitAddObject ($name, $label, $barcode, $type_id, $asset_no) === TRUE)
253 $log[] = array ('code' => 'success', 'message' => "Added new object '${name}'");
254 else
255 $log[] = array ('code' => 'error', 'message' => 'commitAddObject() failed in renderNewObjectForm()');
256 printLog ($log);
257 }
258
259 // Render a form for the next.
260 startPortlet ('Object attributes');
261 echo '<form>';
262 echo "<input type=hidden name=page value=${pageno}>";
263 echo "<input type=hidden name=tab value=${tabno}>";
264 echo '<table border=0 align=center>';
265 echo "<tr><th class=tdright>Type:</th><td class=tdleft>";
266 printSelect (getObjectTypeList(), 'object_type_id');
267 echo "</td></tr>\n";
268 echo "<tr><th class=tdright>Common name:</th><td class=tdleft><input type=text name=object_name></td></tr>\n";
269 echo "<tr><th class=tdright>Visible label:</th><td class=tdleft><input type=text name=object_label></td></tr>\n";
270 echo "<tr><th class=tdright>Asset tag:</th><td class=tdleft><input type=text name=object_asset_no></td></tr>\n";
271 echo "<tr><th class=tdright>Barcode:</th><td class=tdleft><input type=text name=object_barcode></td></tr>\n";
272 echo "<tr><td class=submit colspan=2><input type=submit name=got_data value='Create'></td></tr>\n";
273 echo '</form></table>';
274 finishPortlet();
275}
276
277function renderNewRackForm ($row_id)
278{
279 global $pageno, $tabno;
280
281 // Look for current submit.
282 if (isset ($_REQUEST['got_data']))
283 {
284 $log = array();
285 assertStringArg ('rack_name');
286 assertUIntArg ('rack_height');
287 assertStringArg ('rack_comment', TRUE);
288 $name = $_REQUEST['rack_name'];
289 $height = $_REQUEST['rack_height'];
290 $comment = $_REQUEST['rack_comment'];
291
292 if (commitAddRack ($name, $height, $row_id, $comment) === TRUE)
293 $log[] = array ('code' => 'success', 'message' => "Added new rack '${name}'");
294 else
295 $log[] = array ('code' => 'error', 'message' => 'commitAddRack() failed in renderNewRackForm()');
296 printLog ($log);
297 }
298
299 // Render a form for the next.
300 startPortlet ('Rack attributes');
301 echo '<form>';
302 echo "<input type=hidden name=page value=${pageno}>";
303 echo "<input type=hidden name=tab value=${tabno}>";
304 echo "<input type=hidden name=row_id value=${row_id}>";
305 echo '<table border=0 align=center>';
306 echo "<tr><th class=tdright>Name (required):</th><td class=tdleft><input type=text name=rack_name></td></tr>\n";
307 echo "<tr><th class=tdright>Height in units (required):</th><td class=tdleft><input type=text name=rack_height></td></tr>\n";
308 echo "<tr><th class=tdright>Comment:</th><td class=tdleft><input type=text name=rack_comment></td></tr>\n";
309 echo "<tr><td class=submit colspan=2><input type=submit name=got_data value='Create'></td></tr>\n";
310 echo '</form></table>';
311 finishPortlet();
312}
313
314function renderEditObjectForm ($object_id)
315{
316 showMessageOrError();
317 // Handle submit.
318 if (isset ($_REQUEST['got_data']))
319 {
320 $log = array();
321 // object_id is already verified by page handler
322 assertUIntArg ('object_type_id');
323 assertStringArg ('object_name', TRUE);
324 assertStringArg ('object_label', TRUE);
325 assertStringArg ('object_barcode', TRUE);
326 assertStringArg ('object_asset_no', TRUE);
327 $type_id = $_REQUEST['object_type_id'];
328 if (isset ($_REQUEST['object_has_problems']) and $_REQUEST['object_has_problems'] == 'on')
329 $has_problems = 'yes';
330 else
331 $has_problems = 'no';
332 $name = $_REQUEST['object_name'];
333 $label = $_REQUEST['object_label'];
334 $barcode = $_REQUEST['object_barcode'];
335 $asset_no = $_REQUEST['object_asset_no'];
336 $comment = $_REQUEST['object_comment'];
337
338 if (commitUpdateObject ($object_id, $name, $label, $barcode, $type_id, $has_problems, $asset_no, $comment) === TRUE)
339 $log[] = array ('code' => 'success', 'message' => "Updated object '${name}'");
340 else
341 $log[] = array ('code' => 'error', 'message' => 'commitUpdateObject() failed in renderEditObjectForm()');
342 printLog ($log);
343 }
344
345 global $pageno, $tabno;
346 $object = getObjectInfo ($object_id);
347 if ($object == NULL)
348 {
349 showError ('getObjectInfo() failed in renderEditObjectForm()');
350 return;
351 }
352
353 // Render a form for the next submit;
354 echo '<table border=0 width=100%><tr>';
355
356 echo '<td class=pcleft>';
357 startPortlet ('Static attributes');
358 echo '<form>';
359 echo "<input type=hidden name=page value=${pageno}>";
360 echo "<input type=hidden name=tab value=${tabno}>";
361 echo "<input type=hidden name=object_id value=${object_id}>";
362 echo '<table border=0 align=center>';
363 echo "<tr><th class=tdright>Type:</th><td class=tdleft>";
364 printSelect (getObjectTypeList(), 'object_type_id', $object['objtype_id']);
365 echo "</td></tr>\n";
366 // Common attributes.
367 echo "<tr><th class=tdright>Common name:</th><td class=tdleft><input type=text name=object_name value='${object['name']}'></td></tr>\n";
368 echo "<tr><th class=tdright>Visible label:</th><td class=tdleft><input type=text name=object_label value='${object['label']}'></td></tr>\n";
369 echo "<tr><th class=tdright>Asset tag:</th><td class=tdleft><input type=text name=object_asset_no value='${object['asset_no']}'></td></tr>\n";
370 echo "<tr><th class=tdright>Barcode:</th><td class=tdleft><input type=text name=object_barcode value='${object['barcode']}'></td></tr>\n";
371 echo "<tr><th class=tdright>Has problems:</th><td class=tdleft><input type=checkbox name=object_has_problems";
372 if ($object['has_problems'] == 'yes')
373 echo ' checked';
374 echo "></td></tr>\n";
375 echo "<tr><td colspan=2><b>Comment:</b><br><textarea name=object_comment rows=10 cols=80>${object['comment']}</textarea></td></tr>";
376 echo "<tr><th class=submit colspan=2><input type=submit name=got_data value='Update'></td></tr>\n";
377 echo '</form></table><br>';
378 finishPortlet();
379 echo '</td>';
380
381 // Optional attributes.
382 echo '<td class=pcright>';
383 startPortlet ('Optional attributes');
384 $values = getAttrValues ($object_id);
385 global $root;
386 echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
387 echo "<tr><th>&nbsp;</th><th>Attribute</th><th>Value</th><th>&nbsp;</th></tr>\n";
388 foreach ($values as $record)
389 {
390 echo "<form method=post action='${root}process.php'>";
391 echo "<input type=hidden name=page value=${pageno}>";
392 echo "<input type=hidden name=tab value=${tabno}>";
393 echo "<input type=hidden name=op value=upd>";
394 echo "<input type=hidden name=object_id value=${object_id}>";
395 echo "<input type=hidden name=attr_id value=${record['id']}>";
396 echo "<tr><td><a href=${root}process.php?page=${pageno}&tab=${tabno}&op=del&object_id=${object_id}&attr_id=${record['id']}>";
397 printImageHREF ('delete', 'Delete value');
398 echo "</a></td>";
399 echo "<td class=tdright>${record['name']}:</td><td class=tdleft>";
400 switch ($record['type'])
401 {
402 case 'uint':
403 case 'float':
404 case 'string':
405 echo "<input type=text name=value value='${record['value']}'>";
406 break;
407 case 'dict':
408 $chapter = readChapter ($record['chapter_name']);
409 $chapter[] = array ('dict_key' => 0, 'dict_value' => '-- NOT SET --');
410 printSelect ($chapter, 'value', $record['key']);
411 break;
412 }
413 echo "</td>";
414 echo "<td><input type=submit value='OK'></td></tr>\n";
415 echo "</form>";
416 }
417 echo "</table>\n";
418 finishPortlet();
419 echo '</td>';
420
421 echo '</tr><tr>';
422
423 echo '<td colspan=2>';
424 startPortlet ('history');
425 renderHistory ($pageno, $object_id);
426 finishPortlet();
427 echo '</td>';
428
429 echo '</tr></table>';
430}
431
432// This is a clone of renderEditObjectForm().
433function renderEditRackForm ($rack_id)
434{
435 // Handle submit.
436 if (isset ($_REQUEST['got_data']))
437 {
438 $log = array();
439 assertUIntArg ('rack_row_id');
440 assertUIntArg ('rack_height');
441 assertStringArg ('rack_name');
442 assertStringArg ('rack_comment', TRUE);
443 $row_id = $_REQUEST['rack_row_id'];
444 $height = $_REQUEST['rack_height'];
445 $name = $_REQUEST['rack_name'];
446 $comment = $_REQUEST['rack_comment'];
447
448 if (commitUpdateRack ($rack_id, $name, $height, $row_id, $comment) === TRUE)
449 $log[] = array ('code' => 'success', 'message' => "Updated rack '${name}'");
450 else
451 $log[] = array ('code' => 'error', 'message' => 'commitUpdateRack() failed in renderEditRackForm()');
452 printLog ($log);
453 }
454
455 global $pageno, $tabno;
456 $rack = getRackData ($rack_id);
457 if ($rack == NULL)
458 {
459 showError ('getRackData() failed in renderEditRackForm()');
460 return;
461 }
462
463 // Render a form for the next.
464 startPortlet ('Rack attributes');
465 echo '<form>';
466 echo "<input type=hidden name=page value=${pageno}>";
467 echo "<input type=hidden name=tab value=${tabno}>";
468 echo "<input type=hidden name=rack_id value=${rack_id}>";
469 echo '<table border=0 align=center>';
470 echo "<tr><th class=tdright>Rack row:</th><td class=tdleft>";
471 printSelect (getRackRowInfo(), 'rack_row_id', $rack['row_id']);
472 echo "</td></tr>\n";
473 echo "<tr><th class=tdright>Name (required):</th><td class=tdleft><input type=text name=rack_name value='${rack['name']}'></td></tr>\n";
474 echo "<tr><th class=tdright>Height (required):</th><td class=tdleft><input type=text name=rack_height value='${rack['height']}'></td></tr>\n";
475 echo "<tr><th class=tdright>Comment:</th><td class=tdleft><input type=text name=rack_comment value='${rack['comment']}'></td></tr>\n";
476 echo "<tr><td class=submit colspan=2><input type=submit name=got_data value='Update'></td></tr>\n";
477 echo '</form></table><br>';
478 finishPortlet();
479
480 startPortlet ('History');
481 renderHistory ($pageno, $rack_id);
482 finishPortlet();
483}
484
485// This is a helper for creators and editors.
486function printSelect ($rowList, $select_name, $selected_id = 1)
487{
488 echo "<select name=${select_name}>";
489 foreach ($rowList as $dummy => $data)
490 {
491 echo "<option value=${data['dict_key']}";
492 if ($data['dict_key'] == $selected_id)
493 echo ' selected';
494 echo ">${data['dict_value']}</option>";
495 }
496 echo "</select>";
497}
498
499// This is a universal editor of rack design/waste.
bb09cca0 500function renderGridForm ($rack_id = 0, $filter, $header, $submit, $state1, $state2)
e673ee24
DO
501{
502 if ($rack_id == 0)
503 {
504 showError ('Invalid rack_id in renderGridFrom()');
505 return;
506 }
507 if (($rackData = getRackData ($rack_id)) == NULL)
508 {
509 showError ('getRackData() failed in renderGridFrom()');
510 return;
511 }
512
513 global $root, $pageno, $tabno;
514 $filter($rackData);
515 markupObjectProblems ($rackData);
516
517 // Process form submit.
518 if (isset ($_REQUEST['do_update']))
519 {
520 $log[] = processGridForm ($rackData, $state1, $state2);
521 printLog($log);
522 }
523
524 // Render the result whatever it is.
525 // Main layout.
526 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
527 echo "<tr><td colspan=2 align=center><h1>${rackData['name']}</h1></td></tr>\n";
528
529 // Left column with information portlet.
530 echo "<tr><td class=pcleft height='1%' width='50%'>";
531 startPortlet ('Rack information');
532 echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
533 echo "<tr><th width='50%' class=tdright>Rack name:</th><td class=tdleft>${rackData['name']}</td></tr>\n";
534 echo "<tr><th width='50%' class=tdright>Height:</th><td class=tdleft>${rackData['height']}</td></tr>\n";
535 echo "<tr><th width='50%' class=tdright>Rack row:</th><td class=tdleft>${rackData['row_name']}</td></tr>\n";
536 echo "<tr><th width='50%' class=tdright>Comment:</th><td class=tdleft>${rackData['comment']}</td></tr>\n";
537 echo "</table>\n";
538 finishPortlet();
539
540 echo "</td>\n";
bb09cca0 541 echo "<td class=pcright>";
e673ee24
DO
542
543 // Grid form.
544 startPortlet ($header);
545 echo "<center>\n";
546 echo "<table class=rack border=0 cellspacing=0 cellpadding=1>\n";
547 echo "<tr><th width='10%'>&nbsp;</th><th width='20%'>Front</th>";
548 echo "<th width='50%'>Interior</th><th width='20%'>Back</th></tr>\n";
549 echo "<form action='${root}?'>\n";
550 echo "<input type=hidden name=page value=${pageno}>\n";
551 echo "<input type=hidden name=tab value=${tabno}>\n";
552 echo "<input type=hidden name=rack_id value=${rack_id}>\n";
553 markupAtomGrid ($rackData, $state2);
554 renderAtomGrid ($rackData);
555 echo "</table></center>\n";
556 echo "<br><input type=submit name=do_update value='${submit}'></form><br><br>\n";
557 finishPortlet();
bb09cca0 558 echo "</td></tr></table>\n";
e673ee24
DO
559}
560
561function renderRackDesign ($rack_id)
562{
bb09cca0 563 renderGridForm ($rack_id, 'applyRackDesignMask', 'Rack design', 'Set rack design', 'A', 'F');
e673ee24
DO
564}
565
566function renderRackProblems ($rack_id = 0)
567{
bb09cca0 568 renderGridForm ($rack_id, 'applyRackProblemMask', 'Rack problems', 'Mark unusable atoms', 'F', 'U');
e673ee24
DO
569}
570
571function startPortlet ($title = '')
572{
573 echo "<div class=portlet><h2>${title}</h2>";
574}
575
576function finishPortlet ()
577{
578 echo "</div>\n";
579}
580
581function printRefsOfType ($refs, $type, $eq)
582{
583 global $root;
584 $gotone=0;
585 foreach ($refs as $ref)
586 {
587 if ($eq($ref['type'], $type))
588 {
589 if ($gotone) echo ', ';
590 echo "<a href='${root}?page=object&object_id=${ref['object_id']}'>${ref['object_name']}</a>";
591 $gotone=1;
592 }
593 }
594}
595
596function renderRackObject ($object_id = 0)
597{
598 global $root;
599 if ($object_id <= 0)
600 {
601 showError ('Invalid object_id in renderRackObject()');
602 return;
603 }
604 $info = getObjectInfo ($object_id);
605 if ($info == NULL)
606 {
607 showError ('getObjectInfo() failed in renderRackObject()');
608 return;
609 }
610 // Main layout starts.
611 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
612 echo "<tr><td colspan=2 align=center><h1>${info['dname']}</h1></td></tr>\n";
613 // left column with uknown number of portlets
614 echo "<tr><td class=pcleft>";
615 startPortlet ('Object information');
616 echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
617 if (!empty ($info['name']))
618 echo "<tr><th width='50%' class=tdright>Common name:</th><td class=tdleft>${info['name']}</td></tr>\n";
9c0b0016 619 elseif (in_array ($info['objtype_id'], explode (',', getConfigVar ('NAMEFUL_OBJTYPES'))))
a0ec6295 620 echo "<tr><td colspan=2 class=msg_error>Common name is missing.</td></tr>\n";
e673ee24
DO
621 echo "<tr><th width='50%' class=tdright>Object type:</th><td class=tdleft>${info['objtype_name']}</td></tr>\n";
622 if (!empty ($info['asset_no']))
623 echo "<tr><th width='50%' class=tdright>Asset tag:</th><td class=tdleft>${info['asset_no']}</td></tr>\n";
9c0b0016 624 elseif (in_array ($info['objtype_id'], explode (',', getConfigVar ('NAMEFUL_OBJTYPES'))))
a0ec6295 625 echo "<tr><td colspan=2 class=msg_error>Asset tag is missing.</td></tr>\n";
e673ee24
DO
626 if (!empty ($info['label']))
627 echo "<tr><th width='50%' class=tdright>Visible label:</th><td class=tdleft>${info['label']}</td></tr>\n";
628 if (!empty ($info['barcode']))
629 echo "<tr><th width='50%' class=tdright>Barcode:</th><td class=tdleft>${info['barcode']}</td></tr>\n";
630 if ($info['has_problems'] == 'yes')
631 echo "<tr><td colspan=2 class=msg_error>Has problems</td></tr>\n";
632 foreach (getAttrValues ($object_id) as $record)
633 if (!empty ($record['value']))
634 echo "<tr><th width='50%' class=opt_attr_th>${record['name']}:</th><td class=tdleft>${record['value']}</td></tr>\n";
635 echo "</table><br>\n";
636 finishPortlet();
637
638 if (!empty ($info['comment']))
639 {
640 startPortlet ('Comment');
641 echo '<div class=commentblock>' . $info['comment'] . '</div>';
642 finishPortlet ();
643 }
644
645 $ports = getObjectPortsAndLinks ($object_id);
646 if (count ($ports))
647 {
648 startPortlet ('Ports and links');
649 usort($ports, 'sortByName');
650 if ($ports)
651 {
652 $hl_port_id = 0;
653 if (isset ($_REQUEST['hl_port_id']))
654 {
655 assertUIntArg ('hl_port_id');
656 $hl_port_id = $_REQUEST['hl_port_id'];
657 }
658 echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
659 echo "<tr><th>Local name</th><th>Visible label</th><th>Port type</th><th>L2 address</th>";
660 echo "<th>Rem. Object</th><th>Rem. port</th></tr>\n";
661 foreach ($ports as $port)
662 {
663 echo '<tr';
664 if ($hl_port_id == $port['id'])
665 echo ' class=port_highlight';
666 echo "><td>${port['name']}</td><td>${port['label']}</td><td>${port['type']}</td>";
667 echo "<td>${port['l2address']}</td>";
668 if ($port['remote_object_id'])
669 {
670 echo "<td><a href='${root}?page=object&object_id=${port['remote_object_id']}'>${port['remote_object_name']}</a></td>";
671 echo "<td>${port['remote_name']}</td>";
672 }
673 elseif (!empty ($port['reservation_comment']))
674 {
675 echo "<td><b>Reserved;</b></td>";
676 echo "<td>${port['reservation_comment']}</td>";
677 }
678 else
679 echo '<td>&nbsp;</td><td>&nbsp;</td>';
680 echo "</tr>\n";
681 }
682 echo "</table><br>\n";
683 }
684 finishPortlet();
685 }
686 $addresses = getObjectAddresses ($object_id);
687 usort($addresses, 'sortAddresses');
688 if (count ($addresses))
689 {
690 startPortlet ('Network addresses');
691 echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
692 echo "<tr><th>Interface name</th><th>IP Address</th><th>Description</th><th>Misc</th></tr>\n";
693 foreach ($addresses as $addr)
694 {
695 if (strlen($addr['address_name'])>40)
696 $address_name = substr($addr['address_name'],0,38).'...';
697 else
698 $address_name = $addr['address_name'];
699
700 $virtnum = countRefsOfType($addr['references'], 'virtual', 'eq');
701 $sharednum = countRefsOfType($addr['references'], 'shared', 'eq');
702 $regnum = countRefsOfType($addr['references'], 'regular', 'eq');
703 $notvirtnum = countRefsOfType($addr['references'], 'virtual', 'neq');
704
705 if ($addr['address_reserved']=='yes')
706 $class='trwarning';
707 elseif ($addr['type']!='virtual' && $regnum>0)
708 $class='trwarning';
709 elseif ($addr['type']=='regular' && $sharednum>0)
710 $class='trwarning';
711 else
712 $class='';
713
714 echo "<tr class='$class'><td>${addr['name']}</td><td><a href='${root}?page=ipaddress&ip=${addr['ip']}'>${addr['ip']}</a></td><td class='description'>$address_name</td><td>\n";
715
716 if ($addr['address_reserved']=='yes')
717 echo "<b>Reserved;</b> ";
718
719 if ($addr['type'] == 'virtual')
720 {
721 echo "<b>V</b>";
722 if ($notvirtnum > 0)
723 {
724 echo " Owners: ";
725 printRefsOfType($addr['references'], 'virtual', 'neq');
726 }
727 }
728 elseif ($addr['type'] == 'shared')
729 {
730 echo "<b>S</b>";
731 if ($sharednum > 0)
732 {
733 echo " Peers: ";
734 printRefsOfType($addr['references'], 'shared', 'eq');
735 echo ";";
736 }
737 if ($virtnum > 0)
738 {
739 echo " Virtuals: ";
740 printRefsOfType($addr['references'], 'virtual', 'eq');
741 echo ";";
742 }
743 if ($regnum > 0)
744 {
745 echo " Collisions: ";
746 printRefsOfType($addr['references'], 'regular', 'eq');
747 }
748
749 }
750 else
751 {
752 if ($virtnum > 0)
753 {
754 echo " Virtuals: ";
755 printRefsOfType($addr['references'], 'virtual', 'eq');
756 echo ";";
757 }
758 if ($notvirtnum > 0)
759 {
760 echo " Collisions: ";
761 printRefsOfType($addr['references'], 'virtual', 'neq');
762 }
763 }
764
765 echo "</td></tr>\n";
766 }
767 echo "</table><br>\n";
768 finishPortlet();
769 }
770
771 $forwards = getObjectForwards ($object_id);
772 if (count($forwards['in']) or count($forwards['out']))
773 {
774 startPortlet('Port Forwarding');
775
776 if (count($forwards['out']))
777 {
778
779 echo "<h3>Forwarding out:</h3>";
780
781 echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
782 echo "<tr><th>Source</th><th>Target</th><th>Target Objects</th><th>Description</th></tr>\n";
783
784 foreach ($forwards['out'] as $pf)
785 {
786 $class='trwarning';
787 $name='';
788 foreach ($addresses as $addr)
789 if ($addr['ip'] == $pf['localip'])
790 {
791 $class='';
792 $name=$addr['name'];
793 break;
794 }
795
796 echo "<tr class='$class'>";
797
798 echo "<td>${pf['proto']}/$name:<a href='${root}?page=ipaddress&tab=default&ip=${pf['localip']}'>${pf['localip']}</a>:${pf['localport']}</td>";
799
800 echo "<td><a href='${root}?page=ipaddress&tab=default&ip=${pf['remoteip']}'>${pf['remoteip']}</a>:${pf['remoteport']}</td>";
801
802 $address=getIPAddress($pf['remoteip']);
803
804 echo "<td class='description'>";
805 foreach($address['bonds'] as $bond)
806 echo "<a href='${root}?page=object&tab=default&object_id=${bond['object_id']}'>${bond['object_name']}(${bond['name']})</a> ";
807
808 echo "</td><td class='description'>${pf['description']}</td>";
809
810 echo "</tr>";
811 }
812 echo "</table><br><br>";
813 }
814 if (count($forwards['in']))
815 {
816 echo "<h3>Forwarded from:</h3>";
817
818 echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
819 echo "<tr><th>Source</th><th>Source objects</th><th>Target</th><th>Description</th></tr>\n";
820
821 foreach ($forwards['in'] as $pf)
822 {
823 echo "<tr>";
824 echo "<td>${pf['proto']}/<a href='${root}?page=ipaddress&tab=default&ip=${pf['localip']}'>${pf['localip']}</a>:${pf['localport']}</td>";
825
826 echo "<td class='description'><a href='${root}?page=object&tab=default&object_id=${pf['object_id']}'>${pf['object_name']}</a>";
827
828 echo "</td><td><a href='${root}?page=ipaddress&tab=default&ip=${pf['remoteip']}'>${pf['remoteip']}</a>:${pf['remoteport']}</td>";
829 echo "<td class='description'>${pf['description']}</td></tr>";
830 }
831
832 echo "</table><br><br>";
833 }
834 finishPortlet();
835 }
836
837 echo "</td>\n";
838
839 // After left column we have (surprise!) right column with rackspace portled only.
840 echo "<td class=pcright>";
841 // rackspace portlet
842 startPortlet ('Rackspace allocation');
843 // FIXME: now we call getRackData() twice
844 $racks = getResidentRacksData ($object_id);
845 foreach ($racks as $rackData)
846 renderRack ($rackData['id'], $object_id);
847 echo '<br>';
848 finishPortlet();
849 echo "</td></tr>";
850 echo "</table>\n";
851}
852
853function renderRackMultiSelect ($sname, $racks, $selected)
854{
9c0b0016 855 echo "<select name=${sname} multiple size=" . getConfigVar ('MAXSELSIZE') . " onchange='getElementById(\"racks\").submit()'>\n";
e673ee24
DO
856 foreach ($racks as $rack)
857 {
858 echo "<option value=${rack['id']}";
859 if (!(array_search ($rack['id'], $selected) === FALSE))
860 echo ' selected';
861 echo">${rack['name']}</option>\n";
862 }
863 echo "</select>\n";
864}
865
866function showMessageOrError ()
867{
868 if (isset($_REQUEST['message']))
869 echo "<div class=msg_success>${_REQUEST['message']}</div>";
870 if (isset($_REQUEST['error']))
871 echo "<div class=msg_error>${_REQUEST['error']}</div>";
872}
873
874// This function renders a form for port edition.
875function renderPortsForObject ($object_id = 0)
876{
877 global $root, $pageno, $tabno;
878 if ($object_id <= 0)
879 {
880 showError ('Invalid object_id in renderPortsForObject()');
881 return;
882 }
883 showMessageOrError();
884 startPortlet ('Ports and interfaces');
885 $ports = getObjectPortsAndLinks ($object_id);
886 usort($ports, 'sortByName');
887 echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
888 echo "<tr><th>&nbsp;</th><th>Local name</th><th>Visible label</th><th>Port type</th><th>L2 address</th>";
889 echo "<th>Rem. object</th><th>Rem. port</th><th>(Un)link or (un)reserve</th><th>&nbsp;</th></tr>\n";
890 foreach ($ports as $port)
891 {
892 echo "<form action='${root}process.php'>";
893 echo "<input type=hidden name=op value=editPort>";
894 echo "<input type=hidden name=page value='${pageno}'>\n";
895 echo "<input type=hidden name=tab value='${tabno}'>\n";
896 echo "<input type=hidden name=port_id value='${port['id']}'>";
897 echo "<input type=hidden name=object_id value='$object_id'>\n";
898 echo "<tr><td><a href='${root}process.php?op=delPort&page=${pageno}&tab=${tabno}&port_id=${port['id']}&object_id=$object_id&port_name=${port['name']}'>";
899 printImageHREF ('delete', 'Unlink and Delete this port');
900 echo "</a></td>\n";
901 echo "<td><input type=text name=name value='${port['name']}' size=8></td>";
902 echo "<td><input type=text name=label value='${port['label']}' size=24></td>";
903 echo "<td>${port['type']}</td>\n";
904 echo "<td><input type=text name=l2address value='${port['l2address']}'></td>\n";
905 if ($port['remote_object_id'])
906 {
907 echo "<td><a href='${root}?page=object&object_id=${port['remote_object_id']}'>${port['remote_object_name']}</a></td>";
908 echo "<td>${port['remote_name']}</td>";
909 echo "<td><a href='${root}process.php?op=unlinkPort&page=${pageno}&tab=${tabno}&port_id=${port['id']}&object_id=$object_id&port_name=";
910 echo urlencode ($port['name']);
911 echo "&remote_port_name=${port['remote_name']}&remote_object_name=${port['remote_object_name']}'>";
912 printImageHREF ('unlink', 'Unlink this port');
913 echo "</a></td>";
914 }
915 elseif (!empty ($port['reservation_comment']))
916 {
917 echo "<td><b>Reserved;</b></td>";
918 echo "<td><input type=text name=reservation_comment value='${port['reservation_comment']}'></td>";
919 echo "<td><a href='${root}process.php?op=useup&page=${pageno}&tab=${tabno}&port_id=${port['id']}&object_id=${object_id}'>";
920 printImageHREF ('useup', 'Use up this port');
921 echo "</a></td>";
922 }
923 else
924 {
925 echo "<td>&nbsp;</td><td>&nbsp;</td>";
926 echo "<td>";
927 echo "<a href='javascript:;' onclick='window.open(\"${root}link_helper.php?port=${port['id']}&type=${port['type_id']}&object_id=$object_id&port_name=";
928 echo urlencode ($port['name']);
929 echo "\",\"findlink\",\"height=700, width=400, location=no, menubar=no, resizable=yes, scrollbars=no, status=no, titlebar=no, toolbar=no\");'>";
930 printImageHREF ('link', 'Link this port');
931 echo "</a> <input type=text name=reservation_comment>";
932 echo "</td>\n";
933 }
934 echo "<td><input type='submit' value='OK'></td>";
935 echo "</form></tr>\n";
936 }
937 echo "<form action='${root}process.php'><tr>";
938 echo "<td colspan=2><input type=text size=10 name=port_name tabindex=100></td>\n";
939 echo "<td><input type=text size=24 name=port_label tabindex=101></td>";
940 echo "<input type=hidden name=op value=addPort>\n";
941 echo "<input type=hidden name=object_id value='${object_id}'>\n";
942 echo "<input type=hidden name=page value='${pageno}'>\n";
943 echo "<input type=hidden name=tab value='${tabno}'>\n";
944 echo "<td><select name='port_type_id' tabindex=102>\n";
945 $types = getPortTypes();
9c0b0016 946 $default_port_type = getConfigVar ('default_port_type');
e673ee24
DO
947 foreach ($types as $typeid => $typename)
948 {
949 echo "<option value='${typeid}'";
950 if ($typeid == $default_port_type)
951 echo " selected";
952 echo ">${typename}</option>\n";
953 }
954 echo "</select></td>";
955 echo "<td><input type=text name=port_l2address tabindex=103></td>\n";
956 echo "<td colspan=4><input type='submit' value='Add a new port' tabindex=104></td></tr></form>";
957 echo "</table><br>\n";
958 finishPortlet();
959
960 startPortlet ('Add/update multiple ports');
961 echo "<form action=${root}process.php method=post>";
962 echo "<input type=hidden name=page value='${pageno}'>\n";
963 echo "<input type=hidden name=tab value='${tabno}'>\n";
964 echo "<input type=hidden name=object_id value='${object_id}'>\n";
965 echo "<input type=hidden name=op value=addMultiPorts>";
966 echo 'Format: <select name=format>';
967 echo '<option value=c2900 disabled>Cisco 2900 series: sh int eth</option>';
968 echo '<option value=c3600eth disabled>Cisco 3600 ethernet: sh arp | inc -</option>';
969 echo '<option value=c3600asy>Cisco 3600 async: sh line | inc TTY</option>';
970 echo '<option value=fiwg selected>Foundry ServerIron/FastIron WorkGroup/Edge: sh int br</option>';
971 echo '<option value=fiedge disabled>Foundry FastIron Edge: sh int br</option>';
972 echo '<option value=fisxii>Foundry FastIron SuperX/II4000: sh int br</option>';
973 echo "</select>";
974 echo 'Default port type: ';
975 echo "<select name=port_type>\n";
976 foreach ($types as $typeid => $typename)
977 {
978 echo "<option value='${typeid}'";
979 if ($typeid == $default_port_type)
980 echo " selected";
981 echo ">${typename}</option>\n";
982 }
983 echo "</select>";
984 echo "<input type=submit value='Parse output'><br>\n";
985 echo "<textarea name=input cols=100 rows=50></textarea><br>\n";
986 echo '</form>';
987 finishPortlet();
988}
989
990function renderNetworkForObject ($object_id=0)
991{
992 global $root, $pageno, $tabno;
993 if ($object_id <= 0)
994 {
995 showError ('Invalid object_id in renderNetworkForObject()');
996 return;
997 }
998 showMessageOrError();
999 startPortlet ('Network Addresses');
1000 $addresses = getObjectAddresses ($object_id);
1001 usort($addresses, 'sortAddresses');
1002 echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
1003 echo "<tr><th>&nbsp;</th><th>Interface name</th><th>IP Address</th><th>Description</th><th>Type</th><th>Misc</th><th>&nbsp</th></tr>\n";
1004 foreach ($addresses as $addr)
1005 {
1006 if (strlen($addr['address_name'])>40)
1007 $address_name = substr($addr['address_name'],0,38).'...';
1008 else
1009 $address_name = $addr['address_name'];
1010
1011 $virtnum = countRefsOfType($addr['references'], 'virtual', 'eq');
1012 $sharednum = countRefsOfType($addr['references'], 'shared', 'eq');
1013 $regnum = countRefsOfType($addr['references'], 'regular', 'eq');
1014 $notvirtnum = countRefsOfType($addr['references'], 'virtual', 'neq');
1015
1016 if ($addr['address_reserved']=='yes')
1017 $class='trwarning';
1018 elseif ($addr['type']!='virtual' && $regnum>0)
1019 $class='trwarning';
1020 elseif ($addr['type']=='regular' && $sharednum>0)
1021 $class='trwarning';
1022 else
1023 $class='';
1024
1025 echo "<form action='process.php'>";
1026 echo "<input type=hidden name=page value='${pageno}'>\n";
1027 echo "<input type=hidden name=tab value='${tabno}'>\n";
1028 echo "<input type=hidden name=op value=editAddressFromObject>";
1029 echo "<input type=hidden name=object_id value='$object_id'>";
1030 echo "<input type=hidden name=ip value='${addr['ip']}'>";
1031 echo "<tr class='$class'><td><a href='process.php?op=delAddrFObj&page=${pageno}&tab=${tabno}&ip=${addr['ip']}&object_id=$object_id'>";
1032 printImageHREF ('delete', 'Delete this IPv4 address');
1033 echo "</a></td>";
1034 echo "<td><input type='text' name='bond_name' value='${addr['name']}' size=10></td>";
1035 echo "<td><a href='${root}?page=ipaddress&ip=${addr['ip']}'>${addr['ip']}</a></td>";
1036 echo "<td class='description'>$address_name</td>\n";
1037 echo "<td><select name='bond_type'>";
1038 foreach (array('regular'=>'Regular', 'virtual'=>'Virtual', 'shared'=>'Shared') as $n => $v)
1039 {
1040 echo "<option value='$n'";
1041 if ($addr['type'] == $n)
1042 echo " selected";
1043 echo ">$v</option>";
1044 }
1045 echo "</td><td>";
1046 if ($addr['address_reserved']=='yes')
1047 echo "<b>Reserved</b>; ";
1048
1049 if ($addr['type'] == 'virtual')
1050 {
1051 if ($notvirtnum > 0)
1052 {
1053 echo " Owners: ";
1054 printRefsOfType($addr['references'], 'virtual', 'neq');
1055 }
1056 }
1057 elseif ($addr['type'] == 'shared')
1058 {
1059 if ($sharednum > 0)
1060 {
1061 echo " Peers: ";
1062 printRefsOfType($addr['references'], 'shared', 'eq');
1063 echo ";";
1064 }
1065 if ($virtnum > 0)
1066 {
1067 echo " Virtuals: ";
1068 printRefsOfType($addr['references'], 'virtual', 'eq');
1069 echo ";";
1070 }
1071 if ($regnum > 0)
1072 {
1073 echo " Collisions: ";
1074 printRefsOfType($addr['references'], 'regular', 'eq');
1075 }
1076
1077 }
1078 else
1079 {
1080 if ($virtnum > 0)
1081 {
1082 echo " Virtuals: ";
1083 printRefsOfType($addr['references'], 'virtual', 'eq');
1084 echo ";";
1085 }
1086 if ($notvirtnum > 0)
1087 {
1088 echo " Collisions: ";
1089 printRefsOfType($addr['references'], 'virtual', 'neq');
1090 }
1091 }
1092
1093 echo "</td><td><input type=submit value='OK'></td></form></tr>\n";
1094 }
1095
1096
1097 echo "<form action='${root}process.php'><tr><td colspan=2><input type='text' size='10' name='name' tabindex=100></td>\n";
1098 echo "<input type=hidden name=page value='${pageno}'>\n";
1099 echo "<input type=hidden name=tab value='${tabno}'>\n";
1100 echo "<input type=hidden name=op value=addAddrFObj>\n";
1101 echo "<input type=hidden name=object_id value='$object_id'>\n";
1102
1103 echo "<td><input type=text name='ip' tabindex=101>\n";
1104 echo "</td><td><select name='type' tabindex=102>";
1105 echo "<option value='regular'>Regular</option>";
1106 echo "<option value='virtual'>Virtual</option>";
1107 echo "<option value='shared'>Shared</option>";
1108 echo "</select>";
1109 echo "</td><td colspan=3><input type='submit' value='Add a new interface' tabindex=103></td></tr></form>";
1110 echo "</table><br>\n";
1111 finishPortlet();
1112
1113}
1114
1115function printLog ($log)
1116{
1117 foreach ($log as $record)
1118 echo "<div class=msg_${record['code']}>${record['message']}</div>";
1119}
1120
1121/*
1122The following conditions must be followed:
11231. We can mount onto free atoms only. This means: if any record for an atom
1124already exists in RackSpace, it can't be used for mounting.
11252. We can't unmount from 'W' atoms. Operator should review appropriate comments
1126and either delete them before unmounting or refuse to unmount the object.
1127*/
1128
1129// We extensively use $_REQUEST in the function.
1130function renderRackSpaceForObject ($object_id = 0)
1131{
1132 if ($object_id <= 0)
1133 {
1134 showError ('Invalid object_id in renderRackSpaceForObject()');
1135 return;
1136 }
1137 $is_submit = isset ($_REQUEST['got_atoms']);
1138 $is_update = isset ($_REQUEST['rackmulti'][0]);
1139 $info = getObjectInfo ($object_id);
1140 if ($info == NULL)
1141 {
1142 showError ('getObjectInfo() failed in renderRackSpaceForObject()');
1143 return;
1144 }
1145 // Always process occupied racks plus racks chosen by user. First get racks with
1146 // already allocated rackspace...
1147 $workingRacksData = getResidentRacksData ($object_id);
1148 if ($workingRacksData === NULL)
1149 {
1150 print_r ($workingRacksData);
1151 showError ('getResidentRacksData() failed in renderRackSpaceForObject()');
1152 return;
1153 }
1154
1155 // ...and then add those chosen by user (if any).
1156 if ($is_update)
1157 foreach ($_REQUEST['rackmulti'] as $cand_id)
1158 {
1159 if (!isset ($workingRacksData[$cand_id]))
1160 {
1161 $rackData = getRackData ($cand_id);
1162 if ($rackData == NULL)
1163 {
1164 showError ('getRackData() failed in renderRackSpaceForObject()');
1165 return NULL;
1166 }
1167 $workingRacksData[$cand_id] = $rackData;
1168 }
1169 }
1170
1171 // Do it only once...
1172 foreach ($workingRacksData as &$rackData)
1173 applyObjectMountMask ($rackData, $object_id);
1174 // Now we workaround an old caveat: http://bugs.php.net/bug.php?id=37410
1175 unset ($rackData);
1176
1177 // Here we process form submit by trying to save all submitted info to database.
1178 if ($is_submit)
1179 {
1180 $oldMolecule = getMoleculeForObject ($object_id);
1181 $worldchanged = FALSE;
1182 $log = array();
1183 foreach ($workingRacksData as $rack_id => $rackData)
1184 {
1185 $logrecord = processGridForm ($rackData, 'F', 'T', $object_id);
1186 $log[] = $logrecord;
1187 if ($logrecord['code'] != 300)
1188 {
1189 $worldchanged = TRUE;
1190 // Reload our working copy after form processing.
1191 $rackData = getRackData ($rack_id);
1192 if ($rackData == NULL)
1193 $log[] = array ('code' => 500, 'message' => 'Working copy update failed in renderRackSpaceForObject()');
1194 applyObjectMountMask ($rackData, $object_id);
1195 $workingRacksData[$rack_id] = $rackData;
1196 }
1197 }
1198 if ($worldchanged)
1199 {
1200 // Log a record.
1201 $newMolecule = getMoleculeForObject ($object_id);
1202 $oc = count ($oldMolecule);
1203 $nc = count ($newMolecule);
1204 $omid = $oc ? createMolecule ($oldMolecule) : 'NULL';
1205 $nmid = $nc ? createMolecule ($newMolecule) : 'NULL';
1206 global $remote_username;
1207 $comment = empty ($_REQUEST['comment']) ? 'NULL' : "'${_REQUEST['comment']}'";
1208 $query =
1209 "insert into MountOperation(object_id, old_molecule_id, new_molecule_id, user_name, comment) " .
1210 "values (${object_id}, ${omid}, ${nmid}, '${remote_username}', ${comment})";
1211 global $dbxlink;
1212 $result = $dbxlink->query ($query);
1213 if ($result == NULL)
1214 $log[] = array ('code' => 'error', 'message' => 'SQL query failed during history logging.');
1215 else
1216 $log[] = array ('code' => 'success', 'message' => 'History logged.');
1217 }
1218 printLog ($log);
1219 }
1220
1221 // This is the time for rendering.
1222 global $root, $pageno, $tabno;
1223 echo "<form id='racks' action='${root}'>";
1224 echo "<input type=hidden name=page value='${pageno}'>\n";
1225 echo "<input type=hidden name=tab value='${tabno}'>\n";
1226 echo "<input type=hidden name=object_id value='${object_id}'>\n";
1227 // Main layout starts.
1228 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0><tr>";
1229
1230 // Left portlet with rack list.
1231 echo "<td class=pcleft height='1%'>";
1232 startPortlet ('Racks');
1233 $allRacksData = getRacksForRow();
1234 renderRackMultiSelect ('rackmulti[]', $allRacksData, array_keys ($workingRacksData));
1235 echo "<br>";
1236 echo "<br>";
1237 finishPortlet();
1238 echo "</td>";
1239
1240 // Middle portlet with comment and submit.
1241 echo "<td class=pcleft>";
1242 startPortlet ('Comment');
1243 echo "<textarea name=comment rows=10 cols=40></textarea><br>\n";
1244 echo "<input type=submit value='Save' name=got_atoms>\n";
1245 echo "<br>";
1246 echo "<br>";
1247 finishPortlet();
1248 echo "</td>";
1249
1250 // Right portlet with rendered racks. If this form submit is not final, we have to
1251 // reflect the former state of the grid in current form.
1252 echo "<td class=pcright rowspan=2 height='1%'>";
1253 startPortlet ('Working copy');
1254 echo '<table border=0 cellspacing=10 align=center><tr>';
1255 foreach ($workingRacksData as $rack_id => $rackData)
1256 {
1257 // Order is important here: only original allocation is highlighted.
1258 highlightObject ($rackData, $object_id);
1259 markupAtomGrid ($rackData, 'T');
1260 // If we have a form processed, discard user input and show new database
1261 // contents.
1262 if (!$is_submit and $is_update)
1263 mergeGridFormToRack ($rackData);
1264 echo "<td valign=top>";
1265 echo "<center>\n<h2>${rackData['name']}</h2>\n";
1266 echo "<table class=rack border=0 cellspacing=0 cellpadding=1>\n";
1267 echo "<tr><th width='10%'>&nbsp;</th><th width='20%'>Front</th>";
1268 echo "<th width='50%'>Interior</th><th width='20%'>Back</th></tr>\n";
1269 renderAtomGrid ($rackData);
1270 echo "</table></center>\n";
1271 echo '</td>';
1272 }
1273 echo "</tr></table>";
1274 finishPortlet();
1275 echo "</td>\n";
1276
1277 echo "</form>\n";
1278 echo "</tr></table>\n";
1279}
1280
1281function renderMolecule ($mdata, $object_id)
1282{
1283 // sort data out
1284 $rackpack = array();
1285 global $loclist;
1286 foreach ($mdata as $dummy => $rua)
1287 {
1288 $rack_id = $rua['rack_id'];
1289 $unit_no = $rua['unit_no'];
1290 $atom = $rua['atom'];
1291 if (!isset ($rackpack[$rack_id]))
1292 {
1293 $rackData = getRackData ($rack_id);
1294 for ($i = $rackData['height']; $i > 0; $i--)
1295 for ($locidx = 0; $locidx < 3; $locidx++)
1296 $rackData[$i][$locidx]['state'] = 'F';
1297 $rackpack[$rack_id] = $rackData;
1298 }
1299 $rackpack[$rack_id][$unit_no][$loclist[$atom]]['state'] = 'T';
1300 $rackpack[$rack_id][$unit_no][$loclist[$atom]]['object_id'] = $object_id;
1301 }
1302 // now we have some racks to render
1303 foreach ($rackpack as $dummy => $rackData)
1304 {
1305 markAllSpans ($rackData);
1306 echo "<table class=molecule cellspacing=0>\n";
1307 echo "<caption>${rackData['name']}</caption>\n";
1308 echo "<tr><th width='10%'>&nbsp;</th><th width='20%'>Front</th><th width='50%'>Interior</th><th width='20%'>Back</th></tr>\n";
1309 for ($i = $rackData['height']; $i > 0; $i--)
1310 {
1311 echo "<tr><th>$i</th>";
1312 for ($locidx = 0; $locidx < 3; $locidx++)
1313 {
1314 $state = $rackData[$i][$locidx]['state'];
1315 echo "<td class=state_${state}>&nbsp;</td>\n";
1316 }
1317 echo "</tr>\n";
1318 }
1319 echo "</table>\n";
1320 }
1321}
1322
1323function renderUnmountedObjectsPortlet ()
1324{
1325 startPortlet ('Unmounted objects');
1326 $objs = getUnmountedObjects();
1327 if ($objs === NULL)
1328 {
1329 showError ('getUnmountedObjects() failed in renderUnmountedObjectsPortlet()');
1330 return;
1331 }
1332 global $root, $nextorder;
1333 $order = 'odd';
1334 echo '<br><br><table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
1335 echo '<tr><th>Common name</th><th>Visible label</th><th>Asset number</th></tr>';
1336 foreach ($objs as $obj)
1337 {
1338 echo "<tr class=row_${order}><td><a href='${root}?page=object&object_id=${obj['id']}'>${obj['dname']}</a></td>";
1339 echo "<td>${obj['label']}</td>";
1340 echo "<td>${obj['asset_no']}</td></tr>";
1341 $order = $nextorder[$order];
1342 }
1343 echo "</table><br>\n";
1344 finishPortlet();
1345}
1346
1347function renderProblematicObjectsPortlet ()
1348{
1349 startPortlet ('Problematic objects');
1350 $objs = getProblematicObjects();
1351 if ($objs === NULL)
1352 {
1353 showError ('getProblematicObjects() failed in renderProblematicObjectsPortlet()');
1354 return;
1355 }
1356 global $root, $nextorder;
1357 $order = 'odd';
1358 echo '<br><br><table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
1359 echo '<tr><th>Type</th><th>Common name</th></tr>';
1360 foreach ($objs as $obj)
1361 {
1362 echo "<tr class=row_${order}><td>${obj['objtype_name']}</td>";
1363 echo "<td><a href='${root}?page=object&object_id=${obj['id']}'>${obj['dname']}</a></tr>";
1364 $order = $nextorder[$order];
1365 }
1366 echo "</table><br>\n";
1367 finishPortlet();
1368}
1369
1370function renderObjectGroupSummary ()
1371{
1372 global $root;
1373 $summary = getObjectGroupInfo();
1374 if ($summary === NULL)
1375 {
1376 showError ('getObjectGroupInfo() failed in renderObjectGroupSummary()');
1377 return;
1378 }
1379 echo "<table border=0 class=objectview>\n";
1380 echo "<tr><td class=pcleft width='25%'>";
1381
1382 startPortlet ('Summary');
1383 foreach ($summary as $gi)
1384 {
1385 echo "<a href='${root}?page=objgroup&group_id=${gi['id']}'><b>${gi['name']}</b></a> <i>(${gi['count']})</i><br>";
1386 }
1387 finishPortlet();
1388
1389 echo '</td><td class=pcright>';
1390 renderUnmountedObjectsPortlet();
1391 echo '</td><td class=pcright>';
1392 renderProblematicObjectsPortlet();
1393 echo "</td></tr></table>\n";
1394}
1395
1396function renderObjectGroup ($group_id = 0)
1397{
1398 global $root;
1399 $summary = getObjectGroupInfo();
1400 if ($summary == NULL)
1401 {
1402 showError ('getObjectGroupInfo() failed in renderObjectGroup()');
1403 return;
1404 }
1405 $objects = getObjectList ($group_id);
1406 if ($objects === NULL)
1407 {
1408 showError ('getObjectList() failed in renderObjectGroup()');
1409 return;
1410 }
1411 echo "<table border=0 class=objectview>\n";
1412 echo "<tr><td class=pcleft width='25%'>";
1413
1414 startPortlet ('All objects');
1415 foreach ($summary as $gi)
1416 {
1417 echo "<a href='${root}?page=objgroup&group_id=${gi['id']}'><b>${gi['name']}</b></a> <i>(${gi['count']})</i><br>";
1418 }
1419 finishPortlet();
1420
1421 echo '</td><td class=pcright>';
1422
1423 startPortlet ('Object group');
1424 echo '<br><br><table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
1425 echo '<tr><th>Common name</th><th>Visible label</th><th>Asset tag</th><th>Rack</th></tr>';
1426 $order = 'odd';
1427 global $nextorder;
1428 foreach ($objects as $obj)
1429 {
1430 echo "<tr class=row_${order}><td><a href='${root}?page=object&object_id=${obj['id']}'>${obj['dname']}</a></td>";
1431 echo "<td>${obj['label']}</td>";
1432 echo "<td>${obj['asset_no']}</td>";
1433 if ($obj['rack_id'])
1434 echo "<td><a href='${root}?page=rack&rack_id=${obj['rack_id']}'>${obj['Rack_name']}</a></td>";
1435 else
1436 echo '<td>Unmounted</td>';
1437 echo '</tr>';
1438 $order = $nextorder[$order];
1439 }
1440 echo '</table>';
1441 finishPortlet();
1442
1443 echo "</td></tr></table>";
1444}
1445
1446function renderEmptyPortsSelect ($port_id, $type_id)
1447{
1448 $ports = getEmptyPortsOfType($type_id);
1449 usort($ports, 'sortEmptyPorts');
1450 foreach ($ports as $port)
1451 {
1452 if ($port_id == $port['Port_id'])
1453 continue;
1454 echo "<option value='${port['Port_id']}' onclick='getElementById(\"remote_port_name\").value=\"${port['Port_name']}\"; getElementById(\"remote_object_name\").value=\"${port['Object_name']}\";'>${port['Object_name']} ${port['Port_name']}</option>\n";
1455 }
1456}
1457
1458function renderObjectAddressesAndNames ()
1459{
1460 $addresses = getObjectAddressesAndNames();
1461 usort($addresses, 'sortObjectAddressesAndNames');
1462 foreach ($addresses as $address)
1463 {
1464 echo "<option value='${address['ip']}' onclick='getElementById(\"ip\").value=\"${address['ip']}\";'>${address['object_name']} ${address['name']} ${address['ip']}</option>\n";
1465 }
1466}
1467
1468// History viewer for history-enabled simple dictionaries.
1469function renderHistory ($object_type, $object_id)
1470{
1471 switch ($object_type)
1472 {
1473 case 'row':
1474 $query = "select ctime, user_name, name, deleted, comment from RackRowHistory where id = ${object_id} order by ctime";
1475 $header = '<tr><th>change time</th><th>author</th><th>rack row name</th><th>is deleted?</th><th>rack row comment</th></tr>';
1476 $extra = 4;
1477 break;
1478 case 'rack':
1479 $query =
1480 "select ctime, user_name, rh.name, rh.deleted, d.dict_value as name, rh.height, rh.comment " .
1481 "from RackHistory as rh left join Dictionary as d on rh.row_id = d.dict_key " .
1482 "natural join Chapter " .
1483 "where chapter_name = 'RackRow' and rh.id = ${object_id} order by ctime";
1484 $header = '<tr><th>change time</th><th>author</th><th>rack name</th><th>is deleted?</th><th>rack row name</th><th>rack height</th><th>rack comment</th></tr>';
1485 $extra = 6;
1486 break;
1487 case 'object':
1488 $query =
1489 "select ctime, user_name, name, label, barcode, asset_no, deleted, has_problems, dict_value, comment " .
1490 "from RackObjectHistory inner join Dictionary on objtype_id = dict_key natural join Chapter " .
1491 "where chapter_name = 'RackObjectType' and id=${object_id} order by ctime";
1492 $header = '<tr><th>change time</th><th>author</th><th>common name</th><th>visible label</th><th>barcode</th><th>asset no</th><th>is deleted?</th><th>has problems?</th><th>object type</th><th>comment</th></tr>';
1493 $extra = 9;
1494 break;
1495 default:
1496 showError ("Uknown object type '${object_type}' in renderHistory()");
1497 return;
1498 }
1499 global $dbxlink;
1500 $result = $dbxlink->query ($query);
1501 if ($result == NULL)
1502 {
1503 showError ('SQL query failed in renderHistory()');
1504 return;
1505 }
1506 echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
1507 $order = 'odd';
1508 global $nextorder;
1509 echo $header;
1510 while ($row = $result->fetch (PDO::FETCH_NUM))
1511 {
1512 echo "<tr class=row_${order}><td>${row[0]}</td>";
1513 for ($i = 1; $i <= $extra; $i++)
1514 echo "<td>" . $row[$i] . "</td>";
1515 echo "</tr>\n";
1516 $order = $nextorder[$order];
1517 }
1518 echo "</table><br>\n";
1519}
1520
1521function renderRackspaceHistory ()
1522{
1523 global $root, $nextorder, $pageno, $tabno;
1524 $order = 'odd';
1525 $history = getRackspaceHistory();
1526 // Show the last operation by default.
1527 if (isset ($_REQUEST['op_id']))
1528 $op_id = $_REQUEST['op_id'];
1529 elseif (isset ($history[0]['mo_id']))
1530 $op_id = $history[0]['mo_id'];
1531 else $op_id = NULL;
1532
1533 $omid = NULL;
1534 $nmid = NULL;
1535 $object_id = 1;
1536 if ($op_id)
1537 list ($omid, $nmid) = getOperationMolecules ($op_id);
1538
1539 // Main layout starts.
1540 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
1541
1542 // Left top portlet with old allocation.
1543 echo "<tr><td class=pcleft>";
1544 startPortlet ('Old allocation');
1545 if ($omid)
1546 {
1547 $oldMolecule = getMolecule ($omid);
1548 renderMolecule ($oldMolecule, $object_id);
1549 }
1550 else
1551 echo "nothing";
1552 finishPortlet();
1553
1554 echo '</td><td class=pcright>';
1555
1556 // Right top portlet with new allocation
1557 startPortlet ('New allocation');
1558 if ($nmid)
1559 {
1560 $newMolecule = getMolecule ($nmid);
1561 renderMolecule ($newMolecule, $object_id);
1562 }
1563 else
1564 echo "nothing";
1565 finishPortlet();
1566
1567 echo '</td></tr><tr><td colspan=2>';
1568
1569 // Bottom portlet with list
1570
1571 startPortlet ('Rackspace allocation history');
1572 echo "<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>\n";
1573 echo "<tr><th>timestamp</th><th>author</th><th>rack object ID</th><th>rack object type</th><th>rack object name</th><th>comment</th></tr>\n";
1574 foreach ($history as $row)
1575 {
1576 if ($row['mo_id'] == $op_id)
1577 $class = 'hl';
1578 else
1579 $class = "row_${order}";
1580 echo "<tr class=${class}><td><a href='${root}?page=${pageno}&tab=${tabno}&op_id=${row['mo_id']}'>${row['ctime']}</a></td>";
1581 echo "<td>${row['user_name']}</td>";
1582 echo "<td>${row['ro_id']}</td><td>${row['objtype_name']}</td><td>${row['name']}</td><td>${row['comment']}</td>\n";
1583 echo "</tr>\n";
1584 $order = $nextorder[$order];
1585 }
1586 echo "</table>\n";
1587 finishPortlet();
1588
1589 echo '</td></tr></table>';
1590
1591}
1592
1593function renderAddressspace ()
1594{
1595 global $root;
1596 echo "<table class='widetable' border=0 cellpadding=10 cellspacing=0 align='center'>\n";
1597 $addrspaceList = getAddressspaceList();
1598 echo "<tr><th>Address range</th><th>Name</th><th>Total/used addresses</th></tr>";
1599 foreach ($addrspaceList as $iprange)
1600 {
1601 echo "<tr><td><a href='${root}?page=iprange&id=${iprange['id']}'>${iprange['ip']}/${iprange['mask']}</a></td><td>${iprange['name']}</td><td>";
1602 echo ($iprange['ip_bin'] | $iprange['mask_bin_inv']) - ($iprange['ip_bin'] & $iprange['mask_bin'])+1;
1603 $range = getIPRange($iprange['id']);
1604 echo "/";
1605 echo count($range['addrlist']);
1606 echo "</td></tr>";
1607 }
1608 echo "</table>\n";
1609}
1610
1611function renderAddNewRange ()
1612{
1613 global $root, $pageno, $tabno;
1614 showMessageOrError();
2a201216
DY
1615
1616 echo "<center><h2>Add New Range</h2></center>\n";
1617 echo "<table class='widetable' border=0 cellpadding=10 align='center'>\n";
1618 echo "<tr><th>Address range</th><th>Name</th><th>&nbsp;</th></tr>\n";
1619 echo "<form name='add_new_range' action='process.php'>\n";
1620 echo "<input type=hidden name=op value=addRange>\n";
1621 echo "<input type=hidden name=page value='${pageno}'>\n";
1622 echo "<input type=hidden name=tab value='${tabno}'>\n";
1623 echo "<tr><td class='tdcenter'><input type=text name='range' size=18 class='live-validate'></td>\n";
1624 echo "<td class='tdcenter'><input type=text name='name' size='20'></td>\n";
1625 echo "<td class='tdcenter'><input type=submit value='Add a new range'></td></tr>\n";
1626 echo "</form></table><br><br>\n";
1627
1628 echo "<center><h2>Existing Ranges</h2></center>\n";
1629 echo "<table class='widetable' border=0 cellpadding=10 align='center'>\n";
e673ee24
DO
1630 $addrspaceList = getAddressspaceList();
1631 echo "<tr><th>&nbsp;</th><th>Address range</th><th>Name</th><th>Total/used addresses</th></tr>";
1632 foreach ($addrspaceList as $iprange)
1633 {
1634 $range = getIPRange($iprange['id']);
1635 $usedips = 0;
1636 foreach ($range['addrlist'] as $addr)
1637 if (count($addr['references'])>0 || $addr['reserved']=='yes')
1638 $usedips++;
1639 echo "<tr>";
1640 if ($usedips == 0)
1641 {
1642 echo "<td><a href='process.php?op=delRange&page=${pageno}&tab=${tabno}&id=${iprange['id']}'>";
1643 printImageHREF ('delete', 'Delete this IP range');
1644 echo "</a></td>\n";
1645 }
1646 else
1647 echo "<td>&nbsp</td>";
1648 echo "<td><a href='${root}?page=iprange&id=${iprange['id']}'>${iprange['ip']}/${iprange['mask']}</a></td><td>${iprange['name']}</td><td>";
1649 echo ($iprange['ip_bin'] | $iprange['mask_bin_inv']) - ($iprange['ip_bin'] & $iprange['mask_bin'])+1;
1650 echo "/";
1651 echo $usedips;
2a201216 1652 #echo "</td></tr></table>";
e673ee24
DO
1653 echo "</td></tr>";
1654 }
e673ee24
DO
1655}
1656
1657function renderIPRange ()
1658{
1659 global $root;
1660 $maxperpage=256;
1661 $id = $_REQUEST['id'];
1662 if (isset($_REQUEST['pg']))
1663 $page = $_REQUEST['pg'];
1664 else
1665 $page=0;
1666
1667 $paging=0;
1668
1669 $range = getIPRange($id);
1670 echo "<center><h1>${range['ip']}/${range['mask']}</h1><h2>${range['name']}</h2></center>\n";
1671
1672
1673 $startip = $range['ip_bin'] & $range['mask_bin'];
1674 $endip = $range['ip_bin'] | $range['mask_bin_inv'];
1675 $realstartip = $startip;
1676 $realendip = $endip;
1677 $numpages = 0;
1678 if($endip - $startip > $maxperpage)
1679 {
1680 $paging=1;
1681 $numpages = ($endip - $startip)/$maxperpage;
1682 $startip = $startip + $page * $maxperpage;
1683 $endip = $startip + $maxperpage-1;
1684 }
1685 echo "<center>";
1686 for ($i=0; $i<$numpages; $i++)
1687 {
1688 if ($i == $page)
1689 echo "<b>$i</b> ";
1690 else
1691 echo "<a href='${root}?page=iprange&id=$id&pg=$i'>$i</a> ";
1692 }
1693 echo "</center>";
1694
1695 echo "<table class='widetable' border=0 cellspacing=0 cellpadding=5 align='center'>\n";
1696 echo "<tr><th>Address</th><th>Name</th><th>Allocation</th></tr>\n";
1697
1698
1699 for($ip = $startip; $ip<=$endip; $ip++)
1700 {
1701 if ( (isset($range['addrlist'][$ip])) && ($range['addrlist'][$ip]['ip_bin'] == $ip) )
1702 {
1703 $numshared = countRefsOfType($range['addrlist'][$ip]['references'], 'shared', 'eq');
1704 $numreg = countRefsOfType($range['addrlist'][$ip]['references'], 'regular', 'eq');
1705 $numvirt = countRefsOfType($range['addrlist'][$ip]['references'], 'virtual', 'eq');
1706
1707 $addr = $range['addrlist'][$ip];
1708 if ( ($numshared > 0 && $numreg > 0) || $numreg > 1 )
1709 echo "<tr class='trwarning'>";
1710 elseif ( $addr['reserved'] == 'yes' and $numshared+$numreg+$numvirt > 0)
1711 echo "<tr class='trwarning'>";
1712 elseif ( $addr['reserved'] == 'yes')
1713 echo "<tr class='trbusy'>";
1714 elseif ( $numshared > 0 || $numreg > 0)
1715 echo "<tr class='trbusy'>";
1716 else
1717 echo "<tr>";
1718
1719 echo "<td><a href='${root}?page=ipaddress&ip=${addr['ip']}'>${addr['ip']}</a></td><td>${addr['name']}</td><td>";
1720 if ( $addr['reserved'] == 'yes')
1721 echo "<b>Reserved;</b> ";
1722 foreach ($range['addrlist'][$ip]['references'] as $ref)
1723 {
1724 echo "<a href='${root}?page=object&object_id=${ref['object_id']}'>${ref['object_name']}[${ref['name']}]</a>; ";
1725 }
1726 echo "</td></tr>\n";
1727 }
1728 else
1729 {
1730 echo "<tr><td><a href='${root}?page=ipaddress&ip=".long2ip($ip)."'>".long2ip($ip)."</a></td><td>&nbsp;</td><td>&nbsp;</td></tr>\n";
1731 }
1732 }
1733
1734 echo "</table>";
1735
1736}
1737
1738function renderIPRangeProperties ()
1739{
1740 global $pageno, $tabno;
1741 $id = $_REQUEST['id'];
1742 showMessageOrError();
1743 $range = getIPRange($id);
1744 echo "<center><h1>${range['ip']}/${range['mask']}</h1></center>\n";
1745 echo "<table border=0 cellpadding=10 cellpadding=1 align='center'>\n";
1746 echo "<form action='process.php'><input type=hidden name=op value=editRange>";
1747 echo "<input type=hidden name=page value='${pageno}'>\n";
1748 echo "<input type=hidden name=tab value='${tabno}'>\n";
1749 echo "<input type=hidden name=id value='${id}'>";
1750 echo "<tr><td class='tdright'>Name:</td><td class='tdleft'><input type=text name=name size=20 value='${range['name']}'></tr><tr><td colspan=2 class='tdcenter'><input type=submit value='Update range'></td></form></tr>";
1751 echo "</table>\n";
1752
1753}
1754
1755function renderIPAddress ()
1756{
1757 global $root;
1758 $ip = $_REQUEST['ip'];
1759 $address = getIPAddress($ip);
1760 echo "<center><h1>$ip</h1>";
1761 if ($address['exists'] == 1)
1762 echo "<h2>${address['name']}</h2>";
1763 echo "</center>\n";
1764
1765// echo "<table width='100%' cesspadding=5 cellspacing=0 border=0 align='center'>";
1766// echo "<tr valign='top'><td>";
1767
1768 startPortlet ('Address assignment');
1769 echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
1770 echo "<tr><th>Object name</th><th>Interface name</th><th>Interface type</th></tr>\n";
1771
1772 $numshared = countRefsOfType($address['bonds'], 'shared', 'eq');
1773 $numreg = countRefsOfType($address['bonds'], 'regular', 'eq');
1774 $numvirt = countRefsOfType($address['bonds'], 'virtual', 'eq');
1775
1776
1777 if ( ($numshared > 0 && $numreg > 0) || $numreg > 1 )
1778 $class='trwarning';
1779 elseif ( $address['reserved'] == 'yes' and $numshared+$numreg+$numvirt > 0)
1780 $class='trwarning';
1781 else
1782 $class='';
1783
1784
1785
1786 if ($address['reserved'] == 'yes')
1787 echo "<tr class='$class'><td colspan='3'><b>RESERVED</b></td></tr>";
1788 foreach ($address['bonds'] as $bond)
1789 {
1790 echo "<tr class='$class'><td><a href='${root}?page=object&object_id=${bond['object_id']}'>${bond['object_name']}</td><td>${bond['name']}</td><td><b>";
1791 switch ($bond['type'])
1792 {
1793 case 'virtual':
1794 echo "Virtual";
1795 break;
1796 case 'shared':
1797 echo "Shared";
1798 break;
1799 case 'regular':
1800 echo "Regular";
1801 break;
1802 }
1803 echo "</b></td></tr>\n";
1804 }
1805 echo "</table><br><br>";
1806 finishPortlet();
1807
1808// echo "</td><td>";
1809// echo "</td></tr></table>";
1810}
1811
1812function renderIPAddressProperties ()
1813{
1814 global $pageno, $tabno;
1815 $ip = $_REQUEST['ip'];
1816 showMessageOrError();
1817 $address = getIPAddress($ip);
1818 echo "<center><h1>$ip</h1></center>\n";
1819 echo "<table border=0 cellpadding=10 cellpadding=1 align='center'>\n";
1820 echo "<form action='process.php'><input type=hidden name=op value=editAddress>";
1821 echo "<input type=hidden name=page value='${pageno}'>\n";
1822 echo "<input type=hidden name=tab value='${tabno}'>\n";
1823 echo "<input type=hidden name=ip value='${ip}'>";
1824 echo "<tr><td class='tdright'>Name:</td><td class='tdleft'><input type=text name=name size=20 value='".($address['exists']==1?$address['name']:'')."'></tr>";
1825 echo "<td class='tdright'>Reserved:</td><td class='tdleft'><input type=checkbox name=reserved size=20 ".($address['exists']==1?(($address['reserved']=='yes')?'checked':''):'')."></tr>";
1826 echo "<tr><td colspan=2 class='tdcenter'><input type=submit value='Update address'></td></form></tr>";
1827 echo "</table>\n";
1828
1829}
1830
1831function renderIPAddressAssignment ()
1832{
1833 global $pageno, $tabno, $root;
1834 $ip = $_REQUEST['ip'];
1835 $address = getIPAddress($ip);
1836
1837 showMessageOrError();
1838 echo "<center><h1>$ip</h1></center>\n";
1839
1840
1841 echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
1842 echo "<tr><th>&nbsp;</th><th>Object name</th><th>Interface name</th><th>Interface type</th><th>&nbsp;</th></tr>\n";
1843
1844 $numshared = countRefsOfType($address['bonds'], 'shared', 'eq');
1845 $numreg = countRefsOfType($address['bonds'], 'regular', 'eq');
1846 $numvirt = countRefsOfType($address['bonds'], 'virtual', 'eq');
1847
1848
1849 if ( ($numshared > 0 && $numreg > 0) || $numreg > 1 )
1850 $class='trwarning';
1851 elseif ( $address['reserved'] == 'yes' and $numshared+$numreg+$numvirt > 0)
1852 $class='trwarning';
1853 else
1854 $class='';
1855
1856
1857
1858 if ($address['reserved'] == 'yes')
1859 echo "<tr class='$class'><td colspan='5'><b>RESERVED</b></td></tr>";
1860 foreach ($address['bonds'] as $bond)
1861 {
1862 echo "<tr class='$class'><form action='process.php'>";
1863 echo "<input type=hidden name=op value='editBondForAddress'>";
1864 echo "<input type=hidden name=page value='${pageno}'>";
1865 echo "<input type=hidden name=tab value='${tabno}'>";
1866 echo "<input type=hidden name=ip value='$ip'>";
1867 echo "<input type=hidden name=object_id value='${bond['object_id']}'>";
1868 echo "<td><a href='process.php?op=delIpAssignment&page=${pageno}&tab=${tabno}&ip=$ip&object_id=${bond['object_id']}'>";
1869 printImageHREF ('delete', 'Unallocate address');
1870 echo "</a></td>";
1871 echo "<td><a href='${root}?page=object&object_id=${bond['object_id']}'>${bond['object_name']}</td>";
1872 echo "<td><input type='text' name='bond_name' value='${bond['name']}' size=10></td>";
1873 echo "<td><select name='bond_type'>";
1874 switch ($bond['type'])
1875 {
1876 case 'virtual':
1877 echo "<option value='regular'>Regular</option>";
1878 echo "<option value='virtual' selected>Virtual</option>";
1879 echo "<option value='shared'>Shared</option>";
1880 break;
1881 case 'shared':
1882 echo "<option value='regular'>Regular</option>";
1883 echo "<option value='virtual'>Virtual</option>";
1884 echo "<option value='shared' selected>Shared</option>";
1885 break;
1886 case 'regular':
1887 echo "<option value='regular' selected>Regular</option>";
1888 echo "<option value='virtual'>Virtual</option>";
1889 echo "<option value='shared'>Shared</option>";
1890 break;
1891 }
1892 echo "</select></td><td><input type='submit' value='OK'></td></form></tr>\n";
1893 }
1894 echo "<form action='process.php'><input type='hidden' name='op' value='bindObjectToIp'>";
1895 echo "<input type=hidden name=page value='${pageno}'>\n";
1896 echo "<input type=hidden name=tab value='${tabno}'>\n";
1897 echo "<input type='hidden' name='ip' value='$ip'>";
1898 echo "<td colspan=2><select name='object_id'>";
1899
1900 foreach (array(1, 4, 7, 8, 12, 14) as $type)
1901 {
1902 //get all Balck Boxes, Servers, Routers, Switches, UPS, Modems
1903 $objects = getObjectList($type);
1904 foreach ($objects as $object)
1905 echo "<option value='${object['id']}'>${object['dname']}</option>";
1906 }
1907
1908 echo "</select></td><td><input type='text' name='bond_name' value='' size=10></td>";
1909 echo "<td><select name='bond_type'><option value='regular'>Regular</option><option value='virtual'>Virtual</option><option value='shared'>Shared</option></select></td>";
1910 echo "<td><input type='submit' value='Assign address'></td></form></tr>";
1911 echo "</table><br><br>";
1912
1913}
1914
1915function renderIPAddressPortForwarding ($object_id=0)
1916{
1917 global $pageno, $tabno, $root;
1918
1919 $info = getObjectInfo ($object_id);
1920 $forwards = getObjectForwards ($object_id);
1921 $addresses = getObjectAddresses ($object_id);
1922 showMessageOrError();
1923 echo "<center><h1>Port Forwardings</h1></center>\n";
1924 echo "<center><h3>Forwarding out:</h3></center>";
1925
1926 echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
1927 echo "<tr><th></th><th>Source</th><th>Target</th><th>Target Objects</th><th>Description</th></tr>\n";
1928
1929 foreach ($forwards['out'] as $pf)
1930 {
1931 $class='trwarning';
1932 $name='';
1933 foreach ($addresses as $addr)
1934 if ($addr['ip'] == $pf['localip'])
1935 {
1936 $class='';
1937 $name = $addr['name'];
1938 break;
1939 }
1940
1941 echo "<tr class='$class'>";
1942 echo "<td><a href='process.php?op=delPortForwarding&localip=${pf['localip']}&localport=${pf['localport']}&remoteip=${pf['remoteip']}&remoteport=${pf['remoteport']}&proto=${pf['proto_bin']}&object_id=$object_id&page=${pageno}&tab=${tabno}'><img src='${root}/pix/delete_s.gif' title='Delete port forwarding' border=0 width=16 height=16></a></td>";
1943 echo "<td>${pf['proto']}/$name:<a href='${root}?page=ipaddress&tab=default&ip=${pf['localip']}'>${pf['localip']}</a>:${pf['localport']}</td>";
1944 echo "<td><a href='${root}?page=ipaddress&tab=default&ip=${pf['remoteip']}'>${pf['remoteip']}</a>:${pf['remoteport']}</td>";
1945
1946 $address=getIPAddress($pf['remoteip']);
1947
1948 echo "<td class='description'>";
1949 foreach($address['bonds'] as $bond)
1950 echo "<a href='${root}?page=object&tab=default&object_id=${bond['object_id']}'>${bond['object_name']}(${bond['name']})</a> ";
1951 echo "</td><form action='process.php'><input type='hidden' name='op' value='updPortForwarding'><input type=hidden name=page value='${pageno}'><input type=hidden name=tab value='${tabno}'><input type='hidden' name='object_id' value='$object_id'><input type='hidden' name='localip' value='${pf['localip']}'><input type='hidden' name='localport' value='${pf['localport']}'><input type='hidden' name='remoteip' value='${pf['remoteip']}'><input type='hidden' name='remoteport' value='${pf['remoteport']}'><input type='hidden' name='proto' value='${pf['proto_bin']}'><td class='description'><input type='text' name='description' value='${pf['description']}'> <input type='submit' value='OK'></td></form>";
1952 echo "</tr>";
1953 }
1954 echo "<form action='process.php'><input type='hidden' name='op' value='forwardPorts'>";
1955 echo "<input type='hidden' name='object_id' value='$object_id'>";
1956 echo "<input type=hidden name=page value='${pageno}'>\n";
1957 echo "<input type=hidden name=tab value='${tabno}'>\n";
1958 echo "<tr align='center'><td colspan=2><select name='proto'><option value='1'>TCP</option><option value='2'>UDP</option></select><select name='localip'>";
1959
1960 foreach ($addresses as $addr)
1961 echo "<option value='${addr['ip']}'>" . (empty ($addr['name']) ? '' : "${addr['name']}:") . "${addr['ip']}</option>";
1962
1963 echo "</select>:<input type='text' name='localport' size='4'></td><td><input type='text' name='remoteip' id='remoteip' size='10'>";
1964 echo "<a href='javascript:;' onclick='window.open(\"${root}/find_object_ip_helper.php\", \"findobjectip\", \"height=700, width=400, location=no, menubar=no, resizable=yes, scrollbars=no, status=no, titlebar=no, toolbar=no\");'><img src='${root}/pix/find.png' title='Find object' border=0 height=16 width=16></a>";
1965 echo ":<input type='text' name='remoteport' size='4'></td><td></td><td colspan=1><input type='text' name='description' size='20'> <input type='submit' value='Create Forwarding'></td></tr>";
1966 echo "</form>";
1967
1968 echo "</table><br><br>";
1969
1970
1971 echo "<center><h3>Forwarded from:</h3></center>";
1972 echo "<table class='widetable' cesspadding=5 cellspacing=0 border=0 align='center'>\n";
1973 echo "<tr><th></th><th>Source</th><th>Source objects</th><th>Target</th><th>Description</th></tr>\n";
1974
1975 foreach ($forwards['in'] as $pf)
1976 {
1977 echo "<tr>";
1978
1979 echo "<td><a href='process.php?op=delPortForwarding&localip=${pf['localip']}&localport=${pf['localport']}&remoteip=${pf['remoteip']}&remoteport=${pf['remoteport']}&proto=${pf['proto_bin']}&object_id=${pf['object_id']}&page=${pageno}&tab=${tabno}'><img src='${root}/pix/delete_s.gif' title='Delete port forwarding' border=0 width=16 height=16></a></td>";
1980 echo "<td>${pf['proto']}/<a href='${root}?page=ipaddress&tab=default&ip=${pf['localip']}'>${pf['localip']}</a>:${pf['localport']}</td>";
1981 echo "<td class='description'><a href='${root}?page=object&tab=default&object_id=${pf['object_id']}'>${pf['object_name']}</a>";
1982 echo "</td><td><a href='${root}?page=ipaddress&tab=default&ip=${pf['remoteip']}'>${pf['remoteip']}</a>:${pf['remoteport']}</td>";
1983 echo "<td class='description'>${pf['description']}</td></tr>";
1984 }
1985
1986// echo "<form action='process.php'><input type='hidden' name='op' value='forwardPorts'>";
1987// echo "<input type='hidden' name='object_id' value='$object_id'>";
1988// echo "<input type=hidden name=page value='${pageno}'>\n";
1989// echo "<input type=hidden name=tab value='${tabno}'>\n";
1990// echo "<tr align='center'><td colspan=2><select name='proto'><option value='1'>TCP</option><option value='2'>UDP</option><input type='text' name='localip' size='10'>:<input type='text' name='localport' size='4'></td><td><select name='localip'>";
1991// foreach ($addresses as $addr)
1992// echo "<option value='${addr['ip']}'>${addr['ip']}</option>";
1993//
1994// echo "</select>:<input type='text' name='remoteport' size='4'></td><td><input type='text' name='description' size='20'></td><td><input type='submit' value='Create Forwarding'></td></tr>";
1995// echo "</form>";
1996 echo "</table><br><br>";
1997
1998
1999}
2000
2001
2002function renderAddMultipleObjectsForm ()
2003{
2004 global $pageno, $tabno, $nextorder;
2005
2006 $type_id = array();
7f791d1d 2007 $global_type_id = 0;
e673ee24
DO
2008 $name = array();
2009 $asset_no = array();
2010 $keepvalues = FALSE;
7f791d1d 2011 $log = array();
e673ee24 2012 // Look for current submit.
7f791d1d 2013 if (isset ($_REQUEST['got_fast_data']))
e673ee24
DO
2014 {
2015 $keepvalues = TRUE;
9c0b0016
DO
2016 $max = getConfigVar ('MASSCOUNT');
2017 for ($i = 0; $i < $max; $i++)
e673ee24
DO
2018 {
2019 if (!isset ($_REQUEST["${i}_object_type_id"]))
2020 {
2021 $log[] = array ('code' => 'error', 'message' => "Submitted form is invalid at line " . $i + 1);
2022 break;
2023 }
2024 assertUIntArg ("${i}_object_type_id", TRUE);
2025 assertStringArg ("${i}_object_name", TRUE);
2026 assertStringArg ("${i}_object_label", TRUE);
2027 assertStringArg ("${i}_object_asset_no", TRUE);
2028 assertStringArg ("${i}_object_barcode", TRUE);
2029 $type_id[$i] = $_REQUEST["${i}_object_type_id"];
2030 // Save user input for possible rendering.
2031 $name[$i] = $_REQUEST["${i}_object_name"];
2032 $label[$i] = $_REQUEST["${i}_object_label"];
2033 $asset_no[$i] = $_REQUEST["${i}_object_asset_no"];
2034 $barcode[$i] = $_REQUEST["${i}_object_barcode"];
2035
2036 // It's better to skip silently than printing a notice.
2037 if ($type_id[$i] == 0)
2038 continue;
2039 if (commitAddObject ($name[$i], $label[$i], $barcode[$i], $type_id[$i], $asset_no[$i]) === TRUE)
2040 $log[] = array ('code' => 'success', 'message' => "Added new object '${name[$i]}'");
2041 else
2042 $log[] = array ('code' => 'error', 'message' => 'commitAddObject() failed in renderAddMultipleObjectsForm()');
2043 }
e673ee24 2044 }
7f791d1d
DO
2045 elseif (isset ($_REQUEST['got_very_fast_data']))
2046 {
2047 $keepvalues = TRUE;
2048 assertUIntArg ('global_type_id', TRUE);
2049 assertStringArg ('namelist', TRUE);
2050 $global_type_id = $_REQUEST['global_type_id'];
2051 if ($global_type_id == 0)
2052 {
2053 if (!empty ($_REQUEST['namelist']))
2054 $log[] = array ('code' => 'error', 'message' => 'Object type is not selected, check the form below');
2055 else
2056 $log[] = array ('code' => 'error', 'message' => 'Empty form has been ignored. Cheers.');
2057 }
2058 else
2059 {
2060 // The name extractor below was stolen from ophandlers.php:addMultiPorts()
2061 $names1 = explode ('\n', $_REQUEST['namelist']);
2062 $names2 = array();
2063 foreach ($names1 as $line)
2064 {
2065 $parts = explode ('\r', $line);
2066 reset ($parts);
2067 if (empty ($parts[0]))
2068 continue;
2069 else
2070 $names2[] = rtrim ($parts[0]);
2071 }
2072 foreach ($names2 as $cname)
2073 if (commitAddObject ($cname, '', '', $global_type_id, '') === TRUE)
2074 $log[] = array ('code' => 'success', 'message' => "Added new object '${cname}'");
2075 else
2076 $log[] = array ('code' => 'error', 'message' => "Could not add '${cname}'");
2077 }
2078 }
2079 printLog ($log);
e673ee24
DO
2080
2081 // Render a form for the next.
2082 $typelist = getObjectTypeList();
2083 $typelist[0]['dict_key'] = 0;
7f791d1d
DO
2084 $typelist[0]['dict_value'] = 'select type...';
2085
2086 startPortlet ('Fast way');
e673ee24
DO
2087 echo '<form>';
2088 echo "<input type=hidden name=page value=${pageno}>";
2089 echo "<input type=hidden name=tab value=${tabno}>";
2090 echo '<table border=0 align=center>';
2091 echo "<tr><th>Object type</th><th>Common name</th><th>Visible label</th><th>Asset tag</th><th>Barcode</th></tr>\n";
7f791d1d 2092 // If a user forgot to select object type on input, we keep his
e673ee24 2093 // previous input in the form.
9c0b0016
DO
2094 $max = getConfigVar ('MASSCOUNT');
2095 for ($i = 0; $i < $max; $i++)
e673ee24 2096 {
7f791d1d 2097 echo '<tr><td>';
e673ee24
DO
2098 printSelect ($typelist, "${i}_object_type_id", 0);
2099 echo '</td>';
2100 echo "<td><input type=text size=30 name=${i}_object_name";
2101 if ($keepvalues and $type_id[$i] == 0)
2102 echo " value='${name[$i]}'";
2103 echo "></td>";
2104 echo "<td><input type=text size=30 name=${i}_object_label";
2105 if ($keepvalues and $type_id[$i] == 0)
2106 echo " value='${label[$i]}'";
2107 echo "></td>";
2108 echo "<td><input type=text size=20 name=${i}_object_asset_no";
2109 if ($keepvalues and $type_id[$i] == 0)
2110 echo " value='${asset_no[$i]}'";
2111 echo "></td>";
2112 echo "<td><input type=text size=10 name=${i}_object_barcode";
2113 if ($keepvalues and $type_id[$i] == 0)
2114 echo " value='${barcode[$i]}'";
2115 echo "></td>";
2116 echo "</tr>\n";
e673ee24 2117 }
7f791d1d 2118 echo "<tr><td class=submit colspan=5><input type=submit name=got_fast_data value='Create'></td></tr>\n";
e673ee24
DO
2119 echo "</form></table>\n";
2120 finishPortlet();
7f791d1d
DO
2121
2122 startPortlet ('Very fast way');
2123 echo '<form>';
2124 echo "<input type=hidden name=page value=${pageno}>";
2125 echo "<input type=hidden name=tab value=${tabno}>";
2126 echo 'For each line shown below create an object of type ';
2127 printSelect ($typelist, "global_type_id", 0);
2128 echo " <input type=submit name=got_very_fast_data value='Go!'><br>\n";
2129 echo "<textarea name=namelist cols=40 rows=25>\n";
2130 if ($keepvalues and $global_type_id == 0)
2131 echo $_REQUEST['namelist'];
2132 echo "</textarea></form>\n";
2133 finishPortlet();
e673ee24
DO
2134}
2135
2136function printGreeting ()
2137{
2138 global $remote_username, $accounts;
2139 $account = $accounts[$remote_username];
9c0b0016 2140 echo "Hello, ${account['user_realname']}. This is RackTables " . CODE_VERSION . ". Click <a href=logout.php>here</a> to logout.";
e673ee24
DO
2141}
2142
2143function renderSearchResults ()
2144{
2145 global $remote_username, $root;
2146 $terms = trim ($_REQUEST['q']);
2147 if (empty ($terms))
2148 {
2149 showError ('Search string cannot be empty.');
2150 return;
2151 }
2152 if (!authorized ($remote_username, 'object', 'default'))
2153 {
2154 showError ('You are not authorized for viewing information about objects.');
2155 return;
2156 }
2157 // If we search for L2 address, we can either find one or find none.
2158 if
2159 (
2160 preg_match ('/^[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?:[0-9a-f][0-9a-f]?$/i', $terms) or
2161 preg_match ('/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i', $terms) or
2162 preg_match ('/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f].[0-9a-f][0-9a-f][0-9a-f][0-9a-f].[0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i', $terms)
2163 )
2164 // Search for L2 address.
2165 {
2166 $result = searchByl2address ($terms);
2167 if ($result !== NULL)
2168 {
2169 echo "<script language='Javascript'>document.location='${root}?page=object";
2170 echo "&hl_port_id=${result['port_id']}";
2171 echo "&object_id=${result['object_id']}';//</script>";
2172 }
2173 else
2174 echo "L2 address '${terms}' not found!";
2175 }
2176 elseif (preg_match ('/^[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$/i', $terms))
2177 // STP bridge ID: bridge priotity + port MAC address. Cut off first 4 chars and look for MAC address.
2178 {
2179 $terms = substr ($terms, 4);
2180 $result = searchByl2address ($terms);
2181 if ($result !== NULL)
2182 {
2183 echo "<script language='Javascript'>document.location='${root}?page=object";
2184 echo "&hl_port_id=${result['port_id']}";
2185 echo "&object_id=${result['object_id']}';//</script>";
2186 }
2187 else
2188 echo "L2 address '${terms}' not found!";
2189 }
2190 elseif (preg_match ('/^[0-9][0-9]?[0-9]?\.[0-9]?[0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9]?[0-9]?[0-9]?$/i', $terms))
2191 // Search for IP address.
2192 {
2193 $result = getRangeByIp ($terms);
2194 if ($result !== NULL)
2195 {
2196 echo "<script language='Javascript'>document.location='${root}?page=ipaddress";
2197 echo "&ip=${terms}";
2198 echo "';//</script>";
2199 }
2200 else
2201 echo "IP address '${terms}' not found!";
2202 return;
2203 }
2204 else
2205 // Search for objects.
2206 {
2207 $objects = getSearchResults ($terms);
2208 if (count ($objects) == 1)
2209 {
2210 $obj = current ($objects);
2211 echo "<script language='Javascript'>document.location='${root}?page=object&object_id=${obj['id']}';//</script>";
2212 }
2213 elseif (count ($objects) > 1)
2214 {
2215 echo '<br><br><table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
2216 echo '<tr><th>Common name</th><th>Visible label</th><th>Asset tag</th><th>barcode</th></tr>';
2217 $order = 'odd';
2218 global $nextorder;
2219 foreach ($objects as $obj)
2220 {
2221 echo "<tr class=row_${order}><td><a href=\"${root}?page=object&object_id=${obj['id']}\">${obj['dname']}</a></td>";
2222 echo "<td>${obj['label']}</td>";
2223 echo "<td>${obj['asset_no']}</td>";
2224 echo "<td>${obj['barcode']}</td></tr>";
2225 $order = $nextorder[$order];
2226 }
2227 echo '</table>';
2228 }
2229 else
2230 echo "Object '${terms}' not found!";
2231 }
2232}
2233
2234// This function prints a table of checkboxes to aid the user in toggling mount atoms
2235// from one state to another. The first argument is rack data as
2236// produced by getRackData(), the second is the value used for the 'unckecked' state
2237// and the third is the value used for 'checked' state.
2238// Usage contexts:
2239// for mounting an object: printAtomGrid ($data, 'F', 'T')
2240// for changing rack design: printAtomGrid ($data, 'A', 'F')
2241// for adding rack problem: printAtomGrid ($data, 'F', 'U')
2242// for adding object problem: printAtomGrid ($data, 'T', 'W')
2243
2244function renderAtomGrid ($data)
2245{
2246 $rack_id = $data['id'];
2247 for ($unit_no = $data['height']; $unit_no > 0; $unit_no--)
2248 {
2249 echo "<tr><th>${unit_no}</th>";
2250 for ($locidx = 0; $locidx < 3; $locidx++)
2251 {
2252 $state = $data[$unit_no][$locidx]['state'];
2253 echo "<td class=state_${state}";
2254 if (isset ($data[$unit_no][$locidx]['hl']))
2255 echo $data[$unit_no][$locidx]['hl'];
2256 echo ">";
2257 if (!($data[$unit_no][$locidx]['enabled'] === TRUE))
2258 echo '<input type=checkbox disabled>';
2259 else
2260 echo "<input type=checkbox" . $data[$unit_no][$locidx]['checked'] . " name=atom_${rack_id}_${unit_no}_${locidx}>";
2261 echo '</td>';
2262 }
2263 echo "</tr>\n";
2264 }
2265}
2266
2267function renderPermissions ()
2268{
2269 startPortlet ('User permissions');
2270 echo "<table class=cooltable border=0 cellpadding=5 cellspacing=0 align=center>\n";
2271 echo "<tr><th>Username</th><th>Page</th><th>Tab</th><th>Access</th></tr>";
2272 global $perms, $nextorder;
2273 $order = 'odd';
2274 foreach ($perms as $username => $pages)
2275 foreach ($pages as $page => $tabs)
2276 foreach ($tabs as $tab => $access)
2277 {
2278 echo "<tr class=row_${order}><td class=tdleft>$username</td><td>$page</td><td>$tab</td><td>$access</td></tr>\n";
2279 $order = $nextorder[$order];
2280 }
2281 echo "</table>\n";
2282 finishPortlet();
2283}
2284
2285function renderAccounts ()
2286{
2287 global $nextorder, $accounts;
2288 startPortlet ('User accounts');
2289 echo "<table class=cooltable border=0 cellpadding=5 cellspacing=0 align=center>\n";
2290 echo "<tr><th class=tdleft>Username</th><th class=tdleft>Real name</th></tr>";
2291 $order = 'odd';
2292 foreach ($accounts as $user)
2293 {
2294 echo "<tr class=row_${order}><td class=tdleft>${user['user_name']}</td><td class=tdleft>${user['user_realname']}</td></li>";
2295 $order = $nextorder[$order];
2296 }
2297 echo '</table>';
2298 finishPortlet();
2299}
2300
2301function renderAccountsEditForm ()
2302{
2303 global $root, $pageno, $tabno, $accounts;
2304 startPortlet ('User accounts');
2305 showMessageOrError();
2306 echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
2307 echo "<tr><th>op</th><th>Username</th><th>Real name</th><th>Password</th><th>&nbsp;</th></tr>\n";
2308 foreach ($accounts as $account)
2309 {
2310 echo "<form action='${root}process.php'>";
2311 echo "<input type=hidden name=op value=updateAccount>";
2312 echo "<input type=hidden name=page value='${pageno}'>\n";
2313 echo "<input type=hidden name=tab value='${tabno}'>\n";
2314 echo "<input type=hidden name=id value='${account['user_id']}'><tr>";
2315 echo "<td>";
2316 if ($account['user_enabled'] == 'yes' && $account['user_id'] != 1)
2317 {
2318 echo "<a href='${root}process.php?op=disableAccount&page=${pageno}&tab=${tabno}&id=${account['user_id']}'>";
2319 printImageHREF ('blockuser', 'disable account');
2320 echo "</a>\n";
2321 }
2322 if ($account['user_enabled'] == 'no' && $account['user_id'] != 1)
2323 {
2324 echo "<a href='${root}process.php?op=enableAccount&page=${pageno}&tab=${tabno}&id=${account['user_id']}'>";
2325 printImageHREF ('unblockuser', 'enable account');
2326 echo "</a>\n";
2327 }
2328 // Otherwise skip icon.
2329 echo "</td>";
2330 echo "<td><input type=text name=username value='${account['user_name']}' size=16></td>";
2331 echo "<td><input type=text name=realname value='${account['user_realname']}' size=24></td>";
2332 echo "<td><input type=password name=password value='${account['user_password_hash']}' size=64></td>";
2333 echo "<td><input type='submit' value='OK'></td>";
2334 echo "</form></tr>\n";
2335 }
2336 echo "<form action='${root}process.php' method=post><tr>";
2337 echo "<input type=hidden name=op value=createAccount>\n";
2338 echo "<input type=hidden name=page value='${pageno}'>\n";
2339 echo "<input type=hidden name=tab value='${tabno}'>\n";
2340 echo "<td colspan=2><input type=text size=16 name=username tabindex=100></td>\n";
2341 echo "<td><input type=text size=24 name=realname tabindex=101></td>";
2342 echo "<td><input type=password size=64 name=password tabindex=102></td>";
2343 echo "<td colspan=4><input type=submit value='Create account' tabindex=103></td></tr></form>";
2344 echo "</table><br>\n";
2345 finishPortlet();
2346}
2347
2348function printChildrenAsOptions ($root, $depth = 0)
2349{
2350 echo "<option value=${root['title']}>";
2351 if ($depth == 0)
2352 echo '* ';
2353 for ($i = 0; $i < $depth; $i++)
2354 echo '-- ';
2355 echo $root['title'];
2356 echo "</option>\n";
2357 foreach ($root['kids'] as $kid)
2358 printChildrenAsOptions ($kid, $depth + 1);
2359}
2360
2361// 1. Find all parentless pages.
2362// 2. For each of them recursively find all children.
2363// 3. Output the tree with recursion tree display.
2364function printPagesTree ()
2365{
2366 global $page;
2367 echo '<pre>';
2368 foreach ($page as $ctitle => $cpage)
2369 if (!isset ($cpage['parent']))
2370 {
2371 $croot['title'] = $ctitle;
2372 $croot['kids'] = getAllChildPages ($ctitle);
2373 printChildrenAsOptions ($croot);
2374 }
2375 echo '</pre>';
2376}
2377
2378function renderPermissionsEditForm ()
2379{
2380 global $root, $pageno, $tabno, $perms, $accounts;
2381 startPortlet ('User permissions');
2382 showMessageOrError();
2383 echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n";
2384 echo "<tr><th>&nbsp;</th><th>Username</th><th>Page</th><th>Tab</th><th>Access</th></tr>\n";
2385 foreach ($perms as $username => $pages)
2386 foreach ($pages as $access_page => $tabs)
2387 foreach ($tabs as $access_tab => $access)
2388 {
2389 echo "<td>";
2390 if ($username != '%')
2391 $userid = $accounts[$username]['user_id'];
2392 else
2393 $userid = 0;
2394 echo "<a href='${root}process.php?op=revoke&page=${pageno}&tab=${tabno}&access_userid=${userid}&access_page=${access_page}&access_tab=${access_tab}'>";
2395 printImageHREF ('revoke', 'Revoke permission');
2396 echo "</a></td>";
2397 echo "<td>${username}</td>";
2398 echo "<td>${access_page}</td>";
2399 echo "<td>${access_tab}</td>";
2400 echo "<td>${access}</td>";
2401 echo "</tr>\n";
2402 }
2403 echo "<form action='${root}process.php' method=post><tr>";
2404 echo "<input type=hidden name=op value=grant>\n";
2405 echo "<input type=hidden name=page value='${pageno}'>\n";
2406 echo "<input type=hidden name=tab value='${tabno}'>\n";
2407 // FIXME: border=0 doesn't work here for unknown reason
2408 echo "<td>";
a5ae8c2a 2409 printImageHREF ('grant', '', TRUE, 103);
e673ee24
DO
2410 echo "</td>";
2411 echo "<td><select name=access_userid>";
2412 echo "<option value=0>ANY</option>";
2413 foreach ($accounts as $account)
2414 echo "<option value=${account['user_id']}>${account['user_name']}</option>";
2415 echo "</select></td>\n";
2416 echo "<td><select name=access_page>";
2417 echo "<option value='%'>ANY</option>";
2418 printPagesTree();
2419 echo "</select></td>";
2420 echo "<td><input type=text size=16 name=access_tab tabindex=102 value=default></td>";
2421 echo "<td><input type=radio name=access_value value=no checked>no <input type=radio name=access_value value=yes>yes</td>";
2422 echo "</tr></form>";
2423 echo "</table><br>\n";
2424 finishPortlet();
2425}
2426
e673ee24
DO
2427function renderPortMap ($editable = FALSE)
2428{
2429 global $nextorder, $root, $pageno, $tabno;
2430 showMessageOrError();
2431 startPortlet ("Port compatibility map");
2432 $ptlist = getPortTypes();
2433 $pclist = getPortCompat();
2434 $pctable = buildPortCompatMatrixFromList ($ptlist, $pclist);
2435 if ($editable)
2436 {
2437 echo "<form method=post action='${root}process.php'>";
2438 echo "<input type=hidden name=page value='${pageno}'>";
2439 echo "<input type=hidden name=tab value='${tabno}'>";
2440 echo "<input type=hidden name=op value=save>";
2441 }
2442 echo "<table class=cooltable border=0 cellpadding=5 cellspacing=0 align=center>\n";
2443 echo "<tr><th class=vert_th>&nbsp;</th>";
2444 foreach ($ptlist as $name2)
2445 echo "<th>to ${name2}</th>";
2446 echo "</tr>";
2447 // Make a copy to have an independent array pointer.
2448 $ptlistY = $ptlist;
2449 $order = 'odd';
2450 foreach ($ptlistY as $type1 => $name1)
2451 {
2452 echo "<tr class=row_${order}><th class=vert_th style='border-bottom: 0px;'>from $name1</th>";
2453 foreach ($ptlist as $type2 => $name2)
2454 {
2455 echo '<td><input type=checkbox' . ($editable ? " name=atom_${type1}_${type2}" : ' disabled');
2456 echo ($pctable[$type1][$type2] ? ' checked' : '') . '></td>';
2457 }
2458 echo "</tr>\n";
2459 $order = $nextorder[$order];
2460 }
2461 echo '</table><br>';
2462 if ($editable)
2463 {
2464 echo "<input type=submit value='Save changes'>";
2465 echo "</form>";
2466 }
2467 finishPortlet();
2468}
2469
2470function renderConfigMainpage ()
2471{
2472 global $pageno, $root;
2473 $children = getDirectChildPages ($pageno);
2474 echo '<ul>';
2475 foreach ($children as $cpageno => $child)
2476 {
2477 $ctitle = $child['title']($cpageno);
2478 echo "<li><a href='${root}?page=${cpageno}'>" . $ctitle['name'] . "</li>\n";
2479 }
2480 echo '';
2481 echo '</ul>';
2482}
2483
2484function renderRackPage ($rack_id)
2485{
2486 if ($rack_id == 0)
2487 {
2488 showError ('Invalid rack_id in renderRack()');
2489 return;
2490 }
2491 if (($rackData = getRackData ($rack_id)) == NULL)
2492 {
2493 showError ('getRackData() failed in renderRack()');
2494 return;
2495 }
2496 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0><tr>";
2497
2498 // Left column with information.
2499 echo "<td class=pcleft>";
2500 startPortlet ('Rack information');
2501 echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
2502 echo "<tr><th width='50%' class=tdright>Rack row:</th><td class=tdleft>${rackData['row_name']}</td></tr>\n";
2503 echo "<tr><th width='50%' class=tdright>Name:</th><td class=tdleft>${rackData['name']}</td></tr>\n";
2504 echo "<tr><th width='50%' class=tdright>Height:</th><td class=tdleft>${rackData['height']}</td></tr>\n";
2505 if (!empty ($rackData['comment']))
2506 echo "<tr><th width='50%' class=tdright>Comment:</th><td class=tdleft>${rackData['comment']}</td></tr>\n";
2507 echo '</table>';
2508 finishPortlet();
2509 echo '</td>';
2510
2511 // Right column with rendered rack.
2512 echo '<td>';
2513 startPortlet ('Rack diagram');
2514 renderRack ($rack_id);
2515 finishPortlet();
2516 echo '</td>';
2517
2518 echo '</tr></table>';
2519}
2520
2521function renderDictionary ()
2522{
2523 global $nextorder;
2524 $dict = getDict();
2525 echo "<table border=0><tr>";
2526 foreach ($dict as $chapter)
2527 {
2528 echo "<td class=pcleft>";
2529 startPortlet ($chapter['name'] . ' (' . count ($chapter['word']) . ')');
2530 echo "<table class=cooltable border=0 cellpadding=5 cellspacing=0 align=center>\n";
2531 $order = 'odd';
cfadde04 2532 foreach ($chapter['word'] as $key => $value)
e673ee24 2533 {
cfadde04 2534 echo "<tr class=row_${order}><td class=tdleft><div title='key=${key}'>${value}</div></td></tr>";
e673ee24
DO
2535 $order = $nextorder[$order];
2536 }
2537 echo "</table>";
2538 finishPortlet();
2539 echo "</td>";
2540 }
2541 echo "</tr></table>";
2542}
2543
2544function renderDictionaryEditor ()
2545{
2546 global $root, $pageno, $tabno;
2547 showMessageOrError();
2548 $dict = getDict();
2549 echo "<table border=0><tr>";
2550 foreach ($dict as $chapter)
2551 {
2552 echo "<td class=pcleft>";
2553 startPortlet ($chapter['name'] . ' (' . count ($chapter['word']) . ')');
2554 echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
2555 foreach ($chapter['word'] as $key => $value)
2556 {
2557 echo "<form action='${root}process.php' method=post>";
2558 echo "<input type=hidden name=page value='${pageno}'>";
2559 echo "<input type=hidden name=tab value='${tabno}'>";
2560 echo "<input type=hidden name=op value='upd'>";
2561 echo "<input type=hidden name=chapter_no value='${chapter['no']}'>";
2562 echo "<input type=hidden name=dict_key value='${key}'>";
2563 echo '<tr>';
2564 echo "<td><a href='${root}process.php?page=${pageno}&tab=${tabno}&op=del&chapter_no=${chapter['no']}&dict_key=${key}'>";
2565 printImageHREF ('delete', 'Delete word');
2566 echo "</a></td>";
2567 echo "<td class=tdright><input type=text name=dict_value size=32 value='${value}'></td>";
2568 echo "<td><input type=submit value=OK></td>";
2569 echo '</tr></form>';
2570 }
2571 echo "<form action='${root}process.php' method=post>";
2572 echo "<input type=hidden name=page value='${pageno}'>";
2573 echo "<input type=hidden name=tab value='${tabno}'>";
2574 echo "<input type=hidden name=op value=add>";
2575 echo "<input type=hidden name=chapter_no value='${chapter['no']}'>";
2576 echo '<tr>';
2577 echo "<td>&nbsp;</td>";
2578 echo "<td class=tdright><input type=text name=dict_value size=32></td>";
2579 echo "<td><input type=submit value=OK></td>";
2580 echo '</tr></form>';
2581 echo "</table>";
2582 finishPortlet();
2583 echo "</td>";
2584 }
2585 echo "</tr></table>";
2586}
2587
2588// We don't allow to rename/delete a sticky chapter and we don't allow
2589// to delete a non-empty chapter.
2590function renderChaptersEditor ()
2591{
2592 global $root, $pageno, $tabno;
2593 showMessageOrError();
2594 $dict = getDict();
2595 echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
2596 echo '<tr><th>&nbsp;</th><th>Chapter name</th><th>Words</th><th>&nbsp;</th></tr>';
2597 foreach ($dict as $chapter)
2598 {
2599 $wordcount = count ($chapter['word']);
2600 $sticky = $chapter['sticky'];
2601 echo "<form action='${root}process.php' method=post>";
2602 echo "<input type=hidden name=page value='${pageno}'>";
2603 echo "<input type=hidden name=tab value='${tabno}'>";
2604 echo "<input type=hidden name=op value=upd>";
2605 echo "<input type=hidden name=chapter_no value='${chapter['no']}'>";
2606 echo '<tr>';
2607 echo '<td>';
2608 if ($sticky or $wordcount > 0)
2609 echo '&nbsp;';
2610 else
2611 {
2612 echo "<a href='${root}process.php?page=${pageno}&tab=${tabno}&op=del&chapter_no=${chapter['no']}'>";
2613 printImageHREF ('delete', 'Remove chapter');
2614 echo "</a>";
2615 }
2616 echo '</td>';
2617 echo "<td><input type=text name=chapter_name value='${chapter['name']}'" . ($sticky ? ' disabled' : '') . "></td>";
2618 echo "<td class=tdleft>${wordcount}</td><td>";
2619 if ($sticky)
2620 echo '&nbsp;';
2621 else
2622 echo "<input type=submit value='OK'>";
2623 echo '</td></tr>';
2624 echo '</form>';
2625 }
2626 echo "<form action='${root}process.php' method=post>";
2627 echo "<input type=hidden name=page value='${pageno}'>";
2628 echo "<input type=hidden name=tab value='${tabno}'>";
2629 echo "<input type=hidden name=op value=add>";
2630 echo '<tr><td>';
a5ae8c2a 2631 printImageHREF ('add', '', TRUE);
e673ee24
DO
2632 echo "</td><td colspan=3><input type=text name=chapter_name></td>";
2633 echo '</tr>';
2634 echo '</form>';
2635 echo "</table>\n";
2636}
2637
2638function renderAttributes ()
2639{
2640 global $nextorder;
2641 $attrMap = getAttrMap();
2642 startPortlet ('Optional attributes');
2643 echo "<table class=cooltable border=0 cellpadding=5 cellspacing=0 align=center>\n";
2644 echo "<tr><th class=tdleft>Attribute name</th><th class=tdleft>Attribute type</th><th class=tdleft>Applies to</th></tr>";
2645 $order = 'odd';
2646 foreach ($attrMap as $attr)
2647 {
2648 echo "<tr class=row_${order}>";
2649 echo "<td class=tdleft>${attr['name']}</td>";
2650 echo "<td class=tdleft>${attr['type']}</td>";
2651 echo '<td class=tdleft>';
2652 if (count ($attr['application']) == 0)
2653 echo '&nbsp;';
2654 else
2655 foreach ($attr['application'] as $app)
2656 if ($attr['type'] == 'dict')
2657 echo "${app['objtype_name']} (values from '${app['chapter_name']}')<br>";
2658 else
2659 echo "${app['objtype_name']}<br>";
2660 echo '</td>';
2661 echo "</tr>\n";
2662 $order = $nextorder[$order];
2663 }
2664 echo "</table><br>\n";
2665 finishPortlet();
2666}
2667
2668function renderEditAttributesForm ()
2669{
2670 global $root, $pageno, $tabno;
2671 $attrMap = getAttrMap();
2672 showMessageOrError();
2673 startPortlet ('Optional attributes');
2674 echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
2675 echo '<tr><th>&nbsp;</th><th>Name</th><th>Type</th><th>&nbsp;</th></tr>';
2676 foreach ($attrMap as $attr)
2677 {
2678 echo "<form action='${root}process.php' method=post>";
2679 echo "<input type=hidden name=page value='${pageno}'>";
2680 echo "<input type=hidden name=tab value='${tabno}'>";
2681 echo "<input type=hidden name=op value=upd>";
2682 echo "<input type=hidden name=attr_id value='${attr['id']}'>";
2683 echo '<tr>';
2684 echo "<td><a href='${root}process.php?page=${pageno}&tab=${tabno}&op=del&attr_id=${attr['id']}'>";
2685 printImageHREF ('delete', 'Remove attribute');
2686 echo '</a></td>';
2687 echo "<td><input type=text name=attr_name value='${attr['name']}'></td>";
2688 echo "<td>${attr['type']}</td>";
2689 echo "<td><input type=submit value='OK'></td>";
2690 echo '</tr>';
2691 echo '</form>';
2692 }
2693 echo "<form action='${root}process.php' method=post>";
2694 echo "<input type=hidden name=page value='${pageno}'>";
2695 echo "<input type=hidden name=tab value='${tabno}'>";
2696 echo "<input type=hidden name=op value=add>";
2697 echo '<tr><td>';
a5ae8c2a 2698 printImageHREF ('add', '', TRUE);
e673ee24
DO
2699 echo "</td><td><input type=text name=attr_name></td>";
2700 echo '<td><select name=attr_type>';
2701 echo '<option value=uint>uint</option>';
2702 echo '<option value=float>float</option>';
2703 echo '<option value=string>string</option>';
2704 echo '<option value=dict>dict</option>';
2705 echo '</select></td>';
2706 echo '</tr>';
2707 echo '</form>';
2708 echo "</table>\n";
2709 finishPortlet();
2710}
2711
2712function renderEditAttrMapForm ()
2713{
2714 global $root, $pageno, $tabno;
2715 $attrMap = getAttrMap();
2716 showMessageOrError();
2717 startPortlet ('Attribute map');
2718 echo "<table cellspacing=0 cellpadding=5 align=center class=widetable>\n";
2719 echo '<tr><th>&nbsp;</th><th>Attribute name</th><th>Object type</th><th>Dictionary chapter</th></tr>';
2720 foreach ($attrMap as $attr)
2721 {
2722 if (count ($attr['application']) == 0)
2723 continue;
2724 foreach ($attr['application'] as $app)
2725 {
2726 echo '<tr>';
2727 echo '<td>';
2728 echo "<a href='${root}process.php?page=${pageno}&tab=${tabno}&op=del&";
2729 echo "attr_id=${attr['id']}&objtype_id=${app['objtype_id']}'>";
2730 printImageHREF ('delete', 'Remove mapping');
2731 echo "</a>";
2732 echo '</td>';
2733 echo "<td>${attr['name']}</td>";
2734 echo "<td>${app['objtype_name']}</td>";
2735 echo "<td>";
2736 if ($attr['type'] == 'dict')
2737 echo "${app['chapter_name']}";
2738 else
2739 echo '&nbsp;';
2740 echo "</td></tr>\n";
2741 }
2742 }
2743 echo "<form action='${root}process.php' method=post>";
2744 echo "<input type=hidden name=page value='${pageno}'>";
2745 echo "<input type=hidden name=tab value='${tabno}'>";
2746 echo "<input type=hidden name=op value=add>";
2747 echo '<tr><td>';
a5ae8c2a 2748 printImageHREF ('add', '', TRUE);
e673ee24
DO
2749 echo "</td><td><select name=attr_id>";
2750 $shortType['uint'] = 'U';
2751 $shortType['float'] = 'F';
2752 $shortType['string'] = 'S';
2753 $shortType['dict'] = 'D';
2754 foreach ($attrMap as $attr)
2755 echo "<option value=${attr['id']}>[" . $shortType[$attr['type']] . "] ${attr['name']}</option>";
2756 echo "</select></td>";
2757 echo '<td>';
2758 printSelect (getObjectTypeList(), 'objtype_id');
2759 echo '</td>';
2760 $dict = getDict();
2761 echo '<td><select name=chapter_no>';
2762 foreach ($dict as $chapter)
2763 if (!$chapter['sticky'])
2764 echo "<option value='${chapter['no']}'>${chapter['name']}</option>";
2765 echo '</select></td>';
2766 echo '</tr>';
2767 echo '</form>';
2768 echo "</table>\n";
2769 finishPortlet();
2770}
2771
a5ae8c2a 2772function printImageHREF ($tag, $title = '', $do_input = FALSE, $tabindex = 0)
e673ee24 2773{
a5ae8c2a
DO
2774 global $root;
2775 $image['error']['path'] = 'pix/error.png';
2776 $image['error']['width'] = 76;
2777 $image['error']['height'] = 17;
2778 $image['favicon']['path'] = 'pix/racktables.ico';
2779 $image['favicon']['width'] = 16;
2780 $image['favicon']['height'] = 16;
2781 $image['logo']['path'] = 'pix/defaultlogo.png';
2782 $image['logo']['width'] = 210;
2783 $image['logo']['height'] = 40;
2784 $image['rackspace']['path'] = 'pix/racks.png';
2785 $image['rackspace']['width'] = 218;
2786 $image['rackspace']['height'] = 200;
2787 $image['objects']['path'] = 'pix/server.png';
2788 $image['objects']['width'] = 218;
2789 $image['objects']['height'] = 200;
2790 $image['ipv4space']['path'] = 'pix/addressspace.png';
2791 $image['ipv4space']['width'] = 218;
2792 $image['ipv4space']['height'] = 200;
2793 $image['config']['path'] = 'pix/configuration.png';
2794 $image['config']['width'] = 218;
2795 $image['config']['height'] = 200;
2796 $image['reports']['path'] = 'pix/report.png';
2797 $image['reports']['width'] = 218;
2798 $image['reports']['height'] = 200;
2799 $image['help']['path'] = 'pix/help.png';
2800 $image['help']['width'] = 218;
2801 $image['help']['height'] = 200;
2802 $image['reserve']['path'] = 'pix/stop.png';
2803 $image['reserve']['width'] = 16;
2804 $image['reserve']['height'] = 16;
2805 $image['useup']['path'] = 'pix/go.png';
2806 $image['useup']['width'] = 16;
2807 $image['useup']['height'] = 16;
2808 $image['blockuser'] = $image['reserve'];
2809 $image['unblockuser'] = $image['useup'];
2810 $image['link']['path'] = 'pix/link.png';
2811 $image['link']['width'] = 24;
2812 $image['link']['height'] = 24;
2813 $image['unlink']['path'] = 'pix/unlink.png';
2814 $image['unlink']['width'] = 24;
2815 $image['unlink']['height'] = 24;
2816 $image['add']['path'] = 'pix/greenplus.png';
2817 $image['add']['width'] = 16;
2818 $image['add']['height'] = 16;
2819 $image['delete']['path'] = 'pix/delete_s.gif';
2820 $image['delete']['width'] = 16;
2821 $image['delete']['height'] = 16;
2822 $image['grant'] = $image['add'];
2823 $image['revoke'] = $image['delete'];
2824 $image['helphint']['path'] = 'pix/helphint.png';
2825 $image['helphint']['width'] = 24;
2826 $image['helphint']['height'] = 24;
e673ee24
DO
2827 if (!isset ($image[$tag]))
2828 $tag = 'error';
2829 $img = $image[$tag];
a5ae8c2a
DO
2830 if ($do_input == TRUE)
2831 echo
2832 "<input type=image name=submit " .
2833 "src='${root}${img['path']}' " .
2834 "border=0 " .
2835 ($tabindex ? '' : "tabindex=${tabindex}") .
2836 ">";
2837 else
2838 echo
2839 "<img " .
2840 "src='${root}${img['path']}' " .
2841 "width=${img['width']} " .
2842 "height=${img['height']} " .
2843 "border=0 " .
2844 (empty ($title) ? '' : "title='${title}'") .
2845 ">";
e673ee24
DO
2846}
2847
2848// This function returns URL for favourite icon.
2849function getFaviconURL ()
2850{
2851 global $root, $image;
2852 return $root . $image['favicon']['path'];
2853}
2854
2855function renderReportSummary ()
2856{
2857 echo "Here be dragons :-P";
2858}
2859
2860function renderUIConfig ()
2861{
0a1b1268
DO
2862 global $configCache;
2863 startPortlet ('Current configuration');
2864 echo '<table border=0 class=cooltable align=center>';
2865 echo '<tr><th>name</th><th>type</th><th>Ok&nbsp;if&nbsp;empty?</th><th>value</th></tr>';
2866 foreach ($configCache as $v)
2867 if ($v['is_hidden'] == 'no')
2868 echo
2869 '<tr><td class=tdleft>' . $v['varname'] . '</td><td class=tdleft>' . $v['vartype'] .
2870 '</td><td class=tdleft>' . $v['emptyok'] . '</td><td class=tdleft>' .
2871 $v['varvalue'] . '</td></tr>';
2872 echo "</table>\n";
2873 finishPortlet();
7865c525
DO
2874}
2875
2876// This function queries the gateway about current VLAN configuration and
2877// renders a form suitable for submit. Ah, and it does submit processing as well.
111b4a67
DO
2878function renderVLANMembership ($object_id = 0)
2879{
fc8d0004 2880 global $root, $pageno, $tabno, $remote_username;
111b4a67
DO
2881 if ($object_id <= 0)
2882 {
2883 showError ('Invalid object_id in renderVLANMembership()');
2884 return;
2885 }
7865c525
DO
2886
2887 // Handle probable pending submit.
2888 if (isset ($_REQUEST['portcount']))
111b4a67 2889 {
7865c525
DO
2890 $data = getSwitchVLANs ($object_id);
2891 if ($data === NULL)
2da7c9b0 2892 {
7865c525 2893 showError ('getSwitchVLANs() failed in renderVLANMembership() during submit processing');
fc8d0004
DO
2894 return;
2895 }
7865c525
DO
2896 list ($vlanlist, $portlist) = $data;
2897 // Here we just build up 1 set command for the gateway with all of the ports
2898 // included. The gateway is expected to filter unnecessary changes silently
2899 // and to provide a list of responses with either error or success message
2900 // for each of the rest.
2901 assertUIntArg ('portcount');
2902 $nports = $_REQUEST['portcount'];
2903 $prefix = 'set ';
2904 $log = array();
2905 $setcmd = '';
2906 for ($i = 0; $i < $nports; $i++)
2907 if
2908 (
2909 !isset ($_REQUEST['portname_' . $i]) ||
2910 !isset ($_REQUEST['vlanid_' . $i]) ||
2911 $_REQUEST['portname_' . $i] != $portlist[$i]['portname']
2912 )
2913 $log[] = array ('code' => 'error', 'message' => "Ignoring mailformed record #${i} in form submit");
2914 elseif
2915 (
2916 $_REQUEST['vlanid_' . $i] == $portlist[$i]['vlanid'] ||
2917 $portlist[$i]['vlaind'] == 'TRUNK'
2918 )
2919 continue;
2920 else
2921 {
2922 $setcmd .= $prefix . $_REQUEST['portname_' . $i] . '=' . $_REQUEST['vlanid_' . $i];
2923 $prefix = ';';
2924 }
2925 printLog ($log);
2926 // Feed the gateway and interpret its (non)response.
2927 if ($setcmd != '')
2928 printLog (setSwitchVLANs ($object_id, $setcmd));
2929 }
2930
2931 // Reload and render.
2932 $data = getSwitchVLANs ($object_id);
2933 if ($data === NULL)
2934 return;
2935 list ($vlanlist, $portlist) = $data;
d28ea105
DO
2936
2937 echo '<table border=0 width="100%"><tr><td class=pcleft>'; // --------------------------------------------------
2938
2939 startPortlet ('VLAN table');
2940 echo '<table class=cooltable cellspacing=0 cellpadding=5 align=center>';
2941 echo "<tr><th>ID</th><th>Description</th></tr>";
2942 $order = 'even';
2943 global $nextorder;
2944 foreach ($vlanlist as $id => $descr)
2945 {
2946 echo "<tr class=row_${order}><td class=tdright>${id}</td><td class=tdleft>${descr}</td></tr>";
2947 $order = $nextorder[$order];
2948 }
2949 echo '</table>';
2950 finishPortlet();
2951
2952 echo '</td><td class=pcright>'; // ------------------------------------------------------------
2953
2954 startPortlet ('Port configuration');
7865c525
DO
2955 echo "<table class=widetable cellspacing=0 cellpadding='5' align=center><tr>";
2956 echo "<form method=post>";
2957 echo "<input type=hidden name=page value='${pageno}'>";
2958 echo "<input type=hidden name=tab value='${tabno}'>";
2959 echo "<input type=hidden name=object_id value=${object_id}>";
2960 echo "<input type=hidden name=portcount value=" . count ($portlist) . ">\n";
2961 $portno = 0;
9c0b0016 2962 $ports_per_row = getConfigVar ('PORTS_PER_ROW');
7865c525
DO
2963 foreach ($portlist as $port)
2964 {
2965 // Don't let wide forms break our fancy pages.
9c0b0016 2966 if ($portno % $ports_per_row == 0)
fc8d0004 2967 {
7865c525
DO
2968 if ($portno > 0)
2969 echo "</tr>\n";
9c0b0016 2970 echo "<tr><th>" . ($portno + 1) . "-" . ($portno + $ports_per_row) . "</th>";
fc8d0004 2971 }
0a73c02f 2972 echo '<td class=port_' . $port['status'] . '>' . $port['portname'] . '<br>';
7865c525
DO
2973 echo "<input type=hidden name=portname_${portno} value=" . $port['portname'] . '>';
2974 if ($port['vlanid'] == 'trunk')
fc8d0004 2975 {
7865c525
DO
2976 echo "<input type=hidden name=vlanid_${portno} value='trunk'>";
2977 echo "<select disabled multiple='multiple' size=1><option>TRUNK</option></select>";
fc8d0004 2978 }
7865c525 2979 else
fc8d0004 2980 {
7865c525 2981 echo "<select name=vlanid_${portno}>";
d28ea105 2982 foreach ($vlanlist as $v => $d)
fc8d0004 2983 {
7865c525
DO
2984 echo "<option value=${v}";
2985 if ($v == $port['vlanid'])
2986 echo ' selected';
2987 echo ">${v}</option>";
fc8d0004 2988 }
7865c525 2989 echo "</select>";
fc8d0004 2990 }
7865c525
DO
2991 $portno++;
2992 echo "</td>";
111b4a67 2993 }
9c0b0016 2994 echo "</tr><tr><td colspan=" . ($ports_per_row + 1) . "><input type=submit value='Save changes'></form></td></tr></table>";
7865c525 2995 finishPortlet();
d28ea105
DO
2996
2997 echo '</td></tr></table>'; // -------------------------------------
111b4a67
DO
2998}
2999
e673ee24 3000?>