From 56aee8a1ded64d6257b9b9f41d146889a4423c32 Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Fri, 13 Feb 2026 18:06:19 -0700 Subject: [PATCH] Clear the cache when agent is removed from the Queue - Add checkboxes for removing one or more agents from the call center queue. --- app/call_centers/call_center_queue_edit.php | 28 ++++- .../resources/classes/call_center.php | 106 +++++++++++++++++- 2 files changed, 126 insertions(+), 8 deletions(-) diff --git a/app/call_centers/call_center_queue_edit.php b/app/call_centers/call_center_queue_edit.php index 89dceebcdf..a88426fc43 100644 --- a/app/call_centers/call_center_queue_edit.php +++ b/app/call_centers/call_center_queue_edit.php @@ -132,6 +132,7 @@ $queue_cc_exit_keys = $_POST["queue_cc_exit_keys"] ?? null; $queue_email_address = $_POST["queue_email_address"] ?? null; $queue_description = $_POST["queue_description"]; + $call_center_tier_delete = $_POST["call_center_tier_delete"] ?? null; //set the context for users that do not have the permission if (permission_exists('call_center_queue_context')) { @@ -216,7 +217,7 @@ } //if the user doesn't have the correct permission then - //override domain_uuid and queue_context values + //override domain_uuid and queue_context values if ($action == 'update' && is_uuid($call_center_queue_uuid)) { $sql = "select * from v_call_center_queues "; $sql .= "where call_center_queue_uuid = :call_center_queue_uuid "; @@ -481,6 +482,12 @@ $p->delete("dialplan_add", "temp"); $p->delete("dialplan_edit", "temp"); + //remove checked options + if ($action == 'update' && permission_exists('call_center_tier_delete') && !empty($call_center_tier_delete)) { + $obj = new call_center; + $obj->delete_tiers($call_center_tier_delete); + } + //debug info //echo "
". print_r($message, true) ."
"; exit; @@ -1036,7 +1043,12 @@ echo " ".$text['label-agent_name']."\n"; echo " ".$text['label-tier_level']."\n"; echo " ".$text['label-tier_position']."\n"; - echo " \n"; + if (permission_exists('call_center_tier_delete')) { + echo " \n"; + echo " ".$text['label-delete']."\n"; + echo " \n"; + echo " \n"; + } echo " \n"; $x = 0; if (is_array($tiers)) { @@ -1079,11 +1091,17 @@ } echo " \n"; echo " \n"; - echo " "; if (permission_exists('call_center_tier_delete')) { - echo " $v_link_label_delete"; + if (!empty($field['call_center_agent_uuid']) && is_uuid($field['call_center_agent_uuid'])) { + echo ""; + echo " \n"; + echo " \n"; + } + else { + echo ""; + } + echo "\n"; } - echo " \n"; echo " \n"; $assigned_agents[] = $field['agent_name']; $x++; diff --git a/app/call_centers/resources/classes/call_center.php b/app/call_centers/resources/classes/call_center.php index 68cf6d6f9d..c5724b59b2 100644 --- a/app/call_centers/resources/classes/call_center.php +++ b/app/call_centers/resources/classes/call_center.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Copyright (C) 2015 - 2023 + Copyright (C) 2015 - 2026 All Rights Reserved. Contributor(s): @@ -409,7 +409,7 @@ class call_center { //clear the cache $cache = new cache; $cache->delete("dialplan:" . $this->domain_name); - remove_config_from_cache('configuration:callcenter.conf'); + $cache->delete('configuration:callcenter.conf'); //clear the destinations session array if (isset($_SESSION['destinations']['array'])) { @@ -506,7 +506,10 @@ class call_center { //synchronize configuration save_call_center_xml(); - remove_config_from_cache('configuration:callcenter.conf'); + + //clear the cache + $cache = new cache; + $cache->delete('configuration:callcenter.conf'); //set message message::add($text['message-delete']); @@ -516,6 +519,103 @@ class call_center { } } + /** + * Remove one or more agents from a call center queue by deleting the tier assignment + * + * @param array $records A list of records to delete, where each record is an associative array containing a 'uuid' + * key. + * + * @return void + */ + public function delete_tiers($records) { + + //permission doesn't exist return now + if (!permission_exists('call_center_tier_delete')) { + return; + } + + //validate the token + $token = new token; + if (!$token->validate($_SERVER['PHP_SELF'])) { + message::add($text['message-invalid_token'], 'negative'); + header('Location: ' . $this->list_page); + exit; + } + + //delete multiple records + if (is_array($records) && @sizeof($records) != 0) { + + //delete the tier to remove the agent from the queue + $x = 0; + foreach ($records as $record) { + //not checked skip this row + if (empty($record['checked'])) { + continue; + } + + // //not a valid uuid skip this row + if (!is_uuid($record['uuid'])) { + continue; + } + + //get the agent details + $sql = "select t.call_center_agent_uuid, t.call_center_queue_uuid, q.queue_extension "; + $sql .= "from v_call_center_tiers as t, v_call_center_queues as q "; + $sql .= "where t.domain_uuid = :domain_uuid "; + $sql .= "and t.call_center_tier_uuid = :call_center_tier_uuid "; + $sql .= "and t.call_center_queue_uuid = q.call_center_queue_uuid; "; + $parameters['domain_uuid'] = $this->domain_uuid; + $parameters['call_center_tier_uuid'] = $record['uuid']; + $tiers = $this->database->select($sql, $parameters, 'all'); + unset($sql, $parameters); + if (!empty($tiers)) { + foreach ($tiers as $row) { + $call_center_agent_uuid = $row["call_center_agent_uuid"]; + $call_center_queue_uuid = $row["call_center_queue_uuid"]; + $queue_extension = $row["queue_extension"]; + } + } + + //delete the agent from freeswitch + //setup the event socket connection + $esl = event_socket::create(); + + //remove the tier to unassign the agent from the queue + if ($esl->is_connected()) { + //callcenter_config tier del [queue_name] [agent_name] + if (is_numeric($queue_extension) && is_uuid($call_center_agent_uuid)) { + $cmd = "callcenter_config tier del ".$queue_extension."@".$this->domain_name." ".$call_center_agent_uuid; + $response = event_socket::api($cmd); + } + } + + //build the delete array + if (!empty($record['uuid'])) { + $array['call_center_tiers'][$x]['domain_uuid'] = $this->domain_uuid; + $array['call_center_tiers'][$x]['call_center_tier_uuid'] = $record['uuid']; + } + + //increment the $id + $x++; + } + + //delete the tier from the database + if (!empty($array)) { + $p = permissions::new(); + $p->add('call_center_tier_delete', 'temp'); + + $this->database->delete($array); + unset($array); + + $p->delete('call_center_tier_delete', 'temp'); + } + + //clear the cache + $cache = new cache; + $cache->delete('configuration:callcenter.conf'); + } + } + /** * Copies one or more records *