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