Search::showGenericSearch PHP Method

showGenericSearch() static public method

Params need to parsed before using Search::manageParams function
static public showGenericSearch ( $itemtype, array $params ) : nothing
$itemtype type to display the form
$params array array of parameters may include sort, is_deleted, criteria, metacriteria
return nothing (displays)
    static function showGenericSearch($itemtype, array $params)
    {
        global $CFG_GLPI;
        // Default values of parameters
        $p['sort'] = '';
        $p['is_deleted'] = 0;
        $p['criteria'] = array();
        $p['metacriteria'] = array();
        if (class_exists($itemtype)) {
            $p['target'] = $itemtype::getSearchURL();
        } else {
            $p['target'] = Toolbox::getItemTypeSearchURL($itemtype);
        }
        $p['showreset'] = true;
        $p['showbookmark'] = true;
        $p['addhidden'] = array();
        $p['actionname'] = 'search';
        $p['actionvalue'] = _sx('button', 'Search');
        foreach ($params as $key => $val) {
            $p[$key] = $val;
        }
        echo "<form name='searchform{$itemtype}' method='get' action=\"" . $p['target'] . "\">";
        echo "<div id='searchcriterias'>";
        $nbsearchcountvar = 'nbcriteria' . strtolower($itemtype) . mt_rand();
        $nbmetasearchcountvar = 'nbmetacriteria' . strtolower($itemtype) . mt_rand();
        $searchcriteriatableid = 'criteriatable' . strtolower($itemtype) . mt_rand();
        // init criteria count
        $js = "var {$nbsearchcountvar}=" . count($p['criteria']) . ";";
        $js .= "var {$nbmetasearchcountvar}=" . count($p['metacriteria']) . ";";
        echo Html::scriptBlock($js);
        echo "<table class='tab_cadre_fixe' >";
        echo "<tr class='tab_bg_1'>";
        if (count($p['criteria']) + count($p['metacriteria']) > 1) {
            echo "<td width='10' class='center'>";
            echo "<a href=\"javascript:toggleTableDisplay('{$searchcriteriatableid}','searchcriteriasimg',\n                                                       '" . $CFG_GLPI["root_doc"] . "/pics/deplier_down.png',\n                                                       '" . $CFG_GLPI["root_doc"] . "/pics/deplier_up.png')\">";
            echo "<img alt='' name='searchcriteriasimg' src=\"" . $CFG_GLPI["root_doc"] . "/pics/deplier_up.png\">";
            echo "</td>";
        }
        echo "<td>";
        echo "<table class='tab_format' id='{$searchcriteriatableid}'>";
        // Display normal search parameters
        for ($i = 0; $i < count($p['criteria']); $i++) {
            $_POST['itemtype'] = $itemtype;
            $_POST['num'] = $i;
            include GLPI_ROOT . '/ajax/searchrow.php';
        }
        $metanames = array();
        $linked = self::getMetaItemtypeAvailable($itemtype);
        if (is_array($linked) && count($linked) > 0) {
            for ($i = 0; $i < count($p['metacriteria']); $i++) {
                $_POST['itemtype'] = $itemtype;
                $_POST['num'] = $i;
                include GLPI_ROOT . '/ajax/searchmetarow.php';
            }
        }
        echo "</table>\n";
        echo "</td>\n";
        echo "<td width='150px'>";
        echo "<table width='100%'>";
        // Display deleted selection
        echo "<tr>";
        // Display submit button
        echo "<td width='80' class='center'>";
        echo "<input type='submit' name='" . $p['actionname'] . "' value=\"" . $p['actionvalue'] . "\" class='submit' >";
        echo "</td>";
        if ($p['showbookmark'] || $p['showreset']) {
            echo "<td>";
            if ($p['showbookmark']) {
                Bookmark::showSaveButton(Bookmark::SEARCH, $itemtype);
            }
            if ($p['showreset']) {
                echo "<a href='" . $p['target'] . (strpos($p['target'], '?') ? '&amp;' : '?') . "reset=reset' >";
                echo "&nbsp;&nbsp;<img title=\"" . __s('Blank') . "\" alt=\"" . __s('Blank') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/reset.png' class='calendrier pointer'></a>";
            }
            echo "</td>";
        }
        echo "</tr></table>\n";
        echo "</td></tr>";
        echo "</table>\n";
        if (count($p['addhidden'])) {
            foreach ($p['addhidden'] as $key => $val) {
                echo Html::hidden($key, array('value' => $val));
            }
        }
        // For dropdown
        echo Html::hidden('itemtype', array('value' => $itemtype));
        // Reset to start when submit new search
        echo Html::hidden('start', array('value' => 0));
        echo "</div>";
        Html::closeForm();
    }

Usage Example

if (isset($_GET['reset'])) {
    unset($_SESSION['glpisearch']['PluginMonitoringService']);
}
if (isset($_GET['glpi_tab'])) {
    unset($_GET['glpi_tab']);
}
//Search::manageGetValues("PluginMonitoringService");
//$_GET = Search::prepareDatasForSearch("PluginMonitoringService", $_GET);
if (isset($_GET['hidesearch'])) {
    echo "<table class='tab_cadre_fixe'>";
    echo "<tr class='tab_bg_1'>";
    echo "<th>";
    echo "<a onClick='\$(\"#searchformservices\").toggle();'>\n      <img src='" . $CFG_GLPI["root_doc"] . "/pics/deplier_down.png' />&nbsp;\n         " . __('Display search form', 'monitoring') . "\n      &nbsp;<img src='" . $CFG_GLPI["root_doc"] . "/pics/deplier_down.png' /></a>";
    echo "</th>";
    echo "</tr>";
    echo "</table>";
    echo "<div style='display: none;' id='searchformservices'>";
}
Search::showGenericSearch("PluginMonitoringService", $params);
if (isset($_GET['hidesearch'])) {
    echo "</div>";
}
$perfdatas = false;
if (isset($_GET['perfdatas'])) {
    $perfdatas = true;
}
$pmDisplay->showResourcesBoard('', $perfdatas, $params);
if (isset($_SESSION['glpisearch']['PluginMonitoringService']['reset'])) {
    unset($_SESSION['glpisearch']['PluginMonitoringService']['reset']);
}
Html::footer();
All Usage Examples Of Search::showGenericSearch