Commit | Line | Data |
---|---|---|
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 | ||
6 | include ("../../inc/includes.php"); | |
7 | ||
8 | Session::checkRight("reports", "r"); | |
9 | Session::checkRight("computer", "r"); | |
10 | ||
11 | #Html::header(Report::getTypeName(2), $_SERVER['PHP_SELF'], "utils", "report"); | |
12 | Html::header("Ordinateurs par implantation", $_SERVER['PHP_SELF'], "utils", "report"); | |
13 | Report::title(); | |
14 | ||
15 | $computer = new Computer(); | |
16 | ||
17 | $state_sql = ""; | |
18 | if (($state != "") AND ($state != "0")) { | |
19 | $state_sql = " AND `states_id` = '".$state."' "; | |
20 | } | |
21 | ||
22 | $itemtype = 'Computer'; | |
23 | $table_item = getTableForItemType($itemtype); | |
24 | ||
25 | function svg_circle($color, $size=4) { | |
26 | $r = (int)$size; $cx = $r+1; $cy = $r+1; | |
27 | $svg = '<svg width="'.(2+2*$r).'" height="'.(2+2*$r).'" style="margin: 1px;">'; | |
28 | $svg .= "<circle cx='$cx' cy='$cy' r='$r' stroke='black' stroke-width='0' fill='$color' />"; | |
29 | $svg .= '</svg>'; | |
30 | return $svg; | |
31 | } | |
32 | ||
33 | function svg_pie_chart($values, $size=16) { | |
34 | $colors = Array("#ffa0a0", "#a0ffa0", "#ffffa0", "#a0a0ff"); $color_idx = 0; | |
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; | |
37 | $svg = '<svg width="'.(2+2*$r).'" height="'.(2+2*$r).'" style="margin: 1px;">'; | |
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'; | |
44 | $color = $colors[$color_idx++]; | |
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 | ||
52 | echo "\n<span class='big b'>Ordinateurs par implantation</span><br><br>"; | |
53 | echo "<table class='tab_cadrehov'>"; | |
54 | echo "<tr class='tab_bg_1'><th rowspan='2' colspan='2'>Implantation</th>"; | |
55 | echo "<th colspan='2'>".svg_circle("#ffa0a0")." Serveurs</th>"; | |
56 | echo "<th colspan='2'>".svg_circle("#a0ffa0")." Clients internes</th>"; | |
57 | echo "<th colspan='2'>".svg_circle("#ffffa0")." Clients publics</th>"; | |
58 | echo "<th rowspan='2'>Total<br /><span style='font-size: 75%'>(+ sans statut)</span></th>"; | |
59 | echo "<th rowspan='2'>".svg_circle("#a0a0ff")." Virtuels</th></tr>"; | |
60 | echo "<tr class='tab_bg_1'><th>Total</th><th>Production</th>"; | |
61 | echo "<th>Total</th><th>Attribué</th><th>Total</th><th>Attribué</th></tr>\n"; | |
62 | ||
63 | # récupération de la liste des régions | |
64 | $grand_total = 0; | |
65 | $query = "SELECT id FROM glpi_entities WHERE (id=0 OR entities_id=0)"; | |
66 | $query .= " ".getEntitiesRestrictRequest("AND", "glpi_entities")." ORDER BY name"; | |
67 | $region_result = $DB->query($query); | |
68 | # parcours des régions | |
69 | while ($region_data = $DB->fetch_assoc($region_result)) { | |
70 | $region_id = $region_data['id']; | |
71 | if ($region_id != 0) { | |
72 | $region_name = getTreeLeafValueName("glpi_entities", $region_id); | |
73 | } else { | |
74 | $region_name = "AUF"; | |
75 | } | |
76 | $table_lines = Array(); | |
77 | $region_serveurs_total = 0; $region_serveurs_prod = 0; | |
78 | $region_internes_total = 0; $region_internes_prod = 0; | |
79 | $region_publics_total = 0; $region_publics_prod = 0; | |
80 | $region_total = 0; $region_virtuels_total = 0; | |
81 | $region_autres_total = 0; | |
82 | ||
83 | # récupération de la liste des implantations | |
84 | $query = "SELECT id,level FROM glpi_entities WHERE "; | |
85 | if ($region_id != 0) { | |
86 | $query .= getRealQueryForTreeItem("glpi_entities", $region_id, "id"); | |
87 | } else { | |
88 | $query .= "id=0"; | |
89 | } | |
90 | $query .= " ".getEntitiesRestrictRequest("AND", "glpi_entities")." ORDER BY name"; | |
91 | $implant_result = $DB->query($query); | |
92 | # parcours des implantations | |
93 | while ($implant_data = $DB->fetch_assoc($implant_result)) { | |
94 | $implant_id = $implant_data['id']; | |
95 | if ($implant_id != 0) { | |
96 | $implant_name = getTreeLeafValueName("glpi_entities", $implant_id); | |
97 | } else { | |
98 | $implant_name = "<i>(non classé)</i>"; | |
99 | } | |
100 | ||
101 | # récupération de la liste des systèmes de l'implantation | |
102 | $nb_serveurs_total = 0; $nb_serveurs_prod = 0; | |
103 | $nb_internes_total = 0; $nb_internes_prod = 0; | |
104 | $nb_publics_total = 0; $nb_publics_prod = 0; | |
105 | $nb_virtuels_total = 0; $nb_autres_total = 0; | |
106 | $query = "SELECT COUNT(c.id) AS count, s.id AS sid, s.completename AS sname | |
107 | FROM `$table_item` c | |
108 | LEFT JOIN glpi_entities e ON (c.entities_id = e.id) | |
109 | LEFT JOIN glpi_states s ON (c.states_id = s.id) | |
110 | WHERE c.is_deleted = '0' AND c.is_template = '0' | |
111 | AND c.entities_id = '".$implant_id."' | |
112 | GROUP BY 2 ORDER BY 2"; | |
113 | $result = $DB->query($query); | |
114 | while ($data=$DB->fetch_assoc($result)) { | |
115 | if (preg_match("/^système.*virtu.l/i", $data['sname'])) { | |
116 | $nb_virtuels_total += $data['count']; | |
117 | } elseif (preg_match("/^réserv.*serveur.*test/i", $data['sname'])) { | |
118 | $nb_serveurs_total += $data['count']; | |
119 | } elseif (preg_match("/^attrib.*serveur.*production/i", $data['sname'])) { | |
120 | $nb_serveurs_total += $data['count']; | |
121 | $nb_serveurs_prod += $data['count']; | |
122 | } elseif (preg_match("/^réserv.*poste.*mission/i", $data['sname'])) { | |
123 | $nb_internes_total += $data['count']; | |
124 | } elseif (preg_match("/^attrib.*poste.*interne/i", $data['sname'])) { | |
125 | $nb_internes_total += $data['count']; | |
126 | $nb_internes_prod += $data['count']; | |
127 | } elseif (preg_match("/^réserv.*poste.*stock/i", $data['sname'])) { | |
128 | $nb_publics_total += $data['count']; | |
129 | } elseif (preg_match("/^attrib.*poste.*public/i", $data['sname'])) { | |
130 | $nb_publics_total += $data['count']; | |
131 | $nb_publics_prod += $data['count']; | |
132 | } elseif (preg_match("/^sortie/i", $data['sname'])) { | |
133 | // on ne compte pas les sorties d'inventaire | |
134 | } else { | |
135 | $nb_autres_total += $data['count']; | |
136 | } | |
137 | } // systèmes dans l'implantation | |
138 | ||
139 | $total = $nb_serveurs_total + $nb_internes_total + $nb_publics_total + $nb_autres_total; | |
140 | if ($total > 0) { | |
141 | $spaces = ""; | |
142 | for ($i=1;$i<$implant_data['level'];$i++) { $spaces .= " "; } | |
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 | $autres = ($nb_autres_total > 0) ? "(".$nb_autres_total." +) " : ""; | |
151 | $line .= "<td class='numeric tab_bg_1'>".$autres.$total."</td>"; | |
152 | $line .= "<td class='numeric'>".$nb_virtuels_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 | $autres = ($region_autres_total > 0) ? "(".$region_autres_total." +) " : ""; | |
175 | $line .= "<td class='numeric tab_bg_1'>".$autres.$region_total."</td>"; | |
176 | $line .= "<td class='numeric'>".$region_virtuels_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 | echo implode("\n", $table_lines); | |
182 | ||
183 | $grand_serveurs_total += $region_serveurs_total; | |
184 | $grand_serveurs_prod += $region_serveurs_prod; | |
185 | $grand_internes_total += $region_internes_total; | |
186 | $grand_internes_prod += $region_internes_prod; | |
187 | $grand_publics_total += $region_publics_total; | |
188 | $grand_publics_prod += $region_publics_prod; | |
189 | $grand_total += $region_total; | |
190 | $grand_virtuels_total += $region_virtuels_total; | |
191 | $grand_autres_total += $region_autres_total; | |
192 | } // fin des régions | |
193 | ||
194 | // echo "<tr class='tab_bg_1'><td colspan='8'> </td></tr>"; | |
195 | ||
196 | /* | |
197 | # total operating systems | |
198 | $query = "SELECT COUNT(DISTINCT fia.`tag`) FROM `".$table_item."` | |
199 | LEFT JOIN `glpi_computers_items` ci | |
200 | ON (ci.`itemtype` = '".$itemtype."' | |
201 | AND ci.`items_id` = `".$table_item."`.`id`) | |
202 | LEFT JOIN `glpi_plugin_fusioninventory_agents` fia | |
203 | ON (fia.`computers_id` = `".$table_item."`.`id`) | |
204 | WHERE `".$table_item."`.`is_deleted` = '0' | |
205 | AND `".$table_item."`.`is_template` = '0' ". | |
206 | getEntitiesRestrictRequest("AND", $table_item); | |
207 | $result = $DB->query($query); | |
208 | $grand_total = $DB->result($result, 0, 0); | |
209 | */ | |
210 | $line = "<tr class='tab_bg_1'><td class='b' colspan='2'>Total général</td>"; | |
211 | $line .= "<td class='numeric b'>".$grand_serveurs_total."</td>"; | |
212 | $line .= "<td class='numeric b'>".$grand_serveurs_prod."</td>"; | |
213 | $line .= "<td class='numeric b'>".$grand_internes_total."</td>"; | |
214 | $line .= "<td class='numeric b'>".$grand_internes_prod."</td>"; | |
215 | $line .= "<td class='numeric b'>".$grand_publics_total."</td>"; | |
216 | $line .= "<td class='numeric b'>".$grand_publics_prod."</td>"; | |
217 | $autres = ($grand_autres_total > 0) ? "(".$grand_autres_total." +) " : ""; | |
218 | $line .= "<td class='numeric b'>".$autres.$grand_total."</td>"; | |
219 | $line .= "<td class='numeric b'>$grand_virtuels_total</td></tr>"; | |
220 | echo $line; | |
221 | ||
222 | echo "</table>"; | |
223 | ||
224 | Html::footer(); | |
225 | ?> |