示例#1
0
This file is part of GLPI.

GLPI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
--------------------------------------------------------------------------
*/
// ----------------------------------------------------------------------
// Original Author of file: Julien Dombre
// Purpose of file:
// ----------------------------------------------------------------------
$AJAX_INCLUDE = 1;
define('GLPI_ROOT', '..');
include GLPI_ROOT . "/inc/includes.php";
header("Content-Type: text/html; charset=UTF-8");
header_nocache();
checkLoginUser();
if (isset($_POST['name'])) {
    echo "<input type='text' " . (isset($_POST["size"]) ? " size='" . $_POST["size"] . "' " : "") . " " . (isset($_POST["maxlength"]) ? "maxlength='" . $_POST["maxlength"] . "' " : "") . " name='" . $_POST['name'] . "' value=\"" . cleanInputText(rawurldecode(stripslashes($_POST["data"]))) . "\">";
}
/**
 * Show div with auto completion
 *
 * @param $item item object used for create dropdown
 * @param $field field to search for autocompletion
 * @param $options possible options
 * Parameters which could be used in options array :
 *    - name : string / name of the select (default is field parameter)
 *    - value : integer / preselected value (default value of the item object)
 *    - size : integer / size of the text field
 *    - entity : integer / restrict to a defined entity (default entity of the object if define)
 *              set to -1 not to take into account
 *    - user : integer / restrict to a defined user (default -1 : no restriction)
 *    - option : string / options to add to text field
 *
 * @return nothing (print out an HTML div)
 **/
function autocompletionTextField(CommonDBTM $item, $field, $options = array())
{
    global $CFG_GLPI;
    $params['name'] = $field;
    $params['value'] = '';
    if (array_key_exists($field, $item->fields)) {
        $params['value'] = $item->fields[$field];
    }
    $params['size'] = 40;
    $params['entity'] = -1;
    if (array_key_exists('entities_id', $item->fields)) {
        $params['entity'] = $item->fields['entities_id'];
    }
    $params['user'] = -1;
    $params['option'] = '';
    if (is_array($options) && count($options)) {
        foreach ($options as $key => $val) {
            $params[$key] = $val;
        }
    }
    if ($CFG_GLPI["use_ajax"] && $CFG_GLPI["use_ajax_autocompletion"]) {
        $rand = mt_rand();
        $name = "field_" . $params['name'] . $rand;
        echo "<input " . $params['option'] . " id='text{$name}' type='text' name='" . $params['name'] . "' value=\"" . cleanInputText($params['value']) . "\" size='" . $params['size'] . "'>\n";
        $output = "<script type='text/javascript' >\n";
        $output .= "var text{$name} = new Ext.data.Store({\n         proxy: new Ext.data.HttpProxy(\n         new Ext.data.Connection ({\n            url: '" . $CFG_GLPI["root_doc"] . "/ajax/autocompletion.php',\n            extraParams : {\n               itemtype: '" . $item->getType() . "',\n               field: '{$field}'";
        if ($params['entity'] >= 0) {
            $output .= ",entity_restrict: " . $params['entity'];
        }
        if ($params['user'] >= 0) {
            $output .= ",user_restrict: " . $params['user'];
        }
        $output .= "\n            },\n            method: 'POST'\n            })\n         ),\n         reader: new Ext.data.JsonReader({\n            totalProperty: 'totalCount',\n            root: 'items',\n            id: 'value'\n         }, [\n         {name: 'value', mapping: 'value'}\n         ])\n      });\n      ";
        $output .= "var search{$name} = new Ext.ux.form.SpanComboBox({\n         store: text{$name},\n         displayField:'value',\n         pageSize:20,\n         hideTrigger:true,\n         minChars:3,\n         resizable:true,\n         width: " . $params['size'] * 7 . ",\n         minListWidth:" . $params['size'] * 5 . ", // IE problem : wrong computation of the width of the ComboBox field\n         applyTo: 'text{$name}'\n      });";
        $output .= "</script>";
        echo $output;
    } else {
        echo "<input " . $params['option'] . " type='text' name='" . $params['name'] . "'\n             value=\"" . cleanInputText($params['value']) . "\" size='" . $params['size'] . "'>\n";
    }
}
    include GLPI_ROOT . "/inc/includes.php";
    header("Content-Type: text/html; charset=UTF-8");
    header_nocache();
}
checkRight("software", "w");
if ($_POST['softwares_id'] > 0) {
    if (!isset($_POST['value'])) {
        $_POST['value'] = 0;
    }
    // Make a select box
    $query = "SELECT DISTINCT `glpi_softwareversions`.*,\n                             `glpi_states`.`name` AS sname\n             FROM `glpi_softwareversions`\n             LEFT JOIN `glpi_states` ON (`glpi_softwareversions`.`states_id` = `glpi_states`.`id`)\n             WHERE `glpi_softwareversions`.`softwares_id` = '" . $_POST['softwares_id'] . "'\n             ORDER BY `name`";
    $result = $DB->query($query);
    $number = $DB->numrows($result);
    echo "<select name='" . $_POST['myname'] . "' size='1'>";
    echo "<option value='0'>" . DROPDOWN_EMPTY_VALUE . "</option>";
    $today = date("Y-m-d");
    if ($number) {
        while ($data = $DB->fetch_assoc($result)) {
            $ID = $data['id'];
            $output = $data['name'];
            if (empty($output) || $_SESSION['glpiis_ids_visible']) {
                $output .= " ({$ID})";
            }
            if (!empty($data['sname'])) {
                $output .= " - " . $data['sname'];
            }
            echo "<option " . ($ID == $_POST['value'] ? "selected" : "") . " value='{$ID}' title=\"" . cleanInputText($output) . "\">" . $output . "</option>";
        }
    }
    echo "</select>&nbsp;";
}
    $query = "SELECT DISTINCT `glpi_networkports_networkports`.`id` AS wid,\n                             `glpi_networkports`.`id` AS did,\n                             `{$table}`.`name` AS cname,\n                             `glpi_networkports`.`name` AS nname,\n                             `glpi_netpoints`.`name` AS npname\n             FROM `{$table}`\n             LEFT JOIN `glpi_networkports`\n               ON (`glpi_networkports`.`items_id` = '" . $_POST['item'] . "'\n                   AND `glpi_networkports`.`itemtype` = '" . $_POST["itemtype"] . "'\n                   AND `glpi_networkports`.`items_id` = `{$table}`.`id`)\n             LEFT JOIN `glpi_networkports_networkports`\n               ON (`glpi_networkports_networkports`.`networkports_id_1` = `glpi_networkports`.`id`\n                   OR `glpi_networkports_networkports`.`networkports_id_2`=`glpi_networkports`.`id`)\n             LEFT JOIN `glpi_netpoints`\n               ON (`glpi_netpoints`.`id`=`glpi_networkports`.`netpoints_id`)\n             WHERE `glpi_networkports_networkports`.`id` IS NULL\n                   AND `glpi_networkports`.`id` IS NOT NULL\n                   AND `glpi_networkports`.`id` <> '" . $_POST['current'] . "'\n                   AND `{$table}`.`is_deleted` = '0'\n                   AND `{$table}`.`is_template` = '0'\n             ORDER BY `glpi_networkports`.`id`";
    $result = $DB->query($query);
    echo "<br>";
    echo "<select name='" . $_POST['myname'] . "[" . $_POST["current"] . "]' size='1'>";
    echo "<option value='0'>" . DROPDOWN_EMPTY_VALUE . "</option>";
    if ($DB->numrows($result)) {
        while ($data = $DB->fetch_array($result)) {
            // Device name + port name
            $output = $output_long = $data['cname'];
            if (!empty($data['nname'])) {
                $output .= " - " . $data['nname'];
                $output_long .= " - " . $LANG['networking'][44] . " " . $data['nname'];
            }
            // display netpoint (which will be copied)
            if (!empty($data['npname'])) {
                $output .= " - " . $data['npname'];
                $output_long .= " - " . $LANG['networking'][51] . " " . $data['npname'];
            }
            $ID = $data['did'];
            if ($_SESSION["glpiis_ids_visible"] || empty($output)) {
                $output .= " ({$ID})";
                $output_long .= " ({$ID})";
            }
            $output = utf8_substr($output, 0, $_SESSION["glpidropdown_chars_limit"]);
            echo "<option value='{$ID}' title=\"" . cleanInputText($output_long) . "\">" . $output;
            echo "</option>";
        }
    }
    echo "</select>";
    echo "<input type='submit' name='connect' value=\"" . $LANG['buttons'][9] . "\" class='submit'>";
}
示例#5
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>";
 }
// ----------------------------------------------------------------------
if (strpos($_SERVER['PHP_SELF'], "dropdownSelectSoftware.php")) {
    $AJAX_INCLUDE = 1;
    define('GLPI_ROOT', '..');
    include GLPI_ROOT . "/inc/includes.php";
    header("Content-Type: text/html; charset=UTF-8");
    header_nocache();
}
checkRight("software", "w");
// Make a select box
$rand = mt_rand();
$where = "";
if (strlen($_POST['searchText']) > 0 && $_POST['searchText'] != $CFG_GLPI["ajax_wildcard"]) {
    $where .= " AND `name` " . makeTextSearch($_POST['searchText']) . " ";
}
$where .= getEntitiesRestrictRequest(' AND', 'glpi_softwares', 'entities_id', $_POST["entity_restrict"], true);
$query = "SELECT DISTINCT `glpi_softwares`.`id`,\n                          `glpi_softwares`.`name`\n          FROM `glpi_softwares`\n          WHERE `glpi_softwares`.`is_deleted` = '0'\n                AND `glpi_softwares`.`is_template` = '0'\n                {$where}\n          ORDER BY `glpi_softwares`.`name`";
$result = $DB->query($query);
echo "<select name='softwares_id' id='item_type{$rand}'>\n";
echo "<option value='0'>" . DROPDOWN_EMPTY_VALUE . "</option>\n";
if ($DB->numrows($result)) {
    while ($data = $DB->fetch_array($result)) {
        $softwares_id = $data["id"];
        $output = $data["name"];
        echo "<option value='{$softwares_id}' title=\"" . cleanInputText($output) . "\">" . utf8_substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>";
    }
}
echo "</select>\n";
$paramsselsoft = array('softwares_id' => '__VALUE__', 'myname' => $_POST["myname"]);
ajaxUpdateItemOnSelectEvent("item_type{$rand}", "show_" . $_POST["myname"] . $rand, $CFG_GLPI["root_doc"] . "/ajax/dropdownInstallVersion.php", $paramsselsoft, false);
echo "<span id='show_" . $_POST["myname"] . "{$rand}'>&nbsp;</span>\n";
                            $display = true;
                            break;
                    }
                }
                //Could display be handled by a plugin ?
                if (!$display && ($plug = isPluginItemType(getItemTypeForTable($searchopt['table'])))) {
                    $function = 'plugin_' . $plug['plugin'] . '_searchOptionsValues';
                    if (function_exists($function)) {
                        $params = array('name' => $inputname, 'searchtype' => $_REQUEST['searchtype'], 'searchoption' => $searchopt, 'value' => $_REQUEST['value']);
                        $display = $function($params);
                    }
                }
                // Standard field usage
                if (!$display) {
                    switch ($searchopt['field']) {
                        case "name":
                        case "completename":
                            Dropdown::show(getItemTypeForTable($searchopt['table']), array('value' => $_REQUEST['value'], 'name' => $inputname, 'comments' => 0));
                            $display = true;
                            break;
                    }
                }
            }
            break;
            //case "lessthan" :
    }
    // Default case : text field
    if (!$display) {
        echo "<input type='text' size='13' name='{$inputname}' value=\"" . cleanInputText($_REQUEST['value']) . "\">";
    }
}
    if (!is_array($val)) {
        if (!empty($newgroup) && $items_in_group > 0) {
            echo $newgroup;
            $first_group = false;
        }
        $items_in_group = 0;
        $newgroup = "";
        if (!$first_group) {
            $newgroup .= "</optgroup>";
        }
        $newgroup .= "<optgroup label=\"{$val}\">";
    } else {
        // No search on plugins
        echo $key . "--";
        if (!isPluginItemType($key) && !isset($val["nometa"])) {
            $newgroup .= "<option value='{$key}' title=\"" . cleanInputText($val["name"]) . "\"";
            if ($key == $_POST["field"]) {
                $newgroup .= "selected";
            }
            $newgroup .= ">" . utf8_substr($val["name"], 0, 20) . "</option>\n";
            $items_in_group++;
        }
    }
}
if (!empty($newgroup) && $items_in_group > 0) {
    echo $newgroup;
}
if (!$first_group) {
    echo "</optgroup>";
}
echo "</select>";
示例#9
0
// Make a select box with preselected values
if (!isset($_POST["limit"])) {
    $_POST["limit"] = $_SESSION["glpidropdown_chars_limit"];
}
$NBMAX = $CFG_GLPI["dropdown_max"];
$LIMIT = "LIMIT 0,{$NBMAX}";
$sql = "SELECT `id`, `name`, `ranking`\n        FROM `glpi_rules`\n        WHERE `sub_type` = '" . $_POST["type"] . "'";
if ($_POST['searchText'] == $CFG_GLPI["ajax_wildcard"]) {
    $LIMIT = "";
} else {
    $sql .= " AND `name` " . makeTextSearch($_POST['searchText']);
}
if (isset($_POST['entity_restrict']) && $_POST['entity_restrict'] != '') {
    $sql .= " AND `glpi_rules`.`entities_id` = '" . $_POST['entity_restrict'] . "'";
}
$sql .= " ORDER BY `ranking` ASC " . $LIMIT;
$result = $DB->query($sql);
echo "<select id='dropdown_" . $_POST["myname"] . $_POST["rand"] . "' name='" . $_POST['myname'] . "' size='1'>";
if ($_POST['searchText'] != $CFG_GLPI["ajax_wildcard"] && $DB->numrows($result) == $NBMAX) {
    echo "<option value='0'>--" . $LANG['common'][11] . "--</option>";
} else {
    echo "<option value='0'>" . DROPDOWN_EMPTY_VALUE . "</option>";
}
if ($DB->numrows($result)) {
    while ($data = $DB->fetch_array($result)) {
        $ID = $data['id'];
        $name = $data['name'];
        echo "<option value='{$ID}' title=\"" . cleanInputText($name) . "\">" . utf8_substr($name, 0, $_POST["limit"]) . "</option>";
    }
}
echo "</select>";
                    }
                }
                $ID = $data['id'];
                $addcomment = "";
                if (isset($data["comment"])) {
                    $addcomment = " - " . $data["comment"];
                }
                if ($_SESSION["glpiis_ids_visible"] || strlen($output) == 0) {
                    $output .= " ({$ID})";
                }
                if ($multi && $data["entities_id"] != $prev) {
                    if ($prev >= 0) {
                        echo "</optgroup>";
                    }
                    $prev = $data["entities_id"];
                    echo "<optgroup label=\"" . Dropdown::getDropdownName("glpi_entities", $prev) . "\">";
                }
                echo "<option value='{$ID}' title=\"" . cleanInputText($output . $addcomment) . "\">" . utf8_substr($output, 0, $_POST["limit"]) . "</option>";
            }
            if ($multi) {
                echo "</optgroup>";
            }
        }
        echo "</select>";
    }
}
if (isset($_POST["comment"]) && $_POST["comment"]) {
    $paramscomment = array('value' => '__VALUE__', 'table' => $table);
    ajaxUpdateItemOnSelectEvent("dropdown_" . $_POST["myname"] . $_POST["rand"], "comment_" . $_POST["myname"] . $_POST["rand"], $CFG_GLPI["root_doc"] . "/ajax/comments.php", $paramscomment, false);
}
commonDropdownUpdateItem($_POST);
echo "<select id='dropdown_" . $_POST["myname"] . $_POST["rand"] . "' name='" . $_POST['myname'] . "' size='1'>";
if ($_POST['searchText'] != $CFG_GLPI["ajax_wildcard"] && $DB->numrows($result) == $NBMAX) {
    echo "<option value='0'>--" . $LANG['common'][11] . "--</option>";
} else {
    echo "<option value='0'>" . DROPDOWN_EMPTY_VALUE . "</option>";
}
$output = Dropdown::getDropdownName('glpi_netpoints', $_POST['value']);
if (!empty($output) && $output != "&nbsp;") {
    echo "<option selected value='" . $_POST['value'] . "'>" . $output . "</option>";
}
if ($DB->numrows($result)) {
    while ($data = $DB->fetch_array($result)) {
        $output = $data['netpname'];
        $loc = $data['loc'];
        $ID = $data['id'];
        $addcomment = "";
        if (isset($data["comment"])) {
            $addcomment = " - " . $loc . " - " . $data["comment"];
        }
        if (!$location_restrict) {
            $output .= " ({$loc})";
        }
        echo "<option value='{$ID}' title=\"" . cleanInputText($output . $addcomment) . "\"";
        echo ">" . $output . "</option>";
    }
}
echo "</select>\n";
if (isset($_POST["comment"]) && $_POST["comment"]) {
    $paramscomment = array('value' => '__VALUE__', 'table' => "glpi_netpoints");
    ajaxUpdateItemOnSelectEvent("dropdown_" . $_POST["myname"] . $_POST["rand"], "comment_" . $_POST["myname"] . $_POST["rand"], $CFG_GLPI["root_doc"] . "/ajax/comments.php", $paramscomment, false);
}
示例#12
0
echo ">";
if ($_POST['searchText'] != $CFG_GLPI["ajax_wildcard"] && $DB->numrows($result) == $CFG_GLPI["dropdown_max"]) {
    echo "<option value='0'>--" . $LANG['common'][11] . "--</option>";
}
if ($_POST['all'] == 0) {
    echo "<option value='0'>" . DROPDOWN_EMPTY_VALUE . "</option>";
} else {
    if ($_POST['all'] == 1) {
        echo "<option value='0'>[" . $LANG['common'][66] . "]</option>";
    }
}
if (isset($_POST['value'])) {
    $output = getUserName($_POST['value']);
    if (!empty($output) && $output != "&nbsp;") {
        echo "<option selected value='" . $_POST['value'] . "'>" . $output . "</option>";
    }
}
if (count($users)) {
    foreach ($users as $ID => $output) {
        echo "<option value='{$ID}' title=\"" . cleanInputText($output . " - " . $logins[$ID]) . "\">" . utf8_substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>";
    }
}
echo "</select>";
if (isset($_POST["comment"]) && $_POST["comment"]) {
    $paramscomment = array('value' => '__VALUE__', 'table' => "glpi_users");
    if (isset($_POST['update_link'])) {
        $paramscomment['withlink'] = "comment_link_" . $_POST["myname"] . $_POST["rand"];
    }
    ajaxUpdateItemOnSelectEvent("dropdown_" . $_POST["myname"] . $_POST["rand"], "comment_" . $_POST["myname"] . $_POST["rand"], $CFG_GLPI["root_doc"] . "/ajax/comments.php", $paramscomment, false);
}
commonDropdownUpdateItem($_POST);
 /**
  * Print out an HTML "<form>" for Search knowbase item
  *
  * @param $options : $_GET
  * @param $faq display on faq ?
  *
  * @return nothing (display the form)
  **/
 static function searchForm($options, $faq = 0)
 {
     global $LANG, $CFG_GLPI;
     if (!$CFG_GLPI["use_public_faq"] && !haveRight("knowbase", "r") && !haveRight("faq", "r")) {
         return false;
     }
     // Default values of parameters
     $params["knowbaseitemcategories_id"] = "0";
     $params["contains"] = "";
     $params["target"] = $_SERVER['PHP_SELF'];
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     echo "<div><table class='center-h'><tr><td>";
     echo "<form method=get action='" . $params["target"] . "'><table border='0' class='tab_cadre'>";
     echo "<tr><th colspan='2'>" . $LANG['search'][0] . "&nbsp;:</th></tr>";
     echo "<tr class='tab_bg_2 center'><td>";
     echo "<input type='text' size='30' name='contains' value=\"" . stripslashes(cleanInputText($params["contains"])) . "\"></td>";
     echo "<td><input type='submit' value=\"" . $LANG['buttons'][0] . "\" class='submit'></td></tr>";
     echo "</table>";
     if (isset($options['tickets_id'])) {
         echo "<input type='hidden' name='tickets_id' value='" . $options['tickets_id'] . "'>";
     }
     echo "</form>";
     echo "</td>";
     // Category select not for anonymous FAQ
     if (getLoginUserID() && !$faq && !isset($options['tickets_id'])) {
         echo "<td><form method=get action='" . $params["target"] . "'>";
         echo "<table border='0' class='tab_cadre'>";
         echo "<tr><th colspan='2'>" . $LANG['buttons'][43] . "&nbsp;:</th></tr>";
         echo "<tr class='tab_bg_2'><td class='center'>" . $LANG['common'][36] . "&nbsp;:&nbsp;";
         Dropdown::show('KnowbaseItemCategory', array('value' => '$params["knowbaseitemcategories_id)"]'));
         echo "</td><td><input type='submit' value=\"" . $LANG['buttons'][2] . "\" class='submit'></td>";
         echo "</tr></table></form></td>";
     }
     echo "</tr></table></div>";
 }