Skip to content
Snippets Groups Projects
Commit 94c04bee authored by Nigel Kukard's avatar Nigel Kukard
Browse files

* Group related code cleanup

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