Portions created by the Initial Developer are Copyright (C) 2008-2013 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; require_once "resources/paging.php"; 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 require_once "app_languages.php"; foreach($text as $key => $value) { $text[$key] = $value[$_SESSION['domain']['language']['code']]; } //set the action as an add or an update if (isset($_REQUEST["id"])) { $action = "update"; $dialplan_uuid = check_str($_REQUEST["id"]); } else { $action = "add"; } //get the app uuid $app_uuid = check_str($_REQUEST["app_uuid"]); //get the http post values and set them as php variables if (count($_POST) > 0) { $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"]); } if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { $msg = ''; if ($action == "update") { $dialplan_uuid = check_str($_POST["dialplan_uuid"]); } //check for all required data 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 extension name $dialplan_name = str_replace(" ", "_", $dialplan_name); $dialplan_name = str_replace("/", "", $dialplan_name); //add or update the database if ($_POST["persistformvar"] != "true") { //add the data into the database if ($action == "add" && permission_exists('dialplan_add')) { $dialplan_context = $_SESSION['context']; $dialplan_uuid = uuid(); $sql = "insert into v_dialplans "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "dialplan_uuid, "; $sql .= "app_uuid, "; $sql .= "dialplan_name, "; $sql .= "dialplan_number, "; $sql .= "dialplan_order, "; $sql .= "dialplan_continue, "; $sql .= "dialplan_context, "; $sql .= "dialplan_enabled, "; $sql .= "dialplan_description "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'".$_SESSION['domain_uuid']."', "; $sql .= "'$dialplan_uuid', "; $sql .= "'742714e5-8cdf-32fd-462c-cbe7e3d655db', "; $sql .= "'$dialplan_name', "; $sql .= "'$dialplan_number', "; $sql .= "'$dialplan_order', "; $sql .= "'$dialplan_continue', "; $sql .= "'$dialplan_context', "; $sql .= "'$dialplan_enabled', "; $sql .= "'$dialplan_description' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); } //update the dialplan if ($action == "update" && permission_exists('dialplan_edit')) { $sql = "update v_dialplans set "; $sql .= "dialplan_name = '$dialplan_name', "; $sql .= "dialplan_number = '$dialplan_number', "; $sql .= "dialplan_order = '$dialplan_order', "; $sql .= "dialplan_continue = '$dialplan_continue', "; $sql .= "dialplan_context = '$dialplan_context', "; $sql .= "dialplan_enabled = '$dialplan_enabled', "; $sql .= "dialplan_description = '$dialplan_description' "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and dialplan_uuid = '$dialplan_uuid'"; $db->exec(check_sql($sql)); unset($sql); } //add or update the dialplan details foreach ($dialplan_details as $row) { //set the variables $dialplan_detail_uuid = check_str($row["dialplan_detail_uuid"]); $dialplan_detail_tag = check_str($row["dialplan_detail_tag"]); $dialplan_detail_order = check_str($row["dialplan_detail_order"]); $dialplan_detail_type = check_str($row["dialplan_detail_type"]); $dialplan_detail_data = check_str($row["dialplan_detail_data"]); $dialplan_detail_break = check_str($row["dialplan_detail_break"]); $dialplan_detail_inline = check_str($row["dialplan_detail_inline"]); $dialplan_detail_group = check_str($row["dialplan_detail_group"]); //add the details if (strlen($dialplan_detail_uuid) == 0 && permission_exists('dialplan_detail_add')) { $dialplan_detail_uuid = uuid(); $sql = "insert into v_dialplan_details "; $sql .= "("; $sql .= "dialplan_uuid, "; $sql .= "dialplan_detail_uuid, "; $sql .= "dialplan_detail_tag, "; $sql .= "dialplan_detail_order, "; $sql .= "dialplan_detail_type, "; $sql .= "dialplan_detail_data, "; $sql .= "dialplan_detail_break, "; $sql .= "dialplan_detail_inline, "; $sql .= "dialplan_detail_group, "; $sql .= "domain_uuid "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'$dialplan_uuid', "; $sql .= "'$dialplan_detail_uuid', "; $sql .= "'$dialplan_detail_tag', "; $sql .= "'$dialplan_detail_order', "; $sql .= "'$dialplan_detail_type', "; $sql .= "'$dialplan_detail_data', "; $sql .= "'$dialplan_detail_break', "; $sql .= "'$dialplan_detail_inline', "; if (strlen($dialplan_detail_group) == 0) { $sql .= "null, "; } else { $sql .= "'$dialplan_detail_group', "; } $sql .= "'".$_SESSION['domain_uuid']."' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); } //update the details if (strlen($dialplan_detail_uuid) > 0 && permission_exists('dialplan_detail_edit')) { $sql = "update v_dialplan_details set "; $sql .= "dialplan_uuid = '".$dialplan_uuid."', "; $sql .= "dialplan_detail_tag = '".$dialplan_detail_tag."', "; $sql .= "dialplan_detail_order = '".$dialplan_detail_order."', "; $sql .= "dialplan_detail_type = '".$dialplan_detail_type."', "; $sql .= "dialplan_detail_data = '".$dialplan_detail_data."', "; $sql .= "dialplan_detail_break = '".$dialplan_detail_break."', "; $sql .= "dialplan_detail_inline = '".$dialplan_detail_inline."', "; if (strlen($dialplan_detail_group) == 0) { $sql .= "dialplan_detail_group = null "; } else { $sql .= "dialplan_detail_group = '".$dialplan_detail_group."' "; } $sql .= "where dialplan_detail_uuid = '".$dialplan_detail_uuid."'"; $sql .= "and domain_uuid = '".$_SESSION['domain_uuid']."' "; $db->exec(check_sql($sql)); unset($sql); } } //delete the dialplan context from memcache $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); if ($fp) { $switch_cmd = "memcache delete dialplan:".$dialplan_context; $switch_result = event_socket_request($fp, 'api '.$switch_cmd); } //synchronize the xml config save_dialplan_xml(); //redirect the user /* require_once "resources/header.php"; switch ($app_uuid) { case "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4": //inbound routes echo "\n"; break; case "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3": //outbound routes echo "\n"; break; case "4b821450-926b-175a-af93-a03c441818b1": //time conditions echo "\n"; break; default: echo "\n"; break; } echo "
\n"; if ($action == "add") { echo $text['message-add']."\n"; } if ($action == "update") { echo $text['message-update']."\n"; } echo "
\n"; require_once "resources/footer.php"; return; */ //set the message if ($action == "add") { $_SESSION['message'] = $text['message-add']; } if ($action == "update") { $_SESSION['message'] = $text['message-update']; } } //if ($_POST["persistformvar"] != "true") } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) //pre-populate the form if (count($_GET)>0 && $_POST["persistformvar"] != "true") { $dialplan_uuid = $_GET["id"]; $sql = "select * from v_dialplans "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and dialplan_uuid = '$dialplan_uuid' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { $app_uuid = $row["app_uuid"]; $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 domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and 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 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 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 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 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 foreach($details as $group => $row) { //set the array key for the empty row $x = "999"; //get the highest dialplan_detail_order 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 + 5; //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; } //show the header require_once "resources/header.php"; $page["title"] = $text['title-dialplan_edit']; //javascript to change select to input and back again ?> "; echo "\n"; echo "\n"; echo " "; echo " "; echo "
\n"; echo "
"; echo "
\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"; echo " \n"; echo " \n"; if (strlen($app_uuid) > 0) { echo " \n"; } else { echo " \n"; } echo "
\n"; echo " ".$text['description-dialplan-edit']."\n"; echo " \n"; 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 "\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 " "; echo "
\n"; echo " ".$text['label-name'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo "\n"; echo "
\n"; echo " ".$text['label-number'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo "\n"; echo "
\n"; echo " ".$text['label-context'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo "\n"; echo "
\n"; echo " ".$text['label-continue'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo "
\n"; echo " ".$text['header-dialplan_detail'].":\n"; echo "\n"; //dialplan details if ($action == "update") { //start the table echo "
"; echo "\n"; echo "\n"; echo " "; echo ""; echo "
\n"; //define the alternating row styles $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; ?> \n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if ($result_count > 0) { $x = 0; foreach($details as $group) { if ($x > 0) { echo "
".$text['label-tag']."".$text['label-type']."".$text['label-data']."".$text['label-break']."".$text['label-inline']."".$text['label-group']."".$text['label-order']." 
"; 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"; } foreach($group as $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']; //view /* echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; */ //begin the row echo "\n"; //determine whether to hide the element if (strlen($dialplan_detail_tag) == 0) { $element['hidden'] = false; $element['visibility'] = "visibility:visible;"; } else { $element['hidden'] = true; $element['visibility'] = "visibility:hidden;"; } //add the primary key uuid echo " \n"; //tag $selected = "selected=\"selected\" "; if ($element['hidden']) { $element['width'] = '0'; } else { $element['width'] = '97'; } echo "\n"; //type if ($element['hidden']) { $element['width'] = '0'; } else { $element['width'] = '185'; } echo "\n"; //data if ($element['hidden']) { $element['width'] = '0'; } else { $element['width'] = '200'; } echo "\n"; //break if ($element['hidden']) { $element['width'] = '0'; } else { $element['width'] = '88'; } echo "\n"; //inline if ($element['hidden']) { $element['width'] = '0'; } else { $element['width'] = '65'; } echo "\n"; //group if ($element['hidden']) { $element['width'] = '0'; } else { $element['width'] = '30'; } echo "\n"; //order if ($element['hidden']) { $element['width'] = '0'; } else { $element['width'] = '32'; } echo "\n"; //tools echo " \n"; //end the row echo "\n"; //increment the value $x++; } if ($c==0) { $c=1; } else { $c=0; } $x++; } //end foreach unset($sql, $result, $row_count); } //end if results echo "
".$text['label-tag']."".$text['label-type']."".$text['label-data']."".$text['label-break']."".$text['label-inline']."".$text['label-group']."".$text['label-order']." 
  ".$row['dialplan_detail_tag']."  ".$row['dialplan_detail_type']."  ".wordwrap($row['dialplan_detail_data'],180,"
",1)."
  ".$row['dialplan_detail_break']."  ".$row['dialplan_detail_inline']."  ".$row['dialplan_detail_group']."  ".$row['dialplan_detail_order']."\n"; echo " $v_link_label_edit\n"; echo " $v_link_label_delete\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"; 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 "
"; echo "
"; echo "
"; echo "
"; } //end if update //echo "
\n"; //echo " ".$text['description-conditions_and_actions']."
\n"; echo " ".$text['label-order'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo "
\n"; echo " ".$text['label-enabled'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo "\n"; echo "
\n"; echo " ".$text['label-description'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo "
\n"; if ($action == "update") { echo " \n"; } echo " \n"; echo "
"; echo ""; echo "
"; echo ""; //show the footer require_once "resources/footer.php"; ?>