From c4517b15c25422d90ba407a6c9858ccf5baf03fb Mon Sep 17 00:00:00 2001 From: markjcrane Date: Tue, 21 Jul 2015 09:47:23 -0600 Subject: [PATCH] Move the 'show application' completely out of the content. Then save the result in a session variable $_SESSION['switch']['applications']. --- app/dialplan/dialplan_edit.php | 198 +++++++++++++++++---------------- 1 file changed, 100 insertions(+), 98 deletions(-) diff --git a/app/dialplan/dialplan_edit.php b/app/dialplan/dialplan_edit.php index 1bcf8e2d86..9531b7d0cd 100644 --- a/app/dialplan/dialplan_edit.php +++ b/app/dialplan/dialplan_edit.php @@ -77,100 +77,115 @@ else { $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"]); +//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(); + } } - //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; +//process and save the data + if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { + + $msg = ''; + if ($action == "update") { + $dialplan_uuid = check_str($_POST["dialplan_uuid"]); } - //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 - if (strlen($row["dialplan_uuid"]) > 0) { - $array['dialplan_uuid'] = $_POST["dialplan_uuid"]; - } - if (isset($_POST["domain_uuid"])) { - $array['domain_uuid'] = $_POST['domain_uuid']; - } - else { - $array['domain_uuid'] = $_SESSION['domain_uuid']; - } - $array['dialplan_name'] = $dialplan_name; - $array['dialplan_number'] = $_POST["dialplan_number"]; - $array['dialplan_context'] = $_POST["dialplan_context"]; - $array['dialplan_continue'] = $_POST["dialplan_continue"]; - $array['dialplan_order'] = $_POST["dialplan_order"]; - $array['dialplan_enabled'] = $_POST["dialplan_enabled"]; - $array['dialplan_description'] = $_POST["dialplan_description"]; - $x = 0; - foreach ($_POST["dialplan_details"] as $row) { - if (strlen($row["dialplan_detail_tag"]) > 0) { - if (strlen($row["dialplan_detail_uuid"]) > 0) { - $array['dialplan_details'][$x]['dialplan_detail_uuid'] = $row["dialplan_detail_uuid"]; - } - $array['dialplan_details'][$x]['domain_uuid'] = $array['domain_uuid']; - $array['dialplan_details'][$x]['dialplan_detail_tag'] = $row["dialplan_detail_tag"]; - $array['dialplan_details'][$x]['dialplan_detail_type'] = $row["dialplan_detail_type"]; - $array['dialplan_details'][$x]['dialplan_detail_data'] = $row["dialplan_detail_data"]; - $array['dialplan_details'][$x]['dialplan_detail_break'] = $row["dialplan_detail_break"]; - $array['dialplan_details'][$x]['dialplan_detail_inline'] = $row["dialplan_detail_inline"]; - $array['dialplan_details'][$x]['dialplan_detail_group'] = ($row["dialplan_detail_group"] != '') ? $row["dialplan_detail_group"] : '0'; - $array['dialplan_details'][$x]['dialplan_detail_order'] = $row["dialplan_detail_order"]; + //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; } - $x++; - } - //add or update the database - if ($_POST["persistformvar"] != "true") { - $orm = new orm; - $orm->name('dialplans'); - $orm->uuid($dialplan_uuid); - $orm->save($array); - //$message = $orm->message; - } + //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); - //clear the cache - $cache = new cache; - $cache->delete("dialplan:".$dialplan_context); + //build the array + if (strlen($row["dialplan_uuid"]) > 0) { + $array['dialplan_uuid'] = $_POST["dialplan_uuid"]; + } + if (isset($_POST["domain_uuid"])) { + $array['domain_uuid'] = $_POST['domain_uuid']; + } + else { + $array['domain_uuid'] = $_SESSION['domain_uuid']; + } + $array['dialplan_name'] = $dialplan_name; + $array['dialplan_number'] = $_POST["dialplan_number"]; + $array['dialplan_context'] = $_POST["dialplan_context"]; + $array['dialplan_continue'] = $_POST["dialplan_continue"]; + $array['dialplan_order'] = $_POST["dialplan_order"]; + $array['dialplan_enabled'] = $_POST["dialplan_enabled"]; + $array['dialplan_description'] = $_POST["dialplan_description"]; + $x = 0; + foreach ($_POST["dialplan_details"] as $row) { + if (strlen($row["dialplan_detail_tag"]) > 0) { + if (strlen($row["dialplan_detail_uuid"]) > 0) { + $array['dialplan_details'][$x]['dialplan_detail_uuid'] = $row["dialplan_detail_uuid"]; + } + $array['dialplan_details'][$x]['domain_uuid'] = $array['domain_uuid']; + $array['dialplan_details'][$x]['dialplan_detail_tag'] = $row["dialplan_detail_tag"]; + $array['dialplan_details'][$x]['dialplan_detail_type'] = $row["dialplan_detail_type"]; + $array['dialplan_details'][$x]['dialplan_detail_data'] = $row["dialplan_detail_data"]; + $array['dialplan_details'][$x]['dialplan_detail_break'] = $row["dialplan_detail_break"]; + $array['dialplan_details'][$x]['dialplan_detail_inline'] = $row["dialplan_detail_inline"]; + $array['dialplan_details'][$x]['dialplan_detail_group'] = ($row["dialplan_detail_group"] != '') ? $row["dialplan_detail_group"] : '0'; + $array['dialplan_details'][$x]['dialplan_detail_order'] = $row["dialplan_detail_order"]; + } + $x++; + } - //synchronize the xml config - save_dialplan_xml(); + //add or update the database + if ($_POST["persistformvar"] != "true") { + $orm = new orm; + $orm->name('dialplans'); + $orm->uuid($dialplan_uuid); + $orm->save($array); + //$message = $orm->message; + } - //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; + //clear the cache + $cache = new cache; + $cache->delete("dialplan:".$dialplan_context); -} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) + //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") { @@ -508,18 +523,6 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { //display the results if ($result_count > 0) { - //get the list of applications - $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'); - $installed_app = explode("\n\n", $result); - $installed_app = explode("\n", $installed_app[0]); - unset($result); - unset($fp); - } else { - $installed_app = Array(); - } - echo "\n"; $x = 0; @@ -641,7 +644,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { //} //if (strlen($dialplan_detail_tag) == 0 || $dialplan_detail_tag == "action" || $dialplan_detail_tag == "anti-action") { echo " \n"; - foreach ($installed_app as $row) { + foreach ($_SESSION['switch']['applications'] as $row) { if (strlen($row) > 0) { $application = explode(",", $row); if ($application[0] != "name" && stristr($application[0], "[") != true) { @@ -773,7 +776,6 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { } //end if results - } //end if update echo "
\n";