/**
* 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)
* - used : array / Already used items ID: not to display in dropdown (default empty)
*
* @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['emptylabel'] = self::EMPTY_VALUE;
$params['used'] = array();
if (is_array($options) && count($options)) {
foreach ($options as $key => $val) {
$params[$key] = $val;
}
}
$rand = self::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']);
// manage condition
if ($params['onlyglobal']) {
$p['condition'] = static::addNewCondition("`is_global` = 1");
}
if ($params['used']) {
$p['used'] = $params['used'];
}
$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"] . "/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;
}