wattage_consumption: indent with tabs
[racktables-contribs] / wattage_consumption.php
CommitLineData
fba27978
CB
1<?php
2
3//-----------------------------------------------------------------------------------
4// Wattage Consumption - written by curtisb
5//$tab['reports']['watts_per_row'] = 'Energy Per Row';
6$tab['reports']['watts_per_row'] = 'Enviromental Totals';
7$tabhandler['reports']['watts_per_row'] = 'getWattsPerRow';
8
9function getWattsPerRow ()
10{
b62db262
DO
11 // assertions
12 // find the needed attributes
fba27978 13
b62db262 14 global $nextorder;
fba27978 15
b62db262
DO
16 // Was this function called with a specific row_id?
17 if (isset ($_REQUEST['row_id']))
18 {
19 assertStringArg ('row_id');
20 $row_toshow = $_REQUEST['row_id'];
21 }
22 else
23 {
24 $row_toshow = '50032';
25 }
fba27978 26
b62db262
DO
27 //from renderRackspace(), interface.php:151
28 $found_racks = array();
29 $rows = array();
30 $cellfilter = getCellFilter();
31 $rackCount = 0;
32 $order = 'odd';
33 // get rackspace information
34 foreach (getRackRows() as $row_id => $row_name) {
35 $rackList = filterCellList (listCells ('rack', $row_id), $cellfilter['expression']);
36 $found_racks = array_merge($found_racks, $rackList);
37 $rows[] = array(
38 'row_id' => $row_id,
39 'row_name' => $row_name,
40 'racks' => $rackList
41 );
42 $rackCount += count($rackList);
43 }
fba27978 44
b62db262
DO
45 // Main layout starts.
46 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
fba27978 47
b62db262
DO
48 // Left portlet with list of rows.
49 echo "<tr><td class=pcleft>";
50 startPortlet ('Rack Rows (' . count ($rows) . ')');
51 echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
52 foreach ($rows as $row)
53 {
54 $row_id = $row['row_id'];
55 $row_name = $row['row_name'];
56 $rackList = $row['racks'];
fba27978 57
b62db262
DO
58 echo "<tr class=row_${order}><td width='20%'></td><td class=tdleft>";
59 if (!count ($rackList))
60 {
61 echo "${row_name} (empty row)";
62 }
63 else
64 {
65 echo "<a href='" . makeHref(array('page'=>'reports', 'tab'=>'watts_per_row', 'row_id'=>$row_id)) . "'>${row_name}</a>";
66 }
67 echo "<td><tr>\n";
68 $order = $nextorder[$order];
69 }
fba27978 70
b62db262
DO
71 echo "</td></tr>\n";
72 echo "</table><br>\n";
73 finishPortlet();
fba27978 74
b62db262 75 echo "</td><td class=pcright>";
fba27978 76
b62db262
DO
77 // Right Portlet: Draw the racks in the selected row
78 $rowInfo = getRackRowInfo ($row_toshow);
79 $cellfilter = getCellFilter();
80 $rackList = filterCellList (listCells ('rack', $row_toshow), $cellfilter['expression']);
fba27978 81
b62db262
DO
82 global $nextorder;
83 $rackwidth = getRackImageWidth() * getConfigVar ('ROW_SCALE');
84 // Maximum number of racks per row is proportionally less, but at least 1.
85 $maxPerRow = max (floor (getConfigVar ('RACKS_PER_ROW') / getConfigVar ('ROW_SCALE')), 1);
86 $rackListIdx = 0;
87 $rowTotalWattage = 0;
88 $order = 'odd';
89 startPortlet ('Racks within '. $rowInfo['name'] . ' (' . count($rackList) . ')' );
90 echo "<table border=0 cellspacing=5 align='center'><tr>";
91 foreach ($rackList as $rack)
92 {
93 $rackTotalWattage = 0;
94 // see renderRack(), interface.php:311
95 $rackData = spotEntity ('rack', $rack['id']);
96 amplifyCell ($rackData);
97 $objectChildren = getEntityRelatives ('children', 'object', $objectData['id']);
98 foreach ($rackData['mountedObjects'] as $object)
99 {
100 $objectData = spotEntity ('object', $object);
101 amplifyCell ($objectData);
102 foreach (getAttrValues ($objectData['id']) as $record)
103 {
104 if ($record['name'] == 'Wattage consuption')
105 {
106 $rackTotalWattage += $record['value'];
107 }
108 }
109 }
110 if ($rackListIdx % $maxPerRow == 0)
111 {
112 if ($rackListIdx > 0)
113 echo '</tr>';
114 echo '<tr>';
115 }
116 echo "<td align=center class=row_${order}><a href='".makeHref(array('page'=>'rack', 'rack_id'=>$rack['id']))."'>";
117 echo "<img border=0 width=${rackwidth} height=" . (getRackImageHeight ($rack['height']) * getConfigVar ('ROW_SCALE'));
118 echo " title='${rack['height']} units'";
119 echo "src='?module=image&img=minirack&rack_id=${rack['id']}'>";
120 echo "<br>${rack['name']} ($rackTotalWattage)</a></td>";
121 $order = $nextorder[$order];
122 $rackListIdx++;
123 $rowTotalWattage += $rackTotalWattage;
124 }
fba27978 125
b62db262
DO
126 echo "</tr><tr><td align=center colspan=";
127 print (count($rackList));
128 echo "><br><b>The row total for attribute Wattage consuption is: $rowTotalWattage</b></td>\n";
fba27978 129
b62db262
DO
130 echo "</tr></table>\n";
131 finishPortlet();
132 echo "</td></tr></table>";
fba27978
CB
133}
134
135?>