glpi-plugin-auf : intégration Debian 8 et Ubuntu 14.04
[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 include_once ("inc/functions.php");
8
9 $svg_color_names = Array('blue', 'red', 'green', 'yellow');
10
11 Session::checkRight("reports", "r");
12 Session::checkRight("computer", "r");
13
14 $report_title = "Progression des mises à niveau Ubuntu";
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 "\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>";
28
29 //echo "\n<span class='big b'>Ordinateurs par implantation</span><br><br>";
30 echo "<table class='tab_cadrehov'>";
31 echo "<tr class='tab_bg_1'><th rowspan='2' colspan='2'>Implantation</th>";
32 echo "<th colspan='5'>Parc interne</th>";
33 echo "<th colspan='5'>Parc public</th>";
34 echo "</tr>";
35 echo "<tr class='tab_bg_1'>";
36 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>Ubuntu<br />14.04 ".svg_circle('yellow', 3)."</th><th>Progression</th>";
37 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>Ubuntu<br />14.04 ".svg_circle('yellow', 3)."</th><th>Progression</th>";
38 echo "</tr>\n";
39
40 $grand_internes_1204 = 0; $grand_internes_1004 = 0; $grand_internes_autres = 0;
41 $grand_publics_1204 = 0; $grand_publics_1004 = 0; $grand_publics_autres = 0;
42 // récupération de la liste des régions
43 $query = "SELECT id FROM glpi_entities WHERE (id=0 OR entities_id=0)";
44 $query .= " ".getEntitiesRestrictRequest("AND", "glpi_entities")." ORDER BY name";
45 $region_result = $DB->query($query);
46 // parcours des régions
47 while ($region_data = $DB->fetch_assoc($region_result)) {
48 $region_id = $region_data['id'];
49 if ($region_id != 0) {
50 $region_name = getTreeLeafValueName("glpi_entities", $region_id);
51 } else {
52 $region_name = "AUF";
53 }
54 $table_lines = Array();
55 $region_internes_1404 = 0; $region_internes_1204 = 0; $region_internes_1004 = 0; $region_internes_autres = 0;
56 $region_publics_1404 = 0; $region_publics_1204 = 0; $region_publics_1004 = 0; $region_publics_autres = 0;
57
58 // récupération de la liste des implantations
59 $query = "SELECT id,level FROM glpi_entities WHERE ";
60 if ($region_id != 0) {
61 $query .= getRealQueryForTreeItem("glpi_entities", $region_id, "id");
62 } else {
63 $query .= "id=0";
64 }
65 $query .= " ".getEntitiesRestrictRequest("AND", "glpi_entities")." ORDER BY name";
66 $implant_result = $DB->query($query);
67 // parcours des implantations
68 while ($implant_data = $DB->fetch_assoc($implant_result)) {
69 $implant_id = $implant_data['id'];
70 if ($implant_id != 0) {
71 $implant_name = getTreeLeafValueName("glpi_entities", $implant_id);
72 } else {
73 $implant_name = "<i>(non classé)</i>";
74 }
75
76 // récupération de la liste des systèmes de l'implantation
77 $nb_internes_1404 = 0; $nb_internes_1204 = 0; $nb_internes_1004 = 0; $nb_internes_autres = 0;
78 $nb_publics_1404 = 0; $nb_publics_1204 = 0; $nb_publics_1004 = 0; $nb_publics_autres = 0;
79 $query = "SELECT s.completename AS sname, o.name AS oname,
80 acc.name AS categorie, acu.name AS utilisation
81 FROM `$table_item` c
82 LEFT JOIN glpi_states s ON (c.states_id = s.id)
83 LEFT JOIN glpi_plugin_auf_computers ac ON (c.id = ac.id)
84 LEFT JOIN glpi_plugin_auf_categories acc ON (ac.auf_categories_id = acc.id)
85 LEFT JOIN glpi_plugin_auf_utilisations acu ON (ac.auf_utilisations_id = acu.id)
86 LEFT JOIN glpi_operatingsystems o ON (c.operatingsystems_id = o.id)
87 WHERE c.is_deleted = '0' AND c.is_template = '0'
88 AND ac.est_virtuel IS FALSE
89 AND o.name LIKE 'Ubuntu %'
90 AND c.entities_id = '".$implant_id."'";
91 $result = $DB->query($query);
92 while ($data=$DB->fetch_assoc($result)) {
93 // on ne compte pas les sorties d'inventaire
94 if (preg_match("/^sortie/i", $data['sname'])) {
95 continue;
96 }
97 // postes internes
98 if (preg_match("/^poste.*interne/i", $data['categorie'])) {
99 if (preg_match("/^production/i", $data['utilisation']) &&
100 !preg_match("/panne/i", $data['sname']) ) {
101 if (preg_match("/^Ubuntu 14\.04/", $data['oname'])) {
102 $nb_internes_1404++;
103 } elseif (preg_match("/^Ubuntu 12\.04/", $data['oname'])) {
104 $nb_internes_1204++;
105 } elseif (preg_match("/^Ubuntu 10\.04/", $data['oname'])) {
106 $nb_internes_1004++;
107 } else {
108 $nb_internes_autres++;
109 }
110 }
111 }
112 // postes publics
113 elseif (preg_match("/^poste.*public/i", $data['categorie'])) {
114 if (preg_match("/^production/i", $data['utilisation']) &&
115 !preg_match("/panne/i", $data['sname']) ) {
116 if (preg_match("/^Ubuntu 14\.04/", $data['oname'])) {
117 $nb_publics_1404++;
118 } elseif (preg_match("/^Ubuntu 12\.04/", $data['oname'])) {
119 $nb_publics_1204++;
120 } elseif (preg_match("/^Ubuntu 10\.04/", $data['oname'])) {
121 $nb_publics_1004++;
122 } else {
123 $nb_publics_autres++;
124 }
125 }
126 }
127 // autres
128 else {
129 // on ne compte que les postes clients, pas les serveurs
130 }
131 } // systèmes dans l'implantation
132
133 $total_internes = $nb_internes_1404 + $nb_internes_1204 + $nb_internes_1004 + $nb_internes_autres;
134 $total_publics = $nb_publics_1404 + $nb_publics_1204 + $nb_publics_1004 + $nb_publics_autres;
135 if (($total_internes + $total_publics) > 0) {
136 $spaces = "";
137 for ($i=1;$i<$implant_data['level'];$i++) { $spaces .= "&nbsp;"; }
138 $line = "<tr><td class='tab_bg_1'>$spaces$implant_name</td>";
139 $line .= "<td class='numeric'>$nb_internes_autres</td>";
140 $line .= "<td class='numeric'>$nb_internes_1004</td>";
141 $line .= "<td class='numeric'>$nb_internes_1204</td>";
142 $line .= "<td class='numeric'>$nb_internes_1404</td>";
143 $line .= "<td class='numeric tab_bg_2'>".progression_html(Array($nb_internes_autres, $nb_internes_1004, $nb_internes_1204, $nb_internes_1404), $nb_internes_1204 + $nb_internes_1404)."</td>";
144 $line .= "<td class='numeric'>$nb_publics_autres</td>";
145 $line .= "<td class='numeric'>$nb_publics_1004</td>";
146 $line .= "<td class='numeric'>$nb_publics_1204</td>";
147 $line .= "<td class='numeric'>$nb_publics_1404</td>";
148 $line .= "<td class='numeric tab_bg_2'>".progression_html(Array($nb_publics_autres, $nb_publics_1004, $nb_publics_1204, $nb_publics_1404), $nb_publics_1204 + $nb_publics_1404)."</td>";
149 $line .= "</tr>\n";
150 $table_lines[] = $line;
151 }
152 // total régional
153 $region_internes_autres += $nb_internes_autres;
154 $region_internes_1004 += $nb_internes_1004;
155 $region_internes_1204 += $nb_internes_1204;
156 $region_internes_1404 += $nb_internes_1404;
157 $region_publics_autres += $nb_publics_autres;
158 $region_publics_1004 += $nb_publics_1004;
159 $region_publics_1204 += $nb_publics_1204;
160 $region_publics_1404 += $nb_publics_1404;
161 #$table_lines[] = "<tr><td>".$implant_name."</td></tr>";
162 } // fin des implantations de la région
163
164 $total_internes = $region_internes_1404 + $region_internes_1204 + $region_internes_1004 + $region_internes_autres;
165 $total_publics = $region_publics_1404 + $region_publics_1204 + $region_publics_1004 + $region_publics_autres;
166 if (($total_internes + $total_publics) > 0) {
167 $line = "<tr class='tab_bg_1 b'><td>Sous-total</td>";
168 $line .= "<td class='numeric'>$region_internes_autres</td>";
169 $line .= "<td class='numeric'>$region_internes_1004</td>";
170 $line .= "<td class='numeric'>$region_internes_1204</td>";
171 $line .= "<td class='numeric'>$region_internes_1404</td>";
172 $line .= "<td class='numeric tab_bg_1'>".progression_html(Array($region_internes_autres, $region_internes_1004, $region_internes_1204, $region_internes_1004 + $region_internes_1404), $region_internes_1404)."</td>";
173 $line .= "<td class='numeric'>$region_publics_autres</td>";
174 $line .= "<td class='numeric'>$region_publics_1004</td>";
175 $line .= "<td class='numeric'>$region_publics_1204</td>";
176 $line .= "<td class='numeric'>$region_publics_1404</td>";
177 $line .= "<td class='numeric tab_bg_1'>".progression_html(Array($region_publics_autres, $region_publics_1004, $region_publics_1204, $region_publics_1404), $region_publics_1204 + $region_publics_1404)."</td>";
178 $line .= "</tr>\n";
179 $table_lines[] = $line;
180 }
181
182 # TODO: revoir ce pie-chart
183 $region_name = svg_pie_chart(Array(
184 $region_internes_autres + $region_publics_autres,
185 $region_internes_1004 + $region_publics_1004,
186 $region_internes_1204 + $region_publics_1204,
187 $region_internes_1404 + $region_publics_1404,
188 ), 16) . $region_name;
189 $table_lines[0] = str_replace("<tr>", "<tr><td class='tab_bg_1 b' rowspan='".count($table_lines)."'>$region_name</td>", $table_lines[0]);
190 if ($region_id != 0) {
191 echo "<tr><th colspan='12'></th></tr>\n";
192 }
193 echo implode("\n", $table_lines);
194
195 // total général
196 $grand_internes_autres += $region_internes_autres;
197 $grand_internes_1004 += $region_internes_1004;
198 $grand_internes_1204 += $region_internes_1204;
199 $grand_internes_1404 += $region_internes_1404;
200 $grand_publics_autres += $region_publics_autres;
201 $grand_publics_1004 += $region_publics_1004;
202 $grand_publics_1204 += $region_publics_1204;
203 $grand_publics_1404 += $region_publics_1404;
204 } // fin des régions
205
206 #echo "<tr class='tab_bg_1'><td colspan='8'>&nbsp;</td></tr>";
207
208 $line = "<tr class='tab_bg_1'><td class='b' colspan='2'>";
209 $line .= svg_pie_chart(Array(
210 $grand_internes_autres + $grand_publics_autres,
211 $grand_internes_1004 + $grand_publics_1004,
212 $grand_internes_1204 + $grand_publics_1204,
213 $grand_internes_1404 + $grand_publics_1404,
214 ), 16);
215 $line .= "TOTAL GÉNÉRAL</td>";
216 $line .= "<td class='numeric b'>$grand_internes_autres</td>";
217 $line .= "<td class='numeric b'>$grand_internes_1004</td>";
218 $line .= "<td class='numeric b'>$grand_internes_1204</td>";
219 $line .= "<td class='numeric b'>$grand_internes_1404</td>";
220 $line .= "<td class='numeric tab_bg_1'>".progression_html(Array($grand_internes_autres, $grand_internes_1004, $grand_internes_1204, $grand_internes_1404), $grand_internes_1204 + $grand_internes_1404)."</td>";
221 $line .= "<td class='numeric b'>$grand_publics_autres</td>";
222 $line .= "<td class='numeric b'>$grand_publics_1004</td>";
223 $line .= "<td class='numeric b'>$grand_publics_1204</td>";
224 $line .= "<td class='numeric b'>$grand_publics_1404</td>";
225 $line .= "<td class='numeric tab_bg_1'>".progression_html(Array($grand_publics_autres, $grand_publics_1004, $grand_publics_1204, $grand_publics_1404), $grand_publics_1204 + $grand_publics_1404)."</td>";
226 $line .= "</tr>";
227 echo "<tr><th colspan='12'></th></tr>\n";
228 echo $line;
229
230 echo "</table>";
231
232 echo "<div style='margin: 5px; text-align: center;'><p><strong>Remarques&nbsp;:</strong></p><ul>";
233 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>";
234 echo "<li>Ce rapport ne considère que les machines dans les catégories poste interne ou public, donc pas les serveurs.</li>";
235 echo "<li>Ce rapport ne considère que les machines physiques, pas les machines virtuelles.</li>";
236 echo "<li>Ce rapport ne considère que les machines sous Ubuntu, aucun autre système.</li>";
237 echo "<li>La colonne «&nbsp;Autres&nbsp;» consiste en des systèmes Ubuntu d'une version autre que 14.04, 12.04 ou 10.04.</li>";
238 echo "<li>La valeur de progression considère à la fois les versions 12.04 et 14.04.</li>";
239 echo "<li><i>Note&nbsp;: la mise à niveau vers Ubuntu 14.04 n'est pas encore d'actualité (les paquets AUF ne sont pas prêts à 100%).</i></li>";
240 echo "</ul></div>";
241
242 Html::footer();
243 ?>