Ring Groups: Database class integration.

This commit is contained in:
Nate 2019-08-13 04:48:28 -06:00
parent 9a4ec92981
commit a932eb39ea
8 changed files with 345 additions and 339 deletions

View File

@ -28,29 +28,41 @@
if ($domains_processed == 1) {
//select ring groups with an empty context
$sql = "select * from v_ring_groups where ring_group_context is null ";
$sql = "select * from v_ring_groups ";
$sql .= "where ring_group_context is null ";
$database = new database;
$ring_groups = $database->select($sql, null, 'all');
if (is_array($ring_groups)) {
if (is_array($ring_groups) && @sizeof($ring_groups) != 0) {
//get the domain list
$sql = "select * from v_domains ";
$domains = $database->select($sql, null, 'all');
//update the ring group context
$x = 0;
foreach ($ring_groups as $row) {
foreach ($domains as $domain) {
if ($row['domain_uuid'] == $domain['domain_uuid']) {
$sql = "update v_ring_groups set ring_group_context = :domain_name \n";
$sql .= "where ring_group_uuid = :ring_group_uuid \n";
$parameters['domain_name'] = $domain['domain_name'];
$parameters['ring_group_uuid'] = $row['ring_group_uuid'];
$database->execute($sql, $parameters);
unset($parameters);
$array['ring_groups'][$x]['ring_group_uuid'] = $row['ring_group_uuid'];
$array['ring_groups'][$x]['ring_group_context'] = $domain['domain_name'];
$x++;
}
}
}
}
if (is_array($array) && @sizeof($array) != 0) {
//grant temporary permissions
$p = new permissions;
$p->add('ring_group_edit', 'temp');
//execute update
$database = new database;
$database->app_name = 'ring_groups';
$database->app_uuid = '1d61fb65-1eec-bc73-a6ee-a6203b4fe6f2';
$database->save($array);
unset($array);
//revoke temporary permissions
$p->delete('ring_group_edit', 'temp');
}
}
}
?>
?>

View File

@ -1041,7 +1041,7 @@ $text['header-description']['ru-ru'] = "Описание";
$text['header-description']['sv-se'] = "Beskrivning";
$text['header-description']['uk-ua'] = "Опис";
$text['description-user_list']['en-us'] = "Assign the users that are assigned to this ring group.";
$text['description-user_list']['en-us'] = "Define users assigned to this ring group.";
$text['description-user_list']['ar-eg'] = "";
$text['description-user_list']['de-at'] = "Weisen Sie diese Rufgruppe Benutzern zu."; //copied from de-de
$text['description-user_list']['de-ch'] = "Weisen Sie diese Rufgruppe Benutzern zu."; //copied from de-de

View File

@ -43,28 +43,24 @@
$text = $language->get();
//get the http value and set it as a php variable
if (is_array($_GET)) {
$id = $_GET["id"];
}
$ring_group_uuid = $_GET["id"];
//delete the user data
if (is_uuid($id)) {
if (is_uuid($ring_group_uuid)) {
//get the dialplan_uuid
$sql = "select * from v_ring_groups ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and ring_group_uuid = :ring_group_uuid ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$parameters['ring_group_uuid'] = $id;
$parameters['ring_group_uuid'] = $ring_group_uuid;
$database = new database;
$result = $database->select($sql, $parameters);
if (is_array($result)) {
foreach ($result as &$row) {
$dialplan_uuid = $row["dialplan_uuid"];
$ring_group_context = $row["ring_group_context"];
}
$row = $database->select($sql, $parameters, 'row');
if (is_array($array) && @sizeof($array) != 0) {
$dialplan_uuid = $row["dialplan_uuid"];
$ring_group_context = $row["ring_group_context"];
}
unset($database, $sql, $parameters);
unset($sql, $parameters, $row);
//add the dialplan permission
$p = new permissions;
@ -73,9 +69,9 @@
//delete the data
$array['dialplan_details'][]['dialplan_uuid'] = $dialplan_uuid;
$array['dialplans'][]['dialplan_uuid'] = $dialplan_uuid;
$array['ring_group_destinations'][]['ring_group_uuid'] = $id;
$array['ring_group_users'][]['ring_group_uuid'] = $id;
$array['ring_groups'][]['ring_group_uuid'] = $id;
$array['ring_group_destinations'][]['ring_group_uuid'] = $ring_group_uuid;
$array['ring_group_users'][]['ring_group_uuid'] = $ring_group_uuid;
$array['ring_groups'][]['ring_group_uuid'] = $ring_group_uuid;
$database = new database;
$database->app_name = 'ring_groups';
$database->app_uuid = '1d61fb65-1eec-bc73-a6ee-a6203b4fe6f2';
@ -94,11 +90,13 @@
//clear the cache
$cache = new cache;
$cache->delete("dialplan:".$ring_group_context);
//set message
message::add($text['message-delete']);
}
//redirect the user
message::add($text['message-delete']);
header("Location: ring_groups.php");
return;
exit;
?>
?>

View File

@ -43,27 +43,27 @@
$text = $language->get();
//get the id
if (is_array($_GET)) {
$id = $_GET["id"];
$ring_group_uuid = $_GET["ring_group_uuid"];
}
$ring_group_destination_uuid = $_GET["id"];
$ring_group_uuid = $_GET["ring_group_uuid"];
//delete ring_group_destination
if (is_uuid($id)) {
$array['ring_group_destinations'][]['ring_group_destination_uuid'] = $id;
$database = new database;
$database->app_name = 'ring_groups';
$database->app_uuid = '1d61fb65-1eec-bc73-a6ee-a6203b4fe6f2';
$database->delete($array);
//$message = $database->message;
if (is_uuid($ring_group_destination_uuid) && is_uuid($ring_group_uuid)) {
//build array
$array['ring_group_destinations'][0]['ring_group_destination_uuid'] = $ring_group_destination_uuid;
//execute delete
$database = new database;
$database->app_name = 'ring_groups';
$database->app_uuid = '1d61fb65-1eec-bc73-a6ee-a6203b4fe6f2';
$database->delete($array);
//set message
message::add($text['message-delete']);
//redirect
header("Location: ring_group_edit.php?id=".$ring_group_uuid);
exit;
}
//save the message to a session variable
message::add($text['message-delete']);
//redirect the browser
if (is_uuid($ring_group_uuid)) {
header("Location: ring_group_edit.php?id=".$ring_group_uuid);
}
//default redirect
header("Location: ring_groups.php");
exit;
?>

View File

@ -39,26 +39,26 @@ else {
$text = $language->get();
//action add or update
if (isset($_REQUEST["id"])) {
if (is_uuid($_REQUEST["id"])) {
$action = "update";
$ring_group_destination_uuid = check_str($_REQUEST["id"]);
$ring_group_destination_uuid = $_REQUEST["id"];
}
else {
$action = "add";
}
//set the parent uuid
if (strlen($_GET["ring_group_uuid"]) > 0) {
$ring_group_uuid = check_str($_GET["ring_group_uuid"]);
if (is_uuid($_GET["ring_group_uuid"])) {
$ring_group_uuid = $_GET["ring_group_uuid"];
}
//get http post variables and set them to php variables
if (count($_POST)>0) {
$ring_group_uuid = check_str($_POST["ring_group_uuid"]);
$destination_number = check_str($_POST["destination_number"]);
$destination_delay = check_str($_POST["destination_delay"]);
$destination_timeout = check_str($_POST["destination_timeout"]);
$destination_prompt = check_str($_POST["destination_prompt"]);
$ring_group_uuid = $_POST["ring_group_uuid"];
$destination_number = $_POST["destination_number"];
$destination_delay = $_POST["destination_delay"];
$destination_timeout = $_POST["destination_timeout"];
$destination_prompt = $_POST["destination_prompt"];
}
//define the destination_select function
@ -67,7 +67,7 @@ else {
echo " <select class='formfld' name='$select_name'>\n";
echo " <option value=''></option>\n";
$i = 0;
while($i <= 100) {
while ($i <= 100) {
if ($select_value == $i) {
echo " <option value='$i' selected='selected'>$i</option>\n";
}
@ -83,7 +83,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
$msg = '';
if ($action == "update") {
$ring_group_destination_uuid = check_str($_POST["ring_group_destination_uuid"]);
$ring_group_destination_uuid = $_POST["ring_group_destination_uuid"];
}
//check for all required data
@ -109,74 +109,69 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
//add or update the database
if ($_POST["persistformvar"] != "true") {
if ($action == "add" && permission_exists('ring_group_add')) {
$sql = "insert into v_ring_group_destinations ";
$sql .= "(";
$sql .= "domain_uuid, ";
$sql .= "ring_group_destination_uuid, ";
$sql .= "ring_group_uuid, ";
$sql .= "destination_number, ";
$sql .= "destination_delay, ";
$sql .= "destination_timeout, ";
$sql .= "destination_prompt ";
$sql .= ") ";
$sql .= "values ";
$sql .= "(";
$sql .= "'$domain_uuid', ";
$sql .= "'".uuid()."', ";
$sql .= "'$ring_group_uuid', ";
$sql .= "'$destination_number', ";
$sql .= "'$destination_delay', ";
$sql .= "'$destination_timeout', ";
$sql .= "'$destination_prompt' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
message::add($text['message-add']);
header("Location: ring_group_edit.php?id=".$ring_group_uuid);
return;
} //if ($action == "add")
//begin array
$ring_group_destination_uuid = uuid();
$array['ring_group_destinations'][0]['ring_group_destination_uuid'] = $ring_group_destination_uuid;
//grant temporary permissions
$p = new permissions;
$p->add('ring_group_destination_add', 'temp');
//set message
message::add($text['message-add']);
}
if ($action == "update" && permission_exists('ring_group_edit')) {
$sql = "update v_ring_group_destinations set ";
$sql .= "destination_number = '$destination_number', ";
$sql .= "destination_delay = '$destination_delay', ";
$sql .= "destination_timeout = '$destination_timeout', ";
if (strlen($destination_prompt) == 0) {
$sql .= "destination_prompt = null ";
}
else {
$sql .= "destination_prompt = '$destination_prompt' ";
}
$sql .= "where domain_uuid = '$domain_uuid' ";
$sql .= "and ring_group_destination_uuid = '$ring_group_destination_uuid' ";
$db->exec(check_sql($sql));
unset($sql);
//begin array
$array['ring_group_destinations'][0]['ring_group_destination_uuid'] = $ring_group_destination_uuid;
//grant temporary permissions
$p = new permissions;
$p->add('ring_group_destination_edit', 'temp');
//set message
message::add($text['message-update']);
}
message::add($text['message-update']);
header("Location: ring_group_edit.php?id=".$ring_group_uuid);
return;
} //if ($action == "update")
} //if ($_POST["persistformvar"] != "true")
} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
if (is_array($array) && @sizeof($array) != 0) {
//add common array elements
$array['ring_group_destinations'][0]['domain_uuid'] = $domain_uuid;
$array['ring_group_destinations'][0]['ring_group_uuid'] = $ring_group_uuid;
$array['ring_group_destinations'][0]['destination_number'] = $destination_number;
$array['ring_group_destinations'][0]['destination_delay'] = $destination_delay;
$array['ring_group_destinations'][0]['destination_timeout'] = $destination_timeout;
$array['ring_group_destinations'][0]['destination_prompt'] = strlen($destination_prompt) != 0 ? $destination_prompt : null;
//execute insert/update
$database = new database;
$database->app_name = 'ring_groups';
$database->app_uuid = '1d61fb65-1eec-bc73-a6ee-a6203b4fe6f2';
$database->save($array);
unset($array);
//revoke temporary permissions
$p->delete('ring_group_destination_add', 'temp');
$p->delete('ring_group_destination_edit', 'temp');
//redirect
header("Location: ring_group_edit.php?id=".$ring_group_uuid);
exit;
}
}
}
//pre-populate the form
if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
$ring_group_destination_uuid = check_str($_GET["id"]);
$ring_group_destination_uuid = $_GET["id"];
$sql = "select * from v_ring_group_destinations ";
$sql .= "where domain_uuid = '$domain_uuid' ";
$sql .= "and ring_group_destination_uuid = '$ring_group_destination_uuid' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and ring_group_destination_uuid = :ring_group_destination_uuid ";
$parameters['domain_uuid'] = $domain_uuid;
$parameters['ring_group_destination_uuid'] = $ring_group_destination_uuid;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (is_array($row) && @sizeof($row) != 0) {
$ring_group_uuid = $row["ring_group_uuid"];
$destination_number = $row["destination_number"];
$destination_delay = $row["destination_delay"];
$destination_timeout = $row["destination_timeout"];
$destination_prompt = $row["destination_prompt"];
}
unset ($prep_statement);
unset($sql, $parameters, $row);
}
//show the header
@ -270,4 +265,5 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
//include the footer
require_once "resources/footer.php";
?>
?>

View File

@ -45,17 +45,30 @@
$language = new text;
$text = $language->get();
//delete the user from v_ring_group_users
if ($_GET["a"] == "delete" && strlen($_REQUEST["user_uuid"]) > 0 && permission_exists("ring_group_edit")) {
//delete the user from the ring group
if (
$_GET["a"] == "delete"
&& is_uuid($_REQUEST["user_uuid"])
&& permission_exists("ring_group_edit")
) {
//set the variables
$user_uuid = check_str($_REQUEST["user_uuid"]);
$ring_group_uuid = check_str($_REQUEST["id"]);
//delete the group from the users
$sql = "delete from v_ring_group_users ";
$sql .= "where domain_uuid = '".$domain_uuid."' ";
$sql .= "and ring_group_uuid = '".$ring_group_uuid."' ";
$sql .= "and user_uuid = '".$user_uuid."' ";
$db->exec(check_sql($sql));
$user_uuid = $_REQUEST["user_uuid"];
$ring_group_uuid = $_REQUEST["id"];
//build array
$array['ring_group_users'][0]['domain_uuid'] = $domain_uuid;
$array['ring_group_users'][0]['ring_group_uuid'] = $ring_group_uuid;
$array['ring_group_users'][0]['user_uuid'] = $user_uuid;
//grant temporary permissions
$p = new permissions;
$p->add('ring_group_user_delete', 'temp');
//execute delete
$database = new database;
$database->app_name = 'ring_groups';
$database->app_uuid = '1d61fb65-1eec-bc73-a6ee-a6203b4fe6f2';
$database->delete($array);
unset($array);
//revoke temporary permissions
$p->delete('ring_group_user_delete', 'temp');
//save the message to a session variable
message::add($text['message-delete']);
//redirect the browser
@ -64,7 +77,7 @@
}
//action add or update
if (isset($_REQUEST["id"])) {
if (is_uuid($_REQUEST["id"])) {
$action = "update";
$ring_group_uuid = $_REQUEST["id"];
}
@ -76,18 +89,17 @@
//get total ring group count from the database, check limit, if defined
if ($action == 'add') {
if ($_SESSION['limit']['ring_groups']['numeric'] != '') {
$sql = "select count(*) as num_rows from v_ring_groups where domain_uuid = '".$_SESSION['domain_uuid']."' ";
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
$total_ring_groups = $row['num_rows'];
}
unset($prep_statement, $row);
if ($total_ring_groups >= $_SESSION['limit']['ring_groups']['numeric']) {
$sql = "select count(*) from v_ring_groups ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$total_ring_groups = $database->select($sql, $parameters, 'column');
unset($sql, $parameters);
if (is_numeric($_SESSION['limit']['ring_groups']['numeric']) && $total_ring_groups >= $_SESSION['limit']['ring_groups']['numeric']) {
message::add($text['message-maximum_ring_groups'].' '.$_SESSION['limit']['ring_groups']['numeric'], 'negative');
header('Location: ring_groups.php');
return;
exit;
}
}
}
@ -95,69 +107,74 @@
//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_greeting = check_str($_POST["ring_group_greeting"]);
$ring_group_strategy = check_str($_POST["ring_group_strategy"]);
$ring_group_timeout_action = check_str($_POST["ring_group_timeout_action"]);
$ring_group_call_timeout = check_str($_POST["ring_group_call_timeout"]);
$ring_group_caller_id_name = check_str($_POST["ring_group_caller_id_name"]);
$ring_group_caller_id_number = check_str($_POST["ring_group_caller_id_number"]);
$ring_group_cid_name_prefix = check_str($_POST["ring_group_cid_name_prefix"]);
$ring_group_cid_number_prefix = check_str($_POST["ring_group_cid_number_prefix"]);
$ring_group_distinctive_ring = check_str($_POST["ring_group_distinctive_ring"]);
$ring_group_ringback = check_str($_POST["ring_group_ringback"]);
$ring_group_missed_call_app = check_str($_POST["ring_group_missed_call_app"]);
$ring_group_missed_call_data = check_str($_POST["ring_group_missed_call_data"]);
$ring_group_forward_enabled = check_str($_POST["ring_group_forward_enabled"]);
$ring_group_forward_destination = check_str($_POST["ring_group_forward_destination"]);
$ring_group_forward_toll_allow = check_str($_POST["ring_group_forward_toll_allow"]);
$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_name = $_POST["ring_group_name"];
$ring_group_extension = $_POST["ring_group_extension"];
$ring_group_greeting = $_POST["ring_group_greeting"];
$ring_group_strategy = $_POST["ring_group_strategy"];
$ring_group_timeout_action = $_POST["ring_group_timeout_action"];
$ring_group_call_timeout = $_POST["ring_group_call_timeout"];
$ring_group_caller_id_name = $_POST["ring_group_caller_id_name"];
$ring_group_caller_id_number = $_POST["ring_group_caller_id_number"];
$ring_group_cid_name_prefix = $_POST["ring_group_cid_name_prefix"];
$ring_group_cid_number_prefix = $_POST["ring_group_cid_number_prefix"];
$ring_group_distinctive_ring = $_POST["ring_group_distinctive_ring"];
$ring_group_ringback = $_POST["ring_group_ringback"];
$ring_group_missed_call_app = $_POST["ring_group_missed_call_app"];
$ring_group_missed_call_data = $_POST["ring_group_missed_call_data"];
$ring_group_forward_enabled = $_POST["ring_group_forward_enabled"];
$ring_group_forward_destination = $_POST["ring_group_forward_destination"];
$ring_group_forward_toll_allow = $_POST["ring_group_forward_toll_allow"];
$ring_group_enabled = $_POST["ring_group_enabled"];
$ring_group_description = $_POST["ring_group_description"];
$dialplan_uuid = $_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);
$destination_number = check_str($_POST["destination_number"]);
$destination_delay = check_str($_POST["destination_delay"]);
$destination_timeout = check_str($_POST["destination_timeout"]);
$destination_prompt = check_str($_POST["destination_prompt"]);
$destination_number = $_POST["destination_number"];
$destination_delay = $_POST["destination_delay"];
$destination_timeout = $_POST["destination_timeout"];
$destination_prompt = $_POST["destination_prompt"];
//set the context for users that do not have the permission
if (permission_exists('ring_group_context')) {
$ring_group_context = $_POST["ring_group_context"];
}
elseif ($action == 'add') {
else if ($action == 'add') {
$ring_group_context = $_SESSION['domain_name'];
}
}
//assign the user
if (strlen($_REQUEST["user_uuid"]) > 0 && strlen($_REQUEST["id"]) > 0 && $_GET["a"] != "delete") {
//assign the user to the ring group
if (
is_uuid($_REQUEST["user_uuid"])
&& is_uuid($_REQUEST["id"])
&& $_GET["a"] != "delete"
&& permission_exists("ring_group_edit")
) {
//set the variables
$user_uuid = check_str($_REQUEST["user_uuid"]);
$extension_uuid = check_str($_REQUEST["id"]);
//assign the user to the ring group
$sql_insert = "insert into v_ring_group_users ";
$sql_insert .= "(";
$sql_insert .= "ring_group_user_uuid, ";
$sql_insert .= "domain_uuid, ";
$sql_insert .= "ring_group_uuid, ";
$sql_insert .= "user_uuid ";
$sql_insert .= ")";
$sql_insert .= "values ";
$sql_insert .= "(";
$sql_insert .= "'".uuid()."', ";
$sql_insert .= "'$domain_uuid', ";
$sql_insert .= "'".$ring_group_uuid."', ";
$sql_insert .= "'".$user_uuid."' ";
$sql_insert .= ")";
$db->exec($sql_insert);
//save the message to a session variable
$user_uuid = $_REQUEST["user_uuid"];
$extension_uuid = $_REQUEST["id"];
//build array
$array['ring_group_users'][0]['ring_group_user_uuid'] = uuid();
$array['ring_group_users'][0]['domain_uuid'] = $domain_uuid;
$array['ring_group_users'][0]['ring_group_uuid'] = $ring_group_uuid;
$array['ring_group_users'][0]['user_uuid'] = $user_uuid;
//grant temporary permissions
$p = new permissions;
$p->add('ring_group_user_add', 'temp');
//execute delete
$database = new database;
$database->app_name = 'ring_groups';
$database->app_uuid = '1d61fb65-1eec-bc73-a6ee-a6203b4fe6f2';
$database->save($array);
unset($array);
//revoke temporary permissions
$p->delete('ring_group_user_add', 'temp');
//set message
message::add($text['message-add']);
//redirect the browser
header("Location: ring_group_edit.php?id=$ring_group_uuid");
header("Location: ring_group_edit.php?id=".$ring_group_uuid);
exit;
}
@ -239,12 +256,12 @@
$ring_group_timeout_data = join(':', $ring_group_timeout_array);
//add the domain_uuid
if (strlen($_POST["domain_uuid"]) == 0) {
if (!is_uuid($_POST["domain_uuid"])) {
$_POST["domain_uuid"] = $_SESSION['domain_uuid'];
}
//add the dialplan_uuid
if (strlen($_POST["dialplan_uuid"]) == 0) {
if (!is_uuid($_POST["dialplan_uuid"])) {
$dialplan_uuid = uuid();
}
@ -278,7 +295,7 @@
$y = 0;
foreach ($_POST["ring_group_destinations"] as $row) {
if (isset($row['ring_group_destination_uuid'])) {
if (is_uuid($row['ring_group_destination_uuid'])) {
$ring_group_destination_uuid = $row['ring_group_destination_uuid'];
}
else {
@ -358,21 +375,21 @@
message::add($text['message-update']);
}
} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
}
//initialize the destinations object
$destination = new destinations;
//pre-populate the form
if (strlen($ring_group_uuid) > 0) {
if (is_uuid($ring_group_uuid)) {
$sql = "select * from v_ring_groups ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and ring_group_uuid = :ring_group_uuid ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$parameters['ring_group_uuid'] = $ring_group_uuid;
$database = new database;
$result = $database->select($sql, $parameters, 'all');
foreach ($result as &$row) {
$row = $database->select($sql, $parameters, 'row');
if (is_array($row) && @sizeof($row) != 0) {
$ring_group_name = $row["ring_group_name"];
$ring_group_extension = $row["ring_group_extension"];
$ring_group_greeting = $row["ring_group_greeting"];
@ -396,7 +413,7 @@
$ring_group_description = $row["ring_group_description"];
$dialplan_uuid = $row["dialplan_uuid"];
}
unset($parameters);
unset($sql, $parameters, $row);
if (strlen($ring_group_timeout_app) > 0) {
$ring_group_timeout_action = $ring_group_timeout_app.":".$ring_group_timeout_data;
}
@ -408,15 +425,20 @@
}
//get the ring group destination array
if ($action == "add") { $x = 0; $limit = 5; }
if (strlen($ring_group_uuid) > 0) {
if ($action == "add") {
$x = 0;
$limit = 5;
}
if (is_uuid($ring_group_uuid)) {
$sql = "select * from v_ring_group_destinations ";
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= "and ring_group_uuid = '".$ring_group_uuid."' ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and ring_group_uuid = :ring_group_uuid ";
$sql .= "order by destination_delay, destination_number asc ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$ring_group_destinations = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$parameters['ring_group_uuid'] = $ring_group_uuid;
$database = new database;
$ring_group_destinations = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
}
//add an empty row to the options array
@ -437,27 +459,30 @@
}
//get the ring group users
if (strlen($ring_group_uuid) > 0) {
$sql = "select u.username, r.user_uuid, r.ring_group_uuid from v_ring_group_users as r, v_users as u ";
if (is_uuid($ring_group_uuid)) {
$sql = "select u.username, r.user_uuid, r.ring_group_uuid ";
$sql .= "from v_ring_group_users as r, v_users as u ";
$sql .= "where r.user_uuid = u.user_uuid ";
$sql .= "and u.user_enabled = 'true' ";
$sql .= "and r.domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= "and r.ring_group_uuid = '".$ring_group_uuid."' ";
$sql .= "and r.domain_uuid = :domain_uuid ";
$sql .= "and r.ring_group_uuid = :ring_group_uuid ";
$sql .= "order by u.username asc ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$ring_group_users = $prep_statement->fetchAll(PDO::FETCH_NAMED);
//$ring_group_users[$x]['username'] = '';
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$parameters['ring_group_uuid'] = $ring_group_uuid;
$database = new database;
$ring_group_users = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
}
//get the users
$sql = "SELECT * FROM v_users ";
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql = "select * from v_users ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and user_enabled = 'true' ";
$sql .= "order by username asc ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$users = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$users = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
//set defaults
if (strlen($ring_group_enabled) == 0) { $ring_group_enabled = 'true'; }
@ -559,7 +584,7 @@
foreach($sounds as $key => $value) {
echo "<optgroup label=".$text['label-'.$key].">\n";
$selected = false;
foreach($value as $row) {
foreach ($value as $row) {
if ($ring_group_greeting == $row["value"]) {
$selected = true;
echo " <option value='".escape($row["value"])."' selected='selected'>".escape($row["name"])."</option>\n";
@ -616,7 +641,7 @@
echo " <td></td>\n";
echo " </tr>\n";
$x = 0;
foreach($ring_group_destinations as $row) {
foreach ($ring_group_destinations as $row) {
if (strlen($row['destination_delay']) == 0) { $row['destination_delay'] = "0"; }
if (strlen($row['destination_timeout']) == 0) { $row['destination_timeout'] = "30"; }
@ -631,7 +656,7 @@
echo " <td>\n";
echo " <select name='ring_group_destinations[".$x."][destination_delay]' class='formfld' style='width:55px'>\n";
$i=0;
while($i<=300) {
while ($i <= 300) {
if ($i == $row['destination_delay']) {
echo " <option value='$i' selected='selected'>$i</option>\n";
}
@ -644,8 +669,8 @@
echo " </td>\n";
echo " <td>\n";
echo " <select name='ring_group_destinations[".$x."][destination_timeout]' class='formfld' style='width:55px'>\n";
$i=5;
while($i<=300) {
$i = 5;
while($i <= 300) {
if ($i == $row['destination_timeout']) {
echo " <option value='$i' selected='selected'>$i</option>\n";
}
@ -781,24 +806,27 @@
echo " <td class='vncell' valign='top'>".$text['label-user_list']."</td>";
echo " <td class='vtable'>";
echo " <table width='300px'>\n";
if (isset($ring_group_users)) foreach($ring_group_users as $field) {
echo " <tr>\n";
echo " <td class='vtable'>".escape($field['username'])."</td>\n";
echo " <td>\n";
echo " <a href='ring_group_edit.php?id=".escape($ring_group_uuid)."&user_uuid=".escape($field['user_uuid'])."&a=delete' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">".$v_link_label_delete."</a>\n";
echo " </td>\n";
echo " </tr>\n";
if (is_array($ring_group_users) && @sizeof($ring_group_users) != 0) {
foreach($ring_group_users as $field) {
echo " <tr>\n";
echo " <td class='vtable'>".escape($field['username'])."</td>\n";
echo " <td>\n";
echo " <a href='ring_group_edit.php?id=".escape($ring_group_uuid)."&user_uuid=".escape($field['user_uuid'])."&a=delete' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">".$v_link_label_delete."</a>\n";
echo " </td>\n";
echo " </tr>\n";
}
}
echo " </table>\n";
echo " <br />\n";
echo " <select name=\"user_uuid\" class='formfld' style='width: auto;'>\n";
echo " <option value=\"\"></option>\n";
foreach($users as $field) {
echo " <option value='".escape($field['user_uuid'])."'>".escape($field['username'])."</option>\n";
if (is_array($users) && @sizeof($users) != 0) {
foreach($users as $field) {
echo " <option value='".escape($field['user_uuid'])."'>".escape($field['username'])."</option>\n";
}
}
echo " </select>";
echo " <input type=\"submit\" class='btn' value=\"".$text['button-add']."\">\n";
unset($sql, $result);
echo " <br>\n";
echo " ".$text['description-user_list']."\n";
echo " <br />\n";
@ -903,10 +931,10 @@
echo " <tr>\n";
echo " <td colspan='2' align='right'>\n";
if (strlen($dialplan_uuid) > 0) {
if (is_uuid($dialplan_uuid)) {
echo " <input type='hidden' name='dialplan_uuid' value='".escape($dialplan_uuid)."'>\n";
}
if (strlen($ring_group_uuid) > 0) {
if (is_uuid($ring_group_uuid)) {
echo " <input type='hidden' name='ring_group_uuid' value='".escape($ring_group_uuid)."'>\n";
}
echo " <br>";
@ -920,4 +948,4 @@
//include the footer
require_once "resources/footer.php";
?>
?>

View File

@ -55,59 +55,63 @@
$ring_groups = $_POST['ring_group_forward_enabled'];
$destinations = $_POST['ring_group_forward_destination'];
if (is_array($ring_groups) && sizeof($ring_groups) > 0) {
if (is_array($ring_groups) && @sizeof($ring_groups) != 0 && permission_exists('ring_group_forward')) {
$x = 0;
foreach ($ring_groups as $ring_group_uuid => $ring_group_forward_enabled) {
//remove non-numeric characters
$ring_group_foreward_destination = preg_replace("~[^0-9]~", "", $destinations[$ring_group_uuid]);
//update the ring group
$sql = "update v_ring_groups set ";
$sql .= "ring_group_forward_enabled = '".check_str($ring_group_forward_enabled)."', ";
$sql .= "ring_group_forward_destination = '".check_str($ring_group_foreward_destination)."' ";
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= "and ring_group_uuid = '".$ring_group_uuid."' ";
$db->exec(check_sql($sql));
unset($sql);
//remove non-numeric characters
$ring_group_foreward_destination = preg_replace("~[^0-9]~", "", $destinations[$ring_group_uuid]);
//build array
$array['ring_groups'][$x]['ring_group_uuid'] = $ring_group_uuid;
$array['ring_groups'][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
$array['ring_groups'][$x]['ring_group_forward_enabled'] = $ring_group_forward_enabled;
$array['ring_groups'][$x]['ring_group_forward_destination'] = $ring_group_foreward_destination;
//increment counter
$x++;
}
if (is_array($array) && !sizeof($array) != 0) {
//update ring group
$p = new permissions;
$p->add('ring_group_edit', 'temp');
$database = new database;
$database->app_name = 'ring_groups';
$database->app_uuid = '1d61fb65-1eec-bc73-a6ee-a6203b4fe6f2';
$database->save($array);
unset($array);
$p->delete('ring_group_edit', 'temp');
//set message
message::add($text['message-update']);
//redirect the user
header("Location: ".$_REQUEST['return_url']);
exit;
}
//redirect the user
message::add($text['message-update']);
header("Location: ".$_REQUEST['return_url']);
exit;
}
}
//prepare to page the results
if (permission_exists('ring_group_add') || permission_exists('ring_group_edit')) {
//show all ring groups
$sql = "select count(*) as num_rows from v_ring_groups ";
$sql .= "where domain_uuid = '$domain_uuid' ";
$sql = "select count(*) from v_ring_groups ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $domain_uuid;
}
else {
//show only assigned fax extensions
//show only assigned ring groups
$sql = "select count(*) as num_rows from v_ring_groups as r, v_ring_group_users as u ";
$sql .= "where r.ring_group_uuid = u.ring_group_uuid ";
$sql .= "and r.domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= "and u.user_uuid = '".$_SESSION['user_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';
}
$sql .= "and r.domain_uuid = :domain_uuid ";
$sql .= "and u.user_uuid = :user_uuid ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$parameters['user_uuid'] = $_SESSION['user_uuid'];
}
$database = new database;
$num_rows = $database->select($sql, $parameters, 'column');
//prepare to page the results
if ($is_included) {
$rows_per_page = 10;
}
else {
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
}
$rows_per_page = $is_included ? 10 : (is_numeric($_SESSION['domain']['paging']['numeric']) ? $_SESSION['domain']['paging']['numeric'] : 50);
$param = "";
$page = $_GET['page'];
if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
@ -117,30 +121,17 @@
//get the list
if (permission_exists('ring_group_add') || permission_exists('ring_group_edit')) {
//show all ring groups
$sql = "select * from v_ring_groups ";
$sql .= "where domain_uuid = '".$domain_uuid."' ";
$sql .= str_replace('count(*)', '*', $sql);
}
else {
//show only assigned ring groups
$sql = "select r.ring_group_name, r.ring_group_uuid, r.ring_group_extension, r.ring_group_forward_destination, ";
$sql .= "r.ring_group_forward_enabled, r.ring_group_description ";
$sql .= "from v_ring_groups as r, v_ring_group_users as u ";
$sql .= "where r.ring_group_uuid = u.ring_group_uuid ";
$sql .= "and r.domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= "and u.user_uuid = '".$_SESSION['user_uuid']."' ";
$sql .= str_replace('count(*)', 'r.ring_group_name, r.ring_group_uuid, r.ring_group_extension, r.ring_group_forward_destination, r.ring_group_forward_enabled, r.ring_group_description', $sql);
}
if (strlen($order_by) == 0) {
$sql .= "order by ring_group_extension asc ";
}
else {
$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);
$sql .= order_by($order_by, $order, 'ring_group_extension', 'asc');
$sql .= limit_offset($rows_per_page, $offset);
$database = new database;
$result = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
echo "<form method='post' name='frm' action='".PROJECT_PATH."/app/ring_groups/ring_group_forward.php'>\n";
echo "<input type='hidden' name='return_url' value='".$_SERVER['REQUEST_URI']."'>\n";
@ -171,7 +162,7 @@
echo "</tr>\n";
$c = 0;
if ($result_count > 0) {
if (is_array($result) && @sizeof($result) != 0) {
foreach($result as $row) {
$onclick = "onclick=\"document.getElementById('".$row['ring_group_uuid']."').selectedIndex = (document.getElementById('".$row['ring_group_uuid']."').selectedIndex) ? 0 : 1; if (document.getElementById('".$row['ring_group_uuid']."').selectedIndex) { document.getElementById('destination').focus(); }\"";
echo "<tr>\n";
@ -190,8 +181,8 @@
echo "</tr>\n";
$c = ($c) ? 0 : 1;
}
unset($sql, $result, $row_count);
}
unset($result, $row);
echo "</table>";
echo "</form>";

View File

@ -44,15 +44,16 @@
$text = $language->get();
//add the search term
$search = strtolower(check_str($_GET["search"]));
$search = strtolower($_GET["search"]);
if (strlen($search) > 0) {
$sql_search = "and (";
$sql_search .= "lower(ring_group_name) like '%".$search."%' ";
$sql_search .= "or lower(ring_group_extension) like '%".$search."%' ";
$sql_search .= "or lower(ring_group_description) like '%".$search."%' ";
$sql_search .= "or lower(ring_group_enabled) like '%".$search."%' ";
$sql_search .= "or lower(ring_group_strategy) like '%".$search."%' ";
$sql_search .= "lower(ring_group_name) like :search ";
$sql_search .= "or lower(ring_group_extension) like :search ";
$sql_search .= "or lower(ring_group_description) like :search ";
$sql_search .= "or lower(ring_group_enabled) like :search ";
$sql_search .= "or lower(ring_group_strategy) like :search ";
$sql_search .= ")";
$parameters['search'] = '%'.$search.'%';
}
//additional includes
@ -67,7 +68,6 @@
echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
echo " <tr>\n";
echo " <td width='50%' align='left' nowrap='nowrap'><b>".$text['title-ring_groups']."</b></td>\n";
//echo " <td width='50%' align='right'>&nbsp;</td>\n";
echo " <form method='get' action=''>\n";
echo " <td width='50%' style='vertical-align: top; text-align: right; white-space: nowrap;'>\n";
echo " <input type='text' class='txt' style='width: 150px' name='search' id='search' value='".escape($search)."'>\n";
@ -82,28 +82,17 @@
echo " </tr>\n";
echo "</table>\n";
//get total ring group count from the database
$sql = "select count(*) as num_rows from v_ring_groups where domain_uuid = '".$_SESSION['domain_uuid']."' ";
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
$total_ring_groups = $row['num_rows'];
}
unset($prep_statement, $row);
//get total ring group count
$sql = "select count(*) from v_ring_groups ";
$sql .= "where domain_uuid = :domain_uuid ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$total_ring_groups = $database->select($sql, $parameters, 'column');
//prepare to page the results (reuse $sql from above)
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if (strlen($row['num_rows']) > 0) {
$num_rows = $row['num_rows'];
}
else {
$num_rows = '0';
}
}
//get filtered ring group count
$sql .= $search;
$database = new database;
$num_rows = $database->select($sql, $parameters, 'column');
//prepare to page the results
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
@ -113,21 +102,17 @@
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' ";
$sql .= $sql_search;
//get the list
$sql = str_replace('count(*)', '*', $sql);
if (strlen($order_by) == 0) {
$sql .= "order by ring_group_name, ring_group_extension asc ";
$sql .= "order by ring_group_name asc, ring_group_extension asc ";
}
else {
$sql .= "order by $order_by $order ";
$sql .= order_by($order_by, $order);
}
$sql .= " limit $rows_per_page offset $offset ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$ring_groups = $prep_statement->fetchAll();
unset ($prep_statement, $sql);
$sql .= limit_offset($rows_per_page, $offset);
$ring_groups = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
//set the row styles
$c = 0;
@ -152,7 +137,7 @@
echo "</td>\n";
echo "</tr>\n";
if (is_array($ring_groups)) {
if (is_array($ring_groups) && @sizeof($ring_groups) != 0) {
foreach($ring_groups as $row) {
$tr_link = (permission_exists('ring_group_edit')) ? "href='ring_group_edit.php?id=".$row['ring_group_uuid']."'" : null;
echo "<tr ".$tr_link.">\n";
@ -178,14 +163,14 @@
}
echo " </td>\n";
echo "</tr>\n";
if ($c==0) { $c=1; } else { $c=0; }
} //end foreach
unset($sql, $ring_groups);
} //end if results
$c = $c ? 0 : 1;
}
}
unset($ring_groups, $row);
echo "<tr>\n";
echo "<td colspan='11' align='left'>\n";
echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
echo "</table>";
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";
@ -197,11 +182,7 @@
}
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>";
echo "</table>\n";
echo "<br><br>";
//include the footer