$date = new PluginReportsDateIntervalCriteria($report, 'buy_date');
$type = new PluginReportsItemTypeCriteria($report, 'itemtype', '', 'infocom_types');
$budg = new PluginReportsDropdownCriteria($report, 'budgets_id', 'glpi_budgets', __('Budget'));
//Display criterias form is needed
$report->displayCriteriasForm();
$display_type = Search::HTML_OUTPUT;
//If criterias have been validated
if ($report->criteriasValidated()) {
    $report->setSubNameAuto();
    $title = $report->getFullTitle();
    $itemtype = $type->getParameterValue();
    if ($itemtype && $itemtype != "all") {
        $types = array($itemtype);
    } else {
        $types = array();
        $sql = "SELECT DISTINCT `itemtype`\n                FROM `glpi_infocoms` " . getEntitiesRestrictRequest('WHERE', 'glpi_infocoms') . $date->getSqlCriteriasRestriction('AND') . $budg->getSqlCriteriasRestriction('AND');
        foreach ($DB->request($sql) as $data) {
            $types[] = $data['itemtype'];
        }
    }
    $result = array();
    foreach ($types as $type) {
        if (!class_exists($type)) {
            continue;
        }
        $item = new $type();
        $table = $item->getTable();
        $sql = "SELECT COUNT(*) AS cpt\n              FROM `{$table}`\n              INNER JOIN `glpi_infocoms` ON (`glpi_infocoms`.`itemtype`='{$type}'\n                                             AND `glpi_infocoms`.`items_id`=`{$table}`.`id`)" . getEntitiesRestrictRequest('WHERE', $table);
        if ($item->maybeDeleted()) {
            $sql .= " AND NOT `{$table}`.`is_deleted` ";
        }
示例#2
0
        }
        if ($item->isField('locations_id')) {
            $select .= ", `glpi_locations`.`completename` AS location\n                     , `glpi_locations`.`building`\n                     , `glpi_locations`.`room`";
            $from .= "LEFT JOIN `glpi_locations`\n                         ON (`glpi_locations`.`id` = `{$table}`.`locations_id`)";
        } else {
            $select .= ", '' AS location, '' AS building, '' AS room";
        }
        $select .= ", `glpi_infocoms`.*\n                  , `glpi_infocoms`.`suppliers_id` AS supplier\n                  , `glpi_budgets`.`name` AS budget";
        $from .= "LEFT JOIN `glpi_infocoms`\n                      ON (`glpi_infocoms`.`itemtype` = '{$itemtype}'\n                          AND `glpi_infocoms`.`items_id` = `{$table}`.`id`)\n                  LEFT JOIN `glpi_budgets`\n                      ON (`glpi_budgets`.`id` = `glpi_infocoms`.`budgets_id`)";
        if ($item->maybeDeleted()) {
            $where .= " AND `{$table}`.`is_deleted` = 0 ";
        }
        if ($item->maybeTemplate()) {
            $where .= " AND `{$table}`.`is_template` = 0 ";
        }
        if ($item->isEntityAssign()) {
            $where .= getEntitiesRestrictRequest(" AND ", $table);
        }
        $where .= $budg->getSqlCriteriasRestriction();
        $where .= $date->getSqlCriteriasRestriction();
        if ($sql) {
            $sql .= " UNION ";
        }
        $sql .= "({$select} {$from} {$where})";
    }
    $report->setGroupBy('entity');
    $report->setSqlRequest($sql);
    $report->execute();
} else {
    Html::footer();
}
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;
//}
//Report title
$title = $report->getFullTitle();
// SQL statement
$query = "SELECT glpi_tickets.*  \n               FROM `glpi_tickets`\n               WHERE `glpi_tickets`.`status` = '" . Ticket::CLOSED . "'";
$query .= getEntitiesRestrictRequest('AND', "glpi_tickets", '', '', false);
$query .= $date->getSqlCriteriasRestriction();
$query .= getOrderBy('closedate', $columns);
$res = $DB->query($query);
$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($query . " LIMIT {$start},{$limit}");
    }
} else {
    $start = 0;
}
if ($nbtot == 0) {