diff --git a/inc/category.class.php b/inc/category.class.php index a27bef8..4041d96 100644 --- a/inc/category.class.php +++ b/inc/category.class.php @@ -143,24 +143,43 @@ function multipleDropdownGroup($level) { // find current values for this select $values = []; if (!$this->isNewItem()) { - $res_val = $DB->query("SELECT `groups_id` - FROM glpi_plugin_itilcategorygroups_categories_groups - WHERE (`itilcategories_id` = {$this->fields['itilcategories_id']} - OR `plugin_itilcategorygroups_categories_id` = {$this->getID()} - ) - AND level = $level"); - while ($data_val = $DB->fetchAssoc($res_val)) { + $it = $DB->request([ + 'SELECT' => ['groups_id'], + 'FROM' => 'glpi_plugin_itilcategorygroups_categories_groups', + 'WHERE' => [ + 'OR' => [ + 'itilcategories_id' => $this->fields['itilcategories_id'], + 'plugin_itilcategorygroups_categories_id' => $this->getID() + ], + 'level' => $level, + ] + ]); + foreach ($it as $data_val) { $values[] = $data_val['groups_id']; } } // find possible values for this select - $res_gr = $DB->query("SELECT gr.id, gr.name - FROM glpi_groups gr - INNER JOIN glpi_plugin_itilcategorygroups_groups_levels gr_lvl - ON gr_lvl.groups_id = gr.id - AND gr_lvl.lvl = ".intval($level). - getEntitiesRestrictRequest(" AND", "gr", '', $_SESSION["glpiactiveentities"], true)); + $join_criteria = [ + 'gr_lvl.lvl' => (int) $level, + ]; + $entity_restrict = getEntitiesRestrictCriteria('gr', '', $_SESSION['glpiactiveentities'], true); + if (!empty($entity_restrict)) { + $join_criteria += $entity_restrict; + } + $it = $DB->request([ + 'SELECT' => ['gr.id', 'gr.name'], + 'FROM' => 'glpi_groups AS gr', + 'INNER JOIN' => [ + 'glpi_plugin_itilcategorygroups_groups_levels AS gr_lvl' => [ + 'ON' => [ + 'gr_lvl' => 'groups_id', + 'gr' => 'id', + $join_criteria + ] + ] + ] + ]); if ($this->fields["view_all_lvl$level"] == 1) { $checked = "checked='checked'"; @@ -172,7 +191,7 @@ function multipleDropdownGroup($level) { echo ""; echo "