glpi-plugin-auf : ajout des champs AUF
[auf-serveur.git] / glpi-plugin-auf / plugin / report.computers.php
CommitLineData
f87696f8
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
8Session::checkRight("reports", "r");
9Session::checkRight("computer", "r");
10
11#Html::header(Report::getTypeName(2), $_SERVER['PHP_SELF'], "utils", "report");
12Html::header("Ordinateurs par implantation", $_SERVER['PHP_SELF'], "utils", "report");
13Report::title();
14
15$computer = new Computer();
16
f87696f8
P
17$itemtype = 'Computer';
18$table_item = getTableForItemType($itemtype);
19
c2b8eea0
P
20$svg_colors = Array('red'=>'#ffa0a0', 'green'=>'#a0ffa0', 'yellow'=>'#ffdd80', 'blue'=>'#a0a0ff');
21
f87696f8 22function svg_circle($color, $size=4) {
c2b8eea0
P
23 global $svg_colors;
24 if (array_key_exists($color, $svg_colors)) { $color = $svg_colors[$color]; }
f87696f8 25 $r = (int)$size; $cx = $r+1; $cy = $r+1;
b38636fc 26 $svg = '<svg width="'.(2+2*$r).'" height="'.(2+2*$r).'" style="margin: 1px; vertical-align: middle;">';
f87696f8
P
27 $svg .= "<circle cx='$cx' cy='$cy' r='$r' stroke='black' stroke-width='0' fill='$color' />";
28 $svg .= '</svg>';
29 return $svg;
30}
31
32function svg_pie_chart($values, $size=16) {
c2b8eea0
P
33 global $svg_colors;
34 $color_names = Array('red', 'green', 'yellow', 'blue'); $color_idx = 0;
f87696f8
P
35 $total = 0.0; foreach ($values as $v) { $total += $v; }
36 $r = (int)$size; $cx = $r+1; $cy = $r+1; $rad = 2*pi()/$total; $old_a = 0;
b38636fc 37 $svg = '<svg width="'.(2+2*$r).'" height="'.(2+2*$r).'" style="margin: 2px; vertical-align: middle;">';
f87696f8
P
38 foreach ($values as $a) {
39 $x1 = $cx + $r * cos(-$old_a * $rad);
40 $y1 = $cy + $r * sin(-$old_a * $rad);
41 $x2 = $cx + $r * cos(-($old_a + $a) * $rad);
42 $y2 = $cy + $r * sin(-($old_a + $a) * $rad);
43 $big = ($a > ($total/2)) ? '1' : '0';
c2b8eea0 44 $color = $svg_colors[$color_names[$color_idx++]];
f87696f8
P
45 $svg .= "<path d=\"M$cx,$cy L$x1,$y1 A$r,$r 0 $big,0 $x2,$y2 z\" style=\"stroke: 0 black; fill: $color;\" />";
46 $old_a += $a;
47 }
48 $svg .= '</svg>';
49 return $svg;
50}
51
749e76d6 52//echo "\n<span class='big b'>Ordinateurs par implantation</span><br><br>";
f87696f8
P
53echo "<table class='tab_cadrehov'>";
54echo "<tr class='tab_bg_1'><th rowspan='2' colspan='2'>Implantation</th>";
c2b8eea0
P
55echo "<th colspan='2'>".svg_circle('red')." Serveurs</th>";
56echo "<th colspan='2'>".svg_circle('green')." Clients internes</th>";
57echo "<th colspan='2'>".svg_circle('yellow')." Clients publics</th>";
f87696f8 58echo "<th rowspan='2'>Total<br /><span style='font-size: 75%'>(+ sans statut)</span></th>";
c2b8eea0 59echo "<th rowspan='2'>".svg_circle('blue')." Virtuels</th></tr>";
f87696f8
P
60echo "<tr class='tab_bg_1'><th>Total</th><th>Production</th>";
61echo "<th>Total</th><th>Attribué</th><th>Total</th><th>Attribué</th></tr>\n";
62
749e76d6
P
63$grand_serveurs_total = 0; $grand_serveurs_prod = 0;
64$grand_internes_total = 0; $grand_internes_prod = 0;
65$grand_publics_total = 0; $grand_publics_prod = 0;
66$grand_total = 0; $grand_virtuels_total = 0;
67$grand_autres_total = 0;
f87696f8 68# récupération de la liste des régions
f87696f8
P
69$query = "SELECT id FROM glpi_entities WHERE (id=0 OR entities_id=0)";
70$query .= " ".getEntitiesRestrictRequest("AND", "glpi_entities")." ORDER BY name";
71$region_result = $DB->query($query);
72# parcours des régions
73while ($region_data = $DB->fetch_assoc($region_result)) {
74 $region_id = $region_data['id'];
75 if ($region_id != 0) {
76 $region_name = getTreeLeafValueName("glpi_entities", $region_id);
77 } else {
78 $region_name = "AUF";
79 }
80 $table_lines = Array();
81 $region_serveurs_total = 0; $region_serveurs_prod = 0;
82 $region_internes_total = 0; $region_internes_prod = 0;
83 $region_publics_total = 0; $region_publics_prod = 0;
84 $region_total = 0; $region_virtuels_total = 0;
85 $region_autres_total = 0;
86
87 # récupération de la liste des implantations
88 $query = "SELECT id,level FROM glpi_entities WHERE ";
89 if ($region_id != 0) {
90 $query .= getRealQueryForTreeItem("glpi_entities", $region_id, "id");
91 } else {
92 $query .= "id=0";
93 }
94 $query .= " ".getEntitiesRestrictRequest("AND", "glpi_entities")." ORDER BY name";
95 $implant_result = $DB->query($query);
96 # parcours des implantations
97 while ($implant_data = $DB->fetch_assoc($implant_result)) {
98 $implant_id = $implant_data['id'];
99 if ($implant_id != 0) {
100 $implant_name = getTreeLeafValueName("glpi_entities", $implant_id);
101 } else {
102 $implant_name = "<i>(non classé)</i>";
103 }
104
105 # récupération de la liste des systèmes de l'implantation
106 $nb_serveurs_total = 0; $nb_serveurs_prod = 0;
107 $nb_internes_total = 0; $nb_internes_prod = 0;
108 $nb_publics_total = 0; $nb_publics_prod = 0;
109 $nb_virtuels_total = 0; $nb_autres_total = 0;
110 $query = "SELECT COUNT(c.id) AS count, s.id AS sid, s.completename AS sname
111 FROM `$table_item` c
112 LEFT JOIN glpi_entities e ON (c.entities_id = e.id)
113 LEFT JOIN glpi_states s ON (c.states_id = s.id)
114 WHERE c.is_deleted = '0' AND c.is_template = '0'
115 AND c.entities_id = '".$implant_id."'
116 GROUP BY 2 ORDER BY 2";
117 $result = $DB->query($query);
118 while ($data=$DB->fetch_assoc($result)) {
119 if (preg_match("/^système.*virtu.l/i", $data['sname'])) {
120 $nb_virtuels_total += $data['count'];
121 } elseif (preg_match("/^réserv.*serveur.*test/i", $data['sname'])) {
122 $nb_serveurs_total += $data['count'];
123 } elseif (preg_match("/^attrib.*serveur.*production/i", $data['sname'])) {
124 $nb_serveurs_total += $data['count'];
125 $nb_serveurs_prod += $data['count'];
126 } elseif (preg_match("/^réserv.*poste.*mission/i", $data['sname'])) {
127 $nb_internes_total += $data['count'];
128 } elseif (preg_match("/^attrib.*poste.*interne/i", $data['sname'])) {
129 $nb_internes_total += $data['count'];
130 $nb_internes_prod += $data['count'];
131 } elseif (preg_match("/^réserv.*poste.*stock/i", $data['sname'])) {
132 $nb_publics_total += $data['count'];
133 } elseif (preg_match("/^attrib.*poste.*public/i", $data['sname'])) {
134 $nb_publics_total += $data['count'];
135 $nb_publics_prod += $data['count'];
136 } elseif (preg_match("/^sortie/i", $data['sname'])) {
137 // on ne compte pas les sorties d'inventaire
138 } else {
139 $nb_autres_total += $data['count'];
140 }
141 } // systèmes dans l'implantation
142
143 $total = $nb_serveurs_total + $nb_internes_total + $nb_publics_total + $nb_autres_total;
144 if ($total > 0) {
145 $spaces = "";
146 for ($i=1;$i<$implant_data['level'];$i++) { $spaces .= "&nbsp;&nbsp;"; }
147 $line = "<tr><td class='tab_bg_1'>".$spaces.$implant_name."</td>";
148 $line .= "<td class='numeric'>".$nb_serveurs_total."</td>";
149 $line .= "<td class='numeric'>".$nb_serveurs_prod."</td>";
150 $line .= "<td class='numeric'>".$nb_internes_total."</td>";
151 $line .= "<td class='numeric'>".$nb_internes_prod."</td>";
152 $line .= "<td class='numeric'>".$nb_publics_total."</td>";
153 $line .= "<td class='numeric'>".$nb_publics_prod."</td>";
154 $autres = ($nb_autres_total > 0) ? "(".$nb_autres_total." +) " : "";
155 $line .= "<td class='numeric tab_bg_1'>".$autres.$total."</td>";
156 $line .= "<td class='numeric'>".$nb_virtuels_total."</td></tr>";
157 $table_lines[] = $line;
158 }
159 $region_serveurs_total += $nb_serveurs_total;
160 $region_serveurs_prod += $nb_serveurs_prod;
161 $region_internes_total += $nb_internes_total;
162 $region_internes_prod += $nb_internes_prod;
163 $region_publics_total += $nb_publics_total;
164 $region_publics_prod += $nb_publics_prod;
165 $region_total += $total;
166 $region_virtuels_total += $nb_virtuels_total;
167 $region_autres_total += $nb_autres_total;
168 //$table_lines[] = "<tr><td>".$implant_name."</td></tr>";
169 } // fin des implantations de la région
170
171 $line = "<tr class='tab_bg_1 b'><td>Sous-total</td>";
172 $line .= "<td class='numeric'>".$region_serveurs_total."</td>";
173 $line .= "<td class='numeric'>".$region_serveurs_prod."</td>";
174 $line .= "<td class='numeric'>".$region_internes_total."</td>";
175 $line .= "<td class='numeric'>".$region_internes_prod."</td>";
176 $line .= "<td class='numeric'>".$region_publics_total."</td>";
177 $line .= "<td class='numeric'>".$region_publics_prod."</td>";
178 $autres = ($region_autres_total > 0) ? "(".$region_autres_total." +) " : "";
179 $line .= "<td class='numeric tab_bg_1'>".$autres.$region_total."</td>";
180 $line .= "<td class='numeric'>".$region_virtuels_total."</td></tr>";
181 $table_lines[] = $line;
182
183 $region_name = svg_pie_chart(Array($region_serveurs_total, $region_internes_total, $region_publics_total, $region_virtuels_total), 16) . $region_name;
184 $table_lines[0] = str_replace("<tr>", "<tr><td class='tab_bg_1 b' rowspan='".count($table_lines)."'>$region_name</td>", $table_lines[0]);
185 echo implode("\n", $table_lines);
186
187 $grand_serveurs_total += $region_serveurs_total;
188 $grand_serveurs_prod += $region_serveurs_prod;
189 $grand_internes_total += $region_internes_total;
190 $grand_internes_prod += $region_internes_prod;
191 $grand_publics_total += $region_publics_total;
192 $grand_publics_prod += $region_publics_prod;
193 $grand_total += $region_total;
194 $grand_virtuels_total += $region_virtuels_total;
195 $grand_autres_total += $region_autres_total;
196} // fin des régions
197
198// echo "<tr class='tab_bg_1'><td colspan='8'>&nbsp;</td></tr>";
199
200/*
201# total operating systems
202$query = "SELECT COUNT(DISTINCT fia.`tag`) FROM `".$table_item."`
203 LEFT JOIN `glpi_computers_items` ci
204 ON (ci.`itemtype` = '".$itemtype."'
205 AND ci.`items_id` = `".$table_item."`.`id`)
206 LEFT JOIN `glpi_plugin_fusioninventory_agents` fia
207 ON (fia.`computers_id` = `".$table_item."`.`id`)
208 WHERE `".$table_item."`.`is_deleted` = '0'
209 AND `".$table_item."`.`is_template` = '0' ".
210 getEntitiesRestrictRequest("AND", $table_item);
211$result = $DB->query($query);
212$grand_total = $DB->result($result, 0, 0);
213*/
214$line = "<tr class='tab_bg_1'><td class='b' colspan='2'>Total général</td>";
215$line .= "<td class='numeric b'>".$grand_serveurs_total."</td>";
216$line .= "<td class='numeric b'>".$grand_serveurs_prod."</td>";
217$line .= "<td class='numeric b'>".$grand_internes_total."</td>";
218$line .= "<td class='numeric b'>".$grand_internes_prod."</td>";
219$line .= "<td class='numeric b'>".$grand_publics_total."</td>";
220$line .= "<td class='numeric b'>".$grand_publics_prod."</td>";
221$autres = ($grand_autres_total > 0) ? "(".$grand_autres_total." +) " : "";
222$line .= "<td class='numeric b'>".$autres.$grand_total."</td>";
223$line .= "<td class='numeric b'>$grand_virtuels_total</td></tr>";
224echo $line;
225
226echo "</table>";
227
228Html::footer();
229?>