diff --git a/app/destinations/destination_edit.php b/app/destinations/destination_edit.php index 69ad1168b8..1b599337f2 100644 --- a/app/destinations/destination_edit.php +++ b/app/destinations/destination_edit.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2017 + Portions created by the Initial Developer are Copyright (C) 2008-2018 the Initial Developer. All Rights Reserved. Contributor(s): @@ -82,6 +82,7 @@ //get http post variables and set them to php variables if (count($_POST) > 0) { + //set the variables $dialplan_uuid = check_str($_POST["dialplan_uuid"]); $domain_uuid = check_str($_POST["domain_uuid"]); @@ -167,409 +168,426 @@ return; } - //determine whether save the dialplan - foreach ($_POST["dialplan_details"] as $row) { - if (strlen($row["dialplan_detail_data"]) > 0) { - $add_dialplan = true; - break; - } - } + //save the inbound destination and add the dialplan for the inbound route + if ($destination_type == 'inbound') { + //get the array + $dialplan_details = $_POST["dialplan_details"]; - //get the array - $dialplan_details = $_POST["dialplan_details"]; - - //remove the array from the HTTP POST - unset($_POST["dialplan_details"]); - - //array cleanup - foreach ($dialplan_details as $index => $row) { - //unset the empty row - if (strlen($row["dialplan_detail_data"]) == 0) { - unset($dialplan_details[$index]); - } - } - - //get the fax information - if (strlen($fax_uuid) > 0) { - $sql = "select * from v_fax "; - $sql .= "where fax_uuid = '".$fax_uuid."' "; - if (!permission_exists('destination_domain')) { - $sql .= "and domain_uuid = '".$domain_uuid."' "; - } - $prep_statement = $db->prepare(check_sql($sql)); - $prep_statement->execute(); - $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); - foreach ($result as &$row) { - $fax_extension = $row["fax_extension"]; - $fax_destination_number = $row["fax_destination_number"]; - $fax_name = $row["fax_name"]; - $fax_email = $row["fax_email"]; - $fax_pin_number = $row["fax_pin_number"]; - $fax_caller_id_name = $row["fax_caller_id_name"]; - $fax_caller_id_number = $row["fax_caller_id_number"]; - $fax_forward_number = $row["fax_forward_number"]; - $fax_description = $row["fax_description"]; - } - unset ($prep_statement); - } - - //if empty then get new uuid - if (strlen($dialplan_uuid) == 0) { - $dialplan_uuid = uuid(); - } - - //build the destination array - $destination = $_POST; - $destination["destination_uuid"] = $destination_uuid; - $destination["dialplan_uuid"] = $dialplan_uuid; - - //build the dialplan array - $dialplan["app_uuid"] = "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4"; - $dialplan["dialplan_uuid"] = $dialplan_uuid; - $dialplan["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_name"] = ($dialplan_name != '') ? $dialplan_name : format_phone($destination_number); - $dialplan["dialplan_number"] = $destination_number; - $dialplan["dialplan_context"] = $destination_context; - $dialplan["dialplan_continue"] = "false"; - $dialplan["dialplan_order"] = "100"; - $dialplan["dialplan_enabled"] = $destination_enabled; - $dialplan["dialplan_description"] = ($dialplan_description != '') ? $dialplan_description : $destination_description; - $dialplan_detail_order = 10; - - //set the dialplan detail type - if (strlen($_SESSION['dialplan']['destination']['text']) > 0) { - $dialplan_detail_type = $_SESSION['dialplan']['destination']['text']; - } - else { - $dialplan_detail_type = "destination_number"; - } - - //build the xml dialplan - if ($_SESSION['destinations']['dialplan_details']['boolean'] == "false") { - $dialplan["dialplan_xml"] = "\n"; - $dialplan["dialplan_xml"] .= " \n"; - $dialplan["dialplan_xml"] .= " \n"; - $dialplan["dialplan_xml"] .= " \n"; - $dialplan["dialplan_xml"] .= " \n"; - if (strlen($destination_cid_name_prefix) > 0) { - $dialplan["dialplan_xml"] .= " \n"; - } - if (strlen($destination_record) > 0) { - $dialplan["dialplan_xml"] .= " \n"; - $dialplan["dialplan_xml"] .= " \n"; - $dialplan["dialplan_xml"] .= " \n"; - $dialplan["dialplan_xml"] .= " \n"; - $dialplan["dialplan_xml"] .= " \n"; - $dialplan["dialplan_xml"] .= " \n"; - } - if (strlen($destination_accountcode) > 0) { - $dialplan["dialplan_xml"] .= " \n"; - } - if (strlen($destination_carrier) > 0) { - $dialplan["dialplan_xml"] .= " \n"; - } - if (strlen($fax_uuid) > 0) { - $dialplan["dialplan_xml"] .= " \n"; - $dialplan["dialplan_xml"] .= " \n"; - $dialplan["dialplan_xml"] .= " \n"; - $dialplan["dialplan_xml"] .= " \n"; - } - $dialplan["dialplan_xml"] .= " \n"; - $dialplan["dialplan_xml"] .= " \n"; - $dialplan["dialplan_xml"] .= "\n"; - } - - //dialplan details - if ($_SESSION['destinations']['dialplan_details']['boolean'] == "true") { - - //delete previous dialplan details - $sql = "delete from v_dialplan_details "; - $sql .= "where (domain_uuid = '".$domain_uuid."' or domain_uuid is null) "; - $sql .= "and (dialplan_uuid = '".$dialplan_uuid."' or dialplan_uuid is null) "; - $sql .= "and ("; - $sql .= " dialplan_detail_data like '%tone_detect%' "; - $sql .= " or dialplan_detail_type = 'tone_detect' "; - $sql .= " or dialplan_detail_type = 'record_session' "; - $sql .= " or (dialplan_detail_type = 'sleep' and dialplan_detail_data = '3000') "; - $sql .= ")"; - $db->exec($sql); - unset($sql); - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - - //check the destination number - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "condition"; - if (strlen($_SESSION['dialplan']['destination']['text']) > 0) { - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = $_SESSION['dialplan']['destination']['text']; - } - else { - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "destination_number"; - } - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $destination_number_regex; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - - //set the caller id name prefix - if (strlen($destination_cid_name_prefix) > 0) { - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "effective_caller_id_name=".$destination_cid_name_prefix."#\${caller_id_name}"; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - } - - //set the call accountcode - if (strlen($destination_accountcode) > 0) { - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "accountcode=".$destination_accountcode; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - } - - //set the call carrier - if (strlen($destination_carrier) > 0) { - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "carrier=$destination_carrier"; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - } - - //add fax detection - if (strlen($fax_uuid) > 0) { - - //add set tone detect_hits=1 - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "tone_detect_hits=1"; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - - // execute on tone detect - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "execute_on_tone_detect=transfer ".$fax_extension." XML \${domain_name}"; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - - //add tone_detect fax 1100 r +5000 - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "tone_detect"; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "fax 1100 r +5000"; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - - // execute on tone detect - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "sleep"; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "3000"; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - } - - //add option record to the dialplan - if ($destination_record == "true") { - - //add a variable - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "record_path=\${recordings_dir}/\${domain_name}/archive/\${strftime(%Y)}/\${strftime(%b)}/\${strftime(%d)}"; - $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - - //add a variable - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "record_name=\${uuid}.\${record_ext}"; - $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - - //add a variable - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "record_append=true"; - $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - - //add a variable - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "record_in_progress=true"; - $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - - //add a variable - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "recording_follow_transfer=true"; - $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - - //add a variable - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "record_session"; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "\${record_path}/\${record_name}"; - $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = "false"; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - } - - //add the actions - foreach ($dialplan_details as $row) { - if (strlen($row["dialplan_detail_data"]) > 1) { - $actions = explode(":", $row["dialplan_detail_data"]); - $dialplan_detail_type = array_shift($actions); - $dialplan_detail_data = join(':', $actions); - - //add to the dialplan_details array - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = $dialplan_detail_type; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $dialplan_detail_data; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $dialplan_detail_order = $dialplan_detail_order + 10; - - //set the destination app and data - $_POST["destination_app"] = $dialplan_detail_type; - $_POST["destination_data"] = $dialplan_detail_data; - - //increment the array id - $y++; - } - } - - //delete the previous details - if ($action == "update") { - $sql = "delete from v_dialplan_details "; - $sql .= "where dialplan_uuid = '".$dialplan_uuid."' "; - if (!permission_exists('destination_domain')) { - $sql .= "and (domain_uuid = '".$domain_uuid."' or domain_uuid is null) "; - } - //echo $sql."

"; - $db->exec(check_sql($sql)); - unset($sql); - } - - //remove empty dialplan details from the POST array + //remove the array from the HTTP POST unset($_POST["dialplan_details"]); - //make sure the dialplan_uuid is set - if(strlen($_POST["dialplan_uuid"]) == 0) { - $_POST["dialplan_uuid"] = $dialplan_uuid; + //array cleanup + foreach ($dialplan_details as $index => $row) { + //unset the empty row + if (strlen($row["dialplan_detail_data"]) == 0) { + unset($dialplan_details[$index]); + } } + + //get the fax information + if (strlen($fax_uuid) > 0) { + $sql = "select * from v_fax "; + $sql .= "where fax_uuid = '".$fax_uuid."' "; + if (!permission_exists('destination_domain')) { + $sql .= "and domain_uuid = '".$domain_uuid."' "; + } + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + foreach ($result as &$row) { + $fax_extension = $row["fax_extension"]; + $fax_destination_number = $row["fax_destination_number"]; + $fax_name = $row["fax_name"]; + $fax_email = $row["fax_email"]; + $fax_pin_number = $row["fax_pin_number"]; + $fax_caller_id_name = $row["fax_caller_id_name"]; + $fax_caller_id_number = $row["fax_caller_id_number"]; + $fax_forward_number = $row["fax_forward_number"]; + $fax_description = $row["fax_description"]; + } + unset ($prep_statement); + } + + //if empty then get new uuid + if (strlen($dialplan_uuid) == 0) { + $dialplan_uuid = uuid(); + } + + //set the dialplan_uuid + $destination["dialplan_uuid"] = $dialplan_uuid; + + //build the dialplan array + $dialplan["app_uuid"] = "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4"; + $dialplan["dialplan_uuid"] = $dialplan_uuid; + $dialplan["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_name"] = ($dialplan_name != '') ? $dialplan_name : format_phone($destination_number); + $dialplan["dialplan_number"] = $destination_number; + $dialplan["dialplan_context"] = $destination_context; + $dialplan["dialplan_continue"] = "false"; + $dialplan["dialplan_order"] = "100"; + $dialplan["dialplan_enabled"] = $destination_enabled; + $dialplan["dialplan_description"] = ($dialplan_description != '') ? $dialplan_description : $destination_description; + $dialplan_detail_order = 10; + + //set the dialplan detail type + if (strlen($_SESSION['dialplan']['destination']['text']) > 0) { + $dialplan_detail_type = $_SESSION['dialplan']['destination']['text']; + } + else { + $dialplan_detail_type = "destination_number"; + } + + //build the xml dialplan + if ($_SESSION['destinations']['dialplan_details']['boolean'] == "false") { + $dialplan["dialplan_xml"] = "\n"; + $dialplan["dialplan_xml"] .= " \n"; + $dialplan["dialplan_xml"] .= " \n"; + $dialplan["dialplan_xml"] .= " \n"; + $dialplan["dialplan_xml"] .= " \n"; + if (strlen($destination_cid_name_prefix) > 0) { + $dialplan["dialplan_xml"] .= " \n"; + } + if (strlen($destination_record) > 0) { + $dialplan["dialplan_xml"] .= " \n"; + $dialplan["dialplan_xml"] .= " \n"; + $dialplan["dialplan_xml"] .= " \n"; + $dialplan["dialplan_xml"] .= " \n"; + $dialplan["dialplan_xml"] .= " \n"; + $dialplan["dialplan_xml"] .= " \n"; + } + if (strlen($destination_accountcode) > 0) { + $dialplan["dialplan_xml"] .= " \n"; + } + if (strlen($destination_carrier) > 0) { + $dialplan["dialplan_xml"] .= " \n"; + } + if (strlen($fax_uuid) > 0) { + $dialplan["dialplan_xml"] .= " \n"; + $dialplan["dialplan_xml"] .= " \n"; + $dialplan["dialplan_xml"] .= " \n"; + $dialplan["dialplan_xml"] .= " \n"; + } + $dialplan["dialplan_xml"] .= " \n"; + $dialplan["dialplan_xml"] .= " \n"; + $dialplan["dialplan_xml"] .= "\n"; + } + + //dialplan details + if ($_SESSION['destinations']['dialplan_details']['boolean'] == "true") { + + //delete previous dialplan details + $sql = "delete from v_dialplan_details "; + $sql .= "where (domain_uuid = '".$domain_uuid."' or domain_uuid is null) "; + $sql .= "and (dialplan_uuid = '".$dialplan_uuid."' or dialplan_uuid is null) "; + $sql .= "and ("; + $sql .= " dialplan_detail_data like '%tone_detect%' "; + $sql .= " or dialplan_detail_type = 'tone_detect' "; + $sql .= " or dialplan_detail_type = 'record_session' "; + $sql .= " or (dialplan_detail_type = 'sleep' and dialplan_detail_data = '3000') "; + $sql .= ")"; + $db->exec($sql); + unset($sql); + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + + //check the destination number + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "condition"; + if (strlen($_SESSION['dialplan']['destination']['text']) > 0) { + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = $_SESSION['dialplan']['destination']['text']; + } + else { + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "destination_number"; + } + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $destination_number_regex; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + + //set the caller id name prefix + if (strlen($destination_cid_name_prefix) > 0) { + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "effective_caller_id_name=".$destination_cid_name_prefix."#\${caller_id_name}"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + } + + //set the call accountcode + if (strlen($destination_accountcode) > 0) { + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "accountcode=".$destination_accountcode; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + } + + //set the call carrier + if (strlen($destination_carrier) > 0) { + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "carrier=$destination_carrier"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + } + + //add fax detection + if (strlen($fax_uuid) > 0) { + + //add set tone detect_hits=1 + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "tone_detect_hits=1"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + + // execute on tone detect + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "execute_on_tone_detect=transfer ".$fax_extension." XML \${domain_name}"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + + //add tone_detect fax 1100 r +5000 + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "tone_detect"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "fax 1100 r +5000"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + + // execute on tone detect + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "sleep"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "3000"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + } + + //add option record to the dialplan + if ($destination_record == "true") { + + //add a variable + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "record_path=\${recordings_dir}/\${domain_name}/archive/\${strftime(%Y)}/\${strftime(%b)}/\${strftime(%d)}"; + $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + + //add a variable + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "record_name=\${uuid}.\${record_ext}"; + $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + + //add a variable + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "record_append=true"; + $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + + //add a variable + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "record_in_progress=true"; + $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + + //add a variable + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "set"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "recording_follow_transfer=true"; + $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + + //add a variable + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_uuid"] = $dialplan_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "record_session"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "\${record_path}/\${record_name}"; + $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = "false"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + } + + //add the actions + foreach ($dialplan_details as $row) { + if (strlen($row["dialplan_detail_data"]) > 1) { + $actions = explode(":", $row["dialplan_detail_data"]); + $dialplan_detail_type = array_shift($actions); + $dialplan_detail_data = join(':', $actions); + + //add to the dialplan_details array + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = $dialplan_detail_type; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $dialplan_detail_data; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $dialplan_detail_order = $dialplan_detail_order + 10; + + //set the destination app and data + $_POST["destination_app"] = $dialplan_detail_type; + $_POST["destination_data"] = $dialplan_detail_data; + + //increment the array id + $y++; + } + } + + //delete the previous details + if ($action == "update") { + $sql = "delete from v_dialplan_details "; + $sql .= "where dialplan_uuid = '".$dialplan_uuid."' "; + if (!permission_exists('destination_domain')) { + $sql .= "and (domain_uuid = '".$domain_uuid."' or domain_uuid is null) "; + } + //echo $sql."

"; + $db->exec(check_sql($sql)); + unset($sql); + } + + //remove empty dialplan details from the POST array + unset($_POST["dialplan_details"]); + + //make sure the dialplan_uuid is set + if(strlen($_POST["dialplan_uuid"]) == 0) { + $_POST["dialplan_uuid"] = $dialplan_uuid; + } + } + + //build the destination array + $destination = $_POST; + $destination["destination_uuid"] = $destination_uuid; + + //prepare the array + $array['destinations'][] = $destination; + $array['dialplans'][] = $dialplan; + unset($dialplan); + + //add the dialplan permission + $p = new permissions; + $p->add("dialplan_add", 'temp'); + $p->add("dialplan_detail_add", 'temp'); + $p->add("dialplan_edit", 'temp'); + $p->add("dialplan_detail_edit", 'temp'); + + //save the dialplan + $database = new database; + $database->app_name = 'destinations'; + $database->app_uuid = '5ec89622-b19c-3559-64f0-afde802ab139'; + if (isset($dialplan["dialplan_uuid"])) { + $database->uuid($dialplan["dialplan_uuid"]); + } + $database->save($array); + $dialplan_response = $database->message; + + //remove the temporary permission + $p->delete("dialplan_add", 'temp'); + $p->delete("dialplan_detail_add", 'temp'); + $p->delete("dialplan_edit", 'temp'); + $p->delete("dialplan_detail_edit", 'temp'); + + //update the dialplan xml + $dialplans = new dialplan; + $dialplans->source = "details"; + $dialplans->destination = "database"; + $dialplans->uuid = $dialplan_uuid; + $dialplans->xml(); + + //synchronize the xml config + save_dialplan_xml(); + + //clear the cache + $cache = new cache; + $cache->delete("dialplan:".$destination_context); + $cache->delete("dialplan:".$destination_context.":".$destination_number); } - //prepare the array - $array['destinations'][] = $destination; - $array['dialplans'][] = $dialplan; - unset($dialplan); + //save the outbound destination + if ($destination_type == 'outbound') { - //add the dialplan permission - $p = new permissions; - $p->add("dialplan_add", 'temp'); - $p->add("dialplan_detail_add", 'temp'); - $p->add("dialplan_edit", 'temp'); - $p->add("dialplan_detail_edit", 'temp'); + //prepare the array + $array['destinations'][0]["destination_uuid"] = $destination_uuid; + $array['destinations'][0]["domain_uuid"] = $_POST["domain_uuid"]; + $array['destinations'][0]["destination_type"] = $_POST["destination_type"]; + $array['destinations'][0]["destination_number"] = $_POST["destination_number"]; + $array['destinations'][0]["destination_context"] = $_POST["destination_context"]; + $array['destinations'][0]["destination_enabled"] = $_POST["destination_enabled"]; + $array['destinations'][0]["destination_description"] = $_POST["destination_description"]; - //save the dialplan - $database = new database; - $database->app_name = 'dialplans'; - $database->app_uuid = '5ec89622-b19c-3559-64f0-afde802ab139'; - if (isset($dialplan["dialplan_uuid"])) { - $database->uuid($dialplan["dialplan_uuid"]); + //save the destination + $database = new database; + $database->app_name = 'destinations'; + $database->app_uuid = '5ec89622-b19c-3559-64f0-afde802ab139'; + $database->save($array); + $dialplan_response = $database->message; } - $database->save($array); - $dialplan_response = $database->message; - - //remove the temporary permission - $p->delete("dialplan_add", 'temp'); - $p->delete("dialplan_detail_add", 'temp'); - $p->delete("dialplan_edit", 'temp'); - $p->delete("dialplan_detail_edit", 'temp'); - - //update the dialplan xml - $dialplans = new dialplan; - $dialplans->source = "details"; - $dialplans->destination = "database"; - $dialplans->uuid = $dialplan_uuid; - $dialplans->xml(); - - //synchronize the xml config - save_dialplan_xml(); - - //clear the cache - $cache = new cache; - $cache->delete("dialplan:".$destination_context); - $cache->delete("dialplan:".$destination_context.":".$destination_number); //redirect the user if ($action == "add") { @@ -907,7 +925,7 @@ echo "\n"; echo "\n"; - if (permission_exists('destination_record')) { + if ($destination_type == 'inbound' && permission_exists('destination_record')) { echo "\n"; echo "".$text['label-destination_record']."\n"; echo "\n";