Search::showItem PHP Method

showItem() static public method

Print generic normal Item Cell
static public showItem ( $type, $value, &$num, $row, $extraparam = '' ) : string
$type display type (0=HTML, 1=Sylk,2=PDF,3=CSV)
$value value to display
$row row number
$extraparam extra parameters for display (default '')
return string to display
    static function showItem($type, $value, &$num, $row, $extraparam = '')
    {
        $out = "";
        switch ($type) {
            case self::PDF_OUTPUT_LANDSCAPE:
                //pdf
            //pdf
            case self::PDF_OUTPUT_PORTRAIT:
                global $PDF_TABLE;
                $value = preg_replace('/' . self::LBBR . '/', '<br>', $value);
                $value = preg_replace('/' . self::LBHR . '/', '<hr>', $value);
                $PDF_TABLE .= "<td {$extraparam} valign='top'>";
                $PDF_TABLE .= Html::weblink_extract(Html::clean($value));
                $PDF_TABLE .= "</td>\n";
                break;
            case self::SYLK_OUTPUT:
                //sylk
                global $SYLK_ARRAY, $SYLK_HEADER, $SYLK_SIZE;
                $value = Html::weblink_extract($value);
                $value = preg_replace('/' . self::LBBR . '/', '<br>', $value);
                $value = preg_replace('/' . self::LBHR . '/', '<hr>', $value);
                $SYLK_ARRAY[$row][$num] = self::sylk_clean($value);
                $SYLK_SIZE[$num] = max($SYLK_SIZE[$num], Toolbox::strlen($SYLK_ARRAY[$row][$num]));
                break;
            case self::CSV_OUTPUT:
                //csv
                $value = preg_replace('/' . self::LBBR . '/', '<br>', $value);
                $value = preg_replace('/' . self::LBHR . '/', '<hr>', $value);
                $value = Html::weblink_extract($value);
                $out = "\"" . self::csv_clean($value) . "\"" . $_SESSION["glpicsv_delimiter"];
                break;
            default:
                $out = "<td {$extraparam} valign='top'>";
                if (!preg_match('/' . self::LBHR . '/', $value)) {
                    $values = preg_split('/' . self::LBBR . '/i', $value);
                    $line_delimiter = '<br>';
                } else {
                    $values = preg_split('/' . self::LBHR . '/i', $value);
                    $line_delimiter = '<hr>';
                }
                $limitto = 20;
                if (count($values) > $limitto) {
                    for ($i = 0; $i < $limitto; $i++) {
                        $out .= $values[$i] . $line_delimiter;
                    }
                    // $rand=mt_rand();
                    $out .= "...&nbsp;";
                    $value = preg_replace('/' . self::LBBR . '/', '<br>', $value);
                    $value = preg_replace('/' . self::LBHR . '/', '<hr>', $value);
                    $out .= Html::showToolTip($value, array('display' => false, 'autoclose' => false));
                } else {
                    $value = preg_replace('/' . self::LBBR . '/', '<br>', $value);
                    $value = preg_replace('/' . self::LBHR . '/', '<hr>', $value);
                    $out .= $value;
                }
                $out .= "</td>\n";
        }
        $num++;
        return $out;
    }

Usage Example

Example #1
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);
     }
 }
All Usage Examples Of Search::showItem