Get meta types available for search engine
static public getMetaItemtypeAvailable ( $itemtype ) : Array | ||
$itemtype | type to display the form | |
Résultat | Array | of available itemtype |
/** * Print generic search form * *@param $itemtype type to display the form *@param $params parameters array may include field, contains, sort, is_deleted, link, link2, contains2, field2, type2 * *@return nothing (displays) * **/ function showGenericSearch($params) { global $CFG_GLPI; $itemtype = "PluginResourcesDirectory"; $itemtable = $this->table; // 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("PluginResourcesDirectory"); $target = $CFG_GLPI["root_doc"] . "/plugins/resources/front/directory.php"; // Instanciate an object to access method $item = NULL; if (class_exists($itemtype)) { $item = new $itemtype(); } $linked = Search::getMetaItemtypeAvailable($itemtype); echo "<form name='searchform{$itemtype}' method='get' action=\"{$target}\">"; echo "<table class='tab_cadre_fixe' >"; echo "<tr class='tab_bg_1'>"; echo "<td>"; echo "<table>"; // Display normal search parameters for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) { echo "<tr><td class='left' width='50%'>"; // First line display add / delete images for normal and meta search items if ($i == 0) { echo "<input type='hidden' disabled id='add_search_count' name='add_search_count' value='1'>"; echo "<a href='#' onClick = \"document.getElementById('add_search_count').disabled=false;document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/plus.png\" alt='+' title='" . __s('Add a search criterion') . "'></a> "; if ($_SESSION["glpisearchcount"][$itemtype] > 1) { echo "<input type='hidden' disabled id='delete_search_count' name='delete_search_count' value='1'>"; echo "<a href='#' onClick = \"document.getElementById('delete_search_count').disabled=false;document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/moins.png\" alt='-' title='" . __s('Delete a search criterion') . "'></a> "; } if (is_array($linked) && count($linked) > 0) { echo "<input type='hidden' disabled id='add_search_count2' name='add_search_count2' value='1'>"; echo "<a href='#' onClick = \"document.getElementById('add_search_count2').disabled=false;document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/meta_plus.png\" alt='+' title='" . __s('Add a global search criterion') . "'></a> "; if ($_SESSION["glpisearchcount2"][$itemtype] > 0) { echo "<input type='hidden' disabled id='delete_search_count2' name='delete_search_count2' value='1'>"; echo "<a href='#' onClick = \"document.getElementById('delete_search_count2').disabled=false;document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/meta_moins.png\" alt='-' title='" . __s('Delete a global search criterion') . "'></a> "; } } $itemtable = getTableForItemType($itemtype); } // 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>\n"; echo "<option value='OR' "; if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "OR") { echo "selected"; } echo ">OR</option>\n"; 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>\n"; 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 serach 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 ">" . __('Items seen') . "</option>\n"; reset($options); $first_group = true; $selected = 'view'; foreach ($options as $key => $val) { // print groups if (!is_array($val)) { if (!$first_group) { echo "</optgroup>\n"; } 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>\n"; } } } if (!$first_group) { echo "</optgroup>\n"; } echo "<option value='all' "; if (is_array($p['field']) && isset($p['field'][$i]) && $p['field'][$i] == "all") { echo "selected"; } echo ">" . __('All') . "</option>"; echo "</select> \n"; echo "</td><td class='left'>"; echo "<div id='SearchSpan{$itemtype}{$i}'>\n"; $_POST['itemtype'] = $itemtype; $_POST['num'] = $i; $_POST['field'] = $selected; $_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 . "/ajax/searchoption.php"; echo "</div>\n"; $params = array('field' => '__VALUE__', 'itemtype' => $itemtype, 'num' => $i, 'value' => $_POST["value"], 'searchtype' => $_POST["searchtype"]); Ajax::updateItemOnSelectEvent("Search{$itemtype}{$i}", "SearchSpan{$itemtype}{$i}", $CFG_GLPI["root_doc"] . "/ajax/searchoption.php", $params, false); echo "</td></tr>\n"; } $metanames = array(); if (is_array($linked) && count($linked) > 0) { for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { echo "<tr><td class='left'>"; $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>\n"; echo "<option value='OR' "; if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "OR") { echo "selected"; } echo ">OR</option>\n"; 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>\n"; 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>\n"; 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> "; echo "</td><td>"; // Ajax script for display search met& item echo "<span id='show_" . $itemtype . "_" . $i . "_{$rand}'> </span>\n"; $params = array('itemtype' => '__VALUE__', 'num' => $i, 'field' => is_array($p['field2']) && isset($p['field2'][$i]) ? $p['field2'][$i] : "", 'value' => is_array($p['contains2']) && isset($p['contains2'][$i]) ? $p['contains2'][$i] : "", 'searchtype2' => is_array($p['searchtype2']) && isset($p['searchtype2'][$i]) ? $p['searchtype2'][$i] : ""); Ajax::updateItemOnSelectEvent("itemtype2_" . $itemtype . "_" . $i . "_{$rand}", "show_" . $itemtype . "_" . $i . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/updateMetaSearch.php", $params, false); if (is_array($p['itemtype2']) && isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i])) { $params['itemtype'] = $p['itemtype2'][$i]; Ajax::updateItem("show_" . $itemtype . "_" . $i . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/updateMetaSearch.php", $params, false); echo "<script type='text/javascript' >"; echo "window.document.getElementById('itemtype2_" . $itemtype . "_" . $i . "_{$rand}').value='" . $p['itemtype2'][$i] . "';"; echo "</script>\n"; } echo "</td></tr></table>"; echo "</td></tr>\n"; } } 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' value=\"" . _sx('button', 'Search') . "\" class='submit' >"; echo "</td><td>"; Bookmark::showSaveButton(Bookmark::SEARCH, $itemtype); echo "<a href='{$target}?reset=reset' >"; echo " <img title=\"" . __s('Blank') . "\" alt=\"" . __s('Blank') . "\" src='" . $CFG_GLPI["root_doc"] . "/templates/infotel/pics/reset.png' class='calendrier'></a>"; echo "</td></tr></table>\n"; echo "</td></tr>"; echo "</table>\n"; // 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'>"; Html::closeForm(); }
function showGenericSearch($itemtype, $params) { global $CFG_GLPI; // Default values of parameters $p = array(); $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(); } $linked = Search::getMetaItemtypeAvailable($itemtype); if (!isset($_GET['id']) || strstr($_SERVER['REQUEST_URI'], 'displayview_rule.form.php')) { $item->getEmpty(); } else { $item->getFromDB($_GET['id']); } if (strstr($_SERVER['REQUEST_URI'], 'displayview_rule.form.php')) { echo "<form name='searchform{$itemtype}' method='get' action=\"" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/displayview_rule.form.php\">"; } else { echo "<form name='searchform{$itemtype}' method='get' action=\"" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/componentscatalog_rule.form.php\">"; } $item->showFormHeader(); // echo "<form name='searchform$itemtype' method='get' action=\"". // $CFG_GLPI['root_doc']."/plugins/monitoring/front/componentscatalog_rule.form.php\">"; // echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'>"; echo "<td>"; echo __('Name') . " :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='name' value='" . $_GET['name'] . "'/>"; echo "</td>"; echo "<td>"; echo __('Status') . " :"; echo "</td>"; echo "<td>"; echo $_GET['itemtype']; echo "</td>"; echo "</tr>"; if (isset($_GET['itemtype'])) { echo "<tr class='tab_bg_1'>"; echo "<td colspan='3'>"; echo "<table>"; // Display normal search parameters for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) { echo "<tr><td class='left' width='50%'>"; // First line display add / delete images for normal and meta search items if ($i == 0) { echo "<input type='hidden' disabled id='add_search_count' name='add_search_count'\n value='1'>"; echo "<a href='#' onClick = \"document.getElementById('add_search_count').disabled=false;\n document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/plus.png\" alt='+' title=\"" . __s('Add a search criterion') . "\"></a> "; if ($_SESSION["glpisearchcount"][$itemtype] > 1) { echo "<input type='hidden' disabled id='delete_search_count'\n name='delete_search_count' value='1'>"; echo "<a href='#' onClick = \"document.getElementById('delete_search_count').disabled=false;\n document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/moins.png\" alt='-' title=\"" . __s('Delete a search criterion') . "\"></a> "; } if (is_array($linked) && count($linked) > 0) { echo "<input type='hidden' disabled id='add_search_count2' name='add_search_count2'\n value='1'>"; echo "<a href='#' onClick=\"document.getElementById('add_search_count2').disabled=false;\n document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/meta_plus.png\" alt='+' title=\"" . __s('Add a global search criterion') . "\"></a> "; if ($_SESSION["glpisearchcount2"][$itemtype] > 0) { echo "<input type='hidden' disabled id='delete_search_count2'\n name='delete_search_count2' value='1'>"; echo "<a href='#' onClick=\"document.getElementById('delete_search_count2').disabled=false;\n document.forms['searchform{$itemtype}'].submit();\">"; echo "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/meta_moins.png\" alt='-' title=\"" . __s('Delete a global search criterion') . "\"></a> "; } } // $itemtable = getTableForItemType($itemtype); // if ($item && $item->maybeDeleted()) { // echo "<input type='hidden' id='is_deleted' name='is_deleted' value='". // $p['is_deleted']."'>"; // echo "<a href='#' onClick = \"toogle('is_deleted','','',''); // document.forms['searchform$itemtype'].submit();\"> // <img src=\"".$CFG_GLPI["root_doc"]."/pics/showdeleted". // (!$p['is_deleted']?'_no':'').".png\" name='img_deleted' alt=\"". // (!$p['is_deleted']?$LANG['common'][3]:$LANG['common'][81])."\" title=\"". // (!$p['is_deleted']?$LANG['common'][3]:$LANG['common'][81])."\" ></a>"; // // Dropdown::showYesNo("is_deleted",$p['is_deleted']); // echo ' '; // } } // 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>\n"; echo "<option value='OR' "; if (is_array($p["link"]) && isset($p["link"][$i]) && $p["link"][$i] == "OR") { echo "selected"; } echo ">OR</option>\n"; 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>\n"; 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 ">" . __('Items seen') . "</option>\n"; reset($options); $first_group = true; $selected = 'view'; $str_limit = 28; $nb_in_group = 0; $group = ''; foreach ($options as $key => $val) { // print groups if (!is_array($val)) { if (!$first_group) { $group .= "</optgroup>\n"; } else { $first_group = false; } if ($nb_in_group) { echo $group; } $group = ''; $nb_in_group = 0; $group .= "<optgroup label=\"" . Toolbox::substr($val, 0, $str_limit) . "\">"; } else { if (!isset($val['nosearch']) || $val['nosearch'] == false) { $nb_in_group++; $group .= "<option title=\"" . Html::cleanInputText($val["name"]) . "\" value='{$key}'"; if (is_array($p['field']) && isset($p['field'][$i]) && $key == $p['field'][$i]) { $group .= "selected"; $selected = $key; } $group .= ">" . Toolbox::substr($val["name"], 0, $str_limit) . "</option>\n"; } } } if (!$first_group) { $group .= "</optgroup>\n"; } if ($nb_in_group) { echo $group; } echo "<option value='all' "; if (is_array($p['field']) && isset($p['field'][$i]) && $p['field'][$i] == "all") { echo "selected"; } echo ">" . __('All') . "</option>"; echo "</select>\n"; echo "</td><td class='left'>"; echo "<div id='SearchSpan{$itemtype}{$i}'>\n"; $_POST['itemtype'] = $itemtype; $_POST['num'] = $i; $_POST['field'] = $selected; $_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 . "/ajax/searchoption.php"; echo "</div>\n"; $params = array('field' => '__VALUE__', 'itemtype' => $itemtype, 'num' => $i, 'value' => $_POST["value"], 'searchtype' => $_POST["searchtype"]); Ajax::updateItemOnSelectEvent("Search{$itemtype}{$i}", "SearchSpan{$itemtype}{$i}", $CFG_GLPI["root_doc"] . "/ajax/searchoption.php", $params, false); echo "</td></tr>\n"; } $metanames = array(); if (is_array($linked) && count($linked) > 0) { for ($i = 0; $i < $_SESSION["glpisearchcount2"][$itemtype]; $i++) { echo "<tr><td class='left' colspan='2'>"; $rand = mt_rand(); echo "<table width='100%'><tr class='left'><td width='35%'>"; // 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>\n"; echo "<option value='OR' "; if (is_array($p['link2']) && isset($p['link2'][$i]) && $p['link2'][$i] == "OR") { echo "selected"; } echo ">OR</option>\n"; 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>\n"; 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>\n"; 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> "; echo "</td><td>"; // Ajax script for display search met& item echo "<span id='show_" . $itemtype . "_" . $i . "_{$rand}'> </span>\n"; $params = array('itemtype' => '__VALUE__', 'num' => $i, 'field' => is_array($p['field2']) && isset($p['field2'][$i]) ? $p['field2'][$i] : "", 'value' => is_array($p['contains2']) && isset($p['contains2'][$i]) ? $p['contains2'][$i] : "", 'searchtype2' => is_array($p['searchtype2']) && isset($p['searchtype2'][$i]) ? $p['searchtype2'][$i] : ""); Ajax::updateItemOnSelectEvent("itemtype2_" . $itemtype . "_" . $i . "_{$rand}", "show_" . $itemtype . "_" . $i . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/updateMetaSearch.php", $params, false); if (is_array($p['itemtype2']) && isset($p['itemtype2'][$i]) && !empty($p['itemtype2'][$i])) { $params['itemtype'] = $p['itemtype2'][$i]; Ajax::updateItem("show_" . $itemtype . "_" . $i . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/updateMetaSearch.php", $params, false); echo "<script type='text/javascript' >"; echo "window.document.getElementById('itemtype2_" . $itemtype . "_" . $i . "_{$rand}').value='" . $p['itemtype2'][$i] . "';"; echo "</script>\n"; } echo "</td></tr></table>"; echo "</td></tr>\n"; } } echo "</table>\n"; echo "</td>\n"; echo "<td width='150px'>"; echo "<table width='100%'>"; // Display sort selection /* echo "<tr><td colspan='2'>".$LANG['search'][4]; echo " <select name='sort' size='1'>"; reset($options); $first_group=true; foreach ($options as $key => $val) { if (!is_array($val)) { if (!$first_group) { echo "</optgroup>\n"; } else { $first_group=false; } echo "<optgroup label=\"$val\">"; } else { echo "<option value='$key'"; if ($key == $p['sort']) { echo " selected"; } echo ">".Toolbox::substr($val["name"],0,20)."</option>\n"; } } if (!$first_group) { echo "</optgroup>\n"; } echo "</select> "; echo "</td></tr>\n"; */ // Display deleted selection echo "<tr>"; // Display submit button echo "<td width='80' class='center'>"; echo "<input type='submit' value=\"" . _sx('button', 'Search') . "\" class='submit' >"; echo "</td><td>"; // Bookmark::showSaveButton(Bookmark::SEARCH,$itemtype); if (strstr($_SERVER['REQUEST_URI'], 'displayview_rule.form.php')) { echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/displayview_rule.form.php?" . "reset=reset" . "&name=" . $_GET['name'] . "&plugin_monitoring_displayviews_id=" . $_GET['plugin_monitoring_displayviews_id'] . "&itemtype=" . $_GET['itemtype'] . "' >"; } else { echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/componentscatalog_rule.form.php?" . "reset=reset" . "&name=" . $_GET['name'] . "&plugin_monitoring_componentscalalog_id=" . $_GET['plugin_monitoring_componentscalalog_id'] . "&itemtype=" . $_GET['itemtype'] . "' >"; } echo " <img title=\"" . __s('Blank') . "\" alt=\"" . __s('Blank') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/reset.png' class='calendrier'></a>"; echo "</td></tr>"; echo "</table>\n"; echo "</td></tr>"; echo "<tr>"; } if (isset($_GET['id'])) { echo "<td colspan='2' class='center'>"; if (strstr($_SERVER['REQUEST_URI'], 'displayview_rule.form.php')) { echo "<input type='hidden' name='plugin_monitoring_displayviews_id' value='" . $_GET['plugin_monitoring_displayviews_id'] . "' >"; } else { echo "<input type='hidden' name='plugin_monitoring_componentscalalog_id' value='" . $_GET['plugin_monitoring_componentscalalog_id'] . "' >"; } echo "<input type='hidden' name='id' value='" . $_GET['id'] . "' >"; echo "<input type='submit' name='updaterule' value=\"Update this rule\" class='submit' >"; echo "</td>"; echo "<td colspan='2' class='center'>"; echo "<input type='submit' name='deleterule' value=\"Delete this rule\" class='submit' >"; } else { echo "<td colspan='4' class='center'>"; echo "<input type='hidden' name='plugin_monitoring_componentscalalog_id' value='" . $_GET['plugin_monitoring_componentscalalog_id'] . "' >"; echo "<input type='submit' name='addrule' value=\"Add this rule\" class='submit' >"; } echo "</td>"; echo "</tr>"; echo "</table>\n"; // 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'>"; Html::closeForm(); }
// Non define case if (isset($_POST["itemtype"]) && isset($_POST["num"])) { $metacriteria = array(); if (isset($_SESSION['glpisearch'][$_POST["itemtype"]]['metacriteria'][$_POST["num"]]) && is_array($_SESSION['glpisearch'][$_POST["itemtype"]]['metacriteria'][$_POST["num"]])) { $metacriteria = $_SESSION['glpisearch'][$_POST["itemtype"]]['metacriteria'][$_POST["num"]]; } else { // Set default field $options = Search::getCleanedOptions($_POST["itemtype"]); foreach ($options as $key => $val) { if (is_array($val)) { $metacriteria['field'] = $key; break; } } } $linked = Search::getMetaItemtypeAvailable($_POST["itemtype"]); $rand = mt_rand(); $rowid = 'metasearchrow' . $_POST['itemtype'] . $rand; echo "<tr class='metacriteria' id='{$rowid}'><td class='left' colspan='2'>"; echo "<table class='tab_format'><tr class='left'>"; echo "<td width='30%'>"; echo "<img class='pointer' src=\"" . $CFG_GLPI["root_doc"] . "/pics/meta_moins.png\" alt='-' title=\"" . __s('Delete a global search criterion') . "\" onclick=\"" . Html::jsGetElementbyID($rowid) . ".remove();\">"; echo " "; // Display link item (not for the first item) $value = ''; if (isset($metacriteria["link"])) { $value = $metacriteria["link"]; } Dropdown::showFromArray("metacriteria[" . $_POST["num"] . "][link]", Search::getLogicalOperators(), array('value' => $value, 'width' => '40%')); // Display select of the linked item type available foreach ($linked as $key) {
/** * Prepare query to use depending of the type * * @param $type bookmark type * @param $query_tab parameters array * * @return prepared query array **/ function prepareQueryToUse($type, $query_tab) { switch ($type) { case self::SEARCH: // Check if all datas are valid $opt = Search::getCleanedOptions($this->fields['itemtype']); $query_tab_save = $query_tab; $partial_load = false; // Standard search if (isset($query_tab_save['criteria']) && count($query_tab_save['criteria'])) { unset($query_tab['criteria']); $new_key = 0; foreach ($query_tab_save['criteria'] as $key => $val) { if ($val['field'] != 'view' && $val['field'] != 'all' && (!isset($opt[$val['field']]) || isset($opt[$val['field']]['nosearch']) && $opt[$val['field']]['nosearch'])) { $partial_load = true; } else { $query_tab['criteria'][$new_key] = $val; $new_key++; } } } // Meta search if (isset($query_tab_save['metacriteria']) && count($query_tab_save['metacriteria'])) { $meta_ok = Search::getMetaItemtypeAvailable($query_tab['itemtype']); unset($query_tab['metacriteria']); $new_key = 0; foreach ($query_tab_save['metacriteria'] as $key => $val) { $opt = Search::getCleanedOptions($val['itemtype']); // Use if meta type is valid and option available if (!in_array($val['itemtype'], $meta_ok) || !isset($opt[$val['field']])) { $partial_load = true; } else { $query_tab['metacriteria'][$new_key] = $val; $new_key++; } } } // Display message if ($partial_load) { Session::addMessageAfterRedirect(__('Partial load of the bookmark.'), false, ERROR); } // add reset value $query_tab['reset'] = 'reset'; break; } return $query_tab; }
/** * Test search with all meta to not have SQL errors */ public function test_search_all_meta() { $itemtypeslist = array('Computer', 'Problem', 'Ticket', 'Printer', 'Monitor', 'Peripheral', 'Software', 'Phone'); foreach ($itemtypeslist as $itemtype) { // do a search query $search_params = array('is_deleted' => 0, 'start' => 0, 'criteria' => array(0 => array('field' => 'view', 'searchtype' => 'contains', 'value' => '')), 'metacriteria' => array()); $metacriteria = array(); $metaList = Search::getMetaItemtypeAvailable($itemtype); foreach ($metaList as $metaitemtype) { $item = getItemForItemtype($metaitemtype); foreach ($item->getSearchOptions() as $key => $data) { if (is_int($key)) { if (isset($data['datatype']) && $data['datatype'] == 'bool') { $metacriteria[] = array('link' => 'AND', 'field' => $key, 'searchtype' => 'equals', 'value' => 0); } else { $metacriteria[] = array('link' => 'AND', 'field' => $key, 'searchtype' => 'contains', 'value' => 'f'); } } } } $search_params['metacriteria'] = $metacriteria; $data = $this->doSearch($itemtype, $search_params); // check for sql error (data key missing or empty) $this->assertArrayHasKey('data', $data, $data['last_errors']); $this->assertNotCount(0, $data['data'], $data['last_errors']); } }
/** * Displays tab content * This function adapted from Search::showGenericSearch with controls removed * @param bool $formcontrol : display form buttons * @return nothing, displays a seach form */ static function showCriteria(PluginFusioninventoryDeployGroup $item, $formcontrol = true, $p) { global $CFG_GLPI, $DB; $is_dynamic = $item->isDynamicGroup(); $itemtype = "PluginFusioninventoryComputer"; $can_update = $item->canEdit($item->getID()); if ($can_update) { //show generic search form (duplicated from Search class) echo "<form name='group_search_form' method='POST'>"; echo "<input type='hidden' name='plugin_fusioninventory_deploygroups_id' value='" . $item->getID() . "'>"; echo "<input type='hidden' name='id' value='" . $item->getID() . "'>"; // add tow hidden fields to permit delete of (meta)criteria echo "<input type='hidden' name='criteria' value=''>"; echo "<input type='hidden' name='metacriteria' value=''>"; } echo "<div class='tabs_criteria'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . _n('Criterion', 'Criteria', 2) . "</th></tr>"; echo "<tr><td>"; echo "<div id='searchcriteria'>"; $nb_criteria = count($p['criteria']); if ($nb_criteria == 0) { $nb_criteria++; } $nb_meta_criteria = isset($p['metacriteria']) ? count($p['metacriteria']) : 0; $nbsearchcountvar = 'nbcriteria' . strtolower($itemtype) . mt_rand(); $nbmetasearchcountvar = 'nbmetacriteria' . strtolower($itemtype) . mt_rand(); $searchcriteriatableid = 'criteriatable' . strtolower($itemtype) . mt_rand(); // init criteria count $js = "var {$nbsearchcountvar}=" . $nb_criteria . ";"; $js .= "var {$nbmetasearchcountvar}=" . $nb_meta_criteria . ";"; echo Html::scriptBlock($js); echo "<table class='tab_format' id='{$searchcriteriatableid}'>"; // Displays normal search parameters for ($i = 0; $i < $nb_criteria; $i++) { $_POST['itemtype'] = $itemtype; $_POST['num'] = $i; include GLPI_ROOT . '/ajax/searchrow.php'; } $metanames = array(); $linked = Search::getMetaItemtypeAvailable('Computer'); if (is_array($linked) && count($linked) > 0) { for ($i = 0; $i < $nb_meta_criteria; $i++) { $_POST['itemtype'] = $itemtype; $_POST['num'] = $i; include GLPI_ROOT . '/ajax/searchmetarow.php'; } } echo "</table>\n"; echo "</td>"; echo "</tr>"; echo "</table>\n"; // For dropdown echo "<input type='hidden' name='itemtype' value='{$itemtype}'>"; if ($can_update) { // add new button to search form (to store and preview) echo "<div class='center'>"; if ($is_dynamic) { echo "<input type='submit' value=\" " . _sx('button', 'Save') . " \" class='submit' name='save'>"; } else { echo "<input type='submit' value=\" " . __('Preview') . " \" class='submit' name='preview'>"; } echo "</div>"; } echo "</td></tr></table>"; echo "</div>"; //restore search session variables //$_SESSION['glpisearch'] = $glpisearch_session; // Reset to start when submit new search echo "<input type='hidden' name='start' value='0'>"; Html::closeForm(); //clean with javascript search control /* $clean_script = "jQuery( document ).ready(function( $ ) { $('#parent_criteria img').remove(); $('.tabs_criteria img[name=img_deleted').remove(); });"; echo Html::scriptBlock($clean_script);*/ }
/** * Prepare query to use depending of the type * * @param $type bookmark type * @param $query_tab parameters array * * @return prepared query array **/ function prepareQueryToUse($type, $query_tab) { global $LANG; switch ($type) { case BOOKMARK_SEARCH: // Check if all datas are valid $opt = Search::getCleanedOptions($this->fields['itemtype']); $query_tab_save = $query_tab; $partial_load = false; // Standard search if (isset($query_tab_save['field']) && count($query_tab_save['field'])) { unset($query_tab['field']); unset($query_tab['searchtype']); unset($query_tab['contains']); unset($query_tab['link']); $new_key = 0; foreach ($query_tab_save['field'] as $key => $val) { if ($val != 'view' && $val != 'all' && !isset($opt[$val])) { $query_tab['glpisearchcount']--; $partial_load = true; } else { $query_tab['field'][$new_key] = $val; if (isset($query_tab_save['searchtype']) && isset($query_tab_save['searchtype'][$key])) { $query_tab['searchtype'][$new_key] = $query_tab_save['searchtype'][$key]; } $query_tab['contains'][$new_key] = $query_tab_save['contains'][$key]; if (isset($query_tab_save['link'][$key])) { $query_tab['link'][$new_key] = $query_tab_save['link'][$key]; } $new_key++; } } } if ($query_tab['glpisearchcount'] == 0) { $query_tab['glpisearchcount'] = 1; } // Meta search if (isset($query_tab_save['itemtype2']) && count($query_tab_save['itemtype2'])) { $meta_ok = Search::getMetaItemtypeAvailable($query_tab['itemtype']); unset($query_tab['field2']); unset($query_tab['searchtype2']); unset($query_tab['contains2']); unset($query_tab['link2']); unset($query_tab['itemtype2']); $new_key = 0; foreach ($query_tab_save['field2'] as $key => $val) { $opt = Search::getCleanedOptions($query_tab_save['itemtype2'][$key]); // Use if meta type is valid and option available if (!in_array($query_tab_save['itemtype2'][$key], $meta_ok) || !isset($opt[$val])) { $query_tab['glpisearchcount2']--; $partial_load = true; } else { $query_tab['field2'][$new_key] = $val; if (isset($query_tab_save['searchtype2']) && isset($query_tab_save['searchtype2'][$key])) { $query_tab['searchtype2'][$new_key] = $query_tab_save['searchtype2'][$key]; } $query_tab['contains2'][$new_key] = $query_tab_save['contains2'][$key]; $query_tab['link2'][$new_key] = $query_tab_save['link2'][$key]; $query_tab['itemtype2'][$new_key] = $query_tab_save['itemtype2'][$key]; $new_key++; } } } // Display message if ($partial_load) { addMessageAfterRedirect($LANG['bookmark'][2], false, ERROR); } // add reset value $query_tab['reset'] = 'reset'; break; } return $query_tab; }