<?
$page = "edit_profile.php";
include "manager_header.php";
if(isset($_POST['task'])) { $task = $_POST['task']; } elseif(isset($_GET['task'])) { $task = $_GET['task']; } else { $task = "main"; }
$is_error = "no";
$error = "";


if($task == "cancel") { 
header("Location: edit_profile.php"); 
exit(); 
}


if($task == "dosave") {

$oldpass = $_POST['oldpass'];
$newpass1 = $_POST['newpass1'];
$newpass2 = $_POST['newpass2'];

 if(preg_match("/[^a-z,A-Z,0-9]/", $newpass1)) {
 $is_error = "yes";
 $error = "$changepass2";
 }
 if($newpass1 != $newpass2) {
 $is_error = "yes";
 $error = "$changepass3";
 }
 if(strlen($newpass2) < 4) { 
 $is_error = "yes";
 $error = "$changepass4";
 }
 if(crypt($oldpass, $user_info[code]) != $user_info[password]) {
 $is_error = "yes";
 $error = "$changepass5";
 }
 if($oldpass == "" | $newpass1 == "" | $newpass2 == "") {
 $is_error = "yes";
 $error = "$changepass6";
 }


if($is_error != "yes") {

$newpass1 = crypt($newpass1, $user_info[code]);
mysql_query("UPDATE bhost_users SET password='$newpass1' WHERE u_id='$user_info[u_id]'");
setcookie("password", "$newpass1", 0, "/");

echo $head;
echo "
<h2>$changepass7</h2>
$changepass8
<br><br>
<form action='edit_profile.php' method='POST'>
<input type='submit' class='button' value='$changepass9'>
</form>
";
echo $foot;
exit();
}}



echo $head;
echo "
<h2>$changepass10</h2>
$changepass11
";
if($is_error == "yes") { echo "<br><i>$error</i>"; }
echo "
<br><br>

<table cellpadding='0' cellspacing='0' class='form'>
<form action='changepass.php' method='POST'>
<tr><td class='form1'>$changepass12</td><td class='form2'><input type='password' class='text' name='oldpass'></td></tr>
<tr><td class='form1'>$changepass13</td><td class='form2'><input type='password' class='text' name='newpass1'></td></tr>
<tr><td class='form1'>$changepass14</td><td class='form2'><input type='password' class='text' name='newpass2'></td></tr>
</table>

<br>
<table cellspacing='0' cellpadding='0'>
<tr>
<td><input class='button' name='submit' type='submit' value='$changepass15'></td>
<input type='hidden' name='task' value='dosave'>
</form>
<form action='changepass.php' method='POST'>
<td>&nbsp;<input class='button' name='submit' type='submit' value='$changepass1'></td>
<input type='hidden' name='task' value='cancel'>
</form>
</tr>
</table>
";
echo $foot;
?>