<?php
/* Members Admin Area (C) American Financing 2004-2005 */
require '../mysqlvars.php';
require '../lib/db.php';
require '../lib/form_functions.php';
session_start('ADMIN');
require 'includes/secure_page.php';
$recordsPerPage = 10;
$pagesInList = 10;
$defaultSort = 'username';
unset($error);
$noRecords = 0;
$sort_by = isset($_GET['SORT_BY']) ? $_GET['SORT_BY'] : $defaultSort;
$sort_dir = isset($_GET['SORT_DIR']) ? $_GET['SORT_DIR'] : 'ASC';
$filter_on = isset($_GET['FILTER_ON']) ? $_GET['FILTER_ON'] : '';
$filter_str = isset($_GET['FILTER_STR']) ? $_GET['FILTER_STR'] : '';
$page = isset($_GET['PAGE']) ? $_GET['PAGE'] : 1;
$page = is_numeric($page) ? $page : 1;
$dbConn = connectDB($dbHost, $dbUser, $dbPass, $dbDB);
if ($dbConn) {
$querystr = "SELECT COUNT(*) FROM wsd_admin";
if ($filter_on != '') {
$querystr .= " WHERE $filter_on LIKE '" . str_replace ('*', '%', prepareData($filter_str)) . "' ";
}
$result = mysql_query($querystr);
if ($result) {
if ($frow = mysql_fetch_row($result)) {
$noRecords = $frow[0];
}
}
else {
$error = mysql_error();
}
}
else {
$error = 'Database is currently unavailable';
}
if (!isset($error)) {
$recNo = (($page - 1) * $recordsPerPage) < $noRecords ? ($page - 1) * $recordsPerPage : 0;
$querystr = "SELECT username FROM wsd_admin ";
if ($filter_on != '') {
$querystr .= "WHERE $filter_on LIKE '" . str_replace ('*', '%', prepareData($filter_str)) . "' ";
}
$querystr .= "order by $sort_by $sort_dir LIMIT $recNo, $recordsPerPage";
$result = mysql_query($querystr,$dbConn);
if (!$result) {
$error = mysql_error();
}
}
?>
<html>
<head>
<title>Browse Admin</title>
<META HTTP-EQUIV="PRAGMA" CONTENT="NOCACHE">
<link rel="stylesheet" href="styles/fgp.css" type="text/css">
</head>
<body>
<table class="bg">
<tr>
<td>
<table class="fg">
<tr>
<td class="title">Browse Admin</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<p><a href="./">Menu</a></p> <form method="GET" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<input type="hidden" name="SORT_BY" value="<?php echo $sort_by ?>">
<input type="hidden" name="SORT_DIR" value="<?php echo $sort_dir ?>">
<select name="FILTER_ON">
<option selected value="<?php echo $filter_on ?>"><?php echo $filter_on ?>
<option value=""></option>
<option value="username">username</option>
</select>
<input type="text" name="FILTER_STR" size="15" maxlength="255" value="<?php echo $filter_on == '' ? '*search string*' : htmlChars($filter_str); ?>">
<input type="submit" name="filter" value="Filter">
</form>
</td>
</tr>
<?php if ($noRecords > 0) { ?>
<tr>
<td class="bold">
Page: [<?php echo $page ?>]
<?php
$noPages = intval(($noRecords + $recordsPerPage - 1)/ $recordsPerPage);
$startPage = $page - (($page - 1) % $pagesInList);
$endPage = $startPage + $pagesInList;
$previousPage = $startPage - 1;
if ($startPage > $pagesInList) {
echo "<a href=\"" . getLink($sort_by, $sort_dir, $filter_on, $filter_str, $previousPage) . "\"><<</a> ";
}
for ($i = $startPage; ($i < $endPage) && ($i < ($noPages + 1)); $i++) {
echo "<a href=\"" . getLink($sort_by, $sort_dir, $filter_on, $filter_str, $i) . "\">$i</a> ";
}
if ($i <= $noPages) {
echo "<a href=\"" . getLink($sort_by, $sort_dir, $filter_on, $filter_str, $endPage) . "\">>></a> ";
}
?>
</td>
</tr>
<?php } ?>
<tr>
<td class="error">
<?php
if (isset($error)) {
echo "$error";
} ?>
</td>
</tr>
<?php if ($noRecords > 0 && !isset($error)) {
$sort_dir = $sort_dir == 'ASC' ? 'DESC' : 'ASC'; ?>
<tr>
<td>
<table class="fg">
<tr>
<td class="bold"> </td>
<td class="head"><a class="cell" href="<?php echo getLink('username', $sort_dir, $filter_on, $filter_str) ?>">Username</a></td>
</tr>
<?php if ($frow = mysql_fetch_array($result)) {
$rows = 0;
do {
echo "<tr>";
echo "<td class=\"bold\"><a class=\"cell\" href=\"update_admin.php?username=" . urlencode($frow["username"]) . "\" target=\"EditUser\" onClick=\"window.open('','EditUser','width=500,height=400,scrollbars=1')\">Edit</a> <a class=\"cell\" href=\"delete_admin.php?username=" . urlencode($frow["username"]) . "\" target=\"EditUser\" onClick=\"window.open('','EditUser','width=500,height=400,scrollbars=1')\">Delete</a></td>";
echo "<td class=\"field\">" . $frow["username"] . "</td>";
echo "</tr>";
$rows++;
} while (($frow = mysql_fetch_array($result)) && ($rows < $recordsPerPage));
} ?>
</table>
</td>
</tr>
<tr>
<td class="bold">
** Click field headings to sort
</td>
</tr>
<?php } ?>
<tr>
<td class="bold">
Total Records <?php echo $noRecords; ?>
</td>
</tr>
<tr>
<td class="bold">
<a href="add_admin.php">Add New</a>
</td>
</tr>
</table>
</body>
</html>