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);
}