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 "includes/require.php"; require_once "includes/checkauth.php"; if (if_group("admin") || if_group("superadmin")) { //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']]; } //delete the user from the v_extension_users if ($_GET["a"] == "delete" && permission_exists("user_delete")) { //set the variables $ring_group_extension_uuid = check_str($_REQUEST["id"]); $ring_group_uuid = check_str($_REQUEST["ring_group_uuid"]); //delete the extension from the ring_group $sql = "delete from v_ring_group_extensions "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and ring_group_extension_uuid = '$ring_group_extension_uuid' "; $db->exec(check_sql($sql)); unset($sql); //redirect the browser require_once "includes/header.php"; echo "\n"; echo "
Delete Complete
"; require_once "includes/footer.php"; return; } //action add or update if (isset($_REQUEST["id"])) { $action = "update"; $ring_group_uuid = check_str($_REQUEST["id"]); } else { $action = "add"; } //get http post variables and set them to php variables if (count($_POST)>0) { //set variables from http values $ring_group_name = check_str($_POST["ring_group_name"]); $ring_group_extension = check_str($_POST["ring_group_extension"]); $ring_group_context = check_str($_POST["ring_group_context"]); $ring_group_strategy = check_str($_POST["ring_group_strategy"]); $ring_group_timeout_sec = check_str($_POST["ring_group_timeout_sec"]); $ring_group_timeout_action = check_str($_POST["ring_group_timeout_action"]); $ring_group_cid_name_prefix = check_str($_POST["ring_group_cid_name_prefix"]); $ring_group_ringback = check_str($_POST["ring_group_ringback"]); $ring_group_enabled = check_str($_POST["ring_group_enabled"]); $ring_group_description = check_str($_POST["ring_group_description"]); $dialplan_uuid = check_str($_POST["dialplan_uuid"]); //$ring_group_timeout_action = "transfer:1001 XML default"; $ring_group_timeout_array = explode(":", $ring_group_timeout_action); $ring_group_timeout_app = array_shift($ring_group_timeout_array); $ring_group_timeout_data = join(':', $ring_group_timeout_array); $extension_uuid = check_str($_POST["extension_uuid"]); //set the context for users that are not in the superadmin group if (!if_group("superadmin")) { if (count($_SESSION["domains"]) > 1) { $ring_group_context = $_SESSION['domain_name']; } else { $ring_group_context = "default"; } } } if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $msg = ''; if ($action == "update") { $ring_group_uuid = check_str($_POST["ring_group_uuid"]); } //check for all required data if (strlen($ring_group_name) == 0) { $msg .= $text['message-name']."
\n"; } if (strlen($ring_group_extension) == 0) { $msg .= $text['message-extension']."
\n"; } if (strlen($ring_group_strategy) == 0) { $msg .= $text['message-strategy']."
\n"; } if (strlen($ring_group_timeout_sec) == 0) { $msg .= $text['message-strategy']."
\n"; } if (strlen($ring_group_timeout_app) == 0) { $msg .= $text['message-timeout-action']."
\n"; } //if (strlen($ring_group_cid_name_prefix) == 0) { $msg .= "Please provide: Caller ID Prefix
\n"; } //if (strlen($ring_group_ringback) == 0) { $msg .= "Please provide: Ringback
\n"; } if (strlen($ring_group_enabled) == 0) { $msg .= $text['message-enabled']."
\n"; } //if (strlen($ring_group_description) == 0) { $msg .= "Please provide: 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") { //prepare the uuids $ring_group_uuid = uuid(); $dialplan_uuid = uuid(); //add the ring group $sql = "insert into v_ring_groups "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "ring_group_uuid, "; $sql .= "ring_group_name, "; $sql .= "ring_group_extension, "; $sql .= "ring_group_context, "; $sql .= "ring_group_strategy, "; $sql .= "ring_group_timeout_sec, "; $sql .= "ring_group_timeout_app, "; $sql .= "ring_group_timeout_data, "; $sql .= "ring_group_cid_name_prefix, "; $sql .= "ring_group_ringback, "; $sql .= "ring_group_enabled, "; $sql .= "ring_group_description, "; $sql .= "dialplan_uuid "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'".$_SESSION['domain_uuid']."', "; $sql .= "'".$ring_group_uuid."', "; $sql .= "'$ring_group_name', "; $sql .= "'$ring_group_extension', "; $sql .= "'$ring_group_context', "; $sql .= "'$ring_group_strategy', "; $sql .= "'$ring_group_timeout_sec', "; $sql .= "'$ring_group_timeout_app', "; $sql .= "'$ring_group_timeout_data', "; $sql .= "'$ring_group_cid_name_prefix', "; $sql .= "'$ring_group_ringback', "; $sql .= "'$ring_group_enabled', "; $sql .= "'$ring_group_description', "; $sql .= "'$dialplan_uuid' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); } //if ($action == "add") if ($action == "update") { $sql = "update v_ring_groups set "; $sql .= "ring_group_name = '$ring_group_name', "; $sql .= "ring_group_extension = '$ring_group_extension', "; if (if_group("superadmin")) { $sql .= "ring_group_context = '$ring_group_context', "; } $sql .= "ring_group_strategy = '$ring_group_strategy', "; $sql .= "ring_group_timeout_sec = '$ring_group_timeout_sec', "; $sql .= "ring_group_timeout_app = '$ring_group_timeout_app', "; $sql .= "ring_group_timeout_data = '$ring_group_timeout_data', "; $sql .= "ring_group_cid_name_prefix = '$ring_group_cid_name_prefix', "; $sql .= "ring_group_ringback = '$ring_group_ringback', "; $sql .= "ring_group_enabled = '$ring_group_enabled', "; $sql .= "ring_group_description = '$ring_group_description' "; //$sql .= "dialplan_uuid = '$dialplan_uuid' "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and ring_group_uuid = '$ring_group_uuid' "; $db->exec(check_sql($sql)); unset($sql); } if ($action == "update" || $action == "add") { //if extension_uuid then add it to ring group extensions if (strlen($extension_uuid) > 0) { $ring_group_extension_uuid = uuid(); $sql = "insert into v_ring_group_extensions "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "ring_group_uuid, "; $sql .= "ring_group_extension_uuid, "; $sql .= "extension_uuid "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'".$_SESSION['domain_uuid']."', "; $sql .= "'$ring_group_uuid', "; $sql .= "'$ring_group_extension_uuid', "; $sql .= "'$extension_uuid' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); } //if it does not exist in the dialplan then add it $sql = "select count(*) as num_rows from v_dialplans "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and dialplan_uuid = '".$dialplan_uuid."' "; $db->exec(check_sql($sql)); $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 entry $dialplan_name = $ring_group_name; $dialplan_order ='333'; $dialplan_context = $ring_group_context; $dialplan_enabled = 'true'; $dialplan_description = $ring_group_description; $app_uuid = '1d61fb65-1eec-bc73-a6ee-a6203b4fe6f2'; dialplan_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_name, $dialplan_order, $dialplan_context, $dialplan_enabled, $dialplan_description, $app_uuid); // $dialplan_detail_tag = 'condition'; //condition, action, antiaction $dialplan_detail_type = 'destination_number'; $dialplan_detail_data = '^'.$ring_group_extension.'$'; $dialplan_detail_order = '000'; $dialplan_detail_group = '1'; dialplan_detail_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_detail_tag, $dialplan_detail_order, $dialplan_detail_group, $dialplan_detail_type, $dialplan_detail_data); // $dialplan_detail_tag = 'action'; //condition, action, antiaction $dialplan_detail_type = 'set'; $dialplan_detail_data = 'ring_group_uuid='.$ring_group_uuid; $dialplan_detail_order = '010'; $dialplan_detail_group = '1'; dialplan_detail_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_detail_tag, $dialplan_detail_order, $dialplan_detail_group, $dialplan_detail_type, $dialplan_detail_data); // $dialplan_detail_tag = 'action'; //condition, action, antiaction //$dialplan_detail_type = 'transfer'; //$dialplan_detail_data = $ring_group_extension . ' LUA ring_group.lua'; $dialplan_detail_type = 'lua'; $dialplan_detail_data = 'ring_group.lua'; $dialplan_detail_order = '030'; $dialplan_detail_group = '1'; dialplan_detail_add($_SESSION['domain_uuid'], $dialplan_uuid, $dialplan_detail_tag, $dialplan_detail_order, $dialplan_detail_group, $dialplan_detail_type, $dialplan_detail_data); //save the xml save_dialplan_xml(); //apply settings reminder $_SESSION["reload_xml"] = true; } } //redirect the browser require_once "includes/header.php"; echo "\n"; echo "
\n"; if ($action == "add") { echo $text['message-enabled']."\n"; } if ($action == "update") { echo $text['message-update-complete']."\n"; } echo "
\n"; require_once "includes/footer.php"; exit; } } //if ($_POST["persistformvar"] != "true") } //(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_context = $row["ring_group_context"]; $ring_group_strategy = $row["ring_group_strategy"]; $ring_group_timeout_sec = $row["ring_group_timeout_sec"]; $ring_group_timeout_app = $row["ring_group_timeout_app"]; $ring_group_timeout_data = $row["ring_group_timeout_data"]; $ring_group_cid_name_prefix = $row["ring_group_cid_name_prefix"]; $ring_group_ringback = $row["ring_group_ringback"]; $ring_group_enabled = $row["ring_group_enabled"]; $ring_group_description = $row["ring_group_description"]; $dialplan_uuid = $row["dialplan_uuid"]; } unset ($prep_statement); if (strlen($ring_group_timeout_app) > 0) { $ring_group_timeout_action = $ring_group_timeout_app.":".$ring_group_timeout_data; } } //set defaults if (strlen($ring_group_timeout_sec) == 0) { $ring_group_timeout_sec = '30'; } if (strlen($ring_group_enabled) == 0) { $ring_group_enabled = 'true'; } //set the context for users that are not in the superadmin group if (strlen($ring_group_context) == 0) { if (count($_SESSION["domains"]) > 1) { $ring_group_context = $_SESSION['domain_name']; } else { $ring_group_context = "default"; } } //show the header require_once "includes/header.php"; //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"; if (if_group("superadmin")) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " "; echo " "; echo " "; 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 " "; echo "
".$text['label-ring-group']."
\n"; echo $text['description']."

\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-context'],":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-enter-context']."\n"; echo "
\n"; echo " ".$text['label-strategy'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['label-sequence']."\n"; echo "
".$text['label-extensions'].":"; if ($action == "update") { echo " \n"; $sql = "SELECT g.ring_group_extension_uuid, e.extension_uuid, e.extension "; $sql .= "FROM v_ring_groups as r, v_ring_group_extensions as g, v_extensions as e "; $sql .= "where g.ring_group_uuid = r.ring_group_uuid "; $sql .= "and g.domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and g.ring_group_uuid = '".$ring_group_uuid."' "; $sql .= "and e.extension_uuid = g.extension_uuid "; $sql .= "order by e.extension asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $result_count = count($result); foreach($result as $field) { echo " \n"; echo " \n"; echo " \n"; echo " \n"; } echo "
".$field['extension']."\n"; echo " $v_link_label_delete\n"; echo "
\n"; } echo "
\n"; $sql = "SELECT * FROM v_extensions "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "order by extension asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); echo " "; if ($action == "update") { echo " \n"; } unset($sql, $result); echo "
\n"; echo " ".$text['description-extension']."\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-destination'].":\n"; echo "\n"; //switch_select_destination(select_type, select_label, select_name, select_value, select_style, action); switch_select_destination("dialplan", "", "ring_group_timeout_action", $ring_group_timeout_action, "", ""); echo "
\n"; echo " ".$text['description-destination']."\n"; echo "
\n"; echo " ".$text['label-cid-prefix'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-cid-prefix']." \n"; echo "
\n"; echo " ".$text['label-ringback'].":\n"; echo "\n"; $select_options = ""; if ($ring_group_ringback == "\${us-ring}" || $ring_group_ringback == "us-ring") { $select_options .= " \n"; } else { $select_options .= " \n"; } if ($ring_group_ringback == "\${fr-ring}" || $ring_group_ringback == "fr-ring") { $select_options .= " \n"; } else { $select_options .= " \n"; } if ($ring_group_ringback == "\${uk-ring}" || $ring_group_ringback == "uk-ring") { $select_options .= " \n"; } else { $select_options .= " \n"; } if ($ring_group_ringback == "\${rs-ring}" || $ring_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 = "ring_group_ringback"; $moh->select_value = $ring_group_ringback; $moh->select_options = $select_options; echo $moh->select(); echo "
\n"; echo $text['description-ringback']."\n"; echo "
\n"; echo " ".$text['label-enabled'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-enabled']."\n"; echo "
\n"; echo " 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 "
"; //include the footer require_once "includes/footer.php"; ?>