users page converted

This commit is contained in:
Ryan Walberg 2012-11-17 00:43:39 +00:00
parent 299f91e596
commit 7040459d82
2 changed files with 184 additions and 150 deletions

148
src/templates/users.tpl Normal file
View file

@ -0,0 +1,148 @@
{*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Gift Registry - Manage Users</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<script language="JavaScript" type="text/javascript">
function confirmDelete(fullname) {
return confirm("Are you sure you want to delete " + fullname + "?");
}
</script>
</head>
<body>
{include file='navbar.tpl' isadmin=$isadmin}
<div class="container" style="padding-top: 60px;">
{if isset($message)}
<div class="row">
<div class="span12">
<div class="alert alert-info">{$message|escape:'htmlall'}</div>
</div>
</div>
{/if}
<div class="row">
<div class="span12">
<div class="well">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Username</th>
<th>Fullname</th>
<th>E-mail</th>
<th>E-mail messages?</th>
<th>Approved?</th>
<th>Admin?</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
{foreach from=$users item=row}
<tr>
<td>{$row.username}</td>
<td>{$row.fullname}</td>
<td>{$row.email}</td>
<td>{if $row.email_msgs}Yes{else}No{/if}</td>
<td>{if $row.approved}Yes{else}No{/if}</td>
<td>{if $row.admin}Yes{else}No{/if}</td>
<td align="right">
<a href="users.php?action=edit&userid={$row.userid}#userform"><img alt="Edit User" src="images/write_obj.gif" border="0" title="Edit User" /></a> /
<a onClick="return confirmDelete('{$row.fullname|escape:'htmlall'}');" href="users.php?action=delete&userid={$row.userid}"><img alt="Delete User" src="images/remove.gif" border="0" title="Delete User" /></a> /
{if $row.email != ''}
<a href="users.php?action=reset&userid={$row.userid}&email={$row.email|escape:'htmlall'}">Reset Pwd</a>
{else}
Reset Pwd
{/if}
</td>
</tr>
{/foreach}
</tbody>
</table>
<h5><a href="users.php">Add a new user</a></h5>
</div>
</div>
</div>
<a name="userform">
<div class="row">
<div class="span12">
<form name="users" method="get" action="users.php" class="well form-horizontal">
{if $action == "edit" || (isset($haserror) && $action == "update")}
<input type="hidden" name="userid" value="{$userid}">
<input type="hidden" name="action" value="update">
{else if $action == "" || (isset($haserror) && $action == "insert")}
<input type="hidden" name="action" value="insert">
{/if}
<fieldset>
<legend>{if $action == "edit" || $action == "update"}Edit User{else}Add User{/if}</legend>
<div class="control-group {if isset($username_error)}warning{/if}">
<label class="control-label" for="username">Username</label>
<div class="controls">
<input id="username" name="username" type="text" class="input-xlarge" value="{$username|escape:'htmlall'}" maxlength="255">
{if isset($username_error)}
<span class="help-inline">{$username_error|escape:'htmlall'}</span>
{/if}
</div>
</div>
<div class="control-group {if isset($fullname_error)}warning{/if}">
<label class="control-label" for="fullname">Full name</label>
<div class="controls">
<input id="fullname" name="fullname" type="text" class="input-xlarge" value="{$fullname|escape:'htmlall'}" maxlength="255">
{if isset($fullname_error)}
<span class="help-inline">{$fullname_error|escape:'htmlall'}</span>
{/if}
</div>
</div>
<div class="control-group {if isset($email_error)}warning{/if}">
<label class="control-label" for="email">E-mail address</label>
<div class="controls">
<input id="email" name="email" type="text" class="input-xlarge" value="{$email|escape:'htmlall'}" maxlength="255">
{if isset($email_error)}
<span class="help-inline">{$email_error|escape:'htmlall'}</span>
{/if}
</div>
</div>
<div class="control-group">
<label class="control-label">Flags</label>
<div class="controls">
<input type="checkbox" name="email_msgs" {if $email_msgs}CHECKED{/if}>
E-mail messages
<input type="checkbox" name="approved" {if $approved}CHECKED{/if}>
Approved
<input type="checkbox" name="admin" {if $userisadmin}CHECKED{/if}>
Administrator
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">{if $action == "" || $action == "insert"}Add{else}Update{/if}</button>
<button type="button" class="btn" onClick="document.location.href='users.php';">Cancel</button>
</div>
</fieldset>
</form>
</div>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html>

View file

@ -162,155 +162,41 @@ else {
echo "Unknown verb.";
exit;
}
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Gift Registry - Manage Users</title>
<link href="styles.css" type="text/css" rel="stylesheet" />
<script language="JavaScript" type="text/javascript">
function confirmDelete(fullname) {
return confirm("Are you sure you want to delete " + fullname + "?");
}
</script>
</head>
<body>
<?php
if (isset($message)) {
echo "<span class=\"message\">" . $message . "</span>";
}
$query = "SELECT userid, username, fullname, email, email_msgs, approved, admin FROM {$OPT["table_prefix"]}users ORDER BY username";
$users = mysql_query($query) or die("Could not query: " . mysql_error());
$rs = mysql_query($query) or die("Could not query: " . mysql_error());
$users = array();
while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
$users[] = $row;
}
mysql_free_result($rs);
define('SMARTY_DIR',str_replace("\\","/",getcwd()).'/includes/Smarty-3.1.12/libs/');
require_once(SMARTY_DIR . 'Smarty.class.php');
$smarty = new Smarty();
$smarty->assign('action', $action);
$smarty->assign('username', $username);
if (isset($username_error)) {
$smarty->assign('username_error', $username_error);
}
$smarty->assign('fullname', $fullname);
if (isset($fullname_error)) {
$smarty->assign('fullname_error', $fullname_error);
}
$smarty->assign('email', $email);
if (isset($email_error)) {
$smarty->assign('email_error', $email_error);
}
$smarty->assign('email_msgs', $email_msgs);
$smarty->assign('approved', $approved);
$smarty->assign('userisadmin', $userisadmin);
$smarty->assign('haserror', $haserror);
$smarty->assign('users', $users);
if (isset($message)) {
$smarty->assign('message', $message);
}
$smarty->assign('userid', $userid);
$smarty->assign('isadmin', $_SESSION["admin"]);
$smarty->assign('opt', $OPT);
$smarty->display('users.tpl');
?>
<p>
<table class="partbox" width="100%" cellspacing="0">
<tr class="partboxtitle">
<td colspan="7" align="center">Users</td>
</tr>
<tr>
<th class="colheader">Username</th>
<th class="colheader">Fullname</th>
<th class="colheader">E-mail</th>
<th class="colheader">E-mail messages?</th>
<th class="colheader">Approved?</th>
<th class="colheader">Admin?</th>
<th>&nbsp;</th>
</tr>
<?php
$i = 0;
while ($row = mysql_fetch_array($users,MYSQL_ASSOC)) {
?>
<tr class="<?php echo (!($i++ % 2)) ? "evenrow" : "oddrow" ?>">
<td><?php echo htmlspecialchars($row["username"]); ?></td>
<td><?php echo htmlspecialchars($row["fullname"]); ?></td>
<td><?php echo htmlspecialchars($row["email"]); ?></td>
<td><?php echo ($row["email_msgs"] == 1 ? "Yes" : "No"); ?></td>
<td><?php echo ($row["approved"] == 1 ? "Yes" : "No"); ?></td>
<td><?php echo ($row["admin"] == 1 ? "Yes" : "No"); ?></td>
<td align="right">
<a href="users.php?action=edit&userid=<?php echo $row["userid"]; ?>">Edit</a>
/
<a onClick="return confirmDelete('<?php echo jsEscape($row["fullname"]); ?>');" href="users.php?action=delete&userid=<?php echo $row["userid"]; ?>">Delete</a>
/
<?php
// we can't reset their password if their e-mail address isn't set.
if ($row["email"] != "") {
?>
<a href="users.php?action=reset&userid=<?php echo $row["userid"]; ?>&email=<?php echo urlencode($row["email"]); ?>">Reset Pwd</a>
<?php
}
else
echo "Reset Pwd";
?>
</td>
</tr>
<?php
}
mysql_free_result($users);
?>
</table>
</p>
<p>
<a href="users.php">Add a new user</a> / <a href="index.php">Back to main</a>
</p>
<form name="users" method="get" action="users.php">
<?php
if ($action == "edit" || (isset($haserror) && $action == "update")) {
?>
<input type="hidden" name="userid" value="<?php echo $_GET["userid"]; ?>">
<input type="hidden" name="action" value="update">
<?php
}
else if ($action == "" || (isset($haserror) && $action == "insert")) {
?>
<input type="hidden" name="action" value="insert">
<?php
}
?>
<div align="center">
<table class="partbox">
<tr class="partboxtitle">
<td align="center" colspan="2"><?php echo ($action == "edit" ? "Edit User '" . $username . "'" : "Add New User"); ?></td>
</tr>
<tr valign="top">
<td>Username</td>
<td>
<input name="username" type="text" value="<?php echo htmlspecialchars($username); ?>" maxlength="255" size="50"/>
<?php
if (isset($username_error)) {
?>
<br />
<font color="red"><?php echo $username_error ?></font><?php
}
?>
</td>
</tr>
<tr valign="top">
<td>Fullname</td>
<td>
<input name="fullname" type="text" value="<?php echo htmlspecialchars($fullname); ?>" maxlength="255" size="50"/>
<?php
if (isset($fullname_error)) {
?>
<br />
<font color="red"><?php echo $fullname_error ?></font>
<?php
}
?>
</td>
</tr>
<tr valign="top">
<td>E-Mail</td>
<td>
<input name="email" type="text" value="<?php echo htmlspecialchars($email); ?>" maxlength="255" size="50"/>
<?php
if (isset($email_error)) {
?>
<br />
<font color="red"><?php echo $email_error ?></font>
<?php
}
?>
</td>
</tr>
<tr>
<td colspan="2">
<input type="checkbox" name="email_msgs" <?php if ($email_msgs == 1) echo "CHECKED"; ?>>E-mail messages
&nbsp;
<input type="checkbox" name="approved" <?php if ($approved == 1) echo "CHECKED"; ?>>Approved
&nbsp;
<input type="checkbox" name="admin" <?php if ($userisadmin == 1) echo "CHECKED"; ?>>Administrator
</td>
</tr>
</table>
</div>
<p>
<div align="center">
<input type="submit" value="<?php if ($action == "" || $action == "insert") echo "Add"; else echo "Update"; ?>"/>
<input type="button" value="Cancel" onClick="document.location.href='users.php';">
</div>
</p>
</form>
</body>
</html>