Location: PHPKode > projects > PHP-Comics > php-comics/settings.php
<?php
 include('inc/inc.php');
$errors = array();
if(isset($_POST['Submit']))
{
	if(empty($_POST['Fullname']))
	{
		array_push($errors,"Fullname is a required field.");
	}
	if(empty($_POST['Username']))
	{
		array_push($errors,"Username is a required field.");
	}
	if(isset($_POST['User']) && $_SESSION['Admin'] == 1)
	{
	 	$UID = $_POST['User'];
		if($_POST['User'] == -1)
		{
			if(empty($_POST['NewPassword']) || empty($_POST['NewPassword2']))
			{
				array_push($errors,"Missing Password Field");
			}
			if($_POST['NewPassword'] != $_POST['NewPassword2'])
			{
				array_push($errors,"Passwords are not the same");
			}
			if(empty($errors))
			{
				DB::Query("INSERT INTO Users (Username,Password,Admin,FullName) VALUES ('$_POST[Username]','".MD5($_POST['Password'])."',".(isset($_POST['Admin']) ? 1 : 0).",'".addslashes($_POST['Fullname'])."')");
			}
	 	}
	}
	else
	{
		$UID = $_SESSION['UID'];
	}

	if($UID != -1)
	{
		if(isset($_POST['OldPassword']))
		{
			if(MD5($_POST['OldPassword'])!=DB::QueryResult("SELECT Password FROM USERS WHERE ID=$_SESSION[UID]","Password"))
			{
				array_push($errors,"Old Password is not correct");
			}
			if($_POST['NewPassword'] != $_POST['NewPassword2'])
			{
				array_push($errors,"Passwords are not the same");
			}
			if(empty($errors))
			{
				DB::Query("UPDATE Users SET Password = ".MD5($_POST['NewPassword'])." WHERE ID = $UID");
			}
		}
		if(empty($errors))
		{
				DB::Query("Update Users SET Username = '".addslashes($_POST['Username'])."', FullName = '".addslashes($_POST['FullName'])."'");
				DB::setSetting("ShowCovers",isset($_POST['ShowCovers']),$UID);
		}
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
	<title>PHP Comics: User Settings</title>
	<link rel="stylesheet" type="text/css" href="css/main.css" />
	<link rel="stylesheet" type="text/css" href="css/settings.css" />
	<script type="text/javascript" src="js/jquery.js"></script>
	<script type="text/javascript" src="js/settings.js"></script>
</head>
<body>
<?=site::showsidemenu();?>
<?php
	$result = DB::Query("SELECT * FROM Users WHERE ID = $_SESSION[UID]");
	$row = mysql_fetch_array($result);
	if(!empty($error))
	{
		echo "<div class='errors'>";
		foreach($error as $value)
		{
			echo $value."<br/>";
		}
		echo "</div>";
	}
?>
<form action="" method="post">
<h1>User Settings</h1>
<table width="800px">
	<?php if($_SESSION['Admin']==1)
	{
		echo "<select name='User' id='User' onChange='getUserInfo()'>
			<option value='-1'>[New User]</option>";
		$result2 = DB::Query("SELECT ID,FullName, Username FROM Users");
		while($row2 = mysql_fetch_array($result2))
		{
			echo "<option value='$row2[ID]' ".($row2['ID'] == $_SESSION['UID'] ? 'selected="selected"' :"").">$row2[FullName] ($row2[Username])</option>";
		}
		echo "</select>";
	}?>
	<thead>
		<tr>
			<th width="200px">Option</th>
			<th>Setting</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td class="SettingHeading" colspan="2">User Settings</td>
		</tr>
		<tr>
			<td>Full Name:</td>
			<td><input type="text" id="fullname" name="fullname" value="<?=$row['FullName'] ?>" /></td>
		</tr>
		<tr>
			<td>Username:</td>
			<td><input type="text" id="username" name="username" value="<?=$row['Username']?>" /></td>
		</tr>
		<tr>
			<td>Password:</td>
			<td><span id="passwordstuff"><a href="javascript:showPassword()">[Enter Password]</a></span></td>
		</tr>
		<tr>
			<td>Show Covers</td>
			<td><input type="checkbox" id="covers" name="covers" value="1" <?= (DB::Setting("ShowCovers",$_SESSION['UID'])==1 ? "checked='checked'" : '')?>/></td>
		</tr>
		<tr>
			<td colspan="2" class="submit"><input type="submit" name="Submit" value="Save Settings"/></td>
		</tr>
	</tbody>
</table>
</form>
</body>
</html>
Return current item: PHP-Comics