@@ -149,24 +149,46 @@ public function multipleDropdownGroup($level)
149149 // find current values for this select
150150 $ values = [];
151151 if (!$ this ->isNewItem ()) {
152- $ res_val = $ DB ->doQuery ("SELECT `groups_id`
153- FROM glpi_plugin_itilcategorygroups_categories_groups
154- WHERE (`itilcategories_id` = {$ this ->fields ['itilcategories_id ' ]}
155- OR `plugin_itilcategorygroups_categories_id` = {$ this ->getID ()}
156- )
157- AND level = $ level " );
158- while ($ data_val = $ DB ->fetchAssoc ($ res_val )) {
152+ $ res_val = $ DB ->request ([
153+ 'SELECT ' => 'groups_id ' ,
154+ 'FROM ' => 'glpi_plugin_itilcategorygroups_categories_groups ' ,
155+ 'WHERE ' => [
156+ 'OR ' => [
157+ 'itilcategories_id ' => $ this ->fields ['itilcategories_id ' ],
158+ 'plugin_itilcategorygroups_categories_id ' => $ this ->getID (),
159+ ],
160+ 'level ' => $ level ,
161+ ],
162+ ]);
163+ foreach ($ res_val as $ data_val ) {
159164 $ values [] = $ data_val ['groups_id ' ];
160165 }
161166 }
162167
163168 // find possible values for this select
164- $ res_gr = $ DB ->doQuery ('SELECT gr.id, gr.name
165- FROM glpi_groups gr
166- INNER JOIN glpi_plugin_itilcategorygroups_groups_levels gr_lvl
167- ON gr_lvl.groups_id = gr.id
168- AND gr_lvl.lvl = ' . intval ($ level ) .
169- getEntitiesRestrictRequest (' AND ' , 'gr ' , '' , $ _SESSION ['glpiactiveentities ' ], true ));
169+ $ res_gr = $ DB ->request ([
170+ 'SELECT ' => ['glpi_groups.id ' , 'glpi_groups.name ' ],
171+ 'FROM ' => 'glpi_groups ' ,
172+ 'INNER JOIN ' => [
173+ 'glpi_plugin_itilcategorygroups_groups_levels ' => [
174+ 'ON ' => [
175+ 'glpi_plugin_itilcategorygroups_groups_levels ' => 'groups_id ' ,
176+ 'glpi_groups ' => 'id ' ,
177+ [
178+ 'AND ' => [
179+ 'glpi_plugin_itilcategorygroups_groups_levels.lvl ' => intval ($ level ),
180+ ],
181+ ],
182+ ],
183+ ],
184+ ],
185+ 'WHERE ' => getEntitiesRestrictCriteria (
186+ 'glpi_groups ' ,
187+ '' ,
188+ $ _SESSION ['glpiactiveentities ' ],
189+ true ,
190+ ),
191+ ]);
170192
171193 if ($ this ->fields ["view_all_lvl $ level " ] == 1 ) {
172194 $ checked = "checked='checked' " ;
@@ -178,7 +200,7 @@ public function multipleDropdownGroup($level)
178200
179201 echo "<span id='select_level_ $ level'> " ;
180202 echo "<select name='groups_id_level " . $ level . "[]' id='groups_id_level " . $ level . "[]' $ disabled multiple='multiple' class='chzn-select' data-placeholder='-----' style='width:160px;'> " ;
181- while ($ data_gr = $ DB -> fetchAssoc ( $ res_gr ) ) {
203+ foreach ($ res_gr as $ data_gr ) {
182204 if (in_array ($ data_gr ['id ' ], $ values )) {
183205 $ selected = 'selected ' ;
184206 } else {
@@ -482,8 +504,15 @@ public static function canApplyFilter($itilcategories_id)
482504 $ category = new ITILCategory ();
483505 if ($ category ->getFromDB ($ itilcategories_id )) {
484506 $ table = getTableForItemType (__CLASS__ );
485- $ query = "SELECT is_active FROM ` $ table` WHERE itilcategories_id = $ itilcategories_id AND is_active = '1' AND is_groups_restriction = '1' " ;
486- $ data = $ DB ->request ($ query );
507+ $ data = $ DB ->request ([
508+ 'SELECT ' => 'is_active ' ,
509+ 'FROM ' => $ table ,
510+ 'WHERE ' => [
511+ 'itilcategories_id ' => $ itilcategories_id ,
512+ 'is_active ' => 1 ,
513+ 'is_groups_restriction ' => 1 ,
514+ ],
515+ ]);
487516 // A category rule exist for this ticket
488517 if (count ($ data )) {
489518 return true ;
@@ -498,15 +527,30 @@ public static function getOthersGroupsID($level = 0)
498527 /** @var \DBmysql $DB */
499528 global $ DB ;
500529
501- $ res = $ DB ->doQuery ("SELECT gr.id
502- FROM glpi_groups gr
503- LEFT JOIN glpi_plugin_itilcategorygroups_groups_levels gl
504- ON gl.groups_id = gr.id
505- WHERE gl.lvl != $ level
506- AND gr.is_assign
507- OR gl.lvl IS NULL " );
530+ $ res = $ DB ->request ([
531+ 'SELECT ' => 'glpi_groups.id ' ,
532+ 'FROM ' => 'glpi_groups ' ,
533+ 'LEFT JOIN ' => [
534+ 'glpi_plugin_itilcategorygroups_groups_levels ' => [
535+ 'ON ' => [
536+ 'glpi_plugin_itilcategorygroups_groups_levels ' => 'groups_id ' ,
537+ 'glpi_groups ' => 'id ' ,
538+ ],
539+ ],
540+ ],
541+ 'WHERE ' => [
542+ 'OR ' => [
543+ [
544+ 'NOT ' => ['glpi_plugin_itilcategorygroups_groups_levels.lvl ' => $ level ],
545+ 'glpi_groups.is_assign ' => 1 ,
546+ ],
547+ 'glpi_plugin_itilcategorygroups_groups_levels.lvl ' => null ,
548+ ],
549+ ],
550+ ]);
551+
508552 $ groups_id = [];
509- while ($ row = $ DB -> fetchAssoc ( $ res ) ) {
553+ foreach ($ res as $ row ) {
510554 $ groups_id [$ row ['id ' ]] = $ row ['id ' ];
511555 }
512556
0 commit comments