the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

Certificates 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 Certificates. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
if (strpos($_SERVER['PHP_SELF'], "dropdownTypeCertificates.php")) {
    $AJAX_INCLUDE = 1;
    include '../../../inc/includes.php';
    header("Content-Type: text/html; charset=UTF-8");
    Html::header_nocache();
}
Session::checkCentralAccess();
// Make a select box
if (isset($_POST["plugin_certificates_certificatetypes_id"])) {
    $rand = $_POST['rand'];
    $use_ajax = false;
    $restrict = "glpi_plugin_certificates_certificates.plugin_certificates_certificatetypes_id='" . $_POST["plugin_certificates_certificatetypes_id"] . "' " . getEntitiesRestrictRequest("AND", "glpi_plugin_certificates_certificates", "", $_POST["entity_restrict"], true);
    if ($CFG_GLPI["use_ajax"] && countElementsInTable('glpi_plugin_certificates_certificates', $restrict) > $CFG_GLPI["ajax_limit_count"]) {
        $use_ajax = true;
    }
    $params = array('searchText' => '__VALUE__', 'plugin_certificates_certificatetypes_id' => $_POST["plugin_certificates_certificatetypes_id"], 'entity_restrict' => $_POST["entity_restrict"], 'rand' => $_POST['rand'], 'myname' => $_POST['myname'], 'used' => $_POST['used']);
    $default = "<select name='" . $_POST["myname"] . "'><option value='0'>" . Dropdown::EMPTY_VALUE . "</option></select>";
    Ajax::dropdown($use_ajax, "/plugins/certificates/ajax/dropdownCertificates.php", $params, $default, $rand);
}
 /**
  * Print out an HTML "<select>" for a dropdown with preselected value
  *
  * @param $myname             the name of the HTML select
  * @param $value              the preselected value we want (default 0)
  * @param $locations_id       default location ID for search (default -1)
  * @param $display_comment    display the comment near the dropdown (default 1)
  * @param $entity_restrict    Restrict to a defined entity(default -1)
  * @param $devtype            (default '')
  *
  * @return nothing (display the select box)
  **/
 static function dropdownNetpoint($myname, $value = 0, $locations_id = -1, $display_comment = 1, $entity_restrict = -1, $devtype = '')
 {
     global $CFG_GLPI;
     $rand = mt_rand();
     $name = Dropdown::EMPTY_VALUE;
     $comment = "";
     $limit_length = $_SESSION["glpidropdown_chars_limit"];
     if (empty($value)) {
         $value = 0;
     }
     if ($value > 0) {
         $tmpname = Dropdown::getDropdownName("glpi_netpoints", $value, 1);
         if ($tmpname["name"] != "&nbsp;") {
             $name = $tmpname["name"];
             $comment = $tmpname["comment"];
             $limit_length = max(Toolbox::strlen($name), $_SESSION["glpidropdown_chars_limit"]);
         }
     }
     $use_ajax = false;
     if ($CFG_GLPI["use_ajax"]) {
         if ($locations_id < 0 || $devtype == 'NetworkEquipment') {
             $nb = countElementsInTableForEntity("glpi_netpoints", $entity_restrict);
         } else {
             if ($locations_id > 0) {
                 $nb = countElementsInTable("glpi_netpoints", "locations_id={$locations_id} ");
             } else {
                 $nb = countElementsInTable("glpi_netpoints", "locations_id=0 " . getEntitiesRestrictRequest(" AND ", "glpi_netpoints", '', $entity_restrict));
             }
         }
         if ($nb > $CFG_GLPI["ajax_limit_count"]) {
             $use_ajax = true;
         }
     }
     $params = array('searchText' => '__VALUE__', 'value' => $value, 'locations_id' => $locations_id, 'myname' => $myname, 'limit' => $limit_length, 'comment' => $display_comment, 'rand' => $rand, 'entity_restrict' => $entity_restrict, 'devtype' => $devtype);
     $default = "<select name='{$myname}'><option value='{$value}'>{$name}</option></select>";
     Ajax::dropdown($use_ajax, "/ajax/dropdownNetpoint.php", $params, $default, $rand);
     // Display comment
     if ($display_comment) {
         Html::showToolTip($comment);
         $item = new self();
         if ($item->canCreate()) {
             echo "<img alt='' title=\"" . __s('Add') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png' style='cursor:pointer; margin-left:2px;' " . "onClick=\"var w = window.open('" . $item->getFormURL() . "?popup=1&amp;rand={$rand}' ,'glpipopup', 'height=400, " . "width=1000, top=100, left=100, scrollbars=yes' );w.focus();\">";
         }
     }
     return $rand;
 }
Webapplications 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.

Webapplications 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 Webapplications. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
if (strpos($_SERVER['PHP_SELF'], "dropdownTypeWebApplications.php")) {
    include '../../../inc/includes.php';
    header("Content-Type: text/html; charset=UTF-8");
    Html::header_nocache();
}
Session::checkCentralAccess();
// Make a select box with type selecting
if (isset($_POST["plugin_webapplications_webapplicationtypes_id"])) {
    $rand = $_POST['rand'];
    $use_ajax = false;
    if ($CFG_GLPI["use_ajax"] && countElementsInTable('glpi_plugin_webapplications_webapplications', "glpi_plugin_webapplications_webapplications.plugin_webapplications_webapplicationtypes_id='" . $_POST["plugin_webapplications_webapplicationtypes_id"] . "' " . getEntitiesRestrictRequest("AND", "glpi_plugin_webapplications_webapplications", "", $_POST["entity_restrict"], true)) > $CFG_GLPI["ajax_limit_count"]) {
        $use_ajax = true;
    }
    $params = array('searchText' => '__VALUE__', 'plugin_webapplications_webapplicationtypes_id' => $_POST["plugin_webapplications_webapplicationtypes_id"], 'entity_restrict' => $_POST["entity_restrict"], 'rand' => $_POST['rand'], 'myname' => $_POST['myname'], 'used' => $_POST['used']);
    $default = "<select name='" . $_POST["myname"] . "'><option value='0'>" . Dropdown::EMPTY_VALUE . "</option></select>";
    Ajax::dropdown($use_ajax, "/plugins/webapplications/ajax/dropdownWebApplications.php", $params, $default, $rand);
}
    $link = "dropdownCommandValue.php";
    // Link to user for search only > normal users
    $use_ajax = false;
    if (isset($_POST["countItem"])) {
        // Display an search input if too items in select
        $item = getItemForItemtype($_POST['idtable']);
        $item->getFromDB($_POST['itemID']);
        $tabValue = explode('-', $_POST['value']);
        if (sizeof($tabValue) == 2) {
            if (stristr($tabValue[0], 'mac') || stristr($tabValue[0], 'ip')) {
                if ($CFG_GLPI["use_ajax"] && PluginShellcommandsShellcommand_Item::countForItem($item, array('type' => $tabValue[0], 'itemId' => $tabValue[1])) > $CFG_GLPI["ajax_limit_count"]) {
                    $use_ajax = true;
                }
                echo '</br>' . __('Network port') . ' ';
            }
        }
    }
    $rand = mt_rand();
    $paramsallitems = array('searchText' => '__VALUE__', 'itemtype' => $_POST["itemtype"], 'itemID' => $_POST["itemID"], 'value' => $_POST["value"], 'rand' => $rand, 'myname' => $_POST["myname"], 'displaywith' => array('otherserial', 'serial'), 'display_emptychoice' => false);
    if (isset($_POST['idtable'])) {
        $paramsallitems['idtable'] = $_POST['idtable'];
    }
    if (isset($_POST['entity_restrict'])) {
        $paramsallitems['entity_restrict'] = $_POST['entity_restrict'];
    }
    if (isset($_POST['condition'])) {
        $paramsallitems['condition'] = stripslashes($_POST['condition']);
    }
    $default = "<select name='" . $_POST["myname"] . "'><option value='0'>" . Dropdown::EMPTY_VALUE . "</option></select>";
    Ajax::dropdown($use_ajax, "/plugins/shellcommands/ajax/{$link}", $paramsallitems, $default, $rand);
}
Exemple #5
0
 /**
  * Dropdown rules for a defined sub_type of rule
  *
  * @param $options   array of possible options:
  *    - name : string / name of the select (default is depending itemtype)
  *    - sub_type : integer / sub_type of rule
  **/
 static function dropdown($options = array())
 {
     global $DB, $CFG_GLPI;
     $p['sub_type'] = '';
     $p['name'] = 'rules_id';
     $p['entity_restrict'] = '';
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $p[$key] = $val;
         }
     }
     if ($p['sub_type'] == '') {
         return false;
     }
     $rand = mt_rand();
     $limit_length = $_SESSION["glpidropdown_chars_limit"];
     $use_ajax = false;
     if ($CFG_GLPI["use_ajax"]) {
         $nb = countElementsInTable("glpi_rules", "`sub_type`='" . $p['sub_type'] . "'");
         if ($nb > $CFG_GLPI["ajax_limit_count"]) {
             $use_ajax = true;
         }
     }
     $params = array('searchText' => '__VALUE__', 'myname' => $p['name'], 'limit' => $limit_length, 'rand' => $rand, 'type' => $p['sub_type'], 'entity_restrict' => $p['entity_restrict']);
     $default = "<select name='" . $p['name'] . "' id='dropdown_" . $p['name'] . $rand . "'>";
     $default .= "<option value='0'>" . Dropdown::EMPTY_VALUE . "</option></select>";
     Ajax::dropdown($use_ajax, "/ajax/dropdownRules.php", $params, $default, $rand);
     return $rand;
 }
 /**
  * Permet l'affichage dynamique d'une liste déroulante imbriquee
  *
  * @static
  * @param array ($itemtype,$myname,$value,$entity_restrict,$action,$span)
  */
 static function showGenericDropdown($itemtype, $options = array())
 {
     global $DB, $CFG_GLPI;
     $item = getItemForItemtype($itemtype);
     if ($itemtype && !($item = getItemForItemtype($itemtype))) {
         return false;
     }
     $table = $item->getTable();
     /*$options["table"] = $table;
       $options["rand"] = $rand;
       
       $params['name']        = $item->getForeignKeyField();
       $params['value']       = ($itemtype=='Entity' ? $_SESSION['glpiactive_entity'] : '');
       
       $params['entity']      = -1;
       $params['entity_sons'] = false;
       $params['toupdate']    = '';
       $params['used']        = array();
       $params['toadd']       = array();
       $params['on_change']   = '';
       $params['condition']   = '';
       $params['rand']        = mt_rand();
       $params['displaywith'] = array();
       //Parameters about choice 0
       //Empty choice's label
       $params['emptylabel'] = self::EMPTY_VALUE;*/
     $params['comments'] = true;
     $params['condition'] = '';
     $params['entity'] = -1;
     $params['entity_sons'] = false;
     $params['rand'] = mt_rand();
     $params['used'] = array();
     $params['table'] = $table;
     $params['emptylabel'] = Dropdown::EMPTY_VALUE;
     //Display emptychoice ?
     $params['display_emptychoice'] = true;
     //In case of Entity dropdown, display root entity ?
     $params['display_rootentity'] = false;
     //specific
     $params['action'] = "";
     $params['span'] = "";
     $params['sort'] = false;
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     $name = $params['emptylabel'];
     $comment = "";
     $limit_length = $_SESSION["glpidropdown_chars_limit"];
     if (strlen($params['value']) == 0 || !is_numeric($params['value'])) {
         $params['value'] = 0;
     }
     if ($params['value'] > 0) {
         $tmpname = Dropdown::getDropdownName($table, $params['value'], 1);
         if ($tmpname["name"] != "&nbsp;") {
             $name = $tmpname["name"];
             $comment = $tmpname["comment"];
             if (Toolbox::strlen($name) > $_SESSION["glpidropdown_chars_limit"]) {
                 if ($item instanceof CommonTreeDropdown) {
                     $pos = strrpos($name, ">");
                     $limit_length = max(Toolbox::strlen($name) - $pos, $_SESSION["glpidropdown_chars_limit"]);
                     if (Toolbox::strlen($name) > $limit_length) {
                         $name = "&hellip;" . Toolbox::substr($name, -$limit_length);
                     }
                 } else {
                     $limit_length = Toolbox::strlen($name);
                 }
             } else {
                 $limit_length = $_SESSION["glpidropdown_chars_limit"];
             }
         }
     }
     // Manage entity_sons
     if (!($params['entity'] < 0) && $params['entity_sons']) {
         if (is_array($params['entity'])) {
             echo "entity_sons options is not available with array of entity";
         } else {
             $params['entity'] = getSonsOf('glpi_entities', $params['entity']);
         }
     }
     $use_ajax = false;
     if ($CFG_GLPI["use_ajax"]) {
         $nb = 0;
         if ($item->isEntityAssign()) {
             if (!($params['entity'] < 0)) {
                 $nb = countElementsInTableForEntity($table, $params['entity'], $params['condition']);
             } else {
                 $nb = countElementsInTableForMyEntities($table, $params['condition']);
             }
         } else {
             $nb = countElementsInTable($table, $params['condition']);
         }
         $nb -= count($params['used']);
         if ($nb > $CFG_GLPI["ajax_limit_count"]) {
             $use_ajax = true;
         }
     }
     $param = array('searchText' => '__VALUE__', 'value' => $params['value'], 'itemtype' => $itemtype, 'myname' => $params['name'], 'limit' => $limit_length, 'comment' => $params['comments'], 'rand' => $params['rand'], 'entity_restrict' => $params['entity'], 'used' => $params['used'], 'condition' => $params['condition'], 'emptylabel' => $params['emptylabel'], 'display_emptychoice' => $params['display_emptychoice'], 'display_rootentity' => $params['display_rootentity'], 'action' => $params['action'], 'span' => $params['span'], 'sort' => $params['sort']);
     $default = "<select name='" . $params['name'] . "' id='dropdown_" . $params['name'] . $params['rand'] . "'>";
     $default .= "<option value='" . $params['value'] . "'>{$name}</option></select>";
     Ajax::dropdown($use_ajax, "/plugins/resources/ajax/dropdownValue.php", $param, $default, $params['rand']);
     // Display comment
     if ($params['comments']) {
         $options_tooltip = array('contentid' => "comment_" . $param['myname'] . $params['rand']);
         if ($params['value'] && $item->getFromDB($params['value'])) {
             $options_tooltip['link'] = $item->getLinkURL();
             $options_tooltip['linktarget'] = '_blank';
         }
         Html::showToolTip($comment, $options_tooltip);
         if ($item instanceof CommonDropdown && $item->canCreate() && !isset($_GET['popup'])) {
             echo "<img alt='' title=\"" . _sx('button', 'Add') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png' style='cursor:pointer; margin-left:2px;'\n                     onClick=\"var w = window.open('" . $item->getFormURL() . "?popup=1&amp;rand=" . $params['rand'] . "' ,'glpipopup', 'height=400, " . "width=1000, top=100, left=100, scrollbars=yes' );w.focus();\">";
         }
     }
     return $params['rand'];
 }
include "../../../inc/includes.php";
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
// Make a select box
if (isset($_POST["typetable"])) {
    $test = explode(";", $_POST['typetable']);
    $itemtype = $test[0];
    $table = $test[1];
    // Link to user for search only > normal users
    $rand = mt_rand();
    $use_ajax = false;
    if ($CFG_GLPI["use_ajax"] && countElementsInTable($table) > $CFG_GLPI["ajax_limit_count"]) {
        $use_ajax = true;
    }
    $params = array('searchText' => '__VALUE__', 'itemtype' => $itemtype, 'table' => $table, 'rand' => $rand, 'myname' => $_POST["myname"]);
    if (isset($_POST['value'])) {
        $params['value'] = $_POST['value'];
    }
    if (isset($_POST['entity_restrict'])) {
        $params['entity_restrict'] = $_POST['entity_restrict'];
    }
    $default = "<select name='" . $_POST["myname"] . "'><option value='0'>" . Dropdown::EMPTY_VALUE . "</option></select>";
    Ajax::dropdown($use_ajax, "/plugins/archires/ajax/dropdownValue.php", $params, $default, $rand);
    if (isset($_POST['value']) && $_POST['value'] > 0) {
        $params['searchText'] = $CFG_GLPI["ajax_wildcard"];
        echo "<script type='text/javascript' >\n";
        echo "document.getElementById('search_{$rand}').value='" . $CFG_GLPI["ajax_wildcard"] . "';";
        echo "</script>\n";
        Ajax::pdateItem("results_{$rand}", $CFG_GLPI["root_doc"] . "/plugins/archires/ajax/dropdownValue.php", $params);
    }
}
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, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
 * @since version 0.84
* @brief
*/
include '../inc/includes.php';
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkRight("networking", "w");
// Make a select box
if (class_exists($_POST["itemtype"])) {
    $table = getTableForItemType($_POST["itemtype"]);
    $rand = mt_rand();
    $use_ajax = true;
    $paramsconnectpdt = array('searchText' => '__VALUE__', 'itemtype' => $_POST['itemtype'], 'rand' => $rand, 'myname' => "items", 'entity_restrict' => $_POST["entity_restrict"], 'condition' => "(`id` in (SELECT `items_id`" . "FROM `glpi_networkports`" . "WHERE `itemtype` = '" . $_POST["itemtype"] . "'" . "AND `instantiation_type`" . "= '" . $_POST['instantiation_type'] . "'))", 'update_item' => array('value_fieldname' => 'item', 'to_update' => "results_item_{$rand}", 'url' => $CFG_GLPI["root_doc"] . "/ajax/dropdownConnectNetworkPort.php", 'moreparams' => array('networkports_id' => $_POST['networkports_id'], 'itemtype' => $_POST['itemtype'], 'myname' => $_POST['myname'], 'instantiation_type' => $_POST['instantiation_type'])));
    $default = "<select name='NetworkPortConnect_item'>" . "<option value='0'>" . Dropdown::EMPTY_VALUE . "</option>" . "</select>\n";
    Ajax::dropdown($use_ajax, "/ajax/dropdownValue.php", $paramsconnectpdt, $default, $rand);
    echo "<span id='results_item_{$rand}'>";
    echo "</span>\n";
}
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

Databases 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 Databases. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
if (strpos($_SERVER['PHP_SELF'], "dropdownTypeDatabases.php")) {
    $AJAX_INCLUDE = 1;
    include '../../../inc/includes.php';
    header("Content-Type: text/html; charset=UTF-8");
    Html::header_nocache();
}
Session::checkCentralAccess();
// Make a select box
if (isset($_POST["plugin_databases_databasetypes_id"])) {
    $rand = $_POST['rand'];
    $use_ajax = false;
    $restrict = "glpi_plugin_databases_databases.plugin_databases_databasetypes_id='" . $_POST["plugin_databases_databasetypes_id"] . "' " . getEntitiesRestrictRequest("AND", "glpi_plugin_databases_databases", "", $_POST["entity_restrict"], true);
    if ($CFG_GLPI["use_ajax"] && countElementsInTable('glpi_plugin_databases_databases', $restrict) > $CFG_GLPI["ajax_limit_count"]) {
        $use_ajax = true;
    }
    $params = array('searchText' => '__VALUE__', 'plugin_databases_databasetypes_id' => $_POST["plugin_databases_databasetypes_id"], 'entity_restrict' => $_POST["entity_restrict"], 'rand' => $_POST['rand'], 'myname' => $_POST['myname'], 'used' => $_POST['used']);
    $default = "<select name='" . $_POST["myname"] . "'><option value='0'>" . Dropdown::EMPTY_VALUE . "</option></select>";
    Ajax::dropdown($use_ajax, "/plugins/databases/ajax/dropdownDatabases.php", $params, $default, $rand);
}
 /**
  * Make a select box for connections
  *
  * @param $itemtype               type to connect
  * @param $fromtype               from where the connection is
  * @param $myname                 select name
  * @param $entity_restrict        Restrict to a defined entity (default = -1)
  * @param $onlyglobal             display only global devices (used for templates) (default 0)
  * @param $used             array Already used items ID: not to display in dropdown
  *
  * @return nothing (print out an HTML select box)
  */
 static function dropdownConnect($itemtype, $fromtype, $myname, $entity_restrict = -1, $onlyglobal = 0, $used = array())
 {
     global $CFG_GLPI;
     $rand = mt_rand();
     $use_ajax = false;
     if ($CFG_GLPI["use_ajax"]) {
         $nb = 0;
         if ($entity_restrict >= 0) {
             $nb = countElementsInTableForEntity(getTableForItemType($itemtype), $entity_restrict);
         } else {
             $nb = countElementsInTableForMyEntities(getTableForItemType($itemtype));
         }
         if ($nb > $CFG_GLPI["ajax_limit_count"]) {
             $use_ajax = true;
         }
     }
     $params = array('searchText' => '__VALUE__', 'fromtype' => $fromtype, 'itemtype' => $itemtype, 'myname' => $myname, 'onlyglobal' => $onlyglobal, 'entity_restrict' => $entity_restrict, 'used' => $used);
     $default = "<select name='{$myname}'><option value='0'>" . Dropdown::EMPTY_VALUE . "</option>\n                  </select>\n";
     Ajax::dropdown($use_ajax, "/ajax/dropdownConnect.php", $params, $default, $rand);
     return $rand;
 }
 /**
  * Make a select box for  software to install
  *
  * @param $options array of possible options:
  *    - name          : string / name of the select (default is softwareversions_id)
  *    - softwares_id  : integer / ID of the software
  *    - value         : integer / value of the selected version
  *    - used          : array / already used items
  *
  * @return nothing (print out an HTML select box)
  **/
 static function dropdown($options = array())
 {
     global $CFG_GLPI;
     //$softwares_id,$value=0
     $p['softwares_id'] = 0;
     $p['value'] = 0;
     $p['name'] = 'softwareversions_id';
     $p['used'] = array();
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $p[$key] = $val;
         }
     }
     $rand = mt_rand();
     $params = array('softwares_id' => $p['softwares_id'], 'myname' => $p['name'], 'value' => $p['value'], 'used' => $p['used']);
     $default = "<select name='" . $p['name'] . "'><option value='0'>" . Dropdown::EMPTY_VALUE . "</option>\n                  </select>";
     Ajax::dropdown(false, "/ajax/dropdownInstallVersion.php", $params, $default, $rand);
     return $rand;
 }
Exemple #12
0
function plugin_monitoring_searchOptionsValues($item)
{
    global $CFG_GLPI;
    if ($item['searchoption']['table'] == 'glpi_plugin_monitoring_services' and $item['searchoption']['field'] == 'state') {
        $input = array();
        $input['CRITICAL'] = 'CRITICAL';
        $input['DOWN'] = 'DOWN';
        $input['DOWNTIME'] = 'DOWNTIME';
        $input['FLAPPING'] = 'FLAPPING';
        $input['OK'] = 'OK';
        $input['RECOVERY'] = 'RECOVERY';
        $input['UNKNOWN'] = 'UNKNOWN';
        $input['UNREACHABLE'] = 'UNREACHABLE';
        $input['UP'] = 'UP';
        $input['WARNING'] = 'WARNING';
        Dropdown::showFromArray($item['name'], $input, array('value' => $item['value']));
        return true;
    } else {
        if ($item['searchoption']['table'] == 'glpi_plugin_monitoring_services' and $item['searchoption']['field'] == 'state_type') {
            $input = array();
            $input['HARD'] = 'HARD';
            $input['SOFT'] = 'SOFT';
            Dropdown::showFromArray($item['name'], $input, array('value' => $item['value']));
            return true;
        } else {
            if ($item['searchoption']['table'] == 'glpi_plugin_monitoring_services' and ($item['searchoption']['field'] == 'Computer' or $item['searchoption']['field'] == 'Printer' or $item['searchoption']['field'] == 'NetworkEquipment')) {
                $itemtype = $item['searchoption']['field'];
                $use_ajax = false;
                if ($CFG_GLPI["use_ajax"]) {
                    $nb = countElementsInTable("glpi_plugin_monitoring_componentscatalogs_hosts", "`itemtype`='Computer'");
                    if ($nb > $CFG_GLPI["ajax_limit_count"]) {
                        $use_ajax = true;
                    }
                }
                $params = array();
                $params['itemtype'] = $itemtype;
                $params['searchText'] = '';
                $params['myname'] = $item['name'];
                $params['rand'] = '';
                $params['value'] = $item['value'];
                $default = "<select name='" . $item['name'] . "' id='dropdown_" . $item['name'] . "0'>";
                if (isset($item['value']) and !empty($item['value'])) {
                    $itemm = new $itemtype();
                    $itemm->getFromDB($item['value']);
                    $default .= "<option value='" . $item['value'] . "'>" . $itemm->getName() . "</option></select>";
                }
                Ajax::dropdown($use_ajax, "/plugins/monitoring/ajax/dropdownDevices.php", $params, $default);
                return true;
            }
        }
    }
}
appliances 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.

appliances 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 appliances. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
if (strpos($_SERVER['PHP_SELF'], "dropdownTypeAppliances.php")) {
    include "../../../inc/includes.php";
    header("Content-Type: text/html; charset=UTF-8");
    Html::header_nocache();
}
Session::checkCentralAccess();
// Make a select box
if (isset($_POST["type_appliances"])) {
    $rand = $_POST['rand'];
    $use_ajax = false;
    if ($CFG_GLPI["use_ajax"] && countElementsInTable('glpi_plugin_appliances_appliances', "plugin_appliances_appliancetypes_id ='" . $_POST["type_appliances"] . "' " . getEntitiesRestrictRequest(" AND", "glpi_plugin_appliances_appliances", "", $_POST["entity_restrict"], true)) > $CFG_GLPI["ajax_limit_count"]) {
        $use_ajax = true;
    }
    $params = array('searchText' => ' __VALUE__', 'type_appliances' => $_POST["type_appliances"], 'entity_restrict' => $_POST["entity_restrict"], 'rand' => $_POST['rand'], 'myname' => $_POST['myname'], 'used' => $_POST['used']);
    $default = "<select name='" . $_POST["myname"] . "'>\n               <option value='0'>" . Dropdown::EMPTY_VALUE . "</option></select>";
    Ajax::dropdown($use_ajax, "/plugins/appliances/ajax/dropdownappliances.php", $params, $default, $rand);
}
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.

accounts 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 accounts. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
if (strpos($_SERVER['PHP_SELF'], "dropdownTypeAccounts.php")) {
    include '../../../inc/includes.php';
    header("Content-Type: text/html; charset=UTF-8");
    Html::header_nocache();
}
Session::checkCentralAccess();
// Make a select box
if (isset($_POST["plugin_accounts_accounttypes_id"])) {
    $rand = $_POST['rand'];
    $use_ajax = false;
    $restrict = "plugin_accounts_accounttypes_id='" . $_POST["plugin_accounts_accounttypes_id"] . "'\n            " . getEntitiesRestrictRequest("AND", "glpi_plugin_accounts_accounts", "", $_POST["entity_restrict"], true);
    if ($CFG_GLPI["use_ajax"] && countElementsInTable('glpi_plugin_accounts_accounts', $restrict) > $CFG_GLPI["ajax_limit_count"]) {
        $use_ajax = true;
    }
    $params = array('searchText' => '__VALUE__', 'plugin_accounts_accounttypes_id' => $_POST["plugin_accounts_accounttypes_id"], 'entity_restrict' => $_POST["entity_restrict"], 'rand' => $_POST['rand'], 'myname' => $_POST['myname'], 'used' => $_POST['used']);
    $default = "<select name='" . $_POST["myname"] . "'><option value='0'>" . Dropdown::EMPTY_VALUE . "</option></select>";
    Ajax::dropdown($use_ajax, "/plugins/accounts/ajax/dropdownAccounts.php", $params, $default, $rand);
}
Exemple #15
0
 /**
  * Make a select box for license software to associate
  *
  * @param $myname          select name
  * @param $entity_restrict restrict to a defined entity
  * @param $massiveaction   is it a massiveaction select ? (default 0)
  *
  * @return nothing (print out an HTML select box)
  **/
 static function dropdownLicenseToInstall($myname, $entity_restrict, $massiveaction = 0)
 {
     global $CFG_GLPI;
     $rand = mt_rand();
     $use_ajax = false;
     if ($CFG_GLPI["use_ajax"]) {
         if (countElementsInTableForEntity("glpi_softwarelicenses", $entity_restrict) > $CFG_GLPI["ajax_limit_count"]) {
             $use_ajax = true;
         }
     }
     $params = array('searchText' => '__VALUE__', 'myname' => $myname, 'entity_restrict' => $entity_restrict);
     $default = "<select name='{$myname}'><option value='0'>" . Dropdown::EMPTY_VALUE . " </option>\n                  </select>";
     Ajax::dropdown($use_ajax, "/ajax/dropdownSelectSoftwareLicense.php", $params, $default, $rand);
     return $rand;
 }
Exemple #16
0
 /**
  * Print out an HTML "<select>" for a dropdown with preselected value
  *
  * @param $itemtype        itemtype used for create dropdown
  * @param $options   array of possible options:
  *    - name                : string / name of the select (default is depending itemtype)
  *    - value               : integer / preselected value (default -1)
  *    - comments            : boolean / is the comments displayed near the dropdown (default true)
  *    - toadd               : array / array of specific values to add at the begining
  *    - entity              : integer or array / restrict to a defined entity or array of entities
  *                                               (default -1 : no restriction)
  *    - entity_sons         : boolean / if entity restrict specified auto select its sons
  *                                      only available if entity is a single value not an array
  *                                      (default false)
  *    - toupdate            : array / Update a specific item on select change on dropdown
  *                                    (need value_fieldname, to_update,
  *                                     url (see Ajax::updateItemOnSelectEvent for information)
  *                                     and may have moreparams)
  *    - used                : array / Already used items ID: not to display in dropdown
  *                                    (default empty)
  *    - on_change           : string / value to transmit to "onChange"
  *    - rand                : integer / already computed rand value
  *    - condition           : string / aditional SQL condition to limit display
  *    - displaywith         : array / array of field to display with request
  *    - emptylabel          : Empty choice's label (default self::EMPTY_VALUE)
  *    - display_emptychoice : Display emptychoice ? (default true)
  *    - display             : boolean / display or get string (default true)
  *    - permit_select_parent : boolean / for tree dropdown permit to see parent items not available by default (default false)
  *
  * @return boolean : false if error and random id if OK
  **/
 static function show($itemtype, $options = array())
 {
     global $DB, $CFG_GLPI;
     if ($itemtype && !($item = getItemForItemtype($itemtype))) {
         return false;
     }
     $table = $item->getTable();
     $params['name'] = $item->getForeignKeyField();
     $params['value'] = $itemtype == 'Entity' ? $_SESSION['glpiactive_entity'] : '';
     $params['comments'] = true;
     $params['entity'] = -1;
     $params['entity_sons'] = false;
     $params['toupdate'] = '';
     $params['used'] = array();
     $params['toadd'] = array();
     $params['on_change'] = '';
     $params['condition'] = '';
     $params['rand'] = mt_rand();
     $params['displaywith'] = array();
     //Parameters about choice 0
     //Empty choice's label
     $params['emptylabel'] = self::EMPTY_VALUE;
     //Display emptychoice ?
     $params['display_emptychoice'] = $itemtype != 'Entity';
     $params['display'] = true;
     $params['permit_select_parent'] = false;
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     $output = '';
     $name = $params['emptylabel'];
     $comment = "";
     $limit_length = $_SESSION["glpidropdown_chars_limit"];
     // Check default value for dropdown : need to be a numeric
     if (strlen($params['value']) == 0 || !is_numeric($params['value'])) {
         $params['value'] = 0;
     }
     if ($params['value'] > 0 || $itemtype == "Entity" && $params['value'] >= 0) {
         $tmpname = self::getDropdownName($table, $params['value'], 1);
         if ($tmpname["name"] != "&nbsp;") {
             $name = $tmpname["name"];
             $comment = $tmpname["comment"];
             if (Toolbox::strlen($name) > $_SESSION["glpidropdown_chars_limit"]) {
                 if ($item instanceof CommonTreeDropdown) {
                     $pos = strrpos($name, ">");
                     $limit_length = max(Toolbox::strlen($name) - $pos, $_SESSION["glpidropdown_chars_limit"]);
                     if (Toolbox::strlen($name) > $limit_length) {
                         $name = "&hellip;" . Toolbox::substr($name, -$limit_length);
                     }
                 } else {
                     $limit_length = Toolbox::strlen($name);
                 }
             } else {
                 $limit_length = $_SESSION["glpidropdown_chars_limit"];
             }
         }
     }
     // Manage entity_sons
     if (!($params['entity'] < 0) && $params['entity_sons']) {
         if (is_array($params['entity'])) {
             // translation not needed - only for debug
             $output .= "entity_sons options is not available with entity option as array";
         } else {
             $params['entity'] = getSonsOf('glpi_entities', $params['entity']);
         }
     }
     $use_ajax = false;
     if ($CFG_GLPI["use_ajax"]) {
         $nb = 0;
         if ($item->isEntityAssign()) {
             if (!($params['entity'] < 0)) {
                 $nb = countElementsInTableForEntity($table, $params['entity'], $params['condition']);
             } else {
                 $nb = countElementsInTableForMyEntities($table, $params['condition']);
             }
         } else {
             $nb = countElementsInTable($table, $params['condition']);
         }
         $nb -= count($params['used']);
         if ($nb > $CFG_GLPI["ajax_limit_count"]) {
             $use_ajax = true;
         }
     }
     $param = array('searchText' => '__VALUE__', 'value' => $params['value'], 'itemtype' => $itemtype, 'myname' => $params['name'], 'limit' => $limit_length, 'toadd' => $params['toadd'], 'comment' => $params['comments'], 'rand' => $params['rand'], 'entity_restrict' => $params['entity'], 'update_item' => $params['toupdate'], 'used' => $params['used'], 'on_change' => $params['on_change'], 'condition' => $params['condition'], 'emptylabel' => $params['emptylabel'], 'display_emptychoice' => $params['display_emptychoice'], 'displaywith' => $params['displaywith'], 'display' => false, 'permit_select_parent' => $params['permit_select_parent']);
     if ($item->canView()) {
         $param['update_link'] = 1;
     }
     $default = "<select name='" . $params['name'] . "' id='dropdown_" . $params['name'] . $params['rand'] . "'>";
     $default .= "<option value='" . $params['value'] . "'>{$name}</option></select>";
     $output .= Ajax::dropdown($use_ajax, "/ajax/dropdownValue.php", $param, $default, $params['rand'], false);
     // Display comment
     if ($params['comments']) {
         $options_tooltip = array('contentid' => "comment_" . $params['name'] . $params['rand'], 'display' => false);
         if ($item->canView()) {
             if ($params['value'] && $item->getFromDB($params['value']) && $item->canViewItem()) {
                 $options_tooltip['link'] = $item->getLinkURL();
             } else {
                 $options_tooltip['link'] = $item->getSearchURL();
             }
             $options_tooltip['linkid'] = "comment_link_" . $params['name'] . $params['rand'];
             $options_tooltip['linktarget'] = '_blank';
         }
         $output .= Html::showToolTip($comment, $options_tooltip);
         if ($item instanceof CommonDropdown && $item->canCreate() && !isset($_GET['popup'])) {
             $output .= "<img alt='' title=\"" . __s('Add') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png' style='cursor:pointer; margin-left:2px;'\n                            onClick=\"var w = window.open('" . $item->getFormURL() . "?popup=1&amp;rand=" . $params['rand'] . "' ,'glpipopup', 'height=400, " . "width=1000, top=100, left=100, scrollbars=yes' );w.focus();\">";
         }
         // Display specific Links
         if ($itemtype == "Supplier") {
             if ($item->getFromDB($params['value'])) {
                 $output .= $item->getLinks();
             }
         }
         if ($itemtype == 'ITILCategory' && Session::haveRight('knowbase', 'r')) {
             if ($params['value'] && $item->getFromDB($params['value'])) {
                 $output .= '&nbsp;' . $item->getLinks();
             }
         }
     }
     if ($params['display']) {
         echo $output;
         return $params['rand'];
     } else {
         return $output;
     }
 }
Exemple #17
0
 /**
  * Make a select box with all glpi users where select key = name
  *
  * @param $options array of possible options:
  *    - name         : string / name of the select (default is users_id)
  *    - value
  *    - right        : string / limit user who have specific right :
  *                         id -> only current user (default case);
  *                         interface -> central ;
  *                         all -> all users ;
  *                         specific right like show_all_ticket, create_ticket.... (is array passed one of all passed right is needed)
  *    - comments     : boolean / is the comments displayed near the dropdown (default true)
  *    - entity       : integer or array / restrict to a defined entity or array of entities
  *                      (default -1 : no restriction)
  *    - entity_sons  : boolean / if entity restrict specified auto select its sons
  *                      only available if entity is a single value not an array(default false)
  *    - all          : Nobody or All display for none selected
  *                         all=0 (default) -> Nobody
  *                         all=1 -> All
  *                         all=-1-> nothing
  *    - rand         : integer / already computed rand value
  *    - toupdate     : array / Update a specific item on select change on dropdown
  *                      (need value_fieldname, to_update, url
  *                      (see Ajax::updateItemOnSelectEvent for information)
  *                      and may have moreparams)
  *    - used         : array / Already used items ID: not to display in dropdown (default empty)
  *    - ldap_import
  *    - on_change    : string / value to transmit to "onChange"
  *    - display      : boolean / display or get string (default true)
  *
  * @return rand value if displayed / string if not
  **/
 static function dropdown($options = array())
 {
     global $DB, $CFG_GLPI;
     // Default values
     $p['name'] = 'users_id';
     $p['value'] = '';
     $p['right'] = 'id';
     $p['all'] = 0;
     $p['on_change'] = '';
     $p['comments'] = 1;
     $p['entity'] = -1;
     $p['entity_sons'] = false;
     $p['used'] = array();
     $p['ldap_import'] = false;
     $p['toupdate'] = '';
     $p['rand'] = mt_rand();
     $p['display'] = true;
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $p[$key] = $val;
         }
     }
     $output = '';
     if (!($p['entity'] < 0) && $p['entity_sons']) {
         if (is_array($p['entity'])) {
             $output .= "entity_sons options is not available with array of entity";
         } else {
             $p['entity'] = getSonsOf('glpi_entities', $p['entity']);
         }
     }
     // Make a select box with all glpi users
     $use_ajax = false;
     if ($CFG_GLPI["use_ajax"]) {
         $res = self::getSqlSearchResult(true, $p['right'], $p['entity'], $p['value'], $p['used']);
         $nb = $res ? $DB->result($res, 0, "CPT") : 0;
         if ($nb > $CFG_GLPI["ajax_limit_count"]) {
             $use_ajax = true;
         }
     }
     $user = getUserName($p['value'], 2);
     $default_display = "<select id='dropdown_" . $p['name'] . $p['rand'] . "' name='" . $p['name'] . "'>";
     $default_display .= "<option value='" . $p['value'] . "'>";
     $default_display .= Toolbox::substr($user["name"], 0, $_SESSION["glpidropdown_chars_limit"]);
     $default_display .= "</option></select>";
     $view_users = Session::haveRight("user", "r");
     $params = array('searchText' => '__VALUE__', 'value' => $p['value'], 'myname' => $p['name'], 'all' => $p['all'], 'right' => $p['right'], 'comment' => $p['comments'], 'rand' => $p['rand'], 'on_change' => $p['on_change'], 'entity_restrict' => $p['entity'], 'used' => $p['used'], 'update_item' => $p['toupdate']);
     if ($view_users) {
         $params['update_link'] = $view_users;
     }
     $default = "";
     if (!empty($p['value']) && $p['value'] > 0) {
         $default = $default_display;
     } else {
         $default = "<select name='" . $p['name'] . "' id='dropdown_" . $p['name'] . $p['rand'] . "'>";
         if ($p['all']) {
             $default .= "<option value='0'>--" . __('All') . "--</option></select>";
         } else {
             $default .= "<option value='0'>" . Dropdown::EMPTY_VALUE . "</option></select>\n";
         }
     }
     $output .= Ajax::dropdown($use_ajax, "/ajax/dropdownUsers.php", $params, $default, $p['rand'], false);
     // Display comment
     if ($p['comments']) {
         if (!$view_users) {
             $user["link"] = '';
         } else {
             if (empty($user["link"])) {
                 $user["link"] = $CFG_GLPI['root_doc'] . "/front/user.php";
             }
         }
         $output .= Html::showToolTip($user["comment"], array('contentid' => "comment_" . $p['name'] . $p['rand'], 'display' => false, 'link' => $user["link"], 'linkid' => "comment_link_" . $p["name"] . $p['rand']));
     }
     if (Session::haveRight('import_externalauth_users', 'w') && $p['ldap_import'] && Entity::isEntityDirectoryConfigured($_SESSION['glpiactive_entity'])) {
         $output .= "<img alt='' title=\"" . __s('Import a user') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png' style='cursor:pointer; margin-left:2px;'\n                      onClick=\"var w = window.open('" . $CFG_GLPI['root_doc'] . "/front/popup.php?popup=add_ldapuser&amp;rand=" . $p['rand'] . "&amp;entity=" . $_SESSION['glpiactive_entity'] . "' ,'glpipopup', 'height=400, " . "width=1000, top=100, left=100, scrollbars=yes' );w.focus();\">";
     }
     if ($p['display']) {
         echo $output;
         return $p['rand'];
     }
     return $output;
 }
Exemple #18
0
*/
include '../inc/includes.php';
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
Session::checkCentralAccess();
// Make a select box
if ($_POST["idtable"] && class_exists($_POST["idtable"])) {
    $table = getTableForItemType($_POST["idtable"]);
    // Link to user for search only > normal users
    $link = "dropdownValue.php";
    if ($_POST["idtable"] == 'User') {
        $link = "dropdownUsers.php";
    }
    $rand = mt_rand();
    $use_ajax = false;
    if ($CFG_GLPI["use_ajax"] && countElementsInTable($table) > $CFG_GLPI["ajax_limit_count"]) {
        $use_ajax = true;
    }
    $paramsallitems = array('searchText' => '__VALUE__', 'table' => $table, 'itemtype' => $_POST["idtable"], 'rand' => $rand, 'myname' => $_POST["myname"], 'displaywith' => array('otherserial', 'serial'), 'display_emptychoice' => true);
    if (isset($_POST['value'])) {
        $paramsallitems['value'] = $_POST['value'];
    }
    if (isset($_POST['entity_restrict'])) {
        $paramsallitems['entity_restrict'] = $_POST['entity_restrict'];
    }
    if (isset($_POST['condition'])) {
        $paramsallitems['condition'] = stripslashes($_POST['condition']);
    }
    $default = "<select name='" . $_POST["myname"] . "'><option value='0'>" . Dropdown::EMPTY_VALUE . "</option></select>";
    Ajax::dropdown($use_ajax, "/ajax/{$link}", $paramsallitems, $default, $rand);
}