glpi-plugin-auf : intégration Debian 8 et Ubuntu 14.04
[auf-serveur.git] / glpi-plugin-auf / plugin / report.computers.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('red', 'green', 'yellow', 'blue');
10
11 Session::checkRight("reports", "r");
12 Session::checkRight("computer", "r");
13
14 $report_title = "Nombre de machines par catégorie";
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='2'>".svg_circle('red')." Serveurs</th>";
33 echo "<th colspan='2'>".svg_circle('green')." Postes internes</th>";
34 echo "<th colspan='2'>".svg_circle('yellow')." Postes publics</th>";
35 echo "<th rowspan='2'>Total</th>";
36 echo "<th rowspan='2'>".svg_circle('blue')." Virtuels</th>";
37 echo "<th rowspan='2'>Autres<br /><span style='font-size: 75%'>(sans statut)</span></th></tr>";
38 echo "<tr class='tab_bg_1'><th>Total</th><th>Production</th>";
39 echo "<th>Total</th><th>Attribué</th><th>Total</th><th>Attribué</th></tr>\n";
40
41 $grand_serveurs_total = 0; $grand_serveurs_prod = 0;
42 $grand_internes_total = 0; $grand_internes_prod = 0;
43 $grand_publics_total = 0; $grand_publics_prod = 0;
44 $grand_total = 0;
45 $grand_virtuels_total = 0; $grand_autres_total = 0;
46 # récupération de la liste des régions
47 $query = "SELECT id FROM glpi_entities WHERE (id=0 OR entities_id=0)";
48 $query .= " ".getEntitiesRestrictRequest("AND", "glpi_entities")." ORDER BY name";
49 $region_result = $DB->query($query);
50 # parcours des régions
51 while ($region_data = $DB->fetch_assoc($region_result)) {
52 $region_id = $region_data['id'];
53 if ($region_id != 0) {
54 $region_name = getTreeLeafValueName("glpi_entities", $region_id);
55 } else {
56 $region_name = "AUF";
57 }
58 $table_lines = Array();
59 $region_serveurs_total = 0; $region_serveurs_prod = 0;
60 $region_internes_total = 0; $region_internes_prod = 0;
61 $region_publics_total = 0; $region_publics_prod = 0;
62 $region_total = 0; $region_virtuels_total = 0;
63 $region_autres_total = 0;
64
65 # récupération de la liste des implantations
66 $query = "SELECT id,level FROM glpi_entities WHERE ";
67 if ($region_id != 0) {
68 $query .= getRealQueryForTreeItem("glpi_entities", $region_id, "id");
69 } else {
70 $query .= "id=0";
71 }
72 $query .= " ".getEntitiesRestrictRequest("AND", "glpi_entities")." ORDER BY name";
73 $implant_result = $DB->query($query);
74 # parcours des implantations
75 while ($implant_data = $DB->fetch_assoc($implant_result)) {
76 $implant_id = $implant_data['id'];
77 if ($implant_id != 0) {
78 $implant_name = getTreeLeafValueName("glpi_entities", $implant_id);
79 } else {
80 $implant_name = "<i>(non classé)</i>";
81 }
82
83 # récupération de la liste des systèmes de l'implantation
84 $nb_serveurs_total = 0; $nb_serveurs_prod = 0;
85 $nb_internes_total = 0; $nb_internes_prod = 0;
86 $nb_publics_total = 0; $nb_publics_prod = 0;
87 $nb_virtuels_total = 0; $nb_autres_total = 0;
88 $query = "SELECT s.completename AS sname, ac.est_virtuel AS virtuel,
89 acc.name AS categorie, acu.name AS utilisation
90 FROM `$table_item` c
91 LEFT JOIN glpi_states s ON (c.states_id = s.id)
92 LEFT JOIN glpi_plugin_auf_computers ac ON (c.id = ac.id)
93 LEFT JOIN glpi_plugin_auf_categories acc ON (ac.auf_categories_id = acc.id)
94 LEFT JOIN glpi_plugin_auf_utilisations acu ON (ac.auf_utilisations_id = acu.id)
95 WHERE c.is_deleted = '0' AND c.is_template = '0'
96 AND c.entities_id = '".$implant_id."'";
97 $result = $DB->query($query);
98 while ($data=$DB->fetch_assoc($result)) {
99 // on ne compte pas les sorties d'inventaire
100 if (preg_match("/^sortie/i", $data['sname'])) {
101 continue;
102 }
103 // serveurs
104 if (preg_match("/^infra/i", $data['categorie'])) {
105 $nb_serveurs_total++;
106 if (preg_match("/^production/i", $data['utilisation']) &&
107 !preg_match("/panne/i", $data['sname']) ) {
108 $nb_serveurs_prod++;
109 }
110 }
111 // postes internes
112 elseif (preg_match("/^poste.*interne/i", $data['categorie'])) {
113 $nb_internes_total++;
114 if (preg_match("/^production/i", $data['utilisation']) &&
115 !preg_match("/panne/i", $data['sname']) ) {
116 $nb_internes_prod++;
117 }
118 }
119 // postes publics
120 elseif (preg_match("/^poste.*public/i", $data['categorie'])) {
121 $nb_publics_total++;
122 if (preg_match("/^production/i", $data['utilisation']) &&
123 !preg_match("/panne/i", $data['sname']) ) {
124 $nb_publics_prod++;
125 }
126 }
127 // autres
128 else {
129 // machines virtuelles
130 if ($data['virtuel']) {
131 $nb_virtuels_total++;
132 // autres
133 } else {
134 $nb_autres_total++;
135 }
136 }
137 } // systèmes dans l'implantation
138
139 $total = $nb_serveurs_total + $nb_internes_total + $nb_publics_total;
140 if ($total > 0) {
141 $spaces = "";
142 for ($i=1;$i<$implant_data['level'];$i++) { $spaces .= "&nbsp;&nbsp;"; }
143 $line = "<tr><td class='tab_bg_1'>$spaces$implant_name</td>";
144 $line .= "<td class='numeric'>$nb_serveurs_total</td>";
145 $line .= "<td class='numeric'>$nb_serveurs_prod</td>";
146 $line .= "<td class='numeric'>$nb_internes_total</td>";
147 $line .= "<td class='numeric'>$nb_internes_prod</td>";
148 $line .= "<td class='numeric'>$nb_publics_total</td>";
149 $line .= "<td class='numeric'>$nb_publics_prod</td>";
150 $line .= "<td class='numeric tab_bg_1'>$total</td>";
151 $line .= "<td class='numeric'>$nb_virtuels_total</td>";
152 $line .= "<td class='numeric'>$nb_autres_total</td></tr>";
153 $table_lines[] = $line;
154 }
155 $region_serveurs_total += $nb_serveurs_total;
156 $region_serveurs_prod += $nb_serveurs_prod;
157 $region_internes_total += $nb_internes_total;
158 $region_internes_prod += $nb_internes_prod;
159 $region_publics_total += $nb_publics_total;
160 $region_publics_prod += $nb_publics_prod;
161 $region_total += $total;
162 $region_virtuels_total += $nb_virtuels_total;
163 $region_autres_total += $nb_autres_total;
164 //$table_lines[] = "<tr><td>".$implant_name."</td></tr>";
165 } // fin des implantations de la région
166
167 $line = "<tr class='tab_bg_1 b'><td>Sous-total</td>";
168 $line .= "<td class='numeric'>$region_serveurs_total</td>";
169 $line .= "<td class='numeric'>$region_serveurs_prod</td>";
170 $line .= "<td class='numeric'>$region_internes_total</td>";
171 $line .= "<td class='numeric'>$region_internes_prod</td>";
172 $line .= "<td class='numeric'>$region_publics_total</td>";
173 $line .= "<td class='numeric'>$region_publics_prod</td>";
174 $line .= "<td class='numeric tab_bg_1'>$region_total</td>";
175 $line .= "<td class='numeric'>$region_virtuels_total</td>";
176 $line .= "<td class='numeric'>$region_autres_total</td></tr>";
177 $table_lines[] = $line;
178
179 $region_name = svg_pie_chart(Array($region_serveurs_total, $region_internes_total, $region_publics_total, $region_virtuels_total), 16) . $region_name;
180 $table_lines[0] = str_replace("<tr>", "<tr><td class='tab_bg_1 b' rowspan='".count($table_lines)."'>$region_name</td>", $table_lines[0]);
181 if ($region_id != 0) {
182 echo "<tr><th colspan='11'></th></tr>\n";
183 }
184 echo implode("\n", $table_lines);
185
186 $grand_serveurs_total += $region_serveurs_total;
187 $grand_serveurs_prod += $region_serveurs_prod;
188 $grand_internes_total += $region_internes_total;
189 $grand_internes_prod += $region_internes_prod;
190 $grand_publics_total += $region_publics_total;
191 $grand_publics_prod += $region_publics_prod;
192 $grand_total += $region_total;
193 $grand_virtuels_total += $region_virtuels_total;
194 $grand_autres_total += $region_autres_total;
195 } // fin des régions
196
197 // echo "<tr class='tab_bg_1'><td colspan='8'>&nbsp;</td></tr>";
198
199 /*
200 # total operating systems
201 $query = "SELECT COUNT(DISTINCT fia.`tag`) FROM `".$table_item."`
202 LEFT JOIN `glpi_computers_items` ci
203 ON (ci.`itemtype` = '".$itemtype."'
204 AND ci.`items_id` = `".$table_item."`.`id`)
205 LEFT JOIN `glpi_plugin_fusioninventory_agents` fia
206 ON (fia.`computers_id` = `".$table_item."`.`id`)
207 WHERE `".$table_item."`.`is_deleted` = '0'
208 AND `".$table_item."`.`is_template` = '0' ".
209 getEntitiesRestrictRequest("AND", $table_item);
210 $result = $DB->query($query);
211 $grand_total = $DB->result($result, 0, 0);
212 */
213 $line = "<tr class='tab_bg_1'><td class='b' colspan='2'>Total général</td>";
214 $line .= "<td class='numeric b'>$grand_serveurs_total</td>";
215 $line .= "<td class='numeric b'>$grand_serveurs_prod</td>";
216 $line .= "<td class='numeric b'>$grand_internes_total</td>";
217 $line .= "<td class='numeric b'>$grand_internes_prod</td>";
218 $line .= "<td class='numeric b'>$grand_publics_total</td>";
219 $line .= "<td class='numeric b'>$grand_publics_prod</td>";
220 $line .= "<td class='numeric b'>$grand_total</td>";
221 $line .= "<td class='numeric b'>$grand_virtuels_total</td>";
222 $line .= "<td class='numeric b'>$grand_autres_total</td></tr>";
223 echo "<tr><th colspan='11'></th></tr>\n";
224 echo $line;
225
226 echo "</table>";
227
228 Html::footer();
229 ?>