Portions created by the Initial Developer are Copyright (C) 2008-2012 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ include "root.php"; require_once "includes/require.php"; require_once "includes/checkauth.php"; require_once "includes/paging.php"; //check permissions if (permission_exists('hunt_group_add') || permission_exists('hunt_group_edit')) { //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']]; } //action add or update if (isset($_REQUEST["id"])) { $action = "update"; $hunt_group_uuid = check_str($_REQUEST["id"]); $dialplan_uuid = check_str($_REQUEST["dialplan_uuid"]); } else { $action = "add"; } //get the http values and set them as variables if (count($_POST)>0) { $hunt_group_extension = check_str($_POST["hunt_group_extension"]); $hunt_group_name = check_str($_POST["hunt_group_name"]); $hunt_group_type = check_str($_POST["hunt_group_type"]); $hunt_group_timeout = check_str($_POST["hunt_group_timeout"]); $hunt_group_timeout_destination = check_str($_POST["hunt_group_timeout_destination"]); $hunt_group_timeout_type = check_str($_POST["hunt_group_timeout_type"]); $hunt_group_ringback = check_str($_POST["hunt_group_ringback"]); $hunt_group_cid_name_prefix = check_str($_POST["hunt_group_cid_name_prefix"]); $hunt_group_pin = check_str($_POST["hunt_group_pin"]); $hunt_group_caller_announce = check_str($_POST["hunt_group_caller_announce"]); //prepare the user list for the database $hunt_group_user_list = $_POST["hunt_group_user_list"]; if (strlen($hunt_group_user_list) > 0) { $hunt_group_user_list_array = explode("\n", $hunt_group_user_list); if (count($hunt_group_user_list_array) == 0) { $hunt_group_user_list = ''; } else { $hunt_group_user_list = '|'; foreach($hunt_group_user_list_array as $user){ if(strlen(trim($user)) > 0) { $hunt_group_user_list .= check_str(trim($user))."|"; } } } } $hunt_group_enabled = check_str($_POST["hunt_group_enabled"]); $hunt_group_description = check_str($_POST["hunt_group_description"]); //remove invalid characters $hunt_group_cid_name_prefix = str_replace(":", "-", $hunt_group_cid_name_prefix); $hunt_group_cid_name_prefix = str_replace("\"", "", $hunt_group_cid_name_prefix); $hunt_group_cid_name_prefix = str_replace("@", "", $hunt_group_cid_name_prefix); $hunt_group_cid_name_prefix = str_replace("\\", "", $hunt_group_cid_name_prefix); $hunt_group_cid_name_prefix = str_replace("/", "", $hunt_group_cid_name_prefix); //set default if (strlen($hunt_group_caller_announce) == 0) { $hunt_group_caller_announce = "false"; } } if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $msg = ''; if ($action == "update") { $hunt_group_uuid = check_str($_POST["hunt_group_uuid"]); } //check for all required data if (strlen($domain_uuid) == 0) { $msg .= $text['message-required']."domain_uuid
\n"; } if (strlen($hunt_group_extension) == 0) { $msg .= $text['message-required'].$text['label-extension']."
\n"; } if (strlen($hunt_group_name) == 0) { $msg .= $text['message-required'].$text['label-name']."
\n"; } if (strlen($hunt_group_type) == 0) { $msg .= $text['message-required'].$text['label-strategy']."
\n"; } if (strlen($hunt_group_timeout) == 0) { $msg .= $text['message-required'].$text['label-timeout']."
\n"; } if (strlen($hunt_group_timeout_destination) == 0) { $msg .= $text['message-required'].$text['label-timeout_destination']."
\n"; } if (strlen($hunt_group_timeout_type) == 0) { $msg .= $text['message-required'].$text['label-timeout_type']."
\n"; } //if (strlen($hunt_group_ringback) == 0) { $msg .= $text['message-required'].$text['label-ring_back']."
\n"; } //if (strlen($hunt_group_cid_name_prefix) == 0) { $msg .= $text['message-required'].$text['label-caller_id_name_prefix']."
\n"; } //if (strlen($hunt_group_pin) == 0) { $msg .= $text['message-required'].$text['label-pin_number']."
\n"; } if (strlen($hunt_group_caller_announce) == 0) { $msg .= $text['message-required'].$text['label-caller_announce']."
\n"; } //if (strlen($hunt_group_user_list) == 0) { $msg .= $text['message-required'].$text['label-user_list']."
\n"; } //if (strlen($hunt_group_enabled) == 0) { $msg .= $text['message-required'].$text['label-enabled']."
\n"; } //if (strlen($hunt_group_description) == 0) { $msg .= $text['message-required'].$text['label-description']."
\n"; } if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { require_once "includes/header.php"; require_once "includes/persistformvar.php"; echo "
\n"; echo "
\n"; echo $msg."
"; echo "
\n"; persistformvar($_POST); echo "
\n"; require_once "includes/footer.php"; return; } //add or update the database if ($_POST["persistformvar"] != "true") { if ($action == "add" && permission_exists('hunt_group_add')) { //add to the table $dialplan_uuid = uuid(); $hunt_group_uuid = uuid(); $sql = "insert into v_hunt_groups "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "dialplan_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_caller_announce, "; $sql .= "hunt_group_user_list, "; $sql .= "hunt_group_enabled, "; $sql .= "hunt_group_description "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'$domain_uuid', "; $sql .= "'$dialplan_uuid', "; $sql .= "'$hunt_group_uuid', "; $sql .= "'$hunt_group_extension', "; $sql .= "'$hunt_group_name', "; $sql .= "'$hunt_group_type', "; $sql .= "'".$_SESSION['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_caller_announce', "; $sql .= "'$hunt_group_user_list', "; $sql .= "'$hunt_group_enabled', "; $sql .= "'$hunt_group_description' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); //synchronize the xml config save_hunt_group_xml(); //redirect the user require_once "includes/header.php"; echo "\n"; echo "
\n"; echo $text['message-add']."\n"; echo "
\n"; require_once "includes/footer.php"; return; } //if ($action == "add") if ($action == "update" && permission_exists('hunt_group_edit')) { //update the table $sql = "update v_hunt_groups set "; $sql .= "hunt_group_extension = '$hunt_group_extension', "; $sql .= "hunt_group_name = '$hunt_group_name', "; $sql .= "hunt_group_type = '$hunt_group_type', "; $sql .= "hunt_group_context = '".$_SESSION['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_ringback', "; $sql .= "hunt_group_cid_name_prefix = '$hunt_group_cid_name_prefix', "; $sql .= "hunt_group_pin = '$hunt_group_pin', "; $sql .= "hunt_group_caller_announce = '$hunt_group_caller_announce', "; if (if_group("admin") || if_group("superadmin")) { $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 = '".$_SESSION['domain_uuid']."' "; $sql .= "and hunt_group_uuid = '$hunt_group_uuid'"; $db->exec(check_sql($sql)); unset($sql); //update the dialplan entry require_once "includes/classes/switch_dialplan.php"; $dialplan = new dialplan; $dialplan->domain_uuid = $_SESSION['domain_uuid']; $dialplan->app_uuid = $app_uuid; $dialplan->dialplan_uuid = $dialplan_uuid; $dialplan->dialplan_name = $hunt_group_name; //$dialplan->dialplan_continue = $dialplan_continue; //$dialplan->dialplan_order = '330'; $dialplan->dialplan_context = $_SESSION['context']; $dialplan->dialplan_enabled = $hunt_group_enabled; $dialplan->dialplan_description = $hunt_group_description; $dialplan->dialplan_update(); unset($dialplan); //update the condition $sql = "update v_dialplan_details set "; $sql .= "dialplan_detail_data = '^".$hunt_group_extension."$' "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and dialplan_detail_tag = 'condition' "; $sql .= "and dialplan_detail_type = 'destination_number' "; $sql .= "and dialplan_uuid = '$dialplan_uuid' "; $sql .= "and dialplan_detail_group = '1' "; $db->query($sql); unset($sql); //update the action $sql = "update v_dialplan_details set "; $sql .= "dialplan_detail_data = 'v_huntgroup_".$_SESSION['domain_name']."_".$hunt_group_extension.".lua', "; $sql .= "dialplan_detail_type = 'lua' "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and dialplan_detail_tag = 'action' "; $sql .= "and dialplan_uuid = '$dialplan_uuid' "; $sql .= "and dialplan_detail_type = 'lua' "; $sql .= "and dialplan_detail_group = '1' "; $db->query($sql); //synchronize the xml config save_hunt_group_xml(); //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_result = event_socket_request($fp, 'api '.$switch_cmd); } //rediret the user require_once "includes/header.php"; echo "\n"; echo "
\n"; echo $text['message-update']."\n"; echo "
\n"; require_once "includes/footer.php"; return; } //if ($action == "update") } //if ($_POST["persistformvar"] != "true") } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) //pre-populate the form if (count($_GET)>0 && $_POST["persistformvar"] != "true") { $hunt_group_uuid = $_GET["id"]; $sql = "select * from v_hunt_groups "; $sql .= "where hunt_group_uuid = '$hunt_group_uuid' "; $sql .= "and domain_uuid = '$domain_uuid' "; $sql .- "hunt_group_enabled = 'true' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { $dialplan_uuid = $row["dialplan_uuid"]; $hunt_group_extension = $row["hunt_group_extension"]; $hunt_group_name = $row["hunt_group_name"]; $hunt_group_type = $row["hunt_group_type"]; $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_ringback = $row["hunt_group_ringback"]; $hunt_group_cid_name_prefix = $row["hunt_group_cid_name_prefix"]; $hunt_group_pin = $row["hunt_group_pin"]; $hunt_group_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"]; break; //limit to 1 row } unset ($prep_statement); } //show the header require_once "includes/header.php"; $page["title"] = $text['title-hunt_group']; //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 "\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"; if (!$fp) { $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); } if (switch_module_is_running($fp, 'mod_spidermonkey')) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if (if_group("admin") || if_group("superadmin")) { 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 "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; echo " \n"; echo " ".$text['header-hunt_group']."
\n"; echo "
\n"; echo "
\n"; if ($action != "add") { echo " \n"; } echo " \n"; echo "
\n"; echo " ".$text['description-hunt_group']."\n"; echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; echo " ".$text['label-name'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-name']."\n"; echo "
\n"; echo " ".$text['label-extension'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-extension']."\n"; echo "
\n"; echo " ".$text['label-strategy'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo "\n"; echo "
\n"; echo " ".$text['label-timeout'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-timeout']."\n"; echo "
\n"; echo " ".$text['label-timeout_destination'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-timeout_destination']."\n"; echo "
\n"; echo " ".$text['label-timeout_type'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-timeout_type']."\n"; echo "
\n"; echo " ".$text['label-ring_back'].":\n"; echo "\n"; $select_options = ""; if ($hunt_group_ringback == "\${us-ring}" || $hunt_group_ringback == "us-ring") { $select_options .= " \n"; } else { $select_options .= " \n"; } if ($hunt_group_ringback == "\${fr-ring}" || $hunt_group_ringback == "fr-ring") { $select_options .= " \n"; } else { $select_options .= " \n"; } if ($hunt_group_ringback == "\${uk-ring}" || $hunt_group_ringback == "uk-ring") { $select_options .= " \n"; } else { $select_options .= " \n"; } if ($hunt_group_ringback == "\${rs-ring}" || $hunt_group_ringback == "rs-ring") { $select_options .= " \n"; } else { $select_options .= " \n"; } require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php"; $moh = new switch_music_on_hold; $moh->select_name = "hunt_group_ringback"; $moh->select_value = $hunt_group_ringback; $moh->select_options = $select_options; echo $moh->select(); echo "
\n"; echo $text['description-ring_back']."\n"; echo "
\n"; echo " ".$text['label-caller_id_name_prefix'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-caller_id_name_prefix']."\n"; echo "
\n"; echo " ".$text['label-pin_number'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-pin_number']."\n"; echo "
\n"; echo " ".$text['label-caller_announce'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo "\n"; echo "
\n"; echo " ".$text['label-user_list'].":\n"; echo "\n"; $onchange = "document.getElementById('hunt_group_user_list').value += document.getElementById('username').value + '\\n';"; $table_name = 'v_users'; $field_name = 'username'; $field_current_value = ''; $sql_where_optional = "where domain_uuid = '$domain_uuid' and user_enabled = 'true' "; echo html_select_on_change($db, $table_name, $field_name, $sql_where_optional, $field_current_value, $onchange); echo "
\n"; echo $text['description-user_list_select']."\n"; echo "
\n"; echo "
\n"; //replace the vertical bar with a line feed to display in the textarea $hunt_group_user_list = trim($hunt_group_user_list, "|"); $hunt_group_user_list_array = explode("|", $hunt_group_user_list); $hunt_group_user_list = ''; foreach($hunt_group_user_list_array as $user){ $hunt_group_user_list .= trim($user)."\n"; } echo " \n"; echo "
\n"; echo $text['description-user_list_textarea']."\n"; echo "
\n"; echo "
\n"; echo " ".$text['label-enabled'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-enabled']."\n"; echo "
\n"; echo " ".$text['label-description'].":\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 ""; echo "
"; echo "
"; //list hunt group destinations if ($action == "update") { echo "
"; echo "\n"; echo "\n"; echo " "; echo ""; echo "
\n"; echo "
"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo "

\n"; echo " ".$text['header-hunt_group_destinations']."
\n"; echo " ".$text['description-hunt_group_destinations']."\n"; echo "

\n"; echo "
\n"; $sql = " select * from v_hunt_group_destinations "; $sql .= " where domain_uuid = '$domain_uuid' "; $sql .= " and hunt_group_uuid = '$hunt_group_uuid' "; $sql .= " order by destination_order, destination_data asc"; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $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 "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; 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"; 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-destination']."".$text['label-type']."".$text['label-profile']."".$text['label-order']."".$text['label-description']."\n"; if (permission_exists('hunt_group_add')) { echo " $v_link_label_add\n"; } echo "
  ".$row['destination_data']."  "; switch($row['destination_type']) { case "extension" : echo $text['option-extension']; break; case "voicemail" : echo $text['option-voicemail']; break; case "sip uri" : echo $text['option-sip_uri']; break; } echo "  ".$row['destination_profile']."  ".$row['destination_order']."".$row['destination_description']." \n"; if (permission_exists('hunt_group_edit')) { echo " $v_link_label_edit\n"; } if (permission_exists('hunt_group_delete')) { echo " $v_link_label_delete\n"; } echo "
\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
 $paging_controls\n"; if (permission_exists('hunt_group_add')) { echo " $v_link_label_add\n"; } echo "
\n"; echo "
"; echo "
"; echo "

"; echo "

"; echo "
"; echo "
"; echo "

"; } //end if update //show the footer require_once "includes/footer.php"; ?>