Updates to Access Controls, Bridges, and Call Block.

This commit is contained in:
Nate
2019-10-21 17:03:59 -06:00
parent be15980392
commit 17ac712cc8
9 changed files with 317 additions and 222 deletions
+4 -15
View File
@@ -91,11 +91,10 @@
$search = strtolower($_GET["search"]);
if (strlen($search) > 0) {
$sql_search = " (";
$sql_search .= " lower(call_block_name) like :search ";
$sql_search .= " or lower(call_block_number) like :search ";
$sql_search .= " or lower(call_block_description) like :search ";
$sql_search .= "lower(call_block_name) like :search ";
$sql_search .= "or lower(call_block_number) like :search ";
$sql_search .= "or lower(call_block_description) like :search ";
$sql_search .= ") ";
$parameters['search'] = '%'.$search.'%';
}
@@ -148,16 +147,6 @@
if (permission_exists('call_block_delete')) {
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'onclick'=>"if (confirm('".$text['confirm-delete']."')) { list_action_set('delete'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
}
/*
if (permission_exists('call_block_all')) {
if ($_GET['show'] == 'all') {
echo " <input type='hidden' name='show' value='all'>";
}
else {
echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']);
}
}
*/
echo "<form id='form_search' class='inline' method='get'>\n";
echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown='list_search_reset();'>";
echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search','style'=>($search != '' ? 'display: none;' : null)]);
@@ -201,7 +190,7 @@
echo "<tr class='list-row' href='".$list_row_url."'>\n";
echo " <td class='checkbox'>\n";
echo " <input type='checkbox' name='call_blocks[".$x."][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
echo " <input type='hidden' name='call_blocks[".$x."][call_block_uuid]' value='".escape($row['call_block_uuid'])."' />\n";
echo " <input type='hidden' name='call_blocks[".$x."][uuid]' value='".escape($row['call_block_uuid'])."' />\n";
echo " </td>\n";
echo " <td>";
if (permission_exists('call_block_edit')) {
+22 -10
View File
@@ -87,11 +87,21 @@
//handle the http post
if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
$msg = '';
if ($action == "update") {
//$call_block_uuid = check_str($_POST["call_block_uuid"]);
}
//delete the call block
if (permission_exists('call_block_delete')) {
if ($_POST['action'] == 'delete' && is_uuid($call_block_uuid)) {
//prepare
$array[0]['checked'] = 'true';
$array[0]['uuid'] = $call_block_uuid;
//delete
$obj = new call_block;
$obj->delete($array);
//redirect
header('Location: call_block.php');
exit;
}
}
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
@@ -101,6 +111,7 @@
}
//check for all required data
$msg = '';
if (strlen($call_block_name) == 0) { $msg .= $text['label-provide-name']."<br>\n"; }
if ($action == "add") {
if (strlen($call_block_number) == 0) { $msg .= $text['label-provide-number']."<br>\n"; }
@@ -255,8 +266,6 @@
echo " }\n";
echo "</script>";
// Show last 5-10 calls first, with add button
echo "<form method='post' name='frm' action=''>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
@@ -267,17 +276,20 @@
echo "<td align='left' width='30%' nowrap='nowrap'><b>".$text['label-edit-edit']."</b></td>\n";
}
echo "<td width='70%' align='right'>";
echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='call_block.php'\" value='".$text['button-back']."'>";
echo " <input type='button' class='btn' style='margin-right: 15px;' name='' alt='".$text['button-back']."' onclick=\"window.location='call_block.php'\" value='".$text['button-back']."'>";
if ($action == 'update' && permission_exists('call_block_delete')) {
echo button::create(['type'=>'submit','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'action','value'=>'delete','onclick'=>"if (confirm('".$text['confirm-delete']."')) { document.getElementById('frm').submit(); } else { this.blur(); return false; }",'style'=>'margin-right: 15px;']);
}
echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td align='left' colspan='2'>\n";
if ($action == "add") {
echo $text['label-add-note']."<br /><br />\n";
echo $text['label-add-note']."<br /><br />\n";
}
if ($action == "update") {
echo $text['label-edit-note']."<br /><br />\n";
echo $text['label-edit-note']."<br /><br />\n";
}
echo "</td>\n";
echo "</tr>\n";
+92 -65
View File
@@ -9,14 +9,34 @@ if (!class_exists('call_block')) {
class call_block {
/**
* Called when the object is created
* declare private variables
*/
private $app_name;
private $app_uuid;
private $permission_prefix;
private $list_page;
private $table;
private $uuid_prefix;
private $enabled_prefix;
/**
* called when the object is created
*/
public function __construct() {
//assign private variables
$this->app_name = 'call_block';
$this->app_uuid = '9ed63276-e085-4897-839c-4f2e36d92d6c';
$this->permission_prefix = 'call_block';
$this->list_page = 'call_block.php';
$this->table = 'call_block';
$this->uuid_prefix = 'call_block_';
$this->enabled_prefix = 'call_block_';
}
/**
* Called when there are no references to a particular object
* called when there are no references to a particular object
* unset the variables used in the class
*/
public function __destruct() {
@@ -26,10 +46,10 @@ if (!class_exists('call_block')) {
}
/**
* delete call block
* delete records
*/
public function delete($call_blocks) {
if (permission_exists('call_block_delete')) {
public function delete($records) {
if (permission_exists($this->permission_prefix.'_delete')) {
//add multi-lingual support
$language = new text;
@@ -39,40 +59,44 @@ if (!class_exists('call_block')) {
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: call_block.php');
header('Location: '.$this->list_page);
exit;
}
//delete multiple call blocks
if (is_array($call_blocks) && @sizeof($call_blocks) != 0) {
//delete multiple records
if (is_array($records) && @sizeof($records) != 0) {
//build the delete array
foreach($call_blocks as $x => $row) {
if ($row['checked'] == 'true' && is_uuid($row['call_block_uuid'])) {
$array['call_block'][$x]['call_block_uuid'] = $row['call_block_uuid'];
$array['call_block'][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
foreach($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
$array[$this->table][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
}
}
//delete the checked rows
if (is_array($array) && @sizeof($array) != 0) {
//execute delete
$database = new database;
$database->app_name = 'call_block';
$database->app_uuid = '9ed63276-e085-4897-839c-4f2e36d92d6c';
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->delete($array);
unset($array);
//set message
message::add($text['message-delete']);
}
unset($call_blocks);
unset($records);
}
}
}
/**
* toggle call block
* toggle records
*/
public function toggle($call_blocks) {
if (permission_exists('call_block_edit')) {
public function toggle($records) {
if (permission_exists($this->permission_prefix.'_edit')) {
//add multi-lingual support
$language = new text;
@@ -82,28 +106,29 @@ if (!class_exists('call_block')) {
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: call_block.php');
header('Location: '.$this->list_page);
exit;
}
//toggle the checked call blocks
if (is_array($call_blocks) && @sizeof($call_blocks) != 0) {
//get current enabled state of checked call block
foreach($call_blocks as $x => $row) {
if ($row['checked'] == 'true' && is_uuid($row['call_block_uuid'])) {
$call_block_uuids[] = "call_block_uuid = '".$row['call_block_uuid']."'";
//toggle the checked records
if (is_array($records) && @sizeof($records) != 0) {
//get current enabled state
foreach($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'";
}
}
if (is_array($call_block_uuids) && @sizeof($call_block_uuids) != 0) {
$sql = "select call_block_uuid, call_block_enabled from v_call_block ";
if (is_array($record_uuids) && @sizeof($record_uuids) != 0) {
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->enabled_prefix."enabled as enabled from v_".$this->table." ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql .= "and ( ".implode(' or ', $call_block_uuids)." ) ";
$sql .= "and ( ".implode(' or ', $record_uuids)." ) ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
$call_block_states[$row['call_block_uuid']] = $row['call_block_enabled'];
$states[$row['uuid']] = $row['enabled'];
}
}
unset($sql, $parameters, $rows, $row);
@@ -111,34 +136,36 @@ if (!class_exists('call_block')) {
//build update array
$x = 0;
foreach($call_block_states as $call_block_uuid => $call_block_state) {
$array['call_block'][$x]['call_block_uuid'] = $call_block_uuid;
$array['call_block'][$x]['call_block_enabled'] = $call_block_state == 'true' ? 'false' : 'true';
foreach($states as $uuid => $state) {
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
$array[$this->table][$x][$this->enabled_prefix.'enabled'] = $state == 'true' ? 'false' : 'true';
$x++;
}
//save the changes
if (is_array($array) && @sizeof($array) != 0) {
//save the array
$database = new database;
$database->app_name = 'call_block';
$database->app_uuid = '9ed63276-e085-4897-839c-4f2e36d92d6c';
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->save($array);
unset($array);
//set message
message::add($text['message-toggle']);
}
unset($call_blocks, $call_block_states);
unset($records, $states);
}
}
}
/**
* copy call blocks
* copy records
*/
public function copy($call_blocks) {
if (permission_exists('call_block_add')) {
public function copy($records) {
if (permission_exists($this->permission_prefix.'_add')) {
//add multi-lingual support
$language = new text;
@@ -148,55 +175,60 @@ if (!class_exists('call_block')) {
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: call_block.php');
header('Location: '.$this->list_page);
exit;
}
//copy the checked call blocks
if (is_array($call_blocks) && @sizeof($call_blocks) != 0) {
//copy the checked records
if (is_array($records) && @sizeof($records) != 0) {
//get checked call blocks
foreach($call_blocks as $x => $row) {
if ($row['checked'] == 'true' && is_uuid($row['call_block_uuid'])) {
$call_block_uuids[] = "call_block_uuid = '".$row['call_block_uuid']."'";
//get checked records
foreach($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'";
}
}
//create insert array from existing data
if (is_array($call_block_uuids) && @sizeof($call_block_uuids) != 0) {
$sql = "select * from v_call_block ";
if (is_array($record_uuids) && @sizeof($record_uuids) != 0) {
$sql = "select * from v_".$this->table." ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql .= "and ( ".implode(' or ', $call_block_uuids)." ) ";
$sql .= "and ( ".implode(' or ', $record_uuids)." ) ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $x => $row) {
$array['call_block'][$x]['call_block_uuid'] = uuid();
$array['call_block'][$x]['domain_uuid'] = $row['domain_uuid'];
$array['call_block'][$x]['call_block_name'] = $row['call_block_name'];
$array['call_block'][$x]['call_block_number'] = $row['call_block_number'];
$array['call_block'][$x]['call_block_count'] = 0;
$array['call_block'][$x]['call_block_action'] = $row['call_block_action'];
$array['call_block'][$x]['date_added'] = $row['date_added'];
$array['call_block'][$x]['call_block_enabled'] = $row['call_block_enabled'];
$array['call_block'][$x]['call_block_description'] = trim($row['call_block_description'].' ('.$text['label-copy'].')');
$new_uuid = uuid();
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $new_uuid;
$array[$this->table][$x]['domain_uuid'] = $row['domain_uuid'];
$array[$this->table][$x]['call_block_name'] = $row['call_block_name'];
$array[$this->table][$x]['call_block_number'] = $row['call_block_number'];
$array[$this->table][$x]['call_block_count'] = 0;
$array[$this->table][$x]['call_block_action'] = $row['call_block_action'];
$array[$this->table][$x]['date_added'] = $row['date_added'];
$array[$this->table][$x]['call_block_enabled'] = $row['call_block_enabled'];
$array[$this->table][$x]['call_block_description'] = trim($row['call_block_description'].' ('.$text['label-copy'].')');
}
}
unset($sql, $parameters, $rows, $row);
}
//save the changes and set the message
if (is_array($array) && @sizeof($array) != 0) {
//save the array
$database = new database;
$database->app_name = 'call_block';
$database->app_uuid = '9ed63276-e085-4897-839c-4f2e36d92d6c';
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->save($array);
unset($array);
//set message
message::add($text['message-copy']);
}
unset($call_blocks);
unset($records);
}
}
@@ -205,9 +237,4 @@ if (!class_exists('call_block')) {
}
}
/*
$obj = new call_block;
$obj->delete();
*/
?>