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