Portions created by the Initial Developer are Copyright (C) 2008-2016 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane Luis Daniel Lucio Quiroz */ //includes include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; require_once "resources/paging.php"; //check permissions if (permission_exists('dialplan_add') || permission_exists('dialplan_edit') || permission_exists('inbound_route_add') || permission_exists('inbound_route_edit') || permission_exists('outbound_route_add') || permission_exists('outbound_route_edit') || permission_exists('fifo_edit') || permission_exists('fifo_add') || permission_exists('time_condition_add') || permission_exists('time_condition_edit')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //set the action as an add or an update if (is_uuid($_REQUEST["id"])) { $action = "update"; $dialplan_uuid = $_REQUEST["id"]; } else { $action = "add"; } if (strlen($_REQUEST["app_uuid"]) > 0) { $app_uuid = $_REQUEST["app_uuid"]; } //get the http post values and set them as php variables if (count($_POST) > 0) { $hostname = check_str($_POST["hostname"]); $dialplan_name = check_str($_POST["dialplan_name"]); $dialplan_number = check_str($_POST["dialplan_number"]); $dialplan_order = check_str($_POST["dialplan_order"]); $dialplan_continue = check_str($_POST["dialplan_continue"]); $dialplan_details = $_POST["dialplan_details"]; if (strlen($dialplan_continue) == 0) { $dialplan_continue = "false"; } $dialplan_context = check_str($_POST["dialplan_context"]); $dialplan_enabled = check_str($_POST["dialplan_enabled"]); $dialplan_description = check_str($_POST["dialplan_description"]); } //get the list of applications if (count($_SESSION['switch']['applications']) == 0) { $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); if ($fp) { $result = event_socket_request($fp, 'api show application'); $_SESSION['switch']['applications'] = explode("\n\n", $result); $_SESSION['switch']['applications'] = explode("\n", $_SESSION['switch']['applications'][0]); unset($result); unset($fp); } else { $_SESSION['switch']['applications'] = Array(); } } //process and save the data if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { //get the dialplan uuid if ($action == "update") { $dialplan_uuid = check_str($_POST["dialplan_uuid"]); } //check for all required data $msg = ''; if (strlen($dialplan_name) == 0) { $msg .= $text['message-required'].$text['label-name']."
\n"; } if (strlen($dialplan_order) == 0) { $msg .= $text['message-required'].$text['label-order']."
\n"; } if (strlen($dialplan_continue) == 0) { $msg .= $text['message-required'].$text['label-continue']."
\n"; } if (strlen($dialplan_context) == 0) { $msg .= $text['message-required'].$text['label-context']."
\n"; } if (strlen($dialplan_enabled) == 0) { $msg .= $text['message-required'].$text['label-enabled']."
\n"; } //if (strlen($dialplan_description) == 0) { $msg .= $text['message-required'].$text['label-description']."
\n"; } if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { require_once "resources/header.php"; require_once "resources/persist_form_var.php"; echo "
\n"; echo "
\n"; echo $msg."
"; echo "
\n"; persistformvar($_POST); echo "
\n"; require_once "resources/footer.php"; return; } //remove the invalid characters from the dialplan name $dialplan_name = $_POST["dialplan_name"]; $dialplan_name = str_replace(" ", "_", $dialplan_name); $dialplan_name = str_replace("/", "", $dialplan_name); //build the array $x = 0; if (isset($_POST["dialplan_uuid"])) { $array['dialplans'][$x]['dialplan_uuid'] = $_POST["dialplan_uuid"]; } else { $dialplan_uuid = uuid(); $array['dialplans'][$x]['dialplan_uuid'] = $dialplan_uuid; } if (isset($_POST["domain_uuid"])) { $array['dialplans'][$x]['domain_uuid'] = $_POST['domain_uuid']; } else { $array['dialplans'][$x]['domain_uuid'] = $_SESSION['domain_uuid']; } $array['dialplans'][$x]['hostname'] = $hostname; $array['dialplans'][$x]['dialplan_name'] = $dialplan_name; $array['dialplans'][$x]['dialplan_number'] = $_POST["dialplan_number"]; $array['dialplans'][$x]['dialplan_context'] = $_POST["dialplan_context"]; $array['dialplans'][$x]['dialplan_continue'] = $_POST["dialplan_continue"]; $array['dialplans'][$x]['dialplan_order'] = $_POST["dialplan_order"]; $array['dialplans'][$x]['dialplan_enabled'] = $_POST["dialplan_enabled"]; $array['dialplans'][$x]['dialplan_description'] = $_POST["dialplan_description"]; $y = 0; if (is_array($_POST["dialplan_details"])) { foreach ($_POST["dialplan_details"] as $row) { if (strlen($row["dialplan_detail_tag"]) > 0) { if (strlen($row["dialplan_detail_uuid"]) > 0) { $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_uuid'] = $row["dialplan_detail_uuid"]; } $array['dialplans'][$x]['dialplan_details'][$y]['domain_uuid'] = $array['domain_uuid']; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_tag'] = $row["dialplan_detail_tag"]; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_type'] = $row["dialplan_detail_type"]; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_data'] = $row["dialplan_detail_data"]; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_break'] = $row["dialplan_detail_break"]; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_inline'] = $row["dialplan_detail_inline"]; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_group'] = ($row["dialplan_detail_group"] != '') ? $row["dialplan_detail_group"] : '0'; $array['dialplans'][$x]['dialplan_details'][$y]['dialplan_detail_order'] = $row["dialplan_detail_order"]; } $y++; } } //add or update the database if ($_POST["persistformvar"] != "true") { $database = new database; $database->app_name = 'dialplans'; $database->app_uuid = $app_uuid; $database->uuid($dialplan_uuid); $database->save($array); //$message = $database->message; } //update the dialplan xml $dialplans = new dialplan; $dialplans->source = "details"; $dialplans->destination = "database"; $dialplans->uuid = $dialplan_uuid; $dialplans->xml(); //clear the cache $cache = new cache; $cache->delete("dialplan:".$dialplan_context); //synchronize the xml config save_dialplan_xml(); //set the message if ($action == "add") { $_SESSION['message'] = $text['message-add']; } else if ($action == "update") { $_SESSION['message'] = $text['message-update']; } header("Location: ?id=".$dialplan_uuid.(($app_uuid != '') ? "&app_uuid=".$app_uuid : null)); exit; } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) //pre-populate the form if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { $sql = "select * from v_dialplans "; $sql .= "where dialplan_uuid = '$dialplan_uuid' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); if (is_array($result)) foreach ($result as &$row) { $domain_uuid = $row["domain_uuid"]; //$app_uuid = $row["app_uuid"]; $hostname = $row["hostname"]; $dialplan_name = $row["dialplan_name"]; $dialplan_number = $row["dialplan_number"]; $dialplan_order = $row["dialplan_order"]; $dialplan_continue = $row["dialplan_continue"]; $dialplan_context = $row["dialplan_context"]; $dialplan_enabled = $row["dialplan_enabled"]; $dialplan_description = $row["dialplan_description"]; } unset ($prep_statement); } //get the dialplan details in an array $sql = "select * from v_dialplan_details "; $sql .= "where dialplan_uuid = '$dialplan_uuid' "; $sql .= "order by dialplan_detail_group asc, dialplan_detail_order asc"; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $result_count = count($result); unset ($prep_statement, $sql); //create a new array that is sorted into groups and put the tags in order conditions, actions, anti-actions $x = 0; $details = ''; //conditions if (is_array($result)) foreach($result as $row) { if ($row['dialplan_detail_tag'] == "condition") { $group = $row['dialplan_detail_group']; foreach ($row as $key => $val) { $details[$group][$x][$key] = $val; } } $x++; } //regex if (is_array($result)) foreach($result as $row) { if ($row['dialplan_detail_tag'] == "regex") { $group = $row['dialplan_detail_group']; foreach ($row as $key => $val) { $details[$group][$x][$key] = $val; } } $x++; } //actions if (is_array($result)) foreach($result as $row) { if ($row['dialplan_detail_tag'] == "action") { $group = $row['dialplan_detail_group']; foreach ($row as $key => $val) { $details[$group][$x][$key] = $val; } } $x++; } //anti-actions if (is_array($result)) foreach($result as $row) { if ($row['dialplan_detail_tag'] == "anti-action") { $group = $row['dialplan_detail_group']; foreach ($row as $key => $val) { $details[$group][$x][$key] = $val; } } $x++; } unset($result); //blank row if (is_array($details)) foreach($details as $group => $row) { //set the array key for the empty row $x = "999"; //get the highest dialplan_detail_order if (is_array($row)) foreach ($row as $key => $field) { $dialplan_detail_order = 0; if ($dialplan_detail_order < $field['dialplan_detail_order']) { $dialplan_detail_order = $field['dialplan_detail_order']; } } //increment the highest order by 5 $dialplan_detail_order = $dialplan_detail_order + 10; //set the rest of the empty array //$details[$group][$x]['domain_uuid'] = ''; //$details[$group][$x]['dialplan_uuid'] = ''; $details[$group][$x]['dialplan_detail_tag'] = ''; $details[$group][$x]['dialplan_detail_type'] = ''; $details[$group][$x]['dialplan_detail_data'] = ''; $details[$group][$x]['dialplan_detail_break'] = ''; $details[$group][$x]['dialplan_detail_inline'] = ''; $details[$group][$x]['dialplan_detail_group'] = $group; $details[$group][$x]['dialplan_detail_order'] = $dialplan_detail_order; } //sort the details array by group number if (is_array($details)) { ksort($details); } //show the header require_once "resources/header.php"; $document['title'] = $text['title-dialplan_edit']; //javascript to change select to input and back again ?> \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo" ".$text['title-dialplan_edit']."
\n"; echo "
\n"; if (permission_exists('dialplan_xml')) { echo " 0) ? "app_uuid=".$app_uuid : null)."';\" value='".$text['button-xml']."'>\n"; } echo " 0) ? "?app_uuid=".$app_uuid : null)."';\" value='".$text['button-back']."'>\n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['description-dialplan-edit']."\n"; echo " \n"; echo "
"; echo "
\n"; echo "\n"; echo "\n"; echo ""; echo ""; echo ""; echo "
\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['label-name']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['label-number']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['label-hostname']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['description-hostname']."\n"; echo "
\n"; echo " ".$text['label-context']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['label-continue']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo "
\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; if (permission_exists('dialplan_domain')) { echo " \n"; echo " \n"; echo " \n"; echo " \n"; } echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['label-order']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo "
\n"; echo " ".$text['label-domain']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['description-domain_name']."\n"; echo "
\n"; echo " ".$text['label-enabled']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['label-description']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo "
"; echo "

"; //dialplan details if ($action == "update") { ?> 0) { echo "\n"; $x = 0; if (is_array($details)) foreach($details as $group) { if ($x != 0) { echo ""; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (is_array($group)) foreach($group as $index => $row) { //get the values from the database and set as variables $dialplan_detail_uuid = $row['dialplan_detail_uuid']; $dialplan_detail_tag = $row['dialplan_detail_tag']; $dialplan_detail_type = $row['dialplan_detail_type']; $dialplan_detail_data = $row['dialplan_detail_data']; $dialplan_detail_break = $row['dialplan_detail_break']; $dialplan_detail_inline = $row['dialplan_detail_inline']; $dialplan_detail_group = $row['dialplan_detail_group']; $dialplan_detail_order = $row['dialplan_detail_order']; //no border on last row $no_border = ($index == 999) ? "border: none;" : null; //begin the row echo "\n"; //determine whether to hide the element if (strlen($dialplan_detail_tag) == 0) { $element['hidden'] = false; $element['visibility'] = ""; } else { $element['hidden'] = true; $element['visibility'] = "display: none;"; } //add the primary key uuid if (strlen($dialplan_detail_uuid) > 0) { echo " \n"; } //tag $selected = "selected=\"selected\" "; echo "\n"; //type echo "\n"; //data echo "\n"; //break echo "\n"; //inline echo "\n"; //group echo "\n"; //order echo "\n"; //tools echo " \n"; //end the row echo "\n"; //increment the value $x++; } $x++; } //end foreach unset($sql, $result, $row_count); echo "


".$text['label-tag']."".$text['label-type']."".$text['label-data']."".$text['label-break']."".$text['label-inline']."".$text['label-group']."".$text['label-order']." 
\n"; if ($element['hidden']) { echo " \n"; } echo " \n"; echo "\n"; if ($element['hidden']) { echo " \n"; } echo " \n"; //echo " \n"; echo "\n"; if ($element['hidden']) { $dialplan_detail_data_mod = $dialplan_detail_data; if ($dialplan_detail_type == 'bridge') { // parse out gateway uuid $bridge_statement = explode('/', $dialplan_detail_data); if ($bridge_statement[0] == 'sofia' && $bridge_statement[1] == 'gateway' && is_uuid($bridge_statement[2])) { // retrieve gateway name from db $sql = "select gateway from v_gateways where gateway_uuid = '".$bridge_statement[2]."' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); if (count($result) > 0) { $gateway_name = $result[0]['gateway']; $dialplan_detail_data_mod = str_replace($bridge_statement[2], $gateway_name, $dialplan_detail_data); } unset ($prep_statement, $sql, $bridge_statement); } } echo " \n"; } echo " \n"; echo "\n"; if ($element['hidden']) { echo " \n"; } echo " \n"; echo "\n"; if ($element['hidden']) { echo " \n"; } echo " \n"; echo "\n"; if ($element['hidden']) { echo " \n"; } echo " \n"; /* echo " \n"; */ echo "\n"; if ($element['hidden']) { echo " \n"; } echo " \n"; /* echo " \n"; */ echo "\n"; if ($element['hidden']) { //echo " $v_link_label_edit\n"; echo " $v_link_label_delete\n"; } echo "
"; } //end if results } //end if update echo "
\n"; echo "
\n"; if ($action == "update") { echo " \n"; } echo " \n"; echo "
\n"; echo "

\n"; echo ""; if (file_exists($_SERVER["PROJECT_ROOT"]."/app/billing/app_config.php")){ echo "

".$text['billing-warning']."

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