Check if it's possible to assign ITIL object to a type (core or plugin)
static public isPossibleToAssignType ( $itemtype ) : true | ||
$itemtype | the object's type | |
return | true | if ticket can be assign to this type, false if not |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief */ include '../inc/includes.php'; header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); Session::checkLoginUser(); // Make a select box if (isset($_POST["itemtype"]) && CommonITILObject::isPossibleToAssignType($_POST["itemtype"])) { $table = getTableForItemType($_POST["itemtype"]); $rand = mt_rand(); // Message for post-only if (!isset($_POST["admin"]) || $_POST["admin"] == 0) { echo "<br>" . __('Enter the first letters (user, item name, serial or asset number)'); } echo "<br>"; $field_id = Html::cleanId("dropdown_" . $_POST['myname'] . $rand); $p = array('itemtype' => $_POST["itemtype"], 'entity_restrict' => $_POST['entity_restrict'], 'table' => $table, 'myname' => $_POST["myname"]); if (isset($_POST["used"]) && !empty($_POST["used"])) { if (isset($_POST["used"][$_POST["itemtype"]])) { $p["used"] = $_POST["used"][$_POST["itemtype"]]; } } echo Html::jsAjaxDropdown($_POST['myname'], $field_id, $CFG_GLPI['root_doc'] . "/ajax/getDropdownFindNum.php", $p);
/** * Make a select box for Ticket my devices * * @param $userID User ID for my device section (default 0) * @param $entity_restrict restrict to a specific entity (default -1) * @param $itemtype of selected item (default 0) * @param $items_id of selected item (default 0) * * @return nothing (print out an HTML select box) **/ static function dropdownMyDevices($userID = 0, $entity_restrict = -1, $itemtype = 0, $items_id = 0) { global $DB, $CFG_GLPI; if ($userID == 0) { $userID = Session::getLoginUserID(); } $rand = mt_rand(); $already_add = array(); if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] & pow(2, self::HELPDESK_MY_HARDWARE)) { $my_devices = ""; $my_item = $itemtype . '_' . $items_id; // My items foreach ($CFG_GLPI["linkuser_types"] as $itemtype) { if (($item = getItemForItemtype($itemtype)) && parent::isPossibleToAssignType($itemtype)) { $itemtable = getTableForItemType($itemtype); $query = "SELECT *\n FROM `{$itemtable}`\n WHERE `users_id` = '{$userID}'"; if ($item->maybeDeleted()) { $query .= " AND `is_deleted` = '0' "; } if ($item->maybeTemplate()) { $query .= " AND `is_template` = '0' "; } if (in_array($itemtype, $CFG_GLPI["helpdesk_visible_types"])) { $query .= " AND `is_helpdesk_visible` = '1' "; } $query .= getEntitiesRestrictRequest("AND", $itemtable, "", $entity_restrict, $item->maybeRecursive()) . "\n ORDER BY `name` "; $result = $DB->query($query); $nb = $DB->numrows($result); if ($DB->numrows($result) > 0) { $type_name = $item->getTypeName($nb); while ($data = $DB->fetch_assoc($result)) { $output = $data["name"]; if (empty($output) || $_SESSION["glpiis_ids_visible"]) { $output = sprintf(__('%1$s (%2$s)'), $output, $data['id']); } $output = sprintf(__('%1$s - %2$s'), $type_name, $output); if ($itemtype != 'Software') { if (!empty($data['serial'])) { $output = sprintf(__('%1$s - %2$s'), $output, $data['serial']); } if (!empty($data['otherserial'])) { $output = sprintf(__('%1$s - %2$s'), $output, $data['otherserial']); } } $my_devices .= "<option title=\"{$output}\" value='" . $itemtype . "_" . $data["id"] . "' " . ($my_item == $itemtype . "_" . $data["id"] ? "selected" : "") . ">" . Toolbox::substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>"; $already_add[$itemtype][] = $data["id"]; } } } } if (!empty($my_devices)) { $my_devices = "<optgroup label=\"" . __s('My devices') . "\">" . $my_devices . "</optgroup>"; } // My group items if (Session::haveRight("show_group_hardware", "1")) { $group_where = ""; $query = "SELECT `glpi_groups_users`.`groups_id`, `glpi_groups`.`name`\n FROM `glpi_groups_users`\n LEFT JOIN `glpi_groups`\n ON (`glpi_groups`.`id` = `glpi_groups_users`.`groups_id`)\n WHERE `glpi_groups_users`.`users_id` = '{$userID}' " . getEntitiesRestrictRequest("AND", "glpi_groups", "", $entity_restrict, true); $result = $DB->query($query); $first = true; if ($DB->numrows($result) > 0) { while ($data = $DB->fetch_assoc($result)) { if ($first) { $first = false; } else { $group_where .= " OR "; } $a_groups = getAncestorsOf("glpi_groups", $data["groups_id"]); $a_groups[$data["groups_id"]] = $data["groups_id"]; $group_where .= " `groups_id` IN (" . implode(',', $a_groups) . ") "; } $tmp_device = ""; foreach ($CFG_GLPI["linkgroup_types"] as $itemtype) { if (($item = getItemForItemtype($itemtype)) && parent::isPossibleToAssignType($itemtype)) { $itemtable = getTableForItemType($itemtype); $query = "SELECT *\n FROM `{$itemtable}`\n WHERE ({$group_where}) " . getEntitiesRestrictRequest("AND", $itemtable, "", $entity_restrict, $item->maybeRecursive()); if ($item->maybeDeleted()) { $query .= " AND `is_deleted` = '0' "; } if ($item->maybeTemplate()) { $query .= " AND `is_template` = '0' "; } $result = $DB->query($query); if ($DB->numrows($result) > 0) { $type_name = $item->getTypeName(); if (!isset($already_add[$itemtype])) { $already_add[$itemtype] = array(); } while ($data = $DB->fetch_assoc($result)) { if (!in_array($data["id"], $already_add[$itemtype])) { $output = ''; if (isset($data["name"])) { $output = $data["name"]; } if (empty($output) || $_SESSION["glpiis_ids_visible"]) { $output = sprintf(__('%1$s (%2$s)'), $output, $data['id']); } $output = sprintf(__('%1$s - %2$s'), $type_name, $output); if (isset($data['serial'])) { $output = sprintf(__('%1$s - %2$s'), $output, $data['serial']); } if (isset($data['otherserial'])) { $output = sprintf(__('%1$s - %2$s'), $output, $data['otherserial']); } $tmp_device .= "<option title=\"{$output}\" value='" . $itemtype . "_" . $data["id"] . "' " . ($my_item == $itemtype . "_" . $data["id"] ? "selected" : "") . ">" . Toolbox::substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>"; $already_add[$itemtype][] = $data["id"]; } } } } } if (!empty($tmp_device)) { $my_devices .= "<optgroup label=\"" . __s('Devices own by my groups') . "\">" . $tmp_device . "</optgroup>"; } } } // Get linked items to computers if (isset($already_add['Computer']) && count($already_add['Computer'])) { $search_computer = " XXXX IN (" . implode(',', $already_add['Computer']) . ') '; $tmp_device = ""; // Direct Connection $types = array('Monitor', 'Peripheral', 'Phone', 'Printer'); foreach ($types as $itemtype) { if (in_array($itemtype, $_SESSION["glpiactiveprofile"]["helpdesk_item_type"]) && ($item = getItemForItemtype($itemtype))) { $itemtable = getTableForItemType($itemtype); if (!isset($already_add[$itemtype])) { $already_add[$itemtype] = array(); } $query = "SELECT DISTINCT `{$itemtable}`.*\n FROM `glpi_computers_items`\n LEFT JOIN `{$itemtable}`\n ON (`glpi_computers_items`.`items_id` = `{$itemtable}`.`id`)\n WHERE `glpi_computers_items`.`itemtype` = '{$itemtype}'\n AND " . str_replace("XXXX", "`glpi_computers_items`.`computers_id`", $search_computer); if ($item->maybeDeleted()) { $query .= " AND `{$itemtable}`.`is_deleted` = '0' "; } if ($item->maybeTemplate()) { $query .= " AND `{$itemtable}`.`is_template` = '0' "; } $query .= getEntitiesRestrictRequest("AND", $itemtable, "", $entity_restrict) . "\n ORDER BY `{$itemtable}`.`name`"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { $type_name = $item->getTypeName(); while ($data = $DB->fetch_assoc($result)) { if (!in_array($data["id"], $already_add[$itemtype])) { $output = $data["name"]; if (empty($output) || $_SESSION["glpiis_ids_visible"]) { $output = sprintf(__('%1$s (%2$s)'), $output, $data['id']); } $output = sprintf(__('%1$s - %2$s'), $type_name, $output); if ($itemtype != 'Software') { $output = sprintf(__('%1$s - %2$s'), $output, $data['otherserial']); } $tmp_device .= "<option title=\"{$output}\" value='" . $itemtype . "_" . $data["id"] . "' " . ($my_item == $itemtype . "_" . $data["id"] ? "selected" : "") . ">" . Toolbox::substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>"; $already_add[$itemtype][] = $data["id"]; } } } } } if (!empty($tmp_device)) { $my_devices .= "<optgroup label=\"" . __s('Connected devices') . "\">" . $tmp_device . "</optgroup>"; } // Software if (in_array('Software', $_SESSION["glpiactiveprofile"]["helpdesk_item_type"])) { $query = "SELECT DISTINCT `glpi_softwareversions`.`name` AS version,\n `glpi_softwares`.`name` AS name, `glpi_softwares`.`id`\n FROM `glpi_computers_softwareversions`, `glpi_softwares`,\n `glpi_softwareversions`\n WHERE `glpi_computers_softwareversions`.`softwareversions_id` =\n `glpi_softwareversions`.`id`\n AND `glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`\n AND " . str_replace("XXXX", "`glpi_computers_softwareversions`.`computers_id`", $search_computer) . "\n AND `glpi_softwares`.`is_helpdesk_visible` = '1' " . getEntitiesRestrictRequest("AND", "glpi_softwares", "", $entity_restrict) . "\n ORDER BY `glpi_softwares`.`name`"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { $tmp_device = ""; $item = new Software(); $type_name = $item->getTypeName(); if (!isset($already_add['Software'])) { $already_add['Software'] = array(); } while ($data = $DB->fetch_assoc($result)) { if (!in_array($data["id"], $already_add['Software'])) { $output = sprintf(__('%1$s - %2$s'), $type_name, $data["name"]); $output = sprintf(__('%1$s (%2$s)'), $output, sprintf(__('%1$s: %2$s'), __('version'), $data["version"])); if ($_SESSION["glpiis_ids_visible"]) { $output = sprintf(__('%1$s (%2$s)'), $output, $data["id"]); } $tmp_device .= "<option title=\"{$output}\" value='Software_" . $data["id"] . "' " . ($my_item == 'Software' . "_" . $data["id"] ? "selected" : "") . ">" . Toolbox::substr($output, 0, $_SESSION["glpidropdown_chars_limit"]) . "</option>"; $already_add['Software'][] = $data["id"]; } } if (!empty($tmp_device)) { $my_devices .= "<optgroup label=\"" . _sn('Installed software', 'Installed software', 2) . "\">"; $my_devices .= $tmp_device . "</optgroup>"; } } } } echo "<div id='tracking_my_devices'>"; echo "<select id='my_items' name='_my_items'>"; echo "<option value=''>--- "; echo __('General') . " ---</option>{$my_devices}</select></div>"; // Auto update summary of active or just solved tickets $params = array('my_items' => '__VALUE__'); Ajax::updateItemOnSelectEvent("my_items", "item_ticket_selection_information", $CFG_GLPI["root_doc"] . "/ajax/ticketiteminformation.php", $params); } }