printPager() 정적인 공개 메소드

Print pager for search option (first/previous/next/last)
static public printPager ( $start, $numrows, $target, $parameters, $item_type_output, $item_type_output_param, $additional_info = '' ) : nothing
$start from witch item we start
$numrows total items
$target page would be open when click on the option (last,previous etc)
$parameters parameters would be passed on the URL.
$item_type_output item type display - if >0 display export PDF et Sylk form (default 0)
$item_type_output_param item type parameter for export (default 0)
$additional_info Additional information to display (default '')
리턴 nothing (print a pager)
 /**
  * Display list of hosts
  */
 function showHostsBoard($params, $width = '', $limit = '')
 {
     global $DB, $CFG_GLPI;
     if (!isset($_SESSION['plugin_monitoring_reduced_interface'])) {
         $_SESSION['plugin_monitoring_reduced_interface'] = false;
     }
     $col_to_display = array(0, 10, 1, 2, 3, 6, 7, 8, 9, 11);
     $data = Search::prepareDatasForSearch('PluginMonitoringHost', $params, $col_to_display);
     $data['tocompute'] = $data['toview'];
     Search::constructSQL($data);
     //echo "<pre>";      print_r($data['sql']['search']);
     Search::constructDatas($data);
     //      if (! isset($_GET['order'])) {
     //         $_GET['order'] = "ASC";
     //      }
     //      if (! isset($_GET['sort'])) {
     //         $_GET['sort'] = "";
     //      }
     //
     //      $order = "ASC";
     //      if (isset($_GET['order'])) {
     //         $order = $_GET['order'];
     //      }
     //      $where = '';
     //      if (isset($_GET['field'])) {
     //         foreach ($_GET['field'] as $key=>$value) {
     //            $wheretmp = '';
     //            if (isset($_GET['link'][$key])) {
     //               $wheretmp.= " ".$_GET['link'][$key]." ";
     //            }
     //            $wheretmp .= Search::addWhere(
     //                                   "",
     //                                   0,
     //                                   "PluginMonitoringHost",
     //                                   $_GET['field'][$key],
     //                                   $_GET['searchtype'][$key],
     //                                   $_GET['contains'][$key]);
     //            if (!strstr($wheretmp, "``.``")) {
     //               if ($where != ''
     //                       AND !isset($_GET['link'][$key])) {
     //                  $where .= " AND ";
     //               }
     //               $where .= $wheretmp;
     //            }
     //         }
     //      }
     //      if ($where != '') {
     //         $where = "(".$where;
     //         $where .= ") AND ";
     //      }
     //      $where .= " CONCAT_WS('', `glpi_computers`.`entities_id`, `glpi_printers`.`entities_id`, `glpi_networkequipments`.`entities_id`) IN (".$_SESSION['glpiactiveentities_string'].")";
     //
     //      if ($where != '') {
     //         $where = " WHERE ".$where;
     //         $where = str_replace("`".getTableForItemType("PluginMonitoringDisplay")."`.",
     //                 "", $where);
     //
     //      }
     //
     //      $leftjoin = "
     //         LEFT JOIN `glpi_computers`
     //            ON `glpi_plugin_monitoring_hosts`.`items_id` = `glpi_computers`.`id`
     //               AND `glpi_plugin_monitoring_hosts`.`itemtype`='Computer'
     //         LEFT JOIN `glpi_printers`
     //            ON `glpi_plugin_monitoring_hosts`.`items_id` = `glpi_printers`.`id`
     //               AND `glpi_plugin_monitoring_hosts`.`itemtype`='Printer'
     //         LEFT JOIN `glpi_networkequipments`
     //            ON `glpi_plugin_monitoring_hosts`.`items_id` = `glpi_networkequipments`.`id`
     //               AND `glpi_plugin_monitoring_hosts`.`itemtype`='NetworkEquipment'
     //         LEFT JOIN `glpi_entities`
     //            ON CONCAT_WS('', `glpi_computers`.`entities_id`, `glpi_printers`.`entities_id`, `glpi_networkequipments`.`entities_id`) = `glpi_entities`.`id`
     //
     //      ";
     //
     //      // * ORDER
     //      $ORDERQUERY = "ORDER BY entity_name ASC, host_name ASC";
     //      $toview = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
     //      $toviewComplete = array(
     //          'ITEM_0' => 'entity_name',
     //          'ITEM_1' => 'host_name',
     //          'ITEM_2' => 'host_state',
     //          'ITEM_3' => 'service_state',
     //          'ITEM_4' => 'last_check',
     //          'ITEM_5' => 'event',
     //          'ITEM_6' => 'perf_data',
     //          'ITEM_7' => 'is_acknowledged'
     //      );
     //      foreach ($toview as $key => $val) {
     //         if ($_GET['sort']==$val) {
     //            $ORDERQUERY = Search::addOrderBy("PluginMonitoringHost", $_GET['sort'],
     //                                             $_GET['order'], $key);
     //            foreach ($toviewComplete as $keyi=>$vali) {
     //               $ORDERQUERY= str_replace($keyi, $vali, $ORDERQUERY);
     //            }
     //         }
     //      }
     //
     ////            `glpi_computers`.*
     //
     //      $query = "SELECT
     //            `glpi_entities`.`name` AS entity_name,
     //            CONCAT_WS('', `glpi_computers`.`id`, `glpi_printers`.`id`, `glpi_networkequipments`.`id`) AS idComputer,
     //            CONCAT_WS('', `glpi_computers`.`name`, `glpi_printers`.`name`, `glpi_networkequipments`.`name`) AS host_name,
     //            `glpi_plugin_monitoring_hosts`.*,
     //            `glpi_plugin_monitoring_hosts`.`state` AS host_state,
     //            `glpi_plugin_monitoring_hosts`.`is_acknowledged` AS host_acknowledged
     //         FROM `glpi_plugin_monitoring_hosts`
     //         ".$leftjoin."
     //         ".$where."
     //         ".$ORDERQUERY;
     //      // Toolbox::logInFile("pm", "Query hosts - $query\n");
     //
     //      $result = $DB->query($query);
     //
     //      if (! isset($_GET["start"])) {
     //         $_GET["start"]=0;
     //      }
     //      $start=$_GET['start'];
     //      if (! isset($_GET["order"])) {
     //         $_GET["order"]="ASC";
     //      }
     $rand = mt_rand();
     if (!isset($data['data']) || !isset($data['data']['totalcount'])) {
         return false;
     }
     // Contruct Pager parameters
     $globallinkto = Toolbox::append_params(array('criteria' => Toolbox::stripslashes_deep($data['search']['criteria']), 'metacriteria' => Toolbox::stripslashes_deep($data['search']['metacriteria'])), '&amp;');
     $parameters = "sort=" . $data['search']['sort'] . "&amp;order=" . $data['search']['order'] . '&amp;' . $globallinkto;
     if (isset($_GET['_in_modal'])) {
         $parameters .= "&amp;_in_modal=1";
     }
     // If the begin of the view is before the number of items
     if ($data['data']['count'] > 0) {
         // Display pager only for HTML
         if ($data['display_type'] == Search::HTML_OUTPUT) {
             $search_config_top = "";
             $search_config_bottom = "";
             Html::printPager($data['search']['start'], $data['data']['totalcount'], $data['search']['target'], $parameters, $data['itemtype'], 0, $search_config_top);
         }
         // Define begin and end var for loop
         // Search case
         $begin_display = $data['data']['begin'];
         $end_display = $data['data']['end'];
     }
     echo '<div id="custom_date" style="display:none"></div>';
     echo '<div id="custom_time" style="display:none"></div>';
     if ($width == '') {
         echo "<table class='tab_cadrehov' style='width:100%;'>";
     } else {
         echo "<table class='tab_cadrehov' style='width:" . $width . "px;'>";
     }
     $num = 0;
     if (Session::haveRight("plugin_monitoring_hostcommand", CREATE)) {
         // Host test command ...
         $pmCommand = new PluginMonitoringCommand();
         $a_commands = array();
         $a_list = $pmCommand->find("command_name LIKE 'host_action'");
         foreach ($a_list as $dt) {
             $host_command_name = $dt['name'];
             $host_command_command = $dt['command_line'];
         }
     }
     echo "<tr class='tab_bg_1'>";
     $this->showHeaderItem(__('Entity'), 0, $num, $begin_display, $globallinkto, 'host.php', 'PluginMonitoringHost');
     $this->showHeaderItem(__('Type'), 0, $num, $begin_display, $globallinkto, 'host.php', 'PluginMonitoringHost');
     $this->showHeaderItem(__('Host', 'monitoring'), 1, $num, $begin_display, $globallinkto, 'host.php', 'PluginMonitoringHost');
     $this->showHeaderItem(__('Host state'), 2, $num, $begin_display, $globallinkto, 'host.php', 'PluginMonitoringHost');
     if (isset($host_command_name)) {
         echo '<th>' . __('Host action', 'monitoring') . '</th>';
     }
     echo '<th>' . __('Host resources state', 'monitoring') . '</th>';
     echo '<th>' . __('IP address', 'monitoring') . '</th>';
     $this->showHeaderItem(__('Last check', 'monitoring'), 4, $num, $begin_display, $globallinkto, 'host.php', 'PluginMonitoringHost');
     $this->showHeaderItem(__('Result details', 'monitoring'), 5, $num, $begin_display, $globallinkto, 'host.php', 'PluginMonitoringHost');
     $this->showHeaderItem(__('Performance data', 'monitoring'), 6, $num, $begin_display, $globallinkto, 'host.php', 'PluginMonitoringHost');
     if (Session::haveRight("plugin_monitoring_acknowledge", READ) || Session::haveRight("plugin_monitoring_downtime", READ)) {
         $this->showHeaderItem(__('Maintenance', 'monitoring'), 7, $num, $begin_display, $globallinkto, 'host.php', 'PluginMonitoringHost');
     }
     echo "</tr>";
     foreach ($data['data']['rows'] as $row) {
         // Reduced array or not ?
         if ($_SESSION['plugin_monitoring_reduced_interface'] && $row[3]['displayname'] == 'UP') {
             continue;
         }
         if (isset($host_command_name)) {
             $row['host_command_name'] = $host_command_name;
             $row['host_command_command'] = $host_command_command;
         }
         // Get all host services except if state is ok or is already acknowledged ...
         $a_ret = PluginMonitoringHost::getServicesState($row['id'], "`glpi_plugin_monitoring_services`.`state` != 'OK'\n                                                         AND `glpi_plugin_monitoring_services`.`is_acknowledged` = '0'");
         $row['host_services_state'] = $a_ret[0];
         $row['host_services_state_list'] = $a_ret[1];
         // Get host first IP address
         $row['ip'] = __('Unknown IP address', 'monitoring');
         $ip = PluginMonitoringHostaddress::getIp($row[9]['displayname'], $row[1]['displayname'], '');
         if ($ip != '') {
             $row['ip'] = $ip;
         }
         echo "<tr class='tab_bg_3'>";
         $this->displayHostLine($row);
         echo "</tr>";
     }
     echo "</table>";
     echo "<br/>";
     Html::printPager($data['search']['start'], $data['data']['totalcount'], $data['search']['target'], $parameters, '', 0, $search_config_bottom);
 }
예제 #2
1
 /**
  * Display a list of computers to add or to link
  *
  * @param plugin_ocsinventoryng_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 rowX
  * @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($serverId, $advanced, $check, $start, $entity = 0, $tolinked = false)
 {
     global $DB, $CFG_GLPI;
     if (!Session::haveRight("plugin_ocsinventoryng", UPDATE)) {
         return false;
     }
     $title = __('Import new computers', 'ocsinventoryng');
     if ($tolinked) {
         $title = __('Link new OCSNG computers to existing GLPI computers', 'ocsinventoryng');
     }
     $target = $CFG_GLPI['root_doc'] . '/plugins/ocsinventoryng/front/ocsng.import.php';
     if ($tolinked) {
         $target = $CFG_GLPI['root_doc'] . '/plugins/ocsinventoryng/front/ocsng.link.php';
     }
     // Get all links between glpi and OCS
     $query_glpi = "SELECT ocsid\n                     FROM `glpi_plugin_ocsinventoryng_ocslinks`\n                     WHERE `plugin_ocsinventoryng_ocsservers_id` = '{$serverId}'";
     $result_glpi = $DB->query($query_glpi);
     $already_linked = array();
     if ($DB->numrows($result_glpi) > 0) {
         while ($data = $DB->fetch_array($result_glpi)) {
             $already_linked[] = $data["ocsid"];
         }
     }
     $cfg_ocs = self::getConfig($serverId);
     $computerOptions = array('OFFSET' => $start, 'MAX_RECORDS' => $_SESSION['glpilist_limit'], 'ORDER' => 'LASTDATE', 'FILTER' => array('EXCLUDE_IDS' => $already_linked), 'DISPLAY' => array('CHECKSUM' => PluginOcsinventoryngOcsClient::CHECKSUM_BIOS), 'ORDER' => 'NAME');
     if ($cfg_ocs["tag_limit"] and $tag_limit = explode("\$", trim($cfg_ocs["tag_limit"]))) {
         $computerOptions['FILTER']['TAGS'] = $tag_limit;
     }
     if ($cfg_ocs["tag_exclude"] and $tag_exclude = explode("\$", trim($cfg_ocs["tag_exclude"]))) {
         $computerOptions['FILTER']['EXCLUDE_TAGS'] = $tag_exclude;
     }
     $ocsClient = self::getDBocs($serverId);
     $ocsResult = $ocsClient->getComputers($computerOptions);
     if (isset($ocsResult['COMPUTERS'])) {
         $computers = $ocsResult['COMPUTERS'];
         if (count($computers)) {
             // Get all hardware from OCS DB
             $hardware = array();
             foreach ($computers as $data) {
                 $data = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($data));
                 $id = $data['META']['ID'];
                 $hardware[$id]["date"] = $data['META']["LASTDATE"];
                 $hardware[$id]["name"] = $data['META']["NAME"];
                 $hardware[$id]["TAG"] = $data['META']["TAG"];
                 $hardware[$id]["id"] = $data['META']["ID"];
                 if (isset($data['BIOS']) && count($data['BIOS'])) {
                     $hardware[$id]["serial"] = $data['BIOS']["SSN"];
                     $hardware[$id]["model"] = $data['BIOS']["SMODEL"];
                     $hardware[$id]["manufacturer"] = $data['BIOS']["SMANUFACTURER"];
                 } else {
                     $hardware[$id]["serial"] = '';
                     $hardware[$id]["model"] = '';
                     $hardware[$id]["manufacturer"] = '';
                 }
             }
             if ($tolinked && count($hardware)) {
                 echo "<div class='center b'>" . __('Caution! The imported data (see your configuration) will overwrite the existing one', 'ocsinventoryng') . "</div>";
             }
             echo "<div class='center'>";
             if ($numrows = $ocsResult['TOTAL_COUNT']) {
                 $parameters = "check={$check}";
                 Html::printPager($start, $numrows, $target, $parameters);
                 //Show preview form only in import even in multi-entity mode because computer import
                 //can be refused by a rule
                 if (!$tolinked) {
                     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>" . __('Manual import mode', 'ocsinventoryng') . "</th></tr>\n";
                     echo "<tr class='tab_bg_1'><td class='center'>";
                     if ($advanced) {
                         Html::showSimpleForm($target, 'change_import_mode', __('Disable preview', 'ocsinventoryng'), array('id' => 'false'));
                     } else {
                         Html::showSimpleForm($target, 'change_import_mode', __('Enable preview', 'ocsinventoryng'), array('id' => 'true'));
                     }
                     echo "</td></tr>";
                     echo "<tr class='tab_bg_1'><td class='center b'>" . __('Check first that duplicates have been correctly managed in OCSNG', 'ocsinventoryng') . "</td>";
                     echo "</tr></table>";
                     Html::closeForm();
                     echo "</div>";
                 }
                 echo "<form method='post' name='ocsng_form' id='ocsng_form' action='{$target}'>";
                 if (!$tolinked) {
                     self::checkBox($target);
                 }
                 echo "<table class='tab_cadre_fixe'>";
                 echo "<tr class='tab_bg_1'><td colspan='" . ($advanced || $tolinked ? 10 : 7) . "' class='center'>";
                 echo "<input class='submit' type='submit' name='import_ok' value=\"" . _sx('button', 'Import', 'ocsinventoryng') . "\">";
                 echo "</td></tr>\n";
                 echo "<tr><th>" . __('Name') . "</th>\n";
                 echo "<th>" . __('Manufacturer') . "</th>\n";
                 echo "<th>" . __('Model') . "</th>\n";
                 echo "<th>" . __('Serial number') . "</th>\n";
                 echo "<th>" . __('Date') . "</th>\n";
                 echo "<th>" . __('OCSNG TAG', 'ocsinventoryng') . "</th>\n";
                 if ($advanced && !$tolinked) {
                     echo "<th>" . __('Match the rule ?', 'ocsinventoryng') . "</th>\n";
                     echo "<th>" . __('Destination entity') . "</th>\n";
                     echo "<th>" . __('Target location', 'ocsinventoryng') . "</th>\n";
                 }
                 echo "<th width='20%'>&nbsp;</th></tr>\n";
                 $rule = new RuleImportEntityCollection();
                 foreach ($hardware as $ID => $tab) {
                     $comp = new Computer();
                     $comp->fields["id"] = $tab["id"];
                     $data = array();
                     if ($advanced && !$tolinked) {
                         $data = $rule->processAllRules(array('ocsservers_id' => $serverId, '_source' => 'ocsinventoryng'), array(), array('ocsid' => $tab["id"]));
                     }
                     echo "<tr class='tab_bg_2'><td>" . $tab["name"] . "</td>\n";
                     echo "<td>" . $tab["manufacturer"] . "</td><td>" . $tab["model"] . "</td>";
                     echo "<td>" . $tab["serial"] . "</td>\n";
                     echo "<td>" . Html::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=\"" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png\"></td>\n";
                             $data['entities_id'] = -1;
                         } else {
                             echo "<td class='center'>";
                             $tmprule = new RuleImportEntity();
                             if ($tmprule->can($data['_ruleid'], READ)) {
                                 echo "<a href='" . $tmprule->getLinkURL() . "'>" . $tmprule->getName() . "</a>";
                             } else {
                                 echo $tmprule->getName();
                             }
                             echo "</td>\n";
                         }
                         echo "<td width='30%'>";
                         $ent = "toimport_entities[" . $tab["id"] . "]";
                         Entity::dropdown(array('name' => $ent, 'value' => $data['entities_id'], 'comments' => 0));
                         echo "</td>\n";
                         echo "<td width='30%'>";
                         if (!isset($data['locations_id'])) {
                             $data['locations_id'] = 0;
                         }
                         $loc = "toimport_locations[" . $tab["id"] . "]";
                         Location::dropdown(array('name' => $loc, '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 {
                         $tab['entities_id'] = $entity;
                         $rulelink = new RuleImportComputerCollection();
                         $rulelink_results = array();
                         $params = array('entities_id' => $entity, 'plugin_ocsinventoryng_ocsservers_id' => $serverId);
                         $rulelink_results = $rulelink->processAllRules(Toolbox::stripslashes_deep($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;
                             }
                             $options['width'] = "100%";
                             Computer::dropdown($options);
                         } else {
                             echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'>";
                         }
                     }
                     echo "</td></tr>\n";
                 }
                 echo "<tr class='tab_bg_1'><td colspan='" . ($advanced || $tolinked ? 10 : 7) . "' class='center'>";
                 echo "<input class='submit' type='submit' name='import_ok' value=\"" . _sx('button', 'Import', 'ocsinventoryng') . "\">\n";
                 echo "<input type=hidden name='plugin_ocsinventoryng_ocsservers_id' " . "value='{$serverId}'>";
                 echo "</td></tr>";
                 echo "</table>\n";
                 Html::closeForm();
                 if (!$tolinked) {
                     self::checkBox($target);
                 }
                 Html::printPager($start, $numrows, $target, $parameters);
             } else {
                 echo "<table class='tab_cadre_fixe'>";
                 echo "<tr><th>" . $title . "</th></tr>\n";
                 echo "<tr class='tab_bg_1'>";
                 echo "<td class='center b'>" . __('No new computer to be imported', 'ocsinventoryng') . "</td></tr>\n";
                 echo "</table>";
             }
             echo "</div>";
         } else {
             echo "<div class='center'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr><th>" . $title . "</th></tr>\n";
             echo "<tr class='tab_bg_1'>";
             echo "<td class='center b'>" . __('No new computer to be imported', 'ocsinventoryng') . "</td></tr>\n";
             echo "</table></div>";
         }
     } else {
         echo "<div class='center'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th>" . $title . "</th></tr>\n";
         echo "<tr class='tab_bg_1'>";
         echo "<td class='center b'>" . __('No new computer to be imported', 'ocsinventoryng') . "</td></tr>\n";
         echo "</table></div>";
     }
 }
예제 #3
1
 public function showResult($output_type, $limit = 0)
 {
     global $DB;
     $arrayRet = $this->execQuery($_POST);
     $result = $arrayRet['query_result'];
     $query = $arrayRet['query'];
     $nbtot = $result ? $DB->numrows($result) : 0;
     if ($limit) {
         $start = isset($_GET["start"]) ? $_GET["start"] : 0;
         if ($start >= $nbtot) {
             $start = 0;
         }
         if ($start > 0 || $start + $limit < $nbtot) {
             $result = $DB->query($query . " LIMIT {$start},{$limit}");
         }
     } else {
         $start = 0;
     }
     $nbCols = $DB->num_fields($result);
     $nbrows = $DB->numrows($result);
     $groupByRackName = true;
     if (isset($_POST['groupByRackName']) && $_POST['groupByRackName'] == "on") {
         $groupByRackName = false;
     }
     $title = date("d/m/Y H:i");
     if ($nbtot == 0) {
         echo "<div class='center'><font class='red b'>" . __("No item found") . "</font></div>";
         Html::footer();
     } else {
         if ($output_type == Search::PDF_OUTPUT_LANDSCAPE || $output_type == Search::PDF_OUTPUT_PORTRAIT) {
             include GLPI_ROOT . "/lib/ezpdf/class.ezpdf.php";
         } else {
             if ($output_type == Search::HTML_OUTPUT) {
                 echo "<div class='center'><table class='tab_cadre_fixe'>";
                 echo "<tr  class='tab_bg_1'><th>{$title}</th></tr>\n";
                 echo "<tr class='tab_bg_2 center'><td class='center'>";
                 echo "<form method='POST' action='" . $_SERVER["PHP_SELF"] . "?start={$start}' target='_blank'>\n";
                 $param = "";
                 foreach ($_POST as $key => $val) {
                     if (is_array($val)) {
                         foreach ($val as $k => $v) {
                             echo "<input type='hidden' name='" . $key . "[{$k}]' value='{$v}' >";
                             if (!empty($param)) {
                                 $param .= "&";
                             }
                             $param .= $key . "[" . $k . "]=" . urlencode($v);
                         }
                     } else {
                         echo "<input type='hidden' name='{$key}' value='{$val}' >";
                         if (!empty($param)) {
                             $param .= "&";
                         }
                         $param .= "{$key}=" . urlencode($val);
                     }
                 }
                 echo "<input type='hidden' name='result_search_reports' value='searchdone' >";
                 $param .= "&result_search_reports=searchdone&target=_blank";
                 Dropdown::showOutputFormat();
                 Html::closeForm();
                 echo "</td></tr>";
                 echo "</table></div>";
                 Html::printPager($start, $nbtot, $_SERVER['PHP_SELF'], $param);
             }
         }
     }
     if ($nbtot > 0) {
         if ($output_type == Search::HTML_OUTPUT) {
             echo "<form method='POST' action='" . $_SERVER["PHP_SELF"] . "?start={$start}'>\n";
         }
         echo Search::showHeader($output_type, $nbrows, $nbCols, true);
         $showAllFieds = true;
         $listFields = array();
         $cptField = 0;
         $showAllFieds = (!isset($_POST['cb_object_name']) || $_POST['cb_object_name'] != "on") && (!isset($_POST['cb_object_location']) || $_POST['cb_object_location'] != "on") && (!isset($_POST['cb_group']) || $_POST['cb_group'] != "on") && (!isset($_POST['cb_manufacturer']) || $_POST['cb_manufacturer'] != "on") && (!isset($_POST['cb_model']) || $_POST['cb_model'] != "on") && (!isset($_POST['cb_serial_number']) || $_POST['cb_serial_number'] != "on");
         $num = 1;
         $cptRow = 1;
         if (!$showAllFieds) {
             $this->showTitle($output_type, $num, __("Bay name", "racks"), 'name', false);
             $cptField++;
             $this->showTitle($output_type, $num, _n("Place", "Places", 1, "racks"), 'location', false);
             $cptField++;
             $this->showTitle($output_type, $num, _n("Location", "Locations", 1, "racks"), 'roomlocation', false);
             $cptField++;
             $this->showTitle($output_type, $num, __("U", "racks"), 'u', false);
             $cptField++;
             $this->showTitle($output_type, $num, __("Front", "racks") . " / " . __("Back", "racks"), 'front_rear', false);
             $cptField++;
             if (isset($_POST['cb_object_name']) && $_POST['cb_object_name'] == "on") {
                 $listFields['object_name'] = $_POST['cb_object_name'];
                 $this->showTitle($output_type, $num, __("Object name", "racks"), 'object_name', false);
                 $cptField++;
             }
             // Lieu
             if (isset($_POST['cb_object_location']) && $_POST['cb_object_location'] == "on") {
                 $listFields['object_location'] = $_POST['cb_object_location'];
                 $this->showTitle($output_type, $num, __("Object location", "racks"), 'object_location', false);
                 $cptField++;
             }
             // Groupe
             if (isset($_POST['cb_group']) && $_POST['cb_group'] == "on") {
                 $listFields['group'] = $_POST['cb_group'];
                 $this->showTitle($output_type, $num, __("Group"), 'roomlocation', false);
                 $cptField++;
             }
             // Fabricant
             if (isset($_POST['cb_manufacturer']) && $_POST['cb_manufacturer'] == "on") {
                 $listFields['manufacturer'] = $_POST['cb_manufacturer'];
                 $this->showTitle($output_type, $num, __("Manufacturer"), 'manufacturer', false);
                 $cptField++;
             }
             // Modèle
             if (isset($_POST['cb_model']) && $_POST['cb_model'] == "on") {
                 $listFields['model'] = $_POST['cb_model'];
                 $this->showTitle($output_type, $num, __("Model"), 'model', false);
                 $cptField++;
             }
             // Numéro de série
             if (isset($_POST['cb_serial_number']) && $_POST['cb_serial_number'] == "on") {
                 $listFields['serial_number'] = $_POST['cb_serial_number'];
                 $this->showTitle($output_type, $num, __("Serial number", "racks"), 'group', false);
                 $cptField++;
             }
         } else {
             $this->showTitle($output_type, $num, __("Bay name", "racks"), 'rack_name', false);
             $listFields['rack_name'] = true;
             $this->showTitle($output_type, $num, __("Place", "racks"), 'location', false);
             $listFields['location'] = true;
             $this->showTitle($output_type, $num, __("Location", "racks"), 'roomlocation', false);
             $listFields['roomlocation'] = true;
             $this->showTitle($output_type, $num, __("U", "racks"), 'u', false);
             $listFields['u'] = true;
             $this->showTitle($output_type, $num, __("Front", "racks") . " / " . __("Back", "racks"), 'front_rear', false);
             $listFields['front_rear'] = true;
             $this->showTitle($output_type, $num, __("Object name", "racks"), 'object_name', false);
             $listFields['object_name'] = true;
             $this->showTitle($output_type, $num, __("Object location", "racks"), 'object_location', false);
             $listFields['object_location'] = true;
             $this->showTitle($output_type, $num, __("Group"), false);
             $listFields['group'] = true;
             $this->showTitle($output_type, $num, __("Type"), 'type', false);
             $listFields['type'] = true;
             $this->showTitle($output_type, $num, __("Manufacturer"), 'manufacturer', false);
             $listFields['manufacturer'] = true;
             $this->showTitle($output_type, $num, __("Model"), 'model', false);
             $listFields['model'] = true;
             $this->showTitle($output_type, $num, __("Serial number", "racks"), 'serial_number', false);
             $listFields['serial_number'] = true;
             $this->showTitle($output_type, $num, __("Inventory number"), 'other_serial', false);
             $listFields['other_serial'] = true;
             $cptField = 13;
         }
         echo Search::showEndLine($output_type);
         $num = 1;
         $currentRack = -1;
         while ($row = $DB->fetch_array($result)) {
             // itemtype
             $itemtype = $row['itemtype'];
             $num = 1;
             $cptRow++;
             echo Search::showNewLine($output_type);
             if (isset($row['itemtype']) && $row['itemtype'] != "") {
                 $class = substr($itemtype, 0, -5);
                 $item = new $class();
                 $table = getTableForItemType($class);
                 $r = $DB->query("SELECT * FROM `" . $table . "` WHERE `id` = '" . $row["items_id"] . "' ");
                 $device = $DB->fetch_array($r);
             }
             // nom
             $link = Toolbox::getItemTypeFormURL("PluginRacksRack");
             if ($groupByRackName || $currentRack != $row['id']) {
                 if ($output_type == Search::HTML_OUTPUT) {
                     echo Search::showItem($output_type, "<a href=\"" . $link . "?id=" . $row["id"] . "\">" . $row["name"] . "</a>", $num, $cptRow);
                 } else {
                     echo Search::showItem($output_type, $row["name"], $num, $cptRow);
                 }
             } else {
                 echo Search::showItem($output_type, "&nbsp;", $num, $cptRow);
             }
             // lieu
             if ($groupByRackName || $currentRack != $row['id']) {
                 $tmpId = $row['locations_id'];
                 $tmpObj = new Location();
                 $tmpObj->getFromDB($tmpId);
                 if (isset($tmpObj->fields['name'])) {
                     echo Search::showItem($output_type, $tmpObj->fields['name'], $num, $cptRow);
                 } else {
                     echo Search::showItem($output_type, "&nbsp;", $num, $cptRow);
                 }
             } else {
                 echo Search::showItem($output_type, "&nbsp;", $num, $cptRow);
             }
             // Emplacement
             if ($groupByRackName || $currentRack != $row['id']) {
                 $tmpId = $row['plugin_racks_roomlocations_id'];
                 $tmpObj = new PluginRacksRoomLocation();
                 $tmpObj->getFromDB($tmpId);
                 if (isset($tmpObj->fields['name'])) {
                     echo Search::showItem($output_type, $tmpObj->fields['name'], $num, $cptRow);
                 } else {
                     echo Search::showItem($output_type, '&nbsp;', $num, $cptRow);
                 }
             } else {
                 echo Search::showItem($output_type, "&nbsp;", $num, $cptRow);
             }
             if (isset($row['itemtype']) && $row['itemtype'] != "") {
                 // U
                 if (isset($row['position']) && $row['position'] != "") {
                     echo Search::showItem($output_type, $row['position'], $num, $cptRow);
                 } else {
                     echo Search::showItem($output_type, "&nbsp;", $num, $cptRow);
                 }
                 // avant / arrière
                 if ($row['faces_id'] == 1) {
                     echo Search::showItem($output_type, __("Front", "racks"), $num, $cptRow);
                 } else {
                     echo Search::showItem($output_type, __("Back", "racks"), $num, $cptRow);
                 }
                 // Nom de l'objet
                 if (array_key_exists("object_name", $listFields)) {
                     $link = Toolbox::getItemTypeFormURL(substr($itemtype, 0, -5));
                     if ($itemtype != 'PluginRacksOtherModel') {
                         if ($output_type == Search::HTML_OUTPUT) {
                             echo Search::showItem($output_type, "<a href=\"" . $link . "?id=" . $row["items_id"] . "\">" . $device["name"] . "</a>", $num, $cptRow);
                         } else {
                             echo Search::showItem($output_type, $device["name"], $num, $cptRow);
                         }
                     } else {
                         echo Search::showItem($output_type, $device["name"], $num, $cptRow);
                     }
                 }
                 // Lieu de l'objet
                 if (array_key_exists("object_location", $listFields)) {
                     if ($itemtype != 'PluginRacksOtherModel') {
                         echo Search::showItem($output_type, Dropdown::getDropdownName("glpi_locations", $device["locations_id"]), $num, $cptRow);
                     } else {
                         echo Search::showItem($output_type, Dropdown::EMPTY_VALUE, $num, $cptRow);
                     }
                 }
                 // Groupe
                 if (array_key_exists("group", $listFields)) {
                     // Groupe
                     if ($itemtype != 'PluginRacksOtherModel') {
                         echo Search::showItem($output_type, Dropdown::getDropdownName("glpi_groups", $device["groups_id_tech"]), $num, $cptRow);
                     } else {
                         echo Search::showItem($output_type, Dropdown::EMPTY_VALUE, $num, $cptRow);
                     }
                 }
                 // type
                 if (array_key_exists("type", $listFields)) {
                     echo Search::showItem($output_type, $item->getTypeName(), $num, $cptRow);
                 }
                 // fabricant
                 if (array_key_exists("manufacturer", $listFields)) {
                     if ($itemtype != 'PluginRacksOtherModel') {
                         echo Search::showItem($output_type, Dropdown::getDropdownName("glpi_manufacturers", $device["manufacturers_id"]), $num, $cptRow);
                     } else {
                         echo Search::showItem($output_type, Dropdown::EMPTY_VALUE, $num, $cptRow);
                     }
                 }
                 // modèle //TODO = model du rack => model des objets
                 if (array_key_exists("model", $listFields)) {
                     if ($itemtype != 'PluginRacksOtherModel') {
                         $model_table = getTableForItemType($itemtype);
                         $modelfield = getForeignKeyFieldForTable(getTableForItemType($itemtype));
                         echo Search::showItem($output_type, Dropdown::getDropdownName($model_table, $device[$modelfield]), $num, $cptRow);
                     } else {
                         echo Search::showItem($output_type, Dropdown::EMPTY_VALUE, $num, $cptRow);
                     }
                 }
                 // numéro de série
                 if (array_key_exists("serial_number", $listFields)) {
                     if ($itemtype != 'PluginRacksOtherModel') {
                         echo Search::showItem($output_type, $device['serial'], $num, $cptRow);
                     } else {
                         echo Search::showItem($output_type, Dropdown::EMPTY_VALUE, $num, $cptRow);
                     }
                 }
                 // numéro d'inventaire
                 if (array_key_exists("other_serial", $listFields)) {
                     if ($itemtype != 'PluginRacksOtherModel') {
                         echo Search::showItem($output_type, $device['otherserial'], $num, $cptRow);
                     } else {
                         echo Search::showItem($output_type, Dropdown::EMPTY_VALUE, $num, $cptRow);
                     }
                 }
                 $currentRack = $row['id'];
             } else {
                 for ($k = 0; $k < $cptField - 3; $k++) {
                     echo Search::showItem($output_type, "&nbsp;", $num, $cptRow, "");
                 }
             }
             echo Search::showEndLine($output_type);
         }
         if ($output_type == Search::HTML_OUTPUT) {
             Html::closeForm();
         }
         echo Search::showFooter($output_type, $title);
     }
 }
예제 #4
1
 /**
  * Display datas extracted from DB
  *
  * @param $data array of search datas prepared to get datas
  *
  * @return nothing
  **/
 static function displayDatas(array &$data)
 {
     global $CFG_GLPI;
     $item = null;
     if (class_exists($data['itemtype'])) {
         $item = new $data['itemtype']();
     }
     $rand = mt_rand();
     if (!isset($data['data']) || !isset($data['data']['totalcount'])) {
         return false;
     }
     // Contruct Pager parameters
     $globallinkto = Toolbox::append_params(array('criteria' => Toolbox::stripslashes_deep($data['search']['criteria']), 'metacriteria' => Toolbox::stripslashes_deep($data['search']['metacriteria'])), '&amp;');
     $parameters = "sort=" . $data['search']['sort'] . "&amp;order=" . $data['search']['order'] . '&amp;' . $globallinkto;
     if (isset($_GET['_in_modal'])) {
         $parameters .= "&amp;_in_modal=1";
     }
     // Global search header
     if ($data['display_type'] == self::GLOBAL_SEARCH) {
         if ($data['item']) {
             echo "<div class='center'><h2>" . $data['item']->getTypeName();
             // More items
             if ($data['data']['totalcount'] > $data['search']['start'] + self::GLOBAL_DISPLAY_COUNT) {
                 echo " <a href='" . $data['search']['target'] . "?{$parameters}'>" . __('All') . "</a>";
             }
             echo "</h2></div>\n";
         } else {
             return false;
         }
     }
     // If the begin of the view is before the number of items
     if ($data['data']['count'] > 0) {
         // Display pager only for HTML
         if ($data['display_type'] == self::HTML_OUTPUT) {
             // For plugin add new parameter if available
             if ($plug = isPluginItemType($data['itemtype'])) {
                 $function = 'plugin_' . $plug['plugin'] . '_addParamFordynamicReport';
                 if (function_exists($function)) {
                     $out = $function($data['itemtype']);
                     if (is_array($out) && count($out)) {
                         $parameters .= Toolbox::append_params($out, '&amp;');
                     }
                 }
             }
             $search_config_top = "";
             $search_config_bottom = "";
             if (!isset($_GET['_in_modal']) && Session::haveRightsOr('search_config', array(DisplayPreference::PERSONAL, DisplayPreference::GENERAL))) {
                 $search_config_top = $search_config_bottom = "<div class='pager_controls'><img alt=\"" . __s('Select default items to show') . "\" title=\"" . __s('Select default items to show') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' ";
                 $search_config_top .= " class='pointer' onClick=\"";
                 $search_config_top .= Html::jsGetElementbyID('search_config_top') . ".dialog('open');\">";
                 $search_config_bottom .= " class='pointer' onClick=\"";
                 $search_config_bottom .= Html::jsGetElementbyID('search_config_bottom') . ".dialog('open');\">";
                 $search_config_top .= Ajax::createIframeModalWindow('search_config_top', $CFG_GLPI["root_doc"] . "/front/displaypreference.form.php?itemtype=" . $data['itemtype'], array('title' => __('Select default items to show'), 'reloadonclose' => true, 'display' => false));
                 $search_config_bottom .= Ajax::createIframeModalWindow('search_config_bottom', $CFG_GLPI["root_doc"] . "/front/displaypreference.form.php?itemtype=" . $data['itemtype'], array('title' => __('Select default items to show'), 'reloadonclose' => true, 'display' => false));
             }
             if ($item !== null && $item->maybeDeleted()) {
                 $delete_ctrl = self::isDeletedSwitch($data['search']['is_deleted']);
                 $search_config_top .= $delete_ctrl;
             }
             Html::printPager($data['search']['start'], $data['data']['totalcount'], $data['search']['target'], $parameters, $data['itemtype'], 0, $search_config_top);
             $search_config_top .= "</div>";
             $search_config_bottom .= "</div>";
         }
         // Define begin and end var for loop
         // Search case
         $begin_display = $data['data']['begin'];
         $end_display = $data['data']['end'];
         // Form to massive actions
         $isadmin = $data['item'] && $data['item']->canUpdate();
         if (!$isadmin && InfoCom::canApplyOn($data['itemtype'])) {
             $isadmin = Infocom::canUpdate() || Infocom::canCreate();
         }
         if ($data['itemtype'] != 'AllAssets') {
             $showmassiveactions = count(MassiveAction::getAllMassiveActions($data['item'], $data['search']['is_deleted']));
         } else {
             $showmassiveactions = true;
         }
         $massformid = 'massform' . $data['itemtype'];
         if ($showmassiveactions && $data['display_type'] == self::HTML_OUTPUT) {
             Html::openMassiveActionsForm($massformid);
             $massiveactionparams = $data['search']['massiveactionparams'];
             $massiveactionparams['num_displayed'] = $end_display - $begin_display;
             $massiveactionparams['fixed'] = false;
             $massiveactionparams['is_deleted'] = $data['search']['is_deleted'];
             $massiveactionparams['container'] = $massformid;
             Html::showMassiveActions($massiveactionparams);
         }
         // Compute number of columns to display
         // Add toview elements
         $nbcols = count($data['data']['cols']);
         if ($data['display_type'] == self::HTML_OUTPUT && $showmassiveactions) {
             // HTML display - massive modif
             $nbcols++;
         }
         // Display List Header
         echo self::showHeader($data['display_type'], $end_display - $begin_display + 1, $nbcols);
         // New Line for Header Items Line
         $headers_line = '';
         $headers_line_top = '';
         $headers_line_bottom = '';
         $headers_line_top .= self::showBeginHeader($data['display_type']);
         $headers_line_top .= self::showNewLine($data['display_type']);
         if ($data['display_type'] == self::HTML_OUTPUT) {
             //          $headers_line_bottom .= self::showBeginHeader($data['display_type']);
             $headers_line_bottom .= self::showNewLine($data['display_type']);
         }
         $header_num = 1;
         if ($data['display_type'] == self::HTML_OUTPUT && $showmassiveactions) {
             // HTML display - massive modif
             $headers_line_top .= self::showHeaderItem($data['display_type'], Html::getCheckAllAsCheckbox($massformid), $header_num, "", 0, $data['search']['order']);
             if ($data['display_type'] == self::HTML_OUTPUT) {
                 $headers_line_bottom .= self::showHeaderItem($data['display_type'], Html::getCheckAllAsCheckbox($massformid), $header_num, "", 0, $data['search']['order']);
             }
         }
         // Display column Headers for toview items
         $metanames = array();
         foreach ($data['data']['cols'] as $key => $val) {
             $linkto = '';
             if (!$val['meta'] && (!isset($val['searchopt']['nosort']) || !$val['searchopt']['nosort'])) {
                 $linkto = $data['search']['target'] . (strpos($data['search']['target'], '?') ? '&amp;' : '?') . "itemtype=" . $data['itemtype'] . "&amp;sort=" . $val['id'] . "&amp;order=" . ($data['search']['order'] == "ASC" ? "DESC" : "ASC") . "&amp;start=" . $data['search']['start'] . "&amp;" . $globallinkto;
             }
             $name = $val["name"];
             // prefix by group name (corresponding to optgroup in dropdown) if exists
             if (isset($val['groupname'])) {
                 $name = $val['groupname'] . " - " . $name;
             }
             // Not main itemtype add itemtype to display
             if ($data['itemtype'] != $val['itemtype']) {
                 if (!isset($metanames[$val['itemtype']])) {
                     if ($metaitem = getItemForItemtype($val['itemtype'])) {
                         $metanames[$val['itemtype']] = $metaitem->getTypeName();
                     }
                 }
                 $name = sprintf(__('%1$s - %2$s'), $metanames[$val['itemtype']], $val["name"]);
             }
             $headers_line .= self::showHeaderItem($data['display_type'], $name, $header_num, $linkto, !$val['meta'] && $data['search']['sort'] == $val['id'], $data['search']['order']);
         }
         // Add specific column Header
         if (isset($CFG_GLPI["union_search_type"][$data['itemtype']])) {
             $headers_line .= self::showHeaderItem($data['display_type'], __('Item type'), $header_num);
         }
         // End Line for column headers
         $headers_line .= self::showEndLine($data['display_type']);
         $headers_line_top .= $headers_line;
         if ($data['display_type'] == self::HTML_OUTPUT) {
             $headers_line_bottom .= $headers_line;
         }
         $headers_line_top .= self::showEndHeader($data['display_type']);
         //          $headers_line_bottom .= self::showEndHeader($data['display_type']);
         echo $headers_line_top;
         // Init list of items displayed
         if ($data['display_type'] == self::HTML_OUTPUT) {
             Session::initNavigateListItems($data['itemtype']);
         }
         // Num of the row (1=header_line)
         $row_num = 1;
         $massiveaction_field = 'id';
         if ($data['itemtype'] != 'AllAssets' && isset($CFG_GLPI["union_search_type"][$data['itemtype']])) {
             $massiveaction_field = 'refID';
         }
         $typenames = array();
         // Display Loop
         foreach ($data['data']['rows'] as $rowkey => $row) {
             // Column num
             $item_num = 1;
             $row_num++;
             // New line
             echo self::showNewLine($data['display_type'], $row_num % 2, $data['search']['is_deleted']);
             $current_type = isset($row['TYPE']) ? $row['TYPE'] : $data['itemtype'];
             $massiveaction_type = $current_type;
             if ($data['itemtype'] != 'AllAssets' && isset($CFG_GLPI["union_search_type"][$data['itemtype']])) {
                 $massiveaction_type = $data['itemtype'];
             }
             // Add item in item list
             Session::addToNavigateListItems($current_type, $row["id"]);
             if ($data['display_type'] == self::HTML_OUTPUT && $showmassiveactions) {
                 // HTML display - massive modif
                 $tmpcheck = "";
                 if ($data['itemtype'] == 'Entity' && !in_array($row["id"], $_SESSION["glpiactiveentities"])) {
                     $tmpcheck = "&nbsp;";
                 } else {
                     if ($data['item'] instanceof CommonDBTM && $data['item']->maybeRecursive() && !in_array($row["entities_id"], $_SESSION["glpiactiveentities"])) {
                         $tmpcheck = "&nbsp;";
                     } else {
                         $tmpcheck = Html::getMassiveActionCheckBox($massiveaction_type, $row[$massiveaction_field]);
                     }
                 }
                 echo self::showItem($data['display_type'], $tmpcheck, $item_num, $row_num, "width='10'");
             }
             // Print other toview items
             foreach ($data['data']['cols'] as $colkey => $col) {
                 if (!$col['meta']) {
                     echo self::showItem($data['display_type'], $row[$colkey]['displayname'], $item_num, $row_num, self::displayConfigItem($data['itemtype'], $col['id'], $row, $colkey));
                 } else {
                     // META case
                     echo self::showItem($data['display_type'], $row[$colkey]['displayname'], $item_num, $row_num);
                 }
             }
             if (isset($CFG_GLPI["union_search_type"][$data['itemtype']])) {
                 if (!isset($typenames[$row["TYPE"]])) {
                     if ($itemtmp = getItemForItemtype($row["TYPE"])) {
                         $typenames[$row["TYPE"]] = $itemtmp->getTypeName();
                     }
                 }
                 echo self::showItem($data['display_type'], $typenames[$row["TYPE"]], $item_num, $row_num);
             }
             // End Line
             echo self::showEndLine($data['display_type']);
         }
         // Create title
         $title = '';
         if ($data['display_type'] == self::PDF_OUTPUT_LANDSCAPE || $data['display_type'] == self::PDF_OUTPUT_PORTRAIT) {
             $title = self::computeTitle($data);
         }
         if ($data['display_type'] == self::HTML_OUTPUT) {
             echo $headers_line_bottom;
         }
         // Display footer
         echo self::showFooter($data['display_type'], $title);
         // Delete selected item
         if ($data['display_type'] == self::HTML_OUTPUT) {
             if ($showmassiveactions) {
                 $massiveactionparams['ontop'] = false;
                 Html::showMassiveActions($massiveactionparams);
                 // End form for delete item
                 Html::closeForm();
             } else {
                 echo "<br>";
             }
         }
         if ($data['display_type'] == self::HTML_OUTPUT) {
             // In case of HTML display
             Html::printPager($data['search']['start'], $data['data']['totalcount'], $data['search']['target'], $parameters, '', 0, $search_config_bottom);
         }
     } else {
         if ($item !== null && $item->maybeDeleted()) {
             echo "<div class='center'>" . self::isDeletedSwitch($data['search']['is_deleted']) . "</div><br/>";
         }
         echo self::showError($data['display_type']);
     }
 }
예제 #5
1
 function showMinimalList($params)
 {
     global $DB, $CFG_GLPI;
     // Instanciate an object to access method
     $item = NULL;
     $itemtype = $this->getType();
     $itemtable = $this->getTable();
     if (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 defautlt 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 = Toolbox::getItemTypeSearchURL($itemtype);
     $target = $CFG_GLPI["root_doc"] . "/plugins/resources/front/resourceresting.php";
     $limitsearchopt = Search::getCleanedOptions("PluginResourcesResourceResting");
     $LIST_LIMIT = $_SESSION['glpilist_limit'];
     // Set display type for export if define
     $output_type = Search::HTML_OUTPUT;
     if (isset($_GET['display_type'])) {
         $output_type = $_GET['display_type'];
         // Limit to 10 element
         if ($_GET['display_type'] == Search::GLOBAL_SEARCH) {
             $LIST_LIMIT = Search::GLOBAL_DISPLAY_COUNT;
         }
     }
     $PluginResourcesResource = new PluginResourcesResource();
     $entity_restrict = $PluginResourcesResource->isEntityAssign();
     // Get the items to display
     $toview = Search::addDefaultToView($itemtype);
     // Add items to display depending of personal prefs
     $displaypref = DisplayPreference::getForTypeUser("PluginResourcesResourceResting", Session::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']);
     }
     // Clean toview array
     $toview = array_unique($toview);
     foreach ($toview as $key => $val) {
         if (!isset($limitsearchopt[$val])) {
             unset($toview[$key]);
         }
     }
     $toview_count = count($toview);
     //// 1 - SELECT
     $query = "SELECT " . Search::addDefaultSelect($itemtype);
     // Add select for all toview item
     foreach ($toview as $key => $val) {
         $query .= Search::addSelect($itemtype, $val, $key, 0);
     }
     $query .= "`" . $itemtable . "`.`id` AS id ";
     //// 2 - FROM AND LEFT JOIN
     // Set reference table
     $query .= " 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 = Search::addDefaultJoin($itemtype, $itemtable, $already_link_tables);
     $query .= $COMMONLEFTJOIN;
     $searchopt = array();
     $searchopt[$itemtype] =& Search::getOptions($itemtype);
     // Add all table for toview items
     foreach ($toview as $key => $val) {
         $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$val]["table"], $searchopt[$itemtype][$val]["linkfield"]);
     }
     // 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)) {
                 $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt[$itemtype][$key]["table"], $searchopt[$itemtype][$key]["linkfield"]);
             }
         }
     }
     //// 3 - WHERE
     // default string
     $COMMONWHERE = Search::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"]["PluginResourcesResource"])) {
                 // Will be replace below in Union/Recursivity Hack
                 $COMMONWHERE .= $LINK . " ENTITYRESTRICT ";
             } else {
                 $COMMONWHERE .= getEntitiesRestrictRequest($LINK, "glpi_plugin_resources_resources", '', '', $PluginResourcesResource->maybeRecursive());
             }
         }
     }
     ///R�cup�ration des groupes de l'utilisateur connect�
     $who = Session::getLoginUserID();
     if (!plugin_resources_haveRight("all", "r")) {
         $LINK = " AND ";
         if ($first) {
             $LINK = " ";
             $first = false;
         }
         $COMMONWHERE .= $LINK . "(`glpi_plugin_resources_resources`.`users_id_recipient` = '{$who}' OR `glpi_plugin_resources_resources`.`users_id` = '{$who}') ";
     }
     $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 .= Search::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 .= Search::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 .= Search::addWhere($tmplink, $NOT, $itemtype, $key2, $p['searchtype'][$key], $p['contains'][$key]);
                             }
                         }
                     }
                     $WHERE .= " ) ";
                 }
             }
         }
     }
     if (!empty($WHERE) || !empty($COMMONWHERE)) {
         if (!empty($COMMONWHERE)) {
             $WHERE = ' WHERE ' . $COMMONWHERE . (!empty($WHERE) ? ' AND ( ' . $WHERE . ' )' : '');
         } else {
             $WHERE = ' WHERE ' . $WHERE . ' ';
         }
         $first = false;
     }
     $query .= $WHERE;
     //// 7 - Manage GROUP BY
     $GROUPBY = "";
     // Meta Search / Search All / Count tickets
     if (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`";
             }
         }
     }
     $query .= $GROUPBY;
     //// 4 - ORDER
     $ORDER = " ORDER BY `id` ";
     foreach ($toview as $key => $val) {
         if ($p['sort'] == $val) {
             $ORDER = Search::addOrderBy($itemtype, $p['sort'], $p['order'], $key);
         }
     }
     $query .= $ORDER;
     // Get it from database
     if ($result = $DB->query($query)) {
         $numrows = $DB->numrows($result);
         $globallinkto = Search::getArrayUrlLink("field", $p['field']) . Search::getArrayUrlLink("link", $p['link']) . Search::getArrayUrlLink("contains", $p['contains']) . Search::getArrayUrlLink("field2", $p['field2']) . Search::getArrayUrlLink("contains2", $p['contains2']) . Search::getArrayUrlLink("itemtype2", $p['itemtype2']) . Search::getArrayUrlLink("link2", $p['link2']);
         $parameters = "sort=" . $p['sort'] . "&amp;order=" . $p['order'] . $globallinkto;
         if ($output_type == Search::GLOBAL_SEARCH) {
             if (class_exists($itemtype)) {
                 echo "<div class='center'><h2>" . $this->getTypeName();
                 // More items
                 if ($numrows > $p['start'] + Search::GLOBAL_DISPLAY_COUNT) {
                     echo " <a href='{$target}?{$parameters}'>" . __('All') . "</a>";
                 }
                 echo "</h2></div>\n";
             } else {
                 return false;
             }
         }
         if ($p['start'] < $numrows) {
             // Pager
             if ($output_type == Search::HTML_OUTPUT) {
                 Html::printPager($p['start'], $numrows, $target, $parameters, $itemtype);
             }
             //massive action
             $sel = "";
             if (isset($_GET["select"]) && $_GET["select"] == "all") {
                 $sel = "checked";
             }
             // Add toview elements
             $nbcols = $toview_count;
             if ($output_type == Search::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;
             // Export All case
             if ($p['export_all']) {
                 $begin_display = 0;
                 $end_display = $numrows;
             }
             // Display List Header
             echo Search::showHeader($output_type, $end_display - $begin_display + 1, $nbcols);
             $header_num = 1;
             // Display column Headers for toview items
             echo Search::showNewLine($output_type);
             // 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 Search::showHeaderItem($output_type, $searchopt[$itemtype][$val]["name"], $header_num, $linkto, $p['sort'] == $val, $p['order']);
             }
             // End Line for column headers
             echo Search::showEndLine($output_type);
             $DB->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 == Search::HTML_OUTPUT) {
                 Session::initNavigateListItems($itemtype);
             }
             // Num of the row (1=header_line)
             $row_num = 1;
             // Display Loop
             while ($i < $numrows && $i < $end_display) {
                 $item_num = 1;
                 $data = $DB->fetch_array($result);
                 $i++;
                 $row_num++;
                 echo Search::showNewLine($output_type, $i % 2);
                 Session::addToNavigateListItems($itemtype, $data['id']);
                 foreach ($toview as $key => $val) {
                     echo Search::showItem($output_type, Search::giveItem($itemtype, $val, $data, $key), $item_num, $row_num, Search::displayConfigItem($itemtype, $val, $data, $key));
                 }
                 echo Search::showEndLine($output_type);
             }
             // Close Table
             $title = "";
             // Create title
             if ($output_type == Search::PDF_OUTPUT_PORTRAIT || $output_type == Search::PDF_OUTPUT_LANDSCAPE) {
                 $title .= __('List of non contract periods', 'resources');
             }
             // Display footer
             echo Search::showFooter($output_type, $title);
             // Pager
             if ($output_type == Search::HTML_OUTPUT) {
                 echo "<br>";
                 Html::printPager($p['start'], $numrows, $target, $parameters);
             }
         } else {
             echo Search::showError($output_type);
         }
     }
 }
예제 #6
1
echo "<td class='right'>" . __('Show graphics') . "</td>";
echo "<td rowspan='2' class='center'>";
echo "<input type='submit' class='submit' name='submit' value=\"" . __s('Display report') . "\"></td>" . "</tr>";
echo "<tr class='tab_bg_2'><td class='right'>" . __('End date') . "</td><td>";
Html::showDateField("date2", array('value' => $_GET["date2"]));
echo "</td><td class='center'>";
echo "<input type='hidden' name='value2' value='" . $_GET["value2"] . "'>";
Dropdown::showYesNo('showgraph', $_GET['showgraph']);
echo "</td></tr>";
echo "</table>";
// form using GET method : CRSF not needed
echo "</form>";
echo "</div>";
$val = Stat::getItems($_GET["itemtype"], $_GET["date1"], $_GET["date2"], $_GET["type"], $_GET["value2"]);
$params = array('type' => $_GET["type"], 'date1' => $_GET["date1"], 'date2' => $_GET["date2"], 'value2' => $_GET["value2"], 'start' => $_GET["start"]);
Html::printPager($_GET['start'], count($val), $CFG_GLPI['root_doc'] . '/front/stat.tracking.php', "date1=" . $_GET["date1"] . "&amp;date2=" . $_GET["date2"] . "&amp;type=" . $_GET["type"] . "&amp;showgraph=" . $_GET["showgraph"] . "&amp;itemtype=" . $_GET["itemtype"] . "&amp;value2=" . $_GET['value2'], 'Stat', $params);
if (!$_GET['showgraph']) {
    Stat::showTable($_GET["itemtype"], $_GET["type"], $_GET["date1"], $_GET["date2"], $_GET['start'], $val, $_GET['value2']);
} else {
    $data = Stat::getDatas($_GET["itemtype"], $_GET["type"], $_GET["date1"], $_GET["date2"], $_GET['start'], $val, $_GET['value2']);
    if (isset($data['opened']) && is_array($data['opened'])) {
        foreach ($data['opened'] as $key => $val) {
            $newkey = Toolbox::unclean_cross_side_scripting_deep(Html::clean($key));
            $cleandata[$newkey] = $val;
        }
        Stat::showGraph(array(__('Number opened') => $cleandata), array('title' => __('Number opened'), 'showtotal' => 1, 'unit' => $item->getTypeName(Session::getPluralNumber()), 'type' => 'pie'));
    }
    if (isset($data['solved']) && is_array($data['solved'])) {
        foreach ($data['solved'] as $key => $val) {
            $newkey = Toolbox::unclean_cross_side_scripting_deep(Html::clean($key));
            $cleandata[$newkey] = $val;
예제 #7
0
 /**
  * Print out list kb item
  *
  * @param $options            $_GET
  * @param $type      string   search type : browse / search (default search)
  **/
 static function showList($options, $type = 'search')
 {
     global $DB, $CFG_GLPI;
     // Default values of parameters
     $params['faq'] = !Session::haveRight(self::$rightname, READ);
     $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;
         }
     }
     $ki = new self();
     switch ($type) {
         case 'myunpublished':
             if (!Session::haveRightsOr(self::$rightname, array(UPDATE, self::PUBLISHFAQ))) {
                 return false;
             }
             break;
         case 'allunpublished':
             if (!Session::haveRight(self::$rightname, self::KNOWBASEADMIN)) {
                 return false;
             }
             break;
         default:
             break;
     }
     if (!$params["start"]) {
         $params["start"] = 0;
     }
     $query = self::getListRequest($params, $type);
     // Get it from database
     if ($result = $DB->query($query)) {
         $KbCategory = new KnowbaseItemCategory();
         $title = "";
         if ($KbCategory->getFromDB($params["knowbaseitemcategories_id"])) {
             $title = empty($KbCategory->fields['name']) ? "(" . $params['knowbaseitemcategories_id'] . ")" : $KbCategory->fields['name'];
             $title = sprintf(__('%1$s: %2$s'), __('Category'), $title);
         }
         Session::initNavigateListItems('KnowbaseItem', $title);
         $numrows = $DB->numrows($result);
         $list_limit = $_SESSION['glpilist_limit'];
         $showwriter = in_array($type, array('myunpublished', 'allunpublished', 'allmy'));
         // 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 = Search::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=" . $params['faq'];
             if (isset($options['item_itemtype']) && isset($options['item_items_id'])) {
                 $parameters .= "&amp;item_items_id=" . $options['item_items_id'] . "&amp;item_itemtype=" . $options['item_itemtype'];
             }
             if ($output_type == Search::HTML_OUTPUT) {
                 Html::printPager($params['start'], $numrows, Toolbox::getItemTypeSearchURL('KnowbaseItem'), $parameters, 'KnowbaseItem');
             }
             $nbcols = 1;
             // Display List Header
             echo Search::showHeader($output_type, $numrows_limit + 1, $nbcols);
             echo Search::showNewLine($output_type);
             $header_num = 1;
             echo Search::showHeaderItem($output_type, __('Subject'), $header_num);
             if ($output_type != Search::HTML_OUTPUT) {
                 echo Search::showHeaderItem($output_type, __('Content'), $header_num);
             }
             if ($showwriter) {
                 echo Search::showHeaderItem($output_type, __('Writer'), $header_num);
             }
             echo Search::showHeaderItem($output_type, __('Category'), $header_num);
             if (isset($options['item_itemtype']) && isset($options['item_items_id']) && $output_type == Search::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_assoc($result_limit);
                 Session::addToNavigateListItems('KnowbaseItem', $data["id"]);
                 // Column num
                 $item_num = 1;
                 $row_num++;
                 echo Search::showNewLine($output_type, $i % 2);
                 $item = new self();
                 $item->getFromDB($data["id"]);
                 $name = $data["name"];
                 $answer = $data["answer"];
                 // Manage translations
                 if (isset($data['transname']) && !empty($data['transname'])) {
                     $name = $data["transname"];
                 }
                 if (isset($data['transanswer']) && !empty($data['transanswer'])) {
                     $answer = $data["transanswer"];
                 }
                 if ($output_type == Search::HTML_OUTPUT) {
                     $toadd = '';
                     if (isset($options['item_itemtype']) && isset($options['item_items_id'])) {
                         $href = " href='#' onClick=\"" . Html::jsGetElementbyID('kbshow' . $data["id"]) . ".dialog('open');\"";
                         $toadd = Ajax::createIframeModalWindow('kbshow' . $data["id"], $CFG_GLPI["root_doc"] . "/front/knowbaseitem.form.php?id=" . $data["id"], array('display' => false));
                     } else {
                         $href = " href=\"" . $CFG_GLPI['root_doc'] . "/front/knowbaseitem.form.php?id=" . $data["id"] . "\" ";
                     }
                     echo Search::showItem($output_type, "<div class='kb'>{$toadd}<a " . ($data['is_faq'] ? " class='pubfaq' title='" . __("This item is part of the FAQ") . "' " : " class='knowbase' ") . " {$href}>" . Html::resume_text($name, 80) . "</a></div>\n                                          <div class='kb_resume'>" . Html::resume_text(Html::clean(Toolbox::unclean_cross_side_scripting_deep($answer)), 600) . "</div>", $item_num, $row_num);
                 } else {
                     echo Search::showItem($output_type, $name, $item_num, $row_num);
                     echo Search::showItem($output_type, Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($answer, ENT_QUOTES, "UTF-8"))), $item_num, $row_num);
                 }
                 $showuserlink = 0;
                 if (Session::haveRight('user', READ)) {
                     $showuserlink = 1;
                 }
                 if ($showwriter) {
                     echo Search::showItem($output_type, getUserName($data["users_id"], $showuserlink), $item_num, $row_num);
                 }
                 $categ = $data["category"];
                 if ($output_type == Search::HTML_OUTPUT) {
                     $cathref = $ki->getSearchURL() . "?knowbaseitemcategories_id=" . $data["knowbaseitemcategories_id"] . '&amp;forcetab=Knowbase$2';
                     $categ = "<a href='{$cathref}'>" . $categ . '</a>';
                 }
                 echo Search::showItem($output_type, $categ, $item_num, $row_num);
                 if (isset($options['item_itemtype']) && isset($options['item_items_id']) && $output_type == Search::HTML_OUTPUT) {
                     $forcetab = $options['item_itemtype'];
                     if (!$_SESSION['glpiticket_timeline'] || $_SESSION['glpiticket_timeline_keep_replaced_tabs']) {
                         $forcetab .= '$2';
                         //Solution tab
                     } else {
                         $forcetab .= '$1';
                         //Timeline tab
                     }
                     $content = "<a href='" . Toolbox::getItemTypeFormURL($options['item_itemtype']) . "?load_kb_sol=" . $data['id'] . "&amp;id=" . $options['item_items_id'] . "&amp;forcetab=" . $forcetab . "'>" . __('Use as a solution') . "</a>";
                     echo Search::showItem($output_type, $content, $item_num, $row_num);
                 }
                 // End Line
                 echo Search::showEndLine($output_type);
             }
             // Display footer
             if ($output_type == Search::PDF_OUTPUT_LANDSCAPE || $output_type == Search::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 == Search::HTML_OUTPUT) {
                 Html::printPager($params['start'], $numrows, Toolbox::getItemTypeSearchURL('KnowbaseItem'), $parameters, 'KnowbaseItem');
             }
         } else {
             echo "<div class='center b'>" . __('No item found') . "</div>";
         }
     }
 }
예제 #8
0
 function showBoard($width = '', $limit = '')
 {
     global $DB, $CFG_GLPI;
     $order = "ASC";
     if (isset($_GET['order'])) {
         $order = $_GET['order'];
     }
     $where = '';
     if ($limit == 'hosts') {
         $where = "`plugin_monitoring_services_id`='0' ";
     } else {
         if ($limit == 'services') {
             $where = "`plugin_monitoring_services_id`>0 ";
         }
     }
     if (isset($_GET['field'])) {
         foreach ($_GET['field'] as $key => $value) {
             $wheretmp = '';
             if (isset($_GET['link'][$key])) {
                 $wheretmp .= " " . $_GET['link'][$key] . " ";
             }
             $wheretmp .= Search::addWhere("", 0, "PluginMonitoringService", $_GET['field'][$key], $_GET['searchtype'][$key], $_GET['contains'][$key]);
             if (!strstr($wheretmp, "``.``")) {
                 if ($where != '' and !isset($_GET['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 = '';
     $leftjoin .= " LEFT JOIN `glpi_plugin_monitoring_components`\n         ON `plugin_monitoring_components_id` = \n         `glpi_plugin_monitoring_components`.`id` ";
     $leftjoin .= " LEFT JOIN `glpi_entities`\n         ON `" . getTableForItemType("PluginMonitoringService") . "`.`entities_id` = \n               `glpi_entities`.`id`";
     if (isset($_GET['field'])) {
         foreach ($_GET['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') {
                 } 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` ";
                         }
                     }
                 }
             }
         }
     }
     // * ORDER
     $ORDERQUERY = " ORDER BY `name` ";
     $toview = array(3, 6, 7, 10, 4, 9);
     $toviewComplete = array('ITEM_0' => 'state', 'ITEM_1' => 'completename', 'ITEM_2' => 'component_name', 'ITEM_3' => 'state', 'ITEM_4' => 'last_check', 'ITEM_5' => 'event');
     foreach ($toview as $key => $val) {
         if ($_GET['sort'] == $val) {
             $ORDERQUERY = Search::addOrderBy("PluginMonitoringService", $_GET['sort'], $_GET['order'], $key);
             foreach ($toviewComplete as $keyi => $vali) {
                 $ORDERQUERY = str_replace($keyi, $vali, $ORDERQUERY);
             }
         }
     }
     $query = "SELECT `" . getTableForItemType("PluginMonitoringService") . "`.*,\n            `glpi_plugin_monitoring_components`.`name` as component_name, \n            `glpi_entities`.`completename`\n         FROM `" . getTableForItemType("PluginMonitoringService") . "`\n         " . $leftjoin . "\n         " . $where . "\n         " . $ORDERQUERY;
     $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;
     Html::printPager($_GET['start'], $numrows, $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/service.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);
     echo '<div id="custom_date" style="display:none"></div>';
     echo '<div id="custom_time" style="display:none"></div>';
     if ($width == '') {
         echo "<table class='tab_cadrehov' style='width:100%;'>";
     } else {
         echo "<table class='tab_cadrehov' style='width:100%;'>";
     }
     $num = 0;
     echo "<tr class='tab_bg_1'>";
     $this->showHeaderItem(__('Status'), 3, $num, $start, $globallinkto);
     $this->showHeaderItem(__('Entity'), 6, $num, $start, $globallinkto);
     echo Search::showHeaderItem(0, __('Show graphics'), $num);
     echo Search::showHeaderItem(0, __('Item type') . " - " . __('Name'), $num);
     $this->showHeaderItem(__('Components', 'monitoring'), 7, $num, $start, $globallinkto);
     $this->showHeaderItem(__('Status'), 10, $num, $start, $globallinkto);
     $this->showHeaderItem(__('Last check', 'monitoring'), 4, $num, $start, $globallinkto);
     $this->showHeaderItem(__('Result details'), 9, $num, $start, $globallinkto);
     echo Search::showHeaderItem(0, __('Check period', 'monitoring'), $num);
     echo '<th>' . __('Acknowledge', 'monitoring') . '</th>';
     echo "</tr>";
     PluginMonitoringServicegraph::loadLib();
     while ($data = $DB->fetch_array($result)) {
         echo "<tr class='tab_bg_3'>";
         $this->displayLine($data);
         echo "</tr>";
     }
     echo "</table>";
     echo "<br/>";
     Html::printPager($_GET['start'], $numrows, $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/service.php", $parameters);
 }
 function showForm($id, $options = array())
 {
     if (!Session::haveRight('plugin_fusioninventory_printer', READ)) {
         return FALSE;
     }
     // display stats
     $stats = $this->stats($id);
     if ($stats) {
         $this->showTabs($options);
         $this->showFormHeader($options);
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . __('Total printed pages', 'fusioninventory') . " : </td>";
         echo "<td>" . $stats["num_pages"] . "</td></tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . __('Pages / day', 'fusioninventory') . " : </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>";
     Html::printPager($_GET['start'], $numrows, $_SERVER['PHP_SELF'], $parameters);
     $limit = $numrows;
     if ($_SESSION["glpilist_limit"] < $numrows) {
         $limit = $_SESSION["glpilist_limit"];
     }
     // Get history
     $data = $this->getEntries($id, $_GET['start'], $limit);
     if (!$data) {
         return FALSE;
     }
     echo "<div align='center'><form method='post' name='printer_history_form'\n                 id='printer_history_form'  action=\"" . Toolbox::getItemTypeFormURL(__CLASS__) . "\">";
     echo "<table class='tab_cadre' cellpadding='5'><tr><th colspan='3'>";
     echo __('History meter printer', 'fusioninventory') . " :</th></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th></th>";
     echo "<th>" . __('Date') . " :</th>";
     echo "<th>" . __('Meter', 'fusioninventory') . " :</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 (!Session::haveRight('plugin_fusioninventory_printer', UPDATE)) {
         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'>" . __('Check All', 'fusioninventory') . "</a>";
     echo " - <a onclick= \"if ( unMarkAllRows('printer_history_form') ) return FALSE;\"\n                  href='" . $_SERVER['PHP_SELF'] . "?select=none'>" . __('Uncheck All', 'fusioninventory') . "</a> ";
     echo "<input type='submit' name='delete' value=\"" . __('Delete', 'fusioninventory') . "\" class='submit' ></div></td></tr>";
     echo "</table>";
     Html::closeForm();
     echo "</div>";
 }
예제 #10
0
 /**
  * Print out list kb item
  *
  * @param $options            $_GET
  * @param $type      string   search type : browse / search (default search)
  **/
 static function showList($options, $type = 'search')
 {
     global $DB, $CFG_GLPI;
     // Default values of parameters
     $params['faq'] = !Session::haveRight("knowbase", "r");
     $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;
         }
     }
     $ki = new self();
     switch ($type) {
         case 'myunpublished':
             if (!Session::haveRight('knowbase', 'w') && !Session::haveRight('faq', 'w')) {
                 return false;
             }
             break;
         case 'allunpublished':
             if (!Session::haveRight('knowbase_admin', 1)) {
                 return false;
             }
             break;
         default:
             break;
     }
     if (!$params["start"]) {
         $params["start"] = 0;
     }
     $query = self::getListRequest($params, $type);
     // Get it from database
     if ($result = $DB->query($query)) {
         $KbCategory = new KnowbaseItemCategory();
         $title = "";
         if ($KbCategory->getFromDB($params["knowbaseitemcategories_id"])) {
             $title = empty($KbCategory->fields['name']) ? "(" . $params['knowbaseitemcategories_id'] . ")" : $KbCategory->fields['name'];
             $title = sprintf(__('%1$s: %2$s'), __('Category'), $title);
         }
         Session::initNavigateListItems('KnowbaseItem', $title);
         $numrows = $DB->numrows($result);
         $list_limit = $_SESSION['glpilist_limit'];
         $showwriter = in_array($type, array('myunpublished', 'allunpublished', 'allmy'));
         // 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 = Search::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=" . $params['faq'];
             if (isset($options['item_itemtype']) && isset($options['item_items_id'])) {
                 $parameters .= "&amp;item_items_id=" . $options['item_items_id'] . "&amp;item_itemtype=" . $options['item_itemtype'];
             }
             if ($output_type == Search::HTML_OUTPUT) {
                 Html::printPager($params['start'], $numrows, Toolbox::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, __('Subject'), $header_num);
             if ($output_type != Search::HTML_OUTPUT) {
                 echo Search::showHeaderItem($output_type, __('Content'), $header_num);
             }
             if ($showwriter) {
                 echo Search::showHeaderItem($output_type, __('Writer'), $header_num);
             }
             echo Search::showHeaderItem($output_type, __('Category'), $header_num);
             if (isset($options['item_itemtype']) && isset($options['item_items_id']) && $output_type == Search::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_assoc($result_limit);
                 Session::addToNavigateListItems('KnowbaseItem', $data["id"]);
                 // Column num
                 $item_num = 1;
                 $row_num++;
                 echo Search::showNewLine($output_type, $i % 2);
                 if ($output_type == Search::HTML_OUTPUT) {
                     if (isset($options['item_itemtype']) && isset($options['item_items_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=\"" . $CFG_GLPI['root_doc'] . "/front/knowbaseitem.form.php?id=" . $data["id"] . "\" ";
                     }
                     echo Search::showItem($output_type, "<div class='kb'><a " . ($data['is_faq'] ? " class='pubfaq' " : " class='knowbase' ") . " {$href}>" . Html::resume_text($data["name"], 80) . "</a></div>\n                                          <div class='kb_resume'>" . Html::resume_text(Html::clean(Toolbox::unclean_cross_side_scripting_deep($data["answer"])), 600) . "</div>", $item_num, $row_num);
                 } else {
                     echo Search::showItem($output_type, $data["name"], $item_num, $row_num);
                     echo Search::showItem($output_type, Html::clean(Toolbox::unclean_cross_side_scripting_deep(html_entity_decode($data["answer"], ENT_QUOTES, "UTF-8"))), $item_num, $row_num);
                 }
                 if ($showwriter) {
                     echo Search::showItem($output_type, getUserName($data["users_id"], 1), $item_num, $row_num);
                 }
                 $categ = $data["category"];
                 if ($output_type == Search::HTML_OUTPUT) {
                     $cathref = $ki->getSearchURL() . "?knowbaseitemcategories_id=" . $data["knowbaseitemcategories_id"] . '&amp;forcetab=Knowbase$2';
                     $categ = "<a href='{$cathref}'>" . $categ . '</a>';
                 }
                 echo Search::showItem($output_type, $categ, $item_num, $row_num);
                 if (isset($options['item_itemtype']) && isset($options['item_items_id']) && $output_type == Search::HTML_OUTPUT) {
                     $content = "<a href='" . Toolbox::getItemTypeFormURL($options['item_itemtype']) . "?load_kb_sol=" . $data['id'] . "&amp;id=" . $options['item_items_id'] . "&amp;forcetab=" . $options['item_itemtype'] . "\$2'>" . __('Use as a solution') . "</a>";
                     echo Search::showItem($output_type, $content, $item_num, $row_num);
                 }
                 // End Line
                 echo Search::showEndLine($output_type);
             }
             // Display footer
             if ($output_type == Search::PDF_OUTPUT_LANDSCAPE || $output_type == Search::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 == Search::HTML_OUTPUT) {
                 Html::printPager($params['start'], $numrows, Toolbox::getItemTypeSearchURL('KnowbaseItem'), $parameters, 'KnowbaseItem');
             }
         } else {
             echo "<div class='center b'>" . __('No item found') . "</div>";
         }
     }
 }
예제 #11
0
    Html::footer();
    exit;
}
if (!$item instanceof CommonDevice) {
    // echo "Dropdown";
    $type = "comp_champ";
    $val = Stat::getItems($_GET['itemtype'], $_GET["date1"], $_GET["date2"], $_GET["dropdown"]);
    $params = array('type' => $type, 'dropdown' => $_GET["dropdown"], 'date1' => $_GET["date1"], 'date2' => $_GET["date2"], 'start' => $_GET["start"]);
} else {
    //   echo "Device";
    $type = "device";
    $field = $_GET["dropdown"];
    $val = Stat::getItems($_GET['itemtype'], $_GET["date1"], $_GET["date2"], $_GET["dropdown"]);
    $params = array('type' => $type, 'dropdown' => $_GET["dropdown"], 'date1' => $_GET["date1"], 'date2' => $_GET["date2"], 'start' => $_GET["start"]);
}
Html::printPager($_GET['start'], count($val), $CFG_GLPI['root_doc'] . '/front/stat.location.php', "date1=" . $_GET["date1"] . "&amp;date2=" . $_GET["date2"] . "&amp;itemtype=" . $_GET['itemtype'] . "&amp;dropdown=" . $_GET["dropdown"], 'Stat', $params);
if (!$_GET['showgraph']) {
    Stat::showTable($_GET['itemtype'], $type, $_GET["date1"], $_GET["date2"], $_GET['start'], $val, $_GET["dropdown"]);
} else {
    $data = Stat::getDatas($_GET['itemtype'], $type, $_GET["date1"], $_GET["date2"], $_GET['start'], $val, $_GET["dropdown"]);
    if (isset($data['opened']) && is_array($data['opened'])) {
        foreach ($data['opened'] as $key => $val) {
            $cleandata[Html::clean($key)] = $val;
        }
        Stat::showGraph(array(__('Number opened') => $cleandata), array('title' => __('Number opened'), 'showtotal' => 1, 'unit' => __('Tickets'), 'type' => 'pie'));
    }
    if (isset($data['solved']) && is_array($data['solved'])) {
        foreach ($data['solved'] as $key => $val) {
            $cleandata[Html::clean($key)] = $val;
        }
        Stat::showGraph(array(__('Number solved') => $cleandata), array('title' => __('Number solved'), 'showtotal' => 1, 'unit' => __('Tickets'), 'type' => 'pie'));
예제 #12
0
 /**
  * Execute the report
  *
  * @param $options   array
  **/
 function execute($options = array())
 {
     global $DB, $CFG_GLPI, $HEADER_LOADED;
     // Require (for pager) when not called by displayCriteriasForm
     $this->manageCriteriasValues();
     if (isset($_POST['list_limit'])) {
         $_SESSION['glpilist_limit'] = $_POST['list_limit'];
         unset($_POST['list_limit']);
     }
     $limit = $_SESSION['glpilist_limit'];
     if (isset($_POST["display_type"])) {
         $output_type = $_POST["display_type"];
         if ($output_type < 0) {
             $output_type = -$output_type;
             $limit = 0;
         }
     } else {
         $output_type = Search::HTML_OUTPUT;
     }
     $title = $this->title;
     if ($this->subname) {
         $title = sprintf(__('%1$s - %2$s'), $title, $this->subname);
     }
     $res = $DB->query($this->sql);
     $nbtot = $res ? $DB->numrows($res) : 0;
     if ($limit) {
         $start = isset($_GET["start"]) ? $_GET["start"] : 0;
         if ($start >= $nbtot) {
             $start = 0;
         }
         if ($start > 0 || $start + $limit < $nbtot) {
             $res = $DB->query($this->sql . " LIMIT {$start},{$limit}");
         }
     } else {
         $start = 0;
     }
     if ($nbtot == 0) {
         if (!$HEADER_LOADED) {
             Html::header($title, $_SERVER['PHP_SELF'], "utils", "report");
             Report::title();
         }
         echo "<div class='center'><font class='red b'>" . __('No item found') . "</font></div>";
         Html::footer();
     } else {
         if ($output_type == Search::PDF_OUTPUT_PORTRAIT || $output_type == Search::PDF_OUTPUT_LANDSCAPE) {
             include GLPI_ROOT . "/lib/ezpdf/class.ezpdf.php";
         } else {
             if ($output_type == Search::HTML_OUTPUT) {
                 if (!$HEADER_LOADED) {
                     Html::header($title, $_SERVER['PHP_SELF'], "utils", "report");
                     Report::title();
                 }
                 echo "<div class='center'><table class='tab_cadre_fixe'>";
                 echo "<tr><th>" . $title . "</th></tr>\n";
                 echo "<tr class='tab_bg_2 center'><td class='center'>";
                 echo "<form method='POST' action='" . $_SERVER["PHP_SELF"] . "?start={$start}'>\n";
                 $param = "";
                 foreach ($_POST as $key => $val) {
                     if (is_array($val)) {
                         foreach ($val as $k => $v) {
                             echo "<input type='hidden' name='" . $key . "[{$k}]' value='{$v}' >";
                             if (!empty($param)) {
                                 $param .= "&";
                             }
                             $param .= $key . "[" . $k . "]=" . urlencode($v);
                         }
                     } else {
                         echo "<input type='hidden' name='" . $key . "' value='{$val}' >";
                         if (!empty($param)) {
                             $param .= "&";
                         }
                         $param .= "{$key}=" . urlencode($val);
                     }
                 }
                 Dropdown::showOutputFormat();
                 Html::closeForm();
                 echo "</td></tr>";
                 echo "</table></div>";
                 Html::printPager($start, $nbtot, $_SERVER['PHP_SELF'], $param);
             }
         }
     }
     if (!isset($_POST["display_type"]) || $_POST["display_type"] == Search::HTML_OUTPUT) {
         if (isset($options['withmassiveaction']) && class_exists($options['withmassiveaction'])) {
             echo "<form method='post' name='massiveaction_form' id='massiveaction_form' action=\"" . $CFG_GLPI["root_doc"] . "/front/massiveaction.php\">";
         }
     }
     plugin_reports_checkRight($this->plug, $this->name, "r");
     if ($res && $nbtot > 0) {
         $nbcols = $DB->num_fields($res);
         $nbrows = $DB->numrows($res);
         echo Search::showHeader($output_type, $nbrows, $nbcols, true);
         echo Search::showNewLine($output_type);
         $num = 1;
         // fill $sqlcols with default sql query fields so we can validate $columns
         $sqlcols = array();
         for ($i = 0; $i < $nbcols; $i++) {
             $colname = $DB->field_name($res, $i);
             $sqlcols[] = $colname;
         }
         $colsname = array();
         // if $columns is not empty, display $columns
         if (count($this->columns) > 0) {
             foreach ($this->columns as $colname => $column) {
                 // display only $columns that are valid
                 if (in_array($colname, $sqlcols)) {
                     $column->showTitle($output_type, $num);
                     $colsname[$colname] = $column;
                 }
             }
         } else {
             // else display default columns from SQL query
             foreach ($sqlcols as $colname) {
                 $column = new PluginReportsColumn($colname, $colname);
                 $column->showTitle($output_type, $num);
                 $colsname[$colname] = $column;
             }
         }
         echo Search::showEndLine($output_type);
         $prev = "";
         for ($row_num = 2; $row = $DB->fetch_assoc($res); $row_num++) {
             $crt = "";
             foreach ($this->group_by as $colname) {
                 if (isset($row[$colname])) {
                     $crt .= $row[$colname] . "####";
                 }
             }
             echo Search::showNewLine($output_type);
             $num = 1;
             foreach ($colsname as $colname => $column) {
                 //If value needs to be modified on the fly
                 if (isset($this->columns_mapping[$colname]) && isset($this->columns_mapping[$colname][$row[$colname]])) {
                     $new_value = $this->columns_mapping[$colname][$row[$colname]];
                     $row[$colname] = $new_value;
                 }
                 if (!in_array($colname, $this->group_by)) {
                     $column->showValue($output_type, $row, $num, $row_num);
                 } else {
                     if ($crt == $prev) {
                         $column->showValue($output_type, $output_type == Search::CSV_OUTPUT ? $row : array(), $num, $row_num);
                     } else {
                         $column->showValue($output_type, $row, $num, $row_num, true);
                     }
                 }
             }
             // Each column
             echo Search::showEndLine($output_type);
             $prev = $crt;
         }
         // Each row
         if (isset($options['withtotal']) && $options['withtotal']) {
             echo Search::showNewLine($output_type);
             $num = 1;
             foreach ($colsname as $colname => $column) {
                 $column->showTotal($output_type, $num, $row_num);
             }
             echo Search::showEndLine($output_type);
         }
     }
     echo Search::showFooter($output_type, $title);
     if (!isset($_POST["display_type"]) || $_POST["display_type"] == Search::HTML_OUTPUT) {
         if (isset($options['withmassiveaction']) && class_exists($options['withmassiveaction'])) {
             Html::openArrowMassives("massiveaction_form", true);
             Dropdown::showForMassiveAction($options['withmassiveaction']);
             $options = array();
             Html::closeArrowMassives($options);
             Html::closeForm();
         }
         Html::footer();
     }
 }
예제 #13
0
 /**
  * Display a list of computers to add or to link
  *
  * @param plugin_ocsinventoryng_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 rowX
  * @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($plugin_ocsinventoryng_ocsservers_id, $advanced, $check, $start, $entity = 0, $tolinked = false)
 {
     global $DB, $PluginOcsinventoryngDBocs, $CFG_GLPI;
     if (!plugin_ocsinventoryng_haveRight("ocsng", "w")) {
         return false;
     }
     $target = $CFG_GLPI['root_doc'] . '/plugins/ocsinventoryng/front/ocsng.import.php';
     if ($tolinked) {
         $target = $CFG_GLPI['root_doc'] . '/plugins/ocsinventoryng/front/ocsng.link.php';
     }
     $cfg_ocs = self::getConfig($plugin_ocsinventoryng_ocsservers_id);
     $WHERE = self::getTagLimit($cfg_ocs);
     $query_ocs = "SELECT `hardware`.*,\n                           `accountinfo`.`TAG` AS TAG,\n                           `bios`.`SSN` AS SERIAL,\n                           `bios`.`SMODEL`,\n                           `bios`.`SMANUFACTURER`\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 = $PluginOcsinventoryngDBocs->query($query_ocs);
     // Existing OCS - GLPI link
     $query_glpi = "SELECT*\n                     FROM `glpi_plugin_ocsinventoryng_ocslinks`\n                     WHERE `plugin_ocsinventoryng_ocsservers_id`\n                              = '{$plugin_ocsinventoryng_ocsservers_id}'";
     $result_glpi = $DB->query($query_glpi);
     if ($PluginOcsinventoryngDBocs->numrows($result_ocs) > 0) {
         // Get all hardware from OCS DB
         $hardware = array();
         while ($data = $PluginOcsinventoryngDBocs->fetch_array($result_ocs)) {
             $data = Toolbox::clean_cross_side_scripting_deep(Toolbox::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"];
             $hardware[$data["ID"]]["model"] = $data["SMODEL"];
             $hardware[$data["ID"]]["manufacturer"] = $data["SMANUFACTURER"];
             $query_network = "SELECT*\n                              FROM `networks`\n                              WHERE `HARDWARE_ID` = '" . $data["ID"] . "'";
             //Get network informations for this computer
             //Ignore informations that contains "??"
             foreach ($PluginOcsinventoryngDBocs->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 = $PluginOcsinventoryngDBocs->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 b'>" . __('Caution! The imported data (see your configuration) will overwrite the existing one', 'ocsinventoryng') . "</div>";
         }
         echo "<div class='center'>";
         if (($numrows = count($hardware)) > 0) {
             $parameters = "check={$check}";
             Html::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 even in multi-entity mode because computer import
             //can be refused by a rule
             if (!$tolinked) {
                 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>" . __('Manual import mode', 'ocsinventoryng') . "</th></tr>\n";
                 echo "<tr class='tab_bg_1'><td class='center'>";
                 if ($advanced) {
                     Html::showSimpleForm($target, 'change_import_mode', __('Disable preview', 'ocsinventoryng'), array('id' => 'false'));
                 } else {
                     Html::showSimpleForm($target, 'change_import_mode', __('Enable preview', 'ocsinventoryng'), array('id' => 'true'));
                 }
                 echo "</td></tr>";
                 echo "<tr class='tab_bg_1'><td class='center b'>" . __('Check first that duplicates have been correctly managed in OCSNG', 'ocsinventoryng') . "</td>";
                 echo "</tr></table>";
                 Html::closeForm();
                 echo "</div>";
             }
             echo "<form method='post' name='ocsng_form' id='ocsng_form' action='{$target}'>";
             if (!$tolinked) {
                 self::checkBox($target);
             }
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'><td colspan='" . ($advanced || $tolinked ? 10 : 7) . "' class='center'>";
             echo "<input class='submit' type='submit' name='import_ok' value=\"" . _sx('button', 'Import', 'ocsinventoryng') . "\">";
             echo "</td></tr>\n";
             echo "<tr><th>" . __('Name') . "</th>\n";
             echo "<th>" . __('Manufacturer') . "</th>\n";
             echo "<th>" . __('Model') . "</th>\n";
             echo "<th>" . __('Serial number') . "</th>\n";
             echo "<th>" . __('Date') . "</th>\n";
             echo "<th>" . __('OCSNG TAG', 'ocsinventoryng') . "</th>\n";
             if ($advanced && !$tolinked) {
                 echo "<th>" . __('Match the rule ?', 'ocsinventoryng') . "</th>\n";
                 echo "<th>" . __('Destination entity') . "</th>\n";
                 echo "<th>" . __('Target location', 'ocsinventoryng') . "</th>\n";
             }
             echo "<th>&nbsp;</th></tr>\n";
             $rule = new RuleImportEntityCollection();
             foreach ($hardware as $ID => $tab) {
                 $comp = new Computer();
                 $comp->fields["id"] = $tab["id"];
                 $data = array();
                 if ($advanced && !$tolinked) {
                     $data = $rule->processAllRules(array('ocsservers_id' => $plugin_ocsinventoryng_ocsservers_id, '_source' => 'ocsinventoryng'), array(), array('ocsid' => $tab["id"]));
                 }
                 echo "<tr class='tab_bg_2'><td>" . $tab["name"] . "</td>\n";
                 echo "<td>" . $tab["manufacturer"] . "</td><td>" . $tab["model"] . "</td>";
                 echo "<td>" . $tab["serial"] . "</td>\n";
                 echo "<td>" . Html::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=\"" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png\"></td>\n";
                         $data['entities_id'] = -1;
                     } else {
                         echo "<td class='center'>";
                         $tmprule = new RuleImportEntity();
                         if ($tmprule->can($data['_ruleid'], 'r')) {
                             echo "<a href='" . $tmprule->getLinkURL() . "'>" . $tmprule->getName() . "</a>";
                         } else {
                             echo $tmprule->getName();
                         }
                         echo "</td>\n";
                     }
                     echo "<td>";
                     Entity::dropdown(array('name' => "toimport_entities[" . $tab["id"] . "]=" . $data['entities_id'], 'value' => $data['entities_id'], 'comments' => 0));
                     echo "</td>\n";
                     echo "<td>";
                     if (!isset($data['locations_id'])) {
                         $data['locations_id'] = 0;
                     }
                     Location::dropdown(array('name' => "toimport_locations[" . $tab["id"] . "]=" . $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, 'plugin_ocsinventoryng_ocsservers_id' => $plugin_ocsinventoryng_ocsservers_id);
                     $rulelink_results = $rulelink->processAllRules(Toolbox::stripslashes_deep($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;
                         }
                         Computer::dropdown($options);
                     } else {
                         echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/redbutton.png'>";
                     }
                 }
                 echo "</td></tr>\n";
             }
             echo "<tr class='tab_bg_1'><td colspan='" . ($advanced || $tolinked ? 10 : 7) . "' class='center'>";
             echo "<input class='submit' type='submit' name='import_ok' value=\"" . _sx('button', 'Import', 'ocsinventoryng') . "\">\n";
             echo "<input type=hidden name='plugin_ocsinventoryng_ocsservers_id' " . "value='{$plugin_ocsinventoryng_ocsservers_id}'>";
             echo "</td></tr>";
             echo "</table>\n";
             Html::closeForm();
             if (!$tolinked) {
                 self::checkBox($target);
             }
             Html::printPager($start, $numrows, $target, $parameters);
         } else {
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr><th>" . __('Import new computers') . "</th></tr>\n";
             echo "<tr class='tab_bg_1'>";
             echo "<td class='center b'>" . __('No new computer to be imported', 'ocsinventoryng') . "</td></tr>\n";
             echo "</table>";
         }
         echo "</div>";
     } else {
         echo "<div class='center'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th>" . __('Import new computers', 'ocsinventoryng') . "</th></tr>\n";
         echo "<tr class='tab_bg_1'>";
         echo "<td class='center b'>" . __('No new computer to be imported', 'ocsinventoryng') . "</td></tr>\n";
         echo "</table></div>";
     }
 }
예제 #14
0
 function showMinimalList($params)
 {
     global $DB, $CFG_GLPI;
     $itemtype = "PluginResourcesDirectory";
     $itemtable = $this->table;
     if (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['id'] = 0;
     $p['withtemplate'] = 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;
     }
     $PluginResourcesResource = new PluginResourcesResource();
     $canedit = $PluginResourcesResource->can($p['id'], 'w');
     // Manage defautlt 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 = $CFG_GLPI["root_doc"] . "/plugins/resources/front/directory.php";
     $limitsearchopt = Search::getCleanedOptions("PluginResourcesDirectory");
     $LIST_LIMIT = $_SESSION['glpilist_limit'];
     // Set display type for export if define
     $output_type = Search::HTML_OUTPUT;
     if (isset($_GET['display_type'])) {
         $output_type = $_GET['display_type'];
         // Limit to 10 element
         if ($_GET['display_type'] == Search::GLOBAL_SEARCH) {
             $LIST_LIMIT = Search::GLOBAL_DISPLAY_COUNT;
         }
     }
     $entity_restrict = $PluginResourcesResource->isEntityAssign();
     // Get the items to display
     $toview = Search::addDefaultToView("User");
     // Add items to display depending of personal prefs
     $displaypref = DisplayPreference::getForTypeUser("PluginResourcesDirectory", Session::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']);
     }
     // Clean toview array
     $toview = array_unique($toview);
     foreach ($toview as $key => $val) {
         if (!isset($limitsearchopt[$val])) {
             unset($toview[$key]);
         }
     }
     $toview_count = count($toview);
     //// 1 - SELECT
     $query = "SELECT " . Search::addDefaultSelect("User");
     // Add select for all toview item
     foreach ($toview as $key => $val) {
         $query .= self::addSelect("PluginResourcesDirectory", $val, $key, 0);
     }
     $query .= "`glpi_plugin_resources_resources`.`id` AS id ";
     //// 2 - FROM AND LEFT JOIN
     // Set reference table
     $query .= " 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 = Search::addDefaultJoin("PluginResourcesDirectory", $itemtable, $already_link_tables);
     $query .= $COMMONLEFTJOIN;
     $searchopt = array();
     $searchopt["PluginResourcesDirectory"] =& Search::getOptions("PluginResourcesDirectory");
     // Add all table for toview items
     foreach ($toview as $key => $val) {
         $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt["PluginResourcesDirectory"][$val]["table"], $searchopt["PluginResourcesDirectory"][$val]["linkfield"], 0, 0, $searchopt["PluginResourcesDirectory"][$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)) {
                 $query .= Search::addLeftJoin($itemtype, $itemtable, $already_link_tables, $searchopt["PluginResourcesDirectory"][$key]["table"], $searchopt["PluginResourcesDirectory"][$key]["linkfield"], 0, 0, $searchopt["PluginResourcesDirectory"][$key]["joinparams"]);
             }
         }
     }
     $ASSIGN = " `glpi_plugin_resources_resources`.`is_leaving` = 0 AND `glpi_users`.`is_active` = 1 AND ";
     //// 3 - WHERE
     // default string
     $COMMONWHERE = Search::addDefaultWhere($itemtype);
     $first = empty($COMMONWHERE);
     // Add deleted if item have it
     if ($PluginResourcesResource && $PluginResourcesResource->maybeDeleted()) {
         $LINK = " AND ";
         if ($first) {
             $LINK = " ";
             $first = false;
         }
         $COMMONWHERE .= $LINK . "`glpi_plugin_resources_resources`.`is_deleted` = '" . $p['is_deleted'] . "' ";
     }
     // Remove template items
     if ($PluginResourcesResource && $PluginResourcesResource->maybeTemplate()) {
         $LINK = " AND ";
         if ($first) {
             $LINK = " ";
             $first = false;
         }
         $COMMONWHERE .= $LINK . "`glpi_plugin_resources_resources`.`is_template` = '0' ";
     }
     // Add Restrict to current entities
     if ($entity_restrict) {
         $LINK = " AND ";
         if ($first) {
             $LINK = " ";
             $first = false;
         }
         if (isset($CFG_GLPI["union_search_type"][$itemtype])) {
             // Will be replace below in Union/Recursivity Hack
             $COMMONWHERE .= $LINK . " ENTITYRESTRICT ";
         } else {
             $COMMONWHERE .= getEntitiesRestrictRequest($LINK, "glpi_plugin_resources_resources", '', '', $PluginResourcesResource->maybeRecursive());
         }
     }
     $WHERE = "";
     $HAVING = "";
     // Add search conditions
     // If there is search items
     if ($_SESSION["glpisearchcount"]["PluginResourcesDirectory"] > 0 && count($p['contains']) > 0) {
         for ($key = 0; $key < $_SESSION["glpisearchcount"]["PluginResourcesDirectory"]; $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["PluginResourcesDirectory"][$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 .= Search::addHaving($LINK, $NOT, "PluginResourcesDirectory", $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, "PluginResourcesDirectory", $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["PluginResourcesDirectory"];
                     } else {
                         // toview case : populate toview
                         foreach ($toview as $key2 => $val2) {
                             $items[$val2] = $searchopt["PluginResourcesDirectory"][$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, "PluginResourcesDirectory", $key2, $p['searchtype'][$key], $p['contains'][$key]);
                             }
                         }
                     }
                     $WHERE .= " ) ";
                 }
             }
         }
     }
     if (!empty($WHERE) || !empty($COMMONWHERE)) {
         if (!empty($COMMONWHERE)) {
             $WHERE = ' WHERE ' . $ASSIGN . ' ' . $COMMONWHERE . (!empty($WHERE) ? ' AND ( ' . $WHERE . ' )' : '');
         } else {
             $WHERE = ' WHERE ' . $ASSIGN . ' ' . $WHERE . ' ';
         }
         $first = false;
     }
     $query .= $WHERE;
     //// 7 - Manage GROUP BY
     $GROUPBY = "";
     // Meta Search / Search All / Count tickets
     if (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["PluginResourcesDirectory"][$val2]["forcegroupby"])) {
                 $GROUPBY = " GROUP BY `" . $itemtable . "`.`id`";
             }
         }
     }
     $query .= $GROUPBY;
     //// 4 - ORDER
     $ORDER = " ORDER BY `id` ";
     foreach ($toview as $key => $val) {
         if ($p['sort'] == $val) {
             $ORDER = Search::addOrderBy($itemtype, $p['sort'], $p['order'], $key);
         }
     }
     $query .= $ORDER;
     // Get it from database
     if ($result = $DB->query($query)) {
         $numrows = $DB->numrows($result);
         $globallinkto = Search::getArrayUrlLink("field", $p['field']) . Search::getArrayUrlLink("link", $p['link']) . Search::getArrayUrlLink("contains", $p['contains']) . Search::getArrayUrlLink("searchtype", $p['searchtype']) . Search::getArrayUrlLink("field2", $p['field2']) . Search::getArrayUrlLink("contains2", $p['contains2']) . Search::getArrayUrlLink("searchtype2", $p['searchtype2']) . Search::getArrayUrlLink("itemtype2", $p['itemtype2']) . Search::getArrayUrlLink("link2", $p['link2']);
         $parameters = "sort=" . $p['sort'] . "&amp;order=" . $p['order'] . $globallinkto;
         if ($output_type == Search::GLOBAL_SEARCH) {
             if (class_exists($itemtype)) {
                 echo "<div class='center'><h2>" . $this->getTypeName();
                 // More items
                 if ($numrows > $p['start'] + Search::GLOBAL_DISPLAY_COUNT) {
                     echo " <a href='{$target}?{$parameters}'>" . __('All') . "</a>";
                 }
                 echo "</h2></div>\n";
             } else {
                 return false;
             }
         }
         if ($p['start'] < $numrows) {
             // Pager
             if ($output_type == Search::HTML_OUTPUT) {
                 // HTML display - massive modif
                 $search_config = "";
                 if ($item->canCreate() && $canedit) {
                     $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='" . __('Select default items to show') . "' title='" . __('Select default items to show') . "' src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' ";
                     $search_config .= $tmp . ">";
                 }
                 //echo Search::showHeaderItem($output_type,$search_config,$header_num,"",0,$p['order']);
             }
             // Pager
             if ($output_type == Search::HTML_OUTPUT) {
                 Html::printPager($p['start'], $numrows, $target, $parameters, $itemtype, 0, $search_config);
                 echo "<br>";
             }
             // Define begin and end var for loop
             // Search case
             $begin_display = $p['start'];
             $end_display = $p['start'] + $LIST_LIMIT;
             // Export All case
             if ($p['export_all']) {
                 $begin_display = 0;
                 $end_display = $numrows;
             }
             //massive action
             $sel = "";
             if (isset($_GET["select"]) && $_GET["select"] == "all") {
                 $sel = "checked";
             }
             if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) {
                 Html::openMassiveActionsForm('massform' . $itemtype);
                 $massiveactionparams = array('num_displayed' => $end_display - $begin_display, 'fixed' => false, 'is_deleted' => $p['is_deleted']);
                 Html::showMassiveActions("PluginResourcesDirectory", $massiveactionparams);
             }
             // Add toview elements
             $nbcols = $toview_count;
             if ($output_type == Search::HTML_OUTPUT) {
                 // HTML display - massive modif
                 $nbcols++;
             }
             // Display List Header
             echo Search::showHeader($output_type, $end_display - $begin_display + 1, $nbcols);
             $header_num = 1;
             // Display column Headers for toview items
             $headers_line = '';
             $headers_line_top = '';
             $headers_line_bottom = '';
             echo Search::showNewLine($output_type);
             if ($output_type == Search::HTML_OUTPUT && $item->canCreate() && $canedit) {
                 // HTML display - massive modif
                 $headers_line_top .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']);
                 $headers_line_bottom .= Search::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']);
             }
             // Display column Headers for toview items
             foreach ($toview as $key => $val) {
                 $linkto = '';
                 if (!isset($searchopt["PluginResourcesDirectory"][$val]['nosort']) || !$searchopt["PluginResourcesDirectory"][$val]['nosort']) {
                     $linkto = "javascript:reloadTab('sort=" . $val . "&amp;order=" . ($p['order'] == "ASC" ? "DESC" : "ASC") . "&amp;start=" . $p['start'] . $globallinkto . "')";
                 }
                 $headers_line .= Search::showHeaderItem($output_type, $searchopt["PluginResourcesDirectory"][$val]["name"], $header_num, $linkto, $p['sort'] == $val, $p['order']);
             }
             // End Line for column headers
             $headers_line .= Search::showEndLine($output_type);
             $headers_line_top .= $headers_line;
             $headers_line_bottom .= $headers_line;
             echo $headers_line_top;
             $DB->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 == Search::HTML_OUTPUT) {
                 Session::initNavigateListItems($itemtype);
             }
             // Num of the row (1=header_line)
             $row_num = 1;
             // Display Loop
             while ($i < $numrows && $i < $end_display) {
                 $item_num = 1;
                 $data = $DB->fetch_array($result);
                 $i++;
                 $row_num++;
                 echo Search::showNewLine($output_type, $i % 2);
                 Session::addToNavigateListItems($itemtype, $data['id']);
                 $tmpcheck = "";
                 if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) {
                     $sel = "";
                     $tmpcheck = "<input type='checkbox' name='item[" . $data["id"] . "]' value='1' {$sel}>";
                     echo Search::showItem($output_type, $tmpcheck, $item_num, $row_num, "width='10'");
                 }
                 foreach ($toview as $key => $val) {
                     echo Search::showItem($output_type, Search::giveItem("PluginResourcesDirectory", $val, $data, $key), $item_num, $row_num, Search::displayConfigItem("PluginResourcesDirectory", $val, $data, $key));
                 }
                 echo Search::showEndLine($output_type);
             }
             // Close Table
             $title = "";
             // Create title
             if ($output_type == Search::PDF_OUTPUT_PORTRAIT || $output_type == Search::PDF_OUTPUT_LANDSCAPE) {
                 $title .= self::getTypeName(1);
             }
             // Display footer
             echo Search::showFooter($output_type, $title);
             //massive action
             if ($item->canCreate() && $canedit && $output_type == Search::HTML_OUTPUT && $p['withtemplate'] != 2) {
                 $massiveactionparams['ontop'] = false;
                 $massiveactionparams['fixed'] = false;
                 Html::showMassiveActions("PluginResourcesDirectory", $massiveactionparams);
                 Html::closeForm();
             } else {
                 echo "</table></div>";
             }
             // Pager
             if ($output_type == Search::HTML_OUTPUT) {
                 echo "<br>";
                 Html::printPager($p['start'], $numrows, $target, $parameters, "PluginResourcesDirectory", 0, $search_config);
             }
         } else {
             echo Search::showError($output_type);
         }
     }
 }
예제 #15
0
 /**
  * Generic Search and list function
  *
  * Build the query, make the search and list items after a search.
  *
  * @param $itemtype        item type
  * @param $params    array of parameters may include field, contains, searchtype, sort, order,
  *                         start, deleted, link, link2, contains2, field2, itemtype2, searchtype2
  *
  * @return Nothing (display)
  **/
 static function showList($itemtype, array $params)
 {
     global $DB, $CFG_GLPI;
     // Instanciate an object to access method
     $item = NULL;
     if ($itemtype != 'AllAssets') {
         $item = getItemForItemtype($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;
     }
     if (in_array('all', $p['field']) && !$CFG_GLPI['allow_search_all']) {
         Html::displayRightError();
     }
     if (in_array('view', $p['field']) && !$CFG_GLPI['allow_search_view']) {
         Html::displayRightError();
     }
     // 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 = Toolbox::getItemTypeSearchURL($itemtype);
     $limitsearchopt = self::getCleanedOptions($itemtype);
     $blacklist_tables = array();
     if (isset($CFG_GLPI['union_search_type'][$itemtype])) {
         $itemtable = $CFG_GLPI['union_search_type'][$itemtype];
         $blacklist_tables[] = getTableForItemType($itemtype);
     } else {
         $itemtable = getTableForItemType($itemtype);
     }
     $LIST_LIMIT = $_SESSION['glpilist_limit'];
     // Set display type for export if define
     $output_type = self::HTML_OUTPUT;
     if (isset($_GET['display_type'])) {
         $output_type = $_GET['display_type'];
         // Limit to 10 element
         if ($_GET['display_type'] == self::GLOBAL_SEARCH) {
             $LIST_LIMIT = self::GLOBAL_DISPLAY_COUNT;
         }
     }
     // hack for AllAssets
     if (isset($CFG_GLPI['union_search_type'][$itemtype])) {
         $entity_restrict = true;
     } else {
         $entity_restrict = $item->isEntityAssign();
     }
     self::$output_type = $output_type;
     $metanames = array();
     // Get the items to display
     $toview = self::addDefaultToView($itemtype);
     // Add items to display depending of personal prefs
     $displaypref = DisplayPreference::getForTypeUser($itemtype, Session::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 '" . Toolbox::addslashes_deep($_SESSION['glpiname']) . "' AS currentuser,\n                        " . 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) {
         if (!in_array($searchopt[$itemtype][$val]["table"], $blacklist_tables)) {
             $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)) {
                 if (!in_array($searchopt[$itemtype][$key]["table"], $blacklist_tables)) {
                     $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 (isset($val2['nosearch']) && $val2['nosearch']) {
                             continue;
                         }
                         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},\n                              '" . Toolbox::addslashes_deep($_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);
                 if (($citem = getItemForItemtype($ctype)) && $citem->canView()) {
                     // State case
                     if ($itemtype == 'AllAssets') {
                         $query_num = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery);
                         $query_num = str_replace($itemtype, $ctype, $query_num);
                         $query_num .= " AND `{$ctable}`.`id` IS NOT NULL ";
                         // 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);
                         if ($item && $item->maybeDeleted()) {
                             $tmpquery = str_replace("`" . $CFG_GLPI["union_search_type"][$itemtype] . "`.`is_deleted`", "`{$reftable}`.`is_deleted`", $tmpquery);
                         }
                         $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);
             if (($citem = getItemForItemtype($ctype)) && $citem->canView()) {
                 if ($first) {
                     $first = false;
                 } else {
                     $QUERY .= " UNION ";
                 }
                 $tmpquery = "";
                 // AllAssets case
                 if ($itemtype == 'AllAssets') {
                     $tmpquery = $SELECT . ", '{$ctype}' AS TYPE " . $FROM . $WHERE;
                     if ($itemtype == 'AllAssets') {
                         $tmpquery .= " AND `{$ctable}`.`id` IS NOT NULL ";
                     }
                     // 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' ";
                     }
                     $tmpquery .= $GROUPBY . $HAVING;
                     $tmpquery = str_replace($CFG_GLPI["union_search_type"][$itemtype], $ctable, $tmpquery);
                     $tmpquery = str_replace($itemtype, $ctype, $tmpquery);
                 } 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;
                     if ($item->maybeDeleted()) {
                         $tmpquery = str_replace("`" . $CFG_GLPI["union_search_type"][$itemtype] . "`.`is_deleted`", "`{$reftable}`.`is_deleted`", $tmpquery);
                     }
                     $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 == self::GLOBAL_SEARCH) {
             if ($item = getItemForItemtype($itemtype)) {
                 echo "<div class='center'><h2>" . $item->getTypeName();
                 // More items
                 if ($numrows > $p['start'] + self::GLOBAL_DISPLAY_COUNT) {
                     echo " <a href='{$target}?{$parameters}'>" . __('All') . "</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 == self::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}";
                                 }
                             }
                         }
                     }
                 }
                 $search_config = "";
                 if (Session::haveRight("search_config", DisplayPreference::GENERAL)) {
                     //|| Session::haveRight("search_config_global",CREATE)) {
                     //                   Ajax::createModalWindow('searchconfig_window',
                     //                         $CFG_GLPI['root_doc']."/ajax/searchconfig.php?itemtype=$itemtype",
                     //                         array('title'    => __('Select default items to show'),
                     //                               'width'    => '1000'));
                     //                   $tmp = " class='pointer' onClick=\"searchconfig_window.show()\"";
                     $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=\"" . __s('Select default items to show') . "\" title=\"" . __s('Select default items to show') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' ";
                     $search_config .= $tmp . ">";
                 }
                 Html::printPager($p['start'], $numrows, $target, $parameters, $itemtype, 0, $search_config);
             }
             // Define begin and end var for loop
             // Search case
             $begin_display = $p['start'];
             $end_display = min($numrows, $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;
             }
             // Form to massive actions
             $isadmin = $item && $item->canUpdate();
             if (!$isadmin && in_array($itemtype, $CFG_GLPI["infocom_types"])) {
                 $isadmin = Infocom::canUpdate() || Infocom::canCreate();
             }
             $showmassiveactions = false;
             if ($itemtype != 'AllAssets') {
                 $showmassiveactions = count($item->getAllMassiveActions($p['is_deleted']));
                 if ($showmassiveactions && $output_type == self::HTML_OUTPUT) {
                     Html::openMassiveActionsForm('massform' . $itemtype);
                     $massiveactionparams = array('num_displayed' => $end_display - $begin_display, 'fixed' => false, 'is_deleted' => $p['is_deleted']);
                     Html::showMassiveActions($itemtype, $massiveactionparams);
                 }
             }
             // 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]) && !empty($p['itemtype2'][$i]) && isset($p['contains2'][$i]) && strlen($p['contains2'][$i]) > 0 && (!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 == self::HTML_OUTPUT) {
                 // HTML display - massive modif
                 $nbcols++;
             }
             // Display List Header
             echo self::showHeader($output_type, $end_display - $begin_display + 1, $nbcols);
             // New Line for Header Items Line
             $headers_line = '';
             $headers_line_top = '';
             $headers_line_bottom = '';
             echo self::showNewLine($output_type);
             $header_num = 1;
             if ($output_type == self::HTML_OUTPUT && $showmassiveactions) {
                 // HTML display - massive modif
                 $headers_line_top .= self::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $header_num, "", 0, $p['order']);
                 $headers_line_bottom .= self::showHeaderItem($output_type, Html::getCheckAllAsCheckbox('massform' . $itemtype), $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;
                 }
                 $headers_line .= 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]])) {
                                 if ($metaitem = getItemForItemtype($p['itemtype2'][$i])) {
                                     $metanames[$p['itemtype2'][$i]] = $metaitem->getTypeName();
                                 }
                             }
                             $headers_line .= self::showHeaderItem($output_type, sprintf(__('%1$s - %2$s'), $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') {
                 $headers_line .= self::showHeaderItem($output_type, _n('Cartridge', 'Cartridges', 2), $header_num);
             }
             if ($itemtype == 'ConsumableItem') {
                 $headers_line .= self::showHeaderItem($output_type, _n('Consumable', 'Consumables', 2), $header_num);
             }
             if (isset($CFG_GLPI["union_search_type"][$itemtype])) {
                 $headers_line .= self::showHeaderItem($output_type, __('Item type'), $header_num);
             }
             if ($itemtype == 'ReservationItem' && $output_type == self::HTML_OUTPUT) {
                 $headers_line .= self::showHeaderItem($output_type, "&nbsp;", $header_num);
             }
             // End Line for column headers
             $headers_line .= self::showEndLine($output_type);
             $headers_line_top .= $headers_line;
             $headers_line_bottom .= $headers_line;
             echo $headers_line_top;
             // 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 == self::HTML_OUTPUT) {
                 Session::initNavigateListItems($itemtype);
             }
             // Num of the row (1=header_line)
             $row_num = 1;
             $massiveaction_field = 'id';
             if (isset($CFG_GLPI["union_search_type"][$itemtype])) {
                 $massiveaction_field = 'refID';
             }
             // 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
                 Session::addToNavigateListItems($itemtype, $data["id"]);
                 if ($output_type == self::HTML_OUTPUT && $showmassiveactions) {
                     // HTML display - massive modif
                     $tmpcheck = "";
                     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 {
                             $tmpcheck = Html::getMassiveActionCheckBox($itemtype, $data[$massiveaction_field]);
                         }
                     }
                     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 = self::explodeWithID("\$\$", $split[$k]);
                                             if (isset($split2[1])) {
                                                 if (isset($searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['datatype']) && $searchopt[$p['itemtype2'][$j]][$p['field2'][$j]]['datatype'] == 'itemlink') {
                                                     $out .= "<a id='" . $p['itemtype2'][$j] . '_' . $data["id"] . '_' . $split2[1] . "' ";
                                                     $out .= "href=\"" . Toolbox::getItemTypeFormURL($p['itemtype2'][$j]) . "?id=" . $split2[1] . "\">";
                                                     $out .= Dropdown::getValueWithUnit($split2[0], $unit);
                                                     $linkout = $out;
                                                     if ($_SESSION["glpiis_ids_visible"] || empty($split2[0])) {
                                                         $linkout = sprintf(__('%1$s (%2$s)'), $linkout, $split2[1]);
                                                     }
                                                     $out = $linkout . "</a>";
                                                 } else {
                                                     $out .= Dropdown::getValueWithUnit($split2[0], $unit);
                                                 }
                                             } else {
                                                 $out .= Dropdown::getValueWithUnit($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 != self::HTML_OUTPUT), $item_num, $row_num);
                 }
                 if ($itemtype == 'ConsumableItem') {
                     echo self::showItem($output_type, Consumable::getCount($data["id"], $data["ALARM"], $output_type != self::HTML_OUTPUT), $item_num, $row_num);
                 }
                 if (isset($CFG_GLPI["union_search_type"][$itemtype])) {
                     $typename = $data["TYPE"];
                     if ($itemtmp = getItemForItemtype($data["TYPE"])) {
                         $typename = $itemtmp->getTypeName();
                     }
                     echo self::showItem($output_type, $typename, $item_num, $row_num);
                 }
                 if ($itemtype == 'ReservationItem' && $output_type == self::HTML_OUTPUT) {
                     if ($data["ACTIVE"]) {
                         echo self::showItem($output_type, "<a href='reservation.php?reservationitems_id=" . $data["refID"] . "' title=\"" . __s('See planning') . "\">" . "<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 == self::PDF_OUTPUT_LANDSCAPE || $output_type == self::PDF_OUTPUT_PORTRAIT) {
                 if ($_SESSION["glpisearchcount"][$itemtype] > 0 && count($p['contains']) > 0) {
                     for ($key = 0; $key < $_SESSION["glpisearchcount"][$itemtype]; $key++) {
                         $titlecontain = '';
                         if (strlen($p['contains'][$key]) > 0) {
                             if (isset($p["link"][$key])) {
                                 $titlecontain = " " . $p["link"][$key] . " ";
                             }
                             switch ($p['field'][$key]) {
                                 case "all":
                                     $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, __('All'));
                                     break;
                                 case "view":
                                     $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, __('Items seen'));
                                     break;
                                 default:
                                     $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, $searchopt[$itemtype][$p['field'][$key]]["name"]);
                             }
                             switch ($p['searchtype'][$key]) {
                                 case "equals":
                                     if (in_array($searchopt[$itemtype][$p['field'][$key]]["field"], array('name', 'completename'))) {
                                         $titlecontain = sprintf(__('%1$s = %2$s'), $titlecontain, Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key]));
                                     } else {
                                         $titlecontain = sprintf(__('%1$s = %2$s'), $titlecontain, $p['contains'][$key]);
                                     }
                                     break;
                                 case "notequals":
                                     if (in_array($searchopt[$itemtype][$p['field'][$key]]["field"], array('name', 'completename'))) {
                                         $titlecontain = sprintf(__('%1$s <> %2$s'), $titlecontain, Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key]));
                                     } else {
                                         $titlecontain = sprintf(__('%1$s <> %2$s'), $titlecontain, $p['contains'][$key]);
                                     }
                                     break;
                                 case "lessthan":
                                     $titlecontain = sprintf(__('%1$s < %2$s'), $titlecontain, $p['contains'][$key]);
                                     break;
                                 case "morethan":
                                     $titlecontain = sprintf(__('%1$s > %2$s'), $titlecontain, $p['contains'][$key]);
                                     break;
                                 case "contains":
                                     $titlecontain = sprintf(__('%1$s = %2$s'), $titlecontain, '%' . $p['contains'][$key] . '%');
                                     break;
                                 case "under":
                                     $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, sprintf(__('%1$s %2$s'), __('under'), Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key])));
                                     break;
                                 case "notunder":
                                     $titlecontain = sprintf(__('%1$s %2$s'), $titlecontain, sprintf(__('%1$s %2$s'), __('not under'), Dropdown::getDropdownName($searchopt[$itemtype][$p['field'][$key]]["table"], $p['contains'][$key])));
                                     break;
                                 default:
                                     $titlecontain = sprintf(__('%1$s = %2$s'), $titlecontain, $p['contains'][$key]);
                                     break;
                             }
                         }
                         $title .= $titlecontain;
                     }
                 }
                 if ($_SESSION["glpisearchcount2"][$itemtype] > 0 && count($p['contains2']) > 0) {
                     for ($key = 0; $key < $_SESSION["glpisearchcount2"][$itemtype]; $key++) {
                         $titlecontain2 = '';
                         if (strlen($p['contains2'][$key]) > 0) {
                             if (isset($p['link2'][$key])) {
                                 $titlecontain2 = sprintf(__('%1$s %2$s'), $titlecontain2, $p['link2'][$key]);
                             }
                             $titlecontain2 = sprintf(__('%1$s %2$s'), $titlecontain2, sprintf(__('%1$s / %2$s'), $metanames[$p['itemtype2'][$key]], $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'))) {
                                         $titlecontain2 = sprintf(__('%1$s = %2$s'), $titlecontain2, Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key]));
                                     } else {
                                         $titlecontain2 = sprintf(__('%1$s = %2$s'), $titlecontain2, $p['contains2'][$key]);
                                     }
                                     break;
                                 case "notequals":
                                     if (in_array($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["field"], array('name', 'completename'))) {
                                         $titlecontain2 = sprintf(__('%1$s <> %2$s'), $titlecontain2, Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key]));
                                     } else {
                                         $titlecontain2 = sprintf(__('%1$s <> %2$s'), $titlecontain2, $p['contains2'][$key]);
                                     }
                                     break;
                                 case "lessthan":
                                     $titlecontain2 = sprintf(__('%1$s < %2$s'), $titlecontain2, $p['contains2'][$key]);
                                     break;
                                 case "morethan":
                                     $titlecontain2 = sprintf(__('%1$s > %2$s'), $titlecontain2, $p['contains2'][$key]);
                                     break;
                                 case "contains":
                                     $titlecontain2 = sprintf(__('%1$s = %2$s'), $titlecontain2, '%' . $p['contains2'][$key] . '%');
                                     break;
                                 case "under":
                                     $titlecontain2 = sprintf(__('%1$s %2$s'), $titlecontain2, sprintf(__('%1$s %2$s'), __('under'), Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key])));
                                     break;
                                 case "notunder":
                                     $titlecontain2 = sprintf(__('%1$s %2$s'), $titlecontain2, sprintf(__('%1$s %2$s'), __('not under'), Dropdown::getDropdownName($searchopt[$p['itemtype2'][$key]][$p['field2'][$key]]["table"], $p['contains2'][$key])));
                                     break;
                                 default:
                                     $titlecontain2 = sprintf(__('%1$s = %2$s'), $titlecontain2, $p['contains2'][$key]);
                                     break;
                             }
                         }
                         $title .= $titlecontain2;
                     }
                 }
             }
             if ($output_type == self::HTML_OUTPUT) {
                 echo $headers_line_bottom;
             }
             // Display footer
             echo self::showFooter($output_type, $title);
             // Delete selected item
             if ($output_type == self::HTML_OUTPUT) {
                 if ($showmassiveactions) {
                     $massiveactionparams['ontop'] = false;
                     Html::showMassiveActions($itemtype, $massiveactionparams);
                     // End form for delete item
                     Html::closeForm();
                 } else {
                     echo "<br>";
                 }
             }
             if ($output_type == self::HTML_OUTPUT) {
                 // In case of HTML display
                 Html::printPager($p['start'], $numrows, $target, $parameters, '', 0, $search_config);
             }
         } else {
             echo self::showError($output_type);
         }
     } else {
         echo $DBread->error();
     }
 }
예제 #16
0
파일: event.class.php 프로젝트: stweil/glpi
 /**
  * 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: ) (default 'DESC')
  * @param $sort      order by clause occurences (eg: date) (defaut 'date')
  * @param $start     (default 0)
  **/
 static function showList($target, $order = 'DESC', $sort = 'date', $start = 0)
 {
     global $DB, $CFG_GLPI;
     // Show events from $result in table form
     list($logItemtype, $logService) = self::logArray();
     // Columns of the Table
     $items = array("type" => array(__('Source'), ""), "items_id" => array(__('ID'), ""), "date" => array(__('Date'), ""), "service" => array(__('Service'), "width='8%'"), "level" => array(__('Level'), "width='8%'"), "message" => array(__('Message'), "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'>" . __('No Event') . "</div>";
         return;
     }
     // Output events
     $i = 0;
     echo "<div class='center'>";
     $parameters = "sort={$sort}&amp;order={$order}";
     Html::printPager($start, $numrows, $target, $parameters);
     echo "<table class='tab_cadre_fixehov'>";
     echo "<tr>";
     foreach ($items as $field => $args) {
         echo "<th " . $args[1] . "";
         if ($sort == $field) {
             echo " class='order_{$order}' ";
         }
         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 ($item = getItemForItemtype($type)) {
                 $itemtype = $item->getTypeName(1);
             }
         }
         echo "<tr class='tab_bg_2'>";
         echo "<td>{$itemtype}</td>";
         echo "<td class='center b'>";
         self::displayItemLogID($type, $items_id);
         echo "</td><td>" . Html::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>";
 }
 function showReport($params)
 {
     global $CFG_GLPI;
     $PluginAddressingReport = new PluginAddressingReport();
     // Default values of parameters
     $default_values["start"] = $start = 0;
     $default_values["id"] = $id = 0;
     $default_values["export"] = $export = false;
     foreach ($default_values as $key => $val) {
         if (isset($params[$key])) {
             ${$key} = $params[$key];
         }
     }
     if ($this->getFromDB($id)) {
         $result = $this->compute($start);
         $nbipf = 0;
         // ip libres
         $nbipr = 0;
         // ip reservees
         $nbipt = 0;
         // ip trouvees
         $nbipd = 0;
         // doublons
         foreach ($result as $ip => $lines) {
             if (count($lines)) {
                 if (count($lines) > 1) {
                     $nbipd++;
                 }
                 if (isset($lines[0]['pname']) && strstr($lines[0]['pname'], "reserv")) {
                     $nbipr++;
                 }
                 $nbipt++;
             } else {
                 $nbipf++;
             }
         }
         ////title
         echo "<div class='spaced'>";
         echo "<table class='tab_cadre_fixe'><tr class='tab_bg_2 left'>";
         echo "<td>";
         if ($this->fields['free_ip']) {
             echo __('Number of free ip', 'addressing') . " " . $nbipf . "<br>";
         }
         if ($this->fields['reserved_ip']) {
             echo __('Number of reserved ip', 'addressing') . " " . $nbipr . "<br>";
         }
         if ($this->fields['alloted_ip']) {
             echo __('Number of assigned ip (no doubles)', 'addressing') . " " . $nbipt . "<br>";
         }
         if ($this->fields['double_ip']) {
             echo __('Doubles', 'addressing') . " " . $nbipd . "<br>";
         }
         echo "</td>";
         echo "<td>";
         if ($this->fields['double_ip']) {
             echo "<span class='plugin_addressing_ip_double'>" . __('Red row', 'addressing') . "</span> - " . __('Same Ip', 'addressing') . "<br>";
         }
         if (isset($this->fields['use_ping']) && $this->fields['use_ping']) {
             echo __('Ping free Ip', 'addressing') . "<br>";
             echo "<span class='plugin_addressing_ping_off'>" . __('Ping: got a response - used Ip', 'addressing') . "</span><br>";
             echo "<span class='plugin_addressing_ping_on'>" . __('Ping: no response - free Ip', 'addressing') . "</span>";
         } else {
             echo "<span class='plugin_addressing_ip_free'>" . __('Blue row', 'addressing') . "</span> - " . __('Free Ip', 'addressing') . "<br>";
         }
         echo "</td></tr>";
         echo "<tr><td colspan='2' align='center'>";
         echo "<a href='./report.form.php?id=" . $this->getID() . "&export=true'>" . __('Export') . "</a>";
         echo "</td></tr>";
         echo "</table>";
         echo "</div>";
         $numrows = 1 + ip2long($this->fields['end_ip']) - ip2long($this->fields['begin_ip']);
         if (strpos($_SERVER['PHP_SELF'], "report.form.php")) {
             Html::printPager($start, $numrows, $_SERVER['PHP_SELF'], "start={$start}&amp;id=" . $id, 'PluginAddressingReport');
         } else {
             Html::printAjaxPager("", $start, $numrows);
         }
         //////////////////////////liste ips////////////////////////////////////////////////////////////
         $ping_response = $PluginAddressingReport->displayReport($result, $this);
         if ($this->fields['use_ping']) {
             $total_realfreeip = $nbipf - $ping_response;
             echo "<table class='tab_cadre_fixe'><tr class='tab_bg_2 center'>";
             echo "<td>";
             echo __('Real free Ip (Ping=KO)', 'addressing') . " " . $total_realfreeip;
             echo "</td></tr>";
             echo "</table>";
         }
         echo "</div>";
     } else {
         echo "<div class='center'>" . "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/warning.png\" alt='warning'><br><br><b>" . __('Problem detected with the IP Range', 'addressing') . "</b></div>";
     }
 }
 /**
  * @param $plugin_ocsinventoryng_ocsservers_id
  * @param $check
  * @param $start
  * @return bool|void
  */
 static function showSnmpDeviceToUpdate($plugin_ocsinventoryng_ocsservers_id, $check, $start)
 {
     global $DB, $CFG_GLPI;
     PluginOcsinventoryngOcsServer::checkOCSconnection($plugin_ocsinventoryng_ocsservers_id);
     if (!Session::haveRight("plugin_ocsinventoryng", UPDATE)) {
         return false;
     }
     // Get linked computer ids in GLPI
     $already_linked_query = "SELECT `glpi_plugin_ocsinventoryng_snmpocslinks`.`ocs_id` AS ocsid\n                               FROM `glpi_plugin_ocsinventoryng_snmpocslinks`\n                               WHERE `glpi_plugin_ocsinventoryng_snmpocslinks`.`plugin_ocsinventoryng_ocsservers_id`\n                                            = '{$plugin_ocsinventoryng_ocsservers_id}'";
     $already_linked_result = $DB->query($already_linked_query);
     if ($DB->numrows($already_linked_result) == 0) {
         echo "<div class='center b'>" . __('No new SNMP device to be updated', 'ocsinventoryng') . "</div>";
         return;
     }
     $already_linked_ids = array();
     while ($data = $DB->fetch_assoc($already_linked_result)) {
         $already_linked_ids[] = $data['ocsid'];
     }
     // Fetch linked items from ocs
     $ocsClient = PluginOcsinventoryngOcsServer::getDBocs($plugin_ocsinventoryng_ocsservers_id);
     $ocsResult = $ocsClient->getSnmp(array('ORDER' => 'LASTDATE', 'FILTER' => array('IDS' => $already_linked_ids)));
     if (isset($ocsResult['SNMP'])) {
         if (count($ocsResult['SNMP']) > 0) {
             // Get all ids of the returned items
             $ocs_snmp_ids = array();
             $hardware = array();
             $snmps = array_slice($ocsResult['SNMP'], $start, $_SESSION['glpilist_limit']);
             foreach ($snmps as $snmp) {
                 $LASTDATE = $snmp['META']['LASTDATE'];
                 $ocs_snmp_inv[$snmp['META']['ID']] = $LASTDATE;
                 $NAME = $snmp['META']['NAME'];
                 $ocs_snmp_name[$snmp['META']['ID']] = $NAME;
                 $ID = $snmp['META']['ID'];
                 $ocs_snmp_ids[] = $ID;
                 if (isset($snmp['PRINTER'])) {
                     $TYPE = "printer";
                 } else {
                     $TYPE = "";
                 }
                 $ocs_snmp_type[$snmp['META']['ID']] = $TYPE;
             }
             // query snmp links
             $query = "SELECT * FROM `glpi_plugin_ocsinventoryng_snmpocslinks`\n                WHERE `glpi_plugin_ocsinventoryng_snmpocslinks`.`ocs_id` IN (" . implode(',', $ocs_snmp_ids) . ")";
             $result = $DB->query($query);
             // Get all links between glpi and OCS
             $already_linked = array();
             if ($DB->numrows($result) > 0) {
                 while ($data = $DB->fetch_assoc($result)) {
                     $data = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($data));
                     $format = 'Y-m-d H:i:s';
                     //                  $last_glpi_update = DateTime::createFromFormat($format, $data['last_update']);
                     //                  $last_ocs_inventory = DateTime::createFromFormat($format, $ocs_snmp_inv[$data['ocs_id']]);
                     //TODOSNMP comment for test
                     //if ($last_ocs_inventory > $last_glpi_update) {
                     $already_linked[$data['id']] = $data;
                     //}
                 }
             }
             echo "<div class='center'>";
             echo "<h2>" . __('Snmp device updated in OCSNG', 'ocsinventoryng') . "</h2>";
             $target = $CFG_GLPI['root_doc'] . '/plugins/ocsinventoryng/front/ocsngsnmp.sync.php';
             if (($numrows = $ocsResult['TOTAL_COUNT']) > 0) {
                 $parameters = "check={$check}";
                 Html::printPager($start, $numrows, $target, $parameters);
                 echo "<form method='post' id='ocsng_form' name='ocsng_form' action='" . $target . "'>";
                 PluginOcsinventoryngOcsServer::checkBox($target);
                 echo "<table class='tab_cadre_fixe'>";
                 echo "<tr class='tab_bg_1'><td colspan='6' class='center'>";
                 echo "<input class='submit' type='submit' name='update_ok' value=\"" . _sx('button', 'Synchronize', 'ocsinventoryng') . "\">";
                 echo "&nbsp;<input class='submit' type='submit' name='delete' value=\"" . _sx('button', 'Delete link', 'ocsinventoryng') . "\">";
                 echo "</td></tr>\n";
                 echo "<tr>";
                 echo "<th>" . __('GLPI Object', 'ocsinventoryng') . "</th>";
                 echo "<th>" . __('Item type') . "</th>";
                 echo "<th>" . __('OCS SNMP device', 'ocsinventoryng') . "</th>";
                 echo "<th>" . __('Import date in GLPI', 'ocsinventoryng') . "</th>";
                 echo "<th>" . __('Last OCSNG SNMP inventory date', 'ocsinventoryng') . "</th>";
                 echo "<th>&nbsp;</th></tr>\n";
                 foreach ($already_linked as $ID => $tab) {
                     echo "<tr class='tab_bg_2 center'>";
                     $item = new $tab["itemtype"]();
                     $item->getFromDB($tab["items_id"]);
                     echo "<td>" . $item->getLink() . "</td>\n";
                     echo "<td>" . $item->getTypeName() . "</td>\n";
                     echo "<td>" . $ocs_snmp_name[$tab["ocs_id"]] . "</td>\n";
                     echo "<td>" . Html::convDateTime($tab["last_update"]) . "</td>\n";
                     echo "<td>" . Html::convDateTime($ocs_snmp_inv[$tab["ocs_id"]]) . "</td>\n";
                     echo "<td><input type='checkbox' name='toupdate[" . $tab["id"] . "]' " . ($check == "all" ? "checked" : "") . ">";
                     echo "</td></tr>\n";
                 }
                 echo "<tr class='tab_bg_1'><td colspan='6' class='center'>";
                 echo "<input class='submit' type='submit' name='update_ok' value=\"" . _sx('button', 'Synchronize', 'ocsinventoryng') . "\">";
                 echo "&nbsp;<input class='submit' type='submit' name='delete' value=\"" . _sx('button', 'Delete link', 'ocsinventoryng') . "\">";
                 echo "<input type=hidden name='plugin_ocsinventoryng_ocsservers_id' " . "value='{$plugin_ocsinventoryng_ocsservers_id}'>";
                 echo "</td></tr>";
                 echo "<tr class='tab_bg_1'><td colspan='6' class='center'>";
                 PluginOcsinventoryngOcsServer::checkBox($target);
                 echo "</table>\n";
                 Html::closeForm();
                 Html::printPager($start, $numrows, $target, $parameters);
             } else {
                 echo "<br><span class='b'>" . __('Update SNMP device', 'ocsinventoryng') . "</span>";
             }
             echo "</div>";
         } else {
             echo "<div class='center b'>" . __('No new SNMP device to be updated', 'ocsinventoryng') . "</div>";
         }
     } else {
         echo "<div class='center b'>" . __('No new SNMP device to be updated', 'ocsinventoryng') . "</div>";
     }
 }
 /**
  * @param $target
  * @param $date1
  * @param $date2
  * @param $start
  **/
 static function showItems($target, $date1, $date2, $start)
 {
     global $DB, $CFG_GLPI;
     $view_entities = Session::isMultiEntitiesMode();
     if ($view_entities) {
         $entities = getAllDatasFromTable('glpi_entities');
     }
     $output_type = Search::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 `glpi_items_tickets`.`itemtype`,\n                       `glpi_items_tickets`.`items_id`,\n                       COUNT(*) AS NB\n                FROM `glpi_tickets`\n                LEFT JOIN `glpi_items_tickets`\n                   ON (`glpi_tickets`.`id` = `glpi_items_tickets`.`tickets_id`)\n                WHERE `date` <= '{$date2}'\n                      AND `glpi_tickets`.`date` >= '{$date1}' " . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n                      AND `glpi_items_tickets`.`itemtype` <> ''\n                      AND `glpi_items_tickets`.`items_id` > 0\n                GROUP BY `glpi_items_tickets`.`itemtype`, `glpi_items_tickets`.`items_id`\n                ORDER BY NB DESC";
     $result = $DB->query($query);
     $numrows = $DB->numrows($result);
     if ($numrows > 0) {
         if ($output_type == Search::HTML_OUTPUT) {
             Html::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, _n('Associated element', 'Associated elements', 2), $header_num);
         if ($view_entities) {
             echo Search::showHeaderItem($output_type, __('Entity'), $header_num);
         }
         echo Search::showHeaderItem($output_type, __('Number of tickets'), $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 (!($item = getItemForItemtype($data["itemtype"]))) {
                 continue;
             }
             if ($item->getFromDB($data["items_id"])) {
                 echo Search::showNewLine($output_type, $i % 2);
                 echo Search::showItem($output_type, sprintf(__('%1$s - %2$s'), $item->getTypeName(), $item->getLink()), $item_num, $i - $start + 1, "class='center'" . " " . ($item->isDeleted() ? " class='deleted' " : ""));
                 if ($view_entities) {
                     $ent = $item->getEntityID();
                     $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 == Search::HTML_OUTPUT) {
             echo "</div>";
         }
     }
 }
 /**
  * show  hardware to be identified, or identified and imported, or just the hardware with agents installed on them
  * @param type $hardware array
  * @param type $lim integer
  * @param int|type $start integer
  * @param type $ipAdress string
  * @param type $status string
  * @param $subnet
  * @param $action
  * @global type $CFG_GLPI
  */
 static function showHardware($hardware, $lim, $start = 0, $ipAdress, $status, $subnet, $action)
 {
     global $CFG_GLPI, $DB;
     $output_type = Search::HTML_OUTPUT;
     //0
     $link = $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/front/ipdiscover.import.php";
     $return = $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/front/ipdiscover.php";
     $returnargs = "subnetsChoice={$subnet}&action={$action}";
     $reload = "ip={$ipAdress}&status={$status}&action={$action}";
     $backValues = "?b[]={$ipAdress}&b[]={$status}";
     if ($status == "inventoried") {
         $status_name = __('Inventoried', 'ocsinventoryng');
     } elseif ($status == "imported") {
         $status_name = __('Imported / Linked', 'ocsinventoryng');
     } elseif ($status == "noninventoried") {
         $status_name = __('Non Inventoried', 'ocsinventoryng');
     } else {
         $status_name = __('Identified', 'ocsinventoryng');
     }
     $subnet_name = self::getSubnetNamebyIP($ipAdress);
     echo "<div class='center'>";
     echo "<h2>" . __('Subnet', 'ocsinventoryng') . " " . $subnet_name . " (" . $ipAdress . ") - " . $status_name;
     echo "&nbsp;";
     $refresh = $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/front/ipdiscover.import.php?" . $reload;
     Html::showSimpleForm($refresh, 'refresh', _sx('button', 'Refresh'), array(), $CFG_GLPI["root_doc"] . "/plugins/ocsinventoryng/pics/synchro.png");
     echo "</h2>";
     echo "</div>";
     if ($subnet >= 0) {
         $back = __('Back');
         echo "<div class='center'><a href='{$return}?{$returnargs}'>{$back}</div>";
     }
     echo Html::printPager($start, count($hardware), $link, $reload);
     echo Search::showNewLine($output_type, true);
     if (empty($hardware)) {
         echo "<div class='center b'><br>" . __('No new IPDiscover device to import', 'ocsinventoryng') . "</div>";
         Html::displayBackLink();
     } else {
         $header_num = 1;
         switch ($status) {
             case "inventoried":
                 echo "<table width='100%'class='tab_cadrehov'>\n";
                 echo Search::showHeaderItem($output_type, __('User'), $header_num);
                 echo Search::showHeaderItem($output_type, __('Name'), $header_num);
                 echo Search::showHeaderItem($output_type, __('System'), $header_num);
                 echo Search::showHeaderItem($output_type, __('Version of the operating system'), $header_num);
                 echo Search::showHeaderItem($output_type, __('IP address'), $header_num);
                 echo Search::showHeaderItem($output_type, __('Last OCSNG inventory date', 'ocsinventoryng'), $header_num);
                 echo Search::showEndLine($output_type);
                 $row_num = 1;
                 for ($i = $start; $i < $lim + $start; $i++) {
                     if (isset($hardware[$i])) {
                         $row_num++;
                         $item_num = 1;
                         echo Search::showNewLine($output_type, $row_num % 2);
                         echo Search::showItem($output_type, $hardware[$i]["userid"], $item_num, $row_num);
                         echo Search::showItem($output_type, $hardware[$i]["name"], $item_num, $row_num);
                         echo Search::showItem($output_type, $hardware[$i]["osname"], $item_num, $row_num);
                         echo Search::showItem($output_type, $hardware[$i]["osversion"], $item_num, $row_num);
                         echo Search::showItem($output_type, $hardware[$i]["ipaddr"], $item_num, $row_num);
                         echo Search::showItem($output_type, Html::convDateTime($hardware[$i]["lastdate"]), $item_num, $row_num);
                         echo Search::showEndLine($output_type);
                     }
                 }
                 echo "</table>\n";
                 break;
             case "imported":
                 $target = $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/front/ipdiscover.import.php" . $backValues;
                 self::checkBox($target);
                 echo "<form method='post' id='ipdiscover_form' name='ipdiscover_form' action='{$target}'>";
                 echo "<div class='center' style=\"width=100%\">";
                 echo "<input type='submit' class='submit' name='deletelink'  value=\"" . _sx('button', 'Delete link', 'ocsinventoryng') . "\"></div>";
                 echo "<table width='100%'class='tab_cadrehov'>\n";
                 echo Search::showHeaderItem($output_type, __('Item'), $header_num);
                 echo Search::showHeaderItem($output_type, __('Item type'), $header_num);
                 echo Search::showHeaderItem($output_type, __('MAC address'), $header_num);
                 echo Search::showHeaderItem($output_type, __('IP address'), $header_num);
                 echo Search::showHeaderItem($output_type, __('Location'), $header_num);
                 echo Search::showHeaderItem($output_type, __('Import date in GLPI', 'ocsinventoryng'), $header_num);
                 echo Search::showHeaderItem($output_type, __('Subnet'), $header_num);
                 echo Search::showHeaderItem($output_type, __('&nbsp;'), $header_num);
                 echo Search::showEndLine($output_type);
                 $row_num = 1;
                 for ($i = $start; $i < $lim + $start; $i++) {
                     if (isset($hardware[$i])) {
                         $row_num++;
                         $item_num = 1;
                         echo Search::showNewLine($output_type, $row_num % 2);
                         $class = getItemForItemtype($hardware[$i]["itemtype"]);
                         $class->getFromDB($hardware[$i]["items_id"]);
                         $iplist = "";
                         $ip = new IPAddress();
                         // Update IPAddress
                         foreach ($DB->request('glpi_networkports', array('itemtype' => $hardware[$i]["itemtype"], 'items_id' => $hardware[$i]["items_id"])) as $netname) {
                             foreach ($DB->request('glpi_networknames', array('itemtype' => 'NetworkPort', 'items_id' => $netname['id'])) as $dataname) {
                                 foreach ($DB->request('glpi_ipaddresses', array('itemtype' => 'NetworkName', 'items_id' => $dataname['id'])) as $data) {
                                     $ip->getFromDB($data['id']);
                                     $iplist .= $ip->getName() . "<br>";
                                 }
                             }
                         }
                         echo Search::showItem($output_type, $class->getLink(), $item_num, $row_num);
                         echo Search::showItem($output_type, $class->getTypeName(), $item_num, $row_num);
                         echo Search::showItem($output_type, $hardware[$i]["macaddress"], $item_num, $row_num);
                         echo Search::showItem($output_type, $iplist, $item_num, $row_num);
                         echo Search::showItem($output_type, Dropdown::getDropdownName("glpi_locations", $class->fields["locations_id"]), $item_num, $row_num);
                         echo Search::showItem($output_type, Html::convDateTime($hardware[$i]["last_update"]), $item_num, $row_num);
                         echo Search::showItem($output_type, $hardware[$i]["subnet"], $item_num, $row_num);
                         echo self::showItem($hardware[$i]["id"], "", "", "", true, "", $i);
                         echo Search::showEndLine($output_type);
                     }
                 }
                 echo "<tbody style=\"display:none\">";
                 echo "<tr><td><input type=\"hidden\" name='subnet' value=\"{$ipAdress}\" ></td></tr>";
                 echo "</tbody>";
                 echo "</table>\n";
                 echo "<div class='center' style=\"width=100%\">";
                 echo "<input type='submit' class='submit' name='deletelink'  value=\"" . _sx('button', 'Delete link', 'ocsinventoryng') . "\"></div>";
                 Html::closeForm();
                 self::checkBox($target);
                 break;
             case "noninventoried":
                 $ocsTypes = array("id" => array(Dropdown::EMPTY_VALUE), "name" => array(Dropdown::EMPTY_VALUE));
                 $link = $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/front/ipdiscover.php";
                 $target = $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/front/ipdiscover.import.php" . $backValues;
                 $macConstructor = "";
                 self::getOCSTypes($ocsTypes);
                 self::checkBox($target);
                 echo "<form method='post' id='ipdiscover_form' name='ipdiscover_form' action='{$target}'>";
                 echo "<div class='center' style=\"width=100%\">";
                 if ($action == "import") {
                     echo "<input type='submit' class='submit' name='IdentifyAndImport'  value=\"" . _sx('button', 'Import') . "\">";
                     echo "&nbsp;";
                 } else {
                     echo "<input type='submit' class='submit' name='IdentifyAndLink'  value=\"" . _sx('button', 'Link', 'ocsinventoryng') . "\">";
                     echo "&nbsp;";
                 }
                 echo "<input type='submit' class='submit' name='delete'  value=\"" . _sx('button', 'Delete from OCSNG', 'ocsinventoryng') . "\"></div>";
                 echo "<table width='100%'class='tab_cadrehov'>\n";
                 echo Search::showHeaderItem($output_type, __('Date'), $header_num);
                 echo Search::showHeaderItem($output_type, __('MAC address'), $header_num);
                 echo Search::showHeaderItem($output_type, __('IP address'), $header_num);
                 echo Search::showHeaderItem($output_type, __('Subnet mask'), $header_num);
                 echo Search::showHeaderItem($output_type, __('DNS', 'ocsinventoryng'), $header_num);
                 echo Search::showHeaderItem($output_type, __('Description') . "<span class='red'>*</span>", $header_num);
                 echo Search::showHeaderItem($output_type, __('OCS Type', 'ocsinventoryng') . "<span class='red'>*</span>", $header_num);
                 if ($action == "import") {
                     echo Search::showHeaderItem($output_type, __('Name'), $header_num);
                     if (Session::isMultiEntitiesMode()) {
                         echo Search::showHeaderItem($output_type, __('Entity'), $header_num);
                     }
                     echo Search::showHeaderItem($output_type, __('GLPI Type', 'ocsinventoryng') . "<span class='red'>*</span>", $header_num);
                 } else {
                     echo Search::showHeaderItem($output_type, __('Item to link', 'ocsinventoryng'), $header_num, "", 0, "", 'width=15%');
                 }
                 echo Search::showHeaderItem($output_type, __('&nbsp;'), $header_num);
                 echo Search::showEndLine($output_type);
                 $row_num = 1;
                 $ocstypes = array();
                 foreach ($ocsTypes["name"] as $items) {
                     $ocstypes[$items] = $items;
                 }
                 $itemstypes = array(Dropdown::EMPTY_VALUE);
                 foreach (self::$hardwareItemTypes as $items) {
                     $class = getItemForItemtype($items);
                     $itemstypes[$items] = $class->getTypeName();
                 }
                 for ($i = $start; $i < $lim + $start; $i++) {
                     if (isset($hardware[$i])) {
                         $row_num++;
                         echo Search::showNewLine($output_type, $row_num % 2);
                         echo self::showItem(Html::convDateTime($hardware[$i]["date"]));
                         if (isset($_SESSION["OCS"]["IpdiscoverMacConstructors"])) {
                             $macs = unserialize($_SESSION["OCS"]["IpdiscoverMacConstructors"]);
                             if (isset($macs[mb_strtoupper(substr($hardware[$i]["mac"], 0, 8))])) {
                                 $macConstructor = $macs[mb_strtoupper(substr($hardware[$i]["mac"], 0, 8))];
                             } else {
                                 $macConstructor = __("unknow");
                             }
                         }
                         $mac = $hardware[$i]["mac"] . "<small> ( " . $macConstructor . " )</small>";
                         echo self::showItem($mac);
                         echo self::showItem($ip = $hardware[$i]["ip"]);
                         echo self::showItem($hardware[$i]["mask"]);
                         echo self::showItem($hardware[$i]["DNS"]);
                         echo "<td><input type=\"text\" name='itemsdescription[" . $i . "]' value=\"\" ></td>";
                         echo "<td>";
                         Dropdown::showFromArray("ocsitemstype[{$i}]", $ocstypes);
                         echo "</td>";
                         if ($action == "import") {
                             echo "<td><input type=\"text\" name='itemsname[" . $i . "]' value=\"\"></td>";
                             if (Session::isMultiEntitiesMode()) {
                                 echo "<td>";
                                 Entity::dropdown(array('name' => "entities[{$i}]", 'entity' => $_SESSION["glpiactiveentities"]));
                                 echo "</td>";
                             }
                             echo "<td>";
                             Dropdown::showFromArray("glpiitemstype[{$i}]", $itemstypes);
                             echo "</td>";
                         } else {
                             echo "<td width='10'>";
                             $mtrand = mt_rand();
                             $mynamei = "itemtype";
                             $myname = "tolink_items[" . $i . "]";
                             $rand = Dropdown::showItemTypes($mynamei, self::$hardwareItemTypes, array('rand' => $mtrand));
                             $p = array('itemtype' => '__VALUE__', 'entity_restrict' => $_SESSION["glpiactiveentities"], 'id' => $i, 'rand' => $rand, 'myname' => $myname);
                             //print_r($p);
                             Ajax::updateItemOnSelectEvent("dropdown_{$mynamei}{$rand}", "results_{$mynamei}{$rand}", $CFG_GLPI["root_doc"] . "/plugins/ocsinventoryng/ajax/dropdownitems.php", $p);
                             echo "<span id='results_{$mynamei}{$rand}'>\n";
                             echo "</span>\n";
                             //}
                             echo "</td>";
                         }
                         echo self::showItem($hardware[$i]["mac"], "", "", "", true, "", $i);
                         echo "<tbody style=\"display:none\">";
                         echo "<tr><td><input type=\"hidden\" name='itemsip[" . $i . "]' value=\"{$ip}\" >\n                           <input type=\"hidden\" name='subnet' value=\"{$ipAdress}\" ></td></tr>";
                         echo "</tbody>";
                     }
                 }
                 echo "</table>\n";
                 echo "<div class='center' style=\"width=100%\">";
                 if ($action == "import") {
                     echo "<input type='submit' class='submit' name='IdentifyAndImport'  value=\"" . _sx('button', 'Import') . "\">";
                     echo "&nbsp;";
                 } else {
                     echo "<input type='submit' class='submit' name='IdentifyAndLink'  value=\"" . _sx('button', 'Link', 'ocsinventoryng') . "\">";
                     echo "&nbsp;";
                 }
                 echo "<input type='submit' class='submit' name='delete'  value=\"" . _sx('button', 'Delete from OCSNG', 'ocsinventoryng') . "\"></div>";
                 Html::closeForm();
                 self::checkBox($target);
                 break;
             default:
                 $link = $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/front/ipdiscover.php";
                 $target = $CFG_GLPI['root_doc'] . "/plugins/ocsinventoryng/front/ipdiscover.import.php" . $backValues;
                 $macConstructor = "";
                 self::checkBox($target);
                 echo "<form method='post' id='ipdiscover_form' name='ipdiscover_form' action='{$target}'>";
                 echo "<div class='center' style=\"width=100%\">";
                 if ($action == "import") {
                     echo "<input type='submit' class='submit' name='Import'  value=\"" . _sx('button', 'Import') . "\">";
                     echo "&nbsp;";
                 } else {
                     echo "<input type='submit' class='submit' name='Link'  value=\"" . _sx('button', 'Link', 'ocsinventoryng') . "\">";
                     echo "&nbsp;";
                 }
                 echo "<input type='submit' class='submit' name='delete'  value=\"" . _sx('button', 'Delete from OCSNG', 'ocsinventoryng') . "\"></div>";
                 echo "<table width='100%'class='tab_cadrehov'>";
                 echo Search::showHeaderItem($output_type, __('Date'), $header_num);
                 echo Search::showHeaderItem($output_type, __('Description'), $header_num);
                 echo Search::showHeaderItem($output_type, __('OCS Type', 'ocsinventoryng'), $header_num);
                 echo Search::showHeaderItem($output_type, __('IP address'), $header_num);
                 echo Search::showHeaderItem($output_type, __('MAC address'), $header_num);
                 if ($action == "import") {
                     if (Session::isMultiEntitiesMode()) {
                         echo Search::showHeaderItem($output_type, __('Entity'), $header_num);
                     }
                     echo Search::showHeaderItem($output_type, __('Name'), $header_num);
                     echo Search::showHeaderItem($output_type, __('GLPI Type', 'ocsinventoryng') . "<span class='red'>*</span>", $header_num);
                 } else {
                     echo Search::showHeaderItem($output_type, __('Item to link', 'ocsinventoryng'), $header_num, "", 0, "", 'width=15%');
                 }
                 echo Search::showHeaderItem($output_type, __('&nbsp;'), $header_num);
                 echo Search::showEndLine($output_type);
                 $row_num = 1;
                 $itemstypes = array(Dropdown::EMPTY_VALUE);
                 foreach (self::$hardwareItemTypes as $items) {
                     $class = getItemForItemtype($items);
                     $itemstypes[$items] = $class->getTypeName();
                 }
                 for ($i = $start; $i < $lim + $start; $i++) {
                     if (isset($hardware[$i])) {
                         $row_num++;
                         echo Search::showNewLine($output_type, $row_num % 2);
                         echo self::showItem(Html::convDateTime($hardware[$i]["date"]));
                         echo self::showItem($description = $hardware[$i]["description"]);
                         echo self::showItem($hardware[$i]["type"]);
                         echo self::showItem($ip = $hardware[$i]["ip"]);
                         if (isset($_SESSION["OCS"]["IpdiscoverMacConstructors"])) {
                             $macs = unserialize($_SESSION["OCS"]["IpdiscoverMacConstructors"]);
                             if (isset($macs[mb_strtoupper(substr($hardware[$i]["mac"], 0, 8))])) {
                                 $macConstructor = $macs[mb_strtoupper(substr($hardware[$i]["mac"], 0, 8))];
                             } else {
                                 $macConstructor = __("unknow");
                             }
                         }
                         $mac = $hardware[$i]["mac"] . "<small> ( " . $macConstructor . " )</small>";
                         echo self::showItem($mac);
                         if ($action == "import") {
                             if (Session::isMultiEntitiesMode()) {
                                 echo "<td>";
                                 Entity::dropdown(array('name' => "entities[{$i}]", 'entity' => $_SESSION["glpiactiveentities"]));
                                 echo "</td>";
                             }
                             echo "<td><input type=\"text\" name='itemsname[" . $i . "]' value=\"\"></td>";
                             echo "<td>";
                             Dropdown::showFromArray("glpiitemstype[{$i}]", $itemstypes);
                             echo "</td>";
                         } else {
                             echo "<td width='10'>";
                             $mtrand = mt_rand();
                             $mynamei = "itemtype";
                             $myname = "tolink_items[" . $i . "]";
                             $rand = Dropdown::showItemTypes($mynamei, self::$hardwareItemTypes, array('rand' => $mtrand));
                             $p = array('itemtype' => '__VALUE__', 'entity_restrict' => $_SESSION["glpiactiveentities"], 'id' => $i, 'rand' => $rand, 'myname' => $myname);
                             Ajax::updateItemOnSelectEvent("dropdown_{$mynamei}{$rand}", "results_{$mynamei}{$rand}", $CFG_GLPI["root_doc"] . "/plugins/ocsinventoryng/ajax/dropdownitems.php", $p);
                             echo "<span id='results_{$mynamei}{$rand}'>\n";
                             echo "</span>\n";
                             echo "</td>";
                         }
                         echo self::showItem($hardware[$i]["mac"], "", "", "", true, "", $i);
                         echo "<tbody style=\"display:none\">";
                         echo "<tr><td><input type=\"hidden\" name='itemsip[" . $i . "]' value=\"{$ip}\" >";
                         echo "<input type=\"hidden\" name='itemsdescription[" . $i . "]' value=\"{$description}\" >\n                             <input type=\"hidden\" name='subnet' value=\"{$ipAdress}\" ></tr>";
                         echo "</td></tr></tbody>";
                     }
                 }
                 echo "</table>";
                 echo "<div class='center' style=\"width=100%\">";
                 if ($action == "import") {
                     echo "<input type='submit' class='submit' name='Import'  value=\"" . _sx('button', 'Import') . "\">";
                     echo "&nbsp;";
                 } else {
                     echo "<input type='submit' class='submit' name='Link'  value=\"" . _sx('button', 'Link', 'ocsinventoryng') . "\">";
                     echo "&nbsp;";
                 }
                 echo "<input type='submit' class='submit' name='delete'  value=\"" . _sx('button', 'Delete from OCSNG', 'ocsinventoryng') . "\"></div>";
                 Html::closeForm();
                 self::checkBox($target);
                 break;
         }
     }
     if ($subnet >= 0) {
         $back = __('Back');
         echo "<div class='center'><a href='{$return}?{$returnargs}'>{$back}</div>";
     }
 }
                        }
                        $param .= $key . "[" . $k . "]=" . urlencode($v);
                    }
                } else {
                    echo "<input type='hidden' name='{$key}' value='{$val}' >";
                    if (!empty($param)) {
                        $param .= "&";
                    }
                    $param .= "{$key}=" . urlencode($val);
                }
            }
            Dropdown::showOutputFormat();
            Html::closeForm();
            echo "</td></tr>";
            echo "</table></div>";
            Html::printPager($start, $nbtot, $_SERVER['PHP_SELF'], $param);
        }
    }
}
if ($nbtot > 0) {
    $nbcols = $DB->num_fields($result);
    $nbrows = $DB->numrows($result);
    $num = 1;
    $link = $_SERVER['PHP_SELF'];
    $order = 'ASC';
    $issort = false;
    echo Search::showHeader($output_type, $nbrows, $nbcols, true);
    echo Search::showNewLine($output_type);
    showTitle($output_type, $num, __('Entity'), 'entity', true);
    showTitle($output_type, $num, __('Type'), 'type');
    showTitle($output_type, $num, __('Name'), 'name', true);
예제 #22
0
 /** Show LDAP groups to add or synchronise in an entity
  *
  * @param $target    target page for the form
  * @param $start     where to start the list
  * @param $sync      synchronise or add ? (default 0)
  * @param $filter    ldap filter to use (default '')
  * @param $filter2   second ldap filter to use (which case ?) (default '')
  * @param $entity    working entity
  * @param $order     display order (default DESC)
  *
  * @return  nothing
  **/
 static function showLdapGroups($target, $start, $sync = 0, $filter = '', $filter2 = '', $entity, $order = 'DESC')
 {
     echo "<br>";
     $limitexceeded = false;
     $ldap_groups = self::getAllGroups($_SESSION["ldap_server"], $filter, $filter2, $entity, $limitexceeded, $order);
     if (is_array($ldap_groups)) {
         $numrows = count($ldap_groups);
         $rand = mt_rand();
         $colspan = Session::isMultiEntitiesMode() ? 5 : 4;
         if ($numrows > 0) {
             self::displaySizeLimitWarning($limitexceeded);
             $parameters = '';
             Html::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'>";
             Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
             $massiveactionparams = array('num_displayed' => min($_SESSION['glpilist_limit'], count($ldap_groups)), 'container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array(__CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'import_group' => _sx('button', 'Import')), 'extraparams' => array('massive_action_fields' => array('dn', 'ldap_import_type', 'ldap_import_entities', 'ldap_import_recursive')));
             Html::showMassiveActions($massiveactionparams);
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr>";
             echo "<th width='10'>";
             Html::showCheckbox(array('criterion' => array('tag_for_massive' => 'select_item')));
             echo "</th>";
             $header_num = 0;
             echo Search::showHeaderItem(Search::HTML_OUTPUT, __('Group'), $header_num, $target . "?order=" . ($order == "DESC" ? "ASC" : "DESC"), 1, $order);
             echo "<th>" . __('Group DN') . "</th>";
             echo "<th>" . __('Destination entity') . "</th>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<th>" . __('Child entities') . "</th>";
             }
             echo "</tr>";
             $dn_index = 0;
             foreach ($ldap_groups as $groupinfos) {
                 $group = $groupinfos["cn"];
                 $group_dn = $groupinfos["dn"];
                 $search_type = $groupinfos["search_type"];
                 echo "<tr class='tab_bg_2 center'>";
                 echo "<td>";
                 echo Html::hidden("dn[{$dn_index}]", array('value' => $group_dn, 'data-glpicore-ma-tags' => 'common'));
                 echo Html::hidden("ldap_import_type[{$dn_index}]", array('value' => $search_type, 'data-glpicore-ma-tags' => 'common'));
                 Html::showMassiveActionCheckBox(__CLASS__, $dn_index, array('massive_tags' => 'select_item'));
                 echo "</td>";
                 echo "<td>" . $group . "</td>";
                 echo "<td>" . $group_dn . "</td>";
                 echo "<td>";
                 Entity::dropdown(array('value' => $entity, 'name' => "ldap_import_entities[{$dn_index}]", 'specific_tags' => array('data-glpicore-ma-tags' => 'common')));
                 echo "</td>";
                 if (Session::isMultiEntitiesMode()) {
                     echo "<td>";
                     Html::showCheckbox(array('name' => "ldap_import_recursive[{$dn_index}]", 'specific_tags' => array('data-glpicore-ma-tags' => 'common')));
                     echo "</td>";
                 } else {
                     echo Html::hidden("ldap_import_recursive[{$dn_index}]", array('value' => 0, 'data-glpicore-ma-tags' => 'common'));
                 }
                 echo "</tr>\n";
                 $dn_index++;
             }
             $massiveactionparams['ontop'] = false;
             Html::showMassiveActions($massiveactionparams);
             Html::closeForm();
             echo "</div>";
             Html::printPager($start, $numrows, $target, $parameters);
         } else {
             echo "<div class='center b'>" . __('No group to be imported') . "</div>";
         }
     } else {
         echo "<div class='center b'>" . __('No group to be imported') . "</div>";
     }
 }
예제 #23
-1
 /** Show LDAP groups to add or synchronise in an entity
  *
  * @param $target    target page for the form
  * @param $start     where to start the list
  * @param $sync      synchronise or add ? (default 0)
  * @param $filter    ldap filter to use (default '')
  * @param $filter2   second ldap filter to use (which case ?) (default '')
  * @param $entity    working entity
  * @param $order     display order (default DESC)
  *
  * @return  nothing
  **/
 static function showLdapGroups($target, $start, $sync = 0, $filter = '', $filter2 = '', $entity, $order = 'DESC')
 {
     echo "<br>";
     $limitexceeded = false;
     $ldap_groups = self::getAllGroups($_SESSION["ldap_server"], $filter, $filter2, $entity, $limitexceeded, $order);
     if (is_array($ldap_groups)) {
         $numrows = count($ldap_groups);
         $rand = mt_rand();
         $colspan = Session::isMultiEntitiesMode() ? 5 : 4;
         if ($numrows > 0) {
             self::displaySizeLimitWarning($limitexceeded);
             $parameters = '';
             Html::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'>";
             Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
             $paramsma = array('num_displayed' => min($_SESSION['glpilist_limit'], count($ldap_groups)), 'specific_actions' => array('import_group' => _sx('button', 'Import')));
             Html::showMassiveActions(__CLASS__, $paramsma);
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr>";
             echo "<th width='10'>";
             Html::checkAllAsCheckbox('mass' . __CLASS__ . $rand);
             echo "</th>";
             $header_num = 0;
             echo Search::showHeaderItem(Search::HTML_OUTPUT, __('Group'), $header_num, $target . "?order=" . ($order == "DESC" ? "ASC" : "DESC"), 1, $order);
             echo "<th>" . __('Group DN') . "</th>";
             echo "<th>" . __('Destination entity') . "</th>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<th>" . __('Child entities') . "</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=\"item[" . $group_dn . "]\"></td>";
                 echo "<td>" . $group . "</td>";
                 echo "<td>" . $group_dn . "</td>";
                 echo "<td>";
                 Entity::dropdown(array('value' => $entity, 'name' => "ldap_import_entities[" . $group_dn . "]=" . $entity));
                 echo "</td>";
                 if (Session::isMultiEntitiesMode()) {
                     echo "<td>";
                     Dropdown::showYesNo("ldap_import_recursive[" . $group_dn . "]", 0);
                 } else {
                     echo "<td><input type='hidden' name=\"ldap_import_recursive[" . $group_dn . "]\"\n                             value='0'>";
                 }
                 echo "<input type='hidden' name=\"ldap_import_type[" . $group_dn . "]\" value=\"" . $search_type . "\"></td></tr>";
             }
             $paramsma['ontop'] = false;
             Html::showMassiveActions(__CLASS__, $paramsma);
             Html::closeForm();
             echo "</div>";
             Html::printPager($start, $numrows, $target, $parameters);
         } else {
             echo "<div class='center b'>" . __('No group to be imported') . "</div>";
         }
     } else {
         echo "<div class='center b'>" . __('No group to be imported') . "</div>";
     }
 }
 function display($options = array())
 {
     global $DB, $CFG_GLPI;
     $pfAgent = new PluginFusioninventoryAgent();
     $pfTaskjobstate = new PluginFusioninventoryTaskjobstate();
     $pfTaskjoblog = new PluginFusioninventoryTaskjoblog();
     $pfStateInventory = new PluginFusioninventoryStateInventory();
     $pfTaskjob = new PluginFusioninventoryTaskjob();
     $start = 0;
     if (isset($_REQUEST["start"])) {
         $start = $_REQUEST["start"];
     }
     // Total Number of events
     $querycount = "SELECT count(*) AS cpt FROM `glpi_plugin_fusioninventory_taskjobstates`\n         LEFT JOIN `glpi_plugin_fusioninventory_taskjobs`\n            ON `plugin_fusioninventory_taskjobs_id` = `glpi_plugin_fusioninventory_taskjobs`.`id`\n         WHERE `method` = 'networkdiscovery'\n         GROUP BY `uniqid`\n         ORDER BY `uniqid` DESC ";
     $resultcount = $DB->query($querycount);
     $number = $DB->numrows($resultcount);
     // Display the pager
     Html::printPager($start, $number, $CFG_GLPI['root_doc'] . "/plugins/fusioninventory/front/stateinventory.php", '');
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . __('Unique id', 'fusioninventory') . "</th>";
     echo "<th>" . __('Task job', 'fusioninventory') . "</th>";
     echo "<th>" . __('Agent', 'fusioninventory') . "</th>";
     echo "<th>" . __('Status') . "</th>";
     echo "<th>" . __('Starting date', 'fusioninventory') . "</th>";
     echo "<th>" . __('Ending date', 'fusioninventory') . "</th>";
     echo "<th>" . __('Total duration') . "</th>";
     echo "<th>" . __('Threads number', 'fusioninventory') . "</th>";
     echo "<th>" . __('Total discovery devices', 'fusioninventory') . "</th>";
     echo "<th>" . __('Devices not imported', 'fusioninventory') . "</th>";
     echo "<th>" . __('Devices linked', 'fusioninventory') . "</th>";
     echo "<th>" . __('Devices imported', 'fusioninventory') . "</th>";
     echo "</tr>";
     $sql = "SELECT `glpi_plugin_fusioninventory_taskjobstates`.*\n            FROM `glpi_plugin_fusioninventory_taskjobstates`\n         LEFT JOIN `glpi_plugin_fusioninventory_taskjobs`\n            ON `plugin_fusioninventory_taskjobs_id` = `glpi_plugin_fusioninventory_taskjobs`.`id`\n         WHERE `method` = 'networkdiscovery'\n         GROUP BY `uniqid`\n         ORDER BY `uniqid` DESC\n         LIMIT " . intval($start) . ", " . intval($_SESSION['glpilist_limit']);
     $result = $DB->query($sql);
     while ($data = $DB->fetch_array($result)) {
         echo "<tr class='tab_bg_1'>";
         echo "<td>" . $data['uniqid'] . "</td>";
         $pfTaskjob->getFromDB($data['plugin_fusioninventory_taskjobs_id']);
         echo "<td>" . $pfTaskjob->getLink() . "</td>";
         $pfAgent->getFromDB($data['plugin_fusioninventory_agents_id']);
         echo "<td>" . $pfAgent->getLink(1) . "</td>";
         $nb_found = 0;
         $nb_threads = 0;
         $start_date = "";
         $end_date = "";
         $notimporteddevices = 0;
         $updateddevices = 0;
         $createddevices = 0;
         $a_taskjobstates = $pfTaskjobstate->find("`uniqid`='" . $data['uniqid'] . "'");
         foreach ($a_taskjobstates as $datastate) {
             $a_taskjoblog = $pfTaskjoblog->find("`plugin_fusioninventory_taskjobstates_id`='" . $datastate['id'] . "'");
             foreach ($a_taskjoblog as $taskjoblog) {
                 if (strstr($taskjoblog['comment'], " ==devicesfound==")) {
                     $nb_found += str_replace(" ==devicesfound==", "", $taskjoblog['comment']);
                 } else {
                     if (strstr($taskjoblog['comment'], "==importdenied==")) {
                         $notimporteddevices++;
                     } else {
                         if (strstr($taskjoblog['comment'], "==updatetheitem==")) {
                             $updateddevices++;
                         } else {
                             if (strstr($taskjoblog['comment'], "==addtheitem==")) {
                                 $createddevices++;
                             } else {
                                 if ($taskjoblog['state'] == "1") {
                                     $nb_threads = str_replace(" threads", "", $taskjoblog['comment']);
                                     $start_date = $taskjoblog['date'];
                                 }
                             }
                         }
                     }
                 }
                 if ($taskjoblog['state'] == "2" or $taskjoblog['state'] == "3" or $taskjoblog['state'] == "4" or $taskjoblog['state'] == "5") {
                     if (!strstr($taskjoblog['comment'], 'Merged with ')) {
                         $end_date = $taskjoblog['date'];
                     }
                 }
             }
         }
         // State
         echo "<td>";
         switch ($data['state']) {
             case 0:
                 echo __('Prepared', 'fusioninventory');
                 break;
             case 1:
             case 2:
                 echo __('Started', 'fusioninventory');
                 break;
             case 3:
                 echo __('Finished tasks', 'fusioninventory');
                 break;
         }
         echo "</td>";
         echo "<td>" . Html::convDateTime($start_date) . "</td>";
         echo "<td>" . Html::convDateTime($end_date) . "</td>";
         if ($end_date == '') {
             $end_date = date("Y-m-d H:i:s");
         }
         if ($start_date == '') {
             echo "<td>-</td>";
         } else {
             $interval = '';
             if (phpversion() >= 5.3) {
                 $date1 = new DateTime($start_date);
                 $date2 = new DateTime($end_date);
                 $interval = $date1->diff($date2);
                 $display_date = '';
                 if ($interval->h > 0) {
                     $display_date .= $interval->h . "h ";
                 } else {
                     if ($interval->i > 0) {
                         $display_date .= $interval->i . "min ";
                     }
                 }
                 echo "<td>" . $display_date . $interval->s . "s</td>";
             } else {
                 $interval = $pfStateInventory->date_diff($start_date, $end_date);
             }
         }
         echo "<td>" . $nb_threads . "</td>";
         echo "<td>" . $nb_found . "</td>";
         echo "<td>" . $notimporteddevices . "</td>";
         echo "<td>" . $updateddevices . "</td>";
         echo "<td>" . $createddevices . "</td>";
         echo "</tr>";
     }
     echo "</table>";
 }