warranty_report.php: indentation
[racktables-contribs] / warranty_report.php
1 <?php
2 //
3 // Warranty by Ernest Shaffer
4 // Version: 2.1
5 //
6 // Displays objects with pending or expired HW warranty expiration dates
7 // Groups them into 4 groups:
8 // HW warranty has expired
9 // HW warranty expires within 30 days
10 // HW warranty expires within 60 days
11 // HW warranty expires within 90 days
12 //
13
14 $tab['reports']['warranty'] = 'HW Warranty Expires';
15 $tabhandler['reports']['warranty'] = 'hwExpireReport';
16
17 function scanAttrRelativeDays ($attr_id, $date_format, $not_before_days, $not_after_days)
18 {
19 $attrmap = getAttrMap();
20 if ($attrmap[$attr_id]['type'] != 'string')
21 throw new InvalidArgException ('attr_id', $attr_id, 'attribute cannot store dates');
22 return usePreparedSelectBlade
23 (
24 'SELECT a.string_value, r.id, r.name, r.asset_no ' .
25 'FROM AttributeValue a LEFT JOIN RackObject r ON a.object_id = r.id ' .
26 'WHERE attr_id=? and STR_TO_DATE(a.string_value, ?) BETWEEN '.
27 'DATE_ADD(curdate(), INTERVAL ? DAY) and DATE_ADD(curdate(), INTERVAL ? DAY)',
28 array ($attr_id, $date_format, $not_before_days, $not_after_days)
29 );
30 }
31
32 function hwExpireReport ()
33 {
34 global $nextorder;
35 addCSS ('
36 tr.has_problems_even {
37 background-color: #ffa0a0;
38 }
39 tr.has_problems_odd {
40 background-color: #ffd0d0;
41 }
42 ', TRUE);
43
44 $breakdown = array
45 (
46 array ('from' => -365, 'to' => 0, 'title' => 'HW warranty has expired'),
47 array ('from' => 0, 'to' => 30, 'title' => 'HW warranty expires within 30 days'),
48 array ('from' => 30, 'to' => 60, 'title' => 'HW warranty expires within 60 days'),
49 array ('from' => 60, 'to' => 90, 'title' => 'HW warranty expires within 90 days'),
50 );
51
52 foreach ($breakdown as $section)
53 {
54 $count = 0;
55 $result = scanAttrRelativeDays (22, '%m/%d/%Y', $section['from'], $section['to']);
56 if (! count ($result))
57 continue;
58
59 startPortlet ($section['title']);
60 echo "<table align=center width=60% border=0 cellpadding=5 cellspacing=0 align=center class=cooltable><tr valign=top>";
61
62 echo "<th align=center>Count</th>";
63 echo "<th align=center>Name</th>";
64 echo "<th align=center>Assett Tag</th>";
65 echo "<th align=center>Date Warranty <br> Expires</th>";
66
67 $order = 'odd';
68 while ($row = $result->fetch (PDO::FETCH_ASSOC))
69 {
70 if ($days == 0) {
71 echo "<tr class=has_problems_${order} valign=top>";
72 } else {
73 echo "<tr class=row_${order} valign=top>";
74 }
75 printf("<td>%s</td>", $count += 1);
76 echo "<td><a href='".makeHref(array('page'=>'object', 'object_id'=>$row['id']))."'>${row['name']}</a></td>";
77 printf("<td>%s</td>", $row['asset_no']);
78 printf("<td>%s</td>", $row['string_value']);
79 echo "</tr>\n";
80 $order = $nextorder[$order];
81 }
82 echo "</table>\n";
83 finishPortlet ();
84 }
85 }
86
87 ?>