Location: PHPKode > projects > PHPFreeNews > phpfn/Inc/CatAuthUser.php
<?php

/*	+--------------------------------------------------------------
	| PHPFreeNews - News Headlines on your website                |
	| Developed by Jim Willsher.                                  |
	| http://www.phpfreenews.co.uk                                |
	+-------------------------------------------------------------+
*/

if (! defined('IN_PHPFN'))
	die('Illegal attempt to access script directly!');

// Get the Category ID being processed
$CatID = $_GET['id'];

// Get the category's description
$CatDesc = GetCategoryDescription($CatID);

// Form Submitted?
if (isset($_POST['NumItems']))
{
	$AuthorisedUsers = array();

	// Process all the elements
	$NumItems = $_POST['NumItems'];
	for ($i=1; $i <= $NumItems; $i++)
		if (isset($_POST['id' . $i]))
			$AuthorisedUsers[] = $_POST['id' . $i];

	// Delete all authorised users for this category
	mysql_query("DELETE FROM news_users_categories WHERE CatID='$CatID'");

	// Now process each authorised user in turn
	foreach ($AuthorisedUsers as $Key=> $UserID)
		mysql_query("INSERT INTO news_users_categories SET UserID = '$UserID', CatID = '$CatID'");

	$_SESSION['Info'] = "Users have been updated";

	// Write audit, if required
	if ($EnableAudit == 1)
		WriteAuditEvent(AUDIT_TYPE_CATAUTH, 'C', $CatID, "Authorised Users changed for Category: " . $CatDesc);
}


// Construct the SQL
$Query = "SELECT news_users.ID AS UserID, FullName, CatID FROM news_users LEFT OUTER JOIN news_users_categories ON news_users.ID = news_users_categories.UserID AND news_users_categories.CatID = $CatID ORDER BY FullName";

// Now obtain the record count
$ResultSet = mysql_query($Query) or die("Query failed : " . mysql_error());
$NumRecords = mysql_num_rows($ResultSet);

DisplayGroupHeading("Authorised Users for Category $CatDesc");
DisplayInfoMessage(); ?>
<br />
<table class="Admin">
	<tr>
		<td>
			<form name="auth" action="<?=$AdminScript?>?action=CatAuthUser&id=<?=$CatID?>" method="post">
				<table cellpadding="1">
					<?php

					// Apply any limits, and perform the search
					$i=0;
					while ($row = mysql_fetch_array($ResultSet))
					{
						$i++;
						$UserID = $row['UserID'];
						$FullName = $row['FullName'];
						$Checked = ($row['CatID'] != NULL ? 'CHECKED' : '');
						?>
						<tr>
							<td>
								<input type="checkbox" name="id<?=$i?>" value="<?=$UserID?>" <?=$Checked?>/>
							</td>
							<td>
								<?=$FullName?><br />
							</td>
						</tr>
						<?php
					}
					?>
					<tr>
						<td colspan="2">
							<br />
							<input type="hidden" name="NumItems" value="<?=$i?>" />
							<input class="but" type="button" name="SelectAll" value="Select All" onclick="SelectAllBoxes(document.auth, 'NumItems', 'id')" />
							<input class="but" type="button" name="DeSelectAll" value="De-Select All" onclick="DeSelectAllBoxes(document.auth, 'NumItems', 'id')" />
							<input class="but" type="submit" name="submit" value="Update"/>
						</td>
					</tr>
				</table>
			</form>
		</td>
	</tr>
</table>
Return current item: PHPFreeNews