Esempio n. 1
0
 /**
  * Make a select box with all glpi users where select key = name
  *
  * Parameters which could be used in options array :
  *    - name : string / name of the select (default is users_id)
  *    - 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....
  *    - 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 ajaxUpdateItemOnSelectEvent for informations)
  *                   and may have moreparams)
  *    - used : array / Already used items ID: not to display in dropdown (default empty)
  *    - auto_submit : boolean / autosubmit on change (default false)
  *
  * @param $options possible options
  *
  * @return nothing (print out an HTML select box)
  **/
 static function dropdown($options = array())
 {
     global $DB, $CFG_GLPI, $LANG;
     // Defautl values
     $p['name'] = 'users_id';
     $p['value'] = '';
     $p['right'] = 'id';
     $p['all'] = 0;
     $p['auto_submit'] = false;
     $p['comments'] = 1;
     $p['entity'] = -1;
     $p['entity_sons'] = false;
     $p['used'] = array();
     $p['ldap_import'] = false;
     $p['toupdate'] = '';
     $p['rand'] = mt_rand();
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $p[$key] = $val;
         }
     }
     if (!($p['entity'] < 0) && $p['entity_sons']) {
         if (is_array($p['entity'])) {
             echo "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 .= utf8_substr($user["name"], 0, $_SESSION["glpidropdown_chars_limit"]);
     $default_display .= "</option></select>";
     $view_users = 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'], 'auto_submit' => $p['auto_submit'], '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'>[ " . $LANG['common'][66] . " ]</option></select>";
         } else {
             $default .= "<option value='0'>" . DROPDOWN_EMPTY_VALUE . "</option></select>\n";
         }
     }
     ajaxDropdown($use_ajax, "/ajax/dropdownUsers.php", $params, $default, $p['rand']);
     // Display comment
     if ($p['comments']) {
         if (!$view_users) {
             $user["link"] = '';
         } else {
             if (empty($user["link"])) {
                 $user["link"] = $CFG_GLPI['root_doc'] . "/front/user.php";
             }
         }
         showToolTip($user["comment"], array('contentid' => "comment_" . $p['name'] . $p['rand'], 'link' => $user["link"], 'linkid' => "comment_link_" . $p["name"] . $p['rand']));
     }
     if (haveRight('import_externalauth_users', 'w') && $p['ldap_import'] && EntityData::isEntityDirectoryConfigured($_SESSION['glpiactive_entity'])) {
         echo "<img alt='' title=\"" . $LANG['ldap'][35] . "\" 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();\">";
     }
     return $p['rand'];
 }