Création d'un paquet glpi-plugin-auf.
[auf-serveur.git] / glpi-plugin-auf / plugin / report.wip.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
8 Session::checkRight("reports", "r");
9 Session::checkRight("computer", "r");
10
11 Html::header(Report::getTypeName(2), $_SERVER['PHP_SELF'], "utils", "report");
12 Report::title();
13
14 $computer = new Computer();
15
16 $state_sql = "";
17 if (($state != "") AND ($state != "0")) {
18 $state_sql = " AND `states_id` = '".$state."' ";
19 }
20
21 $itemtype = 'Computer';
22 $table_item = getTableForItemType($itemtype);
23
24 /* reprise du Rapport par défaut */
25 // global $DB;
26 echo "<span class='big b'>WIP (rapport en cours de développement)</span><br><br>";
27 echo "<table class='tab_cadrehov'>";
28
29 echo "<tr class='tab_bg_1'><td>Implantation</td><td>Systèmes d'exploitation</td><td>Qtt</td></tr>";
30 $green_grand_total = 0;
31 $yellow_grand_total = 0;
32 $red_grand_total = 0;
33 $blue_grand_total = 0;
34 $grand_total = 0;
35
36 # parcours des régions
37 $query = "SELECT id,name,completename FROM glpi_entities WHERE (id=0 OR entities_id=0)";
38 $query .= " ".getEntitiesRestrictRequest("AND", "glpi_entities");
39 $region_result = $DB->query($query);
40 while ($region_data = $DB->fetch_assoc($region_result)) {
41 $region_id = $region_data['id'];
42 if ($region_id != 0) {
43 $region_name = getTreeLeafValueName("glpi_entities", $region_id);
44 } else {
45 $region_name = "AUF (non classé)";
46 }
47 echo "<tr class='tab_bg_1'><td colspan='3' class='b'>$region_name</td></tr>";
48 # foreach (getSonsOf("glpi_entities", $data['id']) as $id) {
49 # echo "<tr class='tab_bg_1'><td colspan='3' class='b'>&nbsp;&nbsp;".getTreeValueCompleteName("glpi_entities", $id)."</td></tr>";
50 # }
51 #}
52 $green_total = 0;
53 $yellow_total = 0;
54 $red_total = 0;
55 $blue_total = 0;
56 $region_total = 0;
57
58 # operating systems per computer
59 $query = "SELECT COUNT(c.id) AS count, e.name AS ename,
60 (CASE WHEN o.name REGEXP '^Debian' THEN SUBSTRING_INDEX(REPLACE(o.name,' GNU/Linux',''),'.',1)
61 WHEN o.name REGEXP '^Ubuntu' THEN SUBSTRING_INDEX(REPLACE(o.name,' LTS',''),'.',2)
62 ELSE o.name END) AS oname
63 FROM `$table_item` c
64 LEFT JOIN glpi_computers_items i ON (i.itemtype = 'Computer' AND i.items_id = c.id)
65 LEFT JOIN glpi_entities e ON (c.entities_id = e.id)
66 LEFT JOIN glpi_operatingsystems o ON (c.operatingsystems_id = o.id)
67 WHERE c.is_deleted = '0' AND c.is_template = '0'
68 ".getEntitiesRestrictRequest("AND", "c");
69 if ($region_id != 0) {
70 $query .= " AND ".getRealQueryForTreeItem("glpi_entities", $region_id, "e.id");
71 } else {
72 $query .= " AND e.id = '0'";
73 }
74 $query .= " GROUP BY 2,3 ORDER BY 2,3";
75 $result = $DB->query($query);
76 while ($data=$DB->fetch_assoc($result)) {
77 if (empty($data['ename'])) {
78 $data['ename'] = "<i>(indéterminé)</i>";
79 }
80 if (empty($data['oname'])) {
81 $data['oname'] = "<i>(indéterminé)</i>";
82 }
83 if (($data['oname'] == 'Debian 7') || ($data['oname'] == 'Ubuntu 12.04')) {
84 $oname_plus = '<svg width="5" height="5" style="background-color: #00ff00; margin: 1px;"/>';
85 $green_total += $data['count'];
86 } elseif (($data['oname'] == 'Debian 6') || ($data['oname'] == 'Ubuntu 10.04')) {
87 $oname_plus = '<svg width="5" height="5" style="background-color: #ffff00; margin: 1px;"/>';
88 $yellow_total += $data['count'];
89 } elseif ((substr($data['oname'],0,9) == 'Microsoft') || (substr($data['oname'],strlen($data['oname'])-4,4) == 'OS X')) {
90 $oname_plus = '<svg width="5" height="5" style="background-color: #0000ff; margin: 1px;"/>';
91 $blue_total += $data['count'];
92 } else {
93 $oname_plus = '<svg width="5" height="5" style="background-color: #ff0000; margin: 1px;"/>';
94 $red_total += $data['count'];
95 }
96 echo "<tr class='tab_bg_2 auf_show_details'>";
97 echo "<td>&nbsp;&nbsp;".$data['ename']."</td>";
98 echo "<td>".$oname_plus."&nbsp;".$data['oname']."</td>";
99 echo "<td class='numeric'>".$data['count']."</td></tr>";
100 $region_total += $data['count'];
101 }
102
103 $green_svg = '<svg width="'.(500*$green_total/$region_total).'" height="5" style="background-color: #00ff00; margin: 1px 0;"/>';
104 $yellow_svg = '<svg width="'.(500*$yellow_total/$region_total).'" height="5" style="background-color: #ffff00; margin: 1px 0;"/>';
105 $red_svg = '<svg width="'.(500*$red_total/$region_total).'" height="5" style="background-color: #ff0000; margin: 1px 0;"/>';
106 $blue_svg = '<svg width="'.(500*$blue_total/$region_total).'" height="5" style="background-color: #0000ff; margin: 1px 0;"/>';
107 echo "<tr class='tab_bg_1'><td class='b'>&nbsp;&nbsp;Sous-total</td>";
108 echo "<td>".$green_svg.$yellow_svg.$red_svg.$blue_svg."</td>";
109 echo "<td class='numeric b'>$region_total</td></tr>";
110
111 $green_grand_total += $green_total;
112 $yellow_grand_total += $yellow_total;
113 $red_grand_total += $red_total;
114 $blue_grand_total += $blue_total;
115 $grand_total += $region_total;
116 } // fin des régions
117
118 echo "<tr class='tab_bg_1'><td colspan='3'>&nbsp;</td></tr>";
119
120 # total operating systems
121 $query = "SELECT COUNT(*) FROM `".$table_item."`
122 LEFT JOIN `glpi_computers_items`
123 ON (`glpi_computers_items`.`itemtype` = '".$itemtype."'
124 AND `glpi_computers_items`.`items_id` = `".$table_item."`.`id`)
125 WHERE `".$table_item."`.`is_deleted` = '0'
126 AND `".$table_item."`.`is_template` = '0' ".
127 getEntitiesRestrictRequest("AND", $table_item);
128 $result = $DB->query($query);
129 $total = $DB->result($result, 0, 0);
130
131 $green_svg = '<svg width="'.(500*$green_grand_total/$grand_total).'" height="5" style="background-color: #00ff00; margin: 1px 0;"/>';
132 $yellow_svg = '<svg width="'.(500*$yellow_grand_total/$grand_total).'" height="5" style="background-color: #ffff00; margin: 1px 0;"/>';
133 $red_svg = '<svg width="'.(500*$red_grand_total/$grand_total).'" height="5" style="background-color: #ff0000; margin: 1px 0;"/>';
134 $blue_svg = '<svg width="'.(500*$blue_grand_total/$grand_total).'" height="5" style="background-color: #0000ff; margin: 1px 0;"/>';
135 echo "<tr class='tab_bg_1'><td class='b'>Total général</td>";
136 echo "<td>".$green_svg.$yellow_svg.$red_svg.$blue_svg."</td>";
137 echo "<td class='numeric b'>$total</td></tr>";
138
139
140 /* requête last updated computers
141 $query = "SELECT `last_fusioninventory_update`, `computers_id`
142 FROM `glpi_plugin_fusioninventory_inventorycomputercomputers`
143 LEFT JOIN `glpi_computers` ON `computers_id`=`glpi_computers`.`id`
144 WHERE ((NOW() > ADDDATE(last_fusioninventory_update, INTERVAL ".$nbdays." DAY)
145 OR last_fusioninventory_update IS NULL)
146 ".$state_sql.")".getEntitiesRestrictRequest("AND", "glpi_computers")."
147 ORDER BY last_fusioninventory_update DESC";
148 $result = $DB->query($query);
149
150 echo "<table class='tab_cadre_fixe' cellpadding='5' width='950'>";
151
152 echo "<tr class='tab_bg_1'>";
153 echo "<th colspan='4'>".__('Number of items')." : ".$DB->numrows($result)."</th>";
154 echo "</tr>";
155
156 echo "<tr class='tab_bg_1'>";
157 echo "<th>".__('Name')."</th>";
158 echo "<th>".__('Last inventory')."</th>";
159 echo "<th>".__('Serial Number')."</th>";
160 echo "<th>".__('Inventory number')."</th>";
161 echo "</tr>";
162
163 while ($data=$DB->fetch_array($result)) {
164 echo "<tr class='tab_bg_1'>";
165 echo "<td>";
166 $computer->getFromDB($data['computers_id']);
167 echo $computer->getLink(1);
168 echo "</td>";
169 echo "<td>".Html::convDateTime($data['last_fusioninventory_update'])."</td>";
170 echo "<td>".$computer->fields['serial']."</td>";
171 echo "<td>".$computer->fields['otherserial']."</td>";
172 echo "</tr>";
173 }
174 */
175
176 echo "</table>";
177
178 /*
179 echo '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="150" height="150">
180 <rect width="90" height="90" x="30" y="30" style="fill:#0000ff;fill-opacity:0.75;stroke:#000000"/>
181 <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red"/>
182 <polygon points="100,10 40,180 190,60 10,60 160,180" style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;" />
183 </svg>';
184 echo '<svg width="200" height="200" style="background-color: #D2B48C; display: block; margin-bottom: 5px;" id="embeddedSVG">
185 <g id="myGroup" fill="blue" style="font-size: 18px; text-anchor: middle; font-family: serif;">
186 <circle id="myCircle" cx="100" cy="75" r="50" stroke="firebrick" stroke-width="3" />
187 <text x="100" y="155">Hello World</text>
188 <text x="100" y="175">From Embedded SVG!</text>
189 </g>
190 </svg>';
191 */
192
193 Html::footer();
194
195 ?>