/** * 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&rand=" . $p['rand'] . "&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; }
/** * 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 Ticket::READALL, CREATE.... (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) * - width : specific width needed (default 80%) * - specific_tags : array of HTML5 tags to add the the field * - url : url of the ajax php code which should return the json data to show in * the dropdown (default /ajax/getDropdownUsers.php) * * @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['width'] = '80%'; $p['entity'] = -1; $p['entity_sons'] = false; $p['used'] = array(); $p['ldap_import'] = false; $p['toupdate'] = ''; $p['rand'] = mt_rand(); $p['display'] = true; $p['_user_index'] = 0; $p['specific_tags'] = array(); $p['url'] = $CFG_GLPI['root_doc'] . "/ajax/getDropdownUsers.php"; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $p[$key] = $val; } } // check default value (in case of multiple observers) if (is_array($p['value'])) { $p['value'] = $p['value'][$p['_user_index']]; } // Check default value for dropdown : need to be a numeric if (strlen($p['value']) == 0 || !is_numeric($p['value'])) { $p['value'] = 0; } $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 $user = getUserName($p['value'], 2); $view_users = self::canView(); if (!empty($p['value']) && $p['value'] > 0) { $default = $user["name"]; } else { if ($p['all']) { $default = __('All'); } else { $default = Dropdown::EMPTY_VALUE; } } $field_id = Html::cleanId("dropdown_" . $p['name'] . $p['rand']); $param = array('value' => $p['value'], 'valuename' => $default, 'width' => $p['width'], 'all' => $p['all'], 'right' => $p['right'], 'on_change' => $p['on_change'], 'used' => $p['used'], 'entity_restrict' => $p['entity'], 'specific_tags' => $p['specific_tags']); $output = Html::jsAjaxDropdown($p['name'], $field_id, $p['url'], $param); // Display comment if ($p['comments']) { $comment_id = Html::cleanId("comment_" . $p['name'] . $p['rand']); $link_id = Html::cleanId("comment_link_" . $p["name"] . $p['rand']); 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_id, 'display' => false, 'link' => $user["link"], 'linkid' => $link_id)); $paramscomment = array('value' => '__VALUE__', 'table' => "glpi_users"); if ($view_users) { $paramscomment['withlink'] = $link_id; } $output .= Ajax::updateItemOnSelectEvent($field_id, $comment_id, $CFG_GLPI["root_doc"] . "/ajax/comments.php", $paramscomment, false); } $output .= Ajax::commonDropdownUpdateItem($p, false); if (Session::haveRight('user', self::IMPORTEXTAUTHUSERS) && $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=\"" . Html::jsGetElementbyID('userimport' . $p['rand']) . ".dialog('open');\">"; $output .= Ajax::createIframeModalWindow('userimport' . $p['rand'], $CFG_GLPI["root_doc"] . "/front/ldap.import.php?entity=" . $_SESSION['glpiactive_entity'], array('title' => __('Import a user'), 'display' => false)); } if ($p['display']) { echo $output; return $p['rand']; } return $output; }