diff --git a/app/destinations/destination_edit.php b/app/destinations/destination_edit.php index 178162c6d3..1d588ec027 100644 --- a/app/destinations/destination_edit.php +++ b/app/destinations/destination_edit.php @@ -80,6 +80,7 @@ //get http post variables and set them to php variables if (count($_POST) > 0) { + //set the variables $dialplan_uuid = $_POST["dialplan_uuid"]; $domain_uuid = $_POST["domain_uuid"]; @@ -114,14 +115,14 @@ $destination_carrier = $_POST["destination_carrier"]; //get the destination app and data - $destination_array = explode(":", $_POST["destination_action"], 2); - $destination_app = $destination_array[0]; - $destination_data = $destination_array[1]; + $destination_action_array = explode(":", $_POST["destination_action"], 2); + $destination_app = $destination_action_array[0]; + $destination_data = $destination_action_array[1]; //get the alternate destination app and data - $destination_alternate_array = explode(":", $_POST["destination_alternate_action"], 2); - $destination_alternate_app = $destination_alternate_array[0]; - $destination_alternate_data = $destination_alternate_array[1]; + $destination_alternate_action_array = explode(":", $_POST["destination_alternate_action"], 2); + $destination_alternate_app = $destination_alternate_action_array[0]; + $destination_alternate_data = $destination_alternate_action_array[1]; } //process the http post @@ -133,14 +134,6 @@ $destination->domain_uuid = $domain_uuid; } - //get the uuid - if ($action == "update" && is_uuid($_POST["destination_uuid"])) { - $destination_uuid = $_POST["destination_uuid"]; - } - else { - $destination_uuid = uuid(); - } - //set the default context if ($destination_type =="inbound" && strlen($destination_context) == 0) { $destination_context = 'public'; @@ -194,6 +187,7 @@ //save the inbound destination and add the dialplan for the inbound route if ($destination_type == 'inbound' || $destination_type == 'local') { + //get the array $dialplan_details = $_POST["dialplan_details"]; @@ -232,490 +226,544 @@ unset($sql, $parameters, $row); } - //if the user doesn't have the correct permission then - //override destination_number and destination_context values + //get the uuid + if ($action == "update" && is_uuid($_POST["destination_uuid"])) { + $destination_uuid = $_POST["destination_uuid"]; + } + + //get the destination row values if ($action == 'update' && is_uuid($destination_uuid)) { $sql = "select * from v_destinations "; $sql .= "where destination_uuid = :destination_uuid "; $parameters['destination_uuid'] = $destination_uuid; $database = new database; $row = $database->select($sql, $parameters, 'row'); - if (is_array($row) && @sizeof($row) != 0) { - if (!permission_exists('destination_trunk_prefix')) { - $destination_trunk_prefix = $row["destination_trunk_prefix"]; - } - if (!permission_exists('destination_area_code')) { - $destination_area_code = $row["destination_area_code"]; - } - if (!permission_exists('destination_number')) { - $destination_number = $row["destination_number"]; - $destination_prefix = $row["destination_prefix"]; - } - if (!permission_exists('destination_condition_field')) { - $destination_condition_field = $row["destination_condition_field"]; - } - if (!permission_exists('destination_context')) { - $destination_context = $row["destination_context"]; - } + } + + //get the dialplan_uuid from the database + if (is_array($row) && @sizeof($row) != 0) { + $dialplan_uuid = $row["dialplan_uuid"]; + } + + //if the user doesn't have the correct permission then + //override destination_number and destination_context values + if (is_array($row) && @sizeof($row) != 0) { + if (!permission_exists('destination_trunk_prefix')) { + $destination_trunk_prefix = $row["destination_trunk_prefix"]; + } + if (!permission_exists('destination_area_code')) { + $destination_area_code = $row["destination_area_code"]; + } + if (!permission_exists('destination_number')) { + $destination_number = $row["destination_number"]; + $destination_prefix = $row["destination_prefix"]; + } + if (!permission_exists('destination_condition_field')) { + $destination_condition_field = $row["destination_condition_field"]; + } + if (!permission_exists('destination_context')) { + $destination_context = $row["destination_context"]; } - unset($sql, $parameters, $row); } + unset($sql, $parameters, $row); - //convert the number to a regular expression - if (isset($destination_prefix) && strlen($destination_prefix) > 0) { - $destination_numbers['destination_prefix'] = $destination_prefix; + //build the destination_numbers array + $array = explode('-', $destination_number); + $array = array_map('trim', $array); + if (count($array) == 2 && is_numeric($array[0]) && is_numeric($array[1])) { + $destination_numbers = range($array[0], $array[1]); + $destination_number_range = true; } - if (isset($destination_trunk_prefix) && strlen($destination_trunk_prefix) > 0) { - $destination_numbers['destination_trunk_prefix'] = $destination_trunk_prefix; - } - if (isset($destination_area_code) && strlen($destination_area_code) > 0) { - $destination_numbers['destination_area_code'] = $destination_area_code; - } - if (isset($destination_number) && strlen($destination_number) > 0) { - $destination_numbers['destination_number'] = $destination_number; - } - $destination = new destinations; - $destination_number_regex = $destination->to_regex($destination_numbers); - unset($destination_numbers); - - //if empty then get new uuid - if (!is_uuid($dialplan_uuid)) { - $dialplan_uuid = uuid(); - } - - //set the dialplan_uuid - $array['destinations'][0]["dialplan_uuid"] = $dialplan_uuid; - - //build the dialplan array - if ($destination_type == "inbound") { - $dialplan["app_uuid"] = "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4"; - } - if ($destination_type == "local") { - $dialplan["app_uuid"] = "b5242951-686f-448f-8b4e-5031ba0601a4"; - } - $dialplan["dialplan_uuid"] = $dialplan_uuid; - $dialplan["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_name"] = ($dialplan_name != '') ? $dialplan_name : format_phone($destination_area_code.$destination_number); - $dialplan["dialplan_number"] = $destination_area_code.$destination_number; - $dialplan["dialplan_context"] = $destination_context; - $dialplan["dialplan_continue"] = "false"; - $dialplan["dialplan_order"] = $destination_order; - $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($destination_condition_field) > 0) { - $dialplan_detail_type = $destination_condition_field; - } - elseif (strlen($_SESSION['dialplan']['destination']['text']) > 0) { - $dialplan_detail_type = $_SESSION['dialplan']['destination']['text']; + elseif (stristr($destination_number, 'n') || stristr($destination_number, 'x') || stristr($destination_number, 'z')) { + //n = 2-9, x = 0-9, z = 1-9 + $destination_start = $destination_number; + $destination_end = $destination_number; + $destination_start = str_ireplace("n", "2", $destination_start); + $destination_end = str_ireplace("n", "9", $destination_end); + $destination_start = str_ireplace("x", "0", $destination_start); + $destination_end = str_ireplace("x", "9", $destination_end); + $destination_start = str_ireplace("z", "1", $destination_start); + $destination_end = str_ireplace("z", "9", $destination_end); + $destination_numbers = range($destination_start, $destination_end); + $destination_number_range = true; } else { - $dialplan_detail_type = "destination_number"; + //$destination_numbers[] = $destination_number; + $destination_numbers = $array; + $destination_number_range = false; } + unset($array); - //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"; + //add the destinations and asscociated dialplans + $x = 0; + foreach($destination_numbers as $destination_number) { - //add this only if using application bridge - if ($destination_app == 'bridge') { - $dialplan["dialplan_xml"] .= " \n"; - $dialplan["dialplan_xml"] .= " \n"; - } + //convert the number to a regular expression + if (isset($destination_prefix) && strlen($destination_prefix) > 0) { + $destination_numbers['destination_prefix'] = $destination_prefix; + } + if (isset($destination_trunk_prefix) && strlen($destination_trunk_prefix) > 0) { + $destination_numbers['destination_trunk_prefix'] = $destination_trunk_prefix; + } + if (isset($destination_area_code) && strlen($destination_area_code) > 0) { + $destination_numbers['destination_area_code'] = $destination_area_code; + } + if (isset($destination_number) && strlen($destination_number) > 0) { + $destination_numbers['destination_number'] = $destination_number; + } + $destination = new destinations; + $destination_number_regex = $destination->to_regex($destination_numbers); + unset($destination_numbers); - if (strlen($destination_cid_name_prefix) > 0) { - $dialplan["dialplan_xml"] .= " \n"; - } - if (strlen($destination_record) > 0 && $destination_record == 'true') { - $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_hold_music) > 0) { - $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"; + //if empty then get new uuid + if (!is_uuid($destination_uuid)) { + $destination_uuid = uuid(); + } + if (!is_uuid($dialplan_uuid)) { + $dialplan_uuid = uuid(); + } - } - if ($destination->valid($destination_app.':'.$destination_data)) { - $dialplan["dialplan_xml"] .= " \n"; - } - if (strlen($destination_alternate_app) > 0 && $destination->valid($destination_alternate_app.':'.$destination_alternate_data)) { - $dialplan["dialplan_xml"] .= " \n"; - } - $dialplan["dialplan_xml"] .= " \n"; - $dialplan["dialplan_xml"] .= "\n"; - } + //if the destination range is true then set a new uuid for each iteration of the loop + if ($destination_number_range) { + $destination_uuid = uuid(); + $dialplan_uuid = uuid(); + } - //dialplan details - if ($_SESSION['destinations']['dialplan_details']['boolean'] == "true") { + //set the dialplan_uuid + $array['destinations'][$x]["dialplan_uuid"] = $dialplan_uuid; - //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 .= ")"; - $parameters['domain_uuid'] = $domain_uuid; - $parameters['dialplan_uuid'] = $dialplan_uuid; - $database = new database; - $database->execute($sql, $parameters); - unset($sql, $parameters); + //build the dialplan array + if ($destination_type == "inbound") { + $dialplan["app_uuid"] = "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4"; + } + if ($destination_type == "local") { + $dialplan["app_uuid"] = "b5242951-686f-448f-8b4e-5031ba0601a4"; + } + $dialplan["dialplan_uuid"] = $dialplan_uuid; + $dialplan["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_name"] = ($dialplan_name != '') ? $dialplan_name : format_phone($destination_area_code.$destination_number); + $dialplan["dialplan_number"] = $destination_area_code.$destination_number; + $dialplan["dialplan_context"] = $destination_context; + $dialplan["dialplan_continue"] = "false"; + $dialplan["dialplan_order"] = $destination_order; + $dialplan["dialplan_enabled"] = $destination_enabled; + $dialplan["dialplan_description"] = ($dialplan_description != '') ? $dialplan_description : $destination_description; + $dialplan_detail_order = 10; - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; - - //check the destination number - $y=0; - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "condition"; + //set the dialplan detail type if (strlen($destination_condition_field) > 0) { - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = $destination_condition_field; + $dialplan_detail_type = $destination_condition_field; } elseif (strlen($_SESSION['dialplan']['destination']['text']) > 0) { - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = $_SESSION['dialplan']['destination']['text']; + $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; - - //add this only if using application bridge - if ($destination_app == 'bridge') { - //add hangup_after_bridge - $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"] = "hangup_after_bridge=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 continue_on_fail - $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"] = "continue_on_fail=true"; - $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; + $dialplan_detail_type = "destination_number"; } - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; + //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"; - //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_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; - } - - //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"] = "export"; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "accountcode=".$destination_accountcode; - $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; - } - - //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_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; - } - - //set the hold music - if (strlen($destination_hold_music) > 0) { - $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; - $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; - $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "export"; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "hold_music=".$destination_hold_music; - $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - $y++; - } - - //add fax detection - if (is_uuid($fax_uuid)) { - - //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_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; - - //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_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 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; - - //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 - if ($destination->valid($destination_app.':'.$destination_data)) { - //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"] = $destination_app; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $destination_data; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - - //set inline to true - if ($destination_app == 'set' || $destination_data == 'export') { - $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = 'true'; + //add this only if using application bridge + if ($destination_app == 'bridge') { + $dialplan["dialplan_xml"] .= " \n"; + $dialplan["dialplan_xml"] .= " \n"; } - $y++; + + if (strlen($destination_cid_name_prefix) > 0) { + $dialplan["dialplan_xml"] .= " \n"; + } + if (strlen($destination_record) > 0 && $destination_record == 'true') { + $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_hold_music) > 0) { + $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"; + + } + if ($destination->valid($destination_app.':'.$destination_data)) { + $dialplan["dialplan_xml"] .= " \n"; + } + if (strlen($destination_alternate_app) > 0 && $destination->valid($destination_alternate_app.':'.$destination_alternate_data)) { + $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 .= ")"; + $parameters['domain_uuid'] = $domain_uuid; + $parameters['dialplan_uuid'] = $dialplan_uuid; + $database = new database; + $database->execute($sql, $parameters); + unset($sql, $parameters); //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; + $dialplan_detail_order = $dialplan_detail_order + 10; + + //check the destination number + $y=0; + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "condition"; + if (strlen($destination_condition_field) > 0) { + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = $destination_condition_field; + } + elseif (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; + + //add this only if using application bridge + if ($destination_app == 'bridge') { + //add hangup_after_bridge + $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"] = "hangup_after_bridge=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 continue_on_fail + $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"] = "continue_on_fail=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; + + //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_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; + } + + //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"] = "export"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "accountcode=".$destination_accountcode; + $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; + } + + //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_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; + } + + //set the hold music + if (strlen($destination_hold_music) > 0) { + $dialplan["dialplan_details"][$y]["domain_uuid"] = $domain_uuid; + $dialplan["dialplan_details"][$y]["dialplan_detail_tag"] = "action"; + $dialplan["dialplan_details"][$y]["dialplan_detail_type"] = "export"; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = "hold_music=".$destination_hold_music; + $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = "true"; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + $y++; + } + + //add fax detection + if (is_uuid($fax_uuid)) { + + //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_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; + + //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_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 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; + + //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 + if ($destination->valid($destination_app.':'.$destination_data)) { + //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"] = $destination_app; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $destination_data; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + + //set inline to true + if ($destination_app == 'set' || $destination_data == 'export') { + $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = 'true'; + } + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + } + if ($destination->valid($destination_alternate_app.':'.$destination_alternate_data)) { + //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"] = $destination_alternate_app; + $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $destination_alternate_data; + $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; + + //set inline to true + if ($destination_alternate_app == 'set' || $destination_alternate_app == 'export') { + $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = 'true'; + } + $y++; + + //increment the dialplan detail order + $dialplan_detail_order = $dialplan_detail_order + 10; + } + + //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) "; + $parameters['domain_uuid'] = $domain_uuid; + } + $parameters['dialplan_uuid'] = $dialplan_uuid; + $database = new database; + $database->execute($sql, $parameters); + unset($sql, $parameters); + } + } + + //build the destination array + $array['destinations'][$x]["domain_uuid"] = $domain_uuid; + $array['destinations'][$x]["destination_uuid"] = $destination_uuid; + $array['destinations'][$x]["dialplan_uuid"] = $dialplan_uuid; + $array['destinations'][$x]["fax_uuid"] = $fax_uuid; + if (permission_exists('provider_edit')) { + $array['destinations'][$x]["provider_uuid"] = $provider_uuid; + } + if (permission_exists('user_edit')) { + $array['destinations'][$x]["user_uuid"] = $user_uuid; + } + $array['destinations'][$x]["destination_type"] = $destination_type; + if (permission_exists('destination_condition_field')) { + $array['destinations'][$x]["destination_condition_field"] = $destination_condition_field; + } + if (permission_exists('destination_number')) { + $array['destinations'][$x]["destination_number"] = $destination_number; + $array['destinations'][$x]["destination_number_regex"] = $destination_number_regex; + $array['destinations'][$x]["destination_prefix"] = $destination_prefix; + } + if (permission_exists('destination_trunk_prefix')) { + $array['destinations'][$x]["destination_trunk_prefix"] = $destination_trunk_prefix; + } + if (permission_exists('destination_area_code')) { + $array['destinations'][$x]["destination_area_code"] = $destination_area_code; + } + $array['destinations'][$x]["destination_caller_id_name"] = $destination_caller_id_name; + $array['destinations'][$x]["destination_caller_id_number"] = $destination_caller_id_number; + $array['destinations'][$x]["destination_cid_name_prefix"] = $destination_cid_name_prefix; + $array['destinations'][$x]["destination_context"] = $destination_context; + $array['destinations'][$x]["destination_hold_music"] = $destination_hold_music; + $array['destinations'][$x]["destination_record"] = $destination_record; + $array['destinations'][$x]["destination_accountcode"] = $destination_accountcode; + $array['destinations'][$x]["destination_type_voice"] = $destination_type_voice ? 1 : null; + $array['destinations'][$x]["destination_type_fax"] = $destination_type_fax ? 1 : null; + $array['destinations'][$x]["destination_type_text"] = $destination_type_text ? 1 : null; + if (permission_exists('destination_emergency')){ + $array['destinations'][$x]["destination_type_emergency"] = $destination_type_emergency ? 1 : null; + } + if ($destination->valid($destination_app.':'.$destination_data)) { + $array['destinations'][$x]["destination_app"] = $destination_app; + $array['destinations'][$x]["destination_data"] = $destination_data; } if ($destination->valid($destination_alternate_app.':'.$destination_alternate_data)) { - //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"] = $destination_alternate_app; - $dialplan["dialplan_details"][$y]["dialplan_detail_data"] = $destination_alternate_data; - $dialplan["dialplan_details"][$y]["dialplan_detail_order"] = $dialplan_detail_order; - - //set inline to true - if ($destination_alternate_app == 'set' || $destination_alternate_app == 'export') { - $dialplan["dialplan_details"][$y]["dialplan_detail_inline"] = 'true'; - } - $y++; - - //increment the dialplan detail order - $dialplan_detail_order = $dialplan_detail_order + 10; + $array['destinations'][$x]["destination_alternate_app"] = $destination_alternate_app; + $array['destinations'][$x]["destination_alternate_data"] = $destination_alternate_data; } + $array['destinations'][$x]["destination_order"] = $destination_order; + $array['destinations'][$x]["destination_enabled"] = $destination_enabled; + $array['destinations'][$x]["destination_description"] = $destination_description; + $x++; - //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) "; - $parameters['domain_uuid'] = $domain_uuid; - } - $parameters['dialplan_uuid'] = $dialplan_uuid; - $database = new database; - $database->execute($sql, $parameters); - unset($sql, $parameters); - } - } - - //build the destination array - $array['destinations'][0]["domain_uuid"] = $domain_uuid; - $array['destinations'][0]["destination_uuid"] = $destination_uuid; - $array['destinations'][0]["dialplan_uuid"] = $dialplan_uuid; - $array['destinations'][0]["fax_uuid"] = $fax_uuid; - if (permission_exists('provider_edit')) { - $array['destinations'][0]["provider_uuid"] = $provider_uuid; - } - if (permission_exists('user_edit')) { - $array['destinations'][0]["user_uuid"] = $user_uuid; - } - $array['destinations'][0]["destination_type"] = $destination_type; - if (permission_exists('destination_condition_field')) { - $array['destinations'][0]["destination_condition_field"] = $destination_condition_field; - } - if (permission_exists('destination_number')) { - $array['destinations'][0]["destination_number"] = $destination_number; - $array['destinations'][0]["destination_number_regex"] = $destination_number_regex; - $array['destinations'][0]["destination_prefix"] = $destination_prefix; - } - if (permission_exists('destination_trunk_prefix')) { - $array['destinations'][0]["destination_trunk_prefix"] = $destination_trunk_prefix; - } - if (permission_exists('destination_area_code')) { - $array['destinations'][0]["destination_area_code"] = $destination_area_code; - } - $array['destinations'][0]["destination_caller_id_name"] = $destination_caller_id_name; - $array['destinations'][0]["destination_caller_id_number"] = $destination_caller_id_number; - $array['destinations'][0]["destination_cid_name_prefix"] = $destination_cid_name_prefix; - $array['destinations'][0]["destination_context"] = $destination_context; - $array['destinations'][0]["destination_hold_music"] = $destination_hold_music; - $array['destinations'][0]["destination_record"] = $destination_record; - $array['destinations'][0]["destination_accountcode"] = $destination_accountcode; - $array['destinations'][0]["destination_type_voice"] = $destination_type_voice ? 1 : null; - $array['destinations'][0]["destination_type_fax"] = $destination_type_fax ? 1 : null; - $array['destinations'][0]["destination_type_text"] = $destination_type_text ? 1 : null; - if (permission_exists('destination_emergency')){ - $array['destinations'][0]["destination_type_emergency"] = $destination_type_emergency ? 1 : null; - } - if ($destination->valid($destination_app.':'.$destination_data)) { - $array['destinations'][0]["destination_app"] = $destination_app; - $array['destinations'][0]["destination_data"] = $destination_data; - } - if ($destination->valid($destination_alternate_app.':'.$destination_alternate_data)) { - $array['destinations'][0]["destination_alternate_app"] = $destination_alternate_app; - $array['destinations'][0]["destination_alternate_data"] = $destination_alternate_data; - } - $array['destinations'][0]["destination_order"] = $destination_order; - $array['destinations'][0]["destination_enabled"] = $destination_enabled; - $array['destinations'][0]["destination_description"] = $destination_description; - - //prepare the array - $array['dialplans'][] = $dialplan; - unset($dialplan); + //prepare the array + $array['dialplans'][] = $dialplan; + unset($dialplan); + } //foreach($destination_numbers as $destination_number) //add the dialplan permission $p = new permissions; @@ -728,9 +776,6 @@ $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; @@ -741,11 +786,12 @@ $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(); + if ($_SESSION['destinations']['dialplan_details']['boolean'] == "true") { + $dialplans = new dialplan; + $dialplans->source = "details"; + $dialplans->destination = "database"; + $dialplans->xml(); + } //clear the cache $cache = new cache; @@ -762,14 +808,15 @@ if ($destination_type == 'outbound') { //prepare the array - $array['destinations'][0]["destination_uuid"] = $destination_uuid; - $array['destinations'][0]["domain_uuid"] = $domain_uuid; - $array['destinations'][0]["destination_type"] = $destination_type; - $array['destinations'][0]["destination_number"] = $destination_number; - $array['destinations'][0]["destination_prefix"] = $destination_prefix; - $array['destinations'][0]["destination_context"] = $destination_context; - $array['destinations'][0]["destination_enabled"] = $destination_enabled; - $array['destinations'][0]["destination_description"] = $destination_description; + $x = 0; + $array['destinations'][$x]["destination_uuid"] = $destination_uuid; + $array['destinations'][$x]["domain_uuid"] = $domain_uuid; + $array['destinations'][$x]["destination_type"] = $destination_type; + $array['destinations'][$x]["destination_number"] = $destination_number; + $array['destinations'][$x]["destination_prefix"] = $destination_prefix; + $array['destinations'][$x]["destination_context"] = $destination_context; + $array['destinations'][$x]["destination_enabled"] = $destination_enabled; + $array['destinations'][$x]["destination_description"] = $destination_description; //save the destination $database = new database;