save patch_cords.dia
[racktables-contribs] / ok-cablereport-v3.php
CommitLineData
dd8b2edd
IR
1<?php
2
3///////////////////////////////////////////////////////////
4// Opin Kerfi: CableReport
a2492010 5// Version: 3.2
dd8b2edd
IR
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.
68cfd931 10// Tested on Racktables version 0.20.5 and 0.20.7.
dd8b2edd
IR
11//
12// Author: Ingimar Robertsson <ingimar@ok.is>
13//
14// Installation:
68cfd931 15// Copy ok-cablereport-v31.php into the Racktables plugins folder.
dd8b2edd
IR
16//
17// Version History:
12c3380e 18// 3.2 - Changed fetchPortList call
68cfd931 19// 3.1 - Replaced SQL query with Racktables API calls and added links to devices and ports
dd8b2edd
IR
20// 3.0 - Major cleanup of version 2.0 and republished to racktables-contrib
21// 2.0 - First version using jQuery/DataTables
22// 1.0 - Initial version, static table
23///////////////////////////////////////////////////////////
24
25// Variables:
26$tabname = 'Cable Report';
27$tableheader = 'Cable Report for Racktables';
68cfd931 28$displaylinks = 1; // 1 = Display HTML links for devices and ports
dd8b2edd
IR
29
30///////////////////////////////////////////////////////////
a2492010
IR
31$tabhandler['reports']['cablereport'] = 'CableReport'; // register a report rendering function
32$tab['reports']['cablereport'] = $tabname; // title of the report tab
dd8b2edd 33
a2492010 34function CableReport()
dd8b2edd 35{
68cfd931 36 global $tableheader , $displaylinks;
dd8b2edd 37
68cfd931
IR
38 // Remote jQuery and DataTables files:
39 echo '<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.0/css/jquery.dataTables.css">';
40 echo '<script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-1.10.2.min.js"></script>';
41 echo '<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.0/js/jquery.dataTables.js"></script>';
dd8b2edd
IR
42
43 // Local jQuery and DataTables files from DataTables-1.10.0 distribution zip:
68cfd931
IR
44 //echo '<link rel="stylesheet" type="text/css" href="/rt/extensions/cablereportv3/DataTables-1.10.0/media/css/jquery.dataTables.css">';
45 //echo '<script type="text/javascript" charset="utf8" src="/rt/extensions/cablereportv3/DataTables-1.10.0/media/js/jquery.js"></script>';
46 //echo '<script type="text/javascript" charset="utf8" src="/rt/extensions/cablereportv3/DataTables-1.10.0/media/js/jquery.dataTables.js"></script>';
dd8b2edd
IR
47
48 echo '<script>
49 $(document).ready(function() {
50 $("#cablereport").dataTable({
68cfd931 51 "bPaginate": "true",
dd8b2edd
IR
52 "bLengthChange": "false",
53 "sPaginationType": "full_numbers",
54 "aaSorting": [[ 0, "desc" ]],
68cfd931
IR
55 "iDisplayLength": 20,
56 "stateSave": false,
57 "oLanguage": {
58 "sLengthMenu": \'Display <select>\'+
59 \'<option value="10">10</option>\'+
60 \'<option value="20">20</option>\'+
61 \'<option value="30">30</option>\'+
62 \'<option value="40">40</option>\'+
63 \'<option value="50">50</option>\'+
64 \'<option value="-1">All</option>\'+
65 \'</select> records\'
66 }
dd8b2edd
IR
67 });
68 });
69 </script>';
70
68cfd931 71 echo "\n";
dd8b2edd
IR
72 echo '<div class=portlet>';
73 echo '<h2>' . $tableheader . '</h2>';
68cfd931 74 echo "\n";
dd8b2edd 75 echo '<table id="cablereport" class="display">';
68cfd931 76 echo "\n";
dd8b2edd
IR
77 echo '<thead><tr>';
78 echo '<th>Cable ID</th>';
79 echo '<th>Device 1</th>';
80 echo '<th>Port 1</th>';
81 echo '<th>Type 1</th>';
82 echo '<th>Device 2</th>';
83 echo '<th>Port 2</th>';
84 echo '<th>Type 2</th>';
68cfd931
IR
85 echo '</tr></thead>';
86 echo "\n";
87 echo '<tbody>';
88 echo "\n";
89
12c3380e 90 $allports = fetchPortList('IF(la.porta, pa.id, pb.id) IS NOT NULL');
68cfd931
IR
91 $cid = 0;
92 foreach ( $allports as $port ) {
93 $allporttypes[$port['id']] = $port['oif_name'];
dd8b2edd 94
68cfd931
IR
95 if ( $port['linked'] != 1 ) {
96 continue;
97 }
98
99 if ( $done[$port['id']] == 1 ) {
100 continue;
101 } else {
102 $cid++;
103 $cabletable[$cid]['cableid'] = $port['cableid'];
104 if ( $displaylinks == 1 ) {
105 $cabletable[$cid]['device1'] = formatPortLink($port['object_id'],$port['object_name'],NULL,NULL);
106 $cabletable[$cid]['port1'] = formatPortLink($port['object_id'],NULL,$port['id'],$port['name']);
107 } else {
108 $cabletable[$cid]['device1'] = $port['object_name'];
109 $cabletable[$cid]['port1'] = $port['name'];
110 }
111 $cabletable[$cid]['port1id'] = $port['id'];
112 $cabletable[$cid]['type1'] = $port['oif_name'];
113 if ( $displaylinks == 1 ) {
114 $cabletable[$cid]['device2'] = formatPortLink($port['remote_object_id'],$port['remote_object_name'],NULL,NULL);
115 $cabletable[$cid]['port2'] = formatPortLink($port['remote_object_id'],NULL,$port['remote_id'],$port['remote_name']);
116 } else {
117 $cabletable[$cid]['device2'] = $port['remote_object_name'];
118 $cabletable[$cid]['port2'] = $port['remote_name'];
119 }
120 $cabletable[$cid]['port2id'] = $port['remote_id'];
121 $cabletable[$cid]['type2'] = ''; # missing from fetchPortList() add later from $allporttypes being created;
122 $done[$port['remote_id']] = 1;
123 }
124 }
125
126 foreach ( $cabletable as $cable ) {
dd8b2edd 127 echo '<tr>';
68cfd931
IR
128 echo '<td>';
129 echo $cable['cableid'];
130 echo '</td><td>';
131 echo $cable['device1'];
132 echo '</td><td>';
133 echo $cable['port1'];
134 echo '</td><td>';
135 echo $cable['type1'];
136 echo '</td><td>';
137 echo $cable['device2'];
138 echo '</td><td>';
139 echo $cable['port2'];
140 echo '</td><td>';
141 echo $allporttypes[$cable['port2id']];
142 echo '</td>';
143 echo '</tr>';
144 echo "\n";
dd8b2edd
IR
145 }
146
147 echo '</tbody></table><br/><br/>';
a2492010 148 echo 'ok-cablereport version 3.2';
dd8b2edd
IR
149 echo '</div>';
150}