glpi-plugin-auf : intégration Debian 8 et Ubuntu 14.04
[auf-serveur.git] / glpi-plugin-auf / plugin / report.operatingsystems.php
CommitLineData
277feb35
P
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
6include ("../../inc/includes.php");
1135f035
P
7include_once ("inc/functions.php");
8
9$svg_color_names = Array('green', 'yellow', 'red', 'blue');
277feb35
P
10
11Session::checkRight("reports", "r");
12Session::checkRight("computer", "r");
13
118fab7c
P
14$report_title = "Systèmes d'exploitation par implantation";
15
277feb35 16#Html::header(Report::getTypeName(2), $_SERVER['PHP_SELF'], "utils", "report");
118fab7c 17Html::header($report_title, $_SERVER['PHP_SELF'], "utils", "report");
277feb35
P
18Report::title();
19
118fab7c
P
20echo "\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
277feb35
P
22$computer = new Computer();
23
277feb35
P
24$itemtype = 'Computer';
25$table_item = getTableForItemType($itemtype);
26
749e76d6 27//echo "<span class='big b'>Systèmes d'exploitation par implantation</span><br><br>";
277feb35
P
28echo "<table class='tab_cadrehov'>";
29echo "<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);
40while ($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);
67d402c6 44 echo "<tr><th colspan='3'></th></tr>\n";
277feb35
P
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)
b38636fc 60 WHEN o.name REGEXP '^Microsoft' THEN REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(o.name,'™',''),'®',''),'fessional',''),'fessionnel',''),'Microsoft ','')
277feb35
P
61 WHEN o.name REGEXP '^Mac ' THEN REPLACE(o.name,'Mac ','')
62 ELSE o.name END) AS oname
63 FROM `$table_item` c
277feb35
P
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");
68if ($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);
75while ($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 }
1135f035 82 if (($data['oname'] == 'Debian 8') || ($data['oname'] == 'Ubuntu 12.04')) {
277feb35
P
83 $oname_plus = '<svg width="5" height="5" style="background-color: #00ff00; margin: 1px;"/>';
84 $green_total += $data['count'];
1135f035 85 } elseif (($data['oname'] == 'Debian 7') || ($data['oname'] == 'Ubuntu 14.04')) {
277feb35
P
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
277feb35 102echo "<tr class='tab_bg_2'><td class='b'>&nbsp;&nbsp;Sous-total</td>";
1135f035 103echo "<td>".svg_bar(Array($green_total,$yellow_total,$red_total,$blue_total), 400, 5)."</td>";
277feb35
P
104echo "<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
67d402c6
P
113#echo "<tr class='tab_bg_1'><td colspan='3'>&nbsp;</td></tr>";
114echo "<tr><th colspan='3'></th></tr>\n";
277feb35
P
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
277feb35 127echo "<tr class='tab_bg_1'><td class='b'>Total général</td>";
1135f035 128echo "<td>".svg_bar(Array($green_grand_total,$yellow_grand_total,$red_grand_total,$blue_grand_total), 400, 5)."</td>";
277feb35
P
129echo "<td class='numeric b'>$total</td></tr>";
130
131echo "</table>";
132
133Html::footer();
134?>