glpi-plugin-auf : rapport sur la migration Ubuntu
[auf-serveur.git] / glpi-plugin-auf / plugin / rapport.migrationubuntu.php
CommitLineData
749e76d6
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");
7
d3e48ecc
P
8$svg_bar_width = 28;
9$svg_bar_height = 10;
10
749e76d6
P
11Session::checkRight("reports", "r");
12Session::checkRight("computer", "r");
13
14#Html::header(Report::getTypeName(2), $_SERVER['PHP_SELF'], "utils", "report");
15Html::header("Suivi de la migration vers Ubuntu 12.04.", $_SERVER['PHP_SELF'], "utils", "report");
16Report::title();
17
d3e48ecc
P
18#echo "\n<p class='big b' style='text-align: center'>Suivi de la migration vers Ubuntu 12.04</p><br><br>";
19#echo "<p style=\"font-size: 120%; text-align: center;\">Les données du rapport de migration Ubuntu seront disponibles à partir du jeudi 24 avril 2014.<br />En attendant vous pouvez déjà consulter les rapports sur le <a href=\"https://glpi.auf.org/glpi/plugins/auf/report.computers.php\">parc machine</a> et sur les <a href=\"https://glpi.auf.org/glpi/plugins/auf/report.operatingsystems.php\">systèmes d'exploitation</a>.</p>";
20
21$computer = new Computer();
22
23$itemtype = 'Computer';
24$table_item = getTableForItemType($itemtype);
25
26$svg_colors = Array('red'=>'#ffa0a0', 'green'=>'#a0ffa0', 'yellow'=>'#ffdd80', 'blue'=>'#a0a0ff');
27
28function svg_circle($color, $size=4) {
29 global $svg_colors;
30 if (array_key_exists($color, $svg_colors)) { $color = $svg_colors[$color]; }
31 $r = (int)$size; $cx = $r+1; $cy = $r+1;
32 $svg = '<svg width="'.(2+2*$r).'" height="'.(2+2*$r).'" style="margin: 1px; vertical-align: middle;">';
33 $svg .= "<circle cx='$cx' cy='$cy' r='$r' stroke='black' stroke-width='0' fill='$color' />";
34 $svg .= '</svg>';
35 return $svg;
36}
37
38function svg_pie_chart($values, $size=16) {
39 global $svg_colors;
40 $color_names = Array('blue', 'red', 'green', 'yellow'); $color_idx = 0;
41 $total = 0.0; foreach ($values as $v) { $total += $v; }
42 $r = (int)$size; $cx = $r+1; $cy = $r+1; $rad = 2*pi()/$total; $old_a = 0;
43 $svg = '<svg width="'.(2+2*$r).'" height="'.(2+2*$r).'" style="margin: 2px; vertical-align: middle;">';
44 foreach ($values as $a) {
45 $color = $svg_colors[$color_names[$color_idx++]];
46 if ($a == $total) {
47 $svg .= "<circle cx='$cx' cy='$cy' r='$r' stroke='black' stroke-width='0' fill='$color' />";
48 } elseif ($a > 0) {
49 $x1 = $cx + $r * cos(-$old_a * $rad);
50 $y1 = $cy + $r * sin(-$old_a * $rad);
51 $x2 = $cx + $r * cos(-($old_a + $a) * $rad);
52 $y2 = $cy + $r * sin(-($old_a + $a) * $rad);
53 $big = ($a > ($total/2)) ? '1' : '0';
54 $svg .= "<path d=\"M$cx,$cy L$x1,$y1 A$r,$r 0 $big,0 $x2,$y2 z\" style=\"stroke: 0 black; fill: $color;\" />";
55 }
56 $old_a += $a;
57 }
58 $svg .= '</svg>';
59 return $svg;
60}
61
62function svg_bar($values, $width=100, $height=5) {
63 global $svg_colors;
64 $color_names = Array('blue', 'red', 'green', 'yellow'); $color_idx = 0;
65 $total = 0.0; foreach ($values as $v) { $total += $v; }
66 $svg = "<svg width='$width' height='$height' style='float: left; margin: 2px; vertical-align: middle;'>";
67 $x = 0;
68 foreach ($values as $v) {
69 $color = $svg_colors[$color_names[$color_idx++]];
70 $w = round(($width*$v)/$total);
71 if ($w > 0) {
72 $svg .= "<rect x='$x' y='0' width='$w' height='$height' style='stroke: 0 black; fill: $color;' />";
73 $x += $w;
74 }
75 }
76 $svg .= '</svg>';
77 return $svg;
78}
79
80// echo "\n<span class='big b' style='color: red;'>ATTENTION : ce rapport est en cours de refonte, merci de ne pas tenir compte des données affichées ci-dessous.</span><br><br>";
81
82//echo "\n<span class='big b'>Ordinateurs par implantation</span><br><br>";
83echo "<table class='tab_cadrehov'>";
84echo "<tr class='tab_bg_1'><th rowspan='2' colspan='2'>Implantation</th>";
85echo "<th colspan='4'>Parc interne</th>";
86echo "<th colspan='4'>Parc public</th>";
87echo "</tr>";
88echo "<tr class='tab_bg_1'>";
89echo "<th>Autres ".svg_circle('blue', 3)."</th><th>Ubuntu<br />10.04 ".svg_circle('red', 3)."</th><th>Ubuntu<br />12.04 ".svg_circle('green', 3)."</th><th>Progression</th>";
90echo "<th>Autres ".svg_circle('blue', 3)."</th><th>Ubuntu<br />10.04 ".svg_circle('red', 3)."</th><th>Ubuntu<br />12.04 ".svg_circle('green', 3)."</th><th>Progression</th>";
91echo "</tr>\n";
92
93$grand_internes_1204 = 0; $grand_internes_1004 = 0; $grand_internes_autres = 0;
94$grand_publics_1204 = 0; $grand_publics_1004 = 0; $grand_publics_autres = 0;
95// récupération de la liste des régions
96$query = "SELECT id FROM glpi_entities WHERE (id=0 OR entities_id=0)";
97$query .= " ".getEntitiesRestrictRequest("AND", "glpi_entities")." ORDER BY name";
98$region_result = $DB->query($query);
99// parcours des régions
100while ($region_data = $DB->fetch_assoc($region_result)) {
101 $region_id = $region_data['id'];
102 if ($region_id != 0) {
103 $region_name = getTreeLeafValueName("glpi_entities", $region_id);
104 } else {
105 $region_name = "AUF";
106 }
107 $table_lines = Array();
108 $region_internes_1204 = 0; $region_internes_1004 = 0; $region_internes_autres = 0;
109 $region_publics_1204 = 0; $region_publics_1004 = 0; $region_publics_autres = 0;
110
111 // récupération de la liste des implantations
112 $query = "SELECT id,level FROM glpi_entities WHERE ";
113 if ($region_id != 0) {
114 $query .= getRealQueryForTreeItem("glpi_entities", $region_id, "id");
115 } else {
116 $query .= "id=0";
117 }
118 $query .= " ".getEntitiesRestrictRequest("AND", "glpi_entities")." ORDER BY name";
119 $implant_result = $DB->query($query);
120 // parcours des implantations
121 while ($implant_data = $DB->fetch_assoc($implant_result)) {
122 $implant_id = $implant_data['id'];
123 if ($implant_id != 0) {
124 $implant_name = getTreeLeafValueName("glpi_entities", $implant_id);
125 } else {
126 $implant_name = "<i>(non classé)</i>";
127 }
128
129 // récupération de la liste des systèmes de l'implantation
130 $nb_internes_1204 = 0; $nb_internes_1004 = 0; $nb_internes_autres = 0;
131 $nb_publics_1204 = 0; $nb_publics_1004 = 0; $nb_publics_autres = 0;
132 $query = "SELECT s.completename AS sname, o.name AS oname,
133 acc.name AS categorie, acu.name AS utilisation
134 FROM `$table_item` c
135 LEFT JOIN glpi_states s ON (c.states_id = s.id)
136 LEFT JOIN glpi_plugin_auf_computers ac ON (c.id = ac.id)
137 LEFT JOIN glpi_plugin_auf_categories acc ON (ac.auf_categories_id = acc.id)
138 LEFT JOIN glpi_plugin_auf_utilisations acu ON (ac.auf_utilisations_id = acu.id)
139 LEFT JOIN glpi_operatingsystems o ON (c.operatingsystems_id = o.id)
140 WHERE c.is_deleted = '0' AND c.is_template = '0' AND ac.est_virtuel IS FALSE
141 AND c.entities_id = '".$implant_id."'";
142 $result = $DB->query($query);
143 while ($data=$DB->fetch_assoc($result)) {
144 // on ne compte pas les sorties d'inventaire
145 if (preg_match("/^sortie/i", $data['sname'])) {
146 continue;
147 }
148 // postes internes
149 if (preg_match("/^poste.*interne/i", $data['categorie'])) {
150 if (preg_match("/^production/i", $data['utilisation']) &&
151 !preg_match("/panne/i", $data['sname']) ) {
152 if (preg_match("/^Ubuntu 12\.04/", $data['oname'])) {
153 $nb_internes_1204++;
154 } elseif (preg_match("/^Ubuntu 10\.04/", $data['oname'])) {
155 $nb_internes_1004++;
156 } else {
157 $nb_internes_autres++;
158 }
159 }
160 }
161 // postes publics
162 elseif (preg_match("/^poste.*public/i", $data['categorie'])) {
163 if (preg_match("/^production/i", $data['utilisation']) &&
164 !preg_match("/panne/i", $data['sname']) ) {
165 if (preg_match("/^Ubuntu 12\.04/", $data['oname'])) {
166 $nb_publics_1204++;
167 } elseif (preg_match("/^Ubuntu 10\.04/", $data['oname'])) {
168 $nb_publics_1004++;
169 } else {
170 $nb_publics_autres++;
171 }
172 }
173 }
174 // autres
175 else {
176 // on ne compte que les postes clients, pas les serveurs
177 }
178 } // systèmes dans l'implantation
179
180 $total_internes = $nb_internes_1204 + $nb_internes_1004 + $nb_internes_autres;
181 $total_publics = $nb_publics_1204 + $nb_publics_1004 + $nb_publics_autres;
182 if (($total_internes + $total_publics) > 0) {
183 $spaces = "";
184 for ($i=1;$i<$implant_data['level'];$i++) { $spaces .= "&nbsp;"; }
185 $line = "<tr><td class='tab_bg_1'>$spaces$implant_name</td>";
186 $line .= "<td class='numeric'>$nb_internes_autres</td>";
187 $line .= "<td class='numeric'>$nb_internes_1004</td>";
188 $line .= "<td class='numeric'>$nb_internes_1204</td>";
189 $line .= "<td class='numeric tab_bg_2'>";
190 $line .= svg_bar(Array($nb_internes_autres, $nb_internes_1004, $nb_internes_1204), $svg_bar_width, $svg_bar_height);
191 $line .= round((100*$nb_internes_1204)/$total_internes)."%</td>";
192 $line .= "<td class='numeric'>$nb_publics_autres</td>";
193 $line .= "<td class='numeric'>$nb_publics_1004</td>";
194 $line .= "<td class='numeric'>$nb_publics_1204</td>";
195 $line .= "<td class='numeric tab_bg_2'>";
196 $line .= svg_bar(Array($nb_publics_autres, $nb_publics_1004, $nb_publics_1204), $svg_bar_width, $svg_bar_height);
197 $line .= round((100*$nb_publics_1204)/$total_publics)."%</td>";
198 $line .= "</tr>\n";
199 $table_lines[] = $line;
200 }
201 // total régional
202 $region_internes_autres += $nb_internes_autres;
203 $region_internes_1004 += $nb_internes_1004;
204 $region_internes_1204 += $nb_internes_1204;
205 $region_publics_autres += $nb_publics_autres;
206 $region_publics_1004 += $nb_publics_1004;
207 $region_publics_1204 += $nb_publics_1204;
208 #$table_lines[] = "<tr><td>".$implant_name."</td></tr>";
209 } // fin des implantations de la région
210
211 $total_internes = $region_internes_1204 + $region_internes_1004 + $region_internes_autres;
212 $total_publics += $region_publics_1204 + $region_publics_1004 + $region_publics_autres;
213 if (($total_internes + $total_publics) > 0) {
214 $line = "<tr class='tab_bg_1 b'><td>Sous-total</td>";
215 $line .= "<td class='numeric'>$region_internes_autres</td>";
216 $line .= "<td class='numeric'>$region_internes_1004</td>";
217 $line .= "<td class='numeric'>$region_internes_1204</td>";
218 $line .= "<td class='numeric tab_bg_1'>";
219 $line .= svg_bar(Array($region_internes_autres, $region_internes_1004, $region_internes_1204), $svg_bar_width, $svg_bar_height);
220 $line .= round((100*$region_internes_1204)/$total_internes)."%</td>";
221 $line .= "<td class='numeric'>$region_publics_autres</td>";
222 $line .= "<td class='numeric'>$region_publics_1004</td>";
223 $line .= "<td class='numeric'>$region_publics_1204</td>";
224 $line .= "<td class='numeric tab_bg_1'>";
225 $line .= svg_bar(Array($region_publics_autres, $region_publics_1004, $region_publics_1204), $svg_bar_width, $svg_bar_height);
226 $line .= round((100*$region_publics_1204)/$total_publics)."%</td>";
227 $line .= "</tr>\n";
228 $table_lines[] = $line;
229 }
230
231 # TODO: revoir ce pie-chart
232 $region_name = svg_pie_chart(Array(
233 $region_internes_autres + $region_publics_autres,
234 $region_internes_1004 + $region_publics_1004,
235 $region_internes_1204 + $region_publics_1204,
236 ), 16) . $region_name;
237 $table_lines[0] = str_replace("<tr>", "<tr><td class='tab_bg_1 b' rowspan='".count($table_lines)."'>$region_name</td>", $table_lines[0]);
238 if ($region_id != 0) {
239 echo "<tr><th colspan='10'></th></tr>\n";
240 }
241 echo implode("\n", $table_lines);
242
243 // total général
244 $grand_internes_autres += $region_internes_autres;
245 $grand_internes_1004 += $region_internes_1004;
246 $grand_internes_1204 += $region_internes_1204;
247 $grand_publics_autres += $region_publics_autres;
248 $grand_publics_1004 += $region_publics_1004;
249 $grand_publics_1204 += $region_publics_1204;
250} // fin des régions
251
252#echo "<tr class='tab_bg_1'><td colspan='8'>&nbsp;</td></tr>";
253
254$total_internes = $grand_internes_1204 + $grand_internes_1004 + $grand_internes_autres;
255$total_publics += $grand_publics_1204 + $grand_publics_1004 + $grand_publics_autres;
256$line = "<tr class='tab_bg_1'><td class='b' colspan='2'>Total général</td>";
257$line .= "<td class='numeric b'>$grand_internes_autres</td>";
258$line .= "<td class='numeric b'>$grand_internes_1004</td>";
259$line .= "<td class='numeric b'>$grand_internes_1204</td>";
260$line .= "<td class='numeric tab_bg_1'>";
261$line .= svg_bar(Array($grand_internes_autres, $grand_internes_1004, $grand_internes_1204), $svg_bar_width, $svg_bar_height);
262$line .= round((100*$grand_internes_1204)/$total_internes)."%</td>";
263$line .= "<td class='numeric b'>$grand_publics_autres</td>";
264$line .= "<td class='numeric b'>$grand_publics_1004</td>";
265$line .= "<td class='numeric b'>$grand_publics_1204</td>";
266$line .= "<td class='numeric tab_bg_1'>";
267$line .= svg_bar(Array($grand_publics_autres, $grand_publics_1004, $grand_publics_1204), $svg_bar_width, $svg_bar_height);
268$line .= round((100*$grand_publics_1204)/$total_publics)."%</td>";
269$line .= "</tr>";
270echo "<tr><th colspan='10'></th></tr>\n";
271echo $line;
749e76d6 272
d3e48ecc 273echo "</table>";
749e76d6
P
274
275Html::footer();
276?>