Skip to content

Commit 8685e71

Browse files
committed
Add all Item_Devices* to location_types; permit to display all located items, fix overrided variable
refs #7054
1 parent f658190 commit 8685e71

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

inc/define.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@
323323
'DeviceCase', 'DevicePowerSupply', 'DeviceGeneric',
324324
'DeviceSimcard', 'DeviceSensor'];
325325

326+
foreach ($CFG_GLPI['device_types'] as $dtype) {
327+
$CFG_GLPI['location_types'][] = 'Item_' . $dtype;
328+
}
329+
326330
$CFG_GLPI["itemdevices_types"] = ['Computer', 'NetworkEquipment', 'Peripheral',
327331
'Phone', 'Printer', 'Enclosure'];
328332

inc/location.class.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,15 +390,19 @@ function showItems() {
390390
global $DB, $CFG_GLPI;
391391

392392
$locations_id = $this->fields['id'];
393-
$itemtype = Session::getSavedOption(__CLASS__, 'criterion', '');
393+
$current_itemtype = Session::getSavedOption(__CLASS__, 'criterion', '');
394394

395395
if (!$this->can($locations_id, READ)) {
396396
return false;
397397
}
398398

399399
$queries = [];
400-
$itemtypes = $itemtype ? [$itemtype] : $CFG_GLPI['location_types'];
400+
$itemtypes = $current_itemtype ? [$current_itemtype] : $CFG_GLPI['location_types'];
401401
foreach ($itemtypes as $itemtype) {
402+
$item = new $itemtype();
403+
if (!$item->maybeLocated()) {
404+
continue;
405+
}
402406
$table = getTableForItemType($itemtype);
403407
$itemtype_criteria = [
404408
'SELECT' => [
@@ -410,7 +414,6 @@ function showItems() {
410414
"$table.locations_id" => $locations_id,
411415
] + getEntitiesRestrictCriteria($table, 'entities_id')
412416
];
413-
$item = new $itemtype();
414417
if ($item->maybeDeleted()) {
415418
$itemtype_criteria['WHERE']['is_deleted'] = 0;
416419
}
@@ -437,9 +440,13 @@ function showItems() {
437440
echo "<tr class='tab_bg_1'><th colspan='2'>".__('Type')."</th></tr>";
438441
echo "<tr class='tab_bg_1'><td class='center'>";
439442
echo __('Type')."&nbsp;";
440-
Dropdown::showItemType($CFG_GLPI['location_types'],
441-
['value' => $itemtype,
442-
'on_change' => 'reloadTab("start=0&criterion="+this.value)']);
443+
$all_types = array_merge(['0' => '---'], $CFG_GLPI['location_types']);
444+
Dropdown::showItemType(
445+
$all_types, [
446+
'value' => $current_itemtype,
447+
'on_change' => 'reloadTab("start=0&criterion="+this.value)'
448+
]
449+
);
443450
echo "</td></tr></table>";
444451

445452
if ($number) {

0 commit comments

Comments
 (0)