Item_Ticket::dropdown PHP Method

dropdown() static public method

Make a select box with all glpi items
static public dropdown ( $options = [] )
$options array of possible options: - name : string / name of the select (default is users_id) - value - 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) - 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) - on_change : string / value to transmit to "onChange" - display : boolean / display or get string (default true) - width : specific width needed (default 80%)
    static function dropdown($options = array())
    {
        global $DB;
        // Default values
        $p['name'] = 'items';
        $p['value'] = '';
        $p['all'] = 0;
        $p['on_change'] = '';
        $p['comments'] = 1;
        $p['width'] = '80%';
        $p['entity'] = -1;
        $p['entity_sons'] = false;
        $p['used'] = array();
        $p['toupdate'] = '';
        $p['rand'] = mt_rand();
        $p['display'] = true;
        if (is_array($options) && count($options)) {
            foreach ($options as $key => $val) {
                $p[$key] = $val;
            }
        }
        $itemtypes = array('Computer', 'Monitor', 'NetworkEquipment', 'Peripheral', 'Phone', 'Printer');
        $query = "";
        foreach ($itemtypes as $type) {
            $table = getTableForItemType($type);
            if (!empty($query)) {
                $query .= " UNION ";
            }
            $query .= " SELECT `{$table}`.`id` AS id , '{$type}' AS itemtype , `{$table}`.`name` AS name\n                     FROM `{$table}`\n                     WHERE `{$table}`.`id` IS NOT NULL AND `{$table}`.`is_deleted` = '0' AND `{$table}`.`is_template` = '0' ";
        }
        $result = $DB->query($query);
        $output = array();
        if ($DB->numrows($result) > 0) {
            while ($data = $DB->fetch_assoc($result)) {
                $item = getItemForItemtype($data['itemtype']);
                $output[$data['itemtype'] . "_" . $data['id']] = $item->getTypeName() . " - " . $data['name'];
            }
        }
        return Dropdown::showFromArray($p['name'], $output, $p);
    }