$_POST['searchtype'] = key($tmp); unset($tmp); } // echo $_POST["itemtype"]."--".$_POST["field"]."--".$_POST['searchtype']; // printcleanArray($actions); $randsearch = -1; $dropdownname = "searchtype{$addmeta}" . $_POST["itemtype"] . $_POST["num"]; $searchopt = array(); if (count($actions) > 0) { // get already get search options if (isset($actions['searchopt'])) { $searchopt = $actions['searchopt']; // No name for clean array whith quotes unset($searchopt['name']); unset($actions['searchopt']); } $randsearch = Dropdown::showFromArray("searchtype" . $addmeta . "[" . $_POST["num"] . "]", $actions, array('value' => $_POST["searchtype"])); } echo " <span id='span{$dropdownname}'>\n"; $_REQUEST['searchtype'] = $_POST["searchtype"]; $_REQUEST['field'] = $_POST["field"]; $_REQUEST['itemtype'] = $_POST["itemtype"]; $_REQUEST['num'] = $_POST["num"]; $_REQUEST['value'] = stripslashes($_POST['value']); $_REQUEST['meta'] = $_POST['meta']; $_REQUEST['searchopt'] = serialize($searchopt); include GLPI_ROOT . "/plugins/mobile/ajax/searchoptionvalue.php"; echo "</span>\n"; $paramsaction = array('searchtype' => '__VALUE__', 'field' => $_POST["field"], 'itemtype' => $_POST["itemtype"], 'num' => $_POST["num"], 'value' => rawurlencode(stripslashes($_POST['value'])), 'searchopt' => $searchopt, 'meta' => $_POST['meta']); mobileAjaxUpdateItemOnSelectEvent("dropdown_searchtype" . $addmeta . "[" . $_POST["num"] . "]{$randsearch}", "span{$dropdownname}", $CFG_GLPI["root_doc"] . "/plugins/mobile/ajax/searchoptionvalue.php", $paramsaction, false); }
static function showGenericSearch($itemtype, array $params) { global $LANG, $CFG_GLPI; // Default values of parameters $p['link'] = array(); $p['field'] = array(); $p['contains'] = array(); $p['searchtype'] = array(); $p['sort'] = ''; $p['is_deleted'] = 0; $p['link2'] = ''; $p['contains2'] = ''; $p['field2'] = ''; $p['itemtype2'] = ''; $p['searchtype2'] = ''; foreach ($params as $key => $val) { $p[$key] = $val; } $options = Search::getCleanedOptions($itemtype); //$target = Toolbox::getItemTypeSearchURL($itemtype); // Instanciate an object to access method $item = NULL; if ($itemtype != 'States' && class_exists($itemtype)) { $item = new $itemtype(); } // Meta search names $metaactivated = array('Computer' => $LANG['Menu'][0], 'Printer' => $LANG['Menu'][2], 'Monitor' => $LANG['Menu'][3], 'Peripheral' => $LANG['Menu'][16], 'Software' => $LANG['Menu'][4], 'Phone' => $LANG['Menu'][34], 'Ticket' => $LANG['Menu'][5]); //$target = substr_replace($target, '/central.php#', strrpos($target, '/'), 1); //echo $target; //echo "<form name='searchform$itemtype' method='get' action='$target'>"; echo "<form name='searchform{$itemtype}' method='get' action='" . $CFG_GLPI["root_doc"] . "/plugins/mobile/front/search.php'>"; echo "<input type='hidden' name='menu' value='" . $_GET['menu'] . "' />"; echo "<input type='hidden' name='ssmenu' value='" . $_GET['ssmenu'] . "' />"; // Display normal search parameters for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) { // Display link item if ($i > 0) { echo "<select name='link[{$i}]'>"; echo "<option value='AND' "; if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "AND") { echo "selected"; } echo ">AND</option>"; echo "<option value='OR' "; if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "OR") { echo "selected"; } echo ">OR</option>"; echo "<option value='AND NOT' "; if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "AND NOT") { echo "selected"; } echo ">AND NOT</option>"; echo "<option value='OR NOT' "; if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "OR NOT") { echo "selected"; } echo ">OR NOT</option>"; echo "</select>"; } // display select box to define search item echo "<select id='Search{$itemtype}{$i}' name=\"field[{$i}]\" size='1'>"; echo "<option value='view' "; if (is_array($p['field']) && isset($p['field'][$i]) && $p['field'][$i] == "view") { echo "selected"; } echo ">" . $LANG['search'][11] . "</option>"; reset($options); $first_group = true; $selected = 'view'; foreach ($options as $key => $val) { // print groups if (!is_array($val)) { if (!$first_group) { echo "</optgroup>"; } else { $first_group = false; } echo "<optgroup label='{$val}'>"; } else { if (!isset($val['nosearch']) || $val['nosearch'] == false) { echo "<option title=\"" . Html::cleanInputText($val["name"]) . "\" value='{$key}'"; if (is_array($p['field']) && isset($p['field'][$i]) && $key == $p['field'][$i]) { echo "selected"; $selected = $key; } echo ">" . Toolbox::substr($val["name"], 0, 28) . "</option>"; } } } if (!$first_group) { echo "</optgroup>"; } echo "<option value='all' "; if (is_array($p['field']) && isset($p['field'][$i]) && $p['field'][$i] == "all") { echo "selected"; } echo ">" . $LANG['common'][66] . "</option>"; echo "</select>"; echo "<span id='SearchSpan{$itemtype}{$i}'>\n"; $_POST['itemtype'] = $itemtype; $_POST['num'] = $i; $_POST['field'] = $selected; //$_POST['meta']="type='search'"; $_POST['searchtype'] = is_array($p['searchtype']) && isset($p['searchtype'][$i]) ? $p['searchtype'][$i] : ""; $_POST['value'] = is_array($p['contains']) && isset($p['contains'][$i]) ? stripslashes($p['contains'][$i]) : ""; include GLPI_ROOT . "/plugins/mobile/inc/ajax.function.php"; include GLPI_ROOT . "/plugins/mobile/ajax/searchoption.php"; echo "</span>\n"; $params = array('field' => '__VALUE__', 'itemtype' => $itemtype, 'num' => $i, 'value' => $_POST["value"], 'searchtype' => $_POST["searchtype"]); mobileAjaxUpdateItemOnSelectEvent("Search{$itemtype}{$i}", "SearchSpan{$itemtype}{$i}", $CFG_GLPI["root_doc"] . "/plugins/mobile/ajax/searchoption.php", $params, false); } // Display meta search items $linked = array(); if ($_SESSION["glpisearchcount2"][$itemtype] > 0) { // Define meta search items to linked switch ($itemtype) { case 'Computer': $linked = array('Printer', 'Monitor', 'Peripheral', 'Software', 'Phone'); break; case 'Ticket': if (Session::haveRight("ticket", CREATE)) { $linked = array_keys(Ticket::getAllTypesForHelpdesk()); } break; case 'Printer': case 'Monitor': case 'Peripheral': case 'Software': case 'Phone': $linked = array('Computer'); break; } } $metanames = array(); if (is_array($linked) && count($linked) > 0) { for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { $rand = mt_rand(); // Display link item (not for the first item) echo "<select name='link2[{$i}]'>"; echo "<option value='AND' "; if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "AND") { echo "selected"; } echo ">AND</option>"; echo "<option value='OR' "; if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "OR") { echo "selected"; } echo ">OR</option>"; echo "<option value='AND NOT' "; if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "AND NOT") { echo "selected"; } echo ">AND NOT</option>"; echo "<option value='OR NOT' "; if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "OR NOT") { echo "selected"; } echo ">OR NOT</option>"; echo "</select>"; // Display select of the linked item type available echo "<select name='itemtype2[{$i}]' id='itemtype2_" . $itemtype . "_" . $i . "_{$rand}'>"; echo "<option value=''>" . DROPDOWN_EMPTY_VALUE . "</option>"; foreach ($linked as $key) { if (!isset($metanames[$key])) { $linkitem = new $key(); $metanames[$key] = $linkitem->getTypeName(); } echo "<option value='{$key}'>" . Toolbox::substr($metanames[$key], 0, 20) . "</option>\n"; } echo "</select>"; } } // Display submit button echo "<br /><input type='submit' value=\"" . $LANG['buttons'][0] . "\" class='submit' data-theme='a' data-inline='true'>"; // For dropdown echo "<input type='hidden' name='itemtype' value='{$itemtype}'>"; // Reset to start when submit new search echo "<input type='hidden' name='start' value='0'>"; //echo "</form>"; Html::closeForm(); }