<?php

include ('header.php');



if ($op=="email") {

	$query="update users set pn_email='$email' where pn_uname='$username'";
	$result=$dbconn->execute($query);

	$useremail=$email;

}



elseif ($op=="pass") {

	$pass1=md5($newpass1);
	$pass2=md5($newpass2);
	$currentpass=md5($currentpass);


	$query="select count(pn_uname) from users where pn_uname='$username' and pn_pass='$currentpass'";
	$result=$dbconn->Execute($query);

	list($passcheck)=$result->fields;

	if($passcheck==1 and $pass1==$pass2 and strlen($newpass1)>0) {
	$query="update users set pn_pass='$pass1' where pn_uname='$username'";
	$result=$dbconn->Execute($query);
	$_SESSION['pass'] = $pass1;
	echo "Password has been reset for user $username<BR>";
}
else {
	if ($passcheck!=1) {Echo "Incorrect current password provided<BR>";}
	if ($pass1!=$pass2) {echo "New passwords don't match<BR>";}
}
}



echo "
	<b>$username Settings</b><br>

	<form method=\"post\" action=\"user.php?op=email\">
	<table>
        <td>Email:</td>
        <td><INPUT type=\"text\" name=\"email\" value=\"$useremail\"></td>
        </tr>
        </table>
	<input type=\"submit\" name=\"submit\" value=\"Update Email\">
	</form>



	<FORM method=\"POST\" action=\"user.php?op=pass\">
	<table>
	<tr>
	<td>Current password:</td>
	<td><INPUT type=\"password\" name=\"currentpass\" value=\"\"></td>
	</tr>
	<tr>
	<td>New Password:</td>
	<td><INPUT type=\"password\" name=\"newpass1\" value=\"\"></td>
	</tr>
	<tr>
        <td></td>
        <td><INPUT type=\"password\" name=\"newpass2\" value=\"\"></td>
        </tr>
	<tr>
	<td><input type=\"submit\" name=\"saveuserinfo\" value=\"Change Password\"></td>
	<td></td>
	</tr>
	</table>
	</FORM>";


include ('footer.php');

?>
