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

View File

@ -51,6 +51,21 @@
if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
//delete the access control
if (permission_exists('access_control_delete')) {
if ($_POST['action'] == 'delete' && is_uuid($access_control_uuid)) {
//prepare
$array[0]['checked'] = 'true';
$array[0]['uuid'] = $access_control_uuid;
//delete
$obj = new access_controls;
$obj->delete($array);
//redirect
header('Location: access_controls.php');
exit;
}
}
//get the primary key //get the primary key
if ($action == "update") { if ($action == "update") {
$access_control_uuid = $_POST["access_control_uuid"]; $access_control_uuid = $_POST["access_control_uuid"];
@ -90,15 +105,17 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
$execute = true; $execute = true;
$access_control_uuid = uuid(); $access_control_uuid = uuid();
//add the message //set the message
message::add($text['message-add']); message::add($text['message-add']);
//set redirect url
$redirect_url = 'access_control_edit.php?id='.$access_control_uuid;
} }
if ($action == "update" && permission_exists('access_control_edit')) { if ($action == "update" && permission_exists('access_control_edit')) {
$execute = true; $execute = true;
//$access_control_uuid //already set
//add the message //set the message
message::add($text['message-update']); message::add($text['message-update']);
} }
@ -123,11 +140,11 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
} }
//redirect the user //redirect the user
header("Location: access_controls.php"); header('Location: '.($redirect_url ? $redirect_url : 'access_controls.php'));
return; exit;
}
} //if ($_POST["persistformvar"] != "true") }
} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
//pre-populate the form //pre-populate the form
if (count($_GET) > 0 && $_POST["persistformvar"] != "true" && is_uuid($_GET["id"])) { if (count($_GET) > 0 && $_POST["persistformvar"] != "true" && is_uuid($_GET["id"])) {
@ -158,7 +175,10 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
echo "<tr>\n"; echo "<tr>\n";
echo "<td align='left' width='30%' nowrap='nowrap' valign='top'><b>".$text['title-access_control']."</b><br><br></td>\n"; echo "<td align='left' width='30%' nowrap='nowrap' valign='top'><b>".$text['title-access_control']."</b><br><br></td>\n";
echo "<td width='70%' align='right' valign='top'>\n"; echo "<td width='70%' align='right' valign='top'>\n";
echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='access_controls.php'\" value='".$text['button-back']."'>"; echo " <input type='button' class='btn' style='margin-right: 15px;' name='' alt='".$text['button-back']."' onclick=\"window.location='access_controls.php'\" value='".$text['button-back']."'>";
if ($action == 'update' && permission_exists('access_control_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']."'>"; echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>";
echo "</td>\n"; echo "</td>\n";
echo "</tr>\n"; echo "</tr>\n";

View File

@ -82,7 +82,6 @@
$sql_search .= "or lower(access_control_default) like :search "; $sql_search .= "or lower(access_control_default) like :search ";
$sql_search .= "or lower(access_control_description) like :search "; $sql_search .= "or lower(access_control_description) like :search ";
$sql_search .= ") "; $sql_search .= ") ";
$parameters['search'] = '%'.$search.'%'; $parameters['search'] = '%'.$search.'%';
} }
@ -169,7 +168,7 @@
echo "<tr class='list-row' href='".$list_row_url."'>\n"; echo "<tr class='list-row' href='".$list_row_url."'>\n";
echo " <td class='checkbox'>\n"; echo " <td class='checkbox'>\n";
echo " <input type='checkbox' name='access_controls[".$x."][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n"; echo " <input type='checkbox' name='access_controls[".$x."][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
echo " <input type='hidden' name='access_controls[".$x."][access_control_uuid]' value='".escape($row['access_control_uuid'])."' />\n"; echo " <input type='hidden' name='access_controls[".$x."][uuid]' value='".escape($row['access_control_uuid'])."' />\n";
echo " </td>\n"; echo " </td>\n";
echo " <td><a href='".$list_row_url."'>".escape($row['access_control_name'])."</a></td>\n"; echo " <td><a href='".$list_row_url."'>".escape($row['access_control_name'])."</a></td>\n";
echo " <td>".escape($row['access_control_default'])."</td>\n"; echo " <td>".escape($row['access_control_default'])."</td>\n";

View File

@ -9,14 +9,34 @@ if (!class_exists('access_controls')) {
class access_controls { class access_controls {
/** /**
* 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() { public function __construct() {
//assign private variables
$this->app_name = 'access_controls';
$this->app_uuid = '1416a250-f6e1-4edc-91a6-5c9b883638fd';
$this->permission_prefix = 'access_control';
$this->list_page = 'access_controls.php';
$this->table = 'access_controls';
$this->uuid_prefix = 'access_control_';
$this->enabled_prefix = 'access_control_';
} }
/** /**
* 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 * unset the variables used in the class
*/ */
public function __destruct() { public function __destruct() {
@ -26,10 +46,10 @@ if (!class_exists('access_controls')) {
} }
/** /**
* delete access controls * delete records
*/ */
public function delete($access_controls) { public function delete($records) {
if (permission_exists('access_control_delete') && permission_exists('access_control_node_delete')) { if (permission_exists($this->permission_prefix.'_delete')) {
//add multi-lingual support //add multi-lingual support
$language = new text; $language = new text;
@ -39,40 +59,44 @@ if (!class_exists('access_controls')) {
$token = new token; $token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) { if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative'); message::add($text['message-invalid_token'],'negative');
header('Location: access_controls.php'); header('Location: '.$this->list_page);
exit; exit;
} }
//delete multiple access controls //delete multiple records
if (is_array($access_controls) && @sizeof($access_controls) != 0) { if (is_array($records) && @sizeof($records) != 0) {
//build the delete array //build the delete array
foreach($access_controls as $x => $row) { foreach($records as $x => $record) {
if ($row['checked'] == 'true' && is_uuid($row['access_control_uuid'])) { if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$array['access_controls'][$x]['access_control_uuid'] = $row['access_control_uuid']; $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
$array['access_control_nodes'][$x]['access_control_uuid'] = $row['access_control_uuid']; $array['access_control_nodes'][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
} }
} }
//delete the checked rows //delete the checked rows
if (is_array($array) && @sizeof($array) != 0) { if (is_array($array) && @sizeof($array) != 0) {
//execute delete //execute delete
$database = new database; $database = new database;
$database->app_name = 'access_controls'; $database->app_name = $this->app_name;
$database->app_uuid = '1416a250-f6e1-4edc-91a6-5c9b883638fd'; $database->app_uuid = $this->app_uuid;
$database->delete($array); $database->delete($array);
unset($array); unset($array);
//set message //set message
message::add($text['message-delete']); message::add($text['message-delete']);
} }
unset($access_controls); unset($records);
} }
} }
} }
/** /**
* copy access controls * copy records
*/ */
public function copy($access_controls) { public function copy($records) {
if (permission_exists('access_control_add') && permission_exists('access_control_node_add')) { if (permission_exists($this->permission_prefix.'_add')) {
//add multi-lingual support //add multi-lingual support
$language = new text; $language = new text;
@ -82,44 +106,44 @@ if (!class_exists('access_controls')) {
$token = new token; $token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) { if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative'); message::add($text['message-invalid_token'],'negative');
header('Location: access_controls.php'); header('Location: '.$this->list_page);
exit; exit;
} }
//copy the checked access controls //copy the checked records
if (is_array($access_controls) && @sizeof($access_controls) != 0) { if (is_array($records) && @sizeof($records) != 0) {
//get checked access controls //get checked records
foreach($access_controls as $x => $row) { foreach($records as $x => $record) {
if ($row['checked'] == 'true' && is_uuid($row['access_control_uuid'])) { if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$access_control_uuids[] = "access_control_uuid = '".$row['access_control_uuid']."'"; $record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'";
} }
} }
//create insert array from existing data //create insert array from existing data
if (is_array($access_control_uuids) && @sizeof($access_control_uuids) != 0) { if (is_array($record_uuids) && @sizeof($record_uuids) != 0) {
$sql = "select * from v_access_controls "; $sql = "select * from v_".$this->table." ";
$sql .= "where ".implode(' or ', $access_control_uuids)." "; $sql .= "where ".implode(' or ', $record_uuids)." ";
$database = new database; $database = new database;
$rows = $database->select($sql, $parameters, 'all'); $rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) { if (is_array($rows) && @sizeof($rows) != 0) {
$y = 0; $y = 0;
foreach ($rows as $x => $row) { foreach ($rows as $x => $row) {
//access control //primary table
$access_control_uuid = uuid(); $primary_uuid = uuid();
$array['access_controls'][$x]['access_control_uuid'] = $access_control_uuid; $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $primary_uuid;
$array['access_controls'][$x]['access_control_name'] = $row['access_control_name']; $array[$this->table][$x]['access_control_name'] = $row['access_control_name'];
$array['access_controls'][$x]['access_control_default'] = $row['access_control_default']; $array[$this->table][$x]['access_control_default'] = $row['access_control_default'];
$array['access_controls'][$x]['access_control_description'] = trim($row['access_control_description'].' ('.$text['label-copy'].')'); $array[$this->table][$x]['access_control_description'] = trim($row['access_control_description'].' ('.$text['label-copy'].')');
//access control nodes //sub table
$sql_2 = "select * from v_access_control_nodes where access_control_uuid = :access_control_uuid"; $sql_2 = "select * from v_access_control_nodes where access_control_uuid = :access_control_uuid";
$parameters_2['access_control_uuid'] = $row['access_control_uuid']; $parameters_2['access_control_uuid'] = $row['access_control_uuid'];
$database = new database; $database = new database;
$rows_2 = $database->select($sql_2, $parameters_2, 'all'); $rows_2 = $database->select($sql_2, $parameters_2, 'all');
if (is_array($rows_2) && @sizeof($rows_2) != 0) { if (is_array($rows_2) && @sizeof($rows_2) != 0) {
foreach ($rows_2 as $row_2) { foreach ($rows_2 as $row_2) {
$access_control_node_uuid = uuid(); $array['access_control_nodes'][$y]['access_control_node_uuid'] = uuid();
$array['access_control_nodes'][$y]['access_control_node_uuid'] = $access_control_node_uuid; $array['access_control_nodes'][$y]['access_control_uuid'] = $primary_uuid;
$array['access_control_nodes'][$y]['access_control_uuid'] = $access_control_uuid;
$array['access_control_nodes'][$y]['node_type'] = $row_2['node_type']; $array['access_control_nodes'][$y]['node_type'] = $row_2['node_type'];
$array['access_control_nodes'][$y]['node_cidr'] = $row_2['node_cidr']; $array['access_control_nodes'][$y]['node_cidr'] = $row_2['node_cidr'];
$array['access_control_nodes'][$y]['node_domain'] = $row_2['node_domain']; $array['access_control_nodes'][$y]['node_domain'] = $row_2['node_domain'];
@ -132,19 +156,22 @@ if (!class_exists('access_controls')) {
} }
unset($sql, $parameters, $rows, $row); unset($sql, $parameters, $rows, $row);
} }
//save the changes and set the message //save the changes and set the message
if (is_array($array) && @sizeof($array) != 0) { if (is_array($array) && @sizeof($array) != 0) {
//save the array //save the array
$database = new database; $database = new database;
$database->app_name = 'access_controls'; $database->app_name = $this->app_name;
$database->app_uuid = '1416a250-f6e1-4edc-91a6-5c9b883638fd'; $database->app_uuid = $this->app_uuid;
$database->save($array); $database->save($array);
unset($array); unset($array);
//set message //set message
message::add($text['message-copy']); message::add($text['message-copy']);
} }
unset($access_controls); unset($records);
} }
} }
@ -153,9 +180,4 @@ if (!class_exists('access_controls')) {
} }
} }
/*
$obj = new access_controls;
$obj->delete();
*/
?> ?>

View File

@ -62,11 +62,11 @@
if (permission_exists('bridge_delete')) { if (permission_exists('bridge_delete')) {
if ($_POST['action'] == 'delete' && is_uuid($bridge_uuid)) { if ($_POST['action'] == 'delete' && is_uuid($bridge_uuid)) {
//prepare //prepare
$bridges[0]['checked'] = 'true'; $array[0]['checked'] = 'true';
$bridges[0]['bridge_uuid'] = $bridge_uuid; $array[0]['uuid'] = $bridge_uuid;
//delete //delete
$obj = new bridges; $obj = new bridges;
$obj->delete($bridges); $obj->delete($array);
//redirect //redirect
header('Location: bridges.php'); header('Location: bridges.php');
exit; exit;
@ -169,8 +169,8 @@
echo "<td align='left' width='30%' nowrap='nowrap' valign='top'><b>".$text['title-bridge']."</b><br><br></td>\n"; echo "<td align='left' width='30%' nowrap='nowrap' valign='top'><b>".$text['title-bridge']."</b><br><br></td>\n";
echo "<td width='70%' align='right' valign='top'>\n"; echo "<td width='70%' align='right' valign='top'>\n";
echo "<a href='bridges.php'><button type='button' class='btn btn-default' style='margin-right: 15px;' alt='".$text['button-back']."'>".$text['button-back']."</button></a>"; echo "<a href='bridges.php'><button type='button' class='btn btn-default' style='margin-right: 15px;' alt='".$text['button-back']."'>".$text['button-back']."</button></a>";
if ($action == 'update') { if ($action == 'update' && permission_exists('bridge_delete')) {
echo "<button type='submit' class='btn btn-default' style='margin-right: 15px;' name='action' value='delete' onclick=\"if (confirm('".$text['confirm-delete']."')) { document.getElementById('frm').submit(); } else { this.blur(); return false; }\">".$text['button-delete']."</button>"; 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 "<button type='submit' class='btn btn-default' name='action' value='save'>".$text['button-save']."</button>"; echo "<button type='submit' class='btn btn-default' name='action' value='save'>".$text['button-save']."</button>";
echo "</td>\n"; echo "</td>\n";

View File

@ -94,7 +94,6 @@
$sql_search .= "or lower(bridge_destination) like :search "; $sql_search .= "or lower(bridge_destination) like :search ";
$sql_search .= "or lower(bridge_enabled) like :search "; $sql_search .= "or lower(bridge_enabled) like :search ";
$sql_search .= ") "; $sql_search .= ") ";
$parameters['search'] = '%'.$search.'%'; $parameters['search'] = '%'.$search.'%';
} }
@ -208,7 +207,7 @@
echo "<tr class='list-row' href='".$list_row_url."'>\n"; echo "<tr class='list-row' href='".$list_row_url."'>\n";
echo " <td class='checkbox'>\n"; echo " <td class='checkbox'>\n";
echo " <input type='checkbox' name='bridges[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n"; echo " <input type='checkbox' name='bridges[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
echo " <input type='hidden' name='bridges[$x][bridge_uuid]' value='".escape($row['bridge_uuid'])."' />\n"; echo " <input type='hidden' name='bridges[$x][uuid]' value='".escape($row['bridge_uuid'])."' />\n";
echo " </td>\n"; echo " </td>\n";
if ($_GET['show'] == "all" && permission_exists('bridge_all')) { if ($_GET['show'] == "all" && permission_exists('bridge_all')) {
echo " <td>".escape($_SESSION['domains'][$row['domain_uuid']]['domain_name'])."</td>\n"; echo " <td>".escape($_SESSION['domains'][$row['domain_uuid']]['domain_name'])."</td>\n";

View File

@ -9,14 +9,34 @@ if (!class_exists('bridges')) {
class bridges { class bridges {
/** /**
* 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() { public function __construct() {
//assign private variables
$this->app_name = 'bridges';
$this->app_uuid = 'a6a7c4c5-340a-43ce-bcbc-2ed9bab8659d';
$this->permission_prefix = 'bridge';
$this->list_page = 'bridges.php';
$this->table = 'bridges';
$this->uuid_prefix = 'bridge_';
$this->enabled_prefix = 'bridge_';
} }
/** /**
* 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 * unset the variables used in the class
*/ */
public function __destruct() { public function __destruct() {
@ -26,10 +46,10 @@ if (!class_exists('bridges')) {
} }
/** /**
* delete bridges * delete records
*/ */
public function delete($bridges) { public function delete($records) {
if (permission_exists('bridge_delete')) { if (permission_exists($this->permission_prefix.'_delete')) {
//add multi-lingual support //add multi-lingual support
$language = new text; $language = new text;
@ -39,40 +59,44 @@ if (!class_exists('bridges')) {
$token = new token; $token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) { if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative'); message::add($text['message-invalid_token'],'negative');
header('Location: bridges.php'); header('Location: '.$this->list_page);
exit; exit;
} }
//delete multiple bridges //delete multiple records
if (is_array($bridges) && @sizeof($bridges) != 0) { if (is_array($records) && @sizeof($records) != 0) {
//build the delete array //build the delete array
foreach($bridges as $x => $row) { foreach($records as $x => $record) {
if ($row['checked'] == 'true' && is_uuid($row['bridge_uuid'])) { if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$array['bridges'][$x]['bridge_uuid'] = $row['bridge_uuid']; $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
$array['bridges'][$x]['domain_uuid'] = $_SESSION['domain_uuid']; $array[$this->table][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
} }
} }
//delete the checked rows //delete the checked rows
if (is_array($array) && @sizeof($array) != 0) { if (is_array($array) && @sizeof($array) != 0) {
//execute delete //execute delete
$database = new database; $database = new database;
$database->app_name = 'bridges'; $database->app_name = $this->app_name;
$database->app_uuid = 'a6a7c4c5-340a-43ce-bcbc-2ed9bab8659d'; $database->app_uuid = $this->app_uuid;
$database->delete($array); $database->delete($array);
unset($array); unset($array);
//set message //set message
message::add($text['message-delete']); message::add($text['message-delete']);
} }
unset($bridges); unset($records);
} }
} }
} }
/** /**
* toggle bridges * toggle records
*/ */
public function toggle($bridges) { public function toggle($records) {
if (permission_exists('bridge_edit')) { if (permission_exists($this->permission_prefix.'_edit')) {
//add multi-lingual support //add multi-lingual support
$language = new text; $language = new text;
@ -82,28 +106,29 @@ if (!class_exists('bridges')) {
$token = new token; $token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) { if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative'); message::add($text['message-invalid_token'],'negative');
header('Location: bridges.php'); header('Location: '.$this->list_page);
exit; exit;
} }
//toggle the checked bridges //toggle the checked records
if (is_array($bridges) && @sizeof($bridges) != 0) { if (is_array($records) && @sizeof($records) != 0) {
//get current enabled state of checked bridges
foreach($bridges as $x => $row) { //get current enabled state
if ($row['checked'] == 'true' && is_uuid($row['bridge_uuid'])) { foreach($records as $x => $record) {
$bridge_uuids[] = "bridge_uuid = '".$row['bridge_uuid']."'"; if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'";
} }
} }
if (is_array($bridge_uuids) && @sizeof($bridge_uuids) != 0) { if (is_array($record_uuids) && @sizeof($record_uuids) != 0) {
$sql = "select bridge_uuid, bridge_enabled from v_bridges "; $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 .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql .= "and ( ".implode(' or ', $bridge_uuids)." ) "; $sql .= "and ( ".implode(' or ', $record_uuids)." ) ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database; $database = new database;
$rows = $database->select($sql, $parameters, 'all'); $rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) { if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) { foreach ($rows as $row) {
$bridge_states[$row['bridge_uuid']] = $row['bridge_enabled']; $states[$row['uuid']] = $row['enabled'];
} }
} }
unset($sql, $parameters, $rows, $row); unset($sql, $parameters, $rows, $row);
@ -111,34 +136,36 @@ if (!class_exists('bridges')) {
//build update array //build update array
$x = 0; $x = 0;
foreach($bridge_states as $bridge_uuid => $bridge_state) { foreach($states as $uuid => $state) {
$array['bridges'][$x]['bridge_uuid'] = $bridge_uuid; $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
$array['bridges'][$x]['bridge_enabled'] = $bridge_state == 'true' ? 'false' : 'true'; $array[$this->table][$x][$this->enabled_prefix.'enabled'] = $state == 'true' ? 'false' : 'true';
$x++; $x++;
} }
//save the changes //save the changes
if (is_array($array) && @sizeof($array) != 0) { if (is_array($array) && @sizeof($array) != 0) {
//save the array //save the array
$database = new database; $database = new database;
$database->app_name = 'bridges'; $database->app_name = $this->app_name;
$database->app_uuid = 'a6a7c4c5-340a-43ce-bcbc-2ed9bab8659d'; $database->app_uuid = $this->app_uuid;
$database->save($array); $database->save($array);
unset($array); unset($array);
//set message //set message
message::add($text['message-toggle']); message::add($text['message-toggle']);
} }
unset($bridges, $bridge_states); unset($records, $states);
} }
} }
} }
/** /**
* copy bridges * copy records
*/ */
public function copy($bridges) { public function copy($records) {
if (permission_exists('bridge_add')) { if (permission_exists($this->permission_prefix.'_add')) {
//add multi-lingual support //add multi-lingual support
$language = new text; $language = new text;
@ -148,52 +175,57 @@ if (!class_exists('bridges')) {
$token = new token; $token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) { if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative'); message::add($text['message-invalid_token'],'negative');
header('Location: bridges.php'); header('Location: '.$this->list_page);
exit; exit;
} }
//copy the checked bridges //copy the checked records
if (is_array($bridges) && @sizeof($bridges) != 0) { if (is_array($records) && @sizeof($records) != 0) {
//get checked bridges //get checked records
foreach($bridges as $x => $row) { foreach($records as $x => $record) {
if ($row['checked'] == 'true' && is_uuid($row['bridge_uuid'])) { if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$bridge_uuids[] = "bridge_uuid = '".$row['bridge_uuid']."'"; $record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'";
} }
} }
//create insert array from existing data //create insert array from existing data
if (is_array($bridge_uuids) && @sizeof($bridge_uuids) != 0) { if (is_array($record_uuids) && @sizeof($record_uuids) != 0) {
$sql = "select * from v_bridges "; $sql = "select * from v_".$this->table." ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) "; $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql .= "and ( ".implode(' or ', $bridge_uuids)." ) "; $sql .= "and ( ".implode(' or ', $record_uuids)." ) ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database; $database = new database;
$rows = $database->select($sql, $parameters, 'all'); $rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) { if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $x => $row) { foreach ($rows as $x => $row) {
$array['bridges'][$x]['bridge_uuid'] = uuid(); $new_uuid = uuid();
$array['bridges'][$x]['domain_uuid'] = $row['domain_uuid']; $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $new_uuid;
$array['bridges'][$x]['bridge_name'] = $row['bridge_name']; $array[$this->table][$x]['domain_uuid'] = $row['domain_uuid'];
$array['bridges'][$x]['bridge_destination'] = $row['bridge_destination']; $array[$this->table][$x]['bridge_name'] = $row['bridge_name'];
$array['bridges'][$x]['bridge_enabled'] = $row['bridge_enabled']; $array[$this->table][$x]['bridge_destination'] = $row['bridge_destination'];
$array['bridges'][$x]['bridge_description'] = trim($row['bridge_description'].' ('.$text['label-copy'].')'); $array[$this->table][$x]['bridge_enabled'] = $row['bridge_enabled'];
$array[$this->table][$x]['bridge_description'] = trim($row['bridge_description'].' ('.$text['label-copy'].')');
} }
} }
unset($sql, $parameters, $rows, $row); unset($sql, $parameters, $rows, $row);
} }
//save the changes and set the message //save the changes and set the message
if (is_array($array) && @sizeof($array) != 0) { if (is_array($array) && @sizeof($array) != 0) {
//save the array //save the array
$database = new database; $database = new database;
$database->app_name = 'bridges'; $database->app_name = $this->app_name;
$database->app_uuid = 'a6a7c4c5-340a-43ce-bcbc-2ed9bab8659d'; $database->app_uuid = $this->app_uuid;
$database->save($array); $database->save($array);
unset($array); unset($array);
//set message //set message
message::add($text['message-copy']); message::add($text['message-copy']);
} }
unset($bridges); unset($records);
} }
} }
@ -202,9 +234,4 @@ if (!class_exists('bridges')) {
} }
} }
/*
$obj = new bridges;
$obj->delete();
*/
?> ?>

View File

@ -95,7 +95,6 @@
$sql_search .= "or lower(call_block_number) like :search "; $sql_search .= "or lower(call_block_number) like :search ";
$sql_search .= "or lower(call_block_description) like :search "; $sql_search .= "or lower(call_block_description) like :search ";
$sql_search .= ") "; $sql_search .= ") ";
$parameters['search'] = '%'.$search.'%'; $parameters['search'] = '%'.$search.'%';
} }
@ -148,16 +147,6 @@
if (permission_exists('call_block_delete')) { 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; }"]); 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 "<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 "<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)]); 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 "<tr class='list-row' href='".$list_row_url."'>\n";
echo " <td class='checkbox'>\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='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>\n";
echo " <td>"; echo " <td>";
if (permission_exists('call_block_edit')) { if (permission_exists('call_block_edit')) {

View File

@ -87,9 +87,19 @@
//handle the http post //handle the http post
if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
$msg = ''; //delete the call block
if ($action == "update") { if (permission_exists('call_block_delete')) {
//$call_block_uuid = check_str($_POST["call_block_uuid"]); 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 //validate the token
@ -101,6 +111,7 @@
} }
//check for all required data //check for all required data
$msg = '';
if (strlen($call_block_name) == 0) { $msg .= $text['label-provide-name']."<br>\n"; } if (strlen($call_block_name) == 0) { $msg .= $text['label-provide-name']."<br>\n"; }
if ($action == "add") { if ($action == "add") {
if (strlen($call_block_number) == 0) { $msg .= $text['label-provide-number']."<br>\n"; } if (strlen($call_block_number) == 0) { $msg .= $text['label-provide-number']."<br>\n"; }
@ -255,8 +266,6 @@
echo " }\n"; echo " }\n";
echo "</script>"; echo "</script>";
// Show last 5-10 calls first, with add button
echo "<form method='post' name='frm' action=''>\n"; echo "<form method='post' name='frm' action=''>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n"; echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n"; echo "<tr>\n";
@ -267,7 +276,10 @@
echo "<td align='left' width='30%' nowrap='nowrap'><b>".$text['label-edit-edit']."</b></td>\n"; echo "<td align='left' width='30%' nowrap='nowrap'><b>".$text['label-edit-edit']."</b></td>\n";
} }
echo "<td width='70%' align='right'>"; 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 " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
echo "</td>\n"; echo "</td>\n";
echo "</tr>\n"; echo "</tr>\n";

View File

@ -9,14 +9,34 @@ if (!class_exists('call_block')) {
class 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() { 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 * unset the variables used in the class
*/ */
public function __destruct() { public function __destruct() {
@ -26,10 +46,10 @@ if (!class_exists('call_block')) {
} }
/** /**
* delete call block * delete records
*/ */
public function delete($call_blocks) { public function delete($records) {
if (permission_exists('call_block_delete')) { if (permission_exists($this->permission_prefix.'_delete')) {
//add multi-lingual support //add multi-lingual support
$language = new text; $language = new text;
@ -39,40 +59,44 @@ if (!class_exists('call_block')) {
$token = new token; $token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) { if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative'); message::add($text['message-invalid_token'],'negative');
header('Location: call_block.php'); header('Location: '.$this->list_page);
exit; exit;
} }
//delete multiple call blocks //delete multiple records
if (is_array($call_blocks) && @sizeof($call_blocks) != 0) { if (is_array($records) && @sizeof($records) != 0) {
//build the delete array //build the delete array
foreach($call_blocks as $x => $row) { foreach($records as $x => $record) {
if ($row['checked'] == 'true' && is_uuid($row['call_block_uuid'])) { if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$array['call_block'][$x]['call_block_uuid'] = $row['call_block_uuid']; $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
$array['call_block'][$x]['domain_uuid'] = $_SESSION['domain_uuid']; $array[$this->table][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
} }
} }
//delete the checked rows //delete the checked rows
if (is_array($array) && @sizeof($array) != 0) { if (is_array($array) && @sizeof($array) != 0) {
//execute delete //execute delete
$database = new database; $database = new database;
$database->app_name = 'call_block'; $database->app_name = $this->app_name;
$database->app_uuid = '9ed63276-e085-4897-839c-4f2e36d92d6c'; $database->app_uuid = $this->app_uuid;
$database->delete($array); $database->delete($array);
unset($array); unset($array);
//set message //set message
message::add($text['message-delete']); message::add($text['message-delete']);
} }
unset($call_blocks); unset($records);
} }
} }
} }
/** /**
* toggle call block * toggle records
*/ */
public function toggle($call_blocks) { public function toggle($records) {
if (permission_exists('call_block_edit')) { if (permission_exists($this->permission_prefix.'_edit')) {
//add multi-lingual support //add multi-lingual support
$language = new text; $language = new text;
@ -82,28 +106,29 @@ if (!class_exists('call_block')) {
$token = new token; $token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) { if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative'); message::add($text['message-invalid_token'],'negative');
header('Location: call_block.php'); header('Location: '.$this->list_page);
exit; exit;
} }
//toggle the checked call blocks //toggle the checked records
if (is_array($call_blocks) && @sizeof($call_blocks) != 0) { if (is_array($records) && @sizeof($records) != 0) {
//get current enabled state of checked call block
foreach($call_blocks as $x => $row) { //get current enabled state
if ($row['checked'] == 'true' && is_uuid($row['call_block_uuid'])) { foreach($records as $x => $record) {
$call_block_uuids[] = "call_block_uuid = '".$row['call_block_uuid']."'"; 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) { if (is_array($record_uuids) && @sizeof($record_uuids) != 0) {
$sql = "select call_block_uuid, call_block_enabled from v_call_block "; $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 .= "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']; $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database; $database = new database;
$rows = $database->select($sql, $parameters, 'all'); $rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) { if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) { 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); unset($sql, $parameters, $rows, $row);
@ -111,34 +136,36 @@ if (!class_exists('call_block')) {
//build update array //build update array
$x = 0; $x = 0;
foreach($call_block_states as $call_block_uuid => $call_block_state) { foreach($states as $uuid => $state) {
$array['call_block'][$x]['call_block_uuid'] = $call_block_uuid; $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
$array['call_block'][$x]['call_block_enabled'] = $call_block_state == 'true' ? 'false' : 'true'; $array[$this->table][$x][$this->enabled_prefix.'enabled'] = $state == 'true' ? 'false' : 'true';
$x++; $x++;
} }
//save the changes //save the changes
if (is_array($array) && @sizeof($array) != 0) { if (is_array($array) && @sizeof($array) != 0) {
//save the array //save the array
$database = new database; $database = new database;
$database->app_name = 'call_block'; $database->app_name = $this->app_name;
$database->app_uuid = '9ed63276-e085-4897-839c-4f2e36d92d6c'; $database->app_uuid = $this->app_uuid;
$database->save($array); $database->save($array);
unset($array); unset($array);
//set message //set message
message::add($text['message-toggle']); message::add($text['message-toggle']);
} }
unset($call_blocks, $call_block_states); unset($records, $states);
} }
} }
} }
/** /**
* copy call blocks * copy records
*/ */
public function copy($call_blocks) { public function copy($records) {
if (permission_exists('call_block_add')) { if (permission_exists($this->permission_prefix.'_add')) {
//add multi-lingual support //add multi-lingual support
$language = new text; $language = new text;
@ -148,55 +175,60 @@ if (!class_exists('call_block')) {
$token = new token; $token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) { if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative'); message::add($text['message-invalid_token'],'negative');
header('Location: call_block.php'); header('Location: '.$this->list_page);
exit; exit;
} }
//copy the checked call blocks //copy the checked records
if (is_array($call_blocks) && @sizeof($call_blocks) != 0) { if (is_array($records) && @sizeof($records) != 0) {
//get checked call blocks //get checked records
foreach($call_blocks as $x => $row) { foreach($records as $x => $record) {
if ($row['checked'] == 'true' && is_uuid($row['call_block_uuid'])) { if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$call_block_uuids[] = "call_block_uuid = '".$row['call_block_uuid']."'"; $record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'";
} }
} }
//create insert array from existing data //create insert array from existing data
if (is_array($call_block_uuids) && @sizeof($call_block_uuids) != 0) { if (is_array($record_uuids) && @sizeof($record_uuids) != 0) {
$sql = "select * from v_call_block "; $sql = "select * from v_".$this->table." ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) "; $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']; $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database; $database = new database;
$rows = $database->select($sql, $parameters, 'all'); $rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) { if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $x => $row) { foreach ($rows as $x => $row) {
$array['call_block'][$x]['call_block_uuid'] = uuid(); $new_uuid = uuid();
$array['call_block'][$x]['domain_uuid'] = $row['domain_uuid']; $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $new_uuid;
$array['call_block'][$x]['call_block_name'] = $row['call_block_name']; $array[$this->table][$x]['domain_uuid'] = $row['domain_uuid'];
$array['call_block'][$x]['call_block_number'] = $row['call_block_number']; $array[$this->table][$x]['call_block_name'] = $row['call_block_name'];
$array['call_block'][$x]['call_block_count'] = 0; $array[$this->table][$x]['call_block_number'] = $row['call_block_number'];
$array['call_block'][$x]['call_block_action'] = $row['call_block_action']; $array[$this->table][$x]['call_block_count'] = 0;
$array['call_block'][$x]['date_added'] = $row['date_added']; $array[$this->table][$x]['call_block_action'] = $row['call_block_action'];
$array['call_block'][$x]['call_block_enabled'] = $row['call_block_enabled']; $array[$this->table][$x]['date_added'] = $row['date_added'];
$array['call_block'][$x]['call_block_description'] = trim($row['call_block_description'].' ('.$text['label-copy'].')'); $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); unset($sql, $parameters, $rows, $row);
} }
//save the changes and set the message //save the changes and set the message
if (is_array($array) && @sizeof($array) != 0) { if (is_array($array) && @sizeof($array) != 0) {
//save the array //save the array
$database = new database; $database = new database;
$database->app_name = 'call_block'; $database->app_name = $this->app_name;
$database->app_uuid = '9ed63276-e085-4897-839c-4f2e36d92d6c'; $database->app_uuid = $this->app_uuid;
$database->save($array); $database->save($array);
unset($array); unset($array);
//set message //set message
message::add($text['message-copy']); 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();
*/
?> ?>