diff --git a/app/access_controls/access_control_edit.php b/app/access_controls/access_control_edit.php
index 8d85f0d3f2..352231bd72 100644
--- a/app/access_controls/access_control_edit.php
+++ b/app/access_controls/access_control_edit.php
@@ -118,10 +118,7 @@
$cache->delete("configuration:acl.conf");
//create the event socket connection
- $fp = event_socket_create();
- if ($fp) {
- event_socket_request($fp, "api reloadacl");
- }
+ event_socket::api("reloadacl");
//redirect the user
header('Location: access_control_edit.php?id='.$id);
@@ -204,10 +201,7 @@
$cache->delete("configuration:acl.conf");
//create the event socket connection
- $fp = event_socket_create();
- if ($fp) {
- event_socket_request($fp, "api reloadacl");
- }
+ event_socket::async("reloadacl");
//redirect the user
if (isset($action)) {
diff --git a/app/access_controls/access_controls_reload.php b/app/access_controls/access_controls_reload.php
index df735ec949..ea6304338d 100644
--- a/app/access_controls/access_controls_reload.php
+++ b/app/access_controls/access_controls_reload.php
@@ -40,18 +40,11 @@
//set the variables
$search = $_REQUEST['search'] ?? '';
-//create event socket connection
- $fp = event_socket_create();
- if ($fp) {
- //run the command
- $result = rtrim(event_socket_request($fp, 'api reloadacl'));
+//run the command
+ $result = rtrim(event_socket::api('reloadacl'));
- //add message
- message::add($result, 'alert');
-
- //close the connection
- fclose($fp);
- }
+//add message
+ message::add($result, 'alert');
//redirect
$search = preg_replace('#[^a-zA-Z0-9_\-\.]# ', '', $search);
diff --git a/app/access_controls/app_defaults.php b/app/access_controls/app_defaults.php
index c43a8382d0..7cf90760f0 100644
--- a/app/access_controls/app_defaults.php
+++ b/app/access_controls/app_defaults.php
@@ -157,12 +157,10 @@
$cache->delete("configuration:sofia.conf:".gethostname());
//create the event socket connection
- if (!$fp) {
- $fp = event_socket_create();
- }
+ $esl = event_socket::create();
//reload the acl
- event_socket_request($fp, "api reloadacl");
+ event_socket::async("reloadacl");
//rescan each sip profile
$sql = "select sip_profile_name from v_sip_profiles ";
@@ -171,10 +169,10 @@
$sip_profiles = $database->select($sql, null, 'all');
if (is_array($sip_profiles)) {
foreach ($sip_profiles as $row) {
- if ($fp) {
+ if ($esl->is_connected()) {
$command = "sofia profile '".$row['sip_profile_name']."' rescan";
//echo $command."\n";
- $result = event_socket_request($fp, "api ".$command);
+ $result = event_socket::api($command);
//echo $result."\n";
}
}
diff --git a/app/access_controls/resources/classes/access_controls.php b/app/access_controls/resources/classes/access_controls.php
index 56e1508106..36fae54113 100644
--- a/app/access_controls/resources/classes/access_controls.php
+++ b/app/access_controls/resources/classes/access_controls.php
@@ -87,10 +87,7 @@ if (!class_exists('access_controls')) {
$cache->delete("configuration:acl.conf");
//create the event socket connection
- $fp = event_socket_create();
- if ($fp) {
- event_socket_request($fp, "api reloadacl");
- }
+ event_socket::async("reloadacl");
//set message
message::add($text['message-delete']);
@@ -146,10 +143,7 @@ if (!class_exists('access_controls')) {
$cache->delete("configuration:acl.conf");
//create the event socket connection
- $fp = event_socket_create();
- if ($fp) {
- event_socket_request($fp, "api reloadacl");
- }
+ event_socket::async("reloadacl");
//set message
message::add($text['message-delete']);
@@ -261,10 +255,7 @@ if (!class_exists('access_controls')) {
$cache->delete("configuration:acl.conf");
//create the event socket connection
- $fp = event_socket_create();
- if ($fp) {
- event_socket_request($fp, "api reloadacl");
- }
+ event_socket::async("reloadacl");
//set message
message::add($text['message-copy']);
diff --git a/app/basic_operator_panel/exec.php b/app/basic_operator_panel/exec.php
index 7d44f13f4d..7b392c36d0 100644
--- a/app/basic_operator_panel/exec.php
+++ b/app/basic_operator_panel/exec.php
@@ -57,7 +57,7 @@ if (count($_GET) > 0) {
$direction = trim($_GET["direction"] ?? '');
//setup the event socket connection
- $fp = event_socket_create();
+ $esl = event_socket::create();
//allow specific commands
if (!empty($switch_cmd)) {
@@ -99,7 +99,7 @@ if (count($_GET) > 0) {
}
//run the command
- $switch_result = event_socket_request($fp, 'api '.$api_cmd);
+ $switch_result = event_socket::api($api_cmd);
/*
//record stop
diff --git a/app/basic_operator_panel/index.php b/app/basic_operator_panel/index.php
index 2fecd9f35f..54d04a4763 100644
--- a/app/basic_operator_panel/index.php
+++ b/app/basic_operator_panel/index.php
@@ -97,15 +97,15 @@
//update the user_status
if (is_uuid($call_center_agent_uuid)) {
- $fp = event_socket_create();
+ $esl = event_socket::create();
$switch_cmd .= "callcenter_config agent set status ".$call_center_agent_uuid." '".$user_status."'";
- $switch_result = event_socket_request($fp, 'api '.$switch_cmd);
+ $switch_result = event_socket::api($switch_cmd);
}
//update the user state
if (is_uuid($call_center_agent_uuid)) {
$cmd = "api callcenter_config agent set state ".$call_center_agent_uuid." Waiting";
- $response = event_socket_request($fp, $cmd);
+ $response = event_socket::api($cmd);
}
//update do not disturb
diff --git a/app/basic_operator_panel/resources/classes/basic_operator_panel.php b/app/basic_operator_panel/resources/classes/basic_operator_panel.php
index a68627b831..bcbff94eb6 100644
--- a/app/basic_operator_panel/resources/classes/basic_operator_panel.php
+++ b/app/basic_operator_panel/resources/classes/basic_operator_panel.php
@@ -86,10 +86,12 @@ if (!class_exists('basic_operator_panel')) {
}
//send the command
- $fp = event_socket_create();
- if ($fp) {
- $switch_result = event_socket_request($fp, 'api show channels as json');
+ $switch_result = event_socket::api('show channels as json');
+ if ($switch_result !== false) {
+ $fp = true;
$json_array = json_decode($switch_result, true);
+ } else {
+ $fp = false;
}
//build the response
@@ -205,8 +207,10 @@ if (!class_exists('basic_operator_panel')) {
if ($fp) {
if (is_uuid($field['uuid'])) {
$switch_cmd = 'uuid_dump '.$field['uuid'].' json';
- $dump_result = event_socket_request($fp, 'api '.$switch_cmd);
- $dump_array = json_decode($dump_result, true);
+ $dump_result = event_socket::api($switch_cmd);
+ if ($dump_result !== false) {
+ $dump_array = json_decode($dump_result, true);
+ }
if (is_array($dump_array)) {
foreach ($dump_array as $dump_var_name => $dump_var_value) {
$array[$x][$dump_var_name] = $dump_var_value;
diff --git a/app/basic_operator_panel/resources/content.php b/app/basic_operator_panel/resources/content.php
index d2d300b189..bb220e1b64 100644
--- a/app/basic_operator_panel/resources/content.php
+++ b/app/basic_operator_panel/resources/content.php
@@ -64,9 +64,8 @@ if (!empty($groups)) {
}
//get the valet info
-$fp = event_socket_create();
-if ($fp) {
- $valet_info = event_socket_request($fp, 'api valet_info park@'.$_SESSION['domain_name']);
+$valet_info = event_socket::api('valet_info park@'.$_SESSION['domain_name']);
+if ($valet_info !== false) {
//get an array of the valet call uuid and park numbers
if (isset($valet_info)) {
@@ -78,10 +77,10 @@ if ($fp) {
//unset($_SESSION['valet']);
foreach($valet_matches as $row) {
if (!isset($_SESSION['valet']['uuid']['caller_id_name'])) {
- $_SESSION['valet'][$row[1]]['caller_id_name'] = event_socket_request($fp, 'api uuid_getvar '.$row[1].' caller_id_name');
+ $_SESSION['valet'][$row[1]]['caller_id_name'] = event_socket::api('uuid_getvar '.$row[1].' caller_id_name');
}
if (!isset($_SESSION['valet']['uuid']['caller_id_number'])) {
- $_SESSION['valet'][$row[1]]['caller_id_number'] = event_socket_request($fp, 'api uuid_getvar '.$row[1].' caller_id_number');
+ $_SESSION['valet'][$row[1]]['caller_id_number'] = event_socket::api('uuid_getvar '.$row[1].' caller_id_number');
}
}
diff --git a/app/call_broadcast/call_broadcast_send.php b/app/call_broadcast/call_broadcast_send.php
index 1280942453..89495b5c0d 100644
--- a/app/call_broadcast/call_broadcast_send.php
+++ b/app/call_broadcast/call_broadcast_send.php
@@ -130,7 +130,7 @@
$broadcast_name = str_replace("'", "", $broadcast_name);
//create the event socket connection
- $fp = event_socket_create();
+ $fp = event_socket::create();
//get information over event socket
if (!$fp) {
@@ -196,11 +196,11 @@
//if the event socket connection is lost then re-connect
if (!$fp) {
- $fp = event_socket_create();
+ $fp = event_socket::create();
}
//method 1
- $response = trim(event_socket_request($fp, 'api '.$cmd));
+ $response = trim(event_socket::command($cmd));
//method 2
//cmd_async($_SESSION['switch']['bin']['dir']."/fs_cli -x \"".$cmd."\";");
@@ -216,8 +216,7 @@
$count++;
}
}
- fclose($fp);
-
+
echo "
\n";
echo "
\n";
echo "
\n";
diff --git a/app/call_broadcast/call_broadcast_stop.php b/app/call_broadcast/call_broadcast_stop.php
index e235eda429..08e3689506 100644
--- a/app/call_broadcast/call_broadcast_stop.php
+++ b/app/call_broadcast/call_broadcast_stop.php
@@ -45,10 +45,10 @@ else {
if (is_uuid($uuid)) {
//show the result
if (count($_GET) > 0) {
- $fp = event_socket_create();
- if ($fp) {
+ $fp = event_socket::create();
+ if ($fp !== false) {
$cmd = "sched_del ".$uuid;
- $result = event_socket_request($fp, 'api '.$cmd);
+ $result = event_socket::api($cmd);
message::add(htmlentities($result));
}
}
diff --git a/app/call_center_active/call_center_active_inc.php b/app/call_center_active/call_center_active_inc.php
index 9729b40c72..a2b512b8be 100644
--- a/app/call_center_active/call_center_active_inc.php
+++ b/app/call_center_active/call_center_active_inc.php
@@ -90,10 +90,10 @@
}
//create an event socket connection
- $fp = event_socket_create();
+ $esl = event_socket::create();
//get the call center queue, agent and tiers list
- if (!$fp) {
+ if (!$esl->is_connected()) {
$msg = "
Connection to Event Socket failed.
";
echo "
\n";
echo "
\n";
@@ -117,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_extension."@".$_SESSION["domain_name"];
- $event_socket_str = trim(event_socket_request($fp, 'api '.$switch_command));
+ $event_socket_str = trim(event_socket::api($switch_command));
$result = str_to_named_array($event_socket_str, '|');
//prepare the result for array_multisort
@@ -139,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_extension."@".$_SESSION["domain_name"];
- $event_socket_str = trim(event_socket_request($fp, 'api '.$switch_command));
+ $event_socket_str = trim(event_socket::api($switch_command));
$agent_result = str_to_named_array($event_socket_str, '|');
//get the agents from the database
@@ -280,7 +280,7 @@
//callcenter_config queue list members [queue_name]
if (is_uuid($queue_uuid)) {
$switch_command = 'callcenter_config queue list members '.$queue_extension."@".$_SESSION["domain_name"];
- $event_socket_str = trim(event_socket_request($fp, 'api '.$switch_command));
+ $event_socket_str = trim(event_socket::api($switch_command));
$result = str_to_named_array($event_socket_str, '|');
if (!is_array($result)) { unset($result); }
}
diff --git a/app/call_center_active/call_center_exec.php b/app/call_center_active/call_center_exec.php
index cbe5e5c189..15903d3226 100644
--- a/app/call_center_active/call_center_exec.php
+++ b/app/call_center_active/call_center_exec.php
@@ -90,8 +90,7 @@
//run the command
if (isset($switch_command)) {
- $fp = event_socket_create();
- $response = event_socket_request($fp, 'api '.$switch_command);
+ $response = event_socket::api($switch_command);
}
/*
@@ -134,14 +133,14 @@
//fs cmd
if (!empty($switch_cmd)) {
//setup the event socket connection
- $fp = event_socket_create();
+ $esl = event_socket::create();
//ensure the connection exists
- if ($fp) {
+ if ($esl) {
//send the command
- $switch_result = event_socket_request($fp, 'api '.$switch_cmd);
+ $switch_result = event_socket::api($switch_cmd);
//set the user state
$cmd = "api callcenter_config agent set state ".$username."@".$_SESSION['domain_name']." Waiting";
- $response = event_socket_request($fp, $cmd);
+ $response = event_socket::command($cmd);
}
}
}
diff --git a/app/call_centers/call_center_agent_edit.php b/app/call_centers/call_center_agent_edit.php
index fba293e2e8..5e2ee5fce4 100644
--- a/app/call_centers/call_center_agent_edit.php
+++ b/app/call_centers/call_center_agent_edit.php
@@ -238,37 +238,37 @@
//add the agent
//setup the event socket connection
- $fp = event_socket_create();
+ $esl = event_socket::create();
//add the agent using event socket
- if ($fp) {
+ if ($esl->connected()) {
//add the agent
- $cmd = "api callcenter_config agent add ".$call_center_agent_uuid." ".$agent_type;
- $response = event_socket_request($fp, $cmd);
+ $cmd = "callcenter_config agent add ".$call_center_agent_uuid." '".$agent_type."'";
+ $response = event_socket::api($cmd);
usleep(200);
//agent set contact
- $cmd = "api callcenter_config agent set contact ".$call_center_agent_uuid." ".$agent_contact;
- $response = event_socket_request($fp, $cmd);
+ $cmd = "callcenter_config agent set contact ".$call_center_agent_uuid." '".$agent_contact."'";
+ $response = event_socket::api($cmd);
usleep(200);
//agent set status
- $cmd = "api callcenter_config agent set status ".$call_center_agent_uuid." '".$agent_status."'";
- $response = event_socket_request($fp, $cmd);
+ $cmd = "callcenter_config agent set status ".$call_center_agent_uuid." '".$agent_status."'";
+ $response = event_socket::api($cmd);
usleep(200);
//agent set reject_delay_time
- $cmd = "api callcenter_config agent set reject_delay_time ".$call_center_agent_uuid." ".$agent_reject_delay_time;
- $response = event_socket_request($fp, $cmd);
+ $cmd = 'callcenter_config agent set reject_delay_time '.$call_center_agent_uuid.' '. $agent_reject_delay_time;
+ $response = event_socket::api($cmd);
usleep(200);
//agent set busy_delay_time
- $cmd = "api callcenter_config agent set busy_delay_time ".$call_center_agent_uuid." ".$agent_busy_delay_time;
- $response = event_socket_request($fp, $cmd);
+ $cmd = 'callcenter_config agent set busy_delay_time '.$call_center_agent_uuid.' '.$agent_busy_delay_time;
+ $response = event_socket::api($cmd);
//agent set no_answer_delay_time
- $cmd = "api callcenter_config agent set no_answer_delay_time ".$call_center_agent_uuid." ".$agent_no_answer_delay_time;
- $response = event_socket_request($fp, $cmd);
+ $cmd = 'callcenter_config agent set no_answer_delay_time '.$call_center_agent_uuid.' '.$agent_no_answer_delay_time;
+ $response = event_socket::api($cmd);
//agent set max_no_answer
- $cmd = "api callcenter_config agent set max_no_answer ".$call_center_agent_uuid." ".$agent_max_no_answer;
- $response = event_socket_request($fp, $cmd);
+ $cmd = 'callcenter_config agent set max_no_answer '.$call_center_agent_uuid.' '.$agent_max_no_answer;
+ $response = event_socket::api($cmd);
//agent set wrap_up_time
- $cmd = "api callcenter_config agent set wrap_up_time ".$call_center_agent_uuid." ".$agent_wrap_up_time;
- $response = event_socket_request($fp, $cmd);
+ $cmd = 'callcenter_config agent set wrap_up_time '.$call_center_agent_uuid.' '.$agent_wrap_up_time;
+ $response = event_socket::api($cmd);
}
//redirect the user
diff --git a/app/call_centers/call_center_agent_status.php b/app/call_centers/call_center_agent_status.php
index 04a80ec222..137e1db0cc 100644
--- a/app/call_centers/call_center_agent_status.php
+++ b/app/call_centers/call_center_agent_status.php
@@ -57,7 +57,7 @@
unset($sql, $parameters);
//setup the event socket connection
- $fp = event_socket_create();
+ $esl = event_socket::create();
//get the agents from the database
$sql = "select * from v_call_center_agents ";
@@ -70,12 +70,12 @@
//get the agent list from event socket
$switch_cmd = 'callcenter_config agent list';
- $event_socket_str = trim(event_socket_request($fp, 'api '.$switch_cmd));
+ $event_socket_str = trim(event_socket::api($switch_cmd));
$agent_list = csv_to_named_array($event_socket_str, '|');
//get the agent list from event socket
$switch_cmd = 'callcenter_config tier list';
- $event_socket_str = trim(event_socket_request($fp, 'api '.$switch_cmd));
+ $event_socket_str = trim(event_socket::api($switch_cmd));
$call_center_tiers = csv_to_named_array($event_socket_str, '|');
//get the call center queues from the database
@@ -100,7 +100,7 @@
//get the queue list from event socket
$switch_cmd = "callcenter_config queue list agents ".$queue_id;
- $event_socket_str = trim(event_socket_request($fp, 'api '.$switch_cmd));
+ $event_socket_str = trim(event_socket::api($switch_cmd));
$queue_list = csv_to_named_array($event_socket_str, '|');
$call_center_queues[$x]['queue_list'] = $queue_list;
$x++;
@@ -165,7 +165,7 @@
foreach($_POST['agents'] as $row) {
if (!empty($row['agent_status'])) {
//agent set status
- if ($fp) {
+ if ($esl->is_connected()) {
//set the user_status
if (!isset($row['queue_name'])) {
$array['users'][0]['user_uuid'] = $row['user_uuid'] ?? null;
@@ -211,20 +211,20 @@
//set the call center status to Logged Out
if (is_uuid($row['agent_uuid'])) {
- $command = "api callcenter_config agent set status ".$row['agent_uuid']." 'Logged Out' ";
- $response = event_socket_request($fp, $command);
+ $command = "callcenter_config agent set status ".$row['agent_uuid']." 'Logged Out' ";
+ $response = event_socket::api($command);
}
}
else {
if (is_uuid($row['agent_uuid'])) {
//set the agent status
- $command = "api callcenter_config agent set status ".$row['agent_uuid']." '".$agent_status."'";
- $response = event_socket_request($fp, $command);
+ $command = "callcenter_config agent set status ".$row['agent_uuid']." '".$agent_status."'";
+ $response = event_socket::api($command);
//set the agent state
if ($agent_status == 'Available' || $agent_status == 'Logged Out') {
- $command = "api callcenter_config agent set state ".$row['agent_uuid']." 'Waiting'";
- $response = event_socket_request($fp, $command);
+ $command = "callcenter_config agent set state ".$row['agent_uuid']." 'Waiting'";
+ $response = event_socket::api($command);
}
}
}
@@ -247,22 +247,21 @@
if (isset($row['queue_uuid']) && $row['agent_status'] == 'Available') {
//set the call center status
//$command = "api callcenter_config agent set status ".$row['agent_name']."@".$_SESSION['domain_name']." '".$row['agent_status']."'";
- //$response = event_socket_request($fp, $command);
+ //$response = event_socket::command($command);
//assign the agent to the queue
if (is_uuid($row['queue_uuid']) && is_uuid($row['agent_uuid'])) {
- $command = "api callcenter_config tier add ".$queue_id." ".$row['agent_uuid']." 1 1";
- //echo $command." \n";
- $response = event_socket_request($fp, $command);
+ $command = "callcenter_config tier add ".$queue_id." ".$row['agent_uuid']." 1 1";
+ $response = event_socket::api($command);
}
}
//un-assign the agent from the queue
if (isset($row['queue_uuid']) && $row['agent_status'] == 'Logged Out') {
if (is_uuid($row['queue_uuid']) && is_uuid($row['agent_uuid'])) {
- $command = "api callcenter_config tier del ".$queue_id." ".$row['agent_uuid'];
+ $command = "callcenter_config tier del ".$queue_id." ".$row['agent_uuid'];
//echo $command." \n";
- $response = event_socket_request($fp, $command);
+ $response = event_socket::api($command);
}
}
usleep(200);
diff --git a/app/call_centers/call_center_queue_edit.php b/app/call_centers/call_center_queue_edit.php
index 0155f9b4b2..2bfc02e30c 100644
--- a/app/call_centers/call_center_queue_edit.php
+++ b/app/call_centers/call_center_queue_edit.php
@@ -160,13 +160,13 @@
//delete the agent from freeswitch
//setup the event socket connection
- $fp = event_socket_create();
+ $esl = event_socket::create();
//delete the agent over event socket
- if ($fp) {
+ if ($esl->is_connected()) {
//callcenter_config tier del [queue_name] [agent_name]
if (is_numeric($queue_extension) && is_uuid($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);
+ $cmd = "callcenter_config tier del ".$queue_extension."@".$_SESSION['domain_name']." ".$call_center_agent_uuid;
+ $response = event_socket::api($cmd);
}
}
@@ -468,9 +468,9 @@
if (!empty($agent_name)) {
//setup the event socket connection
- $fp = event_socket_create();
+ $esl = event_socket::create();
//add the agent using event socket
- if ($fp) {
+ if ($esl->is_connected()) {
/* syntax:
callcenter_config tier add [queue_name] [agent_name] [level] [position]
callcenter_config tier set state [queue_name] [agent_name] [state]
@@ -479,20 +479,20 @@
*/
//add the agent
if (is_numeric($queue_extension) && is_uuid($call_center_agent_uuid) && 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);
+ $cmd = "callcenter_config tier add ".$queue_extension."@".$_SESSION["domain_name"]." ".$call_center_agent_uuid." ".$tier_level." ".$tier_position;
+ $response = event_socket::api($cmd);
}
usleep(200);
//agent set level
if (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);
+ $cmd = "callcenter_config tier set level ".$queue_extension."@".$_SESSION["domain_name"]." ".$call_center_agent_uuid." ".$tier_level;
+ $response = event_socket::api($cmd);
}
usleep(200);
//agent set position
if (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);
+ $cmd = "callcenter_config tier set position ".$queue_extension."@".$_SESSION["domain_name"]." ".$tier_position;
+ $response = event_socket::api($cmd);
}
usleep(200);
}
diff --git a/app/call_centers/cmd.php b/app/call_centers/cmd.php
index 1c3fa73ca6..fd2b45aabe 100644
--- a/app/call_centers/cmd.php
+++ b/app/call_centers/cmd.php
@@ -70,11 +70,10 @@
//connect to event socket
if (isset($queue_extension) && isset($cmd)) {
- $fp = event_socket_create();
- if ($fp) {
- $response = event_socket_request($fp, 'api reloadxml');
- $response = event_socket_request($fp, 'api callcenter_config queue '.$cmd. ' '.$queue_extension."@".$_SESSION["domain_name"]);
- fclose($fp);
+ $esl = event_socket::create();
+ if ($esl->is_connected()) {
+ $response = event_socket::api('reloadxml');
+ $response = event_socket::api('callcenter_config queue '.$cmd.' '.$queue_extension.'@'.$_SESSION['domain_name']);
}
else {
$response = '';
@@ -85,4 +84,4 @@
$_SESSION["message"] = $response;
header("Location: call_center_queues.php?savemsg=".urlencode($response));
-?>
\ No newline at end of file
+?>
diff --git a/app/call_centers/resources/classes/call_center.php b/app/call_centers/resources/classes/call_center.php
index 827adc9430..3985c9ce59 100644
--- a/app/call_centers/resources/classes/call_center.php
+++ b/app/call_centers/resources/classes/call_center.php
@@ -338,13 +338,13 @@
if (is_array($array) && @sizeof($array) != 0) {
//setup the event socket connection
- $fp = event_socket_create();
+ $esl = event_socket::create();
//delete the queue in the switch
- if ($fp) {
+ if ($esl->is_connected()) {
foreach ($uuids as $uuid) {
- $cmd = "api callcenter_config queue unload ".$call_center_queues[$uuid]['queue_extension']."@".$_SESSION["domain_name"];
- $response = event_socket_request($fp, $cmd);
+ $cmd = "callcenter_config queue unload ".$call_center_queues[$uuid]['queue_extension']."@".$_SESSION['domain_name'];
+ $response = event_socket::api($cmd);
}
}
@@ -436,13 +436,12 @@
if (is_array($array) && @sizeof($array) != 0) {
//setup the event socket connection
- $fp = event_socket_create();
+ $esl = event_socket::create();
//delete the agent in the switch
- if ($fp) {
+ if ($esl->is_connected()) {
foreach ($uuids as $uuid) {
- $cmd = "api callcenter_config agent del ".$uuid;
- $response = event_socket_request($fp, $cmd);
+ event_socket::async("callcenter_config agent del $uuid");
}
}
@@ -627,4 +626,4 @@ $c->queue_cc_exit_keys = "";
$c->dialplan();
*/
-?>
\ No newline at end of file
+?>
diff --git a/app/call_centers/resources/dashboard/call_center_agents.php b/app/call_centers/resources/dashboard/call_center_agents.php
index a68846d34f..18fa2f2782 100644
--- a/app/call_centers/resources/dashboard/call_center_agents.php
+++ b/app/call_centers/resources/dashboard/call_center_agents.php
@@ -51,7 +51,7 @@
}
//setup the event socket connection
- $fp = event_socket_create();
+ $esl = event_socket::create();
//get the http post values and set them as php variables
if (!empty($_POST['agents'])) {
@@ -91,8 +91,8 @@
$result = $database->save($array);
//send the agent status status to mod_call_center
- $cmd = "api callcenter_config agent set status ".$agent_uuid." '".$agent_status."'";
- $response = event_socket_request($fp, $cmd);
+ $cmd = "callcenter_config agent set status ".$agent_uuid." '".$agent_status."'";
+ $response = event_socket::api($cmd);
//add or delete agents from the queue assigned by the tier
foreach ($_POST['agents'] as $row) {
@@ -103,21 +103,21 @@
//set the agent status to available and assign the agent to the queue with the tier
if ($row['agent_status'] == 'Available') {
//assign the agent to the queue
- $cmd = "api callcenter_config tier add ".$row['queue_extension']."@".$_SESSION['domain_name']." ".$row['id']." 1 1";
- $response = event_socket_request($fp, $cmd);
+ $cmd = "callcenter_config tier add ".$row['queue_extension']."@".$_SESSION['domain_name']." ".$row['id']." 1 1";
+ $response = event_socket::api($cmd);
}
//set the agent status to available and assign the agent to the queue with the tier
if ($row['agent_status'] == 'On Break') {
//assign the agent to the queue
- $cmd = "api callcenter_config tier add ".$row['queue_extension']."@".$_SESSION['domain_name']." ".$row['id']." 1 1";
- $response = event_socket_request($fp, $cmd);
+ $cmd = "callcenter_config tier add ".$row['queue_extension']."@".$_SESSION['domain_name']." ".$row['id']." 1 1";
+ $response = event_socket::api($cmd);
}
//un-assign the agent from the queue
if ($row['agent_status'] == 'Logged Out') {
- $cmd = "api callcenter_config tier del ".$row['queue_extension']."@".$_SESSION['domain_name']." ".$row['id'];
- $response = event_socket_request($fp, $cmd);
+ $cmd = "callcenter_config tier del ".$row['queue_extension']."@".$_SESSION['domain_name']." ".$row['id'];
+ $response = event_socket::api($cmd);
}
//small sleep
@@ -132,7 +132,7 @@
//get the agent list from event socket
$switch_cmd = 'callcenter_config tier list';
- $event_socket_str = trim(event_socket_request($fp, 'api '.$switch_cmd));
+ $event_socket_str = trim(event_socket::api($switch_cmd));
$call_center_tiers = csv_to_named_array($event_socket_str, '|');
//get the agents from the database
diff --git a/app/call_centers/resources/jobs/call_center_agents.php b/app/call_centers/resources/jobs/call_center_agents.php
index 29f3aca9cb..ec83d3f9b4 100644
--- a/app/call_centers/resources/jobs/call_center_agents.php
+++ b/app/call_centers/resources/jobs/call_center_agents.php
@@ -31,11 +31,11 @@
}
//connect to event socket
- $fp = event_socket_create();
+ $esl = event_socket::create();
//get the agent list from event socket
$switch_cmd = 'callcenter_config agent list';
- $event_socket_str = trim(event_socket_request($fp, 'api '.$switch_cmd));
+ $event_socket_str = trim(event_socket::api($switch_cmd));
$agent_list = csv_to_named_array($event_socket_str, '|');
//get the agents from the database
@@ -69,7 +69,7 @@
}
//build the event
- if ($fp) {
+ if ($esl->is_connected()) {
$event = "sendevent PRESENCE_IN\n";
$event .= "proto: agent\n";
$event .= "from: ".$row['agent_name']."@".$row['domain_name']."\n";
@@ -104,16 +104,13 @@
}
//send the event
- $result = event_socket_request($fp, $event);
+ $result = event_socket::command($event);
if (isset($debug)) {
print_r($result, false);
}
}
- //close event socket connection
- fclose($fp);
-
/*
* * * * * cd /var/www/fusionpbx && php /var/www/fusionpbx/app/call_centers/resources/jobs/call_center_agents.php
*/
diff --git a/app/call_flows/call_flow_edit.php b/app/call_flows/call_flow_edit.php
index 7de365c31f..6dc771231f 100644
--- a/app/call_flows/call_flow_edit.php
+++ b/app/call_flows/call_flow_edit.php
@@ -257,8 +257,8 @@
// Update subscribed endpoints
if (!empty($call_flow_feature_code)) {
- $fp = event_socket_create();
- if ($fp) {
+ $esl = event_socket::create();
+ if ($esl->is_connected()) {
//send the event
$event = "sendevent PRESENCE_IN\n";
$event .= "proto: flow\n";
@@ -274,8 +274,7 @@
} else {
$event .= "answer-state: terminated\n";
}
- event_socket_request($fp, $event);
- fclose($fp);
+ event_socket::command($event);
}
}
diff --git a/app/call_flows/resources/classes/call_flows.php b/app/call_flows/resources/classes/call_flows.php
index 264d7759ce..1113548e7b 100644
--- a/app/call_flows/resources/classes/call_flows.php
+++ b/app/call_flows/resources/classes/call_flows.php
@@ -281,8 +281,7 @@ if (!class_exists('call_flows')) {
}
//send the event
- $fp = event_socket_create();
- $switch_result = event_socket_request($fp, $cmd);
+ $switch_result = event_socket::command($cmd);
}
}
unset($call_flows);
diff --git a/app/call_forward/call_forward_edit.php b/app/call_forward/call_forward_edit.php
index 119ede042a..873ce77372 100644
--- a/app/call_forward/call_forward_edit.php
+++ b/app/call_forward/call_forward_edit.php
@@ -399,9 +399,7 @@
$cmd .= "answer-state: confirmed\n";
//send the event
- $fp = event_socket_create();
- $switch_result = event_socket_request($fp, $cmd);
- unset($fp);
+ $switch_result = event_socket::command($cmd);
}
else {
$presence = new presence;
@@ -421,9 +419,7 @@
$cmd .= "answer-state: terminated\n";
//send the event
- $fp = event_socket_create();
- $switch_result = event_socket_request($fp, $cmd);
- unset($fp);
+ $switch_result = event_socket::command($cmd);
}
}
}
diff --git a/app/call_forward/resources/classes/do_not_disturb.php b/app/call_forward/resources/classes/do_not_disturb.php
index 94226edca7..ce1523762e 100644
--- a/app/call_forward/resources/classes/do_not_disturb.php
+++ b/app/call_forward/resources/classes/do_not_disturb.php
@@ -39,10 +39,10 @@
if ($this->enabled == "true") {
//update the call center status
$user_status = "Logged Out";
- $fp = event_socket_create();
- if ($fp) {
+ $esl = event_socket::create();
+ if ($esl->is_connected()) {
$switch_cmd .= "callcenter_config agent set status ".$_SESSION['username']."@".$this->domain_name." '".$user_status."'";
- $switch_result = event_socket_request($fp, 'api '.$switch_cmd);
+ $switch_result = event_socket::api($switch_cmd);
}
//update the database user_status
diff --git a/app/call_forward/resources/classes/feature_event_notify.php b/app/call_forward/resources/classes/feature_event_notify.php
index ec0afa5a0f..a9173dcb55 100644
--- a/app/call_forward/resources/classes/feature_event_notify.php
+++ b/app/call_forward/resources/classes/feature_event_notify.php
@@ -42,11 +42,11 @@
//feature_event method
public function send_notify() {
- $fp = event_socket_create();
- if ($fp) {
+ $esl = event_socket::create();
+ if ($esl->is_connected()) {
// Get the SIP profiles for the extension
$command = "sofia_contact */{$this->extension}@{$this->domain_name}";
- $contact_string = event_socket_request($fp, "api ".$command);
+ $contact_string = event_socket::api($command);
// The first value in the array will be full matching text, the second one will be the array of profile matches
preg_match_all('/sofia\/([^,]+)\/(?:[^,]+)/', $contact_string, $matches);
if (sizeof($matches) != 2 || sizeof($matches[1]) < 1) {
@@ -72,12 +72,11 @@
$event .= "forward_no_answer: " . $this->forward_no_answer_destination . "\n";
$event .= "doNotDisturbOn: " . $this->do_not_disturb . "\n";
$event .= "ringCount: " . $this->ring_count . "\n";
- event_socket_request($fp, $event);
+ event_socket::command($event);
}
- fclose($fp);
}
} //function
-
+
} //class
?>
diff --git a/app/call_forward/resources/jobs/dnd.php b/app/call_forward/resources/jobs/dnd.php
index 98f6b8aea6..f8cd0cc2db 100644
--- a/app/call_forward/resources/jobs/dnd.php
+++ b/app/call_forward/resources/jobs/dnd.php
@@ -3,7 +3,7 @@
//check the permission
if (defined('STDIN')) {
//includes files
- require_once dirname(__DIR__, 4) . "/resources/require.php";
+ require_once dirname(__DIR__, 4) . "/resources/require.php";
}
else {
exit;
@@ -31,54 +31,63 @@
exit;
}
-//connect to event socket
- $fp = event_socket_create();
+//use global conf created from require.php
+ global $conf;
-//get the list
- $sql = "select domain_name, extension, user_context, do_not_disturb, description ";
- $sql .= "from v_extensions as e, v_domains as d ";
- $sql .= "where do_not_disturb = 'true' ";
- $sql .= "and e.domain_uuid = d.domain_uuid ";
- $sql .= "and enabled = 'true' ";
- $database = new database;
- $results = $database->select($sql, $parameters, 'all');
- unset($parameters);
+//set the event socket connection settings
+ $host = $conf['switch.event_socket.host'] ?? $conf['event_socket.ip_address'] ?? '127.0.0.1';
+ $port = $conf['switch.event_socket.port'] ?? $conf['event_socket.port'] ?? '8021';
+ $pass = $conf['switch.event_socket.password'] ?? $conf['event_socket.password'] ?? 'ClueCon';
-//view_array($results);
- foreach($results as $row) {
+//connect to event socket using a lower timeout because we are on cli
+ $esl = event_socket::create($host, $port, $pass, 10000);
- //build the event
- $cmd = "sendevent PRESENCE_IN\n";
- $cmd .= "proto: sip\n";
- $cmd .= "login: ".$row['extension']."@".$row['domain_name']."\n";
- $cmd .= "from: ".$row['extension']."@".$row['domain_name']."\n";
- $cmd .= "status: Active (1 waiting)\n";
- $cmd .= "rpid: unknown\n";
- $cmd .= "event_type: presence\n";
- $cmd .= "alt_event_type: dialog\n";
- $cmd .= "event_count: 1\n";
- $cmd .= "unique-id: ".uuid()."\n";
- $cmd .= "Presence-Call-Direction: outbound\n";
- $cmd .= "answer-state: confirmed\n";
- //$cmd .= "answer-state: early\n";
- //$cmd .= "answer-state: terminated\n";
+//ensure we are connected
+ if ($esl->is_connected()) {
- //send message to the console
- if (isset($debug)) {
- echo "\n";
- echo "[presence] dnd ".$row['extension']."@".$row['domain_name']."\n";
+ //get the list
+ $sql = "select domain_name, extension, user_context, do_not_disturb, description ";
+ $sql .= "from v_extensions as e, v_domains as d ";
+ $sql .= "where do_not_disturb = 'true' ";
+ $sql .= "and e.domain_uuid = d.domain_uuid ";
+ $sql .= "and enabled = 'true' ";
+ $database = new database;
+ $results = $database->select($sql, $parameters, 'all');
+ unset($parameters);
+ foreach ($results as $row) {
+
+ //build the event
+ $cmd = "sendevent PRESENCE_IN\n";
+ $cmd .= "proto: sip\n";
+ $cmd .= "login: " . $row['extension'] . "@" . $row['domain_name'] . "\n";
+ $cmd .= "from: " . $row['extension'] . "@" . $row['domain_name'] . "\n";
+ $cmd .= "status: Active (1 waiting)\n";
+ $cmd .= "rpid: unknown\n";
+ $cmd .= "event_type: presence\n";
+ $cmd .= "alt_event_type: dialog\n";
+ $cmd .= "event_count: 1\n";
+ $cmd .= "unique-id: " . uuid() . "\n";
+ $cmd .= "Presence-Call-Direction: outbound\n";
+ $cmd .= "answer-state: confirmed\n";
+ //$cmd .= "answer-state: early\n";
+ //$cmd .= "answer-state: terminated\n";
+ //send message to the console
+ if (isset($debug)) {
+ echo "\n";
+ echo "[presence] dnd " . $row['extension'] . "@" . $row['domain_name'] . "\n";
+ }
+
+ //send the event
+ $result = event_socket::command($cmd);
+ if (isset($debug)) {
+ print_r($result, false);
+ }
}
-
- //send the event
- $result = event_socket_request($fp, $cmd);
- if (isset($debug)) {
- print_r($result, false);
- }
-
+ }
+ else {
+ trigger_error("Unable to connect to FreeSWITCH using $host, $port, $password", E_USER_ERROR);
}
-/*
-* * * * * cd /var/www/fusionpbx && php /var/www/fusionpbx/app/call_forward/resources/jobs/dnd.php
-*/
-
-?>
+ /*
+ * * * * * cd /var/www/fusionpbx && php /var/www/fusionpbx/app/call_forward/resources/jobs/dnd.php
+ */
diff --git a/app/calls_active/calls_active_inc.php b/app/calls_active/calls_active_inc.php
index f7ff147e14..a6dc6307ce 100644
--- a/app/calls_active/calls_active_inc.php
+++ b/app/calls_active/calls_active_inc.php
@@ -52,11 +52,11 @@
$switch_cmd = 'show channels as json';
//create the event socket connection
- $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
+ $esl = event_socket::create();
//send the event socket command and get the array
- if ($fp) {
- $json = trim(event_socket_request($fp, 'api '.$switch_cmd));
+ if ($esl->is_connected()) {
+ $json = trim(event_socket::api($switch_cmd));
$results = json_decode($json, "true");
}
@@ -90,7 +90,7 @@
//if the connnection is available then run it and return the results
- if (!$fp) {
+ if (!$esl) {
$msg = "
".$text['confirm-socket']."
";
echo "
\n";
diff --git a/app/calls_active/calls_exec.php b/app/calls_active/calls_exec.php
index 652e4393f4..7706df5b16 100644
--- a/app/calls_active/calls_exec.php
+++ b/app/calls_active/calls_exec.php
@@ -58,6 +58,7 @@
exit;
}
+ $calls = [];
//verify submitted call uuids
if (is_array($_POST['calls']) && @sizeof($_POST['calls']) != 0) {
foreach ($_POST['calls'] as $call) {
@@ -71,18 +72,18 @@
}
//iterate through calls
- if (is_array($calls) && @sizeof($calls) != 0) {
+ if (count($calls) > 0) {
//setup the event socket connection
- $fp = event_socket_create();
+ $esl = event_socket::create();
//execute hangup command
- foreach ($calls as $call_uuid) {
- $switch_result = event_socket_request($fp, 'api uuid_kill '.$call_uuid);
+ if ($esl->is_connected()) foreach ($calls as $call_uuid) {
+ event_socket::async("uuid_kill $call_uuid");
}
//set message
- message::add($text['message-calls_ended'].': '.@sizeof($calls),'positive');
+ message::add($text['message-calls_ended'].': '.count($calls),'positive');
}
diff --git a/app/click_to_call/click_to_call.php b/app/click_to_call/click_to_call.php
index f612424072..93baec1d8b 100644
--- a/app/click_to_call/click_to_call.php
+++ b/app/click_to_call/click_to_call.php
@@ -93,124 +93,120 @@
}
//create the even socket connection and send the event socket command
- $fp = event_socket_create();
- if (!$fp) {
- //error message
- echo "
Connection to Event Socket failed.
";
- }
+ $esl = event_socket::create();
+ if ($esl->is_connected()) {
- //set call uuid
- $origination_uuid = trim(event_socket_request($fp, "api create_uuid"));
+ //set call uuid
+ $origination_uuid = trim(event_socket::api("create_uuid"));
- //add record path and name
- if ($rec == "true") {
- $record_path = $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/archive/".date("Y")."/".date("M")."/".date("d");
- if (isset($_SESSION['recordings']['extension']['text'])) {
- $record_extension = $_SESSION['recordings']['extension']['text'];
- }
- else {
- $record_extension = 'wav';
- }
- if (isset($_SESSION['recordings']['template']['text'])) {
- //${year}${month}${day}-${caller_id_number}-${caller_destination}-${uuid}.${record_extension}
- $record_name = $_SESSION['recordings']['template']['text'];
- $record_name = str_replace('${year}', date("Y"), $record_name);
- $record_name = str_replace('${month}', date("M"), $record_name);
- $record_name = str_replace('${day}', date("d"), $record_name);
- $record_name = str_replace('${source}', $src, $record_name);
- $record_name = str_replace('${caller_id_name}', $src_cid_name, $record_name);
- $record_name = str_replace('${caller_id_number}', $src_cid_number, $record_name);
- $record_name = str_replace('${caller_destination}', $dest, $record_name);
- $record_name = str_replace('${destination}', $dest, $record_name);
- $record_name = str_replace('${uuid}', $origination_uuid, $record_name);
- $record_name = str_replace('${record_extension}', $record_extension, $record_name);
- }
- else {
- $record_name = $origination_uuid.'.'.$record_extension;
- }
- }
-
- //determine call direction
- $dir = (user_exists($dest)) ? 'local' : 'outbound';
-
- //define a leg - set source to display the defined caller id name and number
- $source_common = "{";
- $source_common .= "click_to_call=true";
- $source_common .= ",origination_caller_id_name='".$src_cid_name."'";
- $source_common .= ",origination_caller_id_number=".$src_cid_number;
- $source_common .= ",instant_ringback=true";
- $source_common .= ",ringback=".$ringback_value;
- $source_common .= ",presence_id=".$src."@".$_SESSION['domains'][$domain_uuid]['domain_name'];
- $source_common .= ",call_direction=".$dir;
- if ($rec == "true") {
- $source_common .= ",record_path='".$record_path."'";
- $source_common .= ",record_name='".$record_name."'";
- }
-
- if (user_exists($src)) {
- //source is a local extension
- $source = $source_common.$sip_auto_answer.
- ",domain_uuid=".$domain_uuid.
- ",domain_name=".$_SESSION['domains'][$domain_uuid]['domain_name']."}user/".$src."@".$_SESSION['domains'][$domain_uuid]['domain_name'];
- }
- else {
- //source is an external number
- $bridge_array = outbound_route_to_bridge($_SESSION['domain_uuid'], $src);
- $source = $source_common."}".$bridge_array[0];
- }
- unset($source_common);
-
- //define b leg - set destination to display the defined caller id name and number
- $destination_common = " &bridge({origination_caller_id_name='".$dest_cid_name."',origination_caller_id_number=".$dest_cid_number;
- if (user_exists($dest)) {
- //destination is a local extension
- if (strpbrk($dest, '@') != FALSE) { //sip-uri
- $switch_cmd = $destination_common.",call_direction=outbound}sofia/external/".$dest.")";
- }
- else { //not sip-uri
- $switch_cmd = " &transfer('".$dest." XML ".$context."')";
- }
- }
- else {
- //local extension (source) > external number (destination)
- if (user_exists($src) && empty($dest_cid_number)) {
- //retrieve outbound caller id from the (source) extension
- $sql = "select outbound_caller_id_name, outbound_caller_id_number from v_extensions where domain_uuid = :domain_uuid and extension = :src ";
- $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
- $parameters['src'] = $src;
- $database = new database;
- $result = $database->select($sql, $parameters, 'all');
- foreach ($result as &$row) {
- $dest_cid_name = $row["outbound_caller_id_name"];
- $dest_cid_number = $row["outbound_caller_id_number"];
- break; //limit to 1 row
+ //add record path and name
+ if ($rec == "true") {
+ $record_path = $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/archive/".date("Y")."/".date("M")."/".date("d");
+ if (isset($_SESSION['recordings']['extension']['text'])) {
+ $record_extension = $_SESSION['recordings']['extension']['text'];
+ }
+ else {
+ $record_extension = 'wav';
+ }
+ if (isset($_SESSION['recordings']['template']['text'])) {
+ //${year}${month}${day}-${caller_id_number}-${caller_destination}-${uuid}.${record_extension}
+ $record_name = $_SESSION['recordings']['template']['text'];
+ $record_name = str_replace('${year}', date("Y"), $record_name);
+ $record_name = str_replace('${month}', date("M"), $record_name);
+ $record_name = str_replace('${day}', date("d"), $record_name);
+ $record_name = str_replace('${source}', $src, $record_name);
+ $record_name = str_replace('${caller_id_name}', $src_cid_name, $record_name);
+ $record_name = str_replace('${caller_id_number}', $src_cid_number, $record_name);
+ $record_name = str_replace('${caller_destination}', $dest, $record_name);
+ $record_name = str_replace('${destination}', $dest, $record_name);
+ $record_name = str_replace('${uuid}', $origination_uuid, $record_name);
+ $record_name = str_replace('${record_extension}', $record_extension, $record_name);
+ }
+ else {
+ $record_name = $origination_uuid.'.'.$record_extension;
}
}
- if (permission_exists('click_to_call_call')) {
+
+ //determine call direction
+ $dir = (user_exists($dest)) ? 'local' : 'outbound';
+
+ //define a leg - set source to display the defined caller id name and number
+ $source_common = "{";
+ $source_common .= "click_to_call=true";
+ $source_common .= ",origination_caller_id_name='".$src_cid_name."'";
+ $source_common .= ",origination_caller_id_number=".$src_cid_number;
+ $source_common .= ",instant_ringback=true";
+ $source_common .= ",ringback=".$ringback_value;
+ $source_common .= ",presence_id=".$src."@".$_SESSION['domains'][$domain_uuid]['domain_name'];
+ $source_common .= ",call_direction=".$dir;
+ if ($rec == "true") {
+ $source_common .= ",record_path='".$record_path."'";
+ $source_common .= ",record_name='".$record_name."'";
+ }
+
+ if (user_exists($src)) {
+ //source is a local extension
+ $source = $source_common.$sip_auto_answer.
+ ",domain_uuid=".$domain_uuid.
+ ",domain_name=".$_SESSION['domains'][$domain_uuid]['domain_name']."}user/".$src."@".$_SESSION['domains'][$domain_uuid]['domain_name'];
+ }
+ else {
+ //source is an external number
+ $bridge_array = outbound_route_to_bridge($_SESSION['domain_uuid'], $src);
+ $source = $source_common."}".$bridge_array[0];
+ }
+ unset($source_common);
+
+ //define b leg - set destination to display the defined caller id name and number
+ $destination_common = " &bridge({origination_caller_id_name='".$dest_cid_name."',origination_caller_id_number=".$dest_cid_number;
+ if (user_exists($dest)) {
+ //destination is a local extension
if (strpbrk($dest, '@') != FALSE) { //sip-uri
$switch_cmd = $destination_common.",call_direction=outbound}sofia/external/".$dest.")";
}
else { //not sip-uri
- $bridge_array = outbound_route_to_bridge($_SESSION['domain_uuid'], $dest);
- //$switch_cmd = $destination_common."}".$bridge_array[0].")"; // wouldn't set cdr destination correctly, so below used instead
$switch_cmd = " &transfer('".$dest." XML ".$context."')";
}
}
- }
- unset($destination_common);
-
- //create the even socket connection and send the event socket command
- $fp = event_socket_create();
- if (!$fp) {
+ else {
+ //local extension (source) > external number (destination)
+ if (user_exists($src) && empty($dest_cid_number)) {
+ //retrieve outbound caller id from the (source) extension
+ $sql = "select outbound_caller_id_name, outbound_caller_id_number from v_extensions where domain_uuid = :domain_uuid and extension = :src ";
+ $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
+ $parameters['src'] = $src;
+ $database = new database;
+ $result = $database->select($sql, $parameters, 'all');
+ foreach ($result as &$row) {
+ $dest_cid_name = $row["outbound_caller_id_name"];
+ $dest_cid_number = $row["outbound_caller_id_number"];
+ break; //limit to 1 row
+ }
+ }
+ if (permission_exists('click_to_call_call')) {
+ if (strpbrk($dest, '@') != FALSE) { //sip-uri
+ $switch_cmd = $destination_common.",call_direction=outbound}sofia/external/".$dest.")";
+ }
+ else { //not sip-uri
+ $bridge_array = outbound_route_to_bridge($_SESSION['domain_uuid'], $dest);
+ //$switch_cmd = $destination_common."}".$bridge_array[0].")"; // wouldn't set cdr destination correctly, so below used instead
+ $switch_cmd = " &transfer('".$dest." XML ".$context."')";
+ }
+ }
+ }
+ unset($destination_common);
+ } else {
//error message
echo "
Connection to Event Socket failed.
";
}
- else {
+
+ //ensure we are still connected and send the event socket command
+ if ($esl->is_connected()) {
//display the last command
- $switch_cmd = "api originate ".$source.$switch_cmd;
+ $switch_cmd = "originate ".$source.$switch_cmd;
echo "
".escape($src)." has called ".escape($dest)."
\n";
//show the command result
- $result = trim(event_socket_request($fp, $switch_cmd));
+ $result = trim(event_socket::api($switch_cmd));
if (substr($result, 0,3) == "+OK") {
//$uuid = substr($result, 4);
if ($rec == "true") {
@@ -218,12 +214,15 @@
date_default_timezone_set($_SESSION['time_zone']['system']);
//create the api record command and send it over event socket
if (is_uuid($origination_uuid) && file_exists($record_path)) {
- $switch_cmd = "api uuid_record ".$origination_uuid." start ".$record_path."/".$record_name;
+ $switch_cmd = "uuid_record $origination_uuid start $record_path/$record_name";
}
- $result2 = trim(event_socket_request($fp, $switch_cmd));
+ $result2 = trim(event_socket::api($switch_cmd));
}
}
echo "