/** * Make a select box for Tracking All Devices * * @param $myname select name * @param $itemtype preselected value.for item type * @param $items_id preselected value for item ID (default 0) * @param $admin is an admin access ? (default 0) * @param $users_id user ID used to display my devices (default 0 * @param $entity_restrict Restrict to a defined entity (default -1) * * @return nothing (print out an HTML select box) **/ static function dropdownAllDevices($myname, $itemtype, $items_id = 0, $admin = 0, $users_id = 0, $entity_restrict = -1) { global $CFG_GLPI, $DB; $rand = mt_rand(); if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] == 0) { echo "<input type='hidden' name='{$myname}' value='0'>"; echo "<input type='hidden' name='items_id' value='0'>"; } else { echo "<div id='tracking_all_devices'>"; if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] & pow(2, self::HELPDESK_ALL_HARDWARE)) { // Display a message if view my hardware if ($users_id && $_SESSION["glpiactiveprofile"]["helpdesk_hardware"] & pow(2, self::HELPDESK_MY_HARDWARE)) { echo __('Or complete search') . " "; } $types = parent::getAllTypesForHelpdesk(); echo "<select id='search_{$myname}{$rand}' name='{$myname}'>\n"; echo "<option value='-1' >" . Dropdown::EMPTY_VALUE . "</option>\n"; echo "<option value='' " . (empty($itemtype) || $itemtype === 0 ? " selected" : "") . ">" . __('General') . "</option>"; $found_type = false; foreach ($types as $type => $label) { if (strcmp($type, $itemtype) == 0) { $found_type = true; } echo "<option value='" . $type . "' " . (strcmp($type, $itemtype) == 0 ? " selected" : "") . ">" . $label . "</option>\n"; } echo "</select>"; $params = array('itemtype' => '__VALUE__', 'entity_restrict' => $entity_restrict, 'admin' => $admin, 'myname' => "items_id"); Ajax::updateItemOnSelectEvent("search_{$myname}{$rand}", "results_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/ajax/dropdownTrackingDeviceType.php", $params); echo "<span id='results_{$myname}{$rand}'>\n"; // Display default value if itemtype is displayed if ($found_type && $itemtype) { if (($item = getItemForItemtype($itemtype)) && $items_id) { if ($item->getFromDB($items_id)) { echo "<select name='items_id'>\n"; echo "<option value='{$items_id}'>" . $item->getName() . "</option>"; echo "</select>"; } } else { $params['itemtype'] = $itemtype; echo "<script type='text/javascript' >\n"; Ajax::updateItemJsCode("results_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/ajax/dropdownTrackingDeviceType.php", $params); echo '</script>'; } } echo "</span>\n"; } echo "</div>"; } return $rand; }