show a dropdown to selec a type
static public showItemType ( $types = '', $options = [] ) : integer | ||
$types | Types used (default "state_types") (default '') | |
$options | Array of optional options name, value, rand, emptylabel, display_emptychoice, on_change, plural, checkright - 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) | |
Результат | integer | rand for select id |
function preaddRule($componentscatalogs_id) { global $CFG_GLPI, $DB; $networkport_types = $CFG_GLPI['networkport_types']; $networkport_types[] = "PluginMonitoringNetworkport"; $a_usedItemtypes = array(); $query = "SELECT * FROM `" . $this->getTable() . "`\n WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscatalogs_id . "'"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $key = array_search($data['itemtype'], $networkport_types); if (isset($key)) { unset($networkport_types[$key]); } } if (count($a_usedItemtypes) == count($networkport_types)) { return; } $this->getEmpty(); $this->showFormHeader(); echo "<tr class='tab_bg_1'>"; echo "<td>"; echo __('Name') . " :"; echo "</td>"; echo "<td>"; echo "<input type='text' name='name' value=''/>"; echo "</td>"; echo "<td>"; echo __('Item type') . " :"; echo "</td>"; echo "<td>"; Dropdown::showItemType($networkport_types); echo "<input type='hidden' name='plugin_monitoring_componentscalalog_id' value='" . $componentscatalogs_id . "' >"; echo "</td>"; echo "</tr>"; $this->showFormButtons(); }
/** * Show items for the group * * @param $tech boolean false search groups_id, true, search groups_id_tech **/ function showItems($tech) { global $DB, $CFG_GLPI; $rand = mt_rand(); $ID = $this->fields['id']; if ($tech) { $types = $CFG_GLPI['linkgroup_tech_types']; $field = 'groups_id_tech'; $title = __('Managed items'); } else { $types = $CFG_GLPI['linkgroup_types']; $field = 'groups_id'; $title = __('Used items'); } $tree = Session::getSavedOption(__CLASS__, 'tree', 0); $user = Session::getSavedOption(__CLASS__, 'user', 0); $type = Session::getSavedOption(__CLASS__, 'onlytype', ''); if (!in_array($type, $types)) { $type = ''; } echo "<div class='spaced'>"; // Mini Search engine echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='3'>{$title}</tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; echo __('Type') . " "; Dropdown::showItemType($types, array('value' => $type, 'name' => 'onlytype', 'plural' => true, 'on_change' => 'reloadTab("start=0&onlytype="+this.value)', 'checkright' => true)); if ($this->haveChildren()) { echo "</td><td class='center'>" . __('Child groups') . " "; Dropdown::showYesNo('tree', $tree, -1, array('on_change' => 'reloadTab("start=0&tree="+this.value)')); } else { $tree = 0; } if ($this->getField('is_usergroup')) { echo "</td><td class='center'>" . User::getTypeName(Session::getPluralNumber()) . " "; Dropdown::showYesNo('user', $user, -1, array('on_change' => 'reloadTab("start=0&user="******"</td></tr></table>"; $datas = array(); if ($type) { $types = array($type); } $start = isset($_GET['start']) ? intval($_GET['start']) : 0; $nb = $this->getDataItems($types, $field, $tree, $user, $start, $datas); $nbcan = 0; if ($nb) { Html::printAjaxPager('', $start, $nb); Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); echo Html::hidden('field', array('value' => $field, 'data-glpicore-ma-tags' => 'common')); $massiveactionparams = array('num_displayed' => $nb, 'check_itemtype' => 'Group', 'check_items_id' => $ID, 'container' => 'mass' . __CLASS__ . $rand, 'extraparams' => array('is_tech' => $tech, 'massive_action_fields' => array('field')), 'specific_actions' => array(__CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'changegroup' => __('Move'))); Html::showMassiveActions($massiveactionparams); echo "<table class='tab_cadre_fixehov'>"; $header_begin = "<tr><th width='10'>"; $header_top = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom = Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_end = '</th>'; $header_end .= "<th>" . __('Type') . "</th><th>" . __('Name') . "</th><th>" . __('Entity') . "</th>"; if ($tree || $user) { $header_end .= "<th>" . sprintf(__('%1$s / %2$s'), self::getTypeName(1), User::getTypeName(1)) . "</th>"; } $header_end .= "</tr>"; echo $header_begin . $header_top . $header_end; $tuser = new User(); $group = new Group(); foreach ($datas as $data) { if (!($item = getItemForItemtype($data['itemtype']))) { continue; } echo "<tr class='tab_bg_1'><td>"; if ($item->canEdit($data['items_id'])) { Html::showMassiveActionCheckBox($data['itemtype'], $data['items_id']); } echo "</td><td>" . $item->getTypeName(1); echo "</td><td>" . $item->getLink(array('comments' => true)); echo "</td><td>" . Dropdown::getDropdownName("glpi_entities", $item->getEntityID()); if ($tree || $user) { echo "</td><td>"; if ($grp = $item->getField($field)) { if ($group->getFromDB($grp)) { echo $group->getLink(array('comments' => true)); } } else { if ($usr = $item->getField(str_replace('groups', 'users', $field))) { if ($tuser->getFromDB($usr)) { echo $tuser->getLink(array('comments' => true)); } } } } echo "</td></tr>"; } echo $header_begin . $header_bottom . $header_end; echo "</table>"; } else { echo "<p class='center b'>" . __('No item found') . "</p>"; } if ($nb) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); } Html::closeForm(); if ($nb) { Html::printAjaxPager('', $start, $nb); } echo "</div>"; }
/** * Make a select box for connections * * @since version 0.84 * * @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 dropdownAllConnect($fromtype, $myname, $entity_restrict = -1, $onlyglobal = 0, $used = array()) { global $CFG_GLPI; $rand = mt_rand(); $options = array(); $options['checkright'] = true; $options['name'] = 'itemtype'; $rand = Dropdown::showItemType($CFG_GLPI['directconnect_types'], $options); if ($rand) { $params = array('itemtype' => '__VALUE__', 'fromtype' => $fromtype, 'value' => 0, 'myname' => $myname, 'onlyglobal' => $onlyglobal, 'entity_restrict' => $entity_restrict, 'used' => $used); if ($onlyglobal) { $params['condition'] = "`is_global` = '1'"; } Ajax::updateItemOnSelectEvent("dropdown_itemtype{$rand}", "show_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/ajax/dropdownConnect.php", $params); echo "<br><div id='show_{$myname}{$rand}'> </div>\n"; } return $rand; }
/** * Print the HTML array of items for a location * * @since version 0.85 * * @return Nothing (display) **/ function showItems() { global $DB, $CFG_GLPI; $locations_id = $this->fields['id']; $crit = Session::getSavedOption(__CLASS__, 'criterion', ''); if (!$this->can($locations_id, READ)) { return false; } $first = 1; $query = ''; if ($crit) { $table = getTableForItemType($crit); $query = "SELECT `{$table}`.`id`, '{$crit}' AS type\n FROM `{$table}`\n WHERE `{$table}`.`locations_id` = '{$locations_id}' " . getEntitiesRestrictRequest(" AND", $table, "entities_id"); } else { foreach ($CFG_GLPI['location_types'] as $type) { $table = getTableForItemType($type); $query .= ($first ? "SELECT " : " UNION SELECT ") . "`id`, '{$type}' AS type\n FROM `{$table}`\n WHERE `{$table}`.`locations_id` = '{$locations_id}' " . getEntitiesRestrictRequest(" AND", $table, "entities_id"); $first = 0; } } $result = $DB->query($query); $number = $DB->numrows($result); $start = isset($_REQUEST['start']) ? intval($_REQUEST['start']) : 0; if ($start >= $number) { $start = 0; } // Mini Search engine echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_1'><th colspan='2'>" . __('Type') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; echo __('Type') . " "; Dropdown::showItemType($CFG_GLPI['location_types'], array('value' => $crit, 'on_change' => 'reloadTab("start=0&criterion="+this.value)')); echo "</td></tr></table>"; if ($number) { echo "<div class='spaced'>"; Html::printAjaxPager('', $start, $number); echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('Type') . "</th>"; echo "<th>" . __('Entity') . "</th>"; echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Serial number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "</tr>"; $DB->data_seek($result, $start); for ($row = 0; ($data = $DB->fetch_assoc($result)) && $row < $_SESSION['glpilist_limit']; $row++) { $item = getItemForItemtype($data['type']); $item->getFromDB($data['id']); echo "<tr class='tab_bg_1'><td class='center top'>" . $item->getTypeName() . "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $item->getEntityID()); echo "</td><td class='center'>" . $item->getLink() . "</td>"; echo "<td class='center'>" . (isset($item->fields["serial"]) ? "" . $item->fields["serial"] . "" : "-"); echo "</td>"; echo "<td class='center'>" . (isset($item->fields["otherserial"]) ? "" . $item->fields["otherserial"] . "" : "-"); echo "</td></tr>"; } } else { echo "<p class='center b'>" . __('No item found') . "</p>"; } echo "</table></div>"; }
/** * Make a select box for connections * * @since version 0.84 * * @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 dropdownAllConnect($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; // } // } $options = array(); $options['checkright'] = true; $options['name'] = 'itemtype'; $rand = Dropdown::showItemType($CFG_GLPI['directconnect_types'], $options); if ($rand) { $params = array('itemtype' => '__VALUE__', 'fromtype' => $fromtype, 'value' => 0, 'myname' => $myname, 'onlyglobal' => $onlyglobal, 'entity_restrict' => $entity_restrict, 'used' => $used); if ($onlyglobal) { $params['condition'] = "`is_global` = '1'"; } Ajax::updateItemOnSelectEvent("itemtype{$rand}", "show_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/ajax/dropdownConnect.php", $params); echo "<br><span id='show_{$myname}{$rand}'> </span>\n"; } return $rand; }
/** * 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; }
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; }