New version 0.4.0 of the reports plugin
[racktables-contribs] / reports / reports / custom-report.php
1 <?php
2 // Custom Racktables Report v.0.4.0
3 // List a type of objects in a table and allow to export them via CSV
4
5 // 2016-02-04 - Mogilowski Sebastian <sebastian@mogilowski.net>
6 // 2018-09-10 - Lars Vogdt <lars@linux-schulserver.de>
7
8
9 function renderCustomReport()
10 {
11 # Get object list
12 $phys_typelist = readChapter (CHAP_OBJTYPE, 'o');
13 $attibutes = getAttrMap();
14 $aTagList = getTagList();
15 $report_type = 'custom';
16
17 if ( ( $_SERVER['REQUEST_METHOD'] == 'POST' ) && ( isset( $_POST['csv'] ) ) ) {
18
19 header('Content-type: text/csv');
20 header('Content-Disposition: attachment; filename=export_'.$report_type.'_'.date("Ymdhis").'.csv');
21 header('Pragma: no-cache');
22 header('Expires: 0');
23
24 $outstream = fopen("php://output", "w");
25
26 $aResult = getResult($_POST); // Get Result
27 $_POST['name'] = validateColums($_POST); // Fix empty colums
28
29 $csvDelimiter = (isset( $_POST['csvDelimiter'] )) ? $_POST['csvDelimiter'] : ',';
30
31 /* Create Header */
32 $aCSVRow = array();
33
34 if ( isset( $_POST['sName'] ) && $_POST['sName'] )
35 array_push($aCSVRow, "Name");
36
37 if ( isset( $_POST['label'] ) )
38 array_push($aCSVRow, "Label");
39
40 if ( isset( $_POST['type'] ) )
41 array_push($aCSVRow, "Type");
42
43 if ( isset( $_POST['asset_no'] ) )
44 array_push($aCSVRow, "Asset Tag");
45
46 if ( isset( $_POST['has_problems'] ) )
47 array_push($aCSVRow, "Has Problems");
48
49 if ( isset( $_POST['comment'] ) )
50 array_push($aCSVRow, "Comment");
51
52 if ( isset( $_POST['runs8021Q'] ) )
53 array_push($aCSVRow, "Runs 8021Q");
54
55 if ( isset( $_POST['location'] ) )
56 array_push($aCSVRow, "Location");
57
58 if ( isset( $_POST['MACs'] ) )
59 array_push($aCSVRow, "MACs");
60
61 if ( isset( $_POST['IPs'] ) )
62 array_push($aCSVRow, "IPs");
63
64 if ( isset( $_POST['attributeIDs'] ) ) {
65 foreach ( $_POST['attributeIDs'] as $attributeID )
66 array_push($aCSVRow, $attibutes[$attributeID]['name']);
67 }
68
69 if ( isset( $_POST['Tags'] ) )
70 array_push($aCSVRow, "Tags");
71
72 if ( isset( $_POST['Ports'] ) )
73 array_push($aCSVRow, "Ports");
74
75 if ( isset( $_POST['Containers'] ) )
76 array_push($aCSVRow, "Containers");
77
78 if ( isset( $_POST['Childs'] ) )
79 array_push($aCSVRow, "Child objects");
80
81 fputcsv( $outstream, $aCSVRow, $csvDelimiter );
82
83 /* Create data rows */
84 foreach ( $aResult as $Result ) {
85 $aCSVRow = array();
86
87 if ( isset( $_POST['sName'] ) )
88 array_push($aCSVRow, $Result['name']);
89
90 if ( isset( $_POST['label'] ) )
91 array_push($aCSVRow, $Result['label']);
92
93 if ( isset( $_POST['type'] ) )
94 array_push($aCSVRow, $phys_typelist[$Result['objtype_id']]);
95
96 if ( isset( $_POST['asset_no'] ) )
97 array_push($aCSVRow, $Result['asset_no']);
98
99 if ( isset( $_POST['has_problems'] ) )
100 array_push($aCSVRow, $Result['has_problems']);
101
102 if ( isset( $_POST['comment'] ) )
103 array_push($aCSVRow, str_replace('&quot;',"'",$Result['comment']));
104
105 if ( isset( $_POST['runs8021Q'] ) )
106 array_push($aCSVRow, $Result['runs8021Q']);
107
108 if ( isset( $_POST['location'] ) )
109 array_push($aCSVRow, preg_replace('/<a[^>]*>(.*)<\/a>/iU', '$1', getLocation($Result)));
110
111 if ( isset( $_POST['MACs'] ) ) {
112 $sTemp = '';
113 foreach ( getObjectPortsAndLinks($Result['id']) as $portNumber => $aPortDetails ) {
114 if ( trim($aPortDetails['l2address']) != '')
115 $sTemp .= $aPortDetails['l2address'].' ';
116 }
117 array_push($aCSVRow, $sTemp);
118 }
119
120 if ( isset( $_POST['IPs'] ) ) {
121 $sTemp = '';
122 foreach ( getObjectIPv4AllocationList($Result['id']) as $key => $aDetails ) {
123 if ( function_exists('ip4_format') )
124 $key = ip4_format($key);
125 if ( trim($key) != '')
126 $sTemp .= $key.' ';
127
128 }
129 foreach ( getObjectIPv6AllocationList($Result['id']) as $key => $aDetails ) {
130 if ( function_exists('ip6_format') )
131 $key = ip6_format($key);
132 else
133 $key = new IPv6Address($key);
134 if ( trim($key) != '')
135 $sTemp .= $key.' ';
136 }
137 array_push($aCSVRow, $sTemp);
138 }
139
140 if ( isset( $_POST['attributeIDs'] ) ) {
141 $attributes = getAttrValues ($Result['id']);
142 foreach ( $_POST['attributeIDs'] as $attributeID ) {
143 if ( isset( $attributes[$attributeID]['a_value'] ) )
144 array_push($aCSVRow,$attributes[$attributeID]['a_value']);
145 elseif ( ($attributes[$attributeID]['value'] != '') && ( $attributes[$attributeID]['type'] == 'date' ) )
146 array_push($aCSVRow,date("Y-m-d",$attributes[$attributeID]['value']));
147 else
148 array_push($aCSVRow,'');
149 }
150 }
151
152 if ( isset( $_POST['Tags'] ) ) {
153 $sTemp = '';
154 foreach ( $Result['tags'] as $aTag ) {
155 $sTemp .= $aTag['tag'].' ';
156 }
157 if ( count($Result['itags']) > 0 ) {
158 $sTemp .= '(';
159 foreach ( $Result['itags'] as $aTag ) {
160 $sTemp .= $aTag['tag'].' ';
161 }
162 $sTemp .= ')';
163 }
164 array_push($aCSVRow, $sTemp);
165 }
166
167 if ( isset( $_POST['Ports'] ) ) {
168 $sTemp = '';
169
170 foreach ( $Result['portsLinks'] as $port ) {
171 $sTemp .= $port['name'].': '.$port['remote_object_name'];
172 if ( trim($port['cableid']) != '')
173 $sTemp .= ' Cable ID: '.$port['cableid'];
174 $sTemp .= ' ';
175 }
176 $sTemp = trim($sTemp);
177
178 array_push($aCSVRow, $sTemp);
179 }
180
181 if ( isset( $_POST['Containers'] ) ) {
182 $sTemp = '';
183
184 foreach ( getObjectContainerList($Result['id']) as $key => $aDetails ) {
185 $sTemp .= trim($aDetails['container_name']).' ';
186 }
187 $sTemp = trim($sTemp);
188
189 array_push($aCSVRow, $sTemp);
190 }
191
192 if ( isset( $_POST['Childs'] ) ) {
193 $sTemp = '';
194
195 foreach ( getObjectChildObjectList($Result['id']) as $key => $aDetails ) {
196 $sTemp .= trim($aDetails['object_name']).' ';
197 }
198 $sTemp = trim($sTemp);
199
200 array_push($aCSVRow, $sTemp);
201 }
202
203 fputcsv( $outstream, $aCSVRow, $csvDelimiter );
204 }
205
206 fclose($outstream);
207
208 exit(0); # Exit normally after send CSV to browser
209
210 }
211
212 echo '<h2> Custom report</h2><ul>';
213
214 // Load stylesheet and jquery scripts
215 $css_path=getConfigVar('REPORTS_CSS_PATH');
216 $js_path=getConfigVar('REPORTS_JS_PATH');
217 addCSS ("$css_path/style.css");
218 addJS ("$js_path/saveFormValues.js");
219 addJS ("$js_path/jquery-latest.js");
220 addJS ("$js_path/jquery.tablesorter.js");
221 addJS ("$js_path/picnet.table.filter.min.js");
222
223 if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
224 echo '<a href="#" class="show_hide">Show/hide search form</a><br/><br/>';
225
226 echo '<div class="searchForm">';
227
228 echo '<form method="post" name="searchForm">';
229
230 echo '<table class="searchTable">
231 <tr>
232 <th>Object Type</th>
233 <th>Common Values</th>
234 <th>Attributes</th>
235 <th>Tags</th>
236 <th>Misc</th>
237 </tr>
238 <tr>';
239
240 echo '<td valign="top">
241 <table class="searchTable">';
242 $i=0;
243 foreach ( $phys_typelist as $objectTypeID => $sName ) {
244 if( $i % 2 )
245 echo '<tr class="odd">';
246 else
247 echo '<tr>';
248 echo ' <td>
249 <input type="checkbox" name="objectIDs[]" value="'.$objectTypeID.'"';
250 if (isset($_POST['objectIDs']) && in_array($objectTypeID, $_POST['objectIDs']) )
251 echo ' checked="checked"';
252 echo ' > '.$sName.'
253 </td>
254 </tr>';
255 $i++;
256 }
257 echo ' </table>
258 </td>';
259
260 echo '<td valign="top">
261 <table class="searchTable">
262 <tr><td><input type="checkbox" name="sName" value="1" ';if (isset($_POST['sName'])) echo ' checked="checked"'; echo '> Name</td></tr>
263 <tr class="odd"><td><input type="checkbox" name="label" value="1" ';if (isset($_POST['label'])) echo ' checked="checked"'; echo '> Label</td></tr>
264 <tr><td><input type="checkbox" name="type" value="1" ';if (isset($_POST['type'])) echo ' checked="checked"'; echo '> Type</td></tr>
265 <tr class="odd"><td><input type="checkbox" name="asset_no" value="1" ';if (isset($_POST['asset_no'])) echo ' checked="checked"'; echo '> Asset Tag</td></tr>
266 <tr><td><input type="checkbox" name="location" value="1" ';if (isset($_POST['location'])) echo ' checked="checked"'; echo '> Location</td></tr>
267 <tr class="odd"><td><input type="checkbox" name="has_problems" value="1" ';if (isset($_POST['has_problems'])) echo ' checked="checked"'; echo '> Has Problems</td></tr>
268 <tr><td><input type="checkbox" name="comment" value="1" ';if (isset($_POST['comment'])) echo ' checked="checked"'; echo '> Comment</td></tr>
269 <tr class="odd"><td><input type="checkbox" name="runs8021Q" value="1" ';if (isset($_POST['runs8021Q'])) echo ' checked="checked"'; echo '> Runs 8021Q</td></tr>
270 <tr><td><input type="checkbox" name="MACs" value="1" ';if (isset($_POST['MACs'])) echo ' checked="checked"'; echo '> MACs</td></tr>
271 <tr class="odd"><td><input type="checkbox" name="IPs" value="1" ';if (isset($_POST['IPs'])) echo ' checked="checked"'; echo '> IPs</td></tr>
272 <tr><td><input type="checkbox" name="Tags" value="1" ';if (isset($_POST['Tags'])) echo ' checked="checked"'; echo '> Tags</td></tr>
273 <tr class="odd"><td><input type="checkbox" name="Ports" value="1" ';if (isset($_POST['Ports'])) echo ' checked="checked"'; echo '> Ports</td></tr>
274 <tr><td><input type="checkbox" name="Containers" value="1" ';if (isset($_POST['Containers'])) echo ' checked="checked"'; echo '> Containers</td></tr>
275 <tr class="odd"><td><input type="checkbox" name="Childs" value="1" ';if (isset($_POST['Childs'])) echo ' checked="checked"'; echo '> Child objects</td></tr>
276 </table>
277 </td>';
278
279 echo '<td valign="top">
280 <table class="searchTable">';
281 $i=0;
282 foreach ( $attibutes as $attributeID => $aRow ) {
283 if( $i % 2 )
284 echo '<tr class="odd">';
285 else
286 echo '<tr>';
287 echo ' <td>
288 <input type="checkbox" name="attributeIDs[]" value="'.$attributeID.'"';
289 if (isset($_POST['attributeIDs']) && in_array($attributeID, $_POST['attributeIDs']) )
290 echo ' checked="checked"';
291 echo '> '.$aRow['name'].'
292 </td>
293 </tr>';
294 $i++;
295 }
296 echo ' </table>
297 </td>';
298
299 echo '<td valign="top">
300 <table class="searchTable">';
301
302 $i = 0;
303 foreach ( $aTagList as $aTag ) {
304 echo '<tr '.($i%2 ? 'class="odd"' : '').'>
305 <td>
306 <input type="checkbox" name="tag['.$aTag['id'].']" value="1" '.( isset($_POST['tag'][$aTag['id']]) ? 'checked="checked" ' : '').'> '.
307 $aTag['tag'].'
308 </td>
309 </tr>';
310 $i++;
311 }
312 if ( count($aTagList) < 1 )
313 echo '<tr><td><i>No Tags available</i></td></tr>';
314
315 echo ' </table>
316 </td>';
317
318 echo '<td valign="top">
319 <table class="searchTable">
320 <tr class="odd"><td><input type="checkbox" name="csv" value="1"> CSV Export</td></tr>
321 <tr><td><input type="text" name="csvDelimiter" value="," size="1"> CSV Delimiter</td></tr>
322 <tr class="odd"><td>Name Filter: <i>(Regular Expression)</i></td></tr>
323 <tr><td><input type="text" name="name_preg" value="'; if (isset($_POST['name_preg'])) echo $_POST['name_preg']; echo '" style="height: 11pt;"></td></tr>
324 <tr class="odd"><td>Asset Tag Filter: <i>(Regular Expression)</i></td></tr>
325 <tr><td><input type="text" name="tag_preg" value="'; if (isset($_POST['tag_preg'])) echo $_POST['tag_preg']; echo '" style="height: 11pt;"></td></tr>
326 <tr class="odd"><td>Comment Filter: <i>(Regular Expression)</i></td></tr>
327 <tr><td><input type="text" name="comment_preg" value="'; if (isset($_POST['comment_preg'])) echo $_POST['comment_preg']; echo '" style="height: 11pt;"></td></tr>
328 <tr class="odd"><td>&nbsp;</td></tr>
329 <tr>
330 <td>
331 Save:
332 <input id="nameQuery" type="text" name="nameQuery" value="" style="height: 11pt; width:150px"/> <input type="button" value=" Ok " onclick="saveQuery();">
333 </td>
334 </tr>
335 <tr class="odd">
336 <td>
337 Load:<br/>
338 <span id="loadButtons"></span>
339 <script type="text/javascript">
340 loadButtons();
341 </script>
342 </td>
343 </tr>
344 <tr><td>&nbsp;</td></tr>
345 <tr><td align="right"><input type="submit" value=" Search "></td></tr>
346 </table>
347 </td>
348 </tr>
349 </table>';
350
351 echo '</form>';
352
353 echo '</div>';
354
355 if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
356
357 $aResult = getResult($_POST); // Get Result
358 $_POST['sName'] = validateColums($_POST); // Fix empty colums
359
360 if ( count($aResult) > 0) {
361
362 echo '<table id="customTable" class="tablesorter">
363 <thead>
364 <tr>';
365
366 if ( isset( $_POST['sName'] ) && $_POST['sName'] )
367 echo '<th>Name</th>';
368
369 if ( isset( $_POST['label'] ) )
370 echo '<th>Label</th>';
371
372 if ( isset( $_POST['type'] ) )
373 echo '<th>Type</th>';
374
375 if ( isset( $_POST['asset_no'] ) )
376 echo '<th>Asset Tag</th>';
377
378 if ( isset( $_POST['has_problems'] ) )
379 echo '<th>Has Problems</th>';
380
381 if ( isset( $_POST['comment'] ) )
382 echo '<th>Comment</th>';
383
384 if ( isset( $_POST['runs8021Q'] ) )
385 echo '<th>Runs 8021Q</th>';
386
387 if ( isset( $_POST['location'] ) )
388 echo '<th>Location</th>';
389
390 if ( isset( $_POST['MACs'] ) )
391 echo '<th>MAC(s)</th>';
392
393 if ( isset( $_POST['IPs'] ) )
394 echo '<th>IP(s)</th>';
395
396 if ( isset( $_POST['attributeIDs'] ) ) {
397 foreach ( $_POST['attributeIDs'] as $attributeID )
398 echo '<th>'.$attibutes[$attributeID]['name'].'</th>';
399 }
400
401 if ( isset( $_POST['Tags'] ) ) {
402 echo '<th>Tags</th>';
403 }
404
405 if ( isset ($_POST['Ports']) ) {
406 echo '<th>Ports</th>';
407 }
408
409 if ( isset( $_POST['Containers'] ) ) {
410 echo '<th>Containers</th>';
411 }
412
413 if ( isset( $_POST['Childs'] ) ) {
414 echo '<th>Child objects</th>';
415 }
416
417 echo ' </tr>
418 </thead>
419 <tbody>';
420
421 foreach ( $aResult as $Result ) {
422
423 echo '<tr>';
424
425 if ( isset( $_POST['sName'] ) ) {
426 echo '<td>
427 <span class="object_'.str_replace('$','',$Result['atags'][1]['tag']).'">';
428 if ( isset( $Result['name'] ) )
429 echo '<a href="'. makeHref ( array( 'page' => 'object', 'object_id' => $Result['id']) ) .'">'.$Result['name'].'</a>';
430 else
431 echo '&nbsp;';
432 echo ' </span>
433 </td>';
434 }
435
436 if ( isset( $_POST['label'] ) ) {
437 echo '<td>';
438 if ( isset( $Result['label'] ) )
439 echo $Result['label'];
440 else
441 echo '&nbsp;';
442 echo '</td>';
443 }
444
445 if ( isset( $_POST['type'] ) ) {
446 echo '<td>';
447 if ( isset( $Result['objtype_id'] ) )
448 echo $phys_typelist[$Result['objtype_id']];
449 else
450 echo '&nbsp;';
451 echo '</td>';
452 }
453
454 if ( isset( $_POST['asset_no'] ) ) {
455 echo '<td>';
456 if ( isset( $Result['asset_no'] ) )
457 echo $Result['asset_no'];
458 else
459 echo '&nbsp;';
460 echo '</td>';
461 }
462
463 if ( isset( $_POST['has_problems'] ) ) {
464 echo '<td>';
465 if ( isset( $Result['has_problems'] ) )
466 echo $Result['has_problems'];
467 else
468 echo '&nbsp;';
469 echo '</td>';
470 }
471
472 if ( isset( $_POST['comment'] ) ) {
473 echo '<td>';
474 if ( isset( $Result['comment'] ) )
475 echo makeLinksInText($Result['comment']);
476 else
477 echo '&nbsp;';
478 echo '</td>';
479 }
480
481 if ( isset( $_POST['runs8021Q'] ) ) {
482 echo '<td>';
483 if ( isset( $Result['runs8021Q'] ) )
484 echo $Result['runs8021Q'];
485 else
486 echo '&nbsp;';
487 echo '</td>';
488 }
489
490 if ( isset( $_POST['location'] ) ) {
491 echo '<td>';
492 echo getLocation($Result);
493 echo '</td>';
494 }
495
496 if ( isset( $_POST['MACs'] ) ) {
497 echo '<td>';
498 foreach ( getObjectPortsAndLinks($Result['id']) as $portNumber => $aPortDetails ) {
499 if ( trim($aPortDetails['l2address']) != '')
500 echo $aPortDetails['l2address'].'<br/>';
501 }
502 echo '</td>';
503 }
504
505 if ( isset( $_POST['IPs'] ) ) {
506 echo '<td>';
507 foreach ( getObjectIPv4AllocationList($Result['id']) as $key => $aDetails ) {
508 if ( function_exists('ip4_format') )
509 $key = ip4_format($key);
510 if ( trim($key) != '')
511 echo $key . '<br/>';
512 }
513 foreach ( getObjectIPv6AllocationList($Result['id']) as $key => $aDetails ) {
514 if ( function_exists('ip6_format') )
515 $key = ip6_format($key);
516 else
517 $key = new IPv6Address($key);
518 if ( trim($key) != '')
519 echo $key . '<br/>';
520 }
521 echo '</td>';
522 }
523
524 if ( isset( $_POST['attributeIDs'] ) ) {
525 $attributes = getAttrValues ($Result['id']);
526 foreach ( $_POST['attributeIDs'] as $attributeID ) {
527 echo '<td>';
528 if ( isset( $attributes[$attributeID]['a_value'] ) && ($attributes[$attributeID]['a_value'] != '') )
529 echo $attributes[$attributeID]['a_value'];
530 elseif ( ($attributes[$attributeID]['value'] != '') && ( $attributes[$attributeID]['type'] == 'date' ) )
531 echo date("Y-m-d",$attributes[$attributeID]['value']);
532 else
533 echo '&nbsp;';
534
535 }
536 }
537
538 if ( isset( $_POST['Tags'] ) ) {
539 echo '<td>';
540 foreach ( $Result['tags'] as $aTag )
541 echo '<a href="'. makeHref ( array( 'page' => 'depot', 'tab' => 'default', 'andor' => 'and', 'cft[]' => $aTag['id']) ) .'">'.$aTag['tag'].'</a> ';
542
543 if ( count($Result['itags']) > 0 ) {
544 echo '(';
545 foreach ( $Result['itags'] as $aTag )
546 echo '<a href="'. makeHref ( array( 'page' => 'depot', 'tab' => 'default', 'andor' => 'and', 'cft[]' => $aTag['id']) ) .'">'.$aTag['tag'].'</a> ';
547
548 echo ')';
549 }
550 echo '</td>';
551 }
552
553 if ( isset ($_POST['Ports']) ) {
554 echo '<td>';
555
556 foreach ( $Result['portsLinks'] as $port ) {
557 echo $port['name'].': ';
558 if ( $port['remote_object_name'] != 'unknown' )
559 echo formatPortLink ($port['remote_object_id'], $port['remote_object_name'], $port['remote_id'], NULL);
560 else
561 echo $port['remote_object_name'];
562 if ( trim($port['cableid']) != '')
563 echo ' Cable ID: '.$port['cableid'];
564 echo '<br/>';
565 }
566
567 echo '</td>';
568 }
569
570 if ( isset ($_POST['Containers']) ) {
571 echo '<td>';
572
573 foreach ( getObjectContainerList($Result['id']) as $key => $aDetails ) {
574 echo '<a href="'. makeHref ( array( 'page' => 'object', 'object_id' => $key) ) .'">'.$aDetails['container_name'].'</a><br/>';
575 }
576
577 echo '</td>';
578 }
579
580 if ( isset ($_POST['Childs']) ) {
581 echo '<td>';
582
583 foreach ( getObjectChildObjectList($Result['id']) as $key => $aDetails ) {
584 echo '<a href="'. makeHref ( array( 'page' => 'object', 'object_id' => $key) ) .'">'.$aDetails['object_name'].'</a><br/>';
585 }
586
587 echo '</td>';
588 }
589
590 echo '</tr>';
591
592 }
593
594 echo ' </tbody>
595 </table>
596 <script type="text/javascript">$(".searchForm").hide();</script>';
597 }
598 else {
599 echo '<br/><br/><div align="center" style="font-size:10pt;"><i>No items found !!!</i></div><br/>';
600 }
601
602 echo '<script type="text/javascript">
603 $(document).ready(function()
604 {
605 $.tablesorter.defaults.widgets = ["zebra"];
606 $("#customTable").tablesorter(
607 { headers: {
608 }, sortList: [[0,0]] }
609 );
610 $("#customTable").tableFilter();
611
612 $(".show_hide").show();
613
614 $(".show_hide").click(function(){
615 $(".searchForm").slideToggle(\'slow\');
616 });
617
618 }
619 );
620 </script>';
621 }
622
623 }
624
625 /**
626 * getResult Function
627 *
628 * Call Racktables API to get Objects and filter the result if required
629 *
630 * @param array $post
631 * @return array Result
632 */
633 function getResult ( $post ) {
634
635 #Get available objects
636 $phys_typelist = readChapter (CHAP_OBJTYPE, 'o');
637
638 $rackObjectTypeID = array_search('Rack', $phys_typelist);
639 $rowObjectTypeID = array_search('Row', $phys_typelist);
640 $locationObjectTypeID = array_search('Location', $phys_typelist);
641
642 $rackRealm = false;
643 $rowRealm = false;
644 $locationRealm = false;
645
646 $sFilter = '';
647 if ( isset ($post['objectIDs']) ) {
648 foreach ( $post['objectIDs'] as $sFilterValue ) {
649 $sFilter.='{$typeid_'.$sFilterValue.'} or ';
650
651 if (($rackObjectTypeID) && ($sFilterValue == $rackObjectTypeID))
652 $rackRealm = true;
653 if (($rowObjectTypeID) && ($sFilterValue == $rowObjectTypeID))
654 $rowRealm = true;
655 if (($locationObjectTypeID) && ($sFilterValue == $locationObjectTypeID))
656 $locationRealm = true;
657
658 }
659 $sFilter=substr($sFilter, 0, -4);
660 $sFilter = '('.$sFilter.')';
661 }
662
663 $aResult = scanRealmByText ( 'object', $sFilter );
664
665 # Get other realms than objects if user selected them
666 if ($rackRealm)
667 $aResult = array_merge($aResult, scanRealmByText ( 'rack') );
668 if ($rowRealm)
669 $aResult = array_merge($aResult, scanRealmByText ( 'row') );
670 if ($locationRealm)
671 $aResult = array_merge($aResult, scanRealmByText ( 'location') );
672
673 // Add tags
674 $aTemp = array();
675 foreach ( $aResult as $Result) {
676 $Result['tags'] = loadEntityTags( 'object', $Result['id'] );
677 $Result['itags'] = getImplicitTags( $Result['tags'] );
678
679 array_push($aTemp, $Result);
680 }
681 $aResult = $aTemp;
682
683 // Search / Filter by name
684 if ( isset ($post['name_preg']) && ($post['name_preg'] != '') ) {
685 $aTemp = array();
686 foreach ( $aResult as $Result ) {
687 if ( preg_match ( '/'.$post['name_preg'].'/' , $Result['name']) )
688 array_push($aTemp, $Result);
689 }
690 $aResult = $aTemp;
691 }
692
693 // Search / Filter by tag
694 if ( isset ($post['tag_preg']) && ($post['tag_preg'] != '') ) {
695 $aTemp = array();
696 foreach ( $aResult as $Result ) {
697 if ( preg_match ( '/'.$post['tag_preg'].'/' , $Result['asset_no']) )
698 array_push($aTemp, $Result);
699 }
700 $aResult = $aTemp;
701 }
702
703 // Search / Filter by comment
704 if ( isset ($post['comment_preg']) && ($post['comment_preg'] != '') ) {
705 $aTemp = array();
706 foreach ( $aResult as $Result ) {
707 if ( preg_match ( '/'.$post['comment_preg'].'/' , $Result['comment']) )
708 array_push($aTemp, $Result);
709 }
710 $aResult = $aTemp;
711 }
712
713 // Tags
714 if ( (isset ($post['tag'])) && ( count($post['tag']) >0 ) ) {
715 $aTemp = array();
716 $aSearchTags = array_keys($post['tag']);
717
718 foreach ( $aResult as $Result ) {
719
720 foreach ( $Result['tags'] as $aTag ) {
721 if ( in_array($aTag['id'], $aSearchTags) )
722 array_push($aTemp, $Result);
723 }
724
725 foreach ( $Result['itags'] as $aTag ) {
726 if ( in_array($aTag['id'], $aSearchTags) )
727 array_push($aTemp, $Result);
728 }
729
730 }
731
732 $aResult = $aTemp;
733 }
734
735 // Ports - Load port data if necessary
736 if ( isset ($post['Ports']) ) {
737 $aTemp = array();
738
739 foreach ( $aResult as $Result ) {
740
741 $Result['portsLinks'] = getObjectPortsAndLinks ($Result['id']);
742
743 foreach ( $Result['portsLinks'] as $i => $port) {
744
745 $Result['portsLinks'][$i]['remote_object_name'] = 'unknown';
746 if (!is_null( $port['remote_object_id'] )){
747 $remote_object = spotEntity ('object', intval($port['remote_object_id']));
748 $Result['portsLinks'][$i]['remote_object_name'] = $remote_object['name'];
749 }
750 }
751
752 array_push($aTemp, $Result);
753 }
754
755 $aResult = $aTemp;
756 }
757
758 return $aResult;
759 }
760
761 /**
762 * validateColums Function
763 *
764 * If user doesn't select any colum to display this function preselect the name colum
765 * to display the results
766 *
767 * @param array $_POST
768 * @return bool display
769 */
770 function validateColums($POST) {
771 if (isset( $POST['sName'] ) )
772 return true;
773
774 if ( (!isset($POST['label'])) &&
775 (!isset($POST['asset_no'])) &&
776 (!isset($POST['has_problems'])) &&
777 (!isset($POST['comment'])) &&
778 (!isset($POST['runs8021Q'])) &&
779 (!isset($POST['location'])) &&
780 (!isset($POST['MACs'])) &&
781 (!isset($POST['label'])) &&
782 (!isset($POST['attributeIDs'])) ) {
783 return true;
784 }
785
786 }