Create ok-cablereport-v3.php
[racktables-contribs] / ok-cablereport-v3.php
CommitLineData
dd8b2edd
IR
1<?php
2
3///////////////////////////////////////////////////////////
4// Opin Kerfi: CableReport
5// Version: 3.0
6//
7// Description:
8// Racktables reports plugin for listing of all linked cables in Racktables.
9// Uses jQuery and DataTables for easy sorting and searching.
10// Tested on Racktables version 0.20.5.
11//
12// Author: Ingimar Robertsson <ingimar@ok.is>
13//
14// Installation:
15// Copy ok-cablereport-v3.php into the Racktables plugins folder.
16//
17// Version History:
18// 3.0 - Major cleanup of version 2.0 and republished to racktables-contrib
19// 2.0 - First version using jQuery/DataTables
20// 1.0 - Initial version, static table
21///////////////////////////////////////////////////////////
22
23// Variables:
24$tabname = 'Cable Report';
25$tableheader = 'Cable Report for Racktables';
26
27///////////////////////////////////////////////////////////
28$tabhandler['reports']['cablereportv3'] = 'CableReportV3'; // register a report rendering function
29$tab['reports']['cablereportv3'] = $tabname; // title of the report tab
30
31function CableReportV3()
32{
33 global $tableheader;
34 $query = 'SELECT L.cable AS cableid, O.name AS dev1, P.name AS port1, D.dict_value as type1, ' .
35 ' O2.name AS dev2, P2.name as port2, D2.dict_value as type2 ' .
36 'FROM Link as L ' .
37 'LEFT JOIN Port as P on P.id = L.porta ' .
38 'LEFT JOIN Port as P2 on P2.id = L.portb ' .
39 'LEFT JOIN Object as O on O.id = P.object_id ' .
40 'LEFT JOIN Object as O2 on O2.id = P2.object_id ' .
41 'LEFT JOIN Dictionary as D on D.dict_key = P.type ' .
42 'LEFT JOIN Dictionary as D2 on D2.dict_key = P2.type ';
43
44 $result = usePreparedSelectBlade ($query);
45
46 // Local jQuery and DataTables files from DataTables-1.10.0 distribution zip:
47 echo '<link rel="stylesheet" type="text/css" href="/rt/extensions/cablereportv3/DataTables-1.10.0/media/css/jquery.dataTables.css">';
48 echo '<script type="text/javascript" charset="utf8" src="/rt/extensions/cablereportv3/DataTables-1.10.0/media/js/jquery.js"></script>';
49 echo '<script type="text/javascript" charset="utf8" src="/rt/extensions/cablereportv3/DataTables-1.10.0/media/js/jquery.dataTables.js"></script>';
50 // Remote jQuery and DataTables files:
51// echo '<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.0/css/jquery.dataTables.css">';
52// echo '<script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-1.10.2.min.js"></script>';
53// echo '<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.0/js/jquery.dataTables.js"></script>';
54
55 echo '<script>
56 $(document).ready(function() {
57 $("#cablereport").dataTable({
58 "bPaginate": "false",
59 "bLengthChange": "false",
60 "sPaginationType": "full_numbers",
61 "aaSorting": [[ 0, "desc" ]],
62 "iDisplayLength": 99999,
63 });
64 });
65 </script>';
66
67
68 echo '<div class=portlet>';
69 echo '<h2>' . $tableheader . '</h2>';
70 echo '<table id="cablereport" class="display">';
71 echo '<thead><tr>';
72 echo '<th>Cable ID</th>';
73 echo '<th>Device 1</th>';
74 echo '<th>Port 1</th>';
75 echo '<th>Type 1</th>';
76 echo '<th>Device 2</th>';
77 echo '<th>Port 2</th>';
78 echo '<th>Type 2</th>';
79 echo '</tr></thead><tbody>';
80
81 foreach ($result as $row)
82 {
83 echo '<tr>';
84 echo '<td><b>' . $row['cableid'] . '</b></td>';
85 echo '<td><b>' . $row['dev1'] . '</b></td>';
86 echo '<td><b>' . $row['port1'] . '</b></td>';
87 echo '<td>' . $row['type1'] . '</td>';
88 echo '<td><b>' . $row['dev2'] . '</b></td>';
89 echo '<td><b>' . $row['port2'] . '</b></td>';
90 echo '<td>' . $row['type2'] . '</td>';
91 echo "</tr>\n";
92 }
93
94 echo '</tbody></table><br/><br/>';
95 echo '</div>';
96}
97?>