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