Esempio n. 1
0
 /**
  * Show a date selector
  * @param  datetime $date1    date of start
  * @param  datetime $date2    date of ending
  * @param  string $randname random string (to prevent conflict in js selection)
  * @return nothing
  */
 static function showSelector($date1, $date2, $randname)
 {
     $request_string = self::getRequestString($_GET);
     echo "<div class='center'><form method='POST' action='?{$request_string}' name='form'" . " id='mreporting_date_selector'>\n";
     echo "<table class='tab_cadre'><tr class='tab_bg_1'>";
     echo '<td><table><tr class="tab_bg_1">';
     echo "<td>";
     Html::showDateFormItem("date1" . $randname, $date1, false);
     echo "</td>\n";
     echo "<td>";
     Html::showDateFormItem("date2" . $randname, $date2, false);
     echo "</td>\n";
     self::getReportSelectors();
     echo "</tr></table></td>";
     echo "<td rowspan='2' class='center'>";
     echo "<input type='submit' class='button' name='submit' Value=\"" . _sx('button', 'Post') . "\">";
     echo "</td>\n";
     echo "<td class='center'>";
     $_SERVER['REQUEST_URI'] .= "&date1" . $randname . "=" . $date1;
     $_SERVER['REQUEST_URI'] .= "&date2" . $randname . "=" . $date2;
     Bookmark::showSaveButton(Bookmark::URI);
     echo "</td>\n";
     echo "</tr>";
     echo "</table>";
     Html::closeForm();
     echo "</div>\n";
 }
Esempio n. 2
0
 /**
  * Print generic search form
  *
  * Params need to parsed before using Search::manageParams function
  *
  * @param $itemtype        type to display the form
  * @param $params    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();
 }
Esempio n. 3
0
 /**
  * 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>&nbsp;&nbsp;&nbsp;&nbsp;";
             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>&nbsp;&nbsp;&nbsp;&nbsp;";
             }
             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>&nbsp;&nbsp;&nbsp;&nbsp;";
                 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>&nbsp;&nbsp;&nbsp;&nbsp;";
                 }
             }
             $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>&nbsp;";
         }
         // 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>&nbsp;\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>&nbsp;";
             // 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>&nbsp;";
             echo "</td><td>";
             // Ajax script for display search met& item
             echo "<span id='show_" . $itemtype . "_" . $i . "_{$rand}'>&nbsp;</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 "&nbsp;&nbsp;<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();
 }
Esempio n. 4
0
if (Session::haveRight("config", "r")) {
    // Check only read as we probably use the replicate (no 'w' in this case)
    echo "<tr class='tab_bg_3 center'><td colspan='" . ($crit > 0 ? '3' : '2') . "'>";
    echo "<a href='./doublons.config.php'>" . __('Report configuration', 'reports') . "</a></td></tr>\n";
}
echo "<tr class='tab_bg_1'><td class='right'>" . _n('Criterion', 'Criteria', 2) . "</td><td>";
echo "<select name='crit'>";
foreach ($crits as $key => $val) {
    echo "<option value='{$key}'" . ($crit == $key ? "selected" : "") . ">{$val}</option>";
}
echo "</select></td>";
if ($crit > 0) {
    echo "<td>";
    //Add parameters to uri to be saved as bookmarks
    $_SERVER["REQUEST_URI"] = buildBookmarkUrl($_SERVER["REQUEST_URI"], $crit);
    Bookmark::showSaveButton(Bookmark::SEARCH, 'Computer');
    echo "</td>";
}
echo "</tr>\n";
echo "<tr class='tab_bg_1 center'><td colspan='" . ($crit > 0 ? '3' : '2') . "'>";
echo "<input type='submit' value='valider' class='submit'/>";
echo "</td></tr>\n";
echo "</table>\n";
Html::closeForm();
if ($crit == 5) {
    // Search Duplicate IP Address - From glpi_networking_ports
    $IPBlacklist = "AA.`ip` != ''\n                   AND AA.`ip` != '0.0.0.0'";
    if (TableExists("glpi_plugin_reports_doublons_backlists")) {
        $res = $DB->query("SELECT `addr`\n                         FROM `glpi_plugin_reports_doublons_backlists`\n                         WHERE `type` = '2'");
        while ($data = $DB->fetch_array($res)) {
            if (strpos($data["addr"], '%')) {
function displaySearchForm()
{
    global $_SERVER, $_GET, $CFG_GLPI;
    echo "<form action='" . $_SERVER["PHP_SELF"] . "' method='post'>";
    echo "<table class='tab_cadre' cellpadding='5'>";
    echo "<tr class='tab_bg_1' align='center'>";
    echo "<td>";
    echo __('Initial contract period') . " :";
    $values = array();
    $values["sup"] = ">";
    $values["inf"] = "<";
    $values["equal"] = "=";
    if (isset($_GET["contains"][1])) {
        if (strstr($_GET["contains"][1], "lt;")) {
            $_GET["dropdown_sup_inf"] = "inf";
            $_GET["dropdown_calendar"] = str_replace("lt;", "", $_GET["contains"][1]);
            $_GET["dropdown_calendar"] = str_replace("&", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace("\\", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace("'", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace(" 00:00:00", "", $_GET["dropdown_calendar"]);
            $_GET["contains"][1] = "<" . $_GET["dropdown_calendar"];
        }
        if (strstr($_GET["contains"][1], "gt;")) {
            $_GET["dropdown_sup_inf"] = "sup";
            $_GET["dropdown_calendar"] = str_replace("gt;", "", $_GET["contains"][1]);
            $_GET["dropdown_calendar"] = str_replace("&", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace("\\", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace("'", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace(" 00:00:00", "", $_GET["dropdown_calendar"]);
            $_GET["contains"][1] = ">" . $_GET["dropdown_calendar"];
        }
        if (strstr($_GET["contains"][1], "LIKE")) {
            $_GET["dropdown_sup_inf"] = "equal";
            $_GET["dropdown_calendar"] = str_replace("=", "", $_GET["contains"][1]);
            $_GET["dropdown_calendar"] = str_replace("&", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace("\\", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace("'", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace("%", "", $_GET["dropdown_calendar"]);
            $_GET["dropdown_calendar"] = str_replace("LIKE ", "", $_GET["dropdown_calendar"]);
            $_GET["contains"][1] = "LIKE '" . $_GET["dropdown_calendar"] . "%'";
        }
    }
    Dropdown::showFromArray("dropdown_sup_inf", $values, array('value' => isset($_GET["dropdown_sup_inf"]) ? $_GET["dropdown_sup_inf"] : "sup"));
    echo "</td>\n      <td width='120'>";
    Html::showDateFormItem("dropdown_calendar", isset($_GET["dropdown_calendar"]) ? $_GET["dropdown_calendar"] : 0);
    echo "</td>";
    echo "<td>" . __('Location') . "</td>";
    echo "<td>";
    Dropdown::show("Location", array('name' => "location", 'value' => isset($_GET["location"]) ? $_GET["location"] : ""));
    echo "</td>";
    // Display Reset search
    echo "<td>";
    echo "<a href='" . $CFG_GLPI["root_doc"] . "/plugins/fusioninventory/report/ports_date_connections.php?reset_search=reset_search' ><img title=\"" . __('Blank') . "\" alt=\"" . __('Blank') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/reset.png' class='calendrier'></a>";
    echo "</td>";
    echo "<td>";
    //Add parameters to uri to be saved as bookmarks
    $_SERVER["REQUEST_URI"] = buildBookmarkUrl($_SERVER["REQUEST_URI"], $_GET);
    Bookmark::showSaveButton(Bookmark::SEARCH, 'PluginFusioninventoryNetworkport2');
    echo "</td>";
    echo "<td>";
    echo "<input type='submit' value='Valider' class='submit' />";
    echo "</td>";
    echo "</tr>";
    echo "</table>";
    Html::closeForm();
}
Esempio n. 6
0
 /**
  * Print generic search form
  *
  * @param $itemtype        type to display the form
  * @param $params    array of parameters may include field, contains, sort, is_deleted, link,
  *                         link2, contains2, field2, type2
  *
  * @return nothing (displays)
  **/
 static function showGenericSearch($itemtype, array $params)
 {
     global $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 = self::getCleanedOptions($itemtype);
     $target = Toolbox::getItemTypeSearchURL($itemtype);
     // Instanciate an object to access method
     $item = NULL;
     if ($itemtype != 'AllAssets') {
         $item = getItemForItemtype($itemtype);
     }
     $linked = self::getMetaItemtypeAvailable($itemtype);
     echo "<form name='searchform{$itemtype}' method='get' action=\"{$target}\">";
     echo "<div id='searchcriterias'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'>";
     if ($_SESSION["glpisearchcount"][$itemtype] + $_SESSION["glpisearchcount2"][$itemtype] > 1) {
         echo "<td width='10' class='center'>";
         echo "<a href=\"javascript:toggleTableDisplay('searchcriteriastable','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 id='searchcriteriastable'>";
     // Display normal search parameters
     for ($i = 0; $i < $_SESSION["glpisearchcount"][$itemtype]; $i++) {
         echo "<tr " . ($i == 0 ? "class='headerRow'" : '') . "><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>&nbsp;&nbsp;&nbsp;&nbsp;";
             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>&nbsp;&nbsp;&nbsp;&nbsp;";
             }
             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>&nbsp;&nbsp;&nbsp;&nbsp;";
                 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>&nbsp;&nbsp;&nbsp;&nbsp;";
                 }
             }
             $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','','','');\n                      document.forms['searchform{$itemtype}'].submit();\">\n                      <img src=\"" . $CFG_GLPI["root_doc"] . "/pics/showdeleted" . (!$p['is_deleted'] ? '_no' : '') . ".png\" name='img_deleted' alt=\"" . (!$p['is_deleted'] ? __s('Show the dustbin') : __s("Don't show deleted items")) . "\" title=\"" . (!$p['is_deleted'] ? __s('Show the dustbin') : __s("Don't show deleted items")) . "\"></a>";
                 echo '&nbsp;&nbsp;';
             }
         }
         // 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>&nbsp;";
         }
         $selected = $first = '';
         // display select box to define search item
         echo "<select id='Search{$itemtype}{$i}' name=\"field[{$i}]\" size='1'>";
         if ($CFG_GLPI['allow_search_view'] == 2) {
             echo "<option value='view' ";
             if (is_array($p['field']) && isset($p['field'][$i]) && $p['field'][$i] == "view") {
                 echo "selected";
                 $selected = 'view';
             }
             echo ">" . __('Items seen') . "</option>\n";
         }
         reset($options);
         $first_group = true;
         $str_limit = 28;
         // Not $_SESSION['glpidropdown_chars_limit'] because must be really to short (5 or 10) and search engine will be unusable
         $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;
                     } else {
                         if (empty($first)) {
                             $first = $key;
                         }
                     }
                     $group .= ">" . Toolbox::substr($val["name"], 0, $str_limit) . "</option>\n";
                 }
             }
         }
         if (!$first_group) {
             $group .= "</optgroup>\n";
         }
         if ($nb_in_group) {
             echo $group;
         }
         if ($CFG_GLPI['allow_search_view'] == 1) {
             echo "<option value='view' ";
             if (is_array($p['field']) && isset($p['field'][$i]) && $p['field'][$i] == "view") {
                 echo "selected";
                 $selected = 'view';
             }
             echo ">" . __('Items seen') . "</option>\n";
         }
         if ($CFG_GLPI['allow_search_all']) {
             echo "<option value='all' ";
             if (is_array($p['field']) && isset($p['field'][$i]) && $p['field'][$i] == "all") {
                 echo "selected";
                 $selected = 'all';
             }
             echo ">" . __('All') . "</option>";
         }
         if (empty($selected)) {
             $selected = $first;
         }
         echo "</select>\n";
         echo "</td><td class='left'>";
         echo "<div id='SearchSpan{$itemtype}{$i}'>\n";
         $used_itemtype = $itemtype;
         // Force Computer itemtype for AllAssets to permit to show specific items
         if ($itemtype == 'AllAssets') {
             $used_itemtype = 'Computer';
         }
         $_POST['itemtype'] = $used_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' => $used_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);
         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>&nbsp;";
             // 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])) {
                     if ($linkitem = getItemForItemtype($key)) {
                         $metanames[$key] = $linkitem->getTypeName();
                     }
                 }
                 echo "<option value='{$key}'>" . Toolbox::substr($metanames[$key], 0, 20) . "</option>\n";
             }
             echo "</select>&nbsp;";
             echo "</td><td>";
             // Ajax script for display search met& item
             echo "<span id='show_" . $itemtype . "_" . $i . "_{$rand}'>&nbsp;</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);
             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);
                 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'>".__('sorted by');
           echo "&nbsp;<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);
     echo "<a href='{$target}?reset=reset' >";
     echo "&nbsp;&nbsp;<img title=\"" . __s('Blank') . "\" alt=\"" . __s('Blank') . "\" src='" . $CFG_GLPI["root_doc"] . "/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'>";
     echo "</div>";
     Html::closeForm();
 }
Esempio n. 7
0
 /**
  * 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)
  **/
 static function showGenericSearch($itemtype, $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 = self::getCleanedOptions($itemtype);
     $target = getItemTypeSearchURL($itemtype);
     // Instanciate an object to access method
     $item = NULL;
     if ($itemtype != 'States' && class_exists($itemtype)) {
         $item = new $itemtype();
     }
     $linked = self::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'\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=\"" . $LANG['search'][17] . "\"></a>&nbsp;&nbsp;&nbsp;&nbsp;";
             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=\"" . $LANG['search'][18] . "\"></a>&nbsp;&nbsp;&nbsp;&nbsp;";
             }
             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=\"" . $LANG['search'][19] . "\"></a>&nbsp;&nbsp;&nbsp;&nbsp;";
                 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=\"" . $LANG['search'][20] . "\"></a>&nbsp;&nbsp;&nbsp;&nbsp;";
                 }
             }
             $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','','','');\n                      document.forms['searchform{$itemtype}'].submit();\">\n                      <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 '&nbsp;&nbsp;';
             }
         }
         // 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>&nbsp;";
         }
         // 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>\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=\"" . utf8_substr($val, 0, $str_limit) . "\">";
             } else {
                 if (!isset($val['nosearch']) || $val['nosearch'] == false) {
                     $nb_in_group++;
                     $group .= "<option title=\"" . cleanInputText($val["name"]) . "\" value='{$key}'";
                     if (is_array($p['field']) && isset($p['field'][$i]) && $key == $p['field'][$i]) {
                         $group .= "selected";
                         $selected = $key;
                     }
                     $group .= ">" . utf8_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 ">" . $LANG['common'][66] . "</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"]);
         ajaxUpdateItemOnSelectEvent("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>&nbsp;";
             // 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}'>" . utf8_substr($metanames[$key], 0, 20) . "</option>\n";
             }
             echo "</select>&nbsp;";
             echo "</td><td>";
             // Ajax script for display search met& item
             echo "<span id='show_" . $itemtype . "_" . $i . "_{$rand}'>&nbsp;</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] : "");
             ajaxUpdateItemOnSelectEvent("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];
                 ajaxUpdateItem("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 "&nbsp;<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 ">".utf8_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=\"" . $LANG['buttons'][0] . "\" class='submit' >";
     echo "</td><td>";
     Bookmark::showSaveButton(BOOKMARK_SEARCH, $itemtype);
     echo "<a href='{$target}?reset=reset' >";
     echo "&nbsp;&nbsp;<img title=\"" . $LANG['buttons'][16] . "\" alt=\"" . $LANG['buttons'][16] . "\" src='" . $CFG_GLPI["root_doc"] . "/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'>";
     echo "</form>";
 }
Esempio n. 8
0
 /**
  * Display a common search criterias form
  * @param target the form's target
  * @param params the search criterias
  */
 function displayCriteriasForm()
 {
     global $HEADER_LOADED;
     //Get criteria's values
     $this->manageCriteriasValues();
     //Display Html::header is output is HTML
     if (isset($_POST["display_type"]) && $_POST["display_type"] != Search::HTML_OUTPUT) {
         return;
     }
     if (!$HEADER_LOADED) {
         $title = $this->title;
         if ($this->subname) {
             $title = sprintf(__('%1$s - %2$s'), $title, $this->subname);
         }
         if (isStat($this->name)) {
             Html::header($title, $_SERVER['PHP_SELF'], "maintain", "stat");
             Stat::title();
         } else {
             Html::header($title, $_SERVER['PHP_SELF'], "utils", "report");
             Report::title();
         }
     }
     plugin_reports_checkRight($this->plug, $this->name, "r");
     //Display form only if there're criterias
     if (!empty($this->criterias)) {
         echo "<div class='center'>";
         echo "<form method='post' name='form' action='" . $_SERVER['PHP_SELF'] . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='6'>" . __('Search criteria', 'reports');
         //If form is validated, then display the bookmark button
         if ($this->criteriasValidated()) {
             //Add parameters to uri to be saved as bookmarks
             $_SERVER["REQUEST_URI"] = $this->buildBookmarkUrl();
             Bookmark::showSaveButton(Bookmark::URI, isStat($this->name) ? 'PluginReportsStat' : 'PluginReportsReport');
         }
         echo "</th></tr>\n";
         //Display each criteria's html selection item
         foreach ($this->criterias as $criteria) {
             $criteria->displayCriteria();
         }
         $this->closeColumn();
         echo "<tr class='tab_bg_2'><td colspan='4' class='center'>";
         echo "<input type='submit' name='find' value='" . _sx('button', 'Search') . "' class='submit'>";
         echo "</td></tr>";
         echo "</table></div>";
         Html::closeForm();
     }
 }