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
27 changes: 24 additions & 3 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 @@ -427,7 +428,7 @@ public function ajaxModuleItemsDropdown($options)
$modulename = str_replace('DEPLOYINSTALL', 'DEPLOY', strtoupper($method));

// 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,13 +463,33 @@ public function ajaxModuleItemsDropdown($options)
'agents.id',
'agents.items_id'
]
]);
];

$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') {
$filter_id[] = $data_filter['items_id'];
} else {
$filter_id[] = $data_filter['agents_id'];
$pfAgentModule = new PluginGlpiinventoryAgentmodule();
if ($pfAgentModule->isAgentCanDo($modulename, $data_filter['agents_id'])) {
$filter_id[] = $data_filter['agents_id'];
}
}
}

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