123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493 |
- <?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 <[email protected]>
- Portions created by the Initial Developer are Copyright (C) 2008-2012
- the Initial Developer. All Rights Reserved.
- Contributor(s):
- Mark J Crane <[email protected]>
- */
- require_once "root.php";
- require_once "resources/require.php";
- require_once "resources/check_auth.php";
- //check permissions
- if (permission_exists('hunt_group_add') || permission_exists('hunt_group_edit') || permission_exists('hunt_group_call_forward')) {
- //access granted
- }
- else {
- echo "access denied";
- exit;
- }
- //add multi-lingual support
- $language = new text;
- $text = $language->get();
- function destination_select($select_name, $select_value, $select_default) {
- if (strlen($select_value) == 0) { $select_value = $select_default; }
- echo " <select class='formfld' style='width: 40px;' name='$select_name'>\n";
- echo " <option value=''></option>\n";
- $i=5;
- while($i<=100) {
- if ($select_value == $i) {
- echo " <option value='$i' selected='selected'>$i</option>\n";
- }
- else {
- echo " <option value='$i'>$i</option>\n";
- }
- $i=$i+5;
- }
- echo "</select>\n";
- }
- //show the header
- require_once "resources/header.php";
- $page["title"] = $text['title-hunt-group_call_forward'];
- //get the hunt_group_uuid
- $hunt_group_uuid = $_REQUEST["id"];
- //hunt_group information used to determine if this is an add or an update
- $sql = "select * from v_hunt_groups ";
- $sql .= "where domain_uuid = '$domain_uuid' ";
- $sql .= "and hunt_group_uuid = '$hunt_group_uuid' ";
- if (!(permission_exists('hunt_group_add') || permission_exists('hunt_group_edit'))) {
- $sql .= "and hunt_group_user_list like '%|".$_SESSION["username"]."|%' ";
- }
- $prep_statement = $db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- foreach ($result as &$row) {
- $hunt_group_uuid = $row["hunt_group_uuid"];
- $hunt_group_extension = $row["hunt_group_extension"];
- }
- unset ($prep_statement);
- if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
- //get http post variables and set them to php variables
- if (count($_POST)>0) {
- $call_forward_enabled = check_str($_POST["call_forward_enabled"]);
- $call_forward_number = check_str($_POST["call_forward_number"]);
- $hunt_group_call_prompt = check_str($_POST["hunt_group_call_prompt"]);
- if (strlen($call_forward_number) > 0) {
- $call_forward_number = preg_replace("~[^0-9]~", "",$call_forward_number);
- }
- //set the default
- if (strlen($hunt_group_call_prompt) == 0) {
- $hunt_group_call_prompt = 'false';
- }
- }
- //check for all required data
- //if (strlen($call_forward_enabled) == 0) { $msg .= $text['message-required'].$text['label-call_forward']."<br>\n"; }
- //if (strlen($call_forward_number) == 0) { $msg .= $text['message-required'].$text['label-number']."<br>\n"; }
- //if (strlen($hunt_group_call_prompt) == 0) { $msg .= $text['message-required'].$text['label-call_prompt']."<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;
- }
- //call forward is enabled so disable the hunt group
- if ($call_forward_enabled == "true") {
- $sql = "update v_hunt_groups set hunt_group_enabled = 'false' ";
- $sql .= "where hunt_group_extension = '$hunt_group_extension' ";
- $sql .= "and (hunt_group_type = 'simultaneous' or hunt_group_type = 'sequentially') ";
- $db->exec(check_sql($sql));
- }
- //call forward is disabled so enable the hunt group
- if ($call_forward_enabled == "false" || $call_forward_enabled == "") {
- $sql = "update v_hunt_groups set hunt_group_enabled = 'true' ";
- $sql .= "where hunt_group_extension = '$hunt_group_extension' ";
- $sql .= "and (hunt_group_type = 'simultaneous' or hunt_group_type = 'sequentially') ";
- $db->exec(check_sql($sql));
- }
- //set the default action to add
- $call_forward_action = "add";
- //hunt_group information used to determine if this is an add or an update
- $sql = "select * from v_hunt_groups ";
- $sql .= "where domain_uuid = '$domain_uuid' ";
- $sql .= "and hunt_group_type = 'call_forward' ";
- $sql .= "and hunt_group_extension in ( ";
- $sql .= "select hunt_group_extension from v_hunt_groups ";
- $sql .= "where domain_uuid = '$domain_uuid' ";
- $sql .= "and hunt_group_uuid = '$hunt_group_uuid' ";
- if (!(permission_exists('hunt_group_add') || permission_exists('hunt_group_edit'))) {
- $sql .= "and hunt_group_user_list like '%|".$_SESSION["username"]."|%' ";
- }
- $sql .= ") ";
- $prep_statement = $db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- foreach ($result as &$row) {
- if ($row["hunt_group_type"] == 'call_forward') {
- $call_forward_action = "update";
- $call_forward_uuid = $row["hunt_group_uuid"];
- }
- }
- unset ($prep_statement);
- //call forward config
- $huntgroup_name = 'call_forward_'.$hunt_group_extension;
- $hunt_group_type = 'call_forward';
- $hunt_group_context = $_SESSION['context'];
- $hunt_group_timeout = '3600';
- $hunt_group_timeout_destination = $hunt_group_extension;
- $hunt_group_timeout_type = 'voicemail';
- $hunt_group_ring_back = 'us-ring';
- $hunt_group_cid_name_prefix = '';
- $hunt_group_pin = '';
- $huntgroup_caller_announce = 'false';
- $hunt_group_user_list = '';
- $hunt_group_enabled = $call_forward_enabled;
- $hunt_group_description = 'call forward '.$hunt_group_extension;
- if ($call_forward_action == "add" && permission_exists('hunt_group_add')) {
- $call_forward_uuid = uuid();
- $sql = "insert into v_hunt_groups ";
- $sql .= "(";
- $sql .= "domain_uuid, ";
- $sql .= "hunt_group_uuid, ";
- $sql .= "hunt_group_extension, ";
- $sql .= "hunt_group_name, ";
- $sql .= "hunt_group_type, ";
- $sql .= "hunt_group_context, ";
- $sql .= "hunt_group_timeout, ";
- $sql .= "hunt_group_timeout_destination, ";
- $sql .= "hunt_group_timeout_type, ";
- $sql .= "hunt_group_ringback, ";
- $sql .= "hunt_group_cid_name_prefix, ";
- $sql .= "hunt_group_pin, ";
- $sql .= "hunt_group_call_prompt, ";
- $sql .= "hunt_group_caller_announce, ";
- $sql .= "hunt_group_user_list, ";
- $sql .= "hunt_group_enabled, ";
- $sql .= "hunt_group_description ";
- $sql .= ")";
- $sql .= "values ";
- $sql .= "(";
- $sql .= "'$domain_uuid', ";
- $sql .= "'$call_forward_uuid', ";
- $sql .= "'$hunt_group_extension', ";
- $sql .= "'$huntgroup_name', ";
- $sql .= "'$hunt_group_type', ";
- $sql .= "'$hunt_group_context', ";
- $sql .= "'$hunt_group_timeout', ";
- $sql .= "'$hunt_group_timeout_destination', ";
- $sql .= "'$hunt_group_timeout_type', ";
- $sql .= "'$hunt_group_ring_back', ";
- $sql .= "'$hunt_group_cid_name_prefix', ";
- $sql .= "'$hunt_group_pin', ";
- $sql .= "'$hunt_group_call_prompt', ";
- $sql .= "'$huntgroup_caller_announce', ";
- $sql .= "'$hunt_group_user_list', ";
- $sql .= "'$hunt_group_enabled', ";
- $sql .= "'$hunt_group_description' ";
- $sql .= ")";
- if ($v_debug) {
- echo $sql."<br />";
- }
- $db->exec(check_sql($sql));
- unset($sql);
- //delete related v_hunt_group_destinations
- $sql = "delete from v_hunt_group_destinations where hunt_group_uuid = '$call_forward_uuid' ";
- $db->exec(check_sql($sql));
- if (extension_exists($call_forward_number)) {
- $destination_data = $call_forward_number;
- $destination_type = 'extension';
- }
- $destination_profile = 'internal';
- $destination_timeout = '';
- $destination_order = '1';
- $destination_enabled = 'true';
- $destination_description = 'call forward';
- $hunt_group_destination_uuid = uuid();
- $sql = "insert into v_hunt_group_destinations ";
- $sql .= "(";
- $sql .= "domain_uuid, ";
- $sql .= "hunt_group_uuid, ";
- $sql .= "hunt_group_destination_uuid, ";
- $sql .= "destination_data, ";
- $sql .= "destination_type, ";
- $sql .= "destination_profile, ";
- $sql .= "destination_timeout, ";
- $sql .= "destination_order, ";
- $sql .= "destination_enabled, ";
- $sql .= "destination_description ";
- $sql .= ")";
- $sql .= "values ";
- $sql .= "(";
- $sql .= "'$domain_uuid', ";
- $sql .= "'$call_forward_uuid', ";
- $sql .= "'$hunt_group_destination_uuid', ";
- $sql .= "'$destination_data', ";
- $sql .= "'$destination_type', ";
- $sql .= "'$destination_profile', ";
- $sql .= "'$destination_timeout', ";
- $sql .= "'$destination_order', ";
- $sql .= "'$destination_enabled', ";
- $sql .= "'$destination_description' ";
- $sql .= ")";
- $db->exec(check_sql($sql));
- unset($sql);
- } //if ($call_forward_action == "add")
- if ($call_forward_action == "update" && permission_exists('hunt_group_call_forward')) {
- $sql = "update v_hunt_groups set ";
- $sql .= "hunt_group_extension = '$hunt_group_extension', ";
- $sql .= "hunt_group_name = '$huntgroup_name', ";
- $sql .= "hunt_group_type = '$hunt_group_type', ";
- $sql .= "hunt_group_context = '$hunt_group_context', ";
- $sql .= "hunt_group_timeout = '$hunt_group_timeout', ";
- $sql .= "hunt_group_timeout_destination = '$hunt_group_timeout_destination', ";
- $sql .= "hunt_group_timeout_type = '$hunt_group_timeout_type', ";
- $sql .= "hunt_group_ringback = '$hunt_group_ring_back', ";
- $sql .= "hunt_group_cid_name_prefix = '$hunt_group_cid_name_prefix', ";
- $sql .= "hunt_group_pin = '$hunt_group_pin', ";
- $sql .= "hunt_group_call_prompt = '$hunt_group_call_prompt', ";
- $sql .= "hunt_group_caller_announce = '$huntgroup_caller_announce', ";
- $sql .= "hunt_group_user_list = '$hunt_group_user_list', ";
- $sql .= "hunt_group_enabled = '$hunt_group_enabled', ";
- $sql .= "hunt_group_description = '$hunt_group_description' ";
- $sql .= "where domain_uuid = '$domain_uuid' ";
- $sql .= "and hunt_group_uuid = '$call_forward_uuid'";
- $db->exec(check_sql($sql));
- unset($sql);
- //set the variables
- $destination_data = $call_forward_number;
- if (extension_exists($call_forward_number)) {
- $destination_type = 'extension';
- }
- else {
- $destination_type = 'sip uri';
- }
- $destination_profile = 'internal';
- $destination_timeout = '';
- $destination_order = '1';
- $destination_enabled = 'true';
- $destination_description = 'call forward';
- //delete related v_hunt_group_destinations
- $sql = "delete from v_hunt_group_destinations where hunt_group_uuid = '$call_forward_uuid' ";
- $db->exec(check_sql($sql));
- //insert the v_hunt_group_destinations
- $hunt_group_destination_uuid = uuid();
- $sql = "insert into v_hunt_group_destinations ";
- $sql .= "(";
- $sql .= "hunt_group_destination_uuid, ";
- $sql .= "domain_uuid, ";
- $sql .= "hunt_group_uuid, ";
- $sql .= "destination_data, ";
- $sql .= "destination_type, ";
- $sql .= "destination_profile, ";
- $sql .= "destination_timeout, ";
- $sql .= "destination_order, ";
- $sql .= "destination_enabled, ";
- $sql .= "destination_description ";
- $sql .= ")";
- $sql .= "values ";
- $sql .= "(";
- $sql .= "'$hunt_group_destination_uuid', ";
- $sql .= "'$domain_uuid', ";
- $sql .= "'$call_forward_uuid', ";
- $sql .= "'$destination_data', ";
- $sql .= "'$destination_type', ";
- $sql .= "'$destination_profile', ";
- $sql .= "'$destination_timeout', ";
- $sql .= "'$destination_order', ";
- $sql .= "'$destination_enabled', ";
- $sql .= "'$destination_description' ";
- $sql .= ")";
- $db->exec(check_sql($sql));
- unset($sql);
- } //if ($call_forward_action == "update")
- //synchronize the xml config
- save_hunt_group_xml();
- //synchronize the xml config
- save_dialplan_xml();
- //redirect the user
- require_once "resources/header.php";
- echo "<meta http-equiv=\"refresh\" content=\"3;url=".PROJECT_PATH."/app/hunt_group/hunt_group_call_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
- $sql = "select * from v_hunt_groups ";
- $sql .= "where domain_uuid = '$domain_uuid' ";
- $sql .= "and hunt_group_type = 'call_forward' ";
- $sql .= "and hunt_group_extension = '$hunt_group_extension' ";
- $prep_statement = $db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
- foreach ($result as &$row) {
- $hunt_group_uuid = $row["hunt_group_uuid"];
- $hunt_group_extension = $row["hunt_group_extension"];
- $huntgroup_name = $row["hunt_group_name"];
- $hunt_group_type = $row["hunt_group_type"];
- $hunt_group_context = $row["hunt_group_context"];
- $hunt_group_timeout = $row["hunt_group_timeout"];
- $hunt_group_timeout_destination = $row["hunt_group_timeout_destination"];
- $hunt_group_timeout_type = $row["hunt_group_timeout_type"];
- $hunt_group_ring_back = $row["hunt_group_ringback"];
- $hunt_group_cid_name_prefix = $row["hunt_group_cid_name_prefix"];
- $hunt_group_pin = $row["hunt_group_pin"];
- $hunt_group_call_prompt = $row["hunt_group_call_prompt"];
- $huntgroup_caller_announce = $row["hunt_group_caller_announce"];
- $hunt_group_user_list = $row["hunt_group_user_list"];
- $hunt_group_enabled = $row["hunt_group_enabled"];
- $hunt_group_description = $row["hunt_group_description"];
- if ($row["hunt_group_type"] == 'call_forward') {
- $call_forward_enabled = $hunt_group_enabled;
- }
- if ($row["hunt_group_type"] == 'call_forward') {
- $sql = "select * from v_hunt_group_destinations ";
- $sql .= "where hunt_group_uuid = '$hunt_group_uuid' ";
- $prep_statement_2 = $db->prepare(check_sql($sql));
- $prep_statement_2->execute();
- $result2 = $prep_statement_2->fetchAll(PDO::FETCH_NAMED);
- $x=1;
- foreach ($result2 as &$row2) {
- if ($row["hunt_group_type"] == 'call_forward') {
- if (strlen($row2["destination_data"]) > 0) {
- $call_forward_number = $row2["destination_data"];
- }
- }
- }
- unset ($prep_statement_2);
- }
- }
- 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-hunt-group_call_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='hunt_group_call_forward.php'\" value='".$text['button-back']."'>\n";
- echo "</td>\n";
- echo "</tr>\n";
- echo "<tr>\n";
- echo "<td colspan='2'>\n";
- echo " ".$text['description-hunt_group_call_forward_edit']." ".$hunt_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 ($call_forward_enabled == "true") {
- echo " <input type='radio' name='call_forward_enabled' value='true' checked='checked'/> ".$text['option-enabled']." \n";
- }
- else {
- echo " <input type='radio' name='call_forward_enabled' value='true' /> ".$text['option-enabled']." \n";
- }
- if ($call_forward_enabled == "false" || $call_forward_enabled == "") {
- echo " <input type='radio' name='call_forward_enabled' value='false' checked='checked' /> ".$text['option-disabled']." \n";
- }
- else {
- echo " <input type='radio' name='call_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-number'].":\n";
- echo "</td>\n";
- echo "<td class='vtable' align='left'>\n";
- echo " <input class='formfld' type='text' name='call_forward_number' maxlength='255' value=\"$call_forward_number\">\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'>\n";
- echo " <br />\n";
- echo "</td>\n";
- echo "</tr>\n";
- echo " <tr>\n";
- echo " <td colspan='2' align='right'>\n";
- if ($action == "update") {
- echo " <input type='hidden' name='id' value='$call_forward_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";
- ?>
|