From 94c04bee55c14d258383a4ff1c106ba975d6dda3 Mon Sep 17 00:00:00 2001
From: Nigel Kukard <nkukard@lbsd.net>
Date: Thu, 30 Apr 2009 10:15:12 +0000
Subject: [PATCH] * Group related code cleanup

---
 webui/group-add.php              |  4 +--
 webui/group-attribute-add.php    | 13 +--------
 webui/group-attribute-change.php | 17 +++---------
 webui/group-attribute-delete.php | 11 ++------
 webui/group-attributes.php       | 45 ++++++++++++--------------------
 webui/group-delete.php           | 13 +++------
 webui/group-main.php             | 12 ++-------
 webui/group-users.php            | 18 ++-----------
 8 files changed, 33 insertions(+), 100 deletions(-)

diff --git a/webui/group-add.php b/webui/group-add.php
index c34bd352..ad0cc3b5 100644
--- a/webui/group-add.php
+++ b/webui/group-add.php
@@ -102,18 +102,18 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "add") {
 			<div class="warning"><?php print_r($stmt->errorInfo()) ?></div>
 <?php
 		}
+
 	} else {
 ?>
 		<div class="warning">Group name cannot be empty!</div>
 <?php
 
 	}
+
 } else {
 
 ?>
-
 	<div class="warning">Invalid invocation</div>
-
 <?php
 
 }
diff --git a/webui/group-attribute-add.php b/webui/group-attribute-add.php
index d573fb8f..9920129b 100644
--- a/webui/group-attribute-add.php
+++ b/webui/group-attribute-add.php
@@ -16,8 +16,6 @@
 # with this program; if not, write to the Free Software Foundation, Inc.,
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
-session_start();
-
 include_once("includes/header.php");
 include_once("includes/footer.php");
 include_once("includes/db.php");
@@ -86,18 +84,13 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "add") {
 } elseif (isset($_POST['frmaction']) && $_POST['frmaction'] == "add2") {
 
 ?>
-
 	<p class="pageheader">Attribute Add Results</p>
-
 <?php
 
 	# Check for empty values
 	if (empty($_POST['attr_name']) || empty($_POST['attr_operator']) || empty($_POST['attr_value'])) {
-
 ?>
-
 		<div class="warning">Submission cannot have empty value</div>
-
 <?php
 
 	} else {
@@ -121,17 +114,13 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "add") {
 			<div class="warning"><?php print_r($stmt->errorInfo()) ?></div>
 
 <?php
-
 		}
+
 	}
 } else {
-
 ?>
-
 	<div class="warning">Invalid invocation</div>
-
 <?php
-
 }
 printFooter();
 
diff --git a/webui/group-attribute-change.php b/webui/group-attribute-change.php
index 86d2136d..f7c2d492 100644
--- a/webui/group-attribute-change.php
+++ b/webui/group-attribute-change.php
@@ -37,15 +37,14 @@ printHeader(array(
 
 # Display change screen
 if (isset($_POST['frmaction']) && $_POST['frmaction'] == "change") {
+
 	# Check an attribute was selected
 	if (isset($_POST['attr_id'])) {
 		# Prepare statement
 		$sql = "SELECT ID, Name, Operator, Value, Disabled FROM ${DB_TABLE_PREFIX}group_attributes WHERE ID = ".$db->quote($_POST['attr_id']);
 		$res = $db->query($sql); 
 		$row = $res->fetchObject();
-
 ?>
-
 		<p class="pageheader">Update Group Attribute</p>
 
 		<form action="group-attribute-change.php" method="post">
@@ -113,26 +112,21 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "change") {
 				<input type="submit" />
 			</div>
 		</form>
-
 <?php
 
 		$res->closeCursor();
-	} else {
 
+	} else {
 ?>
-
 		<div class="warning">No attribute selected</div>
-
 <?php
-
 	}
+
 # SQL Updates
 } elseif (isset($_POST['frmaction']) && $_POST['frmaction'] == "change2") {
 
 ?>
-
 	<p class="pageheader">Attribute Update Results</p>
-
 <?php
 
 	# Check an attribute was selected
@@ -175,6 +169,7 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "change") {
 				<div class="warning"><?php print_r($db->errorInfo()) ?></div>
 <?php
 			}
+
 		# Warn
 		} else {
 ?>
@@ -190,13 +185,9 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "change") {
 	}
 
 } else {
-
 ?>
-
 	<div class="warning">Invalid invocation</div>
-
 <?php
-
 }
 
 
diff --git a/webui/group-attribute-delete.php b/webui/group-attribute-delete.php
index e77ae3c4..598d80a5 100644
--- a/webui/group-attribute-delete.php
+++ b/webui/group-attribute-delete.php
@@ -37,11 +37,10 @@ printHeader(array(
 
 # Display delete confirm screen
 if (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete") {
+
 	# Check a user was selected
 	if (isset($_POST['attr_id'])) {
-
 ?>
-
 		<p class="pageheader">Delete Attribute</p>
 
 		<form action="group-attribute-delete.php" method="post">
@@ -55,25 +54,19 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete") {
 				<input type="submit" name="confirm" value="no" />
 			</div>
 		</form>
-
 <?php
 
 	} else {
-
 ?>
-
 		<div class="warning">No attribute selected</div>
-
 <?php
-
 	}
+
 # SQL Updates
 } elseif (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete2") {
 
 ?>
-
 	<p class="pageheader">Attribute Delete Results</p>
-
 <?php
 
 	# Make sure we have the attribute ID set
diff --git a/webui/group-attributes.php b/webui/group-attributes.php
index 2c9d228f..eb13bd0f 100644
--- a/webui/group-attributes.php
+++ b/webui/group-attributes.php
@@ -17,8 +17,6 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 
-session_start();
-
 include_once("includes/header.php");
 include_once("includes/footer.php");
 include_once("includes/db.php");
@@ -76,30 +74,27 @@ printHeader(array(
 		</tr>
 
 <?php
-
-		$_SESSION['attr_group_id'] = $_POST['group_id']; 
 		if (isset($_POST['group_id'])) {
 	
-			$sql = "SELECT 
-							ID, 
-							Name, 
-							Operator, 
-							Value, 
-							Disabled 
-					FROM 
-							${DB_TABLE_PREFIX}group_attributes 
-					WHERE 
-							GroupID = ".$db->quote($_POST['group_id'])." 
-					ORDER BY 
-							ID
-					";
+			$sql = "
+				SELECT 
+					ID, 
+					Name, 
+					Operator, 
+					Value, 
+					Disabled 
+				FROM 
+					${DB_TABLE_PREFIX}group_attributes 
+				WHERE 
+					GroupID = ".$db->quote($_POST['group_id'])." 
+				ORDER BY 
+					ID
+			";
 
 			$res = $db->query($sql);
 
 			while ($row = $res->fetchObject()) {
-
 ?>
-
 				<tr class="resultsitem">
 					<td><input type="radio" name="attr_id" value="<?php echo $row->id; ?>"/><?php echo $row->id; ?></td>
 					<td><?php echo $row->name; ?></td>
@@ -107,37 +102,31 @@ printHeader(array(
 					<td><?php echo $row->value; ?></td>
 					<td class="textcenter"><?php echo $row->disabled ? 'yes' : 'no'; ?></td>
 				</tr>
-
 <?php
 
 			}
+
 			$res->closeCursor();
-			if ($res->rowCount() == 0) {
 
+			if ($res->rowCount() == 0) {
 ?>
-
 				<p />
 				<tr>
 					<td colspan="5" class="textcenter">Group attribute list is empty</td>
 				</tr>
-
 <?php
 
 			}
-		} else {
 
+		} else {
 ?>
 
 			<tr class="resultitem">
 				<td colspan="5" class="textcenter">No Group ID selected</td>
 			</tr>
-
 <?php
-
 		}
-
 ?>
-
 	</table>
 </form>
 
diff --git a/webui/group-delete.php b/webui/group-delete.php
index b4b70e38..1a19e1c2 100644
--- a/webui/group-delete.php
+++ b/webui/group-delete.php
@@ -37,11 +37,10 @@ printHeader(array(
 
 # Display delete confirm screen
 if (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete") {
+
 	# Check a policy group was selected
 	if (isset($_POST['group_id'])) {
-
 ?>
-
 		<p class="pageheader">Delete Group</p>
 
 		<form action="group-delete.php" method="post">
@@ -53,28 +52,22 @@ if (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete") {
 				<input type="submit" name="confirm" value="no" />
 			</div>
 		</form>
-
 <?php
 
 	} else {
-
 ?>
-
 		<div class="warning">No group selected</div>
-
 <?php
-
 	}
+
 # SQL Updates
 } elseif (isset($_POST['frmaction']) && $_POST['frmaction'] == "delete2") {
-
 ?>
-
 	<p class="pageheader">Group Delete Results</p>
-
 <?php
 
 	if (isset($_POST['group_id'])) {
+
 		if (isset($_POST['confirm']) && $_POST['confirm'] == "yes") {
 
 			$db->beginTransaction();
diff --git a/webui/group-main.php b/webui/group-main.php
index 2787aea4..fb802bed 100644
--- a/webui/group-main.php
+++ b/webui/group-main.php
@@ -79,12 +79,10 @@ printHeader(array(
 			</tr>
 
 <?php
-
 			$sql = "SELECT ID, Name, Priority, Disabled, Comment FROM ${DB_TABLE_PREFIX}groups ORDER BY ID";
 			$res = $db->query($sql);
 
 			while ($row = $res->fetchObject()) {
-
 ?>
 				<tr class="resultsitem">
 					<td><input type="radio" name="group_id" value="<?php echo $row->id; ?>" /></td>
@@ -93,29 +91,23 @@ printHeader(array(
 					<td class="textcenter"><?php echo $row->disabled ? 'yes' : 'no'; ?></td>
 					<td><?php echo $row->comment; ?></td>
 				</tr>
-
 <?php
-
 			}
-			if ($res->rowCount() == 0) {
 
+			if ($res->rowCount() == 0) {
 ?>
-
 				<p />
 				<tr>
 					<td colspan="5" class="textcenter">Group list is empty</td>
 				</tr>
-
 <?php
-
 			}
+
 			$res->closeCursor();
 
 ?>
-
 		</table>
 	</form>
-
 <?php
 
 printFooter();
diff --git a/webui/group-users.php b/webui/group-users.php
index 850b7e38..7cc9c1fd 100644
--- a/webui/group-users.php
+++ b/webui/group-users.php
@@ -56,9 +56,7 @@ if (isset($_POST['group_id'])) {
 			<td class="textcenter">Member</td>
 			<td class="textcenter">Disabled</td>
 		</tr>
-
 <?php
-
 		# Get list of members belonging to this group
 		$stmt = $db->prepare("SELECT UserID FROM ${DB_TABLE_PREFIX}users_to_groups WHERE GroupID = ?");
 		$stmtResult = $stmt->execute(array($_REQUEST['group_id']));
@@ -71,50 +69,38 @@ if (isset($_POST['group_id'])) {
 
 			# List users
 			while ($row = $res->fetchObject()) {
-
 ?>
-
 				<tr class="resultsitem">
 					<td><?php echo $row->id; ?></td>
 					<td><?php echo $row->username; ?></td>
 					<td class="textcenter"><?php echo $row->disabled ? 'yes' : 'no'; ?></td>
 				</tr>
-
 <?php
-
 			}
+
 			$res->closeCursor();
 		}
 
 		# Did we get any results?
 		if ($stmt->rowCount() == 0) {
-
 ?>
-
 			<p />
 			<tr>
 				<td colspan="3" class="textcenter">Group has no users</td>
 			</tr>
-
 <?php
-
 		}
+
 		$stmt->closeCursor();
 
 ?>
-
 	</table>
-
 <?php
 
 } else {
-
 ?>
-
 	<div class="warning">Invalid invocation</div>
-
 <?php
-
 }
 printFooter();
 
-- 
GitLab