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.

This commit is contained in:
Mark Crane 2013-08-15 19:16:03 +00:00
parent 87841bdce2
commit c05bcaaec1
5 changed files with 458 additions and 64 deletions

View File

@ -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'] = '';
?>

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -0,0 +1,171 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2012
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
James Rose <james.o.rose@gmail.com>
*/
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 "<div align='center'>";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
echo "<tr class='border'>\n";
echo " <td align=\"center\">\n";
echo " <br />";
//echo "<table width='100%' border='0'>\n";
//echo " <tr>\n";
//echo " <td width='50%' align='left' nowrap='nowrap'><b>".$text['title']."</b></td>\n";
//echo " <td width='50%' align='right'>&nbsp;</td>\n";
//echo " </tr>\n";
//echo " <tr>\n";
//echo " <td align='left' colspan='2'>\n";
//echo " ".$text['description']."<br /><br />\n";
//echo " </td>\n";
//echo " </tr>\n";
//echo "</table>\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 "<div align='center'>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\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 "<th>".$text['label-tools']."</th>";
echo th_order_by('ring_group_description', $text['label-description'], $order_by, $order);
echo "<tr>\n";
if ($result_count > 0) {
foreach($result as $row) {
echo "<tr >\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['ring_group_name']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$row['ring_group_extension']."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['ring_group_context']."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['ring_group_strategy']."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['ring_group_timeout_sec']."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['ring_group_timeout_app']."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['ring_group_timeout_data']."&nbsp;</td>\n";
//echo " <td valign='top' class='".$row_style[$c]."'>".$row['ring_group_enabled']."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'><a href='/app/ring_groups/ring_group_forward_edit.php?id=".$row['ring_group_uuid']."' alt='".$text['label-call-forward']."'>".$text['label-call-forward']."</a></td>\n";
echo " <td valign='top' class='row_stylebg'>".$row['ring_group_description']."&nbsp;</td>\n";
echo "</tr>\n";
if ($c==0) { $c=1; } else { $c=0; }
} //end foreach
unset($sql, $result, $row_count);
} //end if results
echo "<tr>\n";
echo "<td colspan='11' align='left'>\n";
echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td width='33.3%' nowrap>&nbsp;</td>\n";
echo " <td width='33.3%' align='center' nowrap>$paging_controls</td>\n";
echo " <td width='33.3%' align='right'>\n";
echo " <td width='33.3%' nowrap>&nbsp;</td>\n";
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>";
echo "</div>";
echo "<br /><br />";
echo "<br /><br />";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</div>";
echo "<br /><br />";
//include the footer
require_once "resources/footer.php";
?>

View File

@ -0,0 +1,194 @@
<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2012
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
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']."<br>\n"; }
//if (strlen($ring_group_forward_destination) == 0) { $msg .= $text['message-required'].$text['label-number']."<br>\n"; }
if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
require_once "resources/header.php";
require_once "resources/persist_form_var.php";
echo "<div align='center'>\n";
echo "<table><tr><td>\n";
echo $msg."<br />";
echo "</td></tr></table>\n";
persistformvar($_POST);
echo "</div>\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 "<meta http-equiv=\"refresh\" content=\"3;url=".PROJECT_PATH."/app/ring_groups/ring_group_forward.php\">\n";
echo "<div align='center'>\n";
echo $text['message-update']."<br />\n";
echo "</div>\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 "<div align='center'>";
echo "<table width='100%' border='0' cellpadding='0' cellspacing=''>\n";
echo "<tr class='border'>\n";
echo " <td align=\"center\">\n";
echo " <br>";
echo "<form method='post' name='frm' action=''>\n";
echo "<table width='100%' border='0' cellpadding='6' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td align='left' width='30%' nowrap>\n";
echo " <b>".$text['header-ring-group-forward']."</b>\n";
echo "</td>\n";
echo "<td width='70%' align='right'>\n";
echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='ring_group_forward.php'\" value='".$text['button-back']."'>\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td colspan='2'>\n";
echo " ".$text['description-ring-group-forward']." ".$ring_group_extension."<br /><br />\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap>\n";
echo " <strong>".$text['label-call-forward']."</strong>\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
if ($ring_group_forward_enabled == "true") {
echo " <input type='radio' name='ring_group_forward_enabled' value='true' checked='checked'/> ".$text['option-enabled']." \n";
}
else {
echo " <input type='radio' name='ring_group_forward_enabled' value='true' /> ".$text['option-enabled']." \n";
}
if ($ring_group_forward_enabled == "false" || $ring_group_forward_enabled == "") {
echo " <input type='radio' name='ring_group_forward_enabled' value='false' checked='checked' /> ".$text['option-disabled']." \n";
}
else {
echo " <input type='radio' name='ring_group_forward_enabled' value='false' /> ".$text['option-disabled']." \n";
}
echo "<br />\n";
echo "<br />\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap>\n";
echo " ".$text['label-forward_destination']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='ring_group_forward_destination' maxlength='255' value=\"$ring_group_forward_destination\">\n";
echo "<br />\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td colspan='2'>\n";
echo " <br />\n";
echo "</td>\n";
echo "</tr>\n";
echo " <tr>\n";
echo " <td colspan='2' align='right'>\n";
echo " <input type='hidden' name='id' value='$ring_group_uuid'>\n";
echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
echo " </td>\n";
echo " </tr>";
echo "</table>";
echo "</form>";
echo " </td>";
echo " </tr>";
echo "</table>";
echo "</div>";
//show the footer
require_once "resources/footer.php";
?>