Location: PHPKode > projects > PHPFreeNews > phpfn/Inc/UserAuthCat.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 User ID being processed
$UserID = $_GET['id'];

// Get the user's name
$UserName = GetUserName($UserID);

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

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

	// Delete all authorised categories for this user
	mysql_query("DELETE FROM news_users_categories WHERE UserID='$UserID'");

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

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

	// Write audit, if required
	if ($EnableAudit == 1)
		WriteAuditEvent(AUDIT_TYPE_CATAUTH, 'C', $UserID, "Authorised Categories changed for User: " . $UserName);
}


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

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

DisplayGroupHeading("Authorised Categories for User $UserName");
DisplayInfoMessage(); ?>
<br />
<table class="Admin">
	<tr>
		<td>
			<form name="auth" action="<?=$AdminScript?>?action=UserAuthCat&id=<?=$UserID?>" method="post">
				<table cellpadding="1">
					<?php

					// Apply any limits, and perform the search
					$i=0;
					while ($row = mysql_fetch_array($ResultSet))
					{
						$i++;
						$CatID = $row['CatID'];
						$CatDesc = $row['CatDesc'];
						$Checked = ($row['UserID'] != NULL ? 'CHECKED' : '');
						?>
						<tr>
							<td>
								<input type="checkbox" name="id<?=$i?>" value="<?=$CatID?>" <?=$Checked?>/>
							</td>
							<td>
								<?=$CatDesc?><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