Ring Groups: Database class integration.
This commit is contained in:
+142
-114
@@ -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";
|
||||
|
||||
?>
|
||||
?>
|
||||
Reference in New Issue
Block a user