Search::giveItem PHP Method

giveItem() static public method

Generic Function to display Items
static public giveItem ( $itemtype, $ID, array $data, $num, $meta, array $addobjectparams = [] ) : string
$itemtype item type
$ID ID of the SEARCH_OPTION item
$data array array containing data results
$num item num in the request
$meta is a meta item ? (default 0)
$addobjectparams array array added parameters for union search
return string to print
    static function giveItem($itemtype, $ID, array $data, $num, $meta = 0, array $addobjectparams = array())
    {
        global $CFG_GLPI, $DB;
        $searchopt =& self::getOptions($itemtype);
        if (isset($CFG_GLPI["union_search_type"][$itemtype]) && $CFG_GLPI["union_search_type"][$itemtype] == $searchopt[$ID]["table"]) {
            if (isset($searchopt[$ID]['addobjectparams']) && $searchopt[$ID]['addobjectparams']) {
                return self::giveItem($data["TYPE"], $ID, $data, $num, $meta, $searchopt[$ID]['addobjectparams']);
            }
            return self::giveItem($data["TYPE"], $ID, $data, $num, $meta);
        }
        if (count($addobjectparams)) {
            $searchopt[$ID] = array_merge($searchopt[$ID], $addobjectparams);
        }
        // Plugin can override core definition for its type
        if ($plug = isPluginItemType($itemtype)) {
            $function = 'plugin_' . $plug['plugin'] . '_giveItem';
            if (function_exists($function)) {
                $out = $function($itemtype, $ID, $data, $num);
                if (!empty($out)) {
                    return $out;
                }
            }
        }
        $NAME = "ITEM_";
        // if ($meta) {
        //    $NAME = "META_";
        // }
        if (isset($searchopt[$ID]["table"])) {
            $table = $searchopt[$ID]["table"];
            $field = $searchopt[$ID]["field"];
            $linkfield = $searchopt[$ID]["linkfield"];
            /// TODO try to clean all specific cases using SpecificToDisplay
            switch ($table . '.' . $field) {
                case "glpi_users.name":
                    // USER search case
                    if ($itemtype != 'User' && isset($searchopt[$ID]["forcegroupby"]) && $searchopt[$ID]["forcegroupby"]) {
                        $out = "";
                        $count_display = 0;
                        $added = array();
                        $showuserlink = 0;
                        if (Session::haveRight('user', READ)) {
                            $showuserlink = 1;
                        }
                        for ($k = 0; $k < $data[$num]['count']; $k++) {
                            if (isset($data[$num][$k]['name']) && $data[$num][$k]['name'] > 0 || isset($data[$num][$k][2]) && $data[$num][$k][2] != '') {
                                if ($count_display) {
                                    $out .= self::LBBR;
                                }
                                if ($itemtype == 'Ticket') {
                                    if (isset($data[$num][$k]['name']) && $data[$num][$k]['name'] > 0) {
                                        $userdata = getUserName($data[$num][$k]['name'], 2);
                                        $tooltip = "";
                                        if (Session::haveRight('user', READ)) {
                                            $tooltip = Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false));
                                        }
                                        $out .= sprintf(__('%1$s %2$s'), $userdata['name'], $tooltip);
                                        $count_display++;
                                    }
                                } else {
                                    $out .= getUserName($data[$num][$k]['name'], $showuserlink);
                                    $count_display++;
                                }
                                // Manage alternative_email for tickets_users
                                if ($itemtype == 'Ticket' && isset($data[$num][$k][2])) {
                                    $split = explode(self::LONGSEP, $data[$num][$k][2]);
                                    for ($l = 0; $l < count($split); $l++) {
                                        $split2 = explode(" ", $split[$l]);
                                        if (count($split2) == 2 && $split2[0] == 0 && !empty($split2[1])) {
                                            if ($count_display) {
                                                $out .= self::LBBR;
                                            }
                                            $count_display++;
                                            $out .= "<a href='mailto:" . $split2[1] . "'>" . $split2[1] . "</a>";
                                        }
                                    }
                                }
                            }
                        }
                        return $out;
                    }
                    if ($itemtype != 'User') {
                        $toadd = '';
                        if ($itemtype == 'Ticket' && $data[$num][0]['id'] > 0) {
                            $userdata = getUserName($data[$num][0]['id'], 2);
                            $toadd = Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false));
                        }
                        $usernameformat = formatUserName($data[$num][0]['id'], $data[$num][0]['name'], $data[$num][0]['realname'], $data[$num][0]['firstname'], 1);
                        return sprintf(__('%1$s %2$s'), $usernameformat, $toadd);
                    }
                    break;
                case "glpi_profiles.name":
                    if ($itemtype == 'User' && $ID == 20) {
                        $out = "";
                        $count_display = 0;
                        $added = array();
                        for ($k = 0; $k < $data[$num]['count']; $k++) {
                            if (strlen(trim($data[$num][$k]['name'])) > 0 && !in_array($data[$num][$k]['name'] . "-" . $data[$num][$k]['entities_id'], $added)) {
                                $text = sprintf(__('%1$s - %2$s'), $data[$num][$k]['name'], Dropdown::getDropdownName('glpi_entities', $data[$num][$k]['entities_id']));
                                $comp = '';
                                if ($data[$num][$k]['is_recursive']) {
                                    $comp = __('R');
                                    if ($data[$num][$k]['is_dynamic']) {
                                        $comp = sprintf(__('%1$s%2$s'), $comp, ", ");
                                    }
                                }
                                if ($data[$num][$k]['is_dynamic']) {
                                    $comp = sprintf(__('%1$s%2$s'), $comp, __('D'));
                                }
                                if (!empty($comp)) {
                                    $text = sprintf(__('%1$s %2$s'), $text, "(" . $comp . ")");
                                }
                                if ($count_display) {
                                    $out .= self::LBBR;
                                }
                                $count_display++;
                                $out .= $text;
                                $added[] = $data[$num][$k]['name'] . "-" . $data[$num][$k]['entities_id'];
                            }
                        }
                        return $out;
                    }
                    break;
                case "glpi_entities.completename":
                    if ($itemtype == 'User') {
                        $out = "";
                        $added = array();
                        $count_display = 0;
                        for ($k = 0; $k < $data[$num]['count']; $k++) {
                            if (isset($data[$num][$k]['name']) && strlen(trim($data[$num][$k]['name'])) > 0 && !in_array($data[$num][$k]['name'] . "-" . $data[$num][$k]['profiles_id'], $added)) {
                                $text = sprintf(__('%1$s - %2$s'), $data[$num][$k]['name'], Dropdown::getDropdownName('glpi_profiles', $data[$num][$k]['profiles_id']));
                                $comp = '';
                                if ($data[$num][$k]['is_recursive']) {
                                    $comp = __('R');
                                    if ($data[$num][$k]['is_dynamic']) {
                                        $comp = sprintf(__('%1$s%2$s'), $comp, ", ");
                                    }
                                }
                                if ($data[$num][$k]['is_dynamic']) {
                                    $comp = sprintf(__('%1$s%2$s'), $comp, __('D'));
                                }
                                if (!empty($comp)) {
                                    $text = sprintf(__('%1$s %2$s'), $text, "(" . $comp . ")");
                                }
                                if ($count_display) {
                                    $out .= self::LBBR;
                                }
                                $count_display++;
                                $out .= $text;
                                $added[] = $data[$num][$k]['name'] . "-" . $data[$num][$k]['profiles_id'];
                            }
                        }
                        return $out;
                    }
                    break;
                case "glpi_documenttypes.icon":
                    if (!empty($data[$num][0]['name'])) {
                        return "<img class='middle' alt='' src='" . $CFG_GLPI["typedoc_icon_dir"] . "/" . $data[$num][0]['name'] . "'>";
                    }
                    return "&nbsp;";
                case "glpi_documents.filename":
                    $doc = new Document();
                    if ($doc->getFromDB($data['id'])) {
                        return $doc->getDownloadLink();
                    }
                    return NOT_AVAILABLE;
                case "glpi_tickets_tickets.tickets_id_1":
                    $out = "";
                    $displayed = array();
                    for ($k = 0; $k < $data[$num]['count']; $k++) {
                        $linkid = $data[$num][$k]['tickets_id_2'] == $data['id'] ? $data[$num][$k]['name'] : $data[$num][$k]['tickets_id_2'];
                        if ($linkid > 0 && !isset($displayed[$linkid])) {
                            $text = "<a ";
                            $text .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id={$linkid}\">";
                            $text .= Dropdown::getDropdownName('glpi_tickets', $linkid) . "</a>";
                            if (count($displayed)) {
                                $out .= self::LBBR;
                            }
                            $displayed[$linkid] = $linkid;
                            $out .= $text;
                        }
                    }
                    return $out;
                case "glpi_problems.id":
                    if ($searchopt[$ID]["datatype"] == 'count') {
                        if ($data[$num][0]['name'] > 0 && Session::haveRight("problem", Problem::READALL)) {
                            if ($itemtype == 'ITILCategory') {
                                $options['criteria'][0]['field'] = 7;
                                $options['criteria'][0]['searchtype'] = 'equals';
                                $options['criteria'][0]['value'] = $data['id'];
                                $options['criteria'][0]['link'] = 'AND';
                            } else {
                                $options['criteria'][0]['field'] = 12;
                                $options['criteria'][0]['searchtype'] = 'equals';
                                $options['criteria'][0]['value'] = 'all';
                                $options['criteria'][0]['link'] = 'AND';
                                $options['metacriteria'][0]['itemtype'] = $itemtype;
                                $options['metacriteria'][0]['field'] = self::getOptionNumber($itemtype, 'name');
                                $options['metacriteria'][0]['searchtype'] = 'equals';
                                $options['metacriteria'][0]['value'] = $data['id'];
                                $options['metacriteria'][0]['link'] = 'AND';
                            }
                            $options['reset'] = 'reset';
                            $out = "<a id='problem{$itemtype}" . $data['id'] . "' ";
                            $out .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/problem.php?" . Toolbox::append_params($options, '&amp;') . "\">";
                            $out .= $data[$num][0]['name'] . "</a>";
                            return $out;
                        }
                    }
                    break;
                case "glpi_tickets.id":
                    if ($searchopt[$ID]["datatype"] == 'count') {
                        if ($data[$num][0]['name'] > 0 && Session::haveRight("ticket", Ticket::READALL)) {
                            if ($itemtype == 'User') {
                                // Requester
                                if ($ID == 60) {
                                    $options['criteria'][0]['field'] = 4;
                                    $options['criteria'][0]['searchtype'] = 'equals';
                                    $options['criteria'][0]['value'] = $data['id'];
                                    $options['criteria'][0]['link'] = 'AND';
                                }
                                // Writer
                                if ($ID == 61) {
                                    $options['criteria'][0]['field'] = 22;
                                    $options['criteria'][0]['searchtype'] = 'equals';
                                    $options['criteria'][0]['value'] = $data['id'];
                                    $options['criteria'][0]['link'] = 'AND';
                                }
                                // Assign
                                if ($ID == 64) {
                                    $options['criteria'][0]['field'] = 5;
                                    $options['criteria'][0]['searchtype'] = 'equals';
                                    $options['criteria'][0]['value'] = $data['id'];
                                    $options['criteria'][0]['link'] = 'AND';
                                }
                            } else {
                                if ($itemtype == 'ITILCategory') {
                                    $options['criteria'][0]['field'] = 7;
                                    $options['criteria'][0]['searchtype'] = 'equals';
                                    $options['criteria'][0]['value'] = $data['id'];
                                    $options['criteria'][0]['link'] = 'AND';
                                } else {
                                    $options['criteria'][0]['field'] = 12;
                                    $options['criteria'][0]['searchtype'] = 'equals';
                                    $options['criteria'][0]['value'] = 'all';
                                    $options['criteria'][0]['link'] = 'AND';
                                    $options['metacriteria'][0]['itemtype'] = $itemtype;
                                    $options['metacriteria'][0]['field'] = self::getOptionNumber($itemtype, 'name');
                                    $options['metacriteria'][0]['searchtype'] = 'equals';
                                    $options['metacriteria'][0]['value'] = $data['id'];
                                    $options['metacriteria'][0]['link'] = 'AND';
                                }
                            }
                            $options['reset'] = 'reset';
                            $out = "<a id='ticket{$itemtype}" . $data['id'] . "' ";
                            $out .= "href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($options, '&amp;') . "\">";
                            $out .= $data[$num][0]['name'] . "</a>";
                            return $out;
                        }
                    }
                    break;
                case "glpi_tickets.due_date":
                case "glpi_problems.due_date":
                case "glpi_changes.due_date":
                case "glpi_tickets.time_to_own":
                    // Due date + progress
                    if ($ID == 151 || $ID == 158) {
                        $out = Html::convDateTime($data[$num][0]['name']);
                        // No due date in waiting status
                        if ($data[$num][0]['status'] == CommonITILObject::WAITING) {
                            return '';
                        }
                        if (empty($data[$num][0]['name'])) {
                            return '';
                        }
                        if ($data[$num][0]['status'] == Ticket::SOLVED || $data[$num][0]['status'] == Ticket::CLOSED) {
                            return $out;
                        }
                        $itemtype = getItemTypeForTable($table);
                        $item = new $itemtype();
                        $item->getFromDB($data['id']);
                        $percentage = 0;
                        $totaltime = 0;
                        $currenttime = 0;
                        $sltField = 'slts_id';
                        switch ($table . '.' . $field) {
                            // If ticket has been taken into account : no progression display
                            case "glpi_tickets.time_to_own":
                                if ($item->fields['takeintoaccount_delay_stat'] > 0) {
                                    return $out;
                                }
                                break;
                        }
                        if ($item->isField($sltField) && $item->fields[$sltField] != 0) {
                            // Have SLT
                            $slt = new SLT();
                            $slt->getFromDB($item->fields[$sltField]);
                            $currenttime = $slt->getActiveTimeBetween($item->fields['date'], date('Y-m-d H:i:s'));
                            $totaltime = $slt->getActiveTimeBetween($item->fields['date'], $data[$num][0]['name']);
                        } else {
                            $calendars_id = Entity::getUsedConfig('calendars_id', $item->fields['entities_id']);
                            if ($calendars_id != 0) {
                                // Ticket entity have calendar
                                $calendar = new Calendar();
                                $calendar->getFromDB($calendars_id);
                                $currenttime = $calendar->getActiveTimeBetween($item->fields['date'], date('Y-m-d H:i:s'));
                                $totaltime = $calendar->getActiveTimeBetween($item->fields['date'], $data[$num][0]['name']);
                            } else {
                                // No calendar
                                $currenttime = strtotime(date('Y-m-d H:i:s')) - strtotime($item->fields['date']);
                                $totaltime = strtotime($data[$num][0]['name']) - strtotime($item->fields['date']);
                            }
                        }
                        if ($totaltime != 0) {
                            $percentage = round(100 * $currenttime / $totaltime);
                        } else {
                            // Total time is null : no active time
                            $percentage = 100;
                        }
                        if ($percentage > 100) {
                            $percentage = 100;
                        }
                        $percentage_text = $percentage;
                        if ($_SESSION['glpiduedatewarning_unit'] == '%') {
                            $less_warn_limit = $_SESSION['glpiduedatewarning_less'];
                            $less_warn = 100 - $percentage;
                        } else {
                            if ($_SESSION['glpiduedatewarning_unit'] == 'hour') {
                                $less_warn_limit = $_SESSION['glpiduedatewarning_less'] * HOUR_TIMESTAMP;
                                $less_warn = $totaltime - $currenttime;
                            } else {
                                if ($_SESSION['glpiduedatewarning_unit'] == 'day') {
                                    $less_warn_limit = $_SESSION['glpiduedatewarning_less'] * DAY_TIMESTAMP;
                                    $less_warn = $totaltime - $currenttime;
                                }
                            }
                        }
                        if ($_SESSION['glpiduedatecritical_unit'] == '%') {
                            $less_crit_limit = $_SESSION['glpiduedatecritical_less'];
                            $less_crit = 100 - $percentage;
                        } else {
                            if ($_SESSION['glpiduedatecritical_unit'] == 'hour') {
                                $less_crit_limit = $_SESSION['glpiduedatecritical_less'] * HOUR_TIMESTAMP;
                                $less_crit = $totaltime - $currenttime;
                            } else {
                                if ($_SESSION['glpiduedatecritical_unit'] == 'day') {
                                    $less_crit_limit = $_SESSION['glpiduedatecritical_less'] * DAY_TIMESTAMP;
                                    $less_crit = $totaltime - $currenttime;
                                }
                            }
                        }
                        $color = $_SESSION['glpiduedateok_color'];
                        if ($less_crit < $less_crit_limit) {
                            $color = $_SESSION['glpiduedatecritical_color'];
                        } else {
                            if ($less_warn < $less_warn_limit) {
                                $color = $_SESSION['glpiduedatewarning_color'];
                            }
                        }
                        //Calculate bar progress
                        $out .= "<div class='center' style='background-color: #ffffff; width: 100%;\n                            border: 1px solid #9BA563; position: relative;' >";
                        $out .= "<div style='position:absolute;'>&nbsp;" . $percentage_text . "%</div>";
                        $out .= "<div class='center' style='background-color: " . $color . ";\n                            width: " . $percentage . "%; height: 12px' ></div>";
                        $out .= "</div>";
                        return $out;
                    }
                    break;
                case "glpi_softwarelicenses.number":
                    if ($data[$num][0]['min'] == -1) {
                        return __('Unlimited');
                    }
                    if (empty($data[$num][0]['name'])) {
                        return 0;
                    }
                    return $data[$num][0]['name'];
                case "glpi_auth_tables.name":
                    return Auth::getMethodName($data[$num][0]['name'], $data[$num][0]['auths_id'], 1, $data[$num][0]['ldapname'] . $data[$num][0]['mailname']);
                case "glpi_reservationitems.comment":
                    if (empty($data[$num][0]['name'])) {
                        return "<a title=\"" . __s('Modify the comment') . "\"\n                           href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data["refID"] . "' >" . __('None') . "</a>";
                    }
                    return "<a title=\"" . __s('Modify the comment') . "\"\n                        href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data['refID'] . "' >" . Html::resume_text($data[$num][0]['name']) . "</a>";
                case 'glpi_crontasks.description':
                    $tmp = new CronTask();
                    return $tmp->getDescription($data[$num][0]['name']);
                case 'glpi_changes.status':
                    $status = Change::getStatus($data[$num][0]['name']);
                    return "<img src=\"" . Change::getStatusIconURL($data[$num][0]['name']) . "\"\n                        alt=\"{$status}\" title=\"{$status}\">&nbsp;{$status}";
                case 'glpi_problems.status':
                    $status = Problem::getStatus($data[$num][0]['name']);
                    return "<img src=\"" . Problem::getStatusIconURL($data[$num][0]['name']) . "\"\n                        alt=\"{$status}\" title=\"{$status}\">&nbsp;{$status}";
                case 'glpi_tickets.status':
                    $status = Ticket::getStatus($data[$num][0]['name']);
                    return "<img src=\"" . Ticket::getStatusIconURL($data[$num][0]['name']) . "\"\n                        alt=\"{$status}\" title=\"{$status}\">&nbsp;{$status}";
                case 'glpi_projectstates.name':
                    $out = '';
                    $query = "SELECT `color`\n                         FROM `glpi_projectstates`\n                         WHERE `name` = '" . $data[$num][0]['name'] . "'";
                    foreach ($DB->request($query) as $color) {
                        $color = $color['color'];
                        $out = "<div style=\"background-color:" . $color . ";\">";
                        $name = $data[$num][0]['name'];
                        if (isset($data[$num][0]['trans'])) {
                            $name = $data[$num][0]['trans'];
                        }
                        if ($itemtype == 'ProjectState') {
                            $out .= "<a href='" . $CFG_GLPI["root_doc"] . "/front/projectstate.form.php?id=" . $data[$num][0]["id"] . "'>" . $name . "</a></div>";
                        } else {
                            $out .= $name . "</div>";
                        }
                    }
                    return $out;
                case 'glpi_items_tickets.items_id':
                case 'glpi_items_problems.items_id':
                    if (!empty($data[$num])) {
                        $items = array();
                        foreach ($data[$num] as $key => $val) {
                            if (is_numeric($key)) {
                                if (!empty($val['itemtype']) && ($item = getItemForItemtype($val['itemtype']))) {
                                    if ($item->getFromDB($val['name'])) {
                                        $items[] = $item->getLink(array('comments' => true));
                                    }
                                }
                            }
                        }
                        if (!empty($items)) {
                            return implode("<br>", $items);
                        }
                    }
                    return '&nbsp;';
                case 'glpi_items_tickets.itemtype':
                case 'glpi_items_problems.itemtype':
                    if (!empty($data[$num])) {
                        $itemtypes = array();
                        foreach ($data[$num] as $key => $val) {
                            if (is_numeric($key)) {
                                if (!empty($val['name'])) {
                                    if (substr($val['name'], 0, 6) == 'Plugin') {
                                        $plug = new $val['name']();
                                        $name = $plug->getTypeName();
                                        $itemtypes[] = __($name);
                                    } else {
                                        $itemtypes[] = __($val['name']);
                                    }
                                }
                            }
                        }
                        if (!empty($itemtypes)) {
                            return implode("<br>", $itemtypes);
                        }
                    }
                    return '&nbsp;';
                case 'glpi_tickets.name':
                case 'glpi_problems.name':
                case 'glpi_changes.name':
                    if (isset($data[$num][0]['content']) && isset($data[$num][0]['id']) && isset($data[$num][0]['status'])) {
                        $link = Toolbox::getItemTypeFormURL($itemtype);
                        $out = "<a id='{$itemtype}" . $data[$num][0]['id'] . "' href=\"" . $link;
                        $out .= strstr($link, '?') ? '&amp;' : '?';
                        $out .= 'id=' . $data[$num][0]['id'];
                        // Force solution tab if solved
                        if ($item = getItemForItemtype($itemtype)) {
                            if (in_array($data[$num][0]['status'], $item->getSolvedStatusArray())) {
                                $out .= "&amp;forcetab={$itemtype}\$2";
                            }
                        }
                        $out .= "\">";
                        $name = $data[$num][0]['name'];
                        if ($_SESSION["glpiis_ids_visible"] || empty($data[$num][0]['name'])) {
                            $name = sprintf(__('%1$s (%2$s)'), $name, $data[$num][0]['id']);
                        }
                        $out .= $name . "</a>";
                        $hdecode = Html::entity_decode_deep($data[$num][0]['content']);
                        $content = Toolbox::unclean_cross_side_scripting_deep($hdecode);
                        $out = sprintf(__('%1$s %2$s'), $out, Html::showToolTip(nl2br(Html::Clean($content)), array('applyto' => $itemtype . $data[$num][0]['id'], 'display' => false)));
                        return $out;
                    }
                case 'glpi_ticketvalidations.status':
                    $out = '';
                    for ($k = 0; $k < $data[$num]['count']; $k++) {
                        if ($data[$num][$k]['name']) {
                            $status = TicketValidation::getStatus($data[$num][$k]['name']);
                            $bgcolor = TicketValidation::getStatusColor($data[$num][$k]['name']);
                            $out .= (empty($out) ? '' : self::LBBR) . "<div style=\"background-color:" . $bgcolor . ";\">" . $status . '</div>';
                        }
                    }
                    return $out;
                case 'glpi_ticketsatisfactions.satisfaction':
                    if (self::$output_type == self::HTML_OUTPUT) {
                        return TicketSatisfaction::displaySatisfaction($data[$num][0]['name']);
                    }
                    break;
                case 'glpi_projects._virtual_planned_duration':
                    return Html::timestampToString(ProjectTask::getTotalPlannedDurationForProject($data["id"]), false);
                case 'glpi_projects._virtual_effective_duration':
                    return Html::timestampToString(ProjectTask::getTotalEffectiveDurationForProject($data["id"]), false);
                case 'glpi_cartridgeitems._virtual':
                    return Cartridge::getCount($data["id"], $data[$num][0]['alarm_threshold'], self::$output_type != self::HTML_OUTPUT);
                case 'glpi_printers._virtual':
                    return Cartridge::getCountForPrinter($data["id"], self::$output_type != self::HTML_OUTPUT);
                case 'glpi_consumableitems._virtual':
                    return Consumable::getCount($data["id"], $data[$num][0]['alarm_threshold'], self::$output_type != self::HTML_OUTPUT);
                case 'glpi_links._virtual':
                    $out = '';
                    $link = new Link();
                    if (($item = getItemForItemtype($itemtype)) && $item->getFromDB($data['id']) && $link->getfromDB($data[$num][0]['id']) && $item->fields['entities_id'] == $link->fields['entities_id']) {
                        if (count($data[$num])) {
                            $count_display = 0;
                            foreach ($data[$num] as $val) {
                                if (is_array($val)) {
                                    $links = Link::getAllLinksFor($item, $val);
                                    foreach ($links as $link) {
                                        if ($count_display) {
                                            $out .= self::LBBR;
                                        }
                                        $out .= $link;
                                        $count_display++;
                                    }
                                }
                            }
                        }
                    }
                    return $out;
                case 'glpi_reservationitems._virtual':
                    if ($data[$num][0]['is_active']) {
                        return "<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>";
                    } else {
                        return "&nbsp;";
                    }
            }
        }
        //// Default case
        // Link with plugin tables : need to know left join structure
        if (isset($table)) {
            if (preg_match("/^glpi_plugin_([a-z0-9]+)/", $table . '.' . $field, $matches)) {
                if (count($matches) == 2) {
                    $plug = $matches[1];
                    $function = 'plugin_' . $plug . '_giveItem';
                    if (function_exists($function)) {
                        $out = $function($itemtype, $ID, $data, $num);
                        if (!empty($out)) {
                            return $out;
                        }
                    }
                }
            }
        }
        $unit = '';
        if (isset($searchopt[$ID]['unit'])) {
            $unit = $searchopt[$ID]['unit'];
        }
        // Preformat items
        if (isset($searchopt[$ID]["datatype"])) {
            switch ($searchopt[$ID]["datatype"]) {
                case "itemlink":
                    $linkitemtype = getItemTypeForTable($searchopt[$ID]["table"]);
                    $out = "";
                    $count_display = 0;
                    $separate = self::LBBR;
                    if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) {
                        $separate = self::LBHR;
                    }
                    for ($k = 0; $k < $data[$num]['count']; $k++) {
                        if (isset($data[$num][$k]['id'])) {
                            if ($count_display) {
                                $out .= $separate;
                            }
                            $count_display++;
                            $page = $linkitemtype::getFormUrl();
                            $page .= strpos($page, '?') ? '&id' : '?id';
                            $name = Dropdown::getValueWithUnit($data[$num][$k]['name'], $unit);
                            if ($_SESSION["glpiis_ids_visible"] || empty($data[$num][$k]['name'])) {
                                $name = sprintf(__('%1$s (%2$s)'), $name, $data[$num][$k]['id']);
                            }
                            $out .= "<a id='" . $linkitemtype . "_" . $data['id'] . "_" . $data[$num][$k]['id'] . "' href='{$page}=" . $data[$num][$k]['id'] . "'>" . $name . "</a>";
                        }
                    }
                    return $out;
                case "text":
                    $separate = self::LBBR;
                    if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) {
                        $separate = self::LBHR;
                    }
                    $out = '';
                    $count_display = 0;
                    for ($k = 0; $k < $data[$num]['count']; $k++) {
                        if (strlen(trim($data[$num][$k]['name'])) > 0) {
                            if ($count_display) {
                                $out .= $separate;
                            }
                            $count_display++;
                            $text = "";
                            if (isset($searchopt[$ID]['htmltext']) && $searchopt[$ID]['htmltext']) {
                                $text = Html::clean(Toolbox::unclean_cross_side_scripting_deep(nl2br($data[$num][$k]['name'])));
                            } else {
                                $text = nl2br($data[$num][$k]['name']);
                            }
                            if (self::$output_type == self::HTML_OUTPUT && Toolbox::strlen($text) > $CFG_GLPI['cut']) {
                                $rand = mt_rand();
                                $out .= sprintf(__('%1$s %2$s'), "<span id='text{$rand}'>" . Html::resume_text($text, $CFG_GLPI['cut']) . '</span>', Html::showToolTip($text, array('applyto' => "text{$rand}", 'display' => false)));
                            } else {
                                $out .= $text;
                            }
                        }
                    }
                    return $out;
                case "date":
                case "date_delay":
                    $out = '';
                    for ($k = 0; $k < $data[$num]['count']; $k++) {
                        if (is_null($data[$num][$k]['name']) && isset($searchopt[$ID]['emptylabel']) && $searchopt[$ID]['emptylabel']) {
                            $out .= (empty($out) ? '' : self::LBBR) . $searchopt[$ID]['emptylabel'];
                        } else {
                            $out .= (empty($out) ? '' : self::LBBR) . Html::convDate($data[$num][$k]['name']);
                        }
                    }
                    return $out;
                case "datetime":
                    $out = '';
                    for ($k = 0; $k < $data[$num]['count']; $k++) {
                        if (is_null($data[$num][$k]['name']) && isset($searchopt[$ID]['emptylabel']) && $searchopt[$ID]['emptylabel']) {
                            $out .= (empty($out) ? '' : self::LBBR) . $searchopt[$ID]['emptylabel'];
                        } else {
                            $out .= (empty($out) ? '' : self::LBBR) . Html::convDateTime($data[$num][$k]['name']);
                        }
                    }
                    return $out;
                case "timestamp":
                    $withseconds = false;
                    if (isset($searchopt[$ID]['withseconds'])) {
                        $withseconds = $searchopt[$ID]['withseconds'];
                    }
                    $withdays = true;
                    if (isset($searchopt[$ID]['withdays'])) {
                        $withdays = $searchopt[$ID]['withdays'];
                    }
                    $out = '';
                    for ($k = 0; $k < $data[$num]['count']; $k++) {
                        $out .= (empty($out) ? '' : '<br>') . Html::timestampToString($data[$num][$k]['name'], $withseconds, $withdays);
                    }
                    return $out;
                case "email":
                    $out = '';
                    $count_display = 0;
                    for ($k = 0; $k < $data[$num]['count']; $k++) {
                        if ($count_display) {
                            $out .= self::LBBR;
                        }
                        $count_display++;
                        if (!empty($data[$num][$k]['name'])) {
                            $out .= empty($out) ? '' : self::LBBR;
                            $out .= "<a href='mailto:" . Html::entities_deep($data[$num][$k]['name']) . "'>" . $data[$num][$k]['name'];
                            $out .= "</a>";
                        }
                    }
                    return empty($out) ? "&nbsp;" : $out;
                case "weblink":
                    $orig_link = trim($data[$num][0]['name']);
                    if (!empty($orig_link)) {
                        // strip begin of link
                        $link = preg_replace('/https?:\\/\\/(www[^\\.]*\\.)?/', '', $orig_link);
                        $link = preg_replace('/\\/$/', '', $link);
                        if (Toolbox::strlen($link) > $CFG_GLPI["url_maxlength"]) {
                            $link = Toolbox::substr($link, 0, $CFG_GLPI["url_maxlength"]) . "...";
                        }
                        return "<a href=\"" . formatOutputWebLink($orig_link) . "\" target='_blank'>{$link}</a>";
                    }
                    return "&nbsp;";
                case "count":
                case "number":
                    $out = "";
                    $count_display = 0;
                    for ($k = 0; $k < $data[$num]['count']; $k++) {
                        if (strlen(trim($data[$num][$k]['name'])) > 0) {
                            if ($count_display) {
                                $out .= self::LBBR;
                            }
                            $count_display++;
                            if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$num][$k]['name']])) {
                                $out .= $searchopt[$ID]['toadd'][$data[$num][$k]['name']];
                            } else {
                                $number = str_replace(' ', '&nbsp;', Html::formatNumber($data[$num][$k]['name'], false, 0));
                                $out .= Dropdown::getValueWithUnit($number, $unit);
                            }
                        }
                    }
                    return $out;
                case "decimal":
                    $out = "";
                    $count_display = 0;
                    for ($k = 0; $k < $data[$num]['count']; $k++) {
                        if (strlen(trim($data[$num][$k]['name'])) > 0) {
                            if ($count_display) {
                                $out .= self::LBBR;
                            }
                            $count_display++;
                            if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$num][$k]['name']])) {
                                $out .= $searchopt[$ID]['toadd'][$data[$num][$k]['name']];
                            } else {
                                $number = str_replace(' ', '&nbsp;', Html::formatNumber($data[$num][$k]['name']));
                                $out .= Dropdown::getValueWithUnit($number, $unit);
                            }
                        }
                    }
                    return $out;
                case "bool":
                    $out = "";
                    $count_display = 0;
                    for ($k = 0; $k < $data[$num]['count']; $k++) {
                        if (strlen(trim($data[$num][$k]['name'])) > 0) {
                            if ($count_display) {
                                $out .= self::LBBR;
                            }
                            $count_display++;
                            $out .= Dropdown::getValueWithUnit(Dropdown::getYesNo($data[$num][$k]['name']), $unit);
                        }
                    }
                    return $out;
                case "itemtypename":
                    if ($obj = getItemForItemtype($data[$num][0]['name'])) {
                        return $obj->getTypeName();
                    }
                    return "";
                case "language":
                    if (isset($CFG_GLPI['languages'][$data[$num][0]['name']])) {
                        return $CFG_GLPI['languages'][$data[$num][0]['name']][0];
                    }
                    return __('Default value');
            }
        }
        // Manage items with need group by / group_concat
        $out = "";
        $count_display = 0;
        $separate = self::LBBR;
        if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) {
            $separate = self::LBHR;
        }
        for ($k = 0; $k < $data[$num]['count']; $k++) {
            if (strlen(trim($data[$num][$k]['name'])) > 0) {
                if ($count_display) {
                    $out .= $separate;
                }
                $count_display++;
                // Get specific display if available
                $itemtype = getItemTypeForTable($table);
                if ($item = getItemForItemtype($itemtype)) {
                    $tmpdata = $data[$num][$k];
                    // Copy name to real field
                    $tmpdata[$field] = $data[$num][$k]['name'];
                    $specific = $item->getSpecificValueToDisplay($field, $tmpdata, array('html' => true, 'searchopt' => $searchopt[$ID]));
                }
                if (!empty($specific)) {
                    $out .= $specific;
                } else {
                    if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$num][$k]['name']])) {
                        $out .= $searchopt[$ID]['toadd'][$data[$num][$k]['name']];
                    } else {
                        // Empty is 0 or empty
                        if (empty($split[0]) && isset($searchopt[$ID]['emptylabel'])) {
                            $out .= $searchopt[$ID]['emptylabel'];
                        } else {
                            // Trans field exists
                            if (isset($data[$num][$k]['trans']) && !empty($data[$num][$k]['trans'])) {
                                $out .= Dropdown::getValueWithUnit($data[$num][$k]['trans'], $unit);
                            } else {
                                $out .= Dropdown::getValueWithUnit($data[$num][$k]['name'], $unit);
                            }
                        }
                    }
                }
            }
        }
        return $out;
        // Trans in group concat
        if (count($split) == 3 && !empty($split[1])) {
            return Dropdown::getValueWithUnit($split[1], $unit);
        }
        return Dropdown::getValueWithUnit($split[0], $unit);
    }

Usage Example

コード例 #1
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);
         }
     }
 }
All Usage Examples Of Search::giveItem