diff --git a/resources/switch.php b/resources/switch.php index 816df20ad6..0c9ea5aa39 100644 --- a/resources/switch.php +++ b/resources/switch.php @@ -650,318 +650,6 @@ function dialplan_detail_add($domain_uuid, $dialplan_uuid, $dialplan_detail_tag, $p->delete('dialplan_detail_add', 'temp'); } -function save_dialplan_xml() { - global $domain_uuid; - - //get the database connection - require_once "resources/classes/database.php"; - $database = new database; - $database->connect(); - $db = $database->db; - - //get the context based from the domain_uuid - $user_context = $_SESSION['domains'][$domain_uuid]['domain_name']; - - //prepare for dialplan .xml files to be written. delete all dialplan files that are prefixed with dialplan_ and have a file extension of .xml - $dialplan_list = glob($_SESSION['switch']['dialplan']['dir'] . "/*/*v_dialplan*.xml"); - foreach($dialplan_list as $name => $value) { - unlink($value); - } - $dialplan_list = glob($_SESSION['switch']['dialplan']['dir'] . "/*/*_v_*.xml"); - foreach($dialplan_list as $name => $value) { - unlink($value); - } - $dialplan_list = glob($_SESSION['switch']['dialplan']['dir'] . "/*/*/*_v_*.xml"); - foreach($dialplan_list as $name => $value) { - unlink($value); - } - - //if dialplan dir exists then build and save the dialplan xml - if (is_dir($_SESSION['switch']['dialplan']['dir'])) { - $sql = "select * from v_dialplans "; - $sql .= "where dialplan_enabled = 'true' "; - $database = new database; - $result = $database->select($sql, null, 'all'); - if (is_array($result) && @sizeof($result) != 0) { - foreach ($result as &$row) { - $tmp = "\n"; - $first_action = true; - - $dialplan_continue = ''; - if ($row['dialplan_continue'] == "true") { - $dialplan_continue = "continue=\"true\""; - } - - $tmp = "\n"; - - $sql = "select * from v_dialplan_details "; - $sql .= "where dialplan_uuid = :dialplan_uuid "; - $sql .= "order by dialplan_detail_group asc, dialplan_detail_order asc "; - $parameters['dialplan_uuid'] = $row['dialplan_uuid']; - $database = new database; - $result_2 = $database->select($sql, $parameters, 'all'); - unset($sql, $parameters); - - if (sizeof($result_2) && @sizeof($result_2) != 0) { - //create a new array that is sorted into groups and put the tags in order conditions, actions, anti-actions - $details = array(); - $previous_tag = ''; - $details[$group]['condition_count'] = ''; - //conditions - $x = 0; - $y = 0; - foreach ($result_2 as $row_2) { - if ($row_2['dialplan_detail_tag'] == "condition") { - //get the group - $group = $row_2['dialplan_detail_group']; - //get the generic type - switch ($row_2['dialplan_detail_type']) { - case "hour": - case "minute": - case "minute-of-day": - case "time-of-day": - case "mday": - case "mweek": - case "mon": - case "yday": - case "year": - case "wday": - case "week": - $type = 'time'; - break; - default: - $type = 'default'; - } - - //add the conditions to the details array - $details[$group]['condition-'.$x]['dialplan_detail_tag'] = $row_2['dialplan_detail_tag']; - $details[$group]['condition-'.$x]['dialplan_detail_type'] = $row_2['dialplan_detail_type']; - $details[$group]['condition-'.$x]['dialplan_uuid'] = $row_2['dialplan_uuid']; - $details[$group]['condition-'.$x]['dialplan_detail_order'] = $row_2['dialplan_detail_order']; - $details[$group]['condition-'.$x]['field'][$y]['type'] = $row_2['dialplan_detail_type']; - $details[$group]['condition-'.$x]['field'][$y]['data'] = $row_2['dialplan_detail_data']; - $details[$group]['condition-'.$x]['dialplan_detail_break'] = $row_2['dialplan_detail_break']; - $details[$group]['condition-'.$x]['dialplan_detail_group'] = $row_2['dialplan_detail_group']; - $details[$group]['condition-'.$x]['dialplan_detail_inline'] = $row_2['dialplan_detail_inline']; - if ($type == "time") { - $y++; - } - } - if ($type == "default") { - $x++; - $y = 0; - } - } - - //actions - $x = 0; - foreach($result_2 as $row_2) { - if ($row_2['dialplan_detail_tag'] == "action") { - $group = $row_2['dialplan_detail_group']; - foreach ($row_2 as $key => $val) { - $details[$group]['action-'.$x][$key] = $val; - } - } - $x++; - } - - //anti-actions - $x = 0; - foreach($result_2 as $row_2) { - if ($row_2['dialplan_detail_tag'] == "anti-action") { - $group = $row_2['dialplan_detail_group']; - foreach ($row_2 as $key => $val) { - $details[$group]['anti-action-'.$x][$key] = $val; - } - } - $x++; - } - - unset($result_2, $row_2); - } - - if (is_array($details) && @sizeof($details) != 0) { - foreach ($details as $group) { - $current_count = 0; - $x = 0; - foreach($group as $ent) { - $close_condition_tag = true; - if (empty($ent)) { - $close_condition_tag = false; - } - $current_tag = $ent['dialplan_detail_tag']; - $c = 0; - if ($ent['dialplan_detail_tag'] == "condition") { - //get the generic type - switch ($ent['dialplan_detail_type']) { - case "hour": - case "minute": - case "minute-of-day": - case "time-of-day": - case "mday": - case "mweek": - case "mon": - case "yday": - case "year": - case "wday": - case "week": - $type = 'time'; - break; - default: - $type = 'default'; - } - - //set the attribute and expression - $condition_attribute = ''; - foreach($ent['field'] as $field) { - if ($type == "time") { - if (strlen($field['type']) > 0) { - $condition_attribute .= $field['type'].'="'.$field['data'].'" '; - } - $condition_expression = ''; - } - if ($type == "default") { - $condition_attribute = ''; - if (strlen($field['type']) > 0) { - $condition_attribute = 'field="'.$field['type'].'" '; - } - $condition_expression = ''; - if (strlen($field['data']) > 0) { - $condition_expression = 'expression="'.$field['data'].'" '; - } - } - } - - //get the condition break attribute - $condition_break = ''; - if (strlen($ent['dialplan_detail_break']) > 0) { - $condition_break = "break=\"".$ent['dialplan_detail_break']."\" "; - } - - //get the count - $count = 0; - foreach($details as $group_2) { - foreach($group_2 as $ent_2) { - if ($ent_2['dialplan_detail_group'] == $ent['dialplan_detail_group'] && $ent_2['dialplan_detail_tag'] == "condition") { - $count++; - } - } - } - unset($group_2, $ent_2); - - //use the correct type of dialplan_detail_tag open or self closed - if ($count == 1) { //single condition - //start dialplan_detail_tag - $tmp .= " \n"; - } - else { //more than one condition - $current_count++; - if ($current_count < $count) { - //all tags should be self-closing except the last one - $tmp .= " \n"; - } - else { - //for the last dialplan_detail_tag use the start dialplan_detail_tag - $tmp .= " \n"; - } - } - } - //actions - if ($ent['dialplan_detail_tag'] == "action") { - //set the domain info for the public context - if ($row['dialplan_context'] == "public") { - if ($first_action) { - $tmp .= " \n"; - $tmp .= " \n"; - $tmp .= " \n"; - $tmp .= " \n"; - $first_action = false; - } - } - //get the action inline attribute - $action_inline = ''; - if (strlen($ent['dialplan_detail_inline']) > 0) { - $action_inline = "inline=\"".$ent['dialplan_detail_inline']."\""; - } - if (strlen($ent['dialplan_detail_data']) > 0) { - $tmp .= " \n"; - } - else { - $tmp .= " \n"; - } - } - //anti-actions - if ($ent['dialplan_detail_tag'] == "anti-action") { - //get the action inline attribute - $anti_action_inline = ''; - if (strlen($ent['dialplan_detail_inline']) > 0) { - $anti_action_inline = "inline=\"".$ent['dialplan_detail_inline']."\""; - } - if (strlen($ent['dialplan_detail_data']) > 0) { - $tmp .= " \n"; - } - else { - $tmp .= " \n"; - } - } - //set the previous dialplan_detail_tag - $previous_tag = $ent['dialplan_detail_tag']; - - } - if ($close_condition_tag == true) { - $tmp .= " \n"; - } - $x++; - } - unset($sql, $result_2, $row_count2); - } - $tmp .= "\n"; - - $dialplan_order = $row['dialplan_order']; - if (strlen($dialplan_order) == 0) { $dialplan_order = "000".$dialplan_order; } - if (strlen($dialplan_order) == 1) { $dialplan_order = "00".$dialplan_order; } - if (strlen($dialplan_order) == 2) { $dialplan_order = "0".$dialplan_order; } - if (strlen($dialplan_order) == 4) { $dialplan_order = "999"; } - if (strlen($dialplan_order) == 5) { $dialplan_order = "999"; } - - //remove invalid characters from the file names - $dialplan_name = $row['dialplan_name']; - $dialplan_name = str_replace(" ", "_", $dialplan_name); - $dialplan_name = preg_replace("/[\*\:\\/\<\>\|\'\"\?]/", "", $dialplan_name); - - $dialplan_filename = $dialplan_order."_v_".$dialplan_name.".xml"; - if (strlen($row['dialplan_context']) > 0) { - if (!is_dir($_SESSION['switch']['dialplan']['dir']."/".$row['dialplan_context'])) { - event_socket_mkdir($_SESSION['switch']['dialplan']['dir']."/".$row['dialplan_context']); - } - if ($row['dialplan_context'] == "public") { - if (count($_SESSION['domains']) > 1 && strlen($row['domain_uuid']) > 0) { - if (!is_dir($_SESSION['switch']['dialplan']['dir']."/public/".$_SESSION['domains'][$row['domain_uuid']]['domain_name'])) { - event_socket_mkdir($_SESSION['switch']['dialplan']['dir']."/public/".$_SESSION['domains'][$row['domain_uuid']]['domain_name']); - } - file_put_contents($_SESSION['switch']['dialplan']['dir']."/public/".$_SESSION['domains'][$row['domain_uuid']]['domain_name']."/".$dialplan_filename, $tmp); - } - else { - file_put_contents($_SESSION['switch']['dialplan']['dir']."/public/".$dialplan_filename, $tmp); - } - } - else { - if (!is_dir($_SESSION['switch']['dialplan']['dir']."/".$row['dialplan_context'])) { - event_socket_mkdir($_SESSION['switch']['dialplan']['dir']."/".$row['dialplan_context']); - } - file_put_contents($_SESSION['switch']['dialplan']['dir']."/".$row['dialplan_context']."/".$dialplan_filename, $tmp); - } - } - unset($dialplan_filename); - unset($tmp); - } - - //apply settings - $_SESSION["reload_xml"] = true; - } - } -} - if (!function_exists('phone_letter_to_number')) { function phone_letter_to_number($tmp) { $tmp = strtolower($tmp); @@ -1193,9 +881,6 @@ if (!function_exists('save_call_center_xml')) { fwrite($fout, $file_contents); fclose($fout); - //save the dialplan xml files - save_dialplan_xml(); - //apply settings $_SESSION["reload_xml"] = true; @@ -1375,9 +1060,6 @@ if (!function_exists('save_sip_profile_xml')) { if (!function_exists('save_switch_xml')) { function save_switch_xml() { - if (is_readable($_SESSION['switch']['dialplan']['dir'])) { - save_dialplan_xml(); - } if (is_readable($_SESSION['switch']['extensions']['dir'])) { if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/extensions/resources/classes/extension.php")) { require_once $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."app/extensions/resources/classes/extension.php";