From 0918706ffd2f775a993e7b627e3c0c94971a0728 Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Thu, 15 Aug 2013 19:16:03 +0000 Subject: [PATCH] Add ring group call forwarding. Remove the memcache entry in case the ring group extension number is changed. Make sure the ring group dialplan entry gets updated. --- app/ring_groups/app_languages.php | 20 +- app/ring_groups/ring_group_delete.php | 18 +- app/ring_groups/ring_group_edit.php | 119 ++++++------ app/ring_groups/ring_group_forward.php | 171 +++++++++++++++++ app/ring_groups/ring_group_forward_edit.php | 194 ++++++++++++++++++++ 5 files changed, 458 insertions(+), 64 deletions(-) create mode 100644 app/ring_groups/ring_group_forward.php create mode 100644 app/ring_groups/ring_group_forward_edit.php diff --git a/app/ring_groups/app_languages.php b/app/ring_groups/app_languages.php index 01f3f77050..0e13576ba6 100644 --- a/app/ring_groups/app_languages.php +++ b/app/ring_groups/app_languages.php @@ -33,6 +33,18 @@ $text['label-extension']['en-us'] = 'Extension'; + $text['label-ring-group-extension']['en-us'] = 'Ring Group Extension'; + + $text['header-ring-group-forward']['en-us'] = 'Ring Group Forward'; + + $text['description-ring-group-forward']['en-us'] = 'Forwards calls to an alternate destination for extension '; + + $text['label-call-forward']['en-us'] = 'Call Forward:'; + + $text['label-forward_destination']['en-us'] = 'Number:'; + + $text['label-tools']['en-us'] = 'Tools'; + $text['label-enabled']['en-us'] = 'Enabled'; $text['label-description']['en-us'] = 'Description'; @@ -147,6 +159,12 @@ $text['confirm-delete']['pt-pt'] = ''; $text['confirm-copy']['en-us'] = 'Do you really want to copy this?'; - $text['confirm-copy']['en-us'] = ''; + $text['confirm-copy']['en-pt'] = ''; + + $text['option-enabled']['en-us'] = 'Enabled'; + $text['option-enabled']['pt-pt'] = ''; + + $text['option-disabled']['en-us'] = 'Disabled'; + $text['option-disabled']['pt-pt'] = ''; ?> \ No newline at end of file diff --git a/app/ring_groups/ring_group_delete.php b/app/ring_groups/ring_group_delete.php index 38253350a9..fa6ee200d0 100644 --- a/app/ring_groups/ring_group_delete.php +++ b/app/ring_groups/ring_group_delete.php @@ -57,24 +57,32 @@ else { $result = $prep_statement->fetchAll(); foreach ($result as &$row) { $dialplan_uuid = $row["dialplan_uuid"]; + $ring_group_context = $row["ring_group_context"]; } unset ($prep_statement); - //delete from the ring groups table + //delete the ring group $sql = "delete from v_ring_groups "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and ring_group_uuid = '".$id."' "; $db->exec(check_sql($sql)); unset($sql); - //delete from the ring group extensions table - $sql = "delete from v_ring_group_extensions "; + //delete the ring group destinations + $sql = "delete from v_ring_group_destinations "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and ring_group_uuid = '".$id."' "; $db->exec(check_sql($sql)); unset($sql); - //delete from the dialplan + //delete the dialplan details + $sql = "delete from v_dialplan_details "; + $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; + $sql .= "and dialplan_uuid = '".$dialplan_uuid."' "; + $db->exec(check_sql($sql)); + unset($sql); + + //delete the dialplan $sql = "delete from v_dialplans "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and dialplan_uuid = '".$dialplan_uuid."' "; @@ -90,7 +98,7 @@ else { //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:".$_SESSION["context"]."@".$_SESSION['domain_name']; + $switch_cmd = "memcache delete dialplan:".$ring_group_context; $switch_result = event_socket_request($fp, 'api '.$switch_cmd); } } diff --git a/app/ring_groups/ring_group_edit.php b/app/ring_groups/ring_group_edit.php index 4f93fbbf88..f2aeb1d454 100644 --- a/app/ring_groups/ring_group_edit.php +++ b/app/ring_groups/ring_group_edit.php @@ -257,75 +257,78 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { unset($sql); } - //if it does not exist in the dialplan then add it - $sql = "select count(*) as num_rows from v_dialplans "; + //delete from the dialplan details + $sql = "delete from v_dialplan_details "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and dialplan_uuid = '".$dialplan_uuid."' "; - $prep_statement = $db->prepare(check_sql($sql)); - if ($prep_statement) { - $prep_statement->execute(); - $row = $prep_statement->fetch(PDO::FETCH_ASSOC); - if ($row['num_rows'] == 0) { - //add the dialplan - require_once "resources/classes/database.php"; - $database = new database; - $database->db = $db; - $database->table = "v_dialplans"; - $database->fields['domain_uuid'] = $_SESSION['domain_uuid']; - $database->fields['dialplan_uuid'] = $dialplan_uuid; - $database->fields['dialplan_name'] = $ring_group_name; - $database->fields['dialplan_order'] = '333'; - $database->fields['dialplan_context'] = $ring_group_context; - $database->fields['dialplan_enabled'] = 'true'; - $database->fields['dialplan_description'] = $ring_group_description; - $database->fields['app_uuid'] = '1d61fb65-1eec-bc73-a6ee-a6203b4fe6f2'; - $database->add(); + $db->exec(check_sql($sql)); + unset($sql); - //add the dialplan details - $database->table = "v_dialplan_details"; - $database->fields['domain_uuid'] = $_SESSION['domain_uuid']; - $database->fields['dialplan_uuid'] = $dialplan_uuid; - $database->fields['dialplan_detail_uuid'] = uuid(); - $database->fields['dialplan_detail_tag'] = 'condition'; //condition, action, antiaction - $database->fields['dialplan_detail_type'] = 'destination_number'; - $database->fields['dialplan_detail_data'] = '^'.$ring_group_extension.'$'; - $database->fields['dialplan_detail_order'] = '000'; - $database->add(); + //delete from the dialplan + $sql = "delete from v_dialplans "; + $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; + $sql .= "and dialplan_uuid = '".$dialplan_uuid."' "; + $db->exec(check_sql($sql)); + unset($sql); - //add the dialplan details - $database->table = "v_dialplan_details"; - $database->fields['domain_uuid'] = $_SESSION['domain_uuid']; - $database->fields['dialplan_uuid'] = $dialplan_uuid; - $database->fields['dialplan_detail_uuid'] = uuid(); - $database->fields['dialplan_detail_tag'] = 'action'; //condition, action, antiaction - $database->fields['dialplan_detail_type'] = 'set'; - $database->fields['dialplan_detail_data'] = 'ring_group_uuid='.$ring_group_uuid; - $database->fields['dialplan_detail_order'] = '025'; - $database->add(); + //add the dialplan + require_once "resources/classes/database.php"; + $database = new database; + $database->db = $db; + $database->table = "v_dialplans"; + $database->fields['domain_uuid'] = $_SESSION['domain_uuid']; + $database->fields['dialplan_uuid'] = $dialplan_uuid; + $database->fields['dialplan_name'] = $ring_group_name; + $database->fields['dialplan_order'] = '333'; + $database->fields['dialplan_context'] = $ring_group_context; + $database->fields['dialplan_enabled'] = 'true'; + $database->fields['dialplan_description'] = $ring_group_description; + $database->fields['app_uuid'] = '1d61fb65-1eec-bc73-a6ee-a6203b4fe6f2'; + $database->add(); - //add the dialplan details - $database->table = "v_dialplan_details"; - $database->fields['domain_uuid'] = $_SESSION['domain_uuid']; - $database->fields['dialplan_uuid'] = $dialplan_uuid; - $database->fields['dialplan_detail_uuid'] = uuid(); - $database->fields['dialplan_detail_tag'] = 'action'; //condition, action, antiaction - $database->fields['dialplan_detail_type'] = 'lua'; - $database->fields['dialplan_detail_data'] = 'app.lua ring_groups'; - $database->fields['dialplan_detail_order'] = '030'; - $database->add(); + //add the dialplan details + $database->table = "v_dialplan_details"; + $database->fields['domain_uuid'] = $_SESSION['domain_uuid']; + $database->fields['dialplan_uuid'] = $dialplan_uuid; + $database->fields['dialplan_detail_uuid'] = uuid(); + $database->fields['dialplan_detail_tag'] = 'condition'; //condition, action, antiaction + $database->fields['dialplan_detail_type'] = 'destination_number'; + $database->fields['dialplan_detail_data'] = '^'.$ring_group_extension.'$'; + $database->fields['dialplan_detail_order'] = '000'; + $database->add(); - //save the xml - save_dialplan_xml(); + //add the dialplan details + $database->table = "v_dialplan_details"; + $database->fields['domain_uuid'] = $_SESSION['domain_uuid']; + $database->fields['dialplan_uuid'] = $dialplan_uuid; + $database->fields['dialplan_detail_uuid'] = uuid(); + $database->fields['dialplan_detail_tag'] = 'action'; //condition, action, antiaction + $database->fields['dialplan_detail_type'] = 'set'; + $database->fields['dialplan_detail_data'] = 'ring_group_uuid='.$ring_group_uuid; + $database->fields['dialplan_detail_order'] = '025'; + $database->add(); - //apply settings reminder - $_SESSION["reload_xml"] = true; - } - } + //add the dialplan details + $database->table = "v_dialplan_details"; + $database->fields['domain_uuid'] = $_SESSION['domain_uuid']; + $database->fields['dialplan_uuid'] = $dialplan_uuid; + $database->fields['dialplan_detail_uuid'] = uuid(); + $database->fields['dialplan_detail_tag'] = 'action'; //condition, action, antiaction + $database->fields['dialplan_detail_type'] = 'lua'; + $database->fields['dialplan_detail_data'] = 'app.lua ring_groups'; + $database->fields['dialplan_detail_order'] = '030'; + $database->add(); + + //save the xml + save_dialplan_xml(); + + //apply settings reminder + $_SESSION["reload_xml"] = true; //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:".$_SESSION["context"]."@".$_SESSION['domain_name']; + $switch_cmd = "memcache delete dialplan:".$ring_group_context; $switch_result = event_socket_request($fp, 'api '.$switch_cmd); } diff --git a/app/ring_groups/ring_group_forward.php b/app/ring_groups/ring_group_forward.php new file mode 100644 index 0000000000..31ea6e4193 --- /dev/null +++ b/app/ring_groups/ring_group_forward.php @@ -0,0 +1,171 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane + James Rose +*/ +require_once "root.php"; +require_once "resources/require.php"; +require_once "resources/check_auth.php"; +if (permission_exists('ring_group_view')) { + //access granted +} +else { + echo "access denied"; + exit; +} + +//add multi-lingual support + unset($text); + require_once "app/ring_groups/app_languages.php"; + foreach($text as $key => $value) { + $text[$key] = $value[$_SESSION['domain']['language']['code']]; + } + +require_once "resources/header.php"; +require_once "resources/paging.php"; + +//get variables used to control the order + $order_by = $_GET["order_by"]; + $order = $_GET["order"]; + +//show the content + echo "
"; + 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 "
".$text['title']." 
\n"; + //echo " ".$text['description']."

\n"; + //echo "
\n"; + + //prepare to page the results + $sql = "select count(*) as num_rows from v_ring_groups "; + $sql .= "where domain_uuid = '$domain_uuid' "; + if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } + $prep_statement = $db->prepare($sql); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + if ($row['num_rows'] > 0) { + $num_rows = $row['num_rows']; + } + else { + $num_rows = '0'; + } + } + + //prepare to page the results + $rows_per_page = 10; + $param = ""; + $page = $_GET['page']; + if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } + list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page); + $offset = $rows_per_page * $page; + + //get the list + $sql = " select * from v_ring_groups "; + $sql .= " where domain_uuid = '$domain_uuid' "; + if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; } + $sql .= " limit $rows_per_page offset $offset "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(); + $result_count = count($result); + unset ($prep_statement, $sql); + + $c = 0; + $row_style["0"] = "row_style0"; + $row_style["1"] = "row_style1"; + + echo "
\n"; + echo "\n"; + echo "\n"; + //echo th_order_by('ring_group_name', $text['label-name'], $order_by, $order); + echo th_order_by('ring_group_extension', $text['label-ring-group-extension'], $order_by, $order); + //echo th_order_by('ring_group_context', 'Context', $order_by, $order); + //echo th_order_by('ring_group_strategy', 'Strategy', $order_by, $order); + //echo th_order_by('ring_group_timeout_sec', 'Timeout', $order_by, $order); + //echo th_order_by('ring_group_timeout_app', 'Timeout App', $order_by, $order); + //echo th_order_by('ring_group_timeout_data', 'Timeout Data', $order_by, $order); + //echo th_order_by('ring_group_enabled', $text['label-enabled'], $order_by, $order); + echo ""; + echo th_order_by('ring_group_description', $text['label-description'], $order_by, $order); + echo "\n"; + + if ($result_count > 0) { + foreach($result as $row) { + echo "\n"; + //echo " \n"; + echo " \n"; + //echo " \n"; + //echo " \n"; + //echo " \n"; + //echo " \n"; + //echo " \n"; + //echo " \n"; + echo " \n"; + echo " \n"; + echo "\n"; + if ($c==0) { $c=1; } else { $c=0; } + } //end foreach + unset($sql, $result, $row_count); + } //end if results + + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
".$text['label-tools']."
".$row['ring_group_name']." ".$row['ring_group_extension']." ".$row['ring_group_context']." ".$row['ring_group_strategy']." ".$row['ring_group_timeout_sec']." ".$row['ring_group_timeout_app']." ".$row['ring_group_timeout_data']." ".$row['ring_group_enabled']." ".$text['label-call-forward']."".$row['ring_group_description']." 
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
 $paging_controls\n"; + echo "  
\n"; + echo "
"; + echo "
"; + echo "

"; + echo "

"; + + echo "
"; + echo "
"; + echo "

"; + +//include the footer + require_once "resources/footer.php"; +?> \ No newline at end of file diff --git a/app/ring_groups/ring_group_forward_edit.php b/app/ring_groups/ring_group_forward_edit.php new file mode 100644 index 0000000000..9146394199 --- /dev/null +++ b/app/ring_groups/ring_group_forward_edit.php @@ -0,0 +1,194 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ +require_once "root.php"; +require_once "resources/require.php"; +require_once "resources/check_auth.php"; + +//check permissions + if (permission_exists('ring_group_add') || permission_exists('ring_group_edit') || permission_exists('ring_call_forward')) { + //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']]; + } + +//show the header + require_once "resources/header.php"; + //$page["title"] = $text['title-ring_group_forward']; + +//get the hunt_group_uuid + $ring_group_uuid = check_str($_REQUEST["id"]); + +//process the HTTP post + if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { + //get http post variables and set them to php variables + if (count($_POST)>0) { + $ring_group_forward_enabled = check_str($_POST["ring_group_forward_enabled"]); + $ring_group_forward_destination = check_str($_POST["ring_group_forward_destination"]); + if (strlen($ring_group_forward_destination) > 0) { + $ring_group_forward_destination = preg_replace("~[^0-9]~", "",$ring_group_forward_destination); + } + } + + //check for all required data + //if (strlen($ring_group_forward_enabled) == 0) { $msg .= $text['message-required'].$text['label-call_forward']."
\n"; } + //if (strlen($ring_group_forward_destination) == 0) { $msg .= $text['message-required'].$text['label-number']."
\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; + } + + //update the ring group + $sql = "update v_ring_groups set "; + $sql .= "ring_group_forward_enabled = '$ring_group_forward_enabled', "; + $sql .= "ring_group_forward_destination = '$ring_group_forward_destination' "; + $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; + $sql .= "and ring_group_uuid = '$ring_group_uuid' "; + $db->exec(check_sql($sql)); + unset($sql); + + //redirect the user + require_once "resources/header.php"; + echo "\n"; + echo "
\n"; + echo $text['message-update']."
\n"; + echo "
\n"; + require_once "resources/footer.php"; + return; + } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) + +//pre-populate the form + if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { + $ring_group_uuid = $_GET["id"]; + $sql = "select * from v_ring_groups "; + $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; + $sql .= "and ring_group_uuid = '$ring_group_uuid' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(); + foreach ($result as &$row) { + $ring_group_name = $row["ring_group_name"]; + $ring_group_extension = $row["ring_group_extension"]; + $ring_group_forward_enabled = $row["ring_group_forward_enabled"]; + $ring_group_forward_destination = $row["ring_group_forward_destination"]; + $ring_group_description = $row["ring_group_description"]; + } + unset ($prep_statement); + } + +//show the content + echo "
"; + 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 "\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['header-ring-group-forward']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo " ".$text['description-ring-group-forward']." ".$ring_group_extension."

\n"; + echo "
\n"; + echo " ".$text['label-call-forward']."\n"; + echo "\n"; + if ($ring_group_forward_enabled == "true") { + echo " ".$text['option-enabled']." \n"; + } + else { + echo " ".$text['option-enabled']." \n"; + } + if ($ring_group_forward_enabled == "false" || $ring_group_forward_enabled == "") { + echo " ".$text['option-disabled']." \n"; + } + else { + echo " ".$text['option-disabled']." \n"; + } + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo " ".$text['label-forward_destination']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + echo " \n"; + echo " \n"; + echo "
"; + echo "
"; + + echo "
"; + echo "
"; + +//show the footer + require_once "resources/footer.php"; +?> \ No newline at end of file