/**
* 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'])), '&');
$parameters = "sort=" . $data['search']['sort'] . "&order=" . $data['search']['order'] . '&' . $globallinkto;
if (isset($_GET['_in_modal'])) {
$parameters .= "&_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, '&');
}
}
}
$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'], '?') ? '&' : '?') . "itemtype=" . $data['itemtype'] . "&sort=" . $val['id'] . "&order=" . ($data['search']['order'] == "ASC" ? "DESC" : "ASC") . "&start=" . $data['search']['start'] . "&" . $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 = " ";
} else {
if ($data['item'] instanceof CommonDBTM && $data['item']->maybeRecursive() && !in_array($row["entities_id"], $_SESSION["glpiactiveentities"])) {
$tmpcheck = " ";
} 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']);
}
}