Improve code for access controls.

This commit is contained in:
markjcrane 2016-06-21 18:00:38 -06:00
parent 774dfd1053
commit f4765e954b
3 changed files with 89 additions and 77 deletions

View File

@ -1,6 +1,10 @@
<?php
//includes
require_once "root.php";
require_once "resources/require.php";
//check permissions
require_once "resources/check_auth.php";
if (permission_exists('access_control_delete')) {
//access granted

View File

@ -1,6 +1,10 @@
<?php
//includes
require_once "root.php";
require_once "resources/require.php";
//check permissions
require_once "resources/check_auth.php";
if (permission_exists('access_control_add') || permission_exists('access_control_edit')) {
//access granted
@ -75,8 +79,8 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
unset($sql);
remove_config_from_cache('configuration:acl.conf');
$_SESSION['message'] = $text['message-add'];
header('Location: access_controls.php');
$_SESSION["message"] = $text['message-add'];
header("Location: access_controls.php");
return;
} //if ($action == "add")
@ -91,8 +95,8 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
unset($sql);
remove_config_from_cache('configuration:acl.conf');
$_SESSION['message'] = $text['message-update'];
header('Location: access_controls.php');
$_SESSION["message"] = $text['message-update'];
header("Location: access_controls.php");
return;
} //if ($action == "update")
@ -120,8 +124,8 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
require_once "resources/header.php";
//show the content
echo "<form method='post' name='frm' action=''>\n";
echo "<table width='100%' border='0' cellpadding='6' cellspacing='0'>\n";
echo "<form name='frm' id='frm' method='post' action=''>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\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 width='70%' align='right' valign='top'>\n";
@ -186,7 +190,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
echo " </tr>";
echo "</table>";
echo "</form>";
echo "<br><br>";
echo "<br /><br />";
if ($action == "update") {
require "access_control_nodes.php";

View File

@ -1,6 +1,10 @@
<?php
//includes
require_once "root.php";
require_once "resources/require.php";
//check permissions
require_once "resources/check_auth.php";
if (permission_exists('access_control_view')) {
//access granted
@ -22,19 +26,6 @@ else {
require_once "resources/header.php";
require_once "resources/paging.php";
//show the content
echo "<table width='100%' border='0'>\n";
echo " <tr>\n";
echo " <td width='50%' align='left' nowrap='nowrap'><b>".$text['title-access_controls']."</b></td>\n";
echo " <td width='50%' align='right'>&nbsp;</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td align='left' colspan='2'>\n";
echo " ".$text['description-access_control']."<br /><br />\n";
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
//prepare to page the results
$sql = "select count(*) as num_rows from v_access_controls ";
if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
@ -65,13 +56,26 @@ else {
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$result_count = count($result);
unset ($prep_statement, $sql);
//alternate the row style
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
//show the content
echo "<table width='100%' border='0'>\n";
echo " <tr>\n";
echo " <td width='50%' align='left' nowrap='nowrap'><b>".$text['title-access_controls']."</b></td>\n";
echo " <td width='50%' align='right'>&nbsp;</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td align='left' colspan='2'>\n";
echo " ".$text['description-access_control']."<br /><br />\n";
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo th_order_by('access_control_name', $text['label-access_control_name'], $order_by, $order);
@ -87,7 +91,7 @@ else {
echo "</td>\n";
echo "<tr>\n";
if ($result_count > 0) {
if (is_array($result)) {
foreach($result as $row) {
if (permission_exists('access_control_edit')) {
$tr_link = "href='access_control_edit.php?id=".$row['access_control_uuid']."'";
@ -126,7 +130,6 @@ else {
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>";
@ -134,4 +137,5 @@ else {
//include the footer
require_once "resources/footer.php";
?>