James Rose */ //includes files require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (permission_exists('click_to_call_view')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //include the header require_once "resources/header.php"; //send the call if (is_array($_GET) && isset($_GET['src']) && isset($_GET['dest'])) { //retrieve submitted variables $src = check_str($_GET['src']); $src_cid_name = check_str($_GET['src_cid_name']); $src_cid_number = check_str($_GET['src_cid_number']); $dest = check_str($_GET['dest']); $dest_cid_name = check_str($_GET['dest_cid_name']); $dest_cid_number = check_str($_GET['dest_cid_number']); $auto_answer = check_str($_GET['auto_answer']); //true,false $rec = check_str($_GET['rec']); //true,false $ringback = check_str($_GET['ringback']); $context = $_SESSION['domain_name']; //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 "de-ring": $ringback_value = "\'%(1000,4000,425.0,0.0)\'"; break; case "us-ring": default: $ringback = 'us-ring'; $ringback_value = "\'%(2000,4000,440.0,480.0)\'"; } //create the even socket connection and send the event socket command $esl = event_socket::create(); if ($esl->is_connected()) { //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 } } 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.
"; } //ensure we are still connected and send the event socket command if ($esl->is_connected()) { //display the last command $switch_cmd = "originate ".$source.$switch_cmd; echo "
".escape($src)." has called ".escape($dest)."
\n"; //show the command result $result = trim(event_socket::api($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 if (is_uuid($origination_uuid) && file_exists($record_path)) { $switch_cmd = "uuid_record $origination_uuid start $record_path/$record_name"; } $result2 = trim(event_socket::api($switch_cmd)); } } echo "

".escape($result)."

\n"; } else { //error message echo "
Connection to Event Socket failed.
"; } } //show html form echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; echo " \n"; echo "
\n"; echo " \n"; echo " ".$text['label-click2call']."\n"; echo " \n"; echo " \n"; echo "  \n"; echo "
\n"; echo " \n"; echo " ".$text['desc-click2call']."\n"; echo " \n"; echo "
"; echo "
"; echo "
\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo" \n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " \n"; echo "\n"; echo "
".$text['label-src-caller-id-nam']."\n"; echo " \n"; echo "
\n"; echo " ".$text['desc-src-caller-id-nam']."\n"; echo "
".$text['label-src-caller-id-num']."\n"; echo " \n"; echo "
\n"; echo " ".$text['desc-src-caller-id-num']."\n"; echo "
".$text['label-dest-caller-id-nam']."\n"; echo " \n"; echo "
\n"; echo " ".$text['desc-dest-caller-id-nam']."\n"; echo "
".$text['label-dest-caller-id-num']."\n"; echo " \n"; echo "
\n"; echo " ".$text['desc-dest-caller-id-num']."\n"; echo "
".$text['label-src-num']."\n"; echo " \n"; echo "
\n"; echo " ".$text['desc-src-num']."\n"; echo "
".$text['label-dest-num']."\n"; echo " \n"; echo "
\n"; echo " ".$text['desc-dest-num']."\n"; echo "
\n"; echo " ".$text['label-auto-answer']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['desc-auto-answer']."\n"; echo "
\n"; echo " ".$text['label-record']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['desc-record']."\n"; echo "
\n"; echo " ".$text['label-ringback']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['desc-ringback']."\n"; echo "
\n"; echo "
"; echo " \n"; echo "
\n"; echo "

"; echo "
"; //show the footer require_once "resources/footer.php"; ?>