From 0bc5a4870cf99a4c7ba61fcb6e2e94d7eaee33e5 Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Thu, 31 Jul 2014 09:21:16 +0000 Subject: [PATCH] Dialplan: Implemented bulk-delete. Default Settings: Minor fixes and enhancements. --- app/dialplan/dialplan_delete.php | 96 ++++++++++--------- app/dialplan/dialplan_detail_delete.php | 4 +- app/dialplan/dialplan_edit.php | 14 +-- app/dialplan/dialplans.php | 50 ++++++++-- .../default_settings/default_setting_edit.php | 14 ++- core/default_settings/default_settings.php | 33 +++++-- 6 files changed, 136 insertions(+), 75 deletions(-) diff --git a/app/dialplan/dialplan_delete.php b/app/dialplan/dialplan_delete.php index 36734e0434..93c26b2bd4 100644 --- a/app/dialplan/dialplan_delete.php +++ b/app/dialplan/dialplan_delete.php @@ -45,41 +45,51 @@ else { } //set the dialplan uuid - if (count($_GET) > 0) { - $dialplan_uuid = check_str($_GET["id"]); - } + $dialplan_uuids = $_REQUEST["id"]; + $app_uuid = check_str($_REQUEST['app_uuid']); -if (strlen($dialplan_uuid) > 0) { - //get the dialplan data - $sql = "select * from v_dialplans "; - //$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; - $sql .= "where 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) { - $database_dialplan_uuid = $row["dialplan_uuid"]; - $dialplan_context = $row["dialplan_context"]; - $app_uuid = $row["app_uuid"]; - } - unset ($prep_statement); +if (sizeof($dialplan_uuids) > 0) { + + //get dialplan contexts + foreach ($dialplan_uuids as $dialplan_uuid) { + + //check each + $dialplan_uuid = check_str($dialplan_uuid); + + //get the dialplan data + $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); + foreach ($result as &$row) { + $database_dialplan_uuid = $row["dialplan_uuid"]; + $dialplan_contexts[] = $row["dialplan_context"]; + } + unset($prep_statement); + } //start the atomic transaction $db->beginTransaction(); - //delete child data - $sql = "delete from v_dialplan_details "; - //$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; - $sql .= "where dialplan_uuid = '$dialplan_uuid'; "; - $db->query($sql); - unset($sql); + //delete dialplan and details + $dialplans_deleted = 0; + foreach ($dialplan_uuids as $dialplan_uuid) { - //delete parent data - $sql = "delete from v_dialplans "; - //$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; - $sql .= "where dialplan_uuid = '$dialplan_uuid'; "; - $db->query($sql); - unset($sql); + //delete child data + $sql = "delete from v_dialplan_details "; + $sql .= "where dialplan_uuid = '".$dialplan_uuid."'; "; + $db->query($sql); + unset($sql); + + //delete parent data + $sql = "delete from v_dialplans "; + $sql .= "where dialplan_uuid = '".$dialplan_uuid."'; "; + $db->query($sql); + unset($sql); + + $dialplans_deleted++; + } //commit the atomic transaction $db->commit(); @@ -87,26 +97,22 @@ if (strlen($dialplan_uuid) > 0) { //synchronize the xml config save_dialplan_xml(); - //delete the dialplan context from memcache + //strip duplicate contexts + $dialplan_contexts = array_unique($dialplan_contexts, SORT_STRING); + + //delete the dialplan contexts from memcache + if (sizeof($dialplan_contexts) > 0) { $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); + foreach($dialplan_contexts as $dialplan_context) { + $switch_cmd = "memcache delete dialplan:".$dialplan_context; + $switch_result = event_socket_request($fp, 'api '.$switch_cmd); + } } + } } -$_SESSION["message"] = $text['message-delete']; -switch ($app_uuid) { - case "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4": //inbound routes - case "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3": //outbound routes - case "4b821450-926b-175a-af93-a03c441818b1": //time conditions - $redirect_url = PROJECT_PATH."/app/dialplan/dialplans.php?app_uuid=".$app_uuid; - break; - default: - $redirect_url = PROJECT_PATH."/app/dialplan/dialplans.php"; -} -header("Location: ".$redirect_url); -return; - +$_SESSION["message"] = $text['message-delete'].(($dialplans_deleted > 1) ? ": ".$dialplans_deleted : null); +header("Location: ".PROJECT_PATH."/app/dialplan/dialplans.php".(($app_uuid != '') ? "?app_uuid=".$app_uuid : null)); ?> \ No newline at end of file diff --git a/app/dialplan/dialplan_detail_delete.php b/app/dialplan/dialplan_detail_delete.php index 24dbc22841..83472fef85 100644 --- a/app/dialplan/dialplan_detail_delete.php +++ b/app/dialplan/dialplan_detail_delete.php @@ -47,8 +47,8 @@ else { //set the variables if (count($_GET) > 0) { $dialplan_detail_uuid = check_str($_GET["id"]); - $app_uuid = check_str($_REQUEST["app_uuid"]); $dialplan_uuid = check_str($_REQUEST["dialplan_uuid"]); + $app_uuid = check_str($_REQUEST["app_uuid"]); } //delete the dialplan detail @@ -75,7 +75,7 @@ else { $_SESSION['message'] = $text['message-delete']; //redirect the browser - header("Location: dialplan_edit.php?id=".$dialplan_uuid."&app_uuid=".$app_uuid); + header("Location: dialplan_edit.php?id=".$dialplan_uuid.(($app_uuid != '') ? "&app_uuid=".$app_uuid : null)); exit; ?> \ No newline at end of file diff --git a/app/dialplan/dialplan_edit.php b/app/dialplan/dialplan_edit.php index 26e584a525..06e7c58485 100644 --- a/app/dialplan/dialplan_edit.php +++ b/app/dialplan/dialplan_edit.php @@ -175,7 +175,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { else if ($action == "update") { $_SESSION['message'] = $text['message-update']; } - header("Location: ?id=".$dialplan_uuid."&app_uuid=".$app_uuid); + header("Location: ?id=".$dialplan_uuid.(($app_uuid != '') ? "&app_uuid=".$app_uuid : null)); exit; } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) @@ -190,7 +190,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { //$message = $orm->message; foreach ($result as &$row) { $domain_uuid = $row["domain_uuid"]; - $app_uuid = $row["app_uuid"]; + //$app_uuid = $row["app_uuid"]; $dialplan_name = $row["dialplan_name"]; $dialplan_number = $row["dialplan_number"]; $dialplan_order = $row["dialplan_order"]; @@ -325,6 +325,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo "
"; echo "
\n"; + echo "\n"; echo "
\n"; echo "\n"; @@ -333,12 +334,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo" ".$text['title-dialplan_edit']."
\n"; echo " \n"; echo " \n"; @@ -764,7 +760,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo " \n"; //end the row diff --git a/app/dialplan/dialplans.php b/app/dialplan/dialplans.php index 94c673cc65..d5749ed452 100644 --- a/app/dialplan/dialplans.php +++ b/app/dialplan/dialplans.php @@ -95,7 +95,7 @@ else { echo " \n"; echo " \n"; - echo " \n"; + echo " \n"; echo " \n"; echo "\n"; @@ -496,7 +496,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo " ".$text['label-description'].":\n"; echo "\n"; echo "\n"; @@ -505,7 +505,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo " \n"; echo " \n"; @@ -518,6 +518,10 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo "
\n"; - if (strlen($app_uuid) > 0) { - echo " \n"; - } - else { - echo " \n"; - } + echo " 0) ? "?app_uuid=".$app_uuid : null)."';\" value='".$text['button-back']."'>\n"; echo " \n"; echo " \n"; echo " \n"; if ($element['hidden']) { //echo " $v_link_label_edit\n"; - echo " $v_link_label_delete\n"; + echo " $v_link_label_delete\n"; } echo " \n"; echo " "; if (strlen($app_uuid) > 0) { @@ -231,8 +231,13 @@ else { $row_style["1"] = "row_style1"; echo "
\n"; + echo "\n"; + echo "\n"; echo "\n"; echo "\n"; + if (permission_exists('dialplan_delete') && $result_count > 0) { + echo ""; + } echo th_order_by('dialplan_name', $text['label-name'], $order_by, $order, $app_uuid); echo th_order_by('dialplan_number', $text['label-number'], $order_by, $order, $app_uuid); echo th_order_by('dialplan_context', $text['label-context'], $order_by, $order, $app_uuid); @@ -255,6 +260,9 @@ else { elseif (permission_exists('dialplan_add')) { echo "$v_link_label_add"; } + if (permission_exists('dialplan_delete') && $result_count > 0) { + echo "".$v_link_label_delete.""; + } echo "\n"; echo "\n"; @@ -286,6 +294,18 @@ else { } unset ($prep_statement); } + + // blank app id if doesn't match others, so will return to dialplan manager + switch ($app_uuid) { + case "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" : // inbound route + case "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3" : // outbound route + case "16589224-c876-aeb3-f59f-523a1c0801f7" : // fifo + case "4b821450-926b-175a-af93-a03c441818b1" : // time condition + break; + default : + unset($app_uuid); + } + if ( ($app_uuid == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_edit')) || ($app_uuid == "8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3" && permission_exists('outbound_route_edit')) || @@ -293,9 +313,13 @@ else { ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_edit')) || permission_exists('dialplan_edit') ) { - $tr_link = "href='dialplan_edit.php?id=".$row['dialplan_uuid']."&app_uuid=".$app_uuid."'"; + $tr_link = "href='dialplan_edit.php?id=".$row['dialplan_uuid'].(($app_uuid != '') ? "&app_uuid=".$app_uuid : null)."'"; } echo "\n"; + if (permission_exists("dialplan_delete")) { + echo " \n"; + $dialplan_ids[] = 'checkbox_'.$row['dialplan_uuid']; + } echo " \n"; echo "\n"; @@ -342,7 +366,7 @@ else { } //end if results echo "\n"; - echo ""; echo ""; echo "
"; if ( ($app_uuid == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_edit')) || @@ -304,7 +328,7 @@ else { ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_edit')) || permission_exists('dialplan_edit') ) { - echo "".$row['dialplan_name'].""; + echo "".$row['dialplan_name'].""; } else { echo $row['dialplan_name']; @@ -323,7 +347,7 @@ else { ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_edit')) || permission_exists('dialplan_edit') ) { - echo "$v_link_label_edit"; + echo "$v_link_label_edit"; } if ( ($app_uuid == "c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4" && permission_exists('inbound_route_delete')) || @@ -332,7 +356,7 @@ else { ($app_uuid == "4b821450-926b-175a-af93-a03c441818b1" && permission_exists('time_condition_delete')) || permission_exists('dialplan_delete') ) { - echo "$v_link_label_delete"; + echo "$v_link_label_delete"; } echo "
\n"; + echo "\n"; echo " \n"; echo " \n"; echo " \n"; @@ -363,6 +387,9 @@ else { elseif (permission_exists('dialplan_add')) { echo "$v_link_label_add"; } + if (permission_exists('dialplan_delete') && $result_count > 0) { + echo "".$v_link_label_delete.""; + } echo " \n"; echo " \n"; echo "
 
\n"; @@ -377,9 +404,20 @@ else { echo "
"; + echo ""; echo "
"; echo "

"; + if (sizeof($dialplan_ids) > 0) { + echo "\n"; + } + //include the footer require_once "resources/footer.php"; diff --git a/core/default_settings/default_setting_edit.php b/core/default_settings/default_setting_edit.php index d82b6e2373..892ab08088 100644 --- a/core/default_settings/default_setting_edit.php +++ b/core/default_settings/default_setting_edit.php @@ -53,8 +53,8 @@ else { } //get http post variables and set them to php variables - if (count($_POST) > 0) { - $default_setting_category = strtolower(check_str($_POST["default_setting_category"])); + if (count($_REQUEST) > 0) { + $default_setting_category = strtolower(check_str($_REQUEST["default_setting_category"])); $default_setting_subcategory = strtolower(check_str($_POST["default_setting_subcategory"])); $default_setting_name = strtolower(check_str($_POST["default_setting_name"])); $default_setting_value = check_str($_POST["default_setting_value"]); @@ -226,7 +226,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo " ".$text['label-subcategory'].":\n"; echo "
\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-subcategory']."\n"; echo "
\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-description']."\n"; echo "
\n"; if ($action == "update") { - echo " \n"; + echo " \n"; } echo " \n"; echo "
"; echo "
"; + if ($_REQUEST["id"] == '' && $_REQUEST["default_setting_category"] != '') { + echo ""; + } + //include the footer require_once "resources/footer.php"; ?> \ No newline at end of file diff --git a/core/default_settings/default_settings.php b/core/default_settings/default_settings.php index d71e037798..bea0df4cb5 100644 --- a/core/default_settings/default_settings.php +++ b/core/default_settings/default_settings.php @@ -318,7 +318,7 @@ if (permission_exists("domain_select") && permission_exists("domain_setting_add" if ($previous_category != $row['default_setting_category']) { echo "\n"; - echo " \n"; + echo " \n"; if ($previous_category != '') { echo "

"; } echo "
\n"; echo " \n"; @@ -335,7 +335,10 @@ if (permission_exists("domain_select") && permission_exists("domain_setting_add" echo " \n"; echo "\n"; echo "\n"; - if (permission_exists("domain_select") && permission_exists("domain_setting_add") && count($_SESSION['domains']) > 1) { + if ( + (permission_exists("domain_select") && permission_exists("domain_setting_add") && count($_SESSION['domains']) > 1) || + permission_exists('default_setting_delete') + ) { echo ""; } echo "".$text['label-subcategory'].""; @@ -345,7 +348,7 @@ if (permission_exists("domain_select") && permission_exists("domain_setting_add" echo "".$text['label-description'].""; echo ""; if (permission_exists('default_setting_add')) { - echo "".$v_link_label_add.""; + echo "".$v_link_label_add.""; } if (permission_exists('default_setting_delete')) { echo "".$v_link_label_delete.""; @@ -357,7 +360,10 @@ if (permission_exists("domain_select") && permission_exists("domain_setting_add" $tr_link = (permission_exists('default_setting_edit')) ? "href='default_setting_edit.php?id=".$row['default_setting_uuid']."'" : null; echo "\n"; - if (permission_exists("domain_select") && permission_exists("domain_setting_add") && count($_SESSION['domains']) > 1) { + if ( + (permission_exists("domain_select") && permission_exists("domain_setting_add") && count($_SESSION['domains']) > 1) || + permission_exists("default_setting_delete") + ) { echo " \n"; $subcat_ids[strtolower($row['default_setting_category'])][] = 'checkbox_'.$row['default_setting_uuid']; } @@ -412,14 +418,26 @@ if (permission_exists("domain_select") && permission_exists("domain_setting_add" } //end if results echo "\n"; - echo " 1) ? 7 : 6)."' align='left'>\n"; + if ( + (permission_exists("domain_select") && permission_exists("domain_setting_add") && count($_SESSION['domains']) > 1) || + permission_exists("domain_delete") + ) { + $colspan = 7; + } + else { + $colspan = 6; + } + echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; @@ -441,8 +459,8 @@ if (permission_exists("domain_select") && permission_exists("domain_setting_add" echo "

"; + // check or uncheck all category checkboxes if (sizeof($subcat_ids) > 0) { - echo "\n"; - } //include the footer
 $paging_controls"; if (permission_exists('default_setting_add')) { - echo "$v_link_label_add"; + echo "$v_link_label_add"; + } + if (permission_exists('default_setting_delete')) { + echo "".$v_link_label_delete.""; } echo "