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'], '?') ? '&' : '?') . "reset=reset' >";
echo " <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();
}