Portions created by the Initial Developer are Copyright (C) 2008-2015 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane Luis Daniel Lucio Quiroz */ require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; if (permission_exists('follow_me') || permission_exists('call_forward') || permission_exists('do_not_disturb')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //define the destination_select function function destination_select($select_name, $select_value, $select_default) { if (strlen($select_value) == 0) { $select_value = $select_default; } echo " \n"; } //get the extension_uuid $extension_uuid = check_str($_REQUEST["id"]); //get the extension number $sql = "select * from v_extensions "; $sql .= "where domain_uuid = '$domain_uuid' "; $sql .= "and extension_uuid = '$extension_uuid' "; if (!(permission_exists('follow_me') || permission_exists('call_forward') || permission_exists('do_not_disturb'))) { if (count($_SESSION['user']['extension']) > 0) { $sql .= "and ("; $x = 0; foreach($_SESSION['user']['extension'] as $row) { if ($x > 0) { $sql .= "or "; } $sql .= "extension = '".$row['user']."' "; $x++; } $sql .= ")"; } else { //hide any results when a user has not been assigned an extension $sql .= "and extension = 'disabled' "; } } $sql .= "and enabled = 'true' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); if (count($result)== 0) { echo "access denied"; exit; } else { foreach ($result as &$row) { $extension = $row["extension"]; $accountcode = $row["accountcode"]; $effective_caller_id_name = $row["effective_caller_id_name"]; $effective_caller_id_number = $row["effective_caller_id_number"]; $outbound_caller_id_name = $row["outbound_caller_id_name"]; $outbound_caller_id_number = $row["outbound_caller_id_number"]; $do_not_disturb = $row["do_not_disturb"]; $forward_all_destination = $row["forward_all_destination"]; $forward_all_enabled = $row["forward_all_enabled"]; $forward_busy_destination = $row["forward_busy_destination"]; $forward_busy_enabled = $row["forward_busy_enabled"]; $forward_no_answer_destination = $row["forward_no_answer_destination"]; $forward_no_answer_enabled = $row["forward_no_answer_enabled"]; $follow_me_uuid = $row["follow_me_uuid"]; $forward_caller_id_uuid = $row["forward_caller_id_uuid"]; break; //limit to 1 row } if (strlen($do_not_disturb) == 0) { $do_not_disturb = "false"; } } unset ($prep_statement); if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { //get http post variables and set them to php variables if (count($_POST)>0) { $forward_all_enabled = check_str($_POST["forward_all_enabled"]); $forward_all_destination = check_str($_POST["forward_all_destination"]); $forward_busy_enabled = check_str($_POST["forward_busy_enabled"]); $forward_busy_destination = check_str($_POST["forward_busy_destination"]); $forward_no_answer_enabled = check_str($_POST["forward_no_answer_enabled"]); $forward_no_answer_destination = check_str($_POST["forward_no_answer_destination"]); $forward_caller_id_uuid = check_str($_POST["forward_caller_id_uuid"]); $cid_name_prefix = check_str($_POST["cid_name_prefix"]); $cid_number_prefix = check_str($_POST["cid_number_prefix"]); $follow_me_enabled = check_str($_POST["follow_me_enabled"]); $follow_me_caller_id_uuid = check_str($_POST["follow_me_caller_id_uuid"]); $follow_me_ignore_busy = check_str($_POST["follow_me_ignore_busy"]); $destination_data_1 = check_str($_POST["destination_data_1"]); $destination_delay_1 = check_str($_POST["destination_delay_1"]); $destination_prompt_1 = check_str($_POST["destination_prompt_1"]); $destination_timeout_1 = check_str($_POST["destination_timeout_1"]); $destination_data_2 = check_str($_POST["destination_data_2"]); $destination_delay_2 = check_str($_POST["destination_delay_2"]); $destination_prompt_2 = check_str($_POST["destination_prompt_2"]); $destination_timeout_2 = check_str($_POST["destination_timeout_2"]); $destination_data_3 = check_str($_POST["destination_data_3"]); $destination_delay_3 = check_str($_POST["destination_delay_3"]); $destination_prompt_3 = check_str($_POST["destination_prompt_3"]); $destination_timeout_3 = check_str($_POST["destination_timeout_3"]); $destination_data_4 = check_str($_POST["destination_data_4"]); $destination_delay_4 = check_str($_POST["destination_delay_4"]); $destination_prompt_4 = check_str($_POST["destination_prompt_4"]); $destination_timeout_4 = check_str($_POST["destination_timeout_4"]); $destination_data_5 = check_str($_POST["destination_data_5"]); $destination_delay_5 = check_str($_POST["destination_delay_5"]); $destination_prompt_5 = check_str($_POST["destination_prompt_5"]); $destination_timeout_5 = check_str($_POST["destination_timeout_5"]); $dnd_enabled = check_str($_POST["dnd_enabled"]); if (strlen($forward_all_destination) > 0) { // $forward_all_destination = preg_replace("~[^0-9]~", "",$forward_all_destination); } if (strlen($forward_busy_destination) > 0) { // $forward_busy_destination = preg_replace("~[^0-9*]~", "",$forward_busy_destination); } if (strlen($forward_no_answer_destination) > 0) { // $forward_no_answer_destination = preg_replace("~[^0-9*]~", "",$forward_no_answer_destination); } if (strlen($destination_data_1) > 0) { // $destination_data_1 = preg_replace("~[^0-9]~", "",$destination_data_1); } if (strlen($destination_data_2) > 0) { // $destination_data_2 = preg_replace("~[^0-9]~", "",$destination_data_2); } if (strlen($destination_data_3) > 0) { // $destination_data_3 = preg_replace("~[^0-9]~", "",$destination_data_3); } if (strlen($destination_data_4) > 0) { // $destination_data_4 = preg_replace("~[^0-9]~", "",$destination_data_4); } if (strlen($destination_data_5) > 0) { // $destination_data_5 = preg_replace("~[^0-9]~", "",$destination_data_5); } } //check for all required data //if (strlen($forward_all_enabled) == 0) { $msg .= "Please provide: Call Forward
\n"; } //if (strlen($forward_all_destination) == 0) { $msg .= "Please provide: Forward Number
\n"; } //if (strlen($forward_busy_enabled) == 0) { $msg .= "Please provide: On Busy
\n"; } //if (strlen($forward_busy_destination) == 0) { $msg .= "Please provide: Busy Number
\n"; } //if (strlen($forward_no_answer_enabled) == 0) { $msg .= "Please provide: no_answer
\n"; } //if (strlen($forward_no_answer_destination) == 0) { $msg .= "Please provide: no_answer Number
\n"; } //if (strlen($follow_me_enabled) == 0) { $msg .= "Please provide: Follow Me
\n"; } //if (strlen($destination_data_1) == 0) { $msg .= "Please provide: 1st Number
\n"; } //if (strlen($destination_timeout_1) == 0) { $msg .= "Please provide: sec
\n"; } //if (strlen($destination_data_2) == 0) { $msg .= "Please provide: 2nd Number
\n"; } //if (strlen($destination_timeout_2) == 0) { $msg .= "Please provide: sec
\n"; } //if (strlen($destination_data_3) == 0) { $msg .= "Please provide: 3rd Number
\n"; } //if (strlen($destination_timeout_3) == 0) { $msg .= "Please provide: sec
\n"; } //if (strlen($destination_data_4) == 0) { $msg .= "Please provide: 4th Number
\n"; } //if (strlen($destination_timeout_4) == 0) { $msg .= "Please provide: sec
\n"; } //if (strlen($destination_data_5) == 0) { $msg .= "Please provide: 5th Number
\n"; } //if (strlen($destination_timeout_5) == 0) { $msg .= "Please provide: sec
\n"; } //if (strlen($destination_data_6) == 0) { $msg .= "Please provide: 6th Number
\n"; } //if (strlen($destination_timeout_6) == 0) { $msg .= "Please provide: sec
\n"; } //if (strlen($destination_data_7) == 0) { $msg .= "Please provide: 7th Number
\n"; } //if (strlen($destination_timeout_7) == 0) { $msg .= "Please provide: sec
\n"; } if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { require_once "resources/header.php"; require_once "resources/persist_form_var.php"; echo "
\n"; echo "
\n"; echo $msg."
"; echo "
\n"; persistformvar($_POST); echo "
\n"; require_once "resources/footer.php"; return; } //set the default action to add $call_forward_action = "add"; //determine if this is an add or an update if (strlen($follow_me_uuid) == 0) { $follow_me_action = "add"; } else { $follow_me_action = "update"; } //include the classes include "resources/classes/call_forward.php"; include "resources/classes/follow_me.php"; include "resources/classes/do_not_disturb.php"; //call forward config if (permission_exists('call_forward')) { $call_forward = new call_forward; $call_forward->domain_uuid = $_SESSION['domain_uuid']; $call_forward->domain_name = $_SESSION['domain_name']; $call_forward->extension_uuid = $extension_uuid; $call_forward->accountcode = $accountcode; $call_forward->forward_all_destination = $forward_all_destination; $call_forward->forward_all_enabled = $forward_all_enabled; $call_forward->forward_caller_id_uuid = $forward_caller_id_uuid; //$call_forward->set(); //unset($call_forward); } //do not disturb (dnd) config if (permission_exists('do_not_disturb')) { $dnd = new do_not_disturb; $dnd->domain_uuid = $_SESSION['domain_uuid']; $dnd->domain_name = $_SESSION['domain_name']; $dnd->extension_uuid = $extension_uuid; $dnd->enabled = $dnd_enabled; //$dnd->set(); //$dnd->user_status(); //unset($dnd); } //if follow me is enabled then process it last if ($follow_me_enabled == "true") { //call forward $call_forward->set(); unset($call_forward); //dnd $dnd->set(); $dnd->user_status(); unset($dnd); } //follow me config if (permission_exists('follow_me')) { $follow_me = new follow_me; $follow_me->domain_uuid = $_SESSION['domain_uuid']; $follow_me->domain_name = $_SESSION['domain_name']; $follow_me->extension_uuid = $extension_uuid; $follow_me->db_type = $db_type; $follow_me->cid_name_prefix = $cid_name_prefix; $follow_me->cid_number_prefix = $cid_number_prefix; $follow_me->follow_me_enabled = $follow_me_enabled; $follow_me->follow_me_caller_id_uuid = $follow_me_caller_id_uuid; $follow_me->follow_me_ignore_busy = $follow_me_ignore_busy; $follow_me->destination_data_1 = $destination_data_1; $follow_me->destination_type_1 = $destination_type_1; $follow_me->destination_delay_1 = $destination_delay_1; $follow_me->destination_prompt_1 = $destination_prompt_1; $follow_me->destination_timeout_1 = $destination_timeout_1; $follow_me->destination_data_2 = $destination_data_2; $follow_me->destination_type_2 = $destination_type_2; $follow_me->destination_delay_2 = $destination_delay_2; $follow_me->destination_prompt_2 = $destination_prompt_2; $follow_me->destination_timeout_2 = $destination_timeout_2; $follow_me->destination_data_3 = $destination_data_3; $follow_me->destination_type_3 = $destination_type_3; $follow_me->destination_delay_3 = $destination_delay_3; $follow_me->destination_prompt_3 = $destination_prompt_3; $follow_me->destination_timeout_3 = $destination_timeout_3; $follow_me->destination_data_4 = $destination_data_4; $follow_me->destination_type_4 = $destination_type_4; $follow_me->destination_delay_4 = $destination_delay_4; $follow_me->destination_prompt_4 = $destination_prompt_4; $follow_me->destination_timeout_4 = $destination_timeout_4; $follow_me->destination_data_5 = $destination_data_5; $follow_me->destination_type_5 = $destination_type_5; $follow_me->destination_delay_5 = $destination_delay_5; $follow_me->destination_prompt_5 = $destination_prompt_5; $follow_me->destination_timeout_5 = $destination_timeout_5; if ($follow_me_action == "add") { $follow_me_uuid = uuid(); $sql = "update v_extensions set "; $sql .= "follow_me_uuid = '$follow_me_uuid' "; $sql .= "where domain_uuid = '$domain_uuid' "; $sql .= "and extension_uuid = '$extension_uuid' "; $db->exec(check_sql($sql)); unset($sql); $follow_me->follow_me_uuid = $follow_me_uuid; $follow_me->add(); $follow_me->set(); } if ($follow_me_action == "update") { $follow_me->follow_me_uuid = $follow_me_uuid; $follow_me->update(); $follow_me->set(); } unset($follow_me); } //if dnd or call forward are enabled process it last if ($follow_me_enabled != "true") { if ($forward_all_enabled == "true") { //dnd $dnd->set(); $dnd->user_status(); unset($dnd); //call forward $call_forward->set(); unset($call_forward); } else{ //call forward $call_forward->set(); unset($call_forward); //dnd $dnd->set(); $dnd->user_status(); unset($dnd); } } //synchronize configuration if (is_readable($_SESSION['switch']['extensions']['dir'])) { require_once "app/extensions/resources/classes/extension.php"; $ext = new extension; $ext->xml(); unset($ext); } // Forward on busy and no_answer is stored in table and will be used by lua scripts $sql = "update v_extensions set "; $sql .= "forward_busy_destination = '".$forward_busy_destination."', "; $sql .= "forward_busy_enabled = '".$forward_busy_enabled."', "; $sql .= "forward_no_answer_destination = '".$forward_no_answer_destination."', "; $sql .= "forward_no_answer_enabled = '".$forward_no_answer_enabled."', "; $sql .= "forward_caller_id_uuid = ".(($forward_caller_id_uuid != '') ? "'".$forward_caller_id_uuid."' " : "null "); $sql .= "where domain_uuid = '".$domain_uuid."' "; $sql .= "and extension_uuid = '".$extension_uuid."'"; $db->exec(check_sql($sql)); unset($sql); //clear the cache $cache = new cache; $cache->delete("directory:".$extension."@".$_SESSION['domain_name']); if(strlen($number_alias) > 0){ $cache->delete("directory:".$number_alias."@".$_SESSION['domain_name']); } //redirect the user $_SESSION["message"] = $text['confirm-update']; header("Location: ".$_REQUEST['return_url']); return; } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) //show the header require_once "resources/header.php"; //pre-populate the form if ($follow_me_uuid != '') { $sql = "select * from v_follow_me "; $sql .= "where domain_uuid = '$domain_uuid' "; $sql .= "and follow_me_uuid = '$follow_me_uuid' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { $cid_name_prefix = $row["cid_name_prefix"]; $cid_number_prefix = $row["cid_number_prefix"]; $follow_me_enabled = $row["follow_me_enabled"]; $follow_me_caller_id_uuid = $row["follow_me_caller_id_uuid"]; $follow_me_ignore_busy = $row["follow_me_ignore_busy"]; $sql = "select * from v_follow_me_destinations "; $sql .= "where follow_me_uuid = '$follow_me_uuid' "; $sql .= "order by follow_me_order asc "; $prep_statement_2 = $db->prepare(check_sql($sql)); $prep_statement_2->execute(); $result2 = $prep_statement_2->fetchAll(PDO::FETCH_NAMED); $x = 1; foreach ($result2 as &$row2) { if ($x == 1) { $destination_data_1 = $row2["follow_me_destination"]; $destination_delay_1 = $row2["follow_me_delay"]; $destination_prompt_1 = $row2["follow_me_prompt"]; $destination_timeout_1 = $row2["follow_me_timeout"]; } if ($x == 2) { $destination_data_2 = $row2["follow_me_destination"]; $destination_delay_2 = $row2["follow_me_delay"]; $destination_prompt_2 = $row2["follow_me_prompt"]; $destination_timeout_2 = $row2["follow_me_timeout"]; } if ($x == 3) { $destination_data_3 = $row2["follow_me_destination"]; $destination_delay_3 = $row2["follow_me_delay"]; $destination_prompt_3 = $row2["follow_me_prompt"]; $destination_timeout_3 = $row2["follow_me_timeout"]; } if ($x == 4) { $destination_data_4 = $row2["follow_me_destination"]; $destination_delay_4 = $row2["follow_me_delay"]; $destination_prompt_4 = $row2["follow_me_prompt"]; $destination_timeout_4 = $row2["follow_me_timeout"]; } if ($x == 5) { $destination_data_5 = $row2["follow_me_destination"]; $destination_delay_5 = $row2["follow_me_delay"]; $destination_prompt_5 = $row2["follow_me_prompt"]; $destination_timeout_5 = $row2["follow_me_timeout"]; } $x++; } unset ($prep_statement_2); } unset ($prep_statement); } //set the default if (!isset($dnd_enabled)) { //set the value from the database $dnd_enabled = $do_not_disturb; } //prepare the autocomplete echo "\n"; echo "\n"; echo "\n"; //show the content 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"; if (permission_exists('follow_me_cid_name_prefix')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (permission_exists('follow_me_cid_number_prefix')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo " "; echo "
\n"; echo " ".$text['title']."\n"; echo "\n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['description']." $extension.

\n"; echo "
\n"; echo " ".$text['label-call-forward']."\n"; echo "\n"; $on_click = "document.getElementById('follow_me_disabled').checked=true;"; $on_click .= "document.getElementById('dnd_disabled').checked=true;"; $on_click .= "document.getElementById('forward_all_destination').focus();"; echo " \n"; echo " \n"; unset($on_click); echo "   "; echo " \n"; if (permission_exists('follow_me_cid_set')) { echo "   "; $sql_forward = "select destination_uuid, destination_number, destination_description from v_destinations where domain_uuid = '$domain_uuid' and destination_type = 'inbound' order by destination_number asc "; $prep_statement_forward = $db->prepare(check_sql($sql_forward)); $prep_statement_forward->execute(); $result_forward = $prep_statement_forward->fetchAll(PDO::FETCH_ASSOC); if (count($result_forward) > 0) { echo "\n"; } unset ($sql_forward, $prep_statement_forward, $result_forward, $row_forward); } echo "
\n"; echo " ".$text['label-on-busy']."\n"; echo "\n"; $on_click = "document.getElementById('dnd_disabled').checked=true;"; $on_click .= "document.getElementById('forward_busy_destination').focus();"; echo " \n"; echo " \n"; unset($on_click); echo "   "; echo " \n"; echo "
".$text['description-on-busy'].".\n"; echo "
\n"; echo " ".$text['label-no_answer']."\n"; echo "\n"; $on_click = "document.getElementById('dnd_disabled').checked=true;"; $on_click .= "document.getElementById('forward_no_answer_destination').focus();"; echo " \n"; echo " \n"; unset($on_click); echo "   "; echo " \n"; echo "
".$text['description-no_answer'].".\n"; echo "

\n"; echo " ".$text['label-follow-me']."\n"; echo "\n"; $on_click = "document.getElementById('forward_all_disabled').checked=true;"; $on_click .= "document.getElementById('dnd_disabled').checked=true; document.getElementById('follow_me_caller_id_uuid').focus();"; echo " \n"; echo " \n"; unset($on_click); if (permission_exists('follow_me_cid_set')) { echo "   "; $sql_follow_me = "select destination_uuid, destination_number, destination_description from v_destinations where domain_uuid = '$domain_uuid' and destination_type = 'inbound' order by destination_number asc "; $prep_statement_follow_me = $db->prepare(check_sql($sql_follow_me)); $prep_statement_follow_me->execute(); $result_follow_me = $prep_statement_follow_me->fetchAll(PDO::FETCH_ASSOC); if (count($result_follow_me) > 0) { echo "\n"; } unset ($sql_follow_me, $prep_statement_follow_me, $result_follow_me, $row_follow_me); } echo "

\n"; echo "
\n"; echo " ".$text['label-destinations']."\n"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; if (permission_exists('follow_me_prompt')) { echo " \n"; } echo " \n"; // 1st destination echo " \n"; echo " \n"; echo " \n"; echo " \n"; if (permission_exists('follow_me_prompt')) { echo " \n"; } echo " \n"; // 2nd destination echo " \n"; echo " \n"; echo " \n"; echo " \n"; if (permission_exists('follow_me_prompt')) { echo " \n"; } echo " \n"; // 3rd destination echo " \n"; echo " \n"; echo " \n"; echo " \n"; if (permission_exists('follow_me_prompt')) { echo " \n"; } echo " \n"; // 4th destination echo " \n"; echo " \n"; echo " \n"; echo " \n"; if (permission_exists('follow_me_prompt')) { echo " \n"; } echo " \n"; // 5th destination echo " \n"; echo " \n"; echo " \n"; echo " \n"; if (permission_exists('follow_me_prompt')) { echo " \n"; } echo " \n"; echo "
".$text['label-destination_number']."".$text['label-destination_delay']."".$text['label-destination_timeout']."".$text['label-destination_prompt']."
\n"; destination_select('destination_delay_1', $destination_delay_1, '0'); echo " \n"; destination_select('destination_timeout_1', $destination_timeout_1, '30'); echo " \n"; echo " \n"; echo "
\n"; destination_select('destination_delay_2', $destination_delay_2, '0'); echo " \n"; destination_select('destination_timeout_2', $destination_timeout_2, '30'); echo " \n"; echo " \n"; echo "
\n"; destination_select('destination_delay_3', $destination_delay_3, '0'); echo " \n"; destination_select('destination_timeout_3', $destination_timeout_3, '30'); echo " \n"; echo " \n"; echo "
\n"; destination_select('destination_delay_4', $destination_delay_4, '0'); echo " \n"; destination_select('destination_timeout_4', $destination_timeout_4, '30'); echo " \n"; echo " \n"; echo "
\n"; destination_select('destination_delay_5', $destination_delay_5, '0'); echo " \n"; destination_select('destination_timeout_5', $destination_timeout_5, '30'); echo " \n"; echo " \n"; echo "
\n"; echo "
"; echo $text['label-ignore-busy']; echo " \n"; echo " \n"; echo "
Interrupt call if one of destination are busy\n"; echo "
\n"; echo " ".$text['label-cid-name-prefix']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-cid-name-prefix']." \n"; echo "
\n"; echo " ".$text['label-cid-number-prefix']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-cid-number-prefix']." \n"; echo "

\n"; echo " ".$text['label-dnd']."\n"; echo "\n"; $on_click = "document.getElementById('forward_all_disabled').checked=true;"; $on_click .= "document.getElementById('forward_busy_disabled').checked=true;"; $on_click .= "document.getElementById('forward_no_answer_disabled').checked=true;"; $on_click .= "document.getElementById('follow_me_disabled').checked=true;"; echo " \n"; echo " \n"; echo "
\n"; echo "
\n"; if ($action == "update") { echo " \n"; } echo "
"; echo " \n"; echo "
"; echo "

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