diff --git a/hook.php b/hook.php index 7ea8a0e..3f3adf4 100644 --- a/hook.php +++ b/hook.php @@ -86,9 +86,30 @@ function plugin_escalade_install() { ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; $DB->query($query); - $query = "INSERT INTO glpi_plugin_escalade_configs - VALUES (NULL, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, '".Ticket::WAITING."',0)"; - $DB->query($query); + $DB->insert('glpi_plugin_escalade_configs', [ + 'remove_group' => 1, + 'show_history' => 1, + 'task_history' => 1, + 'remove_tech' => 1, + 'solve_return_group' => 1, + 'reassign_group_from_cat' => 0, + 'reassign_tech_from_cat' => 0, + 'cloneandlink_ticket' => 1, + 'close_linkedtickets' => 1, + 'use_assign_user_group' => 0, + 'use_assign_user_group_creation' => 0, + 'use_assign_user_group_modification' => 0, + 'remove_delete_requester_user_btn' => 1, + 'remove_delete_watcher_user_btn' => 1, + 'remove_delete_assign_user_btn' => 0, + 'remove_delete_requester_group_btn' => 1, + 'remove_delete_watcher_group_btn' => 1, + 'remove_delete_assign_group_btn' => 0, + 'remove_delete_assign_supplier_btn' => 1, + 'use_filter_assign_group' => 1, + 'ticket_last_status' => Ticket::WAITING, + 'remove_requester' => 0 + ]); } // == Update to 1.2 == @@ -167,10 +188,11 @@ function plugin_escalade_install() { $status = -1; break; } - $query = "UPDATE `glpi_plugin_escalade_configs` - SET `ticket_last_status` = '".$status."' - WHERE `id` = '".$data['id']."'"; - $DB->query($query); + $DB->update('glpi_plugin_escalade_configs', [ + 'ticket_last_status' => $status + ], [ + 'id' => $data['id'] + ]); } $query = "ALTER TABLE `glpi_plugin_escalade_configs` MODIFY `ticket_last_status` INT;"; @@ -204,9 +226,10 @@ function plugin_escalade_install() { $user = new User(); foreach ($user->find() as $data) { - $query = "INSERT INTO glpi_plugin_escalade_users (`users_id`, `use_filter_assign_group`) - VALUES (".$data['id'].", $default_value)"; - $DB->query($query); + $DB->insert('glpi_plugin_escalade_users', [ + 'users_id' => $data['id'], + 'use_filter_assign_group' => $default_value + ]); } } @@ -343,7 +366,7 @@ function plugin_escalade_item_purge($item) { global $DB; if ($item instanceof User) { - $DB->query("DELETE FROM glpi_plugin_escalade_users WHERE users_id = ".$item->getID()); + $DB->delete('glpi_plugin_escalade_users', ['users_id' => $item->getID()]); } if ($item instanceof Ticket) { @@ -377,9 +400,10 @@ function plugin_escalade_item_add_user($item) { $config->getFromDB(1); $default_value = $config->fields["use_filter_assign_group"]; - $query = "INSERT INTO glpi_plugin_escalade_users (`users_id`, `use_filter_assign_group`) - VALUES (".$item->getID().", $default_value)"; - $DB->query($query); + $DB->insert('glpi_plugin_escalade_users', [ + 'users_id' => $item->getID(), + 'use_filter_assign_group' => $default_value + ]); } if ($item instanceof Ticket_User) { diff --git a/inc/history.class.php b/inc/history.class.php index ceca9d0..a5e3e65 100644 --- a/inc/history.class.php +++ b/inc/history.class.php @@ -187,57 +187,71 @@ static function showCentralSpecificList($type) { return false; } - $groups = implode("','", $_SESSION['glpigroups']); - $numrows = 0; - $is_deleted = " `glpi_tickets`.`is_deleted` = 0 "; + $criteria = [ + 'SELECT' => ['glpi_tickets.id'], + 'DISTINCT' => true, + 'FROM' => 'glpi_tickets', + 'LEFT JOIN' => [ + 'glpi_tickets_users' => [ + 'ON' => [ + 'glpi_tickets' => 'id', + 'glpi_tickets_users' => 'tickets_id' + ] + ] + ], + 'WHERE' => [ + 'glpi_tickets.is_deleted' => 0, + ], + 'ORDER' => ['glpi_tickets.date_mod DESC'] + ]; if ($type == "notold") { $title = __("Tickets to follow (escalated)", "escalade"); $status = CommonITILObject::INCOMING.", ".CommonITILObject::PLANNED.", ". CommonITILObject::ASSIGNED.", ".CommonITILObject::WAITING; - $search_assign = " `glpi_plugin_escalade_histories`.`groups_id` IN ('$groups') - AND (`glpi_groups_tickets`.`groups_id` NOT IN ('$groups') - OR `glpi_groups_tickets`.`groups_id` IS NULL)"; - - $query_join = "LEFT JOIN `glpi_plugin_escalade_histories` - ON (`glpi_tickets`.`id` = `glpi_plugin_escalade_histories`.`tickets_id`) - LEFT JOIN `glpi_groups_tickets` - ON (`glpi_tickets`.`id` = `glpi_groups_tickets`.`tickets_id` - AND `glpi_groups_tickets`.`type`=2)"; + $criteria['WHERE']['glpi_plugin_escalade_histories.groups_id'] = $_SESSION['glpigroups']; + $criteria['WHERE'][] = [ + 'OR' => [ + 'NOT' => ['glpi_groups_tickets.groups_id' => $_SESSION['glpigroups']], + 'glpi_groups_tickets.groups_id' => null + ] + ]; + + $criteria['LEFT JOIN']['glpi_plugin_escalade_histories'] = [ + 'ON' => [ + 'glpi_tickets' => 'id', + 'glpi_plugin_escalade_histories' => 'tickets_id' + ] + ]; } else { $title = __("Tickets to close (escalated)", "escalade"); $status = CommonITILObject::SOLVED; - $search_assign = " (`glpi_groups_tickets`.`groups_id` IN ('$groups'))"; - - $query_join = "LEFT JOIN `glpi_groups_tickets` - ON (`glpi_tickets`.`id` = `glpi_groups_tickets`.`tickets_id` - AND `glpi_groups_tickets`.`type`=2)"; + $criteria['WHERE']['glpi_groups_tickets.groups_id'] = $_SESSION['glpigroups']; } - - $query = "SELECT DISTINCT `glpi_tickets`.`id` - FROM `glpi_tickets` - LEFT JOIN `glpi_tickets_users` - ON (`glpi_tickets`.`id` = `glpi_tickets_users`.`tickets_id`)"; - - $query .= $query_join; - - $query .= "WHERE $is_deleted AND ( $search_assign ) - AND (`status` IN ($status))". - getEntitiesRestrictRequest("AND", "glpi_tickets"); - - $query .= " ORDER BY glpi_tickets.date_mod DESC"; - - $result = $DB->query($query); - $numrows = $DB->numrows($result); + $criteria['LEFT JOIN']['glpi_groups_tickets'] = [ + 'ON' => [ + 'glpi_tickets' => 'id', + 'glpi_groups_tickets' => 'tickets_id', + [ + 'AND' => ['glpi_groups_tickets.type' => 2] + ] + ] + ]; + $criteria['WHERE']['status'] = $status; + $criteria['WHERE'][] = getEntitiesRestrictCriteria('glpi_tickets'); + + $result = $DB->request($criteria); + $numrows = count($result); if (!$numrows) { return; } - $query .= " LIMIT 0, 5"; - $result = $DB->query($query); - $number = $DB->numrows($result); + $criteria['START'] = 0; + $criteria['LIMIT'] = 5; + $result = $DB->request($criteria); + $number = count($result); //show central list if ($numrows > 0) { @@ -287,9 +301,8 @@ static function showCentralSpecificList($type) { echo "