"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "inc/item_ticket.class.php" between
glpi-9.3.3.tgz and glpi-9.4.0.tgz

About: GLPI is an IT and asset management software (Information Resource Manager).

item_ticket.class.php  (glpi-9.3.3.tgz):item_ticket.class.php  (glpi-9.4.0.tgz)
skipping to change at line 467 skipping to change at line 467
$iterator = self::getTypeItems($instID, $itemtype); $iterator = self::getTypeItems($instID, $itemtype);
$nb = count($iterator); $nb = count($iterator);
$prem = true; $prem = true;
while ($data = $iterator->next()) { while ($data = $iterator->next()) {
$name = $data["name"]; $name = $data["name"];
if ($_SESSION["glpiis_ids_visible"] if ($_SESSION["glpiis_ids_visible"]
|| empty($data["name"])) { || empty($data["name"])) {
$name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]); $name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]);
} }
if (Session::getCurrentInterface() != 'helpdesk') { if ((Session::getCurrentInterface() != 'helpdesk') && $item::canV iew()) {
$link = $itemtype::getFormURLWithID($data['id']); $link = $itemtype::getFormURLWithID($data['id']);
$namelink = "<a href=\"".$link."\">".$name."</a>"; $namelink = "<a href=\"".$link."\">".$name."</a>";
} else { } else {
$namelink = $name; $namelink = $name;
} }
echo "<tr class='tab_bg_1'>"; echo "<tr class='tab_bg_1'>";
if ($canedit) { if ($canedit) {
echo "<td width='10'>"; echo "<td width='10'>";
Html::showMassiveActionCheckBox(__CLASS__, $data["linkid"]); Html::showMassiveActionCheckBox(__CLASS__, $data["linkid"]);
skipping to change at line 687 skipping to change at line 687
if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"]&pow(2, Ticket::HEL PDESK_MY_HARDWARE)) { if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"]&pow(2, Ticket::HEL PDESK_MY_HARDWARE)) {
$my_devices = ['' => Dropdown::EMPTY_VALUE]; $my_devices = ['' => Dropdown::EMPTY_VALUE];
$devices = []; $devices = [];
// My items // My items
foreach ($CFG_GLPI["linkuser_types"] as $itemtype) { foreach ($CFG_GLPI["linkuser_types"] as $itemtype) {
if (($item = getItemForItemtype($itemtype)) if (($item = getItemForItemtype($itemtype))
&& Ticket::isPossibleToAssignType($itemtype)) { && Ticket::isPossibleToAssignType($itemtype)) {
$itemtable = getTableForItemType($itemtype); $itemtable = getTableForItemType($itemtype);
$query = "SELECT * $criteria = [
FROM `$itemtable` 'FROM' => $itemtable,
WHERE `users_id` = '$userID'"; 'WHERE' => [
'users_id' => $userID
] + getEntitiesRestrictCriteria($itemtable, '', $entity_restri
ct, $item->maybeRecursive()),
'ORDER' => 'name'
];
if ($item->maybeDeleted()) { if ($item->maybeDeleted()) {
$query .= " AND `$itemtable`.`is_deleted` = 0 "; $criteria['WHERE']['is_deleted'] = 0;
} }
if ($item->maybeTemplate()) { if ($item->maybeTemplate()) {
$query .= " AND `$itemtable`.`is_template` = 0 "; $criteria['WHERE']['is_template'] = 0;
} }
if (in_array($itemtype, $CFG_GLPI["helpdesk_visible_types"])) { if (in_array($itemtype, $CFG_GLPI["helpdesk_visible_types"])) {
$query .= " AND `is_helpdesk_visible` = 1 "; $criteria['WHERE']['is_helpdesk_visible'] = 1;
} }
$query .= getEntitiesRestrictRequest("AND", $itemtable, "", $enti $iterator = $DB->request($criteria);
ty_restrict, $nb = count($iterator);
$item->maybeRecursive())." if ($nb > 0) {
ORDER BY `name` ";
$result = $DB->query($query);
$nb = $DB->numrows($result);
if ($DB->numrows($result) > 0) {
$type_name = $item->getTypeName($nb); $type_name = $item->getTypeName($nb);
while ($data = $DB->fetch_assoc($result)) { while ($data = $iterator->next()) {
if (!isset($already_add[$itemtype]) || !in_array($data["id" ], $already_add[$itemtype])) { if (!isset($already_add[$itemtype]) || !in_array($data["id" ], $already_add[$itemtype])) {
$output = $data["name"]; $output = $data["name"];
if (empty($output) || $_SESSION["glpiis_ids_visible"]) { if (empty($output) || $_SESSION["glpiis_ids_visible"]) {
$output = sprintf(__('%1$s (%2$s)'), $output, $data[' id']); $output = sprintf(__('%1$s (%2$s)'), $output, $data[' id']);
} }
$output = sprintf(__('%1$s - %2$s'), $type_name, $output ); $output = sprintf(__('%1$s - %2$s'), $type_name, $output );
if ($itemtype != 'Software') { if ($itemtype != 'Software') {
if (!empty($data['serial'])) { if (!empty($data['serial'])) {
$output = sprintf(__('%1$s - %2$s'), $output, $dat a['serial']); $output = sprintf(__('%1$s - %2$s'), $output, $dat a['serial']);
} }
skipping to change at line 739 skipping to change at line 739
} }
} }
} }
} }
if (count($devices)) { if (count($devices)) {
$my_devices[__('My devices')] = $devices; $my_devices[__('My devices')] = $devices;
} }
// My group items // My group items
if (Session::haveRight("show_group_hardware", "1")) { if (Session::haveRight("show_group_hardware", "1")) {
$group_where = ""; $iterator = $DB->request([
$query = "SELECT `glpi_groups_users`.`groups_id`, `glpi_groups 'SELECT' => [
`.`name` 'glpi_groups_users.groups_id',
FROM `glpi_groups_users` 'glpi_groups.name'
LEFT JOIN `glpi_groups` ],
ON (`glpi_groups`.`id` = `glpi_groups_users`.`grou 'FROM' => 'glpi_groups_users',
ps_id`) 'LEFT JOIN' => [
WHERE `glpi_groups_users`.`users_id` = '$userID' ". 'glpi_groups' => [
getEntitiesRestrictRequest("AND", "glpi_groups 'ON' => [
", "", 'glpi_groups_users' => 'groups_id',
$entity_restrict, t 'glpi_groups' => 'id'
rue); ]
$result = $DB->query($query); ]
],
'WHERE' => [
'glpi_groups_users.users_id' => $userID
] + getEntitiesRestrictCriteria('glpi_groups', '', $entity_restri
ct, true)
]);
$first = true;
$devices = []; $devices = [];
if ($DB->numrows($result) > 0) { $groups = [];
while ($data = $DB->fetch_assoc($result)) { if (count($iterator)) {
if ($first) { while ($data = $iterator->next()) {
$first = false;
} else {
$group_where .= " OR ";
}
$a_groups = getAncestorsOf("glpi_groups", $data["groups_id"]); $a_groups = getAncestorsOf("glpi_groups", $data["groups_id"]);
$a_groups[$data["groups_id"]] = $data["groups_id"]; $a_groups[$data["groups_id"]] = $data["groups_id"];
$group_where .= " `groups_id` IN (".implode(', ', $a_groups).") "; $groups = array_merge($groups, $a_groups);
} }
foreach ($CFG_GLPI["linkgroup_types"] as $itemtype) { foreach ($CFG_GLPI["linkgroup_types"] as $itemtype) {
if (($item = getItemForItemtype($itemtype)) if (($item = getItemForItemtype($itemtype))
&& Ticket::isPossibleToAssignType($itemtype)) { && Ticket::isPossibleToAssignType($itemtype)) {
$itemtable = getTableForItemType($itemtype); $itemtable = getTableForItemType($itemtype);
$query = "SELECT * $criteria = [
FROM `$itemtable` 'FROM' => $itemtable,
WHERE ($group_where) ". 'WHERE' => [
getEntitiesRestrictRequest("AND", $ite 'groups_id' => $groups
mtable, "", ] + getEntitiesRestrictCriteria($itemtable, '', $entity_
$entity_res restrict, $item->maybeRecursive()),
trict, 'ORDER' => 'name'
$item->mayb ];
eRecursive());
if ($item->maybeDeleted()) { if ($item->maybeDeleted()) {
$query .= " AND `is_deleted` = 0 "; $criteria['WHERE']['is_deleted'] = 0;
} }
if ($item->maybeTemplate()) { if ($item->maybeTemplate()) {
$query .= " AND `is_template` = 0 "; $criteria['WHERE']['is_template'] = 0;
} }
$query .= ' ORDER BY `name`';
$result = $DB->query($query); $iterator = $DB->request($criteria);
if ($DB->numrows($result) > 0) { if (count($iterator)) {
$type_name = $item->getTypeName(); $type_name = $item->getTypeName();
if (!isset($already_add[$itemtype])) { if (!isset($already_add[$itemtype])) {
$already_add[$itemtype] = []; $already_add[$itemtype] = [];
} }
while ($data = $DB->fetch_assoc($result)) { while ($data = $iterator->next()) {
if (!in_array($data["id"], $already_add[$itemtype])) { if (!in_array($data["id"], $already_add[$itemtype])) {
$output = ''; $output = '';
if (isset($data["name"])) { if (isset($data["name"])) {
$output = $data["name"]; $output = $data["name"];
} }
if (empty($output) || $_SESSION["glpiis_ids_visibl e"]) { if (empty($output) || $_SESSION["glpiis_ids_visibl e"]) {
$output = sprintf(__('%1$s (%2$s)'), $output, $ data['id']); $output = sprintf(__('%1$s (%2$s)'), $output, $ data['id']);
} }
$output = sprintf(__('%1$s - %2$s'), $type_name, $ output); $output = sprintf(__('%1$s - %2$s'), $type_name, $ output);
if (isset($data['serial'])) { if (isset($data['serial'])) {
skipping to change at line 819 skipping to change at line 823
} }
} }
} }
if (count($devices)) { if (count($devices)) {
$my_devices[__('Devices own by my groups')] = $devices; $my_devices[__('Devices own by my groups')] = $devices;
} }
} }
} }
// Get linked items to computers // Get linked items to computers
if (isset($already_add['Computer']) && count($already_add['Computer'])) { if (isset($already_add['Computer']) && count($already_add['Computer'])) {
$search_computer = " XXXX IN (".implode(',', $already_add['Computer' ]).') ';
$devices = []; $devices = [];
// Direct Connection // Direct Connection
$types = ['Monitor', 'Peripheral', 'Phone', 'Printer']; $types = ['Monitor', 'Peripheral', 'Phone', 'Printer'];
foreach ($types as $itemtype) { foreach ($types as $itemtype) {
if (in_array($itemtype, $_SESSION["glpiactiveprofile"]["helpdesk_ item_type"]) if (in_array($itemtype, $_SESSION["glpiactiveprofile"]["helpdesk_ item_type"])
&& ($item = getItemForItemtype($itemtype))) { && ($item = getItemForItemtype($itemtype))) {
$itemtable = getTableForItemType($itemtype); $itemtable = getTableForItemType($itemtype);
if (!isset($already_add[$itemtype])) { if (!isset($already_add[$itemtype])) {
$already_add[$itemtype] = []; $already_add[$itemtype] = [];
} }
$query = "SELECT DISTINCT `$itemtable`.* $criteria = [
FROM `glpi_computers_items` 'SELECT DISTINCT' => "$itemtable.*",
LEFT JOIN `$itemtable` 'FROM' => 'glpi_computers_items',
ON (`glpi_computers_items`.`items_id` = `$itemt 'LEFT JOIN' => [
able`.`id`) $itemtable => [
WHERE `glpi_computers_items`.`itemtype` = '$itemtype 'ON' => [
' 'glpi_computers_items' => 'items_id',
AND ".str_replace("XXXX", "`glpi_computers_it $itemtable => 'id'
ems`.`computers_id`", ]
$search_computer); ]
],
'WHERE' => [
'glpi_computers_items.itemtype' => $itemtype,
'glpi_computers_items.computers_id' => $already_add['Com
puter']
] + getEntitiesRestrictCriteria($itemtable, '', $entity_res
trict),
'ORDERBY' => "$itemtable.name"
];
if ($item->maybeDeleted()) { if ($item->maybeDeleted()) {
$query .= " AND `$itemtable`.`is_deleted` = 0 "; $criteria['WHERE']["$itemtable.is_deleted"] = 0;
} }
if ($item->maybeTemplate()) { if ($item->maybeTemplate()) {
$query .= " AND `$itemtable`.`is_template` = 0 "; $criteria['WHERE']["$itemtable.is_template"] = 0;
} }
$query .= getEntitiesRestrictRequest("AND", $itemtable, "", $e
ntity_restrict)."
ORDER BY `$itemtable`.`name`";
$result = $DB->query($query); $iterator = $DB->request($criteria);
if ($DB->numrows($result) > 0) { if (count($iterator)) {
$type_name = $item->getTypeName(); $type_name = $item->getTypeName();
while ($data = $DB->fetch_assoc($result)) { while ($data = $iterator->next()) {
if (!in_array($data["id"], $already_add[$itemtype])) { if (!in_array($data["id"], $already_add[$itemtype])) {
$output = $data["name"]; $output = $data["name"];
if (empty($output) || $_SESSION["glpiis_ids_visible"] ) { if (empty($output) || $_SESSION["glpiis_ids_visible"] ) {
$output = sprintf(__('%1$s (%2$s)'), $output, $dat a['id']); $output = sprintf(__('%1$s (%2$s)'), $output, $dat a['id']);
} }
$output = sprintf(__('%1$s - %2$s'), $type_name, $out put); $output = sprintf(__('%1$s - %2$s'), $type_name, $out put);
if ($itemtype != 'Software') { if ($itemtype != 'Software') {
$output = sprintf(__('%1$s - %2$s'), $output, $dat a['otherserial']); $output = sprintf(__('%1$s - %2$s'), $output, $dat a['otherserial']);
} }
$devices[$itemtype."_".$data["id"]] = $output; $devices[$itemtype."_".$data["id"]] = $output;
skipping to change at line 874 skipping to change at line 886
} }
} }
} }
} }
if (count($devices)) { if (count($devices)) {
$my_devices[__('Connected devices')] = $devices; $my_devices[__('Connected devices')] = $devices;
} }
// Software // Software
if (in_array('Software', $_SESSION["glpiactiveprofile"]["helpdesk_it em_type"])) { if (in_array('Software', $_SESSION["glpiactiveprofile"]["helpdesk_it em_type"])) {
$query = "SELECT DISTINCT `glpi_softwareversions`.`name` AS versi $iterator = $DB->request([
on, 'SELECT DISTINCT' => 'glpi_softwareversions.name AS version',
`glpi_softwares`.`name` AS name, `glpi_softwares 'FIELDS' => [
`.`id` 'glpi_softwares.name AS name',
FROM `glpi_computers_softwareversions`, `glpi_softwares 'glpi_softwares.id'
`, ],
`glpi_softwareversions` 'FROM' => 'glpi_computers_softwareversions',
WHERE `glpi_computers_softwareversions`.`softwareversio 'LEFT JOIN' => [
ns_id` = 'glpi_softwareversions' => [
`glpi_softwareversions`.`id` 'ON' => [
AND `glpi_softwareversions`.`softwares_id` = `glp 'glpi_computers_softwareversions' => 'softwareversi
i_softwares`.`id` ons_id',
AND ".str_replace("XXXX", 'glpi_softwareversions' => 'id'
"`glpi_computers_softwareversio ]
ns`.`computers_id`", ],
$search_computer)." 'glpi_softwares' => [
AND `glpi_softwares`.`is_helpdesk_visible` = 1 ". 'ON' => [
getEntitiesRestrictRequest("AND", "glpi_softwares 'glpi_softwareversions' => 'softwares_id',
", "", 'glpi_softwares' => 'id'
$entity_restrict)." ]
ORDER BY `glpi_softwares`.`name`"; ]
],
'WHERE' => [
'glpi_computers_softwareversions.computers_id' => $alread
y_add['Computer'],
'glpi_softwares.is_helpdesk_visible' => 1
] + getEntitiesRestrictCriteria('glpi_softwares', '', $entity_
restrict),
'ORDERBY' => 'glpi_softwares.name'
]);
$devices = []; $devices = [];
$result = $DB->query($query); if (count($iterator)) {
if ($DB->numrows($result) > 0) {
$tmp_device = ""; $tmp_device = "";
$item = new Software(); $item = new Software();
$type_name = $item->getTypeName(); $type_name = $item->getTypeName();
if (!isset($already_add['Software'])) { if (!isset($already_add['Software'])) {
$already_add['Software'] = []; $already_add['Software'] = [];
} }
while ($data = $DB->fetch_assoc($result)) { while ($data = $iterator->next()) {
if (!in_array($data["id"], $already_add['Software'])) { if (!in_array($data["id"], $already_add['Software'])) {
$output = sprintf(__('%1$s - %2$s'), $type_name, $data[" name"]); $output = sprintf(__('%1$s - %2$s'), $type_name, $data[" name"]);
$output = sprintf(__('%1$s (%2$s)'), $output, $output = sprintf(__('%1$s (%2$s)'), $output,
sprintf(__('%1$s: %2$s'), __('version' ), sprintf(__('%1$s: %2$s'), __('version' ),
$data["version"])); $data["version"]));
if ($_SESSION["glpiis_ids_visible"]) { if ($_SESSION["glpiis_ids_visible"]) {
$output = sprintf(__('%1$s (%2$s)'), $output, $data[" id"]); $output = sprintf(__('%1$s (%2$s)'), $output, $data[" id"]);
} }
$devices["Software_".$data["id"]] = $output; $devices["Software_".$data["id"]] = $output;
skipping to change at line 978 skipping to change at line 1003
$p['display'] = true; $p['display'] = true;
if (is_array($options) && count($options)) { if (is_array($options) && count($options)) {
foreach ($options as $key => $val) { foreach ($options as $key => $val) {
$p[$key] = $val; $p[$key] = $val;
} }
} }
$itemtypes = ['Computer', 'Monitor', 'NetworkEquipment', 'Peripheral', 'Ph one', 'Printer']; $itemtypes = ['Computer', 'Monitor', 'NetworkEquipment', 'Peripheral', 'Ph one', 'Printer'];
$query = ""; $union = new \QueryUnion();
foreach ($itemtypes as $type) { foreach ($itemtypes as $type) {
//TODO: migrate when iterator usuports UNION
$table = getTableForItemType($type); $table = getTableForItemType($type);
if (!empty($query)) { $union->addQuery([
$query .= " UNION "; 'SELECT' => [
} 'id',
$query .= " SELECT `$table`.`id` AS id , '$type' AS itemtype , `$table` new \QueryExpression("$type AS " . $DB->quoteName('itemtype')),
.`name` AS name "name"
FROM `$table` ],
WHERE `$table`.`id` IS NOT NULL AND `$table`.`is_deleted` = 'FROM' => $table,
0 AND `$table`.`is_template` = 0 "; 'WHERE' => [
'NOT' => ['id' => null],
'is_deleted' => 0,
'is_template' => 0
]
]);
} }
$result = $DB->query($query); $iterator = $DB->request(['FROM' => $union]);
$output = []; $output = [];
if ($DB->numrows($result) > 0) { while ($data = $iterator->next()) {
while ($data = $DB->fetch_assoc($result)) { $item = getItemForItemtype($data['itemtype']);
$item = getItemForItemtype($data['itemtype']); $output[$data['itemtype']."_".$data['id']] = $item->getTypeName()." - "
$output[$data['itemtype']."_".$data['id']] = $item->getTypeName()." .$data['name'];
- ".$data['name'];
}
} }
return Dropdown::showFromArray($p['name'], $output, $p); return Dropdown::showFromArray($p['name'], $output, $p);
} }
/** /**
* Return used items for a ticket * Return used items for a ticket
* *
* @param type $tickets_id * @param type $tickets_id
* @return type * @return type
skipping to change at line 1119 skipping to change at line 1150
$ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND)); $ma->addMessage($item->getErrorMessage(ERROR_NOT_FOUND));
} }
} }
return; return;
case 'delete_item' : case 'delete_item' :
$input = $ma->getInput(); $input = $ma->getInput();
$item_ticket = new static(); $item_ticket = new static();
foreach ($ids as $id) { foreach ($ids as $id) {
if ($item->getFromDB($id) && !empty($input['items_id'])) { if ($item->getFromDB($id) && !empty($input['items_id'])) {
$item_found = $item_ticket->find("`tickets_id` = $id AND `item $item_found = $item_ticket->find([
type` = '".$input['item_itemtype']."' AND `items_id` = ".$input['items_id']); 'tickets_id' => $id,
'itemtype' => $input['item_itemtype'],
'items_id' => $input['items_id']
]);
if (!empty($item_found)) { if (!empty($item_found)) {
$item_founds_id = array_keys($item_found); $item_founds_id = array_keys($item_found);
$input['id'] = $item_founds_id[0]; $input['id'] = $item_founds_id[0];
if ($item_ticket->can($input['id'], DELETE, $input)) { if ($item_ticket->can($input['id'], DELETE, $input)) {
$ok = true; $ok = true;
if (!$item_ticket->delete($input)) { if (!$item_ticket->delete($input)) {
$ok = false; $ok = false;
} }
 End of changes. 33 change blocks. 
115 lines changed or deleted 136 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)