Location: PHPKode > projects > PHPFreeNews > phpfn/Inc/ViewAudit.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!');

if (! isset($_SESSION['RestrictEventCategory']))
	$_SESSION['RestrictEventCategory'] = '-';

if (! isset($_SESSION['RestrictEventUserID']))
	$_SESSION['RestrictEventUserID'] = '0';

// If specified, store into the session the restriction-information
if (isset($_POST['Cat']))
	$_SESSION['RestrictEventCategory'] = $_POST['Cat'];
if (isset($_POST['EventUserID']))
	$_SESSION['RestrictEventUserID'] = $_POST['EventUserID'];

// If specified, store into the session the restriction-information
SetAdminCurrentRestrictions();

$EventCategory = $_SESSION['RestrictEventCategory'];
$EventUserID = $_SESSION['RestrictEventUserID'];
$PerPage = $_SESSION['PerPage'];
$ShowPage = isset($_REQUEST['ShowPage']) ? $_REQUEST['ShowPage'] : 1;

// Determine the number of records in the file, and work out the number of pages
$sql = "SELECT count(*) AS NumRecs FROM news_audit WHERE ID != 0";
$where = '';

// Restrict by Category or user?
if ($EventCategory != '-')
	$where .= ' AND EventCatID=' . $EventCategory;
if ($EventUserID != '0')
	$where .= ' AND EventUserID=' . $EventUserID;

$resultset = mysql_fetch_array(mysql_query($sql . $where)); 
$NumRecords = $resultset['NumRecs'];

$RecStart = $PerPage * ($ShowPage-1); 
$PageNavBar = ConstructPagingBar($_SERVER['PHP_SELF'].'?action=Audit', $NumRecords, $PerPage, $ShowPage, $RecStart, $AdminPageBarEntries, '', '');

DisplayGroupHeading("Audit Log - Page $ShowPage");
?>
<br />
<table class="Admin">
	<tr>
		<td class="FieldPrompt">
			<form action="<?=$AdminScript?>?action=Audit" method="post">
				Per Page <?= BuildPerPageDropdown('PerPage', $PerPage, true) ?>
				Event Category <?= BuildEventCategoryDropdown('Cat', $EventCategory, true) ?>
				User <?= BuildUserDropdown('EventUserID', $EventUserID, false, true) ?>
				<input class="but" type="submit" name="submit" value="Filter" />
			</form>
		</td>
	</tr>
</table>
<br />
<table class="Admin">
	<tr>
		<td>
			<table class="Admin">
				<tr>
					<th>
						Date and Time
					</th>
					<th>
						User
					</th>
					<th>
						Category
					</th>
					<th>
						Type
					</th>
					<th>
						ID
					</th>
				</tr>
				<?php
				// Now obtain the resultset
				$sql = "SELECT EventDateTime, Username, CatDesc, EventType, LinkedID, news_audit.Description FROM (news_audit, news_audit_categories) LEFT OUTER JOIN news_users ON news_audit.EventUserID=news_users.ID WHERE news_audit.EventCatID=news_audit_categories.ID ";
				$sql .= $where;
				$sql .= " ORDER BY EventDateTime DESC LIMIT $RecStart, $PerPage";

				$results =	mysql_query($sql);
				$odd = true;
				while ($auditrow = mysql_fetch_array($results))
				{
					$EventDateTime = $ShowDateString = date($NewsDisplay_DateFormat, strtotime($auditrow['EventDateTime'])) . '&nbsp;' . date($NewsDisplay_TimeFormat, strtotime($auditrow['EventDateTime']));
					$EventUserName = $auditrow['Username'];
					if (is_null($EventUserName))
						$EventUserName = "(Unknown)";
					$CatDesc = $auditrow['CatDesc'];
					$LinkedID = $auditrow['LinkedID'];
					$Description = $auditrow['Description'];

					switch ($auditrow['EventType'])
					{
						case 'A':
							$EventTypeDesc = "Add";
							break;
						case 'C':
							$EventTypeDesc = "Change";
							break;
						case 'D':
							$EventTypeDesc = "Delete";
							break;
						case 'X':
							$EventTypeDesc = "Other";
							break;
						default:
							$EventTypeDesc = "Unknown!";
							break;
					}
					$ListStyle = "AuditLog" . (($odd) ? "Odd" :"Even");
					?>
					<tr class="<?=$ListStyle?>">
						<td class="<?=$ListStyle?>">
							<?= $ShowDateString ?>
						</td>
						<td class="<?=$ListStyle?>">
							<?=$EventUserName?>
						</td>
						<td class="<?=$ListStyle?>">
							<?=$CatDesc?>
						</td>
						<td class="<?=$ListStyle?>">
							<?=$EventTypeDesc?>
						</td>
						<td class="<?=$ListStyle?>">
							<?=$LinkedID?>
						</td>
					</tr>
					<?php
					$ListStyle = "AuditListDesc" . (($odd) ? "Odd" :"Even");
					?>					
					<tr>
 						<td colspan="5" class="<?=$ListStyle?>">
							&nbsp;&nbsp;&nbsp;<?=$Description?>
						</td>
					</tr>
					<?php
					$odd = ! $odd;
				}
				?>
			</table>
			<br /><br />
			<div align="center">
				<?= $PageNavBar ?>
				<br />
			</div>
		</td>
	</tr>
</table>
Return current item: PHPFreeNews