From a6e59c352231a8fa609e9df4a43bfdffd91dc94f Mon Sep 17 00:00:00 2001 From: markjcrane Date: Tue, 27 Apr 2021 22:42:09 -0600 Subject: [PATCH] Call Center Queue name change from uuid@domain to extension@domain --- .../call_center_active_inc.php | 9 +- app/call_centers/app_defaults.php | 116 ++++++++++++++++-- app/call_centers/call_center_queue_edit.php | 31 +++-- .../resources/classes/call_center.php | 9 +- .../scripts/configuration/callcenter.conf.lua | 13 +- 5 files changed, 139 insertions(+), 39 deletions(-) diff --git a/app/call_center_active/call_center_active_inc.php b/app/call_center_active/call_center_active_inc.php index a25fa73113..77efa37057 100644 --- a/app/call_center_active/call_center_active_inc.php +++ b/app/call_center_active/call_center_active_inc.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2019 + Portions created by the Initial Developer are Copyright (C) 2008-2021 the Initial Developer. All Rights Reserved. Contributor(s): @@ -60,6 +60,7 @@ foreach ($_SESSION['queues'] as $row) { if ($row['call_center_queue_uuid'] == $queue_uuid) { $queue_name = $row['queue_name']; + $queue_extension = $row['queue_extension']; } } @@ -116,7 +117,7 @@ //send the event socket command and get the response //callcenter_config queue list tiers [queue_name] | - $switch_command = 'callcenter_config queue list tiers '.$queue_uuid."@".$_SESSION["domain_name"]; + $switch_command = 'callcenter_config queue list tiers '.$queue_extension."@".$_SESSION["domain_name"]; $event_socket_str = trim(event_socket_request($fp, 'api '.$switch_command)); $result = str_to_named_array($event_socket_str, '|'); @@ -138,7 +139,7 @@ //send the event socket command and get the response //callcenter_config queue list agents [queue_name] [status] | - $switch_command = 'callcenter_config queue list agents '.$queue_uuid."@".$_SESSION["domain_name"]; + $switch_command = 'callcenter_config queue list agents '.$queue_extension."@".$_SESSION["domain_name"]; $event_socket_str = trim(event_socket_request($fp, 'api '.$switch_command)); $agent_result = str_to_named_array($event_socket_str, '|'); @@ -287,7 +288,7 @@ //send the event socket command and get the response //callcenter_config queue list members [queue_name] if (is_uuid($queue_uuid)) { - $switch_command = 'callcenter_config queue list members '.$queue_uuid."@".$_SESSION["domain_name"]; + $switch_command = 'callcenter_config queue list members '.$queue_extension."@".$_SESSION["domain_name"]; $event_socket_str = trim(event_socket_request($fp, 'api '.$switch_command)); $result = str_to_named_array($event_socket_str, '|'); if (!is_array($result)) { unset($result); } diff --git a/app/call_centers/app_defaults.php b/app/call_centers/app_defaults.php index a86035d825..a1edfed90c 100644 --- a/app/call_centers/app_defaults.php +++ b/app/call_centers/app_defaults.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2018 + Portions created by the Initial Developer are Copyright (C) 2018 - 2021 the Initial Developer. All Rights Reserved. Contributor(s): @@ -64,18 +64,108 @@ if ($domains_processed == 1) { } unset($sql); - //update all callcenter dialplans to have the @domain in the queue name - $sql = "UPDATE \n"; - $sql .= " v_dialplans d SET dialplan_xml = REPLACE( \n"; - $sql .= " dialplan_xml, \n"; - $sql .= " (SELECT call_center_queue_uuid::text FROM v_call_center_queues c WHERE c.dialplan_uuid = d.dialplan_uuid ), \n"; - $sql .= " (SELECT call_center_queue_uuid::text FROM v_call_center_queues c WHERE c.dialplan_uuid = d.dialplan_uuid ) || '@' || (SELECT domain_name FROM v_domains vd WHERE vd.domain_uuid = d.domain_uuid) \n"; - $sql .= " ) \n"; - $sql .= "WHERE dialplan_uuid IN (SELECT dialplan_uuid FROM v_call_center_queues) \n"; - $sql .= "AND dialplan_xml NOT LIKE '%%' \n"; - $database = new database; - $database->execute($sql); + //update all callcenter dialplans to have the @domain in the queue name + $sql = "select q.domain_uuid, d.domain_name, q.call_center_queue_uuid, q.dialplan_uuid, "; + $sql .= "q.queue_name, q.queue_extension, q.queue_timeout_action, q.queue_cid_prefix, q.queue_cc_exit_keys, "; + $sql .= "q.queue_description, q.queue_time_base_score_sec, q.queue_greeting "; + $sql .= "from v_call_center_queues as q, v_domains as d "; + $sql .= "where q.domain_uuid = d.domain_uuid "; + $database = new database; + $call_center_queues = $database->select($sql, null, 'all'); + $id = 0; + if (is_array($call_center_queues)) { + foreach ($call_center_queues as $row) { + + //get the application and data + $action_array = explode(":",$row['queue_timeout_action']); + $queue_timeout_app = $action_array[0]; + unset($action_array[0]); + $queue_timeout_data = implode($action_array); + + //add the recording path if needed + if ($row['queue_greeting'] != '') { + if (file_exists($_SESSION['switch']['recordings']['dir'].'/'.$row['domain_name'].'/'.$row['queue_greeting'])) { + $queue_greeting_path = $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$row['queue_greeting']; + } + else { + $queue_greeting_path = trim($row['queue_greeting']); + } + } + + //build the xml dialplan + $dialplan_xml = "\n"; + $dialplan_xml .= " \n"; + $dialplan_xml .= " \n"; + $dialplan_xml .= " \n"; + $dialplan_xml .= " \n"; + $dialplan_xml .= " \n"; + $dialplan_xml .= " \n"; + if ($row['queue_time_base_score_sec'] != '') { + $dialplan_xml .= " \n"; + } + if ($row['queue_greeting_path'] != '') { + $greeting_array = explode(':', $row['queue_greeting_path']); + if (count($greeting_array) == 1) { + $dialplan_xml .= " \n"; + } + else { + if ($greeting_array[0] == 'say' || $greeting_array[0] == 'tone_stream' || $greeting_array[0] == 'phrase') { + $dialplan_xml .= " \n"; + } + } + } + if (strlen($row['queue_cid_prefix']) > 0) { + $dialplan_xml .= " \n"; + } + if (strlen($row['queue_cc_exit_keys']) > 0) { + $dialplan_xml .= " \n"; + } + $dialplan_xml .= " \n"; + //if ($destination->valid($queue_timeout_app.':'.$queue_timeout_data)) { + $dialplan_xml .= " \n"; + //} + $dialplan_xml .= " \n"; + $dialplan_xml .= "\n"; + + //build the dialplan array + $array['dialplans'][$id]["domain_uuid"] = $row["domain_uuid"]; + $array['dialplans'][$id]["dialplan_uuid"] = $row["dialplan_uuid"]; + $array['dialplans'][$id]["dialplan_name"] = $row["queue_name"]; + $array['dialplans'][$id]["dialplan_number"] = $row["queue_extension"]; + $array['dialplans'][$id]["dialplan_context"] = $row['domain_name']; + $array['dialplans'][$id]["dialplan_continue"] = "false"; + $array['dialplans'][$id]["dialplan_xml"] = $dialplan_xml; + $array['dialplans'][$id]["dialplan_order"] = "230"; + $array['dialplans'][$id]["dialplan_enabled"] = "true"; + $array['dialplans'][$id]["dialplan_description"] = $row["queue_description"]; + $array['dialplans'][$id]["app_uuid"] = "95788e50-9500-079e-2807-fd530b0ea370"; + + //increment the array id + $id++; + + } + } + unset ($prep_statement); + + //save the array to the database + if (is_array($array)) { + //add the dialplan permission + $p = new permissions; + $p->add("dialplan_add", "temp"); + $p->add("dialplan_edit", "temp"); + + //save to the data + $database = new database; + $database->app_name = 'call_centers'; + $database->app_uuid = '95788e50-9500-079e-2807-fd530b0ea370'; + $database->save($array); + $message = $database->message; + + //remove the temporary permission + $p->delete("dialplan_add", "temp"); + $p->delete("dialplan_edit", "temp"); + } } -?> +?> \ No newline at end of file diff --git a/app/call_centers/call_center_queue_edit.php b/app/call_centers/call_center_queue_edit.php index ed2c7e5567..1acc6acb8e 100644 --- a/app/call_centers/call_center_queue_edit.php +++ b/app/call_centers/call_center_queue_edit.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2020 + Portions created by the Initial Developer are Copyright (C) 2008-2021 the Initial Developer. All Rights Reserved. Contributor(s): @@ -118,11 +118,13 @@ //set the variables $call_center_queue_uuid = $_REQUEST["id"]; $call_center_tier_uuid = $_REQUEST["call_center_tier_uuid"]; + //get the agent details - $sql = "select agent_name, queue_name, call_center_agent_uuid, call_center_queue_uuid "; - $sql .= "from v_call_center_tiers "; - $sql .= "where domain_uuid = :domain_uuid "; - $sql .= "and call_center_tier_uuid = :call_center_tier_uuid "; + $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'] = $_SESSION['domain_uuid']; $parameters['call_center_tier_uuid'] = $call_center_tier_uuid; $database = new database; @@ -133,8 +135,10 @@ 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 $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); @@ -142,10 +146,11 @@ if ($fp) { //callcenter_config tier del [queue_name] [agent_name] if (is_uuid($call_center_queue_uuid) && is_uuid($call_center_agent_uuid)) { - $cmd = "api callcenter_config tier del ".$call_center_queue_uuid."@".$_SESSION['domain_name']." ".$call_center_agent_uuid; + $cmd = "api callcenter_config tier del ".$queue_extension."@".$_SESSION['domain_name']." ".$call_center_agent_uuid; $response = event_socket_request($fp, $cmd); } } + //delete the tier from the database if (strlen($call_center_tier_uuid) > 0) { $array['call_center_tiers'][0]['call_center_tier_uuid'] = $call_center_tier_uuid; @@ -347,7 +352,7 @@ if (strlen($queue_cc_exit_keys) > 0) { $dialplan_xml .= " \n"; } - $dialplan_xml .= " \n"; + $dialplan_xml .= " \n"; if ($destination->valid($queue_timeout_app.':'.$queue_timeout_data)) { $dialplan_xml .= " \n"; } @@ -429,20 +434,20 @@ callcenter_config tier set position [queue_name] [agent_name] [position] */ //add the agent - if (is_uuid($call_center_queue_uuid) && is_uuid($call_center_agent_uuid) && is_numeric($tier_level) && is_numeric($tier_position)) { - $cmd = "api callcenter_config tier add ".$call_center_queue_uuid."@".$_SESSION["domain_name"]." ".$call_center_agent_uuid." ".$tier_level." ".$tier_position; + if (is_uuid($call_center_queue_uuid) && is_numeric($queue_extension) && is_numeric($tier_level) && is_numeric($tier_position)) { + $cmd = "api callcenter_config tier add ".$queue_extension."@".$_SESSION["domain_name"]." ".$call_center_agent_uuid." ".$tier_level." ".$tier_position; $response = event_socket_request($fp, $cmd); } usleep(200); //agent set level - if (is_uuid($call_center_queue_uuid) && is_uuid($call_center_agent_uuid) && is_numeric($tier_level)) { - $cmd = "api callcenter_config tier set level ".$call_center_queue_uuid."@".$_SESSION["domain_name"]." ".$call_center_agent_uuid." ".$tier_level; + if (is_uuid($call_center_queue_uuid) && is_numeric($queue_extension) && is_numeric($tier_level)) { + $cmd = "api callcenter_config tier set level ".$queue_extension."@".$_SESSION["domain_name"]." ".$call_center_agent_uuid." ".$tier_level; $response = event_socket_request($fp, $cmd); } usleep(200); //agent set position - if (is_uuid($call_center_queue_uuid) && is_uuid($call_center_agent_uuid) && is_numeric($tier_position)) { - $cmd = "api callcenter_config tier set position ".$call_center_queue_uuid."@".$_SESSION["domain_name"]." ".$tier_position; + if (is_uuid($call_center_queue_uuid) && is_numeric($queue_extension) && is_numeric($tier_position)) { + $cmd = "api callcenter_config tier set position ".$queue_extension."@".$_SESSION["domain_name"]." ".$tier_position; $response = event_socket_request($fp, $cmd); } usleep(200); diff --git a/app/call_centers/resources/classes/call_center.php b/app/call_centers/resources/classes/call_center.php index 169d289172..34b83ebd02 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 - 2016 + Copyright (C) 2015 - 2021 All Rights Reserved. Contributor(s): @@ -311,7 +311,7 @@ //get necessary details if (is_array($uuids) && @sizeof($uuids) != 0) { - $sql = "select ".$this->uuid_prefix."uuid as uuid, dialplan_uuid, queue_name from v_".$this->table." "; + $sql = "select ".$this->uuid_prefix."uuid as uuid, dialplan_uuid, queue_name, queue_extension from v_".$this->table." "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; @@ -321,6 +321,7 @@ foreach ($rows as $row) { $call_center_queues[$row['uuid']]['dialplan_uuid'] = $row['dialplan_uuid']; $call_center_queues[$row['uuid']]['queue_name'] = $row['queue_name']; + $call_center_queues[$row['uuid']]['queue_extension'] = $row['queue_extension']; } } unset($sql, $parameters, $rows, $row); @@ -338,7 +339,7 @@ $array['call_center_tiers'][$x][$this->uuid_prefix.'uuid'] = $call_center_queue_uuid; $array['call_center_tiers'][$x]['domain_uuid'] = $_SESSION['domain_uuid']; $x++; - $array['call_center_tiers'][$x]['queue_name'] = $call_center_queue['queue_name']."@".$_SESSION['domain_name']; + $array['call_center_tiers'][$x]['queue_name'] = $call_center_queue['queue_extension']."@".$_SESSION['domain_name']; $array['call_center_tiers'][$x]['domain_uuid'] = $_SESSION['domain_uuid']; $x++; } @@ -352,7 +353,7 @@ //delete the queue in the switch if ($fp) { foreach ($uuids as $uuid) { - $cmd = "api callcenter_config queue unload ".$uuid."@".$_SESSION["domin_name"]; + $cmd = "api callcenter_config queue unload ".$call_center_queues[$uuid]['queue_extension']."@".$_SESSION["domin_name"]; $response = event_socket_request($fp, $cmd); } } diff --git a/app/scripts/resources/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua b/app/scripts/resources/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua index b6efb21000..3321d80186 100644 --- a/app/scripts/resources/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua +++ b/app/scripts/resources/scripts/app/xml_handler/resources/scripts/configuration/callcenter.conf.lua @@ -1,6 +1,6 @@ -- xml_handler.lua -- Part of FusionPBX --- Copyright (C) 2015-2020 Mark J Crane +-- Copyright (C) 2015-2021 Mark J Crane -- All rights reserved. -- -- Redistribution and use in source and binary forms, with or without @@ -101,7 +101,7 @@ queue_name = queue_name:gsub(" ", "-"); --start the xml - table.insert(xml, [[ ]]); + table.insert(xml, [[ ]]); table.insert(xml, [[ ]]); --set ringback queue_ringback = format_ringback(queue_moh_sound); @@ -255,8 +255,10 @@ table.insert(xml, [[ ]]); --get the tiers - sql = "select * from v_call_center_tiers as t, v_domains as d "; - sql = sql .. "where d.domain_uuid = t.domain_uuid; "; + sql = "select t.domain_uuid, d.domain_name, t.call_center_agent_uuid, t.call_center_queue_uuid, q.queue_extension, t.tier_level, t.tier_position "; + sql = sql .. "from v_call_center_tiers as t, v_domains as d, v_call_center_queues as q "; + sql = sql .. "where d.domain_uuid = t.domain_uuid "; + sql = sql .. "and t.call_center_queue_uuid = q.call_center_queue_uuid; "; if (debug["sql"]) then freeswitch.consoleLog("notice", "[xml_handler] SQL: " .. sql .. "\n"); end @@ -267,12 +269,13 @@ domain_name = row.domain_name; agent_uuid = row.call_center_agent_uuid; queue_uuid = row.call_center_queue_uuid; + queue_extension = row.queue_extension; tier_level = row.tier_level; tier_position = row.tier_position; --build the xml table.insert(xml, [[