Skip to content
1 change: 1 addition & 0 deletions ajax/taskjob_moduleitems.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
$pfTaskjob = new PluginGlpiinventoryTaskjob();

$params = [
"taskid" => filter_input(INPUT_GET, "taskid"),
"moduletype" => filter_input(INPUT_GET, "moduletype"),
"itemtype" => filter_input(INPUT_GET, "itemtype"),
"method" => filter_input(INPUT_GET, "method"),
Expand Down
45 changes: 43 additions & 2 deletions inc/taskjobview.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ public function ajaxModuleItemsDropdown($options)
$moduletype = $options['moduletype'];
$itemtype = $options['itemtype'];
$method = $options['method'];
$taskid = $options['taskid'];
$title = '';
if ($itemtype === "") {
return;
Expand Down Expand Up @@ -426,8 +427,26 @@ public function ajaxModuleItemsDropdown($options)
// remove install suffix from deploy
$modulename = str_replace('DEPLOYINSTALL', 'DEPLOY', strtoupper($method));

switch (strtoupper($modulename)) {
case "INVENTORYCOMPUTERESX":
$moduleactive = "agents.use_module_esx_remote_inventory";
break;
case "NETWORKDISCOVERY":
$moduleactive = "agents.use_module_network_discovery";
break;
case "NETWORKINVENTORY":
$moduleactive = "agents.use_module_network_inventory";
break;
case "DEPLOY":
$moduleactive = "agents.use_module_package_deployment";
break;
case "COLLECT":
$moduleactive = "agents.use_module_collect_data";
break;
}

// prepare a query to retrieve agent's & computer's id
$iterator = $DB->request([
$crit = [
'SELECT' => [
'agents.id AS agents_id',
'agents.items_id'
Expand Down Expand Up @@ -462,7 +481,29 @@ public function ajaxModuleItemsDropdown($options)
'agents.id',
'agents.items_id'
]
]);
];

if (isset($moduleactive)) {
array_push($crit['SELECT'], $moduleactive);
$crit['WHERE'] += [ $moduleactive => 1 ];
}

$item = getItemForItemtype($itemtype);
if ($item->isEntityAssign()) {
// get entity ID from task ID
$pfTask = new PluginGlpiinventoryTask();
$pfTask->getFromDB($taskid);

$crit['WHERE'] += getEntitiesRestrictCriteria(
'agents',
'',
$pfTask->fields['entities_id'] ?? 0,
$item->maybeRecursive()
);
}

$iterator = $DB->request($crit);

$filter_id = [];
foreach ($iterator as $data_filter) {
if ($itemtype == 'Computer') {
Expand Down
3 changes: 3 additions & 0 deletions js/taskjobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,12 @@ taskjobs.show_moduletypes = function(ajax_url, moduletype) {

taskjobs.show_moduleitems = function(ajax_url, moduletype, itemtype) {
taskjobs.hide_moduleitems_dropdown();
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
$.ajax({
url: ajax_url,
data: {
"taskid" : (typeof urlParams.get('id') !== null ? urlParams.get('id') : 0),
"itemtype" : itemtype,
"moduletype" : moduletype,
"method" : $('#method_selected').text()
Expand Down