Search::showHeader PHP Method

showHeader() static public method

Print generic footer
static public showHeader ( $type, $rows, $cols, $fixed ) : string
$type display type (0=HTML, 1=Sylk,2=PDF,3=CSV)
$rows number of rows
$cols number of columns
$fixed used tab_cadre_fixe table for HTML export ? (default 0)
return string to display
    static function showHeader($type, $rows, $cols, $fixed = 0)
    {
        $out = "";
        switch ($type) {
            case self::PDF_OUTPUT_LANDSCAPE:
                //pdf
            //pdf
            case self::PDF_OUTPUT_PORTRAIT:
                global $PDF_TABLE;
                $PDF_TABLE = "<table cellspacing=\"0\" cellpadding=\"1\" border=\"1\" >";
                break;
            case self::SYLK_OUTPUT:
                // Sylk
                global $SYLK_ARRAY, $SYLK_HEADER, $SYLK_SIZE;
                $SYLK_ARRAY = array();
                $SYLK_HEADER = array();
                $SYLK_SIZE = array();
                // entetes HTTP
                header("Expires: Mon, 26 Nov 1962 00:00:00 GMT");
                header('Pragma: private');
                /// IE BUG + SSL
                header('Cache-control: private, must-revalidate');
                /// IE BUG + SSL
                header("Content-disposition: filename=glpi.slk");
                header('Content-type: application/octetstream');
                // entete du fichier
                echo "ID;PGLPI_EXPORT\n";
                // ID;Pappli
                echo "\n";
                // formats
                echo "P;PGeneral\n";
                echo "P;P#,##0.00\n";
                // P;Pformat_1 (reels)
                echo "P;P#,##0\n";
                // P;Pformat_2 (entiers)
                echo "P;P@\n";
                // P;Pformat_3 (textes)
                echo "\n";
                // polices
                echo "P;EArial;M200\n";
                echo "P;EArial;M200\n";
                echo "P;EArial;M200\n";
                echo "P;FArial;M200;SB\n";
                echo "\n";
                // nb lignes * nb colonnes
                echo "B;Y" . $rows;
                echo ";X" . $cols . "\n";
                // B;Yligmax;Xcolmax
                echo "\n";
                break;
            case self::CSV_OUTPUT:
                // csv
                header("Expires: Mon, 26 Nov 1962 00:00:00 GMT");
                header('Pragma: private');
                /// IE BUG + SSL
                header('Cache-control: private, must-revalidate');
                /// IE BUG + SSL
                header("Content-disposition: filename=glpi.csv");
                header('Content-type: application/octetstream');
                // zero width no break space (for excel)
                echo "";
                break;
            default:
                if ($fixed) {
                    $out = "<div class='center'><table border='0' class='tab_cadre_fixehov'>\n";
                } else {
                    $out = "<div class='center'><table border='0' class='tab_cadrehov'>\n";
                }
        }
        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::showHeader