echo "<select name='type'>" . $INSELECT . "</select></td>";
echo "<td class='right'>" . $LANG['search'][8] . "&nbsp;:</td><td>";
showDateFormItem("date1", $_REQUEST["date1"]);
echo "</td>";
echo "<td class='right'>" . $LANG['stats'][7] . "&nbsp;:</td>";
echo "<td rowspan='2' class='center'>";
echo "<input type='submit' class='button' name='submit' value=\"" . $LANG['buttons'][7] . "\"></td></tr>";
echo "<tr class='tab_bg_2'><td class='right'>" . $LANG['search'][9] . "&nbsp;:</td><td>";
showDateFormItem("date2", $_REQUEST["date2"]);
echo "</td><td class='center'>";
Dropdown::showYesNo('showgraph', $_REQUEST['showgraph']);
echo "</td></tr>";
echo "</table></form></div>";
$val = Stat::getItems($_REQUEST["date1"], $_REQUEST["date2"], $_REQUEST["type"]);
$params = array('type' => $_REQUEST["type"], 'date1' => $_REQUEST["date1"], 'date2' => $_REQUEST["date2"], 'start' => $_REQUEST["start"]);
printPager($_REQUEST['start'], count($val), $CFG_GLPI['root_doc'] . '/front/stat.tracking.php', "date1=" . $_REQUEST["date1"] . "&amp;date2=" . $_REQUEST["date2"] . "&amp;type=" . $_REQUEST["type"] . "&amp;showgraph=" . $_REQUEST["showgraph"], 'Stat', $params);
if (!$_REQUEST['showgraph']) {
    Stat::show($_REQUEST["type"], $_REQUEST["date1"], $_REQUEST["date2"], $_REQUEST['start'], $val);
} else {
    $data = Stat::getDatas($_REQUEST["type"], $_REQUEST["date1"], $_REQUEST["date2"], $_REQUEST['start'], $val);
    if (isset($data['opened']) && is_array($data['opened'])) {
        foreach ($data['opened'] as $key => $val) {
            $newkey = html_clean($key);
            $cleandata[$newkey] = $val;
        }
        Stat::showGraph(array($LANG['stats'][5] => $cleandata), array('title' => $LANG['stats'][5], 'showtotal' => 1, 'unit' => $LANG['stats'][35], 'type' => 'pie'));
    }
    if (isset($data['solved']) && is_array($data['solved'])) {
        foreach ($data['solved'] as $key => $val) {
            $newkey = html_clean($key);
            $cleandata[$newkey] = $val;
 /**
  * Print a nice tab for last event
  *
  * Print a great tab to present lasts events occured on glpi
  *
  * @param $target where to go when complete
  * @param $order order by clause occurences (eg: )
  * @param $sort order by clause occurences (eg: date)
  * @param $start
  **/
 static function showList($target, $order = 'DESC', $sort = 'date', $start = 0)
 {
     global $DB, $CFG_GLPI, $LANG;
     // Show events from $result in table form
     list($logItemtype, $logService) = self::logArray();
     // Columns of the Table
     $items = array("items_id" => array($LANG['event'][0], "colspan='2'"), "date" => array($LANG['common'][27], ""), "service" => array($LANG['event'][2], "width='8%'"), "level" => array($LANG['event'][3], "width='8%'"), "message" => array($LANG['event'][4], "width='50%'"));
     // define default sorting
     if (!isset($items[$sort])) {
         $sort = "date";
     }
     if ($order != "ASC") {
         $order = "DESC";
     }
     // Query Database
     $query_limit = "SELECT *\n                      FROM `glpi_events`\n                      ORDER BY `{$sort}` {$order}\n                      LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']);
     // Number of results
     $numrows = countElementsInTable("glpi_events");
     // Get results
     $result = $DB->query($query_limit);
     $number = $DB->numrows($result);
     // No Events in database
     if ($number < 1) {
         echo "<div class='center b'>" . $LANG['central'][4] . "</div>";
         return;
     }
     // Output events
     $i = 0;
     echo "<div class='center'>";
     $parameters = "sort={$sort}&amp;order={$order}";
     printPager($start, $numrows, $target, $parameters);
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     foreach ($items as $field => $args) {
         echo "<th " . $args[1] . ">";
         if ($sort == $field) {
             if ($order == "DESC") {
                 echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/puce-down.png\" alt='' title=''>";
             } else {
                 echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/puce-up.png\" alt='' title=''>";
             }
         }
         echo "<a href='{$target}?sort={$field}&amp;order=" . ($order == "ASC" ? "DESC" : "ASC") . "'>" . $args[0] . "</a></th>";
     }
     echo "</tr>";
     while ($i < $number) {
         $ID = $DB->result($result, $i, "id");
         $items_id = $DB->result($result, $i, "items_id");
         $type = $DB->result($result, $i, "type");
         $date = $DB->result($result, $i, "date");
         $service = $DB->result($result, $i, "service");
         $level = $DB->result($result, $i, "level");
         $message = $DB->result($result, $i, "message");
         $itemtype = "&nbsp;";
         if (isset($logItemtype[$type])) {
             $itemtype = $logItemtype[$type];
         } else {
             $type = getSingular($type);
             if (class_exists($type)) {
                 $item = new $type();
                 $itemtype = $item->getTypeName();
             }
         }
         echo "<tr class='tab_bg_2'>";
         echo "<td>{$itemtype} :</td>";
         echo "<td class='center b'>";
         self::displayItemLogID($type, $items_id);
         echo "</td><td>" . convDateTime($date) . "</td>";
         echo "<td class='center'>" . (isset($logService[$service]) ? $logService[$service] : $service);
         echo "</td><td class='center'>{$level}</td><td>{$message}</td></tr>";
         $i++;
     }
     echo "</table></div><br>";
 }
 /** Show LDAP groups to add or synchronise in an entity
  *
  * @param   $target target page for the form
  * @param   $check check all ? -> need to be delete
  * @param   $start where to start the list
  * @param   $sync synchronise or add ?
  * @param   $filter ldap filter to use
  * @param   $filter2 second ldap filter to use (which case ?)
  * @param   $entity working entity
  * @param   $order display order
  *
  * @return  nothing
  **/
 static function showLdapGroups($target, $check, $start, $sync = 0, $filter = '', $filter2 = '', $entity, $order = 'DESC')
 {
     global $LANG;
     echo "<br>";
     $ldap_groups = self::getAllGroups($_SESSION["ldap_server"], $filter, $filter2, $entity, $order);
     if (is_array($ldap_groups)) {
         $numrows = count($ldap_groups);
         $action = "toimport";
         $form_action = "import_ok";
         $colspan = isMultiEntitiesMode() ? 5 : 4;
         if ($numrows > 0) {
             $parameters = "check={$check}";
             printPager($start, $numrows, $target, $parameters);
             // delete end
             array_splice($ldap_groups, $start + $_SESSION['glpilist_limit']);
             // delete begin
             if ($start > 0) {
                 array_splice($ldap_groups, 0, $start);
             }
             echo "<div class='center'>";
             echo "<form method='post' id='ldap_form' name='ldap_form'  action='{$target}'>";
             echo "<a href='" . $target . "?check=all'\n                   onclick= \"if ( markCheckboxes('ldap_form') ) return false;\">" . $LANG['buttons'][18] . "</a>&nbsp;/&nbsp;";
             echo "<a href='" . $target . "?check=none'\n                   onclick= \"if ( unMarkCheckboxes('ldap_form') ) return false;\">" . $LANG['buttons'][19] . "</a>";
             echo "<table class='tab_cadre'>";
             echo "<tr><th>" . $LANG['buttons'][37] . "</th>";
             $header_num = 0;
             echo Search::showHeaderItem(HTML_OUTPUT, $LANG['common'][35], $header_num, $target . "?order=" . ($order == "DESC" ? "ASC" : "DESC"), 1, $order);
             echo "<th>" . $LANG['setup'][261] . "</th>";
             echo "<th>" . $LANG['ocsng'][36] . "</th>";
             if (isMultiEntitiesMode()) {
                 echo "<th>" . $LANG['entity'][9] . "</th>";
             }
             echo "</tr>";
             foreach ($ldap_groups as $groupinfos) {
                 $group = $groupinfos["cn"];
                 $group_dn = $groupinfos["dn"];
                 $search_type = $groupinfos["search_type"];
                 echo "<tr class='tab_bg_2 center'>";
                 //Need to use " instead of ' because it doesn't work with names with ' inside !
                 echo "<td><input type='checkbox' name=\"" . $action . "[" . $group_dn . "]\" " . ($check == "all" ? "checked" : "") . "></td>";
                 echo "<td>" . $group . "</td>";
                 echo "<td>" . $group_dn . "</td>";
                 echo "<td>";
                 Dropdown::show('Entity', array('value' => $entity, 'name' => "toimport_entities[" . $group_dn . "]=" . $entity));
                 echo "</td>";
                 if (isMultiEntitiesMode()) {
                     echo "<td>";
                     Dropdown::showYesNo("toimport_recursive[" . $group_dn . "]", 0);
                     echo "</td>";
                 } else {
                     echo "<td><input type='hidden' name=\"toimport_recursive[" . $group_dn . "]\"\n                             value='0'></td>";
                 }
                 echo "<td><input type='hidden' name=\"toimport_type[" . $group_dn . "]\" value=\"" . $search_type . "\"></td></tr>";
             }
             echo "<tr class='tab_bg_1'><td colspan='{$colspan}' class='center'>";
             echo "<input class='submit' type='submit' name='" . $form_action . "' value='" . $LANG['buttons'][37] . "'>";
             echo "</td></tr>";
             echo "</table></form></div>";
             printPager($start, $numrows, $target, $parameters);
         } else {
             echo "<div class='center b'>" . $LANG['ldap'][25] . "</div>";
         }
     } else {
         echo "<div class='center b'>" . $LANG['ldap'][25] . "</div>";
     }
 }
 function showForm($target, $ID)
 {
     global $LANG;
     if (!PluginFusioninventory::haveRight("snmp_printers", "r")) {
         return false;
     }
     // display stats
     if ($stats = $this->stats($ID)) {
         echo "<br><div align = 'center'>";
         echo "<table class='tab_cadre' cellpadding='5'><tr><th colspan='2'>";
         echo $LANG['plugin_fusioninventory']["prt_history"][10] . " " . $stats["num_days"] . " " . $LANG['plugin_fusioninventory']["prt_history"][11] . "</th></tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . $LANG['plugin_fusioninventory']["prt_history"][12] . " : </td>";
         echo "<td>" . $stats["num_pages"] . "</td></tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . $LANG['plugin_fusioninventory']["prt_history"][13] . " : </td>";
         echo "<td>" . $stats["pages_per_day"] . "</td></tr>";
         echo "</table></div>";
     }
     // preparing to display history
     if (!isset($_GET['start'])) {
         $_GET['start'] = 0;
     }
     $numrows = $this->countAllEntries($ID);
     $parameters = "ID=" . $_GET["ID"] . "&onglet=" . $_SESSION["glpi_onglet"];
     echo "<br>";
     printPager($_GET['start'], $numrows, $_SERVER['PHP_SELF'], $parameters);
     if ($_SESSION["glpilist_limit"] < $numrows) {
         $limit = $_SESSION["glpilist_limit"];
     } else {
         $limit = $numrows;
     }
     // Get history
     if (!($data = $this->getEntries($ID, $_GET['start'], $limit))) {
         return false;
     }
     echo "<div align='center'><form method='post' name='printer_history_form'\n                 id='printer_history_form'  action=\"" . $target . "\">";
     echo "<table class='tab_cadre' cellpadding='5'><tr><th colspan='3'>";
     echo $LANG['plugin_fusioninventory']["prt_history"][20] . " :</th></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th></th>";
     echo "<th>" . $LANG['plugin_fusioninventory']["prt_history"][21] . " :</th>";
     echo "<th>" . $LANG['plugin_fusioninventory']["prt_history"][22] . " :</th></tr>";
     for ($i = 0; $i < $limit; $i++) {
         echo "<tr class='tab_bg_1'>";
         echo "<td align='center'>";
         echo "<input type='checkbox' name='checked_{$i}' value='1'>";
         echo "</td>";
         echo "<td align='center'>" . $data["{$i}"]['date'] . "</td>";
         echo "<td align='center'>" . $data["{$i}"]['pages'] . "</td>";
         echo "</td></tr>";
         echo "<input type='hidden' name='ID_{$i}' value='" . $data["{$i}"]['ID'] . "'>";
     }
     if (!PluginFusioninventory::haveRight("snmp_printers", "w")) {
         return false;
     }
     echo "<input type='hidden' name='limit' value='" . $limit . "'>";
     echo "<tr class='tab_bg_1'><td colspan='3'>";
     echo "<div align='center'><a onclick= \"if (markAllRows('printer_history_form')) \n                 return false;\"\n                 href='" . $_SERVER['PHP_SELF'] . "?select=all'>" . $LANG["buttons"][18] . "</a>";
     echo " - <a onclick= \"if ( unMarkAllRows('printer_history_form') ) return false;\"\n                  href='" . $_SERVER['PHP_SELF'] . "?select=none'>" . $LANG["buttons"][19] . "</a> ";
     echo "<input type='submit' name='delete' value=\"" . $LANG["buttons"][6] . "\" class='submit' >\n            </div></td></tr>";
     echo "</table></form></div>";
 }
Exemple #5
0
    ?>
</a></td>
<td><?php 
    if ($task['status'] == 'working') {
        print 'Still on it';
    } else {
        print $task['completion_time'];
    }
    ?>
</td>
<td><?php 
    echo ucfirst($task['type']);
    ?>
</td>

<td class="action"><a class="icon edit" href="edit.php?task=<?php 
    echo $id;
    ?>
&amp;action=show_form">Edit</a></td>
<td class="action"><a class="icon delete confirm" href="delete.php?task=<?php 
    echo $id;
    ?>
">Delete</a></td></tr>
<?php 
}
?>
</table>

<?php 
printPager();
 function showForm($type, $target, $ID)
 {
     global $LANG;
     if (!PluginFusioninventory::haveRight("errors", "r")) {
         return false;
     }
     // preparing to display history
     if (!isset($_GET['start'])) {
         $_GET['start'] = 0;
     }
     $numrows = $this->countEntries($type, $ID);
     $parameters = "ID=" . $_GET["ID"] . "&onglet=" . $_SESSION["glpi_onglet"];
     echo "<br>";
     printPager($_GET['start'], $numrows, $_SERVER['PHP_SELF'], $parameters);
     if ($_SESSION["glpilist_limit"] < $numrows) {
         $limit = $_SESSION["glpilist_limit"];
     } else {
         $limit = $numrows;
     }
     // Get history
     if (!($data = $this->getEntries($type, $ID, $_GET['start'], $limit))) {
         return false;
     }
     // for $_GET['type'] (useful to check rights)
     if ($type == COMPUTER_TYPE) {
         echo "<div align='center'><form method='post' name='errors_form' id='errors_form'\n                    action=\"" . $target . "?type=" . COMPUTER_TYPE . "\">";
     } else {
         if ($type == NETWORKING_TYPE) {
             echo "<div align='center'><form method='post' name='errors_form' id='errors_form'\n                    action=\"" . $target . "?type=" . NETWORKING_TYPE . "\">";
         } else {
             // $type == PRINTER_TYPE
             echo "<div align='center'><form method='post' name='errors_form' id='errors_form'\n                    action=\"" . $target . "?type=" . PRINTER_TYPE . "\">";
         }
     }
     echo "<table class='tab_cadre' cellpadding='5'><tr><th colspan='5'>";
     echo $LANG['plugin_fusioninventory']["errors"][0] . " :</th></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th></th>";
     echo "<th>" . $LANG['plugin_fusioninventory']["errors"][1] . " :</th>";
     echo "<th>" . $LANG['plugin_fusioninventory']["errors"][2] . " :</th>";
     echo "<th>" . $LANG['plugin_fusioninventory']["errors"][3] . " :</th>";
     echo "<th>" . $LANG['plugin_fusioninventory']["errors"][4] . " :</th></tr>";
     for ($i = 0; $i < $limit; $i++) {
         echo "<tr class='tab_bg_1'>";
         echo "<td align='center'>";
         echo "<input type='checkbox' name='checked_{$i}' value='1'>";
         echo "</td>";
         echo "<td align='center'>" . $data["{$i}"]['ifaddr'] . "</td>";
         echo "<td align='center'>" . $data["{$i}"]['description'] . "</td>";
         echo "<td align='center'>" . $data["{$i}"]['first_pb_date'] . "</td>";
         echo "<td align='center'>" . $data["{$i}"]['last_pb_date'] . "</td>";
         echo "</td></tr>";
         echo "<input type='hidden' name='ID_{$i}' value='" . $data["{$i}"]['ID'] . "'>";
     }
     if (!PluginFusioninventory::haveRight("errors", "w")) {
         return false;
     }
     echo "<input type='hidden' name='limit' value='" . $limit . "'>";
     echo "<tr class='tab_bg_1'><td colspan='5'>";
     echo "<div align='center'><a onclick= \"if ( markAllRows('errors_form') ) return false;\"\n                 href='" . $_SERVER['PHP_SELF'] . "?select=all'>" . $LANG["buttons"][18] . "</a>";
     echo " - <a onclick= \"if ( unMarkAllRows('errors_form') ) return false;\"\n                  href='" . $_SERVER['PHP_SELF'] . "?select=none'>" . $LANG["buttons"][19] . "</a> ";
     echo "<input type='submit' name='delete' value=\"" . $LANG["buttons"][6] . "\" class='submit' >\n            </div></td></tr>";
     echo "</table></form></div>";
 }
 function showBoard($width = '', $limit = '')
 {
     global $DB, $CFG_GLPI, $LANG;
     $where = '';
     if ($limit == 'hosts') {
         $where = "`plugin_monitoring_services_id`='0' ";
     } else {
         if ($limit == 'services') {
             $where = "`plugin_monitoring_services_id`>0 ";
         }
     }
     if (isset($_SESSION['plugin_monitoring']['service']['field'])) {
         foreach ($_SESSION['plugin_monitoring']['service']['field'] as $key => $value) {
             $wheretmp = '';
             if (isset($_SESSION['plugin_monitoring']['service']['link'][$key])) {
                 $wheretmp .= " " . $_SESSION['plugin_monitoring']['service']['link'][$key] . " ";
             }
             $wheretmp .= Search::addWhere("", 0, "PluginMonitoringService", $_SESSION['plugin_monitoring']['service']['field'][$key], $_SESSION['plugin_monitoring']['service']['searchtype'][$key], $_SESSION['plugin_monitoring']['service']['contains'][$key]);
             if (!strstr($wheretmp, "``.``")) {
                 if ($where != '' and !isset($_SESSION['plugin_monitoring']['service']['link'][$key])) {
                     $where .= " AND ";
                 }
                 $where .= $wheretmp;
             }
         }
     }
     if ($where != '') {
         $where = "(" . $where;
         $where .= ") AND ";
     }
     $where .= ' `glpi_plugin_monitoring_services`.`entities_id` IN (' . $_SESSION['glpiactiveentities_string'] . ')';
     if ($where != '') {
         $where = " WHERE " . $where;
         $where = str_replace("`" . getTableForItemType("PluginMonitoringDisplay") . "`.", "", $where);
     }
     $leftjoin = '';
     if (isset($_SESSION['plugin_monitoring']['service']['field'])) {
         foreach ($_SESSION['plugin_monitoring']['service']['field'] as $value) {
             if ($value == '20' or $value == '21' or $value == '22') {
                 $leftjoin .= " LEFT JOIN `glpi_plugin_monitoring_componentscatalogs_hosts`\n                  ON `plugin_monitoring_componentscatalogs_hosts_id` = \n                  `glpi_plugin_monitoring_componentscatalogs_hosts`.`id` ";
             } else {
                 if ($value == '7') {
                     $leftjoin .= " LEFT JOIN `glpi_plugin_monitoring_components`\n                  ON `plugin_monitoring_components_id` = \n                  `glpi_plugin_monitoring_components`.`id` ";
                 } else {
                     if ($value == '8') {
                         if (!strstr($leftjoin, 'LEFT JOIN `glpi_plugin_monitoring_componentscatalogs_hosts`')) {
                             $leftjoin .= " LEFT JOIN `glpi_plugin_monitoring_componentscatalogs_hosts`\n                  ON `plugin_monitoring_componentscatalogs_hosts_id` = \n                  `glpi_plugin_monitoring_componentscatalogs_hosts`.`id` ";
                         }
                         if (!strstr($leftjoin, 'LEFT JOIN `glpi_plugin_monitoring_componentscatalogs`')) {
                             $leftjoin .= " LEFT JOIN `glpi_plugin_monitoring_componentscatalogs`\n                     ON `glpi_plugin_monitoring_componentscatalogs_hosts`.`plugin_monitoring_componentscalalog_id` = \n                     `glpi_plugin_monitoring_componentscatalogs`.`id` ";
                         }
                     }
                 }
             }
         }
     }
     $query = "SELECT `" . getTableForItemType("PluginMonitoringService") . "`.* FROM `" . getTableForItemType("PluginMonitoringService") . "`\n         " . $leftjoin . "\n         " . $where . "\n         ORDER BY `name`";
     $result = $DB->query($query);
     $start = 0;
     if (isset($_GET["start"])) {
         $start = $_GET["start"];
     }
     $numrows = $DB->numrows($result);
     $parameters = '';
     $globallinkto = Search::getArrayUrlLink("field", $_GET['field']) . Search::getArrayUrlLink("link", $_GET['link']) . Search::getArrayUrlLink("contains", $_GET['contains']) . Search::getArrayUrlLink("searchtype", $_GET['searchtype']) . Search::getArrayUrlLink("field2", $_GET['field2']) . Search::getArrayUrlLink("contains2", $_GET['contains2']) . Search::getArrayUrlLink("itemtype2", $_GET['itemtype2']) . Search::getArrayUrlLink("searchtype2", $_GET['searchtype2']) . Search::getArrayUrlLink("link2", $_GET['link2']);
     $parameters = "sort=" . $_GET['sort'] . "&amp;order=" . $_GET['order'] . $globallinkto;
     printPager($_GET['start'], $numrows, $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/display.php", $parameters);
     $limit = $numrows;
     if ($_SESSION["glpilist_limit"] < $numrows) {
         $limit = $_SESSION["glpilist_limit"];
     }
     $query .= " LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']);
     $result = $DB->query($query);
     if ($width == '') {
         echo "<table class='tab_cadrehov' style='width:100%;'>";
     } else {
         echo "<table class='tab_cadrehov' style='width:100%;'>";
     }
     echo "<tr class='tab_bg_1'>";
     echo "<th>";
     echo $LANG['joblist'][0];
     echo "</th>";
     echo "<th>";
     echo $LANG['entity'][0];
     echo "</th>";
     echo "<th>";
     echo $LANG['stats'][7];
     echo "</th>";
     echo "<th>";
     echo $LANG['state'][6] . " - " . $LANG['common'][16];
     echo "</th>";
     echo "<th>";
     echo $LANG['plugin_monitoring']['component'][0];
     echo "</th>";
     echo "<th>";
     echo $LANG['state'][0];
     echo "</th>";
     echo "<th>";
     echo $LANG['plugin_monitoring']['service'][18];
     echo "</th>";
     echo "<th>";
     echo $LANG['rulesengine'][82];
     echo "</th>";
     echo "<th>";
     echo $LANG['plugin_monitoring']['host'][9];
     echo "</th>";
     echo "</tr>";
     while ($data = $DB->fetch_array($result)) {
         echo "<tr class='tab_bg_3'>";
         $this->displayLine($data);
         echo "</tr>";
     }
     echo "</table>";
     echo "<br/>";
     printPager($_GET['start'], $numrows, $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/display.php", $parameters);
 }
    exit;
}
$item = new $_REQUEST["dropdown"]();
if (!$item instanceof CommonDevice) {
    // echo "Dropdown";
    $type = "comp_champ";
    $val = Stat::getItems($_REQUEST["date1"], $_REQUEST["date2"], $_REQUEST["dropdown"]);
    $params = array('type' => $type, 'dropdown' => $_REQUEST["dropdown"], 'date1' => $_REQUEST["date1"], 'date2' => $_REQUEST["date2"], 'start' => $_REQUEST["start"]);
} else {
    //   echo "Device";
    $type = "device";
    $field = $_REQUEST["dropdown"];
    $val = Stat::getItems($_REQUEST["date1"], $_REQUEST["date2"], $_REQUEST["dropdown"]);
    $params = array('type' => $type, 'dropdown' => $_REQUEST["dropdown"], 'date1' => $_REQUEST["date1"], 'date2' => $_REQUEST["date2"], 'start' => $_REQUEST["start"]);
}
printPager($_REQUEST['start'], count($val), $CFG_GLPI['root_doc'] . '/front/stat.location.php', "date1=" . $_REQUEST["date1"] . "&amp;date2=" . $_REQUEST["date2"] . "&amp;dropdown=" . $_REQUEST["dropdown"], 'Stat', $params);
if (!$_REQUEST['showgraph']) {
    Stat::show($type, $_REQUEST["date1"], $_REQUEST["date2"], $_REQUEST['start'], $val, $_REQUEST["dropdown"]);
} else {
    $data = Stat::getDatas($type, $_REQUEST["date1"], $_REQUEST["date2"], $_REQUEST['start'], $val, $_REQUEST["dropdown"]);
    if (isset($data['opened']) && is_array($data['opened'])) {
        foreach ($data['opened'] as $key => $val) {
            $cleandata[html_clean($key)] = $val;
        }
        Stat::showGraph(array($LANG['stats'][5] => $cleandata), array('title' => $LANG['stats'][5], 'showtotal' => 1, 'unit' => $LANG['stats'][35], 'type' => 'pie'));
    }
    if (isset($data['solved']) && is_array($data['solved'])) {
        foreach ($data['solved'] as $key => $val) {
            $cleandata[html_clean($key)] = $val;
        }
        Stat::showGraph(array($LANG['stats'][11] => $cleandata), array('title' => $LANG['stats'][11], 'showtotal' => 1, 'unit' => $LANG['stats'][35], 'type' => 'pie'));
 static function showItems($target, $date1, $date2, $start)
 {
     global $DB, $CFG_GLPI, $LANG;
     $view_entities = isMultiEntitiesMode();
     if ($view_entities) {
         $entities = getAllDatasFromTable('glpi_entities');
     }
     $output_type = HTML_OUTPUT;
     if (isset($_GET["display_type"])) {
         $output_type = $_GET["display_type"];
     }
     if (empty($date2)) {
         $date2 = date("Y-m-d");
     }
     $date2 .= " 23:59:59";
     // 1 an par defaut
     if (empty($date1)) {
         $date1 = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d"), date("Y") - 1));
     }
     $date1 .= " 00:00:00";
     $query = "SELECT `itemtype`,\n                       `items_id`,\n                       COUNT(*) AS NB\n                FROM `glpi_tickets`\n                WHERE `date` <= '{$date2}'\n                      AND `date` >= '{$date1}' " . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n                      AND `itemtype` <> ''\n                      AND `items_id` > 0\n                GROUP BY `itemtype`, `items_id`\n                ORDER BY NB DESC";
     $result = $DB->query($query);
     $numrows = $DB->numrows($result);
     if ($numrows > 0) {
         if ($output_type == HTML_OUTPUT) {
             printPager($start, $numrows, $target, "date1=" . $date1 . "&amp;date2=" . $date2 . "&amp;type=hardwares&amp;start={$start}", 'Stat');
             echo "<div class='center'>";
         }
         $end_display = $start + $_SESSION['glpilist_limit'];
         if (isset($_GET['export_all'])) {
             $end_display = $numrows;
         }
         echo Search::showHeader($output_type, $end_display - $start + 1, 2, 1);
         $header_num = 1;
         echo Search::showNewLine($output_type);
         echo Search::showHeaderItem($output_type, $LANG['document'][14], $header_num);
         if ($view_entities) {
             echo Search::showHeaderItem($output_type, $LANG['entity'][0], $header_num);
         }
         echo Search::showHeaderItem($output_type, $LANG['stats'][13], $header_num);
         echo Search::showEndLine($output_type);
         $DB->data_seek($result, $start);
         $i = $start;
         if (isset($_GET['export_all'])) {
             $start = 0;
         }
         for ($i = $start; $i < $numrows && $i < $end_display; $i++) {
             $item_num = 1;
             // Get data and increment loop variables
             $data = $DB->fetch_assoc($result);
             if (!class_exists($data["itemtype"])) {
                 continue;
             }
             $item = new $data["itemtype"]();
             if ($item->getFromDB($data["items_id"])) {
                 echo Search::showNewLine($output_type, $i % 2);
                 echo Search::showItem($output_type, $item->getTypeName() . " - " . $item->getLink(), $item_num, $i - $start + 1, "class='center'" . " " . ($item->isDeleted() ? " class='deleted' " : ""));
                 if ($view_entities) {
                     $ent = $item->getEntityID();
                     if ($ent == 0) {
                         $ent = $LANG['entity'][2];
                     } else {
                         $ent = $entities[$ent]['completename'];
                     }
                     echo Search::showItem($output_type, $ent, $item_num, $i - $start + 1, "class='center'" . " " . ($item->isDeleted() ? " class='deleted' " : ""));
                 }
                 echo Search::showItem($output_type, $data["NB"], $item_num, $i - $start + 1, "class='center'" . " " . ($item->isDeleted() ? " class='deleted' " : ""));
             }
         }
         echo Search::showFooter($output_type);
         if ($output_type == HTML_OUTPUT) {
             echo "</div>";
         }
     }
 }
function glpiuImportPrinters($mode, $start = 0)
{
    global $PRINTERSLIST, $UC_OCSIDS, $UC_NAMES, $CFG_GLPI, $LANG;
    $DBocs = new DBocs($_SESSION["ocsservers_id"]);
    $DB = new DB();
    $noPort = 0;
    $numrows = 0;
    $UC_OCSIDS = array();
    // Correspondance UC ocs/glpi
    // Recherche les ports
    $query_ports = "select distinct hardware.NAME as UC_Name, hardware.DEVICEID, printers.NAME, printers.PORT, printers.DRIVER from printers " . "inner join hardware on hardware.ID = printers.HARDWARE_ID  where  printers.DRIVER <> '' order by hardware.DEVICEID, printers.NAME, printers.PORT, printers.DRIVER";
    $result_ports = $DBocs->query($query_ports) or die($DBocs->error());
    if ($DBocs->numrows($result_ports) > 0) {
        // Récupère les UC dans GLPI
        $query_UC = "select distinct glpi_id, ocs_id from glpi_ocs_link order by glpi_id";
        $result_UC = $DB->query($query_UC) or die($DB->error());
        if ($DB->numrows($result_UC) > 0) {
            while ($data = $DB->fetch_array($result_UC)) {
                $UC_OCSIDS[$data["ocs_id"]] = array('glpi_id' => $data["glpi_id"], 'UC_Name' => '', 'driver' => '');
            }
        }
        unset($result_UC);
        // Recherche les UC liés à une imprimante dans OCS
        $query_UC = "select distinct hardware.NAME as UC_Name, hardware.ID as ocs_id from hardware " . "inner join printers on printers.HARDWARE_ID = hardware.ID order by hardware.DEVICEID, hardware.NAME";
        $result_UC = $DBocs->query($query_UC) or die($DBocs->error());
        if ($DBocs->numrows($result_UC) > 0) {
            while ($data = $DBocs->fetch_array($result_UC)) {
                if (array_key_exists($data["ocs_id"], $UC_OCSIDS)) {
                    $UC_OCSIDS[$data["ocs_id"]]['UC_Name'] = strtoupper($data["UC_Name"]);
                }
            }
        }
        unset($result_UC);
        // Suppression des UC sans imprimante
        // création d'une table des UC avec nom pour clé
        foreach ($UC_OCSIDS as $ocs_id => &$item) {
            if ($item['UC_Name'] === '') {
                unset($UC_OCSIDS[$ocs_id]);
            } else {
                $UC_NAMES[$item['UC_Name']] = array('glpi_id' => $item["glpi_id"], 'ocs_id' => $ocs_id);
            }
        }
        unset($UC_OCSIDS);
        // Création des imprimantes
        while ($data = $DBocs->fetch_array($result_ports)) {
            glpiuInsertPrinter($data["PORT"], $data["NAME"], $data["UC_Name"], $data["DRIVER"]);
        }
        unset($result_ports);
        unset($UC_NAMES);
        // Si en mode action, suppression des imprimantes
        /*if ($mode == 1 && count($PRINTERSLIST) > 0)
        		{
        		processObjects(PRINTER_TYPE, DELETE_ACTION);
        		}*/
        // Récupère les imprimantes dans GLPI
        $printer_names = array();
        if (count($PRINTERSLIST) > 0) {
            $query_PRN = "select distinct ID, name from glpi_printers where deleted='0' ";
            $result_PRN = $DB->query($query_PRN) or die($DB->error());
            if ($DB->numrows($result_PRN) > 0) {
                while ($data = $DB->fetch_array($result_PRN)) {
                    $printer_names[$data["name"]] = $data["ID"];
                }
            }
        }
        // Complétion des imprimantes et suppression de celles à ne pas importer
        $numrows = 0;
        foreach ($PRINTERSLIST as $prn_no => &$printer) {
            if ($printer->portType <= PORT_TYPE_USB) {
                $printer->getName();
                if ($printer->server != '' && !isset($printer_names[$printer->name])) {
                    $numrows++;
                } else {
                    unset($PRINTERSLIST[$prn_no]);
                }
            } else {
                unset($PRINTERSLIST[$prn_no]);
            }
        }
        unset($printer_names);
        // Importation
        if ($mode == 1 && isset($_POST['toimport'])) {
            foreach ($_POST['toimport'] as $prn_no => $val) {
                if ($val == "on") {
                    $PRINTERSLIST[$prn_no]->addToDB();
                    unset($PRINTERSLIST[$prn_no]);
                    $numrows--;
                }
            }
        }
        unset($_POST['toimport']);
        // Affichage
        echo "<div align='center'>";
        if ($numrows) {
            $readOnly = !haveRight("ocsng", "w");
            $parameters = "objectType=" . PRINTER_TYPE . "&amp;actionId=" . IMPORT_PRINTERS_ACTION;
            printPager($start, $numrows, $_SERVER["PHP_SELF"], $parameters);
            // delete end
            array_splice($PRINTERSLIST, $start + $_SESSION["glpilist_limit"]);
            // delete begin
            if ($start > 0) {
                array_splice($PRINTERSLIST, 0, $start);
            }
            echo "<form method='post' name='printer_form' id='printer_form' action='" . $_SERVER["PHP_SELF"] . "'>";
            echo "<a href='" . $_SERVER["PHP_SELF"] . "' onclick= \"if ( markAllRows('printer_form') ) return false;\">" . $LANG["buttons"][18] . "</a>&nbsp;/&nbsp;<a href='" . $_SERVER["PHP_SELF"] . "' onclick= \"if ( unMarkAllRows('printer_form') ) return false;\">" . $LANG["buttons"][19] . "</a>";
            echo "<input type='hidden' name='objectType' value='" . PRINTER_TYPE . "'>";
            echo "<input type='hidden' name='actionId' value='" . IMPORT_PRINTERS_ACTION . "'>";
            echo "<table class='tab_cadre'>";
            if (!$readOnly) {
                echo "<tr class='tab_bg_1'><th colspan=8><input class='submit' type='submit' name='do_action' value='" . $LANG["buttons"][37] . "'></th></tr>" . chr(10);
            }
            echo '<tr><th></th><th>Type</th><th>IP</th><th>Nom</th><th width="150px">Port</th><th>Serveurs</th><th>Files d\'impression</th><th>Erreurs</th></tr>' . chr(10);
            foreach ($PRINTERSLIST as &$printer) {
                $printer->display();
            }
            if (!$readOnly) {
                echo "<tr class='tab_bg_1'><th colspan=8><input  class='submit' type='submit' name='do_action' value='" . $LANG["buttons"][37] . "'></th></tr>" . chr(10);
            }
            echo "</table>";
            //echo '<br>'.$numrows.'<br>';
            echo "</form>";
            printPager($start, $numrows, $_SERVER["PHP_SELF"], $parameters);
        } else {
            echo "<strong>" . $LANG["ocsng"][9] . "<br>";
            echo "<a href='../index.php'>" . $LANG["buttons"][13] . "</a></strong>";
        }
        echo "</div>";
    }
    return $numrows;
}
 /**
     * Generic Search and list function
     *
     * Build the query, make the search and list items after a search.
     *
     * @param $itemtype item type
     * @param $params parameters array may include field, contains, searchtype, sort, order, start,
                      deleted, link, link2, contains2, field2, itemtype2, searchtype2
     *
     * @return Nothing (display)
    **/
 static function showList($itemtype, $params)
 {
     global $DB, $CFG_GLPI, $LANG;
     // Instanciate an object to access method
     $item = NULL;
     if ($itemtype != 'States' && class_exists($itemtype)) {
         $item = new $itemtype();
     }
     // Default values of parameters
     $p['link'] = array();
     //
     $p['field'] = array();
     //
     $p['contains'] = array();
     //
     $p['searchtype'] = array();
     //
     $p['sort'] = '1';
     //
     $p['order'] = 'ASC';
     //
     $p['start'] = 0;
     //
     $p['is_deleted'] = 0;
     $p['export_all'] = 0;
     $p['link2'] = '';
     //
     $p['contains2'] = '';
     //
     $p['field2'] = '';
     //
     $p['itemtype2'] = '';
     $p['searchtype2'] = '';
     foreach ($params as $key => $val) {
         $p[$key] = $val;
     }
     if ($p['export_all']) {
         $p['start'] = 0;
     }
     // Manage defautll seachtype value : for bookmark compatibility
     if (count($p['contains'])) {
         foreach ($p['contains'] as $key => $val) {
             if (!isset($p['searchtype'][$key])) {
                 $p['searchtype'][$key] = 'contains';
             }
         }
     }
     if (is_array($p['contains2']) && count($p['contains2'])) {
         foreach ($p['contains2'] as $key => $val) {
             if (!isset($p['searchtype2'][$key])) {
                 $p['searchtype2'][$key] = 'contains';
             }
         }
     }
     $target = getItemTypeSearchURL($itemtype);
     $limitsearchopt = self::getCleanedOptions($itemtype);
     if (isset($CFG_GLPI['union_search_type'][$itemtype])) {
         $itemtable = $CFG_GLPI['union_search_type'][$itemtype];
     } else {
         $itemtable = getTableForItemType($itemtype);
     }
     $LIST_LIMIT = $_SESSION['glpilist_limit'];
     // Set display type for export if define
     $output_type = HTML_OUTPUT;
     if (isset($_GET['display_type'])) {
         $output_type = $_GET['display_type'];
         // Limit to 10 element
         if ($_GET['display_type'] == GLOBAL_SEARCH) {
             $LIST_LIMIT = GLOBAL_SEARCH_DISPLAY_COUNT;
         }
     }
     // hack for States
     if (isset($CFG_GLPI['union_search_type'][$itemtype])) {
         $entity_restrict = true;
     } else {
         $entity_restrict = $item->isEntityAssign();
     }
     $metanames = array();
     // Get the items to display
     $toview = self::addDefaultToView($itemtype);
     // Add items to display depending of personal prefs
     $displaypref = DisplayPreference::getForTypeUser($itemtype, getLoginUserID());
     if (count($displaypref)) {
         foreach ($displaypref as $val) {
             array_push($toview, $val);
         }
     }
     // Add searched items
     if (count($p['field']) > 0) {
         foreach ($p['field'] as $key => $val) {
             if (!in_array($val, $toview) && $val != 'all' && $val != 'view') {
                 array_push($toview, $val);
             }
         }
     }
     // Add order item
     if (!in_array($p['sort'], $toview)) {
         array_push($toview, $p['sort']);
     }
     // Special case for Ticket : put ID in front
     if ($itemtype == 'Ticket') {
         array_unshift($toview, 2);
     }
     // Clean toview array
     $toview = array_unique($toview);
     foreach ($toview as $key => $val) {
         if (!isset($limitsearchopt[$val])) {
             unset($toview[$key]);
         }
     }
     $toview_count = count($toview);
     // Construct the request
     //// 1 - SELECT
     // request currentuser for SQL supervision, not displayed
     $SELECT = "SELECT '" . $_SESSION['glpiname'] . "' AS currentuser, " . self::addDefaultSelect($itemtype);
     // Add select for all toview item
     foreach ($toview as $key => $val) {
         $SELECT .= self::addSelect($itemtype, $val, $key, 0);
     }
     //// 2 - FROM AND LEFT JOIN
     // Set reference table
     $FROM = " FROM `{$itemtable}`";
     // Init already linked tables array in order not to link a table several times
     $already_link_tables = array();
     // Put reference table
     array_push($already_link_tables, $itemtable);
     // Add default join
     $COMMONLEFTJOIN = self::addDefaultJoin($itemtype, $itemtable, $already_link_tables);
     $FROM .= $COMMONLEFTJOIN;
     $searchopt = array();
     $searchopt[$itemtype] =& self::getOptions($itemtype);
     // Add all table for toview items
     foreach ($toview as $key => $val) {
         $FROM .= self::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$val]["table"], $searchopt[$itemtype][$val]["linkfield"], 0, 0, $searchopt[$itemtype][$val]["joinparams"]);
     }
     // Search all case :
     if (in_array("all", $p['field'])) {
         foreach ($searchopt[$itemtype] as $key => $val) {
             // Do not search on Group Name
             if (is_array($val)) {
                 $FROM .= self::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$key]["table"], $searchopt[$itemtype][$key]["linkfield"], 0, 0, $searchopt[$itemtype][$key]["joinparams"]);
             }
         }
     }
     //// 3 - WHERE
     // default string
     $COMMONWHERE = self::addDefaultWhere($itemtype);
     $first = empty($COMMONWHERE);
     // Add deleted if item have it
     if ($item && $item->maybeDeleted()) {
         $LINK = " AND ";
         if ($first) {
             $LINK = " ";
             $first = false;
         }
         $COMMONWHERE .= $LINK . "`{$itemtable}`.`is_deleted` = '" . $p['is_deleted'] . "' ";
     }
     // Remove template items
     if ($item && $item->maybeTemplate()) {
         $LINK = " AND ";
         if ($first) {
             $LINK = " ";
             $first = false;
         }
         $COMMONWHERE .= $LINK . "`{$itemtable}`.`is_template` = '0' ";
     }
     // Add Restrict to current entities
     if ($entity_restrict) {
         $LINK = " AND ";
         if ($first) {
             $LINK = " ";
             $first = false;
         }
         if ($itemtype == 'Entity') {
             $COMMONWHERE .= getEntitiesRestrictRequest($LINK, $itemtable, 'id', '', true);
         } else {
             if (isset($CFG_GLPI["union_search_type"][$itemtype])) {
                 // Will be replace below in Union/Recursivity Hack
                 $COMMONWHERE .= $LINK . " ENTITYRESTRICT ";
             } else {
                 $COMMONWHERE .= getEntitiesRestrictRequest($LINK, $itemtable, '', '', $item->maybeRecursive());
             }
         }
     }
     $WHERE = "";
     $HAVING = "";
     // Add search conditions
     // If there is search items
     if ($_SESSION["glpisearchcount"][$itemtype] > 0 && count($p['contains']) > 0) {
         for ($key = 0; $key < $_SESSION["glpisearchcount"][$itemtype]; $key++) {
             // if real search (strlen >0) and not all and view search
             if (isset($p['contains'][$key]) && strlen($p['contains'][$key]) > 0) {
                 // common search
                 if ($p['field'][$key] != "all" && $p['field'][$key] != "view") {
                     $LINK = " ";
                     $NOT = 0;
                     $tmplink = "";
                     if (is_array($p['link']) && isset($p['link'][$key])) {
                         if (strstr($p['link'][$key], "NOT")) {
                             $tmplink = " " . str_replace(" NOT", "", $p['link'][$key]);
                             $NOT = 1;
                         } else {
                             $tmplink = " " . $p['link'][$key];
                         }
                     } else {
                         $tmplink = " AND ";
                     }
                     if (isset($searchopt[$itemtype][$p['field'][$key]]["usehaving"])) {
                         // Manage Link if not first item
                         if (!empty($HAVING)) {
                             $LINK = $tmplink;
                         }
                         // Find key
                         $item_num = array_search($p['field'][$key], $toview);
                         $HAVING .= self::addHaving($LINK, $NOT, $itemtype, $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key], 0, $item_num);
                     } else {
                         // Manage Link if not first item
                         if (!empty($WHERE)) {
                             $LINK = $tmplink;
                         }
                         $WHERE .= self::addWhere($LINK, $NOT, $itemtype, $p['field'][$key], $p['searchtype'][$key], $p['contains'][$key]);
                     }
                     // view and all search
                 } else {
                     $LINK = " OR ";
                     $NOT = 0;
                     $globallink = " AND ";
                     if (is_array($p['link']) && isset($p['link'][$key])) {
                         switch ($p['link'][$key]) {
                             case "AND":
                                 $LINK = " OR ";
                                 $globallink = " AND ";
                                 break;
                             case "AND NOT":
                                 $LINK = " AND ";
                                 $NOT = 1;
                                 $globallink = " AND ";
                                 break;
                             case "OR":
                                 $LINK = " OR ";
                                 $globallink = " OR ";
                                 break;
                             case "OR NOT":
                                 $LINK = " AND ";
                                 $NOT = 1;
                                 $globallink = " OR ";
                                 break;
                         }
                     } else {
                         $tmplink = "  AND ";
                     }
                     // Manage Link if not first item
                     if (!empty($WHERE)) {
                         $WHERE .= $globallink;
                     }
                     $WHERE .= " ( ";
                     $first2 = true;
                     $items = array();
                     if ($p['field'][$key] == "all") {
                         $items = $searchopt[$itemtype];
                     } else {
                         // toview case : populate toview
                         foreach ($toview as $key2 => $val2) {
                             $items[$val2] = $searchopt[$itemtype][$val2];
                         }
                     }
                     foreach ($items as $key2 => $val2) {
                         if (is_array($val2)) {
                             // Add Where clause if not to be done in HAVING CLAUSE
                             if (!isset($val2["usehaving"])) {
                                 $tmplink = $LINK;
                                 if ($first2) {
                                     $tmplink = " ";
                                     $first2 = false;
                                 }
                                 $WHERE .= self::addWhere($tmplink, $NOT, $itemtype, $key2, $p['searchtype'][$key], $p['contains'][$key]);
                             }
                         }
                     }
                     $WHERE .= " ) ";
                 }
             }
         }
     }
     //// 4 - ORDER
     $ORDER = " ORDER BY `id` ";
     foreach ($toview as $key => $val) {
         if ($p['sort'] == $val) {
             $ORDER = self::addOrderBy($itemtype, $p['sort'], $p['order'], $key);
         }
     }
     //// 5 - META SEARCH
     // Preprocessing
     if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) {
         // a - SELECT
         for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) {
             if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) {
                 $SELECT .= self::addSelect($p['itemtype2'][$i], $p['field2'][$i], $i, 1, $p['itemtype2'][$i]);
             }
         }
         // b - ADD LEFT JOIN
         // Already link meta table in order not to linked a table several times
         $already_link_tables2 = array();
         // Link reference tables
         for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) {
             if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) {
                 if (!in_array(getTableForItemType($p['itemtype2'][$i]), $already_link_tables2)) {
                     $FROM .= self::addMetaLeftJoin($itemtype, $p['itemtype2'][$i], $already_link_tables2, $p['contains2'][$i] == "NULL" || strstr($p['link2'][$i], "NOT"));
                 }
             }
         }
         // Link items tables
         for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) {
             if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) {
                 if (!isset($searchopt[$p['itemtype2'][$i]])) {
                     $searchopt[$p['itemtype2'][$i]] =& self::getOptions($p['itemtype2'][$i]);
                 }
                 if (!in_array($searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["table"] . "_" . $p['itemtype2'][$i], $already_link_tables2)) {
                     $FROM .= self::addLeftJoin($p['itemtype2'][$i], getTableForItemType($p['itemtype2'][$i]), $already_link_tables2, $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["table"], $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["linkfield"], 1, $p['itemtype2'][$i], $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["joinparams"]);
                 }
             }
         }
     }
     //// 6 - Add item ID
     // Add ID to the select
     if (!empty($itemtable)) {
         $SELECT .= "`{$itemtable}`.`id` AS id ";
     }
     //// 7 - Manage GROUP BY
     $GROUPBY = "";
     // Meta Search / Search All / Count tickets
     if ($_SESSION["glpisearchcount2"][$itemtype] > 0 || !empty($HAVING) || in_array('all', $p['field'])) {
         $GROUPBY = " GROUP BY `{$itemtable}`.`id`";
     }
     if (empty($GROUPBY)) {
         foreach ($toview as $key2 => $val2) {
             if (!empty($GROUPBY)) {
                 break;
             }
             if (isset($searchopt[$itemtype][$val2]["forcegroupby"])) {
                 $GROUPBY = " GROUP BY `{$itemtable}`.`id`";
             }
         }
     }
     // Specific search for others item linked  (META search)
     if (is_array($p['itemtype2'])) {
         for ($key = 0; $key < $_SESSION["glpisearchcount2"][$itemtype]; $key++) {
             if (isset($p['itemtype2'][$key]) && !empty($p['itemtype2'][$key]) && isset($p['contains2'][$key]) && strlen($p['contains2'][$key]) > 0) {
                 $LINK = "";
                 // For AND NOT statement need to take into account all the group by items
                 if (strstr($p['link2'][$key], "AND NOT") || isset($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["usehaving"])) {
                     $NOT = 0;
                     if (strstr($p['link2'][$key], "NOT")) {
                         $tmplink = " " . str_replace(" NOT", "", $p['link2'][$key]);
                         $NOT = 1;
                     } else {
                         $tmplink = " " . $p['link2'][$key];
                     }
                     if (!empty($HAVING)) {
                         $LINK = $tmplink;
                     }
                     $HAVING .= self::addHaving($LINK, $NOT, $p['itemtype2'][$key], $p['field2'][$key], $p['searchtype2'][$key], $p['contains2'][$key], 1, $key);
                 } else {
                     // Meta Where Search
                     $LINK = " ";
                     $NOT = 0;
                     // Manage Link if not first item
                     if (is_array($p['link2']) && isset($p['link2'][$key]) && strstr($p['link2'][$key], "NOT")) {
                         $tmplink = " " . str_replace(" NOT", "", $p['link2'][$key]);
                         $NOT = 1;
                     } else {
                         if (is_array($p['link2']) && isset($p['link2'][$key])) {
                             $tmplink = " " . $p['link2'][$key];
                         } else {
                             $tmplink = " AND ";
                         }
                     }
                     if (!empty($WHERE)) {
                         $LINK = $tmplink;
                     }
                     $WHERE .= self::addWhere($LINK, $NOT, $p['itemtype2'][$key], $p['field2'][$key], $p['searchtype2'][$key], $p['contains2'][$key], 1);
                 }
             }
         }
     }
     // Use a ReadOnly connection if available and configured to be used
     $DBread = DBConnection::getReadConnection();
     // If no research limit research to display item and compute number of item using simple request
     $nosearch = true;
     for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) {
         if (isset($p['contains'][$i]) && strlen($p['contains'][$i]) > 0) {
             $nosearch = false;
         }
     }
     if ($_SESSION["glpisearchcount2"][$itemtype] > 0) {
         $nosearch = false;
     }
     $LIMIT = "";
     $numrows = 0;
     //No search : count number of items using a simple count(ID) request and LIMIT search
     if ($nosearch) {
         $LIMIT = " LIMIT " . $p['start'] . ", " . $LIST_LIMIT;
         // Force group by for all the type -> need to count only on table ID
         if (!isset($searchopt[$itemtype][1]['forcegroupby'])) {
             $count = "count(*)";
         } else {
             $count = "count(DISTINCT `{$itemtable}`.`id`)";
         }
         // request currentuser for SQL supervision, not displayed
         $query_num = "SELECT {$count}, '" . $_SESSION['glpiname'] . "' AS currentuser\n                       FROM `{$itemtable}`" . $COMMONLEFTJOIN;
         $first = true;
         if (!empty($COMMONWHERE)) {
             $LINK = " AND ";
             if ($first) {
                 $LINK = " WHERE ";
                 $first = false;
             }
             $query_num .= $LINK . $COMMONWHERE;
         }
         // Union Search :
         if (isset($CFG_GLPI["union_search_type"][$itemtype])) {
             $tmpquery = $query_num;
             $numrows = 0;
             foreach ($CFG_GLPI[$CFG_GLPI["union_search_type"][$itemtype]] as $ctype) {
                 $ctable = getTableForItemType($ctype);
                 $citem = new $ctype();
                 if ($citem->canView()) {
                     // State case
                     if ($itemtype == 'States') {
                         $query_num = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery);
                         $query_num .= " AND {$ctable}.`states_id` > '0' ";
                         // Add deleted if item have it
                         if ($citem && $citem->maybeDeleted()) {
                             $query_num .= " AND `{$ctable}`.`is_deleted` = '0' ";
                         }
                         // Remove template items
                         if ($citem && $citem->maybeTemplate()) {
                             $query_num .= " AND `{$ctable}`.`is_template` = '0' ";
                         }
                     } else {
                         // Ref table case
                         $reftable = getTableForItemType($itemtype);
                         $replace = "FROM `{$reftable}`\n                                  INNER JOIN `{$ctable}`\n                                       ON (`{$reftable}`.`items_id` =`{$ctable}`.`id`\n                                           AND `{$reftable}`.`itemtype` = '{$ctype}')";
                         $query_num = str_replace("FROM `" . $CFG_GLPI["union_search_type"][$itemtype] . "`", $replace, $tmpquery);
                         $query_num = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $query_num);
                     }
                     $query_num = str_replace("ENTITYRESTRICT", getEntitiesRestrictRequest('', $ctable, '', '', $citem->maybeRecursive()), $query_num);
                     $result_num = $DBread->query($query_num);
                     $numrows += $DBread->result($result_num, 0, 0);
                 }
             }
         } else {
             $result_num = $DBread->query($query_num);
             $numrows = $DBread->result($result_num, 0, 0);
         }
     }
     // If export_all reset LIMIT condition
     if ($p['export_all']) {
         $LIMIT = "";
     }
     if (!empty($WHERE) || !empty($COMMONWHERE)) {
         if (!empty($COMMONWHERE)) {
             $WHERE = ' WHERE ' . $COMMONWHERE . (!empty($WHERE) ? ' AND ( ' . $WHERE . ' )' : '');
         } else {
             $WHERE = ' WHERE ' . $WHERE . ' ';
         }
         $first = false;
     }
     if (!empty($HAVING)) {
         $HAVING = ' HAVING ' . $HAVING;
     }
     // Create QUERY
     if (isset($CFG_GLPI["union_search_type"][$itemtype])) {
         $first = true;
         $QUERY = "";
         foreach ($CFG_GLPI[$CFG_GLPI["union_search_type"][$itemtype]] as $ctype) {
             $ctable = getTableForItemType($ctype);
             $citem = new $ctype();
             if ($citem->canView()) {
                 if ($first) {
                     $first = false;
                 } else {
                     $QUERY .= " UNION ";
                 }
                 $tmpquery = "";
                 // State case
                 if ($itemtype == 'States') {
                     $tmpquery = $SELECT . ", '{$ctype}' AS TYPE " . $FROM . $WHERE;
                     $tmpquery = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery);
                     $tmpquery .= " AND `{$ctable}`.`states_id` > '0' ";
                     // Add deleted if item have it
                     if ($citem && $citem->maybeDeleted()) {
                         $tmpquery .= " AND `{$ctable}`.`is_deleted` = '0' ";
                     }
                     // Remove template items
                     if ($citem && $citem->maybeTemplate()) {
                         $tmpquery .= " AND `{$ctable}`.`is_template` = '0' ";
                     }
                 } else {
                     // Ref table case
                     $reftable = getTableForItemType($itemtype);
                     $tmpquery = $SELECT . ", '{$ctype}' AS TYPE,\n                                      `{$reftable}`.`id` AS refID, " . "\n                                      `{$ctable}`.`entities_id` AS ENTITY " . $FROM . $WHERE;
                     $replace = "FROM `{$reftable}`" . "\n                              INNER JOIN `{$ctable}`" . "\n                                 ON (`{$reftable}`.`items_id`=`{$ctable}`.`id`" . "\n                                     AND `{$reftable}`.`itemtype` = '{$ctype}')";
                     $tmpquery = str_replace("FROM `" . $CFG_GLPI["union_search_type"][$itemtype] . "`", $replace, $tmpquery);
                     $tmpquery = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery);
                 }
                 $tmpquery = str_replace("ENTITYRESTRICT", getEntitiesRestrictRequest('', $ctable, '', '', $citem->maybeRecursive()), $tmpquery);
                 // SOFTWARE HACK
                 if ($ctype == 'Software') {
                     $tmpquery = str_replace("glpi_softwares.serial", "''", $tmpquery);
                     $tmpquery = str_replace("glpi_softwares.otherserial", "''", $tmpquery);
                 }
                 $QUERY .= $tmpquery;
             }
         }
         if (empty($QUERY)) {
             echo self::showError($output_type);
             return;
         }
         $QUERY .= str_replace($CFG_GLPI["union_search_type"][$itemtype] . ".", "", $ORDER) . $LIMIT;
     } else {
         $QUERY = $SELECT . $FROM . $WHERE . $GROUPBY . $HAVING . $ORDER . $LIMIT;
     }
     $DBread->query("SET SESSION group_concat_max_len = 4096;");
     $result = $DBread->query($QUERY);
     /// Check group concat limit : if warning : increase limit
     if ($result2 = $DBread->query('SHOW WARNINGS')) {
         if ($DBread->numrows($result2) > 0) {
             $data = $DBread->fetch_assoc($result2);
             if ($data['Code'] == 1260) {
                 $DBread->query("SET SESSION group_concat_max_len = 4194304;");
                 $result = $DBread->query($QUERY);
             }
         }
     }
     // Get it from database and DISPLAY
     if ($result) {
         // if real search or complete export : get numrows from request
         if (!$nosearch || $p['export_all']) {
             $numrows = $DBread->numrows($result);
         }
         // Contruct Pager parameters
         $globallinkto = self::getArrayUrlLink("field", $p['field']) . self::getArrayUrlLink("link", $p['link']) . self::getArrayUrlLink("contains", $p['contains']) . self::getArrayUrlLink("searchtype", $p['searchtype']) . self::getArrayUrlLink("field2", $p['field2']) . self::getArrayUrlLink("contains2", $p['contains2']) . self::getArrayUrlLink("itemtype2", $p['itemtype2']) . self::getArrayUrlLink("searchtype2", $p['searchtype2']) . self::getArrayUrlLink("link2", $p['link2']);
         $parameters = "sort=" . $p['sort'] . "&amp;order=" . $p['order'] . $globallinkto;
         // Not more used : clean pages : try to comment it
         /*
         $tmp=explode('?',$target,2);
         if (count($tmp)>1) {
            $target = $tmp[0];
            $parameters = $tmp[1].'&amp;'.$parameters;
         }
         */
         if ($output_type == GLOBAL_SEARCH) {
             if (class_exists($itemtype)) {
                 echo "<div class='center'><h2>" . $item->getTypeName();
                 // More items
                 if ($numrows > $p['start'] + GLOBAL_SEARCH_DISPLAY_COUNT) {
                     echo " <a href='{$target}?{$parameters}'>" . $LANG['common'][66] . "</a>";
                 }
                 echo "</h2></div>\n";
             } else {
                 return false;
             }
         }
         // If the begin of the view is before the number of items
         if ($p['start'] < $numrows) {
             // Display pager only for HTML
             if ($output_type == HTML_OUTPUT) {
                 // For plugin add new parameter if available
                 if ($plug = isPluginItemType($itemtype)) {
                     $function = 'plugin_' . $plug['plugin'] . '_addParamFordynamicReport';
                     if (function_exists($function)) {
                         $out = $function($itemtype);
                         if (is_array($out) && count($out)) {
                             foreach ($out as $key => $val) {
                                 if (is_array($val)) {
                                     $parameters .= self::getArrayUrlLink($key, $val);
                                 } else {
                                     $parameters .= "&amp;{$key}={$val}";
                                 }
                             }
                         }
                     }
                 }
                 printPager($p['start'], $numrows, $target, $parameters, $itemtype);
             }
             // Form to massive actions
             $isadmin = $item && $item->canUpdate();
             if (!$isadmin && in_array($itemtype, $CFG_GLPI["infocom_types"])) {
                 $infoc = new Infocom();
                 $isadmin = $infoc->canUpdate() || $infoc->canCreate();
             }
             if ($isadmin && $output_type == HTML_OUTPUT) {
                 echo "<form method='post' name='massiveaction_form' id='massiveaction_form' action=\"" . $CFG_GLPI["root_doc"] . "/front/massiveaction.php\">";
             }
             // Compute number of columns to display
             // Add toview elements
             $nbcols = $toview_count;
             $already_printed = array();
             // Add meta search elements if real search (strlen>0) or only NOT search
             if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) {
                 for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) {
                     if (isset($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0 && !empty($p['itemtype2'][$i]) && (!isset($p['link2'][$i]) || !strstr($p['link2'][$i], "NOT"))) {
                         if (!isset($already_printed[$p['itemtype2'][$i] . $p['field2'][$i]])) {
                             $nbcols++;
                             $already_printed[$p['itemtype2'][$i] . $p['field2'][$i]] = 1;
                         }
                     }
                 }
             }
             if ($output_type == HTML_OUTPUT) {
                 // HTML display - massive modif
                 $nbcols++;
             }
             // Define begin and end var for loop
             // Search case
             $begin_display = $p['start'];
             $end_display = $p['start'] + $LIST_LIMIT;
             // No search Case
             if ($nosearch) {
                 $begin_display = 0;
                 $end_display = min($numrows - $p['start'], $LIST_LIMIT);
             }
             // Export All case
             if ($p['export_all']) {
                 $begin_display = 0;
                 $end_display = $numrows;
             }
             // Display List Header
             echo self::showHeader($output_type, $end_display - $begin_display + 1, $nbcols);
             // New Line for Header Items Line
             echo self::showNewLine($output_type);
             $header_num = 1;
             if ($output_type == HTML_OUTPUT) {
                 // HTML display - massive modif
                 $search_config = "";
                 if (haveRight("search_config", "w") || haveRight("search_config_global", "w")) {
                     $tmp = " class='pointer' onClick=\"var w = window.open('" . $CFG_GLPI["root_doc"] . "/front/popup.php?popup=search_config&amp;itemtype={$itemtype}' ,'glpipopup', " . "'height=400, width=1000, top=100, left=100, scrollbars=yes'); w.focus();\"";
                     $search_config = "<img alt=\"" . $LANG['setup'][252] . "\" title=\"" . $LANG['setup'][252] . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' ";
                     $search_config .= $tmp . ">";
                 }
                 echo self::showHeaderItem($output_type, $search_config, $header_num, "", 0, $p['order']);
             }
             // Display column Headers for toview items
             foreach ($toview as $key => $val) {
                 $linkto = '';
                 if (!isset($searchopt[$itemtype][$val]['nosort']) || !$searchopt[$itemtype][$val]['nosort']) {
                     $linkto = "{$target}?itemtype={$itemtype}&amp;sort=" . $val . "&amp;order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&amp;start=" . $p['start'] . $globallinkto;
                 }
                 echo self::showHeaderItem($output_type, $searchopt[$itemtype][$val]["name"], $header_num, $linkto, $p['sort'] == $val, $p['order']);
             }
             // Display columns Headers for meta items
             $already_printed = array();
             if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) {
                 for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) {
                     if (isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0) {
                         if (!isset($already_printed[$p['itemtype2'][$i] . $p['field2'][$i]])) {
                             if (!isset($metanames[$p['itemtype2'][$i]])) {
                                 $metaitem = new $p['itemtype2'][$i]();
                                 $metanames[$p['itemtype2'][$i]] = $metaitem->getTypeName();
                             }
                             echo self::showHeaderItem($output_type, $metanames[$p['itemtype2'][$i]] . " - " . $searchopt[$p['itemtype2'][$i]][$p['field2'][$i]]["name"], $header_num);
                             $already_printed[$p['itemtype2'][$i] . $p['field2'][$i]] = 1;
                         }
                     }
                 }
             }
             // Add specific column Header
             if ($itemtype == 'CartridgeItem') {
                 echo self::showHeaderItem($output_type, $LANG['cartridges'][0], $header_num);
             }
             if ($itemtype == 'ConsumableItem') {
                 echo self::showHeaderItem($output_type, $LANG['consumables'][0], $header_num);
             }
             if ($itemtype == 'States' || $itemtype == 'ReservationItem') {
                 echo self::showHeaderItem($output_type, $LANG['state'][6], $header_num);
             }
             if ($itemtype == 'ReservationItem' && $output_type == HTML_OUTPUT) {
                 if (haveRight("reservation_central", "w")) {
                     echo self::showHeaderItem($output_type, $LANG['reservation'][4], $header_num);
                     echo self::showHeaderItem($output_type, "&nbsp;", $header_num);
                 }
                 echo self::showHeaderItem($output_type, "&nbsp;", $header_num);
             }
             // End Line for column headers
             echo self::showEndLine($output_type);
             // if real search seek to begin of items to display (because of complete search)
             if (!$nosearch) {
                 $DBread->data_seek($result, $p['start']);
             }
             // Define begin and end var for loop
             // Search case
             $i = $begin_display;
             // Init list of items displayed
             if ($output_type == HTML_OUTPUT) {
                 initNavigateListItems($itemtype);
             }
             // Num of the row (1=header_line)
             $row_num = 1;
             // Display Loop
             while ($i < $numrows && $i < $end_display) {
                 // Column num
                 $item_num = 1;
                 // Get data and increment loop variables
                 $data = $DBread->fetch_assoc($result);
                 $i++;
                 $row_num++;
                 // New line
                 echo self::showNewLine($output_type, $i % 2, $p['is_deleted']);
                 // Add item in item list
                 addToNavigateListItems($itemtype, $data["id"]);
                 if ($output_type == HTML_OUTPUT) {
                     // HTML display - massive modif
                     $tmpcheck = "";
                     if ($isadmin) {
                         if ($itemtype == 'Entity' && !in_array($data["id"], $_SESSION["glpiactiveentities"])) {
                             $tmpcheck = "&nbsp;";
                         } else {
                             if ($item->maybeRecursive() && !in_array($data["entities_id"], $_SESSION["glpiactiveentities"])) {
                                 $tmpcheck = "&nbsp;";
                             } else {
                                 $sel = "";
                                 if (isset($_GET["select"]) && $_GET["select"] == "all") {
                                     $sel = "checked";
                                 }
                                 if (isset($_SESSION['glpimassiveactionselected'][$data["id"]])) {
                                     $sel = "checked";
                                 }
                                 $tmpcheck = "<input type='checkbox' name='item[" . $data["id"] . "]' value='1'\n                                      {$sel}>";
                             }
                         }
                     }
                     echo self::showItem($output_type, $tmpcheck, $item_num, $row_num, "width='10'");
                 }
                 // Print other toview items
                 foreach ($toview as $key => $val) {
                     echo self::showItem($output_type, self::giveItem($itemtype, $val, $data, $key), $item_num, $row_num, self::displayConfigItem($itemtype, $val, $data, $key));
                 }
                 // Print Meta Item
                 $already_printed = array();
                 if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && is_array($p['itemtype2'])) {
                     for ($j = 0; $j < $_SESSION["glpisearchcount2"][$itemtype]; $j++) {
                         if (isset($p['itemtype2'][$j]) && !empty($p['itemtype2'][$j]) && isset($p['contains2'][$j]) && strlen($p['contains2'][$j]) > 0) {
                             if (!isset($already_printed[$p['itemtype2'][$j] . $p['field2'][$j]])) {
                                 // General case
                                 if (strpos($data["META_{$j}"], "\$\$\$\$") === false) {
                                     $out = self::giveItem($p['itemtype2'][$j], $p['field2'][$j], $data, $j, 1);
                                     echo self::showItem($output_type, $out, $item_num, $row_num);
                                     // Case of GROUP_CONCAT item : split item and multilline display
                                 } else {
                                     $split = explode("\$\$\$\$", $data["META_{$j}"]);
                                     $count_display = 0;
                                     $out = "";
                                     $unit = "";
                                     $separate = '<br>';
                                     if (isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['splititems']) && $searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['splititems']) {
                                         $separate = '<hr>';
                                     }
                                     if (isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['unit'])) {
                                         $unit = $searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['unit'];
                                     }
                                     for ($k = 0; $k < count($split); $k++) {
                                         if ($p['contains2'][$j] == "NULL" || strlen($p['contains2'][$j]) == 0 || preg_match('/' . $p['contains2'][$j] . '/i', $split[$k]) || isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['forcegroupby'])) {
                                             if ($count_display) {
                                                 $out .= $separate;
                                             }
                                             $count_display++;
                                             // Manage Link to item
                                             $split2 = explode("\$\$", $split[$k]);
                                             if (isset($split2[1])) {
                                                 $out .= "<a id='" . $p['itemtype2'][$j] . '_' . $data["id"] . '_' . $split2[1] . "' ";
                                                 $out .= "href=\"" . getItemTypeFormURL($p['itemtype2'][$j]) . "?id=" . $p['itemtype2'][$j] . "\">";
                                                 $out .= $split2[0] . $unit;
                                                 if ($_SESSION["glpiis_ids_visible"] || empty($split2[0])) {
                                                     $out .= " (" . $split2[1] . ")";
                                                 }
                                                 $out .= "</a>";
                                             } else {
                                                 $out .= $split[$k] . $unit;
                                             }
                                         }
                                     }
                                     echo self::showItem($output_type, $out, $item_num, $row_num);
                                 }
                                 $already_printed[$p['itemtype2'][$j] . $p['field2'][$j]] = 1;
                             }
                         }
                     }
                 }
                 // Specific column display
                 if ($itemtype == 'CartridgeItem') {
                     echo self::showItem($output_type, Cartridge::getCount($data["id"], $data["ALARM"], $output_type != HTML_OUTPUT), $item_num, $row_num);
                 }
                 if ($itemtype == 'ConsumableItem') {
                     echo self::showItem($output_type, Consumable::getCount($data["id"], $data["ALARM"], $output_type != HTML_OUTPUT), $item_num, $row_num);
                 }
                 if ($itemtype == 'States' || $itemtype == 'ReservationItem') {
                     $typename = $data["TYPE"];
                     if (class_exists($data["TYPE"])) {
                         $itemtmp = new $data["TYPE"]();
                         $typename = $itemtmp->getTypeName();
                     }
                     echo self::showItem($output_type, $typename, $item_num, $row_num);
                 }
                 if ($itemtype == 'ReservationItem' && $output_type == HTML_OUTPUT) {
                     if (haveRight("reservation_central", "w")) {
                         if (!haveAccessToEntity($data["ENTITY"])) {
                             echo self::showItem($output_type, "&nbsp;", $item_num, $row_num);
                             echo self::showItem($output_type, "&nbsp;", $item_num, $row_num);
                         } else {
                             echo self::showItem($output_type, "<a href=\"" . getItemTypeFormURL($itemtype) . "?id=" . $data["refID"] . "&amp;is_active=" . ($data["ACTIVE"] ? 0 : 1) . "&amp;update=update\" " . "title=\"" . ($data["ACTIVE"] ? $LANG['buttons'][42] : $LANG['buttons'][41]) . "\">" . "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($data["ACTIVE"] ? "moins" : "plus") . ".png\" alt=''\n                                                title=''></a>", $item_num, $row_num, "class='center'");
                             echo self::showItem($output_type, "<a href='" . getItemTypeFormURL($itemtype) . "?id=" . $data["refID"] . "&amp;delete=delete' " . addConfirmationOnAction(array($LANG['reservation'][38], $LANG['reservation'][39])) . " title=\"" . $LANG['reservation'][6] . "\">" . "<img src='" . $CFG_GLPI["root_doc"] . "/pics/delete.png'\n                                                alt='' title=''></a>", $item_num, $row_num, "class='center'");
                         }
                     }
                     if ($data["ACTIVE"]) {
                         echo self::showItem($output_type, "<a href='reservation.php?reservationitems_id=" . $data["refID"] . "' title=\"" . $LANG['reservation'][21] . "\">" . "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/reservation-3.png\" alt='' title=''></a>", $item_num, $row_num, "class='center'");
                     } else {
                         echo self::showItem($output_type, "&nbsp;", $item_num, $row_num);
                     }
                 }
                 // End Line
                 echo self::showEndLine($output_type);
             }
             $title = "";
             // Create title
             if ($output_type == PDF_OUTPUT_LANDSCAPE || $output_type == PDF_OUTPUT_PORTRAIT) {
                 if ($_SESSION["glpisearchcount"][$itemtype] > 0 && count($p['contains']) > 0) {
                     for ($key = 0; $key < $_SESSION["glpisearchcount"][$itemtype]; $key++) {
                         if (strlen($p['contains'][$key]) > 0) {
                             if (isset($p["link"][$key])) {
                                 $title .= " " . $p["link"][$key] . " ";
                             }
                             switch ($p['field'][$key]) {
                                 case "all":
                                     $title .= $LANG['common'][66];
                                     break;
                                 case "view":
                                     $title .= $LANG['search'][11];
                                     break;
                                 default:
                                     $title .= $searchopt[$itemtype][$p['field'][$key]]["name"];
                             }
                             switch ($p['searchtype'][$key]) {
                                 case "equals":
                                     if (in_array($searchopt[$itemtype][$p['field'][$key]]["field"], array('name', 'completename'))) {
                                         $title .= ' = ' . Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key]);
                                     } else {
                                         $title .= ' = ' . $p['contains'][$key];
                                     }
                                     break;
                                 case "notequals":
                                     if (in_array($searchopt[$itemtype][$p['field'][$key]]["field"], array('name', 'completename'))) {
                                         $title .= ' <> ' . Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key]);
                                     } else {
                                         $title .= ' <> ' . $p['contains'][$key];
                                     }
                                     break;
                                 case "lessthan":
                                     $title .= ' < ' . $p['contains'][$key];
                                     break;
                                 case "morethan":
                                     $title .= ' > ' . $p['contains'][$key];
                                     break;
                                 case "contains":
                                     $title .= ' = %' . $p['contains'][$key] . '%';
                                     break;
                                 default:
                                     $title .= ' = ' . $p['contains'][$key];
                                     break;
                             }
                         }
                     }
                 }
                 if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && count($p['contains2']) > 0) {
                     for ($key = 0; $key < $_SESSION["glpisearchcount2"][$itemtype]; $key++) {
                         if (strlen($p['contains2'][$key]) > 0) {
                             if (isset($p['link2'][$key])) {
                                 $title .= " " . $p['link2'][$key] . " ";
                             }
                             $title .= $metanames[$p['itemtype2'][$key]] . "/";
                             $title .= $searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["name"];
                             switch ($p['searchtype2'][$key]) {
                                 case "equals":
                                     if (in_array($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["field"], array('name', 'completename'))) {
                                         $title .= ' = ' . Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key]);
                                     } else {
                                         $title .= ' = ' . $p['contains2'][$key];
                                     }
                                     break;
                                 case "notequals":
                                     if (in_array($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["field"], array('name', 'completename'))) {
                                         $title .= ' <> ' . Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key]);
                                     } else {
                                         $title .= ' <> ' . $p['contains2'][$key];
                                     }
                                     break;
                                 case "lessthan":
                                     $title .= ' < ' . $p['contains2'][$key];
                                     break;
                                 case "morethan":
                                     $title .= ' > ' . $p['contains2'][$key];
                                     break;
                                 case "contains":
                                     $title .= ' = %' . $p['contains2'][$key] . '%';
                                     break;
                                 default:
                                     $title .= ' = ' . $p['contains2'][$key];
                                     break;
                             }
                         }
                     }
                 }
             }
             // Display footer
             echo self::showFooter($output_type, $title);
             // Delete selected item
             if ($output_type == HTML_OUTPUT) {
                 if ($isadmin) {
                     openArrowMassive("massiveaction_form");
                     Dropdown::showForMassiveAction($itemtype, $p['is_deleted']);
                     closeArrowMassive();
                     // End form for delete item
                     echo "</form>\n";
                 } else {
                     echo "<br>";
                 }
             }
             if ($output_type == HTML_OUTPUT) {
                 // In case of HTML display
                 printPager($p['start'], $numrows, $target, $parameters);
             }
         } else {
             echo self::showError($output_type);
         }
     } else {
         echo $DBread->error();
     }
     // Clean selection
     $_SESSION['glpimassiveactionselected'] = array();
 }
    }
    if ($item_count == IMG_PER_PAGE) {
        echo '<li><a href="list.php?page=' . ($page + 2) . '" class="button">下一頁</a></li>';
    }
    echo '</ul></div>';
}
printPager($page, count($result));
?>
<div>
<?php 
for ($i = 0; $i < count($result); $i++) {
    if ($i % 4 == 0) {
        echo '<div class="row">';
    }
    echo '<div class="col-md-3 col-sm-3 col-xs-6"><a href="show.php?code=' . $result[$i]['code'] . '"><img class="list-img" src="//i.imgur.com/' . $result[$i]['code'] . 'm.jpg"></a></div>';
    if ($i % 4 == 3) {
        echo '</div>';
    }
}
?>
</div>
<?php 
printPager($page, count($result));
?>
<ul class="actions">
  <li><a href="./" class="button">產生我的頭貼</a></li>
</ul>
					</section>

<?php 
include 'inc/footer.php';
 /**
  *Print out list kb item
  *
  * @param $options : $_GET
  * @param $faq display on faq ?
  **/
 static function showList($options, $faq = 0)
 {
     global $DB, $LANG, $CFG_GLPI;
     // Default values of parameters
     $params["start"] = "0";
     $params["knowbaseitemcategories_id"] = "0";
     $params["contains"] = "";
     $params["target"] = $_SERVER['PHP_SELF'];
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     // Lists kb Items
     $where = "";
     $order = "";
     $score = "";
     // Build query
     if (getLoginUserID()) {
         $where = getEntitiesRestrictRequest("", "glpi_knowbaseitems", "", "", true) . " AND ";
     } else {
         // Anonymous access
         if (isMultiEntitiesMode()) {
             $where = " (`glpi_knowbaseitems`.`entities_id` = '0'\n                        AND `glpi_knowbaseitems`.`is_recursive` = '1')\n                        AND ";
         }
     }
     if ($faq) {
         // helpdesk
         $where .= " (`glpi_knowbaseitems`.`is_faq` = '1')\n                      AND ";
     }
     // a search with $contains
     if (strlen($params["contains"]) > 0) {
         $search = unclean_cross_side_scripting_deep($params["contains"]);
         $score = " ,MATCH(glpi_knowbaseitems.question, glpi_knowbaseitems.answer)\n                     AGAINST('{$search}' IN BOOLEAN MODE) AS SCORE ";
         $where_1 = $where . " MATCH(glpi_knowbaseitems.question, glpi_knowbaseitems.answer)\n                    AGAINST('{$search}' IN BOOLEAN MODE) ";
         $order = "ORDER BY `SCORE` DESC";
         // preliminar query to allow alternate search if no result with fulltext
         $query_1 = "SELECT COUNT(`id`)\n                     FROM `glpi_knowbaseitems`\n                     WHERE {$where_1}";
         $result_1 = $DB->query($query_1);
         $numrows_1 = $DB->result($result_1, 0, 0);
         if ($numrows_1 <= 0) {
             // not result this fulltext try with alternate search
             $search1 = array('/\\\\"/', "/\\+/", "/\\*/", "/~/", "/</", "/>/", "/\\(/", "/\\)/", "/\\-/");
             $contains = preg_replace($search1, "", $params["contains"]);
             $where .= " (`glpi_knowbaseitems`.`question` " . makeTextSearch($contains) . "\n                         OR `glpi_knowbaseitems`.`answer` " . makeTextSearch($contains) . ")";
         } else {
             $where = $where_1;
         }
     } else {
         // no search -> browse by category
         $where .= " (`glpi_knowbaseitems`.`knowbaseitemcategories_id`\n                        = '" . $params["knowbaseitemcategories_id"] . "')";
         $order = " ORDER BY `glpi_knowbaseitems`.`question` ASC";
     }
     if (!$params["start"]) {
         $params["start"] = 0;
     }
     $query = "SELECT `glpi_knowbaseitems`.*,\n                       `glpi_knowbaseitemcategories`.`completename` AS category\n                       {$score}\n                FROM `glpi_knowbaseitems`\n                LEFT JOIN `glpi_knowbaseitemcategories`\n                     ON (`glpi_knowbaseitemcategories`.`id`\n                           = `glpi_knowbaseitems`.`knowbaseitemcategories_id`)\n                WHERE {$where}\n                {$order}";
     // Get it from database
     if ($result = $DB->query($query)) {
         $KbCategory = new KnowbaseItemCategory();
         $title = "";
         if ($KbCategory->getFromDB($params["knowbaseitemcategories_id"])) {
             $title = $LANG['common'][36] . " = " . (empty($KbCategory->fields['name']) ? "(" . $params['knowbaseitemcategories_id'] . ")" : $KbCategory->fields['name']);
         }
         initNavigateListItems('KnowbaseItem', $title);
         $numrows = $DB->numrows($result);
         $list_limit = $_SESSION['glpilist_limit'];
         // Limit the result, if no limit applies, use prior result
         if ($numrows > $list_limit && !isset($_GET['export_all'])) {
             $query_limit = $query . " LIMIT " . intval($params["start"]) . ", " . intval($list_limit) . " ";
             $result_limit = $DB->query($query_limit);
             $numrows_limit = $DB->numrows($result_limit);
         } else {
             $numrows_limit = $numrows;
             $result_limit = $result;
         }
         if ($numrows_limit > 0) {
             // Set display type for export if define
             $output_type = HTML_OUTPUT;
             if (isset($_GET["display_type"])) {
                 $output_type = $_GET["display_type"];
             }
             // Pager
             $parameters = "start=" . $params["start"] . "&amp;knowbaseitemcategories_id=" . $params['knowbaseitemcategories_id'] . "&amp;contains=" . $params["contains"] . "&amp;is_faq={$faq}";
             if (isset($options['tickets_id'])) {
                 $parameters .= "&amp;tickets_id=" . $options['tickets_id'];
             }
             if ($output_type == HTML_OUTPUT) {
                 printPager($params['start'], $numrows, getItemTypeSearchURL('KnowbaseItem'), $parameters, 'KnowbaseItem');
             }
             $nbcols = 1;
             // Display List Header
             echo Search::showHeader($output_type, $numrows_limit + 1, $nbcols);
             $header_num = 1;
             echo Search::showHeaderItem($output_type, $LANG['knowbase'][14], $header_num);
             if ($output_type != HTML_OUTPUT) {
                 echo Search::showHeaderItem($output_type, $LANG['knowbase'][15], $header_num);
             }
             echo Search::showHeaderItem($output_type, $LANG['common'][36], $header_num);
             if (isset($options['tickets_id']) && $output_type == HTML_OUTPUT) {
                 echo Search::showHeaderItem($output_type, '&nbsp;', $header_num);
             }
             // Num of the row (1=header_line)
             $row_num = 1;
             for ($i = 0; $i < $numrows_limit; $i++) {
                 $data = $DB->fetch_array($result_limit);
                 addToNavigateListItems('KnowbaseItem', $data["id"]);
                 // Column num
                 $item_num = 1;
                 $row_num++;
                 echo Search::showNewLine($output_type, $i % 2);
                 if ($output_type == HTML_OUTPUT) {
                     if (isset($options['tickets_id'])) {
                         $href = " href='#' onClick=\"var w = window.open('" . $CFG_GLPI["root_doc"] . "/front/popup.php?popup=show_kb&amp;id=" . $data['id'] . "' ,'glpipopup', " . "'height=400, width=1000, top=100, left=100, scrollbars=yes' );w.focus();\"";
                     } else {
                         $href = " href=\"" . $params['target'] . "?id=" . $data["id"] . "\" ";
                     }
                     echo Search::showItem($output_type, "<div class='kb'><a " . ($data['is_faq'] ? " class='pubfaq' " : " class='knowbase' ") . " {$href}>" . resume_text($data["question"], 80) . "</a></div>\n                                          <div class='kb_resume'>" . resume_text(html_clean(unclean_cross_side_scripting_deep($data["answer"])), 600) . "</div>", $item_num, $row_num);
                 } else {
                     echo Search::showItem($output_type, $data["question"], $item_num, $row_num);
                     echo Search::showItem($output_type, html_clean(unclean_cross_side_scripting_deep(html_entity_decode($data["answer"], ENT_QUOTES, "UTF-8"))), $item_num, $row_num);
                 }
                 echo Search::showItem($output_type, $data["category"], $item_num, $row_num);
                 if (isset($options['tickets_id']) && $output_type == HTML_OUTPUT) {
                     $content = "<a href='" . $CFG_GLPI['root_doc'] . "/front/ticket.form.php?load_kb_sol=" . $data['id'] . "&amp;id=" . $options['tickets_id'] . "&amp;forcetab=4'>" . $LANG['job'][24] . "</a>";
                     echo Search::showItem($output_type, $content, $item_num, $row_num);
                 }
                 // End Line
                 echo Search::showEndLine($output_type);
             }
             // Display footer
             if ($output_type == PDF_OUTPUT_LANDSCAPE || $output_type == PDF_OUTPUT_PORTRAIT) {
                 echo Search::showFooter($output_type, Dropdown::getDropdownName("glpi_knowbaseitemcategories", $params['knowbaseitemcategories_id']));
             } else {
                 echo Search::showFooter($output_type);
             }
             echo "<br>";
             if ($output_type == HTML_OUTPUT) {
                 printPager($params['start'], $numrows, getItemTypeSearchURL('KnowbaseItem'), $parameters, 'KnowbaseItem');
             }
         } else {
             if ($params["knowbaseitemcategories_id"] != 0) {
                 echo "<div class='center b'>" . $LANG['search'][15] . "</div>";
             }
         }
     }
 }
 /**
  * Display a list of computers to add or to link
  *
  * @param ocsservers_id the ID of the ocs server
  * @param advanced display detail about the computer import or not (target entity, matched rules, etc.)
  * @param check indicates if checkboxes are checked or not
  * @param start display a list of computers starting at row X
  * @param entity a list of entities in which computers can be added or linked
  * @param tolinked false for an import, true for a link
  *
  * @return nothing
  **/
 static function showComputersToAdd($ocsservers_id, $advanced, $check, $start, $entity = 0, $tolinked = false)
 {
     global $DB, $DBocs, $LANG, $CFG_GLPI;
     if (!haveRight("ocsng", "w")) {
         return false;
     }
     $target = $CFG_GLPI['root_doc'] . '/front/ocsng.import.php';
     if ($tolinked) {
         $target = $CFG_GLPI['root_doc'] . '/front/ocsng.link.php';
     }
     $cfg_ocs = self::getConfig($ocsservers_id);
     $WHERE = self::getTagLimit($cfg_ocs);
     $query_ocs = "SELECT `hardware`.*,\n                           `accountinfo`.`TAG` AS TAG,\n                           `bios`.`SSN` AS SERIAL\n                    FROM `hardware`\n                    INNER JOIN `accountinfo` ON (`hardware`.`id` = `accountinfo`.`HARDWARE_ID`)\n                    INNER JOIN `bios` ON (`hardware`.`id` = `bios`.`HARDWARE_ID`)" . (!empty($WHERE) ? "WHERE {$WHERE}" : "") . "\n                    ORDER BY `hardware`.`NAME`";
     $result_ocs = $DBocs->query($query_ocs);
     // Existing OCS - GLPI link
     $query_glpi = "SELECT *\n                     FROM `glpi_ocslinks`\n                     WHERE `ocsservers_id` = '{$ocsservers_id}'";
     $result_glpi = $DB->query($query_glpi);
     if ($DBocs->numrows($result_ocs) > 0) {
         // Get all hardware from OCS DB
         $hardware = array();
         while ($data = $DBocs->fetch_array($result_ocs)) {
             $data = clean_cross_side_scripting_deep(addslashes_deep($data));
             $hardware[$data["ID"]]["date"] = $data["LASTDATE"];
             $hardware[$data["ID"]]["name"] = $data["NAME"];
             $hardware[$data["ID"]]["TAG"] = $data["TAG"];
             $hardware[$data["ID"]]["id"] = $data["ID"];
             $hardware[$data["ID"]]["serial"] = $data["SERIAL"];
             $query_network = "SELECT *\n                              FROM `networks`\n                              WHERE `HARDWARE_ID` = '" . $data["ID"] . "'";
             //Get network informations for this computer
             //Ignore informations that contains "??"
             foreach ($DBocs->request($query_network) as $network) {
                 if (isset($network['IPADDRESS']) && $network['IPADDRESS'] != '??') {
                     $hardware[$data["ID"]]['IPADDRESS'][] = $network['IPADDRESS'];
                 }
                 if (isset($network['IPSUBNET']) && $network['IPSUBNET'] != '??') {
                     $hardware[$data["ID"]]['IPSUBNET'][] = $network['IPSUBNET'];
                 }
                 if (isset($network['MACADDRESS']) && $network['MACADDR'] != '??') {
                     $hardware[$data["ID"]]['MACADDRESS'][] = $network['MACADDR'];
                 }
             }
         }
         // Get all links between glpi and OCS
         $already_linked = array();
         if ($DB->numrows($result_glpi) > 0) {
             while ($data = $DBocs->fetch_array($result_glpi)) {
                 $already_linked[$data["ocsid"]] = $data["last_update"];
             }
         }
         // Clean $hardware from already linked element
         if (count($already_linked) > 0) {
             foreach ($already_linked as $ID => $date) {
                 if (isset($hardware[$ID]) && isset($already_linked[$ID])) {
                     unset($hardware[$ID]);
                 }
             }
         }
         if ($tolinked && count($hardware)) {
             echo "<div class='center'><strong>" . $LANG['ocsng'][22] . "</strong></div>";
         }
         echo "<div class='center'>";
         if (($numrows = count($hardware)) > 0) {
             $parameters = "check={$check}";
             printPager($start, $numrows, $target, $parameters);
             // delete end
             array_splice($hardware, $start + $_SESSION['glpilist_limit']);
             // delete begin
             if ($start > 0) {
                 array_splice($hardware, 0, $start);
             }
             //Show preview form only in import and in multi-entity mode
             if (!$tolinked && isMultiEntitiesMode()) {
                 echo "<div class='firstbloc'>";
                 echo "<form method='post' name='ocsng_import_mode' id='ocsng_import_mode'\n                      action='{$target}'>\n";
                 echo "<table class='tab_cadre_fixe'>";
                 echo "<tr><th>" . $LANG['ocsng'][41] . "</th></tr>\n";
                 echo "<tr class='tab_bg_1'><td class='center'>";
                 if ($advanced) {
                     $status = "false";
                 } else {
                     $status = "true";
                 }
                 echo "<a href='" . $target . "?change_import_mode=" . $status . "'>";
                 if ($advanced) {
                     echo $LANG['ocsng'][38];
                 } else {
                     echo $LANG['ocsng'][37];
                 }
                 echo "</a></td></tr>";
                 echo "<tr class='tab_bg_1'><td class='center b'>" . $LANG['ocsconfig'][18] . "<br>";
                 echo "</tr></table></form></div>";
             }
             echo "<form method='post' name='ocsng_form' id='ocsng_form' action='{$target}'>";
             if (!$tolinked) {
                 echo "<a href='" . $target . "?check=all&amp;start={$start}' onclick= " . "\"if ( markCheckboxes('ocsng_form') ) return false;\">" . $LANG['buttons'][18] . "</a>&nbsp;/&nbsp;<a href='" . $target . "?check=none&amp;start=" . "{$start}' onclick= \"if ( unMarkCheckboxes('ocsng_form') ) return false;\">" . $LANG['buttons'][19] . "</a>\n";
             }
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'><td colspan='" . ($advanced ? 8 : 5) . "' class='center'>";
             echo "<input class='submit' type='submit' name='import_ok' value=\"" . $LANG['buttons'][37] . "\">";
             echo "</td></tr>\n";
             echo "<tr><th>" . $LANG['ocsng'][5] . "</th>\n<th>" . $LANG['common'][19] . "</th>\n";
             echo "<th>" . $LANG['common'][27] . "</th>\n<th>TAG</th>\n";
             if ($advanced && !$tolinked) {
                 echo "<th>" . $LANG['ocsng'][40] . "</th>\n";
                 echo "<th>" . $LANG['ocsng'][36] . "</th>\n";
                 echo "<th>" . $LANG['ocsng'][39] . "</th>\n";
             }
             echo "<th>&nbsp;</th></tr>\n";
             $rule = new RuleOcsCollection($ocsservers_id);
             foreach ($hardware as $ID => $tab) {
                 $comp = new Computer();
                 $comp->fields["id"] = $tab["id"];
                 $data = array();
                 if ($advanced && !$tolinked) {
                     $data = $rule->processAllRules(array(), array(), $tab["id"]);
                 }
                 echo "<tr class='tab_bg_2'><td>" . $tab["name"] . "</td>\n";
                 echo "<td>" . $tab["serial"] . "</td>\n";
                 echo "<td>" . convDateTime($tab["date"]) . "</td>\n";
                 echo "<td>" . $tab["TAG"] . "</td>\n";
                 if ($advanced && !$tolinked) {
                     if (!isset($data['entities_id']) || $data['entities_id'] == -1) {
                         echo "<td class='center'><img src=\"" . GLPI_ROOT . "/pics/redbutton.png\"></td>\n";
                         $data['entities_id'] = -1;
                     } else {
                         echo "<td class='center'>";
                         //echo "<td class='center'><img src=\"".GLPI_ROOT. "/pics/greenbutton.png\">";
                         //echo "&nbsp;";
                         $tmprule = new RuleOcs();
                         if ($tmprule->can($data['_ruleid'], 'r')) {
                             echo "<a href='" . $tmprule->getLinkURL() . "'>" . $tmprule->getName() . "</a>";
                         } else {
                             echo $tmprule->getName();
                         }
                         echo "</td>\n";
                     }
                     echo "<td>";
                     Dropdown::show('Entity', array('name' => "toimport_entities[" . $tab["id"] . "]\n                                                      =" . $data['entities_id'], 'value' => $data['entities_id'], 'comments' => 0));
                     echo "</td>\n";
                     echo "<td>";
                     if (!isset($data['locations_id'])) {
                         $data['locations_id'] = 0;
                     }
                     Dropdown::show('Location', array('name' => "toimport_locations[" . $tab["id"] . "]\n                                                      =" . $data['locations_id'], 'value' => $data['locations_id'], 'comments' => 0));
                     echo "</td>\n";
                 }
                 echo "<td>";
                 if (!$tolinked) {
                     echo "<input type='checkbox' name='toimport[" . $tab["id"] . "]' " . ($check == "all" ? "checked" : "") . ">";
                 } else {
                     $rulelink = new RuleImportComputerCollection();
                     $rulelink_results = array();
                     $params = array('entities_id' => $entity, 'ocsservers_id' => $ocsservers_id);
                     $rulelink_results = $rulelink->processAllRules($tab, array(), $params);
                     //Look for the computer using automatic link criterias as defined in OCSNG configuration
                     $options = array('name' => "tolink[" . $tab["id"] . "]");
                     $show_dropdown = true;
                     //If the computer is not explicitly refused by a rule
                     if (!isset($rulelink_results['action']) || $rulelink_results['action'] != self::LINK_RESULT_NO_IMPORT) {
                         if (!empty($rulelink_results['found_computers'])) {
                             $options['value'] = $rulelink_results['found_computers'][0];
                             $options['entity'] = $entity;
                         }
                         Dropdown::show('Computer', $options);
                     } else {
                         echo "<img src='" . GLPI_ROOT . "/pics/redbutton.png'>";
                     }
                 }
                 echo "</td></tr>\n";
             }
             echo "<tr class='tab_bg_1'><td colspan='" . ($advanced ? 8 : 5) . "' class='center'>";
             echo "<input class='submit' type='submit' name='import_ok' value=\"" . $LANG['buttons'][37] . "\">\n";
             echo "<input type=hidden name='ocsservers_id' value='{$ocsservers_id}'>";
             echo "</td></tr>";
             echo "</table></form>\n";
             if (!$tolinked) {
                 echo "<a href='" . $target . "?check=all&amp;start={$start}' onclick=" . "\"if ( markCheckboxes('ocsng_form') ) return false;\">" . $LANG['buttons'][18] . "</a>&nbsp;/&nbsp;" . "<a href='" . $target . "?check=none&amp;start=" . "{$start}' onclick=\"if (unMarkCheckboxes('ocsng_form')) return false;\">" . $LANG['buttons'][19] . "</a>\n";
             }
             printPager($start, $numrows, $target, $parameters);
         } else {
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr><th>" . $LANG['ocsng'][2] . "</th></tr>\n";
             echo "<tr class='tab_bg_1'><td class='center b'>" . $LANG['ocsng'][9] . "</td></tr>\n";
             echo "</table>";
         }
         echo "</div>";
     } else {
         echo "<div class='center'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th>" . $LANG['ocsng'][2] . "</th></tr>\n";
         echo "<tr class='tab_bg_1'><td class='center b'>" . $LANG['ocsng'][9] . "</td></tr>\n";
         echo "</table></div>";
     }
 }