/** * 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; }
Html::header_nocache(); if (!($item = getItemForItemtype($_POST['itemtype']))) { exit; } $item->checkGlobal(READ); $group = ""; $values = array(); $searchopt = Search::getCleanedOptions($_POST["itemtype"], READ, false); echo "<table width='100%'><tr><td width='40%'>"; foreach ($searchopt as $key => $val) { // print groups $str_limit = 28; if (!is_array($val)) { $group = $val; } else { // No search on plugins if (!isPluginItemType($key) && !isset($val["nometa"])) { $values[$group][$key] = $val["name"]; } } } $rand = Dropdown::showFromArray("metacriteria[" . $_POST["num"] . "][field]", $values, array('value' => $_POST["field"])); $field_id = Html::cleanId("dropdown_metacriteria[" . $_POST["num"] . "][field]" . $rand); echo "</td><td class='left'>"; echo "<span id='Search2Span" . $_POST["itemtype"] . $_POST["num"] . "'>\n"; $_POST['meta'] = 1; include GLPI_ROOT . "/ajax/searchoption.php"; echo "</span>\n"; $params = array('field' => '__VALUE__', 'itemtype' => $_POST["itemtype"], 'num' => $_POST["num"], 'value' => $_POST["value"], 'searchtype' => $_POST["searchtype"], 'meta' => 1); Ajax::updateItemOnSelectEvent($field_id, "Search2Span" . $_POST["itemtype"] . $_POST["num"], $CFG_GLPI["root_doc"] . "/ajax/searchoption.php", $params); echo '</td></tr></table>';
/** * 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 = ""; if (empty($value)) { $value = 0; } if ($value > 0) { $tmpname = Dropdown::getDropdownName("glpi_netpoints", $value, 1); if ($tmpname["name"] != " ") { $name = $tmpname["name"]; $comment = $tmpname["comment"]; } } $field_id = Html::cleanId("dropdown_" . $myname . $rand); $param = array('value' => $value, 'valuename' => $name, 'entity_restrict' => $entity_restrict, 'devtype' => $devtype, 'locations_id' => $locations_id); echo Html::jsAjaxDropdown($myname, $field_id, $CFG_GLPI['root_doc'] . "/ajax/getDropdownNetpoint.php", $param); // Display comment if ($display_comment) { $comment_id = Html::cleanId("comment_" . $myname . $rand); Html::showToolTip($comment, array('contentid' => $comment_id)); $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=\"" . Html::jsGetElementbyID('netpoint' . $rand) . ".dialog('open');\">"; Ajax::createIframeModalWindow('netpoint' . $rand, $item->getFormURL()); } $paramscomment = array('value' => '__VALUE__', 'table' => "glpi_netpoints"); echo Ajax::updateItemOnSelectEvent($field_id, $comment_id, $CFG_GLPI["root_doc"] . "/ajax/comments.php", $paramscomment, false); } return $rand; }
/** * Display for reservation * * @param $ID ID of the reservation (empty for create new) * @param $options array of possibles options: * - item reservation items ID for creation process * - date date for creation process **/ function showForm($ID, $options = array()) { global $CFG_GLPI; if (!Session::haveRight("reservation", ReservationItem::RESERVEANITEM)) { return false; } $resa = new self(); if (!empty($ID)) { if (!$resa->getFromDB($ID)) { return false; } if (!$resa->can($ID, UPDATE)) { return false; } // Set item if not set if ((!isset($options['item']) || count($options['item']) == 0) && ($itemid = $resa->getField('reservationitems_id'))) { $options['item'][$itemid] = $itemid; } } else { $resa->getEmpty(); $resa->fields["begin"] = $options['begin']; if (!isset($options['end'])) { $resa->fields["end"] = date("Y-m-d H:00:00", strtotime($resa->fields["begin"]) + HOUR_TIMESTAMP); } else { $resa->fields["end"] = $options['end']; } } // No item : problem if (!isset($options['item']) || count($options['item']) == 0) { return false; } echo "<div class='center'><form method='post' name=form action='reservation.form.php'>"; if (!empty($ID)) { echo "<input type='hidden' name='id' value='{$ID}'>"; } echo "<table class='tab_cadre' width='700px'>"; echo "<tr><th colspan='2'>" . __('Reserve an item') . "</th></tr>\n"; // Add Hardware name $r = new ReservationItem(); echo "<tr class='tab_bg_1'><td>" . __('Item') . "</td>"; echo "<td>"; foreach ($options['item'] as $itemID) { $r->getFromDB($itemID); $type = $r->fields["itemtype"]; $name = NOT_AVAILABLE; $item = NULL; if ($item = getItemForItemtype($r->fields["itemtype"])) { $type = $item->getTypeName(); if ($item->getFromDB($r->fields["items_id"])) { $name = $item->getName(); } else { $item = NULL; } } echo "<span class='b'>" . sprintf(__('%1$s - %2$s'), $type, $name) . "</span><br>"; echo "<input type='hidden' name='items[{$itemID}]' value='{$itemID}'>"; } echo "</td></tr>\n"; if (!Session::haveRight("reservation", UPDATE) || is_null($item) || !Session::haveAccessToEntity($item->fields["entities_id"])) { echo "<input type='hidden' name='users_id' value='" . Session::getLoginUserID() . "'>"; } else { echo "<tr class='tab_bg_2'><td>" . __('By') . "</td>"; echo "<td>"; if (empty($ID)) { User::dropdown(array('value' => Session::getLoginUserID(), 'entity' => $item->getEntityID(), 'right' => 'all')); } else { User::dropdown(array('value' => $resa->fields["users_id"], 'entity' => $item->getEntityID(), 'right' => 'all')); } echo "</td></tr>\n"; } echo "<tr class='tab_bg_2'><td>" . __('Start date') . "</td><td>"; $rand_begin = Html::showDateTimeField("resa[begin]", array('value' => $resa->fields["begin"], 'timestep' => -1, 'maybeempty' => false)); echo "</td></tr>\n"; $default_delay = floor((strtotime($resa->fields["end"]) - strtotime($resa->fields["begin"])) / $CFG_GLPI['time_step'] / MINUTE_TIMESTAMP) * $CFG_GLPI['time_step'] * MINUTE_TIMESTAMP; echo "<tr class='tab_bg_2'><td>" . __('Duration') . "</td><td>"; $rand = Dropdown::showTimeStamp("resa[_duration]", array('min' => 0, 'max' => 24 * HOUR_TIMESTAMP, 'value' => $default_delay, 'emptylabel' => __('Specify an end date'))); echo "<br><div id='date_end{$rand}'></div>"; $params = array('duration' => '__VALUE__', 'end' => $resa->fields["end"], 'name' => "resa[end]"); Ajax::updateItemOnSelectEvent("dropdown_resa[_duration]{$rand}", "date_end{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planningend.php", $params); if ($default_delay == 0) { $params['duration'] = 0; Ajax::updateItem("date_end{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planningend.php", $params); } Alert::displayLastAlert('Reservation', $ID); echo "</td></tr>\n"; if (empty($ID)) { echo "<tr class='tab_bg_2'><td>" . __('Rehearsal') . "</td>"; echo "<td>"; $values = array('' => _x('periodicity', 'None'), 'day' => _x('periodicity', 'Daily'), 'week' => _x('periodicity', 'Weekly'), 'month' => _x('periodicity', 'Monthly')); $rand = Dropdown::showFromArray('periodicity[type]', $values); $field_id = Html::cleanId("dropdown_periodicity[type]{$rand}"); $params = array('type' => '__VALUE__', 'end' => $resa->fields["end"]); Ajax::updateItemOnSelectEvent($field_id, "resaperiodcontent{$rand}", $CFG_GLPI["root_doc"] . "/ajax/resaperiod.php", $params); echo "<br><div id='resaperiodcontent{$rand}'></div>"; echo "</td></tr>\n"; } echo "<tr class='tab_bg_2'><td>" . __('Comments') . "</td>"; echo "<td><textarea name='comment' rows='8' cols='60'>" . $resa->fields["comment"] . "</textarea>"; echo "</td></tr>\n"; if (empty($ID)) { echo "<tr class='tab_bg_2'>"; echo "<td colspan='2' class='top center'>"; echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>\n"; } else { if ($resa->fields["users_id"] == Session::getLoginUserID() || Session::haveRightsOr(static::$rightname, array(PURGE, UPDATE))) { echo "<tr class='tab_bg_2'>"; if ($resa->fields["users_id"] == Session::getLoginUserID() || Session::haveRight(static::$rightname, PURGE)) { echo "<td class='top center'>"; echo "<input type='submit' name='purge' value=\"" . _sx('button', 'Delete permanently') . "\"\n class='submit'>"; if ($resa->fields["group"] > 0) { echo "<br><input type='checkbox' name='_delete_group'> " . __s('Delete all rehearsals'); } echo "</td>"; } if ($resa->fields["users_id"] == Session::getLoginUserID() || Session::haveRight(static::$rightname, UPDATE)) { echo "<td class='top center'>"; echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\"\n class='submit'>"; echo "</td>"; } echo "</tr>\n"; } } echo "</table>"; Html::closeForm(); echo "</div>\n"; }
/** * Javascript code for update an item (Javascript code only) * * @param $toupdate id of the item to update * @param $url Url to get datas to update the item * @param $parameters array of parameters to send to ajax URL * @param $toobserve id of another item used to get value in case of __VALUE__ used * or * array of id to get value in case of __VALUE#__ used (default '') * @param $display boolean display or get string (default true) **/ static function updateItemJsCode($toupdate, $url, $parameters = array(), $toobserve = "", $display = true) { $out = Html::jsGetElementbyID($toupdate) . ".load('{$url}'\n"; if (count($parameters)) { $out .= ",{"; $first = true; foreach ($parameters as $key => $val) { if ($first) { $first = false; } else { $out .= ","; } $out .= $key . ":"; if (!is_array($val) && preg_match('/^__VALUE(\\d+)__$/', $val, $regs)) { $out .= Html::jsGetElementbyID(Html::cleanId($toobserve[$regs[1]])) . ".val()"; } else { if (!is_array($val) && $val === "__VALUE__") { $out .= Html::jsGetElementbyID(Html::cleanId($toobserve)) . ".val()"; } else { $out .= json_encode($val); } } } $out .= "}\n"; } $out .= ")\n"; if ($display) { echo $out; } else { return $out; } }
/** * Get right linear right choice. * * @since version 0.85 * * @param $elements array all pair identifier => label * @param $options array possible: * 'canedit' * 'field' name of the HTML field * 'value' the value inside the database * 'max_per_line' maximum number of elements per line * 'check_all' add a checkbox to check or uncheck every checkbox * 'rand' random value used to generate the ids * 'zero_on_empty' do we send 0 when checkbox is not checked ? * 'display' * 'check_method' method used to check the right * * @return content if !display **/ static function getLinearRightChoice(array $elements, array $options = array()) { $param = array(); $param['canedit'] = true; $param['field'] = ''; $param['value'] = ''; $param['max_per_line'] = 10; $param['check_all'] = false; $param['rand'] = mt_rand(); $param['zero_on_empty'] = true; $param['display'] = true; $param['check_method'] = function ($element, $field) { return ($field & $element) == $element; }; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $param[$key] = $val; } } if (empty($param['field'])) { return; } $nb_cbs = count($elements); $cb_options = array('readonly' => !$param['canedit']); if ($param['check_all']) { $nb_cbs++; $massive_tag = 'checkall_' . $param['field'] . '_' . $param['rand']; $cb_options['massive_tags'] = $massive_tag; } $nb_lines = ceil($nb_cbs / $param['max_per_line']); $nb_item_per_line = ceil($nb_cbs / $nb_lines); $out = ''; $count = 0; $nb_checked = 0; foreach ($elements as $element => $label) { if ($count != 0) { if ($count % $nb_item_per_line == 0) { $out .= "<br>\n"; } else { $out .= " -\n\t\t "; } } else { $out .= "\n\t\t"; } $out .= $label . ' '; $cb_options['name'] = $param['field'] . '[' . $element . ']'; $cb_options['id'] = Html::cleanId('checkbox_linear_' . $cb_options['name'] . '_' . $param['rand']); $cb_options['zero_on_empty'] = $param['zero_on_empty']; $cb_options['checked'] = $param['check_method']($element, $param['value']); $out .= Html::getCheckbox($cb_options); $count++; if ($cb_options['checked']) { $nb_checked++; } } if ($param['check_all']) { $cb_options = array('criterion' => array('tag_for_massive' => $massive_tag), 'id' => Html::cleanId('checkbox_linear_' . $param['rand'])); if ($nb_checked > count($elements) / 2) { $cb_options['checked'] = true; } $out .= " - <i><b>" . __('Select/unselect all') . "</b></i> " . Html::getCheckbox($cb_options); } if (!$param['display']) { return $out; } echo $out; }
/** * Make a select box for all items * * @since version 0.85 * * @param $options array: * - itemtype_name : the name of the field containing the itemtype (default 'itemtype') * - items_id_name : the name of the field containing the id of the selected item * (default 'items_id') * - itemtypes : all possible types to search for (default: $CFG_GLPI["state_types"]) * - default_itemtype : the default itemtype to select (don't define if you don't * need a default) (defaut 0) * - entity_restrict : restrict entity in searching items (default -1) * - onlyglobal : don't match item that don't have `is_global` == 1 (false by default) * - checkright : check to see if we can "view" the itemtype (false by default) * - showItemSpecificity : given an item, the AJAX file to open if there is special * treatment. For instance, select a Item_Device* for CommonDevice * - emptylabel : Empty choice's label (default self::EMPTY_VALUE) * * @return randomized value used to generate HTML IDs **/ static function showSelectItemFromItemtypes(array $options = array()) { global $CFG_GLPI; $params = array(); $params['itemtype_name'] = 'itemtype'; $params['items_id_name'] = 'items_id'; $params['itemtypes'] = ''; $params['default_itemtype'] = 0; $params['entity_restrict'] = -1; $params['onlyglobal'] = false; $params['checkright'] = false; $params['showItemSpecificity'] = ''; $params['condition'] = ''; $params['emptylabel'] = Dropdown::EMPTY_VALUE; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $params[$key] = $val; } } $rand = Dropdown::showItemType($params['itemtypes'], array('checkright' => $params['checkright'], 'name' => $params['itemtype_name'], 'emptylabel' => $params['emptylabel'])); if ($rand) { $p = array('idtable' => '__VALUE__', 'name' => $params['items_id_name'], 'entity_restrict' => $params['entity_restrict'], 'showItemSpecificity' => $params['showItemSpecificity']); $field_id = Html::cleanId("dropdown_" . $params['itemtype_name'] . $rand); $show_id = Html::cleanId("show_" . $params['items_id_name'] . $rand); Ajax::updateItemOnSelectEvent($field_id, $show_id, $CFG_GLPI["root_doc"] . "/plugins/consumables/ajax/dropdownAllItems.php", $p); echo "<br><span id='{$show_id}'> </span>\n"; // We check $options as the caller will set $options['default_itemtype'] only if it needs a // default itemtype and the default value can be '' thus empty won't be valid ! if (array_key_exists('default_itemtype', $options)) { echo "<script type='text/javascript' >\n"; echo Html::jsSetDropdownValue($field_id, $params['default_itemtype']); echo "</script>\n"; $p["idtable"] = $params['default_itemtype']; Ajax::updateItem($show_id, $CFG_GLPI["root_doc"] . "/ajax/dropdownAllItems.php", $p); } } return $rand; }
if (count($actions) && (empty($_POST['searchtype']) || !isset($actions[$_POST['searchtype']]))) { $tmp = $actions; unset($tmp['searchopt']); $_POST['searchtype'] = key($tmp); unset($tmp); } $randsearch = -1; $dropdownname = "searchtype{$fieldname}" . $_POST["itemtype"] . $_POST["num"]; $searchopt = array(); echo "<table width='100%'><tr><td width='20%'>"; if (count($actions) > 0) { // get already get search options if (isset($actions['searchopt'])) { $searchopt = $actions['searchopt']; // No name for clean array whith quotes unset($searchopt['name']); unset($actions['searchopt']); } $randsearch = Dropdown::showFromArray($fieldname . "[" . $_POST["num"] . "][searchtype]", $actions, array('value' => $_POST["searchtype"], 'width' => '100%')); $fieldsearch_id = Html::cleanId("dropdown_" . $fieldname . "[" . $_POST["num"] . "][searchtype]{$randsearch}"); } echo "</td><td width='80%'>"; echo "<span id='span{$dropdownname}'>\n"; $_POST['value'] = stripslashes($_POST['value']); $_POST['searchopt'] = $searchopt; include GLPI_ROOT . "/ajax/searchoptionvalue.php"; echo "</span>\n"; echo "</td></tr></table>"; $paramsaction = array('searchtype' => '__VALUE__', 'field' => $_POST["field"], 'itemtype' => $_POST["itemtype"], 'num' => $_POST["num"], 'value' => rawurlencode($_POST['value']), 'searchopt' => $searchopt, 'meta' => $_POST['meta']); Ajax::updateItemOnSelectEvent($fieldsearch_id, "span{$dropdownname}", $CFG_GLPI["root_doc"] . "/ajax/searchoptionvalue.php", $paramsaction); }
/** * Dropdown of values in an array * * @param $name select name * @param $elements array of elements to display * @param $options array of possible options: * - value : integer / preselected value (default 0) * - used : array / Already used items ID: not to display in dropdown (default empty) * - readonly : boolean / used as a readonly item (default false) * - on_change : string / value to transmit to "onChange" * - multiple : boolean / can select several values (default false) * - size : integer / number of rows for the select (default = 1) * - display : boolean / display or return string * - other : boolean or string if not false, then we can use an "other" value * if it is a string, then the default value will be this string * - rand : specific rand if needed (default is generated one) * - width : specific width needed (default not set) * - emptylabel : empty label if empty displayed (default self::EMPTY_VALUE) * - display_emptychoice : display empty choice (default false) * - tooltip : string / message to add as tooltip on the dropdown (default '') * - option_tooltips : array / message to add as tooltip on the dropdown options. Use the same keys as for the $elements parameter, but none is mandotary. Missing keys will just be ignored and no tooltip will be added. To add a tooltip on an option group, is the '__optgroup_label' key inside the array describing option tooltips : 'optgroupname1' => array('__optgroup_label' => 'tooltip for option group') (default empty) * * Permit to use optgroup defining items in arrays * array('optgroupname' => array('key1' => 'val1', * 'key2' => 'val2'), * 'optgroupname2' => array('key3' => 'val3', * 'key4' => 'val4')) **/ static function showFromArray($name, array $elements, $options = array()) { $param['value'] = ''; $param['values'] = array(''); $param['tooltip'] = ''; $param['option_tooltips'] = array(); $param['used'] = array(); $param['readonly'] = false; $param['on_change'] = ''; $param['width'] = ''; $param['multiple'] = false; $param['size'] = 1; $param['display'] = true; $param['other'] = false; $param['rand'] = mt_rand(); $param['emptylabel'] = self::EMPTY_VALUE; $param['display_emptychoice'] = false; if (is_array($options) && count($options)) { if (isset($options['value']) && strlen($options['value'])) { $options['values'] = array($options['value']); unset($options['value']); } foreach ($options as $key => $val) { $param[$key] = $val; } } if ($param['other'] !== false) { $other_select_option = $name . '_other_value'; $param['on_change'] .= "displayOtherSelectOptions(this, \"{$other_select_option}\");"; // If $param['other'] is a string, then we must highlight "other" option if (is_string($param['other'])) { if (!$param["multiple"]) { $param['values'] = array($other_select_option); } else { $param['values'][] = $other_select_option; } } } $param['option_tooltips'] = Html::entities_deep($param['option_tooltips']); if ($param["display_emptychoice"]) { $elements = array(0 => $param['emptylabel']) + $elements; } if ($param["multiple"]) { $field_name = $name . "[]"; } else { $field_name = $name; } $output = ''; // readonly mode $field_id = Html::cleanId("dropdown_" . $name . $param['rand']); if ($param['readonly']) { $to_display = array(); foreach ($param['values'] as $value) { $output .= "<input type='hidden' name='{$field_name}' value='{$value}'>"; if (isset($elements[$value])) { $to_display[] = $elements[$value]; } } $output .= implode('<br>', $to_display); } else { $output .= "<select name='{$field_name}' id='{$field_id}'"; if ($param['tooltip']) { $output .= ' title="' . Html::entities_deep($param['tooltip']) . '"'; } if (!empty($param["on_change"])) { $output .= " onChange='" . $param["on_change"] . "'"; } if (is_int($param["size"]) && $param["size"] > 0) { $output .= " size='" . $param["size"] . "'"; } if ($param["multiple"]) { $output .= " multiple"; } $output .= '>'; $max_option_size = 0; foreach ($elements as $key => $val) { // optgroup management if (is_array($val)) { $opt_goup = Html::entities_deep($key); if ($max_option_size < strlen($opt_goup)) { $max_option_size = strlen($opt_goup); } $output .= "<optgroup label=\"{$opt_goup}\""; $optgroup_tooltips = false; if (isset($param['option_tooltips'][$key])) { if (is_array($param['option_tooltips'][$key])) { if (isset($param['option_tooltips'][$key]['__optgroup_label'])) { $output .= ' title="' . $param['option_tooltips'][$key]['__optgroup_label'] . '"'; } $optgroup_tooltips = $param['option_tooltips'][$key]; } else { $output .= ' title="' . $param['option_tooltips'][$key] . '"'; } } $output .= ">"; foreach ($val as $key2 => $val2) { if (!isset($param['used'][$key2])) { $output .= "<option value='" . $key2 . "'"; // Do not use in_array : trouble with 0 and empty value foreach ($param['values'] as $value) { if (strcmp($key2, $value) === 0) { $output .= " selected"; break; } } if ($optgroup_tooltips && isset($optgroup_tooltips[$key2])) { $output .= ' title="' . $optgroup_tooltips[$key2] . '"'; } $output .= ">" . $val2 . "</option>"; if ($max_option_size < strlen($val2)) { $max_option_size = strlen($val2); } } } $output .= "</optgroup>"; } else { if (!isset($param['used'][$key])) { $output .= "<option value='" . $key . "'"; // Do not use in_array : trouble with 0 and empty value foreach ($param['values'] as $value) { if (strcmp($key, $value) === 0) { $output .= " selected"; break; } } if (isset($param['option_tooltips'][$key])) { $output .= ' title="' . $param['option_tooltips'][$key] . '"'; } $output .= ">" . $val . "</option>"; if ($max_option_size < strlen($val)) { $max_option_size = strlen($val); } } } } if ($param['other'] !== false) { $output .= "<option value='{$other_select_option}'"; if (is_string($param['other'])) { $output .= " selected"; } $output .= ">" . __('Other...') . "</option>"; } $output .= "</select>"; if ($param['other'] !== false) { $output .= "<input name='{$other_select_option}' id='{$other_select_option}' type='text'"; if (is_string($param['other'])) { $output .= " value=\"" . $param['other'] . "\""; } else { $output .= " style=\"display: none\""; } $output .= ">"; } } // Width set on select $output .= Html::jsAdaptDropdown($field_id, array('width' => $param["width"])); if ($param["multiple"]) { // Hack for All / None because select2 does not provide it $select = __('All'); $deselect = __('None'); $output .= "<div class='invisible' id='selectallbuttons_{$field_id}'>"; $output .= "<div class='select2-actionable-menu'>"; $output .= "<a class='vsubmit floatleft' " . "onclick=\"selectAll('{$field_id}');\$('#{$field_id}').select2('close');\">{$select}" . "</a> "; $output .= "<a class='vsubmit floatright' onclick=\"deselectAll('{$field_id}');\">{$deselect}" . "</a>"; $output .= "</div></div>"; $js = "\n var multichecksappend{$field_id} = false;\n \$('#{$field_id}').on('select2-open', function() {\n if (!multichecksappend{$field_id}) {\n \$('#select2-drop').append(\$('#selectallbuttons_{$field_id}').html());\n multichecksappend{$field_id} = true;\n }\n });"; $output .= Html::scriptBlock($js); } $output .= Ajax::commonDropdownUpdateItem($param, false); if ($param['display']) { echo $output; return $param['rand']; } return $output; }
(at your option) any later version. Racks 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 Racks. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ include '../../../inc/includes.php'; header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); Plugin::load('racks', true); if (isset($_POST["modeltable"]) && !empty($_POST["modeltable"])) { $rand = mt_rand(); $itemtype = substr($_POST['modeltable'], 0, -5); $modelfield = getForeignKeyFieldForTable(getTableForItemType($_POST['modeltable'])); $table = getTableForItemType($itemtype); $params = array('searchText' => '__VALUE__', 'modeltable' => $_POST["modeltable"], 'modelfield' => $modelfield, 'itemtype' => $itemtype, 'rand' => $rand, 'width' => '500', 'myname' => $_POST["myname"]); if (isset($_POST['value'])) { $params['value'] = $_POST['value']; $params['valuename'] = "-----"; } if (isset($_POST['entity_restrict'])) { $params['entity_restrict'] = $_POST['entity_restrict']; } $field_id = Html::cleanId($_POST['myname'] . $rand); echo Html::jsAjaxDropdown($_POST["myname"], $field_id, $CFG_GLPI['root_doc'] . "/plugins/racks/ajax/dropdownValue.php", $params); }
/** * 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(); $field_id = Html::cleanId("dropdown_" . $myname . $rand); $param = array('entity_restrict' => $entity_restrict, 'fromtype' => $fromtype, 'itemtype' => $itemtype, 'onlyglobal' => $onlyglobal, 'used' => $used); echo Html::jsAjaxDropdown($myname, $field_id, $CFG_GLPI['root_doc'] . "/ajax/getDropdownConnect.php", $param); return $rand; }
Html::header_nocache(); // Make a select box if (isset($_POST["type"]) && $_POST['action']) { if ($_POST['action'] == 'showType') { $item = getItemForItemtype($_POST['type'] . "Type"); } else { $item = getItemForItemtype($_POST['type']); } $itemtype = $_POST['type']; $table = $item->getTable(); if (!empty($table)) { // Link to user for search only > normal users $rand = mt_rand(); $params = array('searchText' => '__VALUE__', 'itemtype' => $itemtype, 'table' => $table, 'rand' => $rand, 'emptylabel' => true, 'valuename' => Dropdown::EMPTY_VALUE, 'value2' => isset($_POST['value']) ? $_POST['value'] : 0, 'name' => $_POST["myname"], 'width' => 200, 'locations_id' => $_POST["locations_id"]); if (isset($_POST['value'])) { $params['value'] = $_POST['value']; } if (isset($_POST['entity_restrict'])) { $params['entity_restrict'] = $_POST['entity_restrict']; } $field_id = Html::cleanId("dropdown_" . $params['name'] . $params['rand']); echo Html::jsAjaxDropdown($_POST["myname"], $field_id, $CFG_GLPI['root_doc'] . "/plugins/positions/ajax/dropdownValue.php", $params); 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::updateItem("results_{$rand}", $CFG_GLPI["root_doc"] . "/plugins/positions/ajax/dropdownValue.php", $params); } } }
$values[$group][$key] = $val["name"]; } } } if ($CFG_GLPI['allow_search_view'] == 1) { $values['view'] = __('Items seen'); } if ($CFG_GLPI['allow_search_all']) { $values['all'] = __('All'); } $value = ''; if (isset($criteria['field'])) { $value = $criteria['field']; } $rand = Dropdown::showFromArray("criteria[" . $_POST["num"] . "][field]", $values, array('value' => $value)); $field_id = Html::cleanId("dropdown_criteria[" . $_POST["num"] . "][field]{$rand}"); echo "</td><td class='left'>"; $spanid = 'SearchSpan' . $_POST["itemtype"] . $_POST["num"]; echo "<div id='{$spanid}'>\n"; $used_itemtype = $_POST["itemtype"]; // Force Computer itemtype for AllAssets to permit to show specific items if ($_POST["itemtype"] == 'AllAssets') { $used_itemtype = 'Computer'; } $_POST['itemtype'] = $used_itemtype; $_POST['field'] = $value; $_POST['searchtype'] = isset($criteria['searchtype']) ? $criteria['searchtype'] : ""; $_POST['value'] = isset($criteria['value']) ? stripslashes($criteria['value']) : ""; include GLPI_ROOT . "/ajax/searchoption.php"; echo "</div>\n"; $params = array('field' => '__VALUE__', 'itemtype' => $used_itemtype, 'num' => $_POST["num"], 'value' => $_POST["value"], 'searchtype' => $_POST["searchtype"]);
$objeto = new $itemtype(); $table = $objeto->getTable(); } //$use_ajax=$CFG_GLPI['use_ajax']; //echo $CFG_GLPI['use_ajax']; $tabletype = PluginRelationRelation::getNombreClaseRelacionada($_POST['type_relations']); /* switch ($tabletype){ case "Group" : $use_ajax=0; break; case "User" : $use_ajax=0; break; default: $use_ajax=$CFG_GLPI['use_ajax']; break; } */ //echo $tabletype."-".$use_ajax; //$params = array(); $params = array('searchText' => '__VALUE__', 'type_relations' => $_POST['type_relations'], 'entity_restrict' => $_POST['entity_restrict'], 'itemtype' => $_POST['itemtype'], 'rand' => $_POST['rand'], 'myname' => $_POST['myname']); //'used'=>$_POST['used'] //print_r($params); //Session::addMessageAfterRedirect($_POST , false, ERROR); $field_id = Html::cleanId("show_" . $_POST['myname'] . $rand); //$field_id = "show_".$_POST['myname'].$rand; //$default='<select name="'.$_POST['myname'].'"><option value="0">------</option></select>'; //Ajax::dropdown($use_ajax,'/plugins/relation/ajax/dropdownValue.php',$params,$default,$rand); echo Html::jsAjaxDropdown($_POST['myname'], $field_id, $CFG_GLPI['root_doc'] . "/plugins/relation/ajax/dropdownValue.php", $params); }
/** * Make a select box for link tasklists * * Parameters which could be used in options array : * - name : string / name of the select (default is documents_id) * - entity : integer or array / restrict to a defined entity or array of entities * (default -1 : no restriction) * - used : array / Already used items ID: not to display in dropdown (default empty) * * @param $options array of possible options * * @return nothing (print out an HTML select box) * */ static function dropdownTasklists($options = array()) { global $DB, $CFG_GLPI; $p['name'] = 'plugin_tasklists_tasklists_id'; $p['entity'] = ''; $p['used'] = array(); $p['display'] = true; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $p[$key] = $val; } } $rand = mt_rand(); $where = " WHERE `glpi_plugin_tasklists_tasklists`.`is_deleted` = '0' "; $where .= getEntitiesRestrictRequest("AND", 'glpi_plugin_tasklists_tasklists', '', $p['entity'], true); if (count($p['used'])) { $where .= " AND `id` NOT IN (0, " . implode(",", $p['used']) . ")"; } $query = "SELECT *\n FROM `glpi_plugin_tasklists_tasktypes`\n WHERE `id` IN (SELECT DISTINCT `plugin_tasklists_tasktypes_id`\n FROM `glpi_plugin_tasklists_tasks`\n {$where})\n ORDER BY `name`"; $result = $DB->query($query); $values = array(0 => Dropdown::EMPTY_VALUE); while ($data = $DB->fetch_assoc($result)) { $values[$data['id']] = $data['name']; } $out = Dropdown::showFromArray('_tasktype', $values, array('width' => '30%', 'rand' => $rand, 'display' => false)); $field_id = Html::cleanId("dropdown__tasktype{$rand}"); $params = array('tasktypes' => '__VALUE__', 'entity' => $p['entity'], 'rand' => $rand, 'myname' => $p['name'], 'used' => $p['used']); $out .= Ajax::updateItemOnSelectEvent($field_id, "show_" . $p['name'] . $rand, $CFG_GLPI["root_doc"] . "/plugins/tasklists/ajax/dropdownTypeTasks.php", $params, false); $out .= "<span id='show_" . $p['name'] . "{$rand}'>"; $out .= "</span>\n"; $params['tasktype'] = 0; $out .= Ajax::updateItem("show_" . $p['name'] . $rand, $CFG_GLPI["root_doc"] . "/plugins/tasklists/ajax/dropdownTypeTasks.php", $params, false); if ($p['display']) { echo $out; return $rand; } return $out; }
$value = ''; if (isset($metacriteria["link"])) { $value = $metacriteria["link"]; } Dropdown::showFromArray("metacriteria[" . $_POST["num"] . "][link]", Search::getLogicalOperators(), array('value' => $value, 'width' => '40%')); // Display select of the linked item type available foreach ($linked as $key) { if (!isset($metanames[$key])) { if ($linkitem = getItemForItemtype($key)) { $metanames[$key] = $linkitem->getTypeName(); } } } $value = ''; if (isset($metacriteria['itemtype']) && !empty($metacriteria['itemtype'])) { $value = $metacriteria['itemtype']; } $rand = Dropdown::showItemTypes("metacriteria[" . $_POST["num"] . "][itemtype]", $linked, array('width' => '50%', 'value' => $value)); $field_id = Html::cleanId("dropdown_metacriteria[" . $_POST["num"] . "][itemtype]{$rand}"); echo "</td><td>"; // Ajax script for display search met& item echo "<span id='show_" . $_POST["itemtype"] . "_" . $_POST["num"] . "_{$rand}'> </span>\n"; $params = array('itemtype' => '__VALUE__', 'num' => $_POST["num"], 'field' => isset($metacriteria['field']) ? $metacriteria['field'] : "", 'value' => isset($metacriteria['value']) ? stripslashes($metacriteria['value']) : "", 'searchtype' => isset($metacriteria['searchtype']) ? $metacriteria['searchtype'] : ""); Ajax::updateItemOnSelectEvent($field_id, "show_" . $_POST["itemtype"] . "_" . $_POST["num"] . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/updateMetaSearch.php", $params); if (isset($metacriteria['itemtype']) && !empty($metacriteria['itemtype'])) { $params['itemtype'] = $metacriteria['itemtype']; Ajax::updateItem("show_" . $_POST["itemtype"] . "_" . $_POST["num"] . "_{$rand}", $CFG_GLPI["root_doc"] . "/ajax/updateMetaSearch.php", $params); } echo "</td></tr></table>"; echo "</td></tr>\n"; }
/** * Display choice matrix * * @since version 0.85 * @param $columns array of column field name => column label * @param $rows array of field name => array( * 'label' the label of the row * 'columns' an array of specific information regaring current row and given column indexed by column field_name * * a string if only have to display a string * * an array('value' => ???, 'readonly' => ???) that is used to Dropdown::showYesNo() * @param $options array possible: * 'title' of the matrix * 'first_cell' the content of the upper-left cell * 'row_check_all' set to true to display a checkbox to check all elements of the row * 'col_check_all' set to true to display a checkbox to check all elements of the col * 'rand' random number to use for ids * * @return random value used to generate the ids **/ static function showCheckboxMatrix(array $columns, array $rows, array $options = array()) { $param['title'] = ''; $param['first_cell'] = ' '; $param['row_check_all'] = false; $param['col_check_all'] = false; $param['rotate_column_titles'] = false; $param['rand'] = mt_rand(); $param['table_class'] = 'tab_cadre_fixehov'; $param['cell_class_method'] = NULL; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $param[$key] = $val; } } $cb_options = array('title' => __s('Check/uncheck all')); $number_columns = count($columns) + 1; if ($param['row_check_all']) { $number_columns += 1; } $width = round(100 / $number_columns); echo "\n<table class='" . $param['table_class'] . "'>\n"; if (!empty($param['title'])) { echo "\t<tr>\n"; echo "\t\t<th colspan='{$number_columns}'>" . $param['title'] . "</th>\n"; echo "\t</tr>\n"; } echo "\t<tr class='tab_bg_1'>\n"; echo "\t\t<td>" . $param['first_cell'] . "</td>\n"; foreach ($columns as $col_name => $column) { $nb_cb_per_col[$col_name] = array('total' => 0, 'checked' => 0); $col_id = Html::cleanId('col_label_' . $col_name . '_' . $param['rand']); echo "\t\t<td class='center b"; if ($param['rotate_column_titles']) { echo " rotate"; } echo "' id='{$col_id}' width='{$width}%'>"; if (!is_array($column)) { $columns[$col_name] = $column = array('label' => $column); } if (isset($column['short']) && isset($column['long'])) { echo $column['short']; self::showToolTip($column['long'], array('applyto' => $col_id)); } else { echo $column['label']; } echo "</td>\n"; } if ($param['row_check_all']) { $col_id = Html::cleanId('col_of_table_' . $param['rand']); echo "\t\t<td class='center"; if ($param['rotate_column_titles']) { echo " rotate"; } echo "' id='{$col_id}'>" . __('Select/unselect all') . "</td>\n"; } echo "\t</tr>\n"; foreach ($rows as $row_name => $row) { if (!is_string($row) && !is_array($row)) { continue; } echo "\t<tr class='tab_bg_1'>\n"; if (is_string($row)) { echo "\t\t<th colspan='{$number_columns}'>{$row}</th>\n"; } else { $row_id = Html::cleanId('row_label_' . $row_name . '_' . $param['rand']); if (isset($row['class'])) { $class = $row['class']; } else { $class = ''; } echo "\t\t<td class='b {$class}' id='{$row_id}'>"; if (!empty($row['label'])) { echo $row['label']; } else { echo " "; } echo "</td>\n"; $nb_cb_per_row = array('total' => 0, 'checked' => 0); foreach ($columns as $col_name => $column) { $class = ''; if (!empty($row['class']) && !empty($column['class'])) { if (is_callable($param['cell_class_method'])) { $class = $param['cell_class_method']($row['class'], $column['class']); } } else { if (!empty($row['class'])) { $class = $row['class']; } else { if (!empty($column['class'])) { $class = $column['class']; } } } echo "\t\t<td class='center {$class}'>"; // Warning: isset return false if the value is NULL ... if (array_key_exists($col_name, $row['columns'])) { $content = $row['columns'][$col_name]; if (is_array($content) && array_key_exists('checked', $content)) { if (!array_key_exists('readonly', $content)) { $content['readonly'] = false; } $content['massive_tags'] = array(); if ($param['row_check_all']) { $content['massive_tags'][] = 'row_' . $row_name . '_' . $param['rand']; } if ($param['col_check_all']) { $content['massive_tags'][] = 'col_' . $col_name . '_' . $param['rand']; } if ($param['row_check_all'] && $param['col_check_all']) { $content['massive_tags'][] = 'table_' . $param['rand']; } $content['name'] = $row_name . "[{$col_name}]"; $content['id'] = Html::cleanId('cb_' . $row_name . '_' . $col_name . '_' . $param['rand']); Html::showCheckbox($content); $nb_cb_per_col[$col_name]['total']++; $nb_cb_per_row['total']++; if ($content['checked']) { $nb_cb_per_col[$col_name]['checked']++; $nb_cb_per_row['checked']++; } } else { if (is_string($content)) { echo $content; } else { echo " "; } } } else { echo " "; } echo "</td>\n"; } } if ($param['row_check_all'] && !is_string($row) && $nb_cb_per_row['total'] > 1) { $cb_options['criterion'] = array('tag_for_massive' => 'row_' . $row_name . '_' . $param['rand']); $cb_options['massive_tags'] = 'table_' . $param['rand']; $cb_options['id'] = Html::cleanId('cb_checkall_row_' . $row_name . '_' . $param['rand']); $cb_options['checked'] = $nb_cb_per_row['checked'] > $nb_cb_per_row['total'] / 2; echo "\t\t<td class='center'>" . Html::getCheckbox($cb_options) . "</td>\n"; } echo "\t</tr>\n"; } if ($param['col_check_all']) { echo "\t<tr class='tab_bg_1'>\n"; echo "\t\t<td>" . __('Select/unselect all') . "</td>\n"; foreach ($columns as $col_name => $column) { echo "\t\t<td class='center'>"; if ($nb_cb_per_col[$col_name]['total'] > 1) { $cb_options['criterion'] = array('tag_for_massive' => 'col_' . $col_name . '_' . $param['rand']); $cb_options['massive_tags'] = 'table_' . $param['rand']; $cb_options['id'] = Html::cleanId('cb_checkall_col_' . $col_name . '_' . $param['rand']); $cb_options['checked'] = $nb_cb_per_col[$col_name]['checked'] > $nb_cb_per_col[$col_name]['total'] / 2; echo Html::getCheckbox($cb_options); } else { echo " "; } echo "</td>\n"; } if ($param['row_check_all']) { $cb_options['criterion'] = array('tag_for_massive' => 'table_' . $param['rand']); $cb_options['massive_tags'] = ''; $cb_options['id'] = Html::cleanId('cb_checkall_table_' . $param['rand']); echo "\t\t<td class='center'>" . Html::getCheckbox($cb_options) . "</td>\n"; } echo "\t</tr>\n"; } echo "</table>\n"; return $param['rand']; }
* @brief */ 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 = "getDropdownValue.php"; if ($_POST["idtable"] == 'User') { $link = "getDropdownUsers.php"; } $rand = mt_rand(); $field_id = Html::cleanId("dropdown_" . $_POST["name"] . $rand); $p = array('value' => 0, 'valuename' => Dropdown::EMPTY_VALUE, 'itemtype' => $_POST["idtable"], 'display_emptychoice' => true, 'displaywith' => array('otherserial', 'serial')); if (isset($_POST['value'])) { $p['value'] = $_POST['value']; } if (isset($_POST['entity_restrict'])) { $p['entity_restrict'] = $_POST['entity_restrict']; } if (isset($_POST['condition'])) { $p['condition'] = $_POST['condition']; } echo Html::jsAjaxDropdown($_POST["name"], $field_id, $CFG_GLPI['root_doc'] . "/ajax/" . $link, $p); if (!empty($_POST['showItemSpecificity'])) { $params = array('items_id' => '__VALUE__', 'itemtype' => $_POST["idtable"]); if (isset($_POST['entity_restrict'])) { $params['entity_restrict'] = $_POST['entity_restrict'];
along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ include '../inc/includes.php'; header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); Session::checkLoginUser(); // Make a select box if (isset($_POST["itemtype"]) && CommonITILObject::isPossibleToAssignType($_POST["itemtype"])) { $table = getTableForItemType($_POST["itemtype"]); $rand = mt_rand(); // Message for post-only if (!isset($_POST["admin"]) || $_POST["admin"] == 0) { echo "<br>" . __('Enter the first letters (user, item name, serial or asset number)'); } echo "<br>"; $field_id = Html::cleanId("dropdown_" . $_POST['myname'] . $rand); $p = array('itemtype' => $_POST["itemtype"], 'entity_restrict' => $_POST['entity_restrict'], 'table' => $table, 'myname' => $_POST["myname"]); if (isset($_POST["used"]) && !empty($_POST["used"])) { if (isset($_POST["used"][$_POST["itemtype"]])) { $p["used"] = $_POST["used"][$_POST["itemtype"]]; } } echo Html::jsAjaxDropdown($_POST['myname'], $field_id, $CFG_GLPI['root_doc'] . "/ajax/getDropdownFindNum.php", $p); // Auto update summary of active or just solved tickets $params = array('items_id' => '__VALUE__', 'itemtype' => $_POST['itemtype']); Ajax::updateItemOnSelectEvent($field_id, "item_ticket_selection_information", $CFG_GLPI["root_doc"] . "/ajax/ticketiteminformation.php", $params); }
public static function dropdown($options = array()) { global $DB, $CFG_GLPI; $params['itemtype_name'] = 'itemtype'; $params['items_id_name'] = 'items_id'; $params['itemtypes'] = array(); $params['default_itemtype'] = 0; $params['entity_restrict'] = -1; $params['onlyglobal'] = false; $params['checkright'] = false; $params['showItemSpecificity'] = ''; $params['emptylabel'] = ''; //$p['entity'] = ''; if (is_array($options) && count($options)) { foreach ($options as $key => $val) { $p[$key] = $val; } } $rand = mt_rand(); $query = "select id, name from glpi_plugin_relation_typerelations order by 1"; $result = $DB->query($query); $type_relations = "type_relations" . $p['name']; //Desplegable tipos de relaciones echo "<select name='_nombresrelaciones' id='nombresrelaciones'>\n"; if ($DB->numrows($result)) { while ($data = $DB->fetch_array($result)) { echo "<option value='" . $data[0] . "'>" . $data[1] . "</option>\n"; } } echo "</select>\n"; //Desplegable de las clases $query = "select rc.id, rc.classlist, c.viewname FROM glpi_plugin_relation_relationclases rc, glpi_plugin_relation_clases c where rc.classlist=c.name and classname='" . $p['itemtype'] . "' order by 1"; //echo $query; $result = $DB->query($query); $arraySelect = array(); if ($DB->numrows($result)) { while ($data = $DB->fetch_array($result)) { $arraySelect[] = $data[1]; } $params['itemtypes'] = $arraySelect; } $rand = Dropdown::showItemType($params['itemtypes'], array('checkright' => $params['checkright'], 'name' => $params['itemtype_name'], 'emptylabel' => $params['emptylabel'])); if ($rand) { $p = array('idtable' => '__VALUE__', 'name' => $params['items_id_name'], 'entity_restrict' => $params['entity_restrict'], 'width' => '120', 'display_emptychoice' => true, 'showItemSpecificity' => $params['showItemSpecificity']); if ($params['onlyglobal']) { $p['condition'] = "`is_global` = 1"; } $field_id = Html::cleanId("dropdown_" . $params['itemtype_name'] . $rand); $show_id = Html::cleanId("show_" . $params['items_id_name'] . $rand); Ajax::updateItemOnSelectEvent($field_id, $show_id, $CFG_GLPI["root_doc"] . "/plugins/relation/ajax/dropdownAllItems.php", $p); echo "<br><span id='{$show_id}'> </span>\n"; // We check $options as the caller will set $options['default_itemtype'] only if it needs a // default itemtype and the default value can be '' thus empty won't be valid ! if (array_key_exists('default_itemtype', $options)) { echo "<script type='text/javascript' >\n"; echo Html::jsSetDropdownValue($field_id, $params['default_itemtype']); echo "</script>\n"; $p["idtable"] = $params['default_itemtype']; Ajax::updateItem($show_id, $CFG_GLPI["root_doc"] . "/plugins/relation/ajax/dropdownAllItems.php", $p); } } return $rand; }