glpi-plugin-auf : intégration Debian 8 et Ubuntu 14.04
[auf-serveur.git] / glpi-plugin-auf / plugin / report.operatingsystems.php
1 <?php
2 //Options for GLPI 0.71 and newer : need slave db to access the report
3 $USEDBREPLICATE=1;
4 $DBCONNECTION_REQUIRED=0;
5
6 include ("../../inc/includes.php");
7 include_once ("inc/functions.php");
8
9 $svg_color_names = Array('green', 'yellow', 'red', 'blue');
10
11 Session::checkRight("reports", "r");
12 Session::checkRight("computer", "r");
13
14 $report_title = "Systèmes d'exploitation par implantation";
15
16 #Html::header(Report::getTypeName(2), $_SERVER['PHP_SELF'], "utils", "report");
17 Html::header($report_title, $_SERVER['PHP_SELF'], "utils", "report");
18 Report::title();
19
20 echo "\n<p class='big b' style='margin: 5px; text-align: center'><span id='report_date' style='float: right; margin: 2px 20px; font-size: 75%; font-style: italic'>(".date('Y-m-d H:i:s')." UTC)</span>$report_title</p>";
21
22 $computer = new Computer();
23
24 $itemtype = 'Computer';
25 $table_item = getTableForItemType($itemtype);
26
27 //echo "<span class='big b'>Systèmes d'exploitation par implantation</span><br><br>";
28 echo "<table class='tab_cadrehov'>";
29 echo "<tr class='tab_bg_1'><th>Implantation</th><th>Système d'exploitation</th><th>Quantité</th></tr>";
30 $green_grand_total = 0;
31 $yellow_grand_total = 0;
32 $red_grand_total = 0;
33 $blue_grand_total = 0;
34 $grand_total = 0;
35
36 # parcours des régions
37 $query = "SELECT id,name,completename FROM glpi_entities WHERE (id=0 OR entities_id=0)";
38 $query .= " ".getEntitiesRestrictRequest("AND", "glpi_entities");
39 $region_result = $DB->query($query);
40 while ($region_data = $DB->fetch_assoc($region_result)) {
41 $region_id = $region_data['id'];
42 if ($region_id != 0) {
43 $region_name = getTreeLeafValueName("glpi_entities", $region_id);
44 echo "<tr><th colspan='3'></th></tr>\n";
45 } else {
46 $region_name = "AUF (non classé)";
47 }
48 echo "<tr class='tab_bg_1'><td colspan='3' class='b'>$region_name</td></tr>";
49
50 $green_total = 0;
51 $yellow_total = 0;
52 $red_total = 0;
53 $blue_total = 0;
54 $region_total = 0;
55
56 # operating systems per computer
57 $query = "SELECT COUNT(c.id) AS count, e.name AS ename,
58 (CASE WHEN o.name REGEXP '^Debian ' THEN SUBSTRING_INDEX(REPLACE(o.name,' GNU/Linux',''),'.',1)
59 WHEN o.name REGEXP '^Ubuntu ' THEN SUBSTRING_INDEX(REPLACE(o.name,' LTS',''),'.',2)
60 WHEN o.name REGEXP '^Microsoft' THEN REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(o.name,'™',''),'®',''),'fessional',''),'fessionnel',''),'Microsoft ','')
61 WHEN o.name REGEXP '^Mac ' THEN REPLACE(o.name,'Mac ','')
62 ELSE o.name END) AS oname
63 FROM `$table_item` c
64 LEFT JOIN glpi_entities e ON (c.entities_id = e.id)
65 LEFT JOIN glpi_operatingsystems o ON (c.operatingsystems_id = o.id)
66 WHERE c.is_deleted = '0' AND c.is_template = '0'
67 ".getEntitiesRestrictRequest("AND", "c");
68 if ($region_id != 0) {
69 $query .= " AND ".getRealQueryForTreeItem("glpi_entities", $region_id, "e.id");
70 } else {
71 $query .= " AND e.id = '0'";
72 }
73 $query .= " GROUP BY 2,3 ORDER BY 2,3";
74 $result = $DB->query($query);
75 while ($data=$DB->fetch_assoc($result)) {
76 if (empty($data['ename'])) {
77 $data['ename'] = "<i>(indéterminé)</i>";
78 }
79 if (empty($data['oname'])) {
80 $data['oname'] = "<i>(indéterminé)</i>";
81 }
82 if (($data['oname'] == 'Debian 8') || ($data['oname'] == 'Ubuntu 12.04')) {
83 $oname_plus = '<svg width="5" height="5" style="background-color: #00ff00; margin: 1px;"/>';
84 $green_total += $data['count'];
85 } elseif (($data['oname'] == 'Debian 7') || ($data['oname'] == 'Ubuntu 14.04')) {
86 $oname_plus = '<svg width="5" height="5" style="background-color: #ffff00; margin: 1px;"/>';
87 $yellow_total += $data['count'];
88 } elseif ((substr($data['oname'],0,7) == 'Windows') || (substr($data['oname'],strlen($data['oname'])-4,4) == 'OS X')) {
89 $oname_plus = '<svg width="5" height="5" style="background-color: #0000ff; margin: 1px;"/>';
90 $blue_total += $data['count'];
91 } else {
92 $oname_plus = '<svg width="5" height="5" style="background-color: #ff0000; margin: 1px;"/>';
93 $red_total += $data['count'];
94 }
95 echo "<tr class='tab_bg_2 auf_show_details'>";
96 echo "<td>&nbsp;&nbsp;".$data['ename']."</td>";
97 echo "<td>".$oname_plus."&nbsp;".$data['oname']."</td>";
98 echo "<td class='numeric'>".$data['count']."</td></tr>";
99 $region_total += $data['count'];
100 }
101
102 echo "<tr class='tab_bg_2'><td class='b'>&nbsp;&nbsp;Sous-total</td>";
103 echo "<td>".svg_bar(Array($green_total,$yellow_total,$red_total,$blue_total), 400, 5)."</td>";
104 echo "<td class='numeric b'>$region_total</td></tr>";
105
106 $green_grand_total += $green_total;
107 $yellow_grand_total += $yellow_total;
108 $red_grand_total += $red_total;
109 $blue_grand_total += $blue_total;
110 $grand_total += $region_total;
111 } // fin des régions
112
113 #echo "<tr class='tab_bg_1'><td colspan='3'>&nbsp;</td></tr>";
114 echo "<tr><th colspan='3'></th></tr>\n";
115
116 # total operating systems
117 $query = "SELECT COUNT(*) FROM `".$table_item."`
118 LEFT JOIN `glpi_computers_items`
119 ON (`glpi_computers_items`.`itemtype` = '".$itemtype."'
120 AND `glpi_computers_items`.`items_id` = `".$table_item."`.`id`)
121 WHERE `".$table_item."`.`is_deleted` = '0'
122 AND `".$table_item."`.`is_template` = '0' ".
123 getEntitiesRestrictRequest("AND", $table_item);
124 $result = $DB->query($query);
125 $total = $DB->result($result, 0, 0);
126
127 echo "<tr class='tab_bg_1'><td class='b'>Total général</td>";
128 echo "<td>".svg_bar(Array($green_grand_total,$yellow_grand_total,$red_grand_total,$blue_grand_total), 400, 5)."</td>";
129 echo "<td class='numeric b'>$total</td></tr>";
130
131 echo "</table>";
132
133 Html::footer();
134 ?>