Location: PHPKode > projects > ZompLog > admin/users.php
<?php
/* Written by Gerben Schmidt, http://scripts.zomp.nl */
ob_start();
include_once("functions.php");
include('config.php');
include("session.php");
include("header.php");


if(!$_SESSION["loggedIn"]){ echo "You are not allowed to view this page, please log in first."; exit; }

$user = loadUser($_SESSION['login'],$link,$table_users);

if(!$user[admin]){
header("Location: members.php");
}

$query = "SELECT * FROM $table_users ORDER BY id ASC";
$result = mysql_query ($query, $link) or die("Died getting info from db.  Error returned if any: ".mysql_error());
$users = arrayMaker($result,MYSQL_ASSOC);

if($_POST["submit"]){
	
	field_validator($lang_username, $_POST["login"], "alphanumeric", 4, 15);
	field_validator($lang_password, $_POST["password"], "string", 4, 15);
	field_validator($lang_confirmation_password, $_POST["password2"], "string", 4, 15);
	
	
	if(strcmp($_POST["password"], $_POST["password2"])) {
		
		$messages[]="$lang_mismatch";
	}

	
	$query="SELECT login FROM $table_users WHERE login='".$_POST["login"]."'";
	
	
	$result=mysql_query($query, $link) or die("MySQL query $query failed.  Error if any: ".mysql_error());
	

	if( ($row=mysql_fetch_array($result)) ){
		$messages[]="$lang_username \"".$_POST["login"]."\" $lang_login_id";
	}

	
	if(empty($messages)) {
		
		newUser();

		header("Location: users.php?message=9");
		ob_end_flush();
	}
}


?>

<div id="submenu"><a href="profile.php" class="sub"><?php echo "$lang_editprofile"; ?></a><?php if($user[admin]){ ?> | <a href="users.php" class="sub"><?php echo "$lang_manage_users"; ?></a><?php } ?></div>


<div id="side">
<div class="title">&nbsp;</div>
<div class="box"><?php
if(!empty($messages)){
	displayErrors($messages);
}

elseif($_GET[message] && empty($messages)){
displayMessage($_GET[message]);
  }

else{
echo "$lang_message008";
}  
  
?>
</div>

<br />
<div class="box">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="text">
<tr valign="top"><td width="22px"><img src="icons/pencil.png" alt="<?php echo "$lang_edit $lang_user"; ?>" title="<?php echo "$lang_edit $lang_user"; ?>" width="16" height="16" align="absmiddle" /></td><td><?php echo "$lang_edit $lang_user"; ?></td></tr>
<tr valign="top"><td width="22px"><img src="icons/cross.png" alt="<?php echo "$lang_delete $lang_user"; ?>" title="<?php echo "$lang_delete $lang_user"; ?>" width="16" height="16" align="absmiddle" /></td><td><?php echo "$lang_delete $lang_user"; ?></td></tr>
<tr valign="top"><td width="22px"><img src="icons/user.png" alt="<?php echo "$lang_logged_in"; ?>" title="<?php echo "$lang_logged_in"; ?>" width="16" height="16" align="absmiddle" /></td><td><?php echo "$lang_logged_in"; ?></td></tr>
</table>
</div>
</div>


<div id="main">
<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">
	<h1><?php echo "$lang_manage_users"; ?></h1><br />
	<fieldset id="titlediv">
      <legend><?php echo "$lang_create_user"; ?></legend>
      <table width="400" border="0" cellspacing="0" class="text">
        <tr>
          <td width="150"><?php echo "$lang_username"; ?></td>
          <td width="293"><input type="text" name="login" value="<?php print $_POST["login"] ?>" maxlength="15"></td>
        </tr>
        <tr>
          <td><?php echo "$lang_password"; ?></td>
          <td><input type="password" name="password" value="" maxlength="15"></td>
        </tr>
        <tr>
          <td><?php echo "$lang_retype_password"; ?></td>
          <td><input type="password" name="password2" value="" maxlength="15"></td>
        </tr>
        <tr>
          <td><?php echo "$lang_administrator"; ?></td>
          <td><input name="admin" type="checkbox" id="admin" value="1"></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input name="submit" type="submit" value="<?php echo "$lang_submit"; ?>"></td>
        </tr>
      </table>
	  </fieldset>
    </form>
	<br/>
		<fieldset id="titlediv">
      <legend><?php echo "$lang_current_users"; ?></legend>
      <div class="text"><ul class="List">
        <?php
foreach($users as $user){
?>
<li>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="text"><tr>
<td width="4%"><a href='editor_users.php?username=<?php echo "$user[login]"; ?>'><img src='icons/pencil.png' border='0' alt="<?php echo "$lang_edit"; ?>" title="<?php echo "$lang_edit"; ?>" ></a></td>
<td width="67%"><?php echo "$user[login]"; ?></td>
<td width="25%"><?php if($user[admin]){ echo "$lang_administrator"; }
else
{ echo "$lang_user"; } ?></td>
<td width="4%"><?php 
// prevent admin from deleting him/herself
if($user[login] != $_SESSION[login]){
echo "<a href='schredder.php?tablename=$table_users&id=$user[id]' onclick=\"return verify()\"><img src='icons/cross.png' border='0' alt='$lang_delete' title='$lang_delete'></a></div>"; 
}
else {
	echo "<img src='icons/user.png' border='0' alt='$lang_logged_in' title='$lang_logged_in'>";
} ?></td>
</tr></table>
</li>

<?php } ?>
 </ul>
 </div>
</fieldset>
</div>

<?php include("footer.php");

?>

Return current item: ZompLog