Location: PHPKode > projects > Phpman > phpman-2.0a_RC2/admin/users.php
<?php
/**
* Manage users
* @package phpman
* @copyright (c) 2004 Samuel Suter
* @author Samuel Suter <hide@address.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @version 1.0
**/
?>
<h1><?=$lang->users?></h1>
<?php
if($_REQUEST["add"]) {
	editUser();
} elseif($_REQUEST["edit"]) {
	editUser($_REQUEST["edit"]);
} elseif($_REQUEST["delete"]) {
	$table = new mlsDBtable("#__users","user_ID",$database);
	$table->delete($_REQUEST["data"]["user_ID"]);
	listUsers();
} elseif($_REQUEST["save"]) {
	saveUser($_REQUEST["data"]);
	listUsers();
} else {
	listUsers();
}

function saveUser($data) {
	global $database,$lang;
	if($data["password"] != "") {
		$data["password"] = mlsCrypt($data["password"]);
	} else {
		unset($data["password"]);
	}
	$table = new mlsDBtable("#__users","user_ID",$database);
	$table->bind($data);
	$table->store();
};

function editUser($id = 0) {
	global $database,$lang;
	$table = new mlsDBtable("#__users","user_ID",$database);
	$data = $table->load($id);
	?>
	<form method="POST" action="index.php" name="adminForm">
	<input type="hidden" name="data[user_ID]" value="<?=$data["user_ID"] ?>">
	<table cellpadding="4" cellspacing="0" border="0" width="100%" class="admintable">
		<tr>
			<td class="form"><?=$lang->username?>:</td>
			<td class="form"><input class="inputbox" size="40" type="text" name="data[username]" value="<?=$data["username"] ?>"></td>
		</tr>
		<tr>
			<td class="form"><?=$lang->name?>:</td>
			<td class="form"><input class="inputbox" size="40" type="text" name="data[name]" value="<?=$data["name"] ?>"></td>
		</tr>
		<tr>
			<td class="form"><?=$lang->email?>:</td>
			<td class="form"><input class="inputbox" size="40" type="text" name="data[email]" value="<?=$data["email"] ?>"></td>
		</tr>
		<tr>
			<td colspan="2" height="15"><td>
		</tr>
		<tr>
			<td class="form"><?=$lang->password?>:</td>
			<td class="form"><input class="inputbox" size="40" type="text" name="data[password]" value=""></td>
		</tr>
		<tr>
			<td></td>
			<td>
			<input type="submit" name="save" value="<?=$lang->save?>">
			<input type="submit" name="delete" value="<?=$lang->delete?>">
			</td>
		</tr>
		</table>
		<input type="hidden" name="page" value="<?=$_REQUEST["page"]?>">
		<input type="hidden" name="lang" value="<?=$_REQUEST["lang"]?>">
		</form>
	<?php
}
function listUsers() {
	global $database,$lang;
	$table = new mlsDBtable("#__users","user_ID",$database);
	$table->select('','username','ASC');
	$rows = $table->_db->loadRowsAssoc();
	?>
	[ <a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>&add=yes"><?=$lang->add?></a> ]<br>
	<table cellpadding="4" cellspacing="0" border="0" width="100%" class="admintable">
		<tr>
			<th><?=$lang->user_ID?></th>
			<th><?=$lang->username?></th>
			<th><?=$lang->name?></th>
			<th><?=$lang->email?></th>
			<th>&nbsp;</th>
		</tr>
		<?php
		$k = 0;
		foreach($rows as $row) {
			?>
			<tr class="row<?=$k?>">
				<td><?=$row["user_ID"]?></td>
				<td><?=$row["username"]?></td>
				<td><?=$row["name"]?></td>
				<td><?=$row["email"]?></td>
				<td><a href="?page=<?=$_REQUEST["page"]?>&lang=<?=$_REQUEST["lang"]?>&edit=<?=$row["user_ID"]?>"><?=$lang->edit?></a></td>
			</tr>
			<?php
			$k = 1 - $k;
		}
		?>
	</table>
	<?php
	
};
?>
Return current item: Phpman