+<?php
+//Options for GLPI 0.71 and newer : need slave db to access the report
+$USEDBREPLICATE=1;
+$DBCONNECTION_REQUIRED=0;
+
+include ("../../inc/includes.php");
+
+Session::checkRight("reports", "r");
+Session::checkRight("computer", "r");
+
+Html::header(Report::getTypeName(2), $_SERVER['PHP_SELF'], "utils", "report");
+Report::title();
+
+$computer = new Computer();
+
+$state_sql = "";
+if (($state != "") AND ($state != "0")) {
+ $state_sql = " AND `states_id` = '".$state."' ";
+}
+
+$itemtype = 'Computer';
+$table_item = getTableForItemType($itemtype);
+
+/* reprise du Rapport par défaut */
+// global $DB;
+echo "<span class='big b'>WIP (rapport en cours de développement)</span><br><br>";
+echo "<table class='tab_cadrehov'>";
+
+echo "<tr class='tab_bg_1'><td>Implantation</td><td>Systèmes d'exploitation</td><td>Qtt</td></tr>";
+$green_grand_total = 0;
+$yellow_grand_total = 0;
+$red_grand_total = 0;
+$blue_grand_total = 0;
+$grand_total = 0;
+
+# parcours des régions
+$query = "SELECT id,name,completename FROM glpi_entities WHERE (id=0 OR entities_id=0)";
+$query .= " ".getEntitiesRestrictRequest("AND", "glpi_entities");
+$region_result = $DB->query($query);
+while ($region_data = $DB->fetch_assoc($region_result)) {
+ $region_id = $region_data['id'];
+ if ($region_id != 0) {
+ $region_name = getTreeLeafValueName("glpi_entities", $region_id);
+ } else {
+ $region_name = "AUF (non classé)";
+ }
+ echo "<tr class='tab_bg_1'><td colspan='3' class='b'>$region_name</td></tr>";
+# foreach (getSonsOf("glpi_entities", $data['id']) as $id) {
+# echo "<tr class='tab_bg_1'><td colspan='3' class='b'> ".getTreeValueCompleteName("glpi_entities", $id)."</td></tr>";
+# }
+#}
+ $green_total = 0;
+ $yellow_total = 0;
+ $red_total = 0;
+ $blue_total = 0;
+ $region_total = 0;
+
+# operating systems per computer
+$query = "SELECT COUNT(c.id) AS count, e.name AS ename,
+ (CASE WHEN o.name REGEXP '^Debian' THEN SUBSTRING_INDEX(REPLACE(o.name,' GNU/Linux',''),'.',1)
+ WHEN o.name REGEXP '^Ubuntu' THEN SUBSTRING_INDEX(REPLACE(o.name,' LTS',''),'.',2)
+ ELSE o.name END) AS oname
+ FROM `$table_item` c
+ LEFT JOIN glpi_computers_items i ON (i.itemtype = 'Computer' AND i.items_id = c.id)
+ LEFT JOIN glpi_entities e ON (c.entities_id = e.id)
+ LEFT JOIN glpi_operatingsystems o ON (c.operatingsystems_id = o.id)
+ WHERE c.is_deleted = '0' AND c.is_template = '0'
+ ".getEntitiesRestrictRequest("AND", "c");
+if ($region_id != 0) {
+ $query .= " AND ".getRealQueryForTreeItem("glpi_entities", $region_id, "e.id");
+} else {
+ $query .= " AND e.id = '0'";
+}
+$query .= " GROUP BY 2,3 ORDER BY 2,3";
+$result = $DB->query($query);
+while ($data=$DB->fetch_assoc($result)) {
+ if (empty($data['ename'])) {
+ $data['ename'] = "<i>(indéterminé)</i>";
+ }
+ if (empty($data['oname'])) {
+ $data['oname'] = "<i>(indéterminé)</i>";
+ }
+ if (($data['oname'] == 'Debian 7') || ($data['oname'] == 'Ubuntu 12.04')) {
+ $oname_plus = '<svg width="5" height="5" style="background-color: #00ff00; margin: 1px;"/>';
+ $green_total += $data['count'];
+ } elseif (($data['oname'] == 'Debian 6') || ($data['oname'] == 'Ubuntu 10.04')) {
+ $oname_plus = '<svg width="5" height="5" style="background-color: #ffff00; margin: 1px;"/>';
+ $yellow_total += $data['count'];
+ } elseif ((substr($data['oname'],0,9) == 'Microsoft') || (substr($data['oname'],strlen($data['oname'])-4,4) == 'OS X')) {
+ $oname_plus = '<svg width="5" height="5" style="background-color: #0000ff; margin: 1px;"/>';
+ $blue_total += $data['count'];
+ } else {
+ $oname_plus = '<svg width="5" height="5" style="background-color: #ff0000; margin: 1px;"/>';
+ $red_total += $data['count'];
+ }
+ echo "<tr class='tab_bg_2 auf_show_details'>";
+ echo "<td> ".$data['ename']."</td>";
+ echo "<td>".$oname_plus." ".$data['oname']."</td>";
+ echo "<td class='numeric'>".$data['count']."</td></tr>";
+ $region_total += $data['count'];
+}
+
+$green_svg = '<svg width="'.(500*$green_total/$region_total).'" height="5" style="background-color: #00ff00; margin: 1px 0;"/>';
+$yellow_svg = '<svg width="'.(500*$yellow_total/$region_total).'" height="5" style="background-color: #ffff00; margin: 1px 0;"/>';
+$red_svg = '<svg width="'.(500*$red_total/$region_total).'" height="5" style="background-color: #ff0000; margin: 1px 0;"/>';
+$blue_svg = '<svg width="'.(500*$blue_total/$region_total).'" height="5" style="background-color: #0000ff; margin: 1px 0;"/>';
+echo "<tr class='tab_bg_1'><td class='b'> Sous-total</td>";
+echo "<td>".$green_svg.$yellow_svg.$red_svg.$blue_svg."</td>";
+echo "<td class='numeric b'>$region_total</td></tr>";
+
+$green_grand_total += $green_total;
+$yellow_grand_total += $yellow_total;
+$red_grand_total += $red_total;
+$blue_grand_total += $blue_total;
+$grand_total += $region_total;
+} // fin des régions
+
+echo "<tr class='tab_bg_1'><td colspan='3'> </td></tr>";
+
+# total operating systems
+$query = "SELECT COUNT(*) FROM `".$table_item."`
+ LEFT JOIN `glpi_computers_items`
+ ON (`glpi_computers_items`.`itemtype` = '".$itemtype."'
+ AND `glpi_computers_items`.`items_id` = `".$table_item."`.`id`)
+ WHERE `".$table_item."`.`is_deleted` = '0'
+ AND `".$table_item."`.`is_template` = '0' ".
+ getEntitiesRestrictRequest("AND", $table_item);
+$result = $DB->query($query);
+$total = $DB->result($result, 0, 0);
+
+$green_svg = '<svg width="'.(500*$green_grand_total/$grand_total).'" height="5" style="background-color: #00ff00; margin: 1px 0;"/>';
+$yellow_svg = '<svg width="'.(500*$yellow_grand_total/$grand_total).'" height="5" style="background-color: #ffff00; margin: 1px 0;"/>';
+$red_svg = '<svg width="'.(500*$red_grand_total/$grand_total).'" height="5" style="background-color: #ff0000; margin: 1px 0;"/>';
+$blue_svg = '<svg width="'.(500*$blue_grand_total/$grand_total).'" height="5" style="background-color: #0000ff; margin: 1px 0;"/>';
+echo "<tr class='tab_bg_1'><td class='b'>Total général</td>";
+echo "<td>".$green_svg.$yellow_svg.$red_svg.$blue_svg."</td>";
+echo "<td class='numeric b'>$total</td></tr>";
+
+
+/* requête last updated computers
+$query = "SELECT `last_fusioninventory_update`, `computers_id`
+ FROM `glpi_plugin_fusioninventory_inventorycomputercomputers`
+ LEFT JOIN `glpi_computers` ON `computers_id`=`glpi_computers`.`id`
+WHERE ((NOW() > ADDDATE(last_fusioninventory_update, INTERVAL ".$nbdays." DAY)
+ OR last_fusioninventory_update IS NULL)
+ ".$state_sql.")".getEntitiesRestrictRequest("AND", "glpi_computers")."
+ ORDER BY last_fusioninventory_update DESC";
+$result = $DB->query($query);
+
+echo "<table class='tab_cadre_fixe' cellpadding='5' width='950'>";
+
+echo "<tr class='tab_bg_1'>";
+echo "<th colspan='4'>".__('Number of items')." : ".$DB->numrows($result)."</th>";
+echo "</tr>";
+
+echo "<tr class='tab_bg_1'>";
+echo "<th>".__('Name')."</th>";
+echo "<th>".__('Last inventory')."</th>";
+echo "<th>".__('Serial Number')."</th>";
+echo "<th>".__('Inventory number')."</th>";
+echo "</tr>";
+
+while ($data=$DB->fetch_array($result)) {
+ echo "<tr class='tab_bg_1'>";
+ echo "<td>";
+ $computer->getFromDB($data['computers_id']);
+ echo $computer->getLink(1);
+ echo "</td>";
+ echo "<td>".Html::convDateTime($data['last_fusioninventory_update'])."</td>";
+ echo "<td>".$computer->fields['serial']."</td>";
+ echo "<td>".$computer->fields['otherserial']."</td>";
+ echo "</tr>";
+}
+*/
+
+echo "</table>";
+
+/*
+echo '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="150" height="150">
+ <rect width="90" height="90" x="30" y="30" style="fill:#0000ff;fill-opacity:0.75;stroke:#000000"/>
+ <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red"/>
+ <polygon points="100,10 40,180 190,60 10,60 160,180" style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;" />
+ </svg>';
+echo '<svg width="200" height="200" style="background-color: #D2B48C; display: block; margin-bottom: 5px;" id="embeddedSVG">
+ <g id="myGroup" fill="blue" style="font-size: 18px; text-anchor: middle; font-family: serif;">
+ <circle id="myCircle" cx="100" cy="75" r="50" stroke="firebrick" stroke-width="3" />
+ <text x="100" y="155">Hello World</text>
+ <text x="100" y="175">From Embedded SVG!</text>
+ </g>
+ </svg>';
+*/
+
+Html::footer();
+
+?>