From a932eb39eacb0beda4013377e93e741d10577fd4 Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 13 Aug 2019 04:48:28 -0600 Subject: [PATCH] Ring Groups: Database class integration. --- app/ring_groups/app_defaults.php | 32 ++- app/ring_groups/app_languages.php | 2 +- app/ring_groups/ring_group_delete.php | 34 ++- .../ring_group_destination_delete.php | 36 +-- .../ring_group_destination_edit.php | 130 +++++---- app/ring_groups/ring_group_edit.php | 256 ++++++++++-------- app/ring_groups/ring_group_forward.php | 111 ++++---- app/ring_groups/ring_groups.php | 83 +++--- 8 files changed, 345 insertions(+), 339 deletions(-) diff --git a/app/ring_groups/app_defaults.php b/app/ring_groups/app_defaults.php index 21bd76ecb7..64787d82bc 100644 --- a/app/ring_groups/app_defaults.php +++ b/app/ring_groups/app_defaults.php @@ -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'); } } } -?> +?> \ No newline at end of file diff --git a/app/ring_groups/app_languages.php b/app/ring_groups/app_languages.php index 27c69faf3f..df9a690bfc 100644 --- a/app/ring_groups/app_languages.php +++ b/app/ring_groups/app_languages.php @@ -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 diff --git a/app/ring_groups/ring_group_delete.php b/app/ring_groups/ring_group_delete.php index e8fa9e764e..29f3bba257 100644 --- a/app/ring_groups/ring_group_delete.php +++ b/app/ring_groups/ring_group_delete.php @@ -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; -?> +?> \ No newline at end of file diff --git a/app/ring_groups/ring_group_destination_delete.php b/app/ring_groups/ring_group_destination_delete.php index a646a7b93e..76be410a44 100644 --- a/app/ring_groups/ring_group_destination_delete.php +++ b/app/ring_groups/ring_group_destination_delete.php @@ -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; ?> diff --git a/app/ring_groups/ring_group_destination_edit.php b/app/ring_groups/ring_group_destination_edit.php index 69aa4ec24c..622e1e45b0 100644 --- a/app/ring_groups/ring_group_destination_edit.php +++ b/app/ring_groups/ring_group_destination_edit.php @@ -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 " \n"; $i=0; - while($i<=300) { + while ($i <= 300) { if ($i == $row['destination_delay']) { echo " \n"; } @@ -644,8 +669,8 @@ echo " \n"; echo " \n"; echo " \n"; echo " \n"; - foreach($users as $field) { - echo " \n"; + if (is_array($users) && @sizeof($users) != 0) { + foreach($users as $field) { + echo " \n"; + } } echo " "; echo " \n"; - unset($sql, $result); echo "
\n"; echo " ".$text['description-user_list']."\n"; echo "
\n"; @@ -903,10 +931,10 @@ echo " \n"; echo " \n"; - if (strlen($dialplan_uuid) > 0) { + if (is_uuid($dialplan_uuid)) { echo " \n"; } - if (strlen($ring_group_uuid) > 0) { + if (is_uuid($ring_group_uuid)) { echo " \n"; } echo "
"; @@ -920,4 +948,4 @@ //include the footer require_once "resources/footer.php"; -?> +?> \ No newline at end of file diff --git a/app/ring_groups/ring_group_forward.php b/app/ring_groups/ring_group_forward.php index 8ef51e31c2..6af045bbcc 100644 --- a/app/ring_groups/ring_group_forward.php +++ b/app/ring_groups/ring_group_forward.php @@ -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 "
\n"; echo "\n"; @@ -171,7 +162,7 @@ echo "\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 "\n"; @@ -190,8 +181,8 @@ echo "\n"; $c = ($c) ? 0 : 1; } - unset($sql, $result, $row_count); } + unset($result, $row); echo ""; echo "
"; diff --git a/app/ring_groups/ring_groups.php b/app/ring_groups/ring_groups.php index cce5fad9b9..6b80302f23 100644 --- a/app/ring_groups/ring_groups.php +++ b/app/ring_groups/ring_groups.php @@ -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 "\n"; echo " \n"; echo " \n"; - //echo " \n"; echo " \n"; echo " \n"; echo "
".$text['title-ring_groups']." 
\n"; echo " \n"; @@ -82,28 +82,17 @@ echo "
\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 "\n"; echo "\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 "\n"; @@ -178,14 +163,14 @@ } echo " \n"; echo "\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 "\n"; - echo "\n"; - echo " \n"; + echo "
"; + echo "\n"; echo " \n"; echo " \n"; echo " \n"; @@ -197,11 +182,7 @@ } echo " \n"; echo " \n"; - echo "
 $paging_controls
\n"; - echo "\n"; - echo "\n"; - - echo ""; + echo "\n"; echo "

"; //include the footer