User Dashboard: Restore Click-to-Call functionality.

This commit is contained in:
reliberate
2016-03-14 18:59:30 -06:00
parent d8aeecad35
commit 10c99b93b5
2 changed files with 133 additions and 133 deletions
+82 -119
View File
@@ -49,168 +49,131 @@ else {
require_once "resources/header.php";
if (is_array($_REQUEST) && !empty($_REQUEST['src']) && !empty($_REQUEST['dest'])) {
//get the http variables and set them as variables
//retrieve submitted variables
$src = check_str($_REQUEST['src']);
$dest = check_str($_REQUEST['dest']);
$ringback = check_str($_REQUEST['ringback']);
$src = str_replace(array('.', '(', ')', '-', ' '), '', $src);
if (strpbrk($dest, '@') != FALSE) {
$dest = str_replace(array('(', ')', ' '), '', $dest); //don't strip periods or dashes in sip-uri calls
}
else {
$dest = str_replace(array('.', '(', ')', '-', ' '), '', $dest); //strip the periods for phone numbers.
}
$src_cid_name = check_str($_REQUEST['src_cid_name']);
$src_cid_number = check_str($_REQUEST['src_cid_number']);
$dest = check_str($_REQUEST['dest']);
$dest_cid_name = check_str($_REQUEST['dest_cid_name']);
$dest_cid_number = check_str($_REQUEST['dest_cid_number']);
$auto_answer = check_str($_REQUEST['auto_answer']); //true,false
$rec = check_str($_REQUEST['rec']); //true,false
if ($auto_answer == "true") {
$sip_auto_answer = "sip_auto_answer=true,";
}
else {
$sip_auto_answer = '';
}
if (strlen($cid_number) == 0) { $cid_number = $src;}
$ringback = check_str($_REQUEST['ringback']);
$context = $_SESSION['context'];
//workaround for TBDialout on Thunderbird
//seems it can only handle the first %NUM%
if ($dest == "%NUM%"){
//echo "Thunderbird fix, dest now = $src_cid_number <br>";
$dest = $src_cid_number;
}
//clean up variable values
$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
//adjust variable values
$sip_auto_answer = ($auto_answer == "true") ? ",sip_auto_answer=true" : null;
//mozilla thunderbird TBDialout workaround (seems it can only handle the first %NUM%)
$dest = ($dest == "%NUM%") ? $src_cid_number : $dest;
//translate ringback
switch ($ringback) {
case "music": $ringback_value = "\'local_stream://moh\'"; 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 "pt-ring": $ringback_value = "\'%(1000,5000,400.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 "us-ring":
$ringback_value = "\'%(2000,4000,440.0,480.0)\'";
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 "pt-ring":
$ringback_value = "\'%(1000,5000,400.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 "music":
$ringback_value = "\'local_stream://moh\'";
break;
default:
$ringback = 'us-ring';
$ringback_value = "\'%(2000,4000,440.0,480.0)\'";
}
//source should see the destination caller id
//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 = "{".
"click_to_call=true".
",origination_caller_id_name='".$src_cid_name."'".
",origination_caller_id_number=".$src_cid_number.
",instant_ringback=true".
",ringback=".$ringback_value.
",presence_id=".$src."@".$_SESSION['domains'][$domain_uuid]['domain_name'].
",call_direction=".$dir;
if (strlen($src) < 7) {
$source = "{click_to_call=true,".$sip_auto_answer."origination_caller_id_name='$src_cid_name',origination_caller_id_number=$src_cid_number,instant_ringback=true,ringback=$ringback_value,presence_id=$src@".$_SESSION['domains'][$domain_uuid]['domain_name'].",call_direction=outbound,domain_uuid=".$domain_uuid.",domain_name=".$_SESSION['domains'][$domain_uuid]['domain_name']."}user/$src@".$_SESSION['domains'][$domain_uuid]['domain_name'];
//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 {
$bridge_array = outbound_route_to_bridge ($_SESSION['domain_uuid'], $src);
$source = "{click_to_call=true,origination_caller_id_name='$src_cid_name',origination_caller_id_number=$src_cid_number,instant_ringback=true,ringback=$ringback_value,presence_id=$src@".$_SESSION['domains'][$domain_uuid]['domain_name'].",call_direction=outbound}".$bridge_array[0];
//source is an external number
$bridge_array = outbound_route_to_bridge($_SESSION['domain_uuid'], $src);
$source = $source_common."}".$bridge_array[0];
}
unset($source_common);
//destination needs to see the source caller id
//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) {
if (strpbrk($dest, '@') != FALSE) {
//echo "Found an @ 2<br><br>";
$switch_cmd = "api originate $source &bridge({origination_caller_id_name='$dest_cid_name',origination_caller_id_number=$dest_cid_number,call_direction=outbound}sofia/external/$dest)";
echo "$switch_cmd";
//destination is a local extension
if (strpbrk($dest, '@') != FALSE) { //sip-uri
$switch_cmd = $destination_common.",call_direction=outbound}sofia/external/".$dest.")";
}
else {
$switch_cmd = "api originate $source &transfer('".$dest." XML ".$context."')";
else { //not sip-uri
$switch_cmd = " &transfer('".$dest." XML ".$context."')";
}
}
else {
if (strlen($src) < 7) {
if (strlen($dest_cid_number) == 0) {
//get the caller id from the extension caller id comes from the extension (the source number)
$sql = "select * from v_extensions ";
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= "and extension = '$src' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
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
}
unset ($prep_statement);
//local extension (source) > external number (destination)
if (strlen($src) < 7 && strlen($dest_cid_number) == 0) {
//retrieve outbound caller id from the (source) extension
$sql = "select outbound_caller_id_name, outbound_caller_id_number from v_extensions where domain_uuid = '".$_SESSION['domain_uuid']."' and extension = '".$src."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
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
}
unset ($prep_statement);
}
$bridge_array = outbound_route_to_bridge ($_SESSION['domain_uuid'], $dest);
$destination = "{origination_caller_id_name='$dest_cid_name',origination_caller_id_number=$dest_cid_number}".$bridge_array[0];
if (permission_exists('click_to_call_call')) {
if (strpbrk($dest, '@') != FALSE) {
//call a sip uri
//echo "Found an @ 4, do nothing for now<br><br>";
$switch_cmd = "api originate $source &bridge({origination_caller_id_name='$dest_cid_name',origination_caller_id_number=$dest_cid_number,call_direction=outbound}sofia/external/$dest)";
//echo "<br>SWITCH-CMD: $switch_cmd<br>";
if (strpbrk($dest, '@') != FALSE) { //sip-uri
$switch_cmd = $destination_common.",call_direction=outbound}sofia/external/".$dest.")";
}
else {
//regular call
$switch_cmd = "api originate $source &bridge($destination)";
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."')";
}
}
}
//display the last command
echo "<div align='center'>\n";
echo "<table width='40%'>\n";
echo "<tr>\n";
echo "<th align='left'>Message</th>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='row_style1'><strong>$switch_cmd $src has called $dest</strong></td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</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) {
//show the error message
$msg = "<div align='center'>Connection to Event Socket failed.<br /></div>";
echo "<div align='center'>\n";
echo "<table width='40%'>\n";
echo "<tr>\n";
echo " <th align='left'>Message</th>\n";
echo "</tr>\n";
echo "<tr>\n";
echo " <td class='row_style1'><strong>$msg</strong></td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</div>\n";
//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 ".$uuid." start ".$_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/archive/".date("Y")."/".date("M")."/".date("d")."/".$uuid.".wav";
$result2 = trim(event_socket_request($fp, $switch_cmd));
}
$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 ".$uuid." start ".$_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/archive/".date("Y")."/".date("M")."/".date("d")."/".$uuid.".wav";
$result2 = trim(event_socket_request($fp, $switch_cmd));
}
echo "<div align='center'>\n";
echo "<br />\n";
echo $result;
echo "<br />\n";
echo "<br />\n";
echo "</div>\n";
}
echo "<div align='center'><br />".$result."<br /><br /></div>\n";
}
}