/** * 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(); } }