Update click_to_call.php
This commit is contained in:
parent
b1674362d3
commit
fff7b78ab3
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/*
|
/*
|
||||||
call.php
|
click_to_call.php
|
||||||
Copyright (C) 2008, 2018 Mark J Crane
|
Copyright (C) 2008, 2018 Mark J Crane
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
|
|
@ -28,8 +28,8 @@
|
||||||
Contributor(s):
|
Contributor(s):
|
||||||
Mark J Crane <markjcrane@fusionpbx.com>
|
Mark J Crane <markjcrane@fusionpbx.com>
|
||||||
James Rose <james.o.rose@gmail.com>
|
James Rose <james.o.rose@gmail.com>
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//includes
|
//includes
|
||||||
include "root.php";
|
include "root.php";
|
||||||
require_once "resources/require.php";
|
require_once "resources/require.php";
|
||||||
|
|
@ -51,157 +51,178 @@
|
||||||
//include the header
|
//include the header
|
||||||
require_once "resources/header.php";
|
require_once "resources/header.php";
|
||||||
|
|
||||||
if (is_array($_REQUEST) && !empty($_REQUEST['src']) && !empty($_REQUEST['dest'])) {
|
//send the call
|
||||||
//retrieve submitted variables
|
if (is_array($_REQUEST) && !empty($_REQUEST['src']) && !empty($_REQUEST['dest'])) {
|
||||||
$src = check_str($_REQUEST['src']);
|
//retrieve submitted variables
|
||||||
$src_cid_name = check_str($_REQUEST['src_cid_name']);
|
$src = check_str($_REQUEST['src']);
|
||||||
$src_cid_number = check_str($_REQUEST['src_cid_number']);
|
$src_cid_name = check_str($_REQUEST['src_cid_name']);
|
||||||
|
$src_cid_number = check_str($_REQUEST['src_cid_number']);
|
||||||
|
|
||||||
$dest = check_str($_REQUEST['dest']);
|
$dest = check_str($_REQUEST['dest']);
|
||||||
$dest_cid_name = check_str($_REQUEST['dest_cid_name']);
|
$dest_cid_name = check_str($_REQUEST['dest_cid_name']);
|
||||||
$dest_cid_number = check_str($_REQUEST['dest_cid_number']);
|
$dest_cid_number = check_str($_REQUEST['dest_cid_number']);
|
||||||
|
|
||||||
$auto_answer = check_str($_REQUEST['auto_answer']); //true,false
|
$auto_answer = check_str($_REQUEST['auto_answer']); //true,false
|
||||||
$rec = check_str($_REQUEST['rec']); //true,false
|
$rec = check_str($_REQUEST['rec']); //true,false
|
||||||
$ringback = check_str($_REQUEST['ringback']);
|
$ringback = check_str($_REQUEST['ringback']);
|
||||||
$context = $_SESSION['context'];
|
$context = $_SESSION['context'];
|
||||||
|
|
||||||
//clean up variable values
|
//clean up variable values
|
||||||
$src = str_replace(array('.','(',')','-',' '), '', $src);
|
$src = str_replace(array('.','(',')','-',' '), '', $src);
|
||||||
$dest = (strpbrk($dest, '@') != FALSE) ? str_replace(array('(',')',' '), '', $dest) : str_replace(array('.','(',')','-',' '), '', $dest); //don't strip periods or dashes in sip-uri calls, only phone numbers
|
$dest = (strpbrk($dest, '@') != FALSE) ? str_replace(array('(',')',' '), '', $dest) : str_replace(array('.','(',')','-',' '), '', $dest); //don't strip periods or dashes in sip-uri calls, only phone numbers
|
||||||
|
|
||||||
//adjust variable values
|
//adjust variable values
|
||||||
$sip_auto_answer = ($auto_answer == "true") ? ",sip_auto_answer=true" : null;
|
$sip_auto_answer = ($auto_answer == "true") ? ",sip_auto_answer=true" : null;
|
||||||
|
|
||||||
//mozilla thunderbird TBDialout workaround (seems it can only handle the first %NUM%)
|
//mozilla thunderbird TBDialout workaround (seems it can only handle the first %NUM%)
|
||||||
$dest = ($dest == "%NUM%") ? $src_cid_number : $dest;
|
$dest = ($dest == "%NUM%") ? $src_cid_number : $dest;
|
||||||
|
|
||||||
//translate ringback
|
//translate ringback
|
||||||
switch ($ringback) {
|
switch ($ringback) {
|
||||||
case "music": $ringback_value = "\'local_stream://moh\'"; break;
|
case "music": $ringback_value = "\'local_stream://moh\'"; break;
|
||||||
case "uk-ring": $ringback_value = "\'%(400,200,400,450);%(400,2200,400,450)\'"; break;
|
case "uk-ring": $ringback_value = "\'%(400,200,400,450);%(400,2200,400,450)\'"; break;
|
||||||
case "fr-ring": $ringback_value = "\'%(1500,3500,440.0,0.0)\'"; break;
|
case "fr-ring": $ringback_value = "\'%(1500,3500,440.0,0.0)\'"; break;
|
||||||
case "pt-ring": $ringback_value = "\'%(1000,5000,400.0,0.0)\'"; break;
|
case "pt-ring": $ringback_value = "\'%(1000,5000,400.0,0.0)\'"; break;
|
||||||
case "rs-ring": $ringback_value = "\'%(1000,4000,425.0,0.0)\'"; break;
|
case "rs-ring": $ringback_value = "\'%(1000,4000,425.0,0.0)\'"; break;
|
||||||
case "it-ring": $ringback_value = "\'%(1000,4000,425.0,0.0)\'"; break;
|
case "it-ring": $ringback_value = "\'%(1000,4000,425.0,0.0)\'"; break;
|
||||||
case "de-ring": $ringback_value = "\'%(1000,4000,425.0,0.0)\'"; break;
|
case "de-ring": $ringback_value = "\'%(1000,4000,425.0,0.0)\'"; break;
|
||||||
case "us-ring":
|
case "us-ring":
|
||||||
default:
|
default:
|
||||||
$ringback = 'us-ring';
|
$ringback = 'us-ring';
|
||||||
$ringback_value = "\'%(2000,4000,440.0,480.0)\'";
|
$ringback_value = "\'%(2000,4000,440.0,480.0)\'";
|
||||||
}
|
|
||||||
|
|
||||||
//create the even socket connection and send the event socket command
|
|
||||||
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
|
||||||
if (!$fp) {
|
|
||||||
//error message
|
|
||||||
echo "<div align='center'><strong>Connection to Event Socket failed.</strong></div>";
|
|
||||||
}
|
|
||||||
|
|
||||||
//set call uuid
|
|
||||||
$origination_uuid = trim(event_socket_request($fp, "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");
|
|
||||||
$record_name = $origination_uuid.".wav";
|
|
||||||
}
|
|
||||||
|
|
||||||
//determine call direction
|
|
||||||
$dir = (strlen($dest) < 7) ? 'local' : 'outbound';
|
|
||||||
|
|
||||||
//define a leg - set source to display the defined caller id name and number
|
|
||||||
$source_common = "{";
|
|
||||||
$source_common .= "origination_uuid=".$origination_uuid;
|
|
||||||
$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 (strlen($src) < 7) {
|
|
||||||
//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 (strlen($dest) < 7) {
|
|
||||||
//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."')";
|
//create the even socket connection and send the event socket command
|
||||||
|
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
||||||
|
if (!$fp) {
|
||||||
|
//error message
|
||||||
|
echo "<div align='center'><strong>Connection to Event Socket failed.</strong></div>";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
//set call uuid
|
||||||
//local extension (source) > external number (destination)
|
$origination_uuid = trim(event_socket_request($fp, "api create_uuid"));
|
||||||
if (strlen($src) < 7 && strlen($dest_cid_number) == 0) {
|
|
||||||
//retrieve outbound caller id from the (source) extension
|
//add record path and name
|
||||||
$sql = "select outbound_caller_id_name, outbound_caller_id_number from v_extensions where domain_uuid = '".$_SESSION['domain_uuid']."' and extension = '".$src."' ";
|
if ($rec == "true") {
|
||||||
$prep_statement = $db->prepare(check_sql($sql));
|
$record_path = $_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/archive/".date("Y")."/".date("M")."/".date("d");
|
||||||
$prep_statement->execute();
|
if (isset($_SESSION['recordings']['extension']['text'])) {
|
||||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
$record_extension = $_SESSION['recordings']['extension']['text'];
|
||||||
foreach ($result as &$row) {
|
}
|
||||||
$dest_cid_name = $row["outbound_caller_id_name"];
|
else {
|
||||||
$dest_cid_number = $row["outbound_caller_id_number"];
|
$record_extension = 'wav';
|
||||||
break; //limit to 1 row
|
}
|
||||||
|
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('${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('${uuid}', $origination_uuid, $record_name);
|
||||||
|
$record_name = str_replace('${record_extension}', $record_extension, $record_name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$record_name = $origination_uuid.'.'.$record_extension;
|
||||||
}
|
}
|
||||||
unset ($prep_statement);
|
|
||||||
}
|
}
|
||||||
if (permission_exists('click_to_call_call')) {
|
|
||||||
|
//determine call direction
|
||||||
|
$dir = (strlen($dest) < 7) ? 'local' : 'outbound';
|
||||||
|
|
||||||
|
//define a leg - set source to display the defined caller id name and number
|
||||||
|
$source_common = "{";
|
||||||
|
$source_common .= "origination_uuid=".$origination_uuid;
|
||||||
|
$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 (strlen($src) < 7) {
|
||||||
|
//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 (strlen($dest) < 7) {
|
||||||
|
//destination is a local extension
|
||||||
if (strpbrk($dest, '@') != FALSE) { //sip-uri
|
if (strpbrk($dest, '@') != FALSE) { //sip-uri
|
||||||
$switch_cmd = $destination_common.",call_direction=outbound}sofia/external/".$dest.")";
|
$switch_cmd = $destination_common.",call_direction=outbound}sofia/external/".$dest.")";
|
||||||
}
|
}
|
||||||
else { //not sip-uri
|
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."')";
|
$switch_cmd = " &transfer('".$dest." XML ".$context."')";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
unset($destination_common);
|
//local extension (source) > external number (destination)
|
||||||
|
if (strlen($src) < 7 && strlen($dest_cid_number) == 0) {
|
||||||
//create the even socket connection and send the event socket command
|
//retrieve outbound caller id from the (source) extension
|
||||||
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
$sql = "select outbound_caller_id_name, outbound_caller_id_number from v_extensions where domain_uuid = '".$_SESSION['domain_uuid']."' and extension = '".$src."' ";
|
||||||
if (!$fp) {
|
$prep_statement = $db->prepare(check_sql($sql));
|
||||||
//error message
|
$prep_statement->execute();
|
||||||
echo "<div align='center'><strong>Connection to Event Socket failed.</strong></div>";
|
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||||
}
|
foreach ($result as &$row) {
|
||||||
else {
|
$dest_cid_name = $row["outbound_caller_id_name"];
|
||||||
//display the last command
|
$dest_cid_number = $row["outbound_caller_id_number"];
|
||||||
$switch_cmd = "api originate ".$source.$switch_cmd;
|
break; //limit to 1 row
|
||||||
echo "<div align='center'>".$switch_cmd."<br /><br /><strong>".$src." has called ".$dest."</strong></div>\n";
|
}
|
||||||
//show the command result
|
unset ($prep_statement);
|
||||||
$result = trim(event_socket_request($fp, $switch_cmd));
|
}
|
||||||
if (substr($result, 0,3) == "+OK") {
|
if (permission_exists('click_to_call_call')) {
|
||||||
//$uuid = substr($result, 4);
|
if (strpbrk($dest, '@') != FALSE) { //sip-uri
|
||||||
if ($rec == "true") {
|
$switch_cmd = $destination_common.",call_direction=outbound}sofia/external/".$dest.")";
|
||||||
//use the server's time zone to ensure it matches the time zone used by freeswitch
|
}
|
||||||
date_default_timezone_set($_SESSION['time_zone']['system']);
|
else { //not sip-uri
|
||||||
//create the api record command and send it over event socket
|
$bridge_array = outbound_route_to_bridge($_SESSION['domain_uuid'], $dest);
|
||||||
$switch_cmd = "api uuid_record ".$origination_uuid." start ".$record_path."/".$record_name;
|
//$switch_cmd = $destination_common."}".$bridge_array[0].")"; // wouldn't set cdr destination correctly, so below used instead
|
||||||
$result2 = trim(event_socket_request($fp, $switch_cmd));
|
$switch_cmd = " &transfer('".$dest." XML ".$context."')";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo "<div align='center'><br />".$result."<br /><br /></div>\n";
|
unset($destination_common);
|
||||||
}
|
|
||||||
}
|
//create the even socket connection and send the event socket command
|
||||||
|
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
||||||
|
if (!$fp) {
|
||||||
|
//error message
|
||||||
|
echo "<div align='center'><strong>Connection to Event Socket failed.</strong></div>";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//display the last command
|
||||||
|
$switch_cmd = "api originate ".$source.$switch_cmd;
|
||||||
|
echo "<div align='center'>".$switch_cmd."<br /><br /><strong>".$src." has called ".$dest."</strong></div>\n";
|
||||||
|
//show the command result
|
||||||
|
$result = trim(event_socket_request($fp, $switch_cmd));
|
||||||
|
if (substr($result, 0,3) == "+OK") {
|
||||||
|
//$uuid = substr($result, 4);
|
||||||
|
if ($rec == "true") {
|
||||||
|
//use the server's time zone to ensure it matches the time zone used by freeswitch
|
||||||
|
date_default_timezone_set($_SESSION['time_zone']['system']);
|
||||||
|
//create the api record command and send it over event socket
|
||||||
|
$switch_cmd = "api uuid_record ".$origination_uuid." start ".$record_path."/".$record_name;
|
||||||
|
$result2 = trim(event_socket_request($fp, $switch_cmd));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo "<div align='center'><br />".$result."<br /><br /></div>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//show html form
|
//show html form
|
||||||
echo " <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
|
echo " <table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue