<?
$page = "admin_changepass.php";
include "admin_header.php";
if(isset($_POST['task'])) { $task = $_POST['task']; }




if($task == "changepass") {

$submit = $_POST['submit'];
if($submit == "$admin_changepass12") { header("Location: admin.php"); exit(); }
$username_new = $_POST['username_new'];
$password_new = $_POST['password_new'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$is_error = "no";

// FIELD ERRORS
if((strlen($username_new) < 4 & $username_new != "") | str_replace(" ", "", $username_new) == "") { $is_error = "yes"; $error = $admin_changepass13; }
if((strlen($password_new) < 4 & $password_new != "") | str_replace(" ", "", $password_new) == "") { $is_error = "yes"; $error = $admin_changepass14; }
if(str_replace(" ", "", $fname) == "" | str_replace(" ", "", $lname) == "") { $is_error = "yes"; $error = $admin_changepass15; }

if($is_error == "yes") {
echo $head;
echo "
<h2>$admin_changepass16</h2>
$error<br><br><input type='button' class='button' value='$admin_changepass17' onClick='history.go(-1);'>
";
echo $foot;
exit();
}


if(str_replace(" ", "", $username_new) != "") {
$user = crypt($username_new, "admin");
setcookie("admin_username", "$user", 0, "/");
} else {
$username_new = $admin_info[username];
}
if(str_replace(" ", "", $password_new) != "") {
$pass = crypt($password_new, "admin");
setcookie("admin_password", "$pass", 0, "/");
} else {
$password_new = $admin_info[password];
}

mysql_query("UPDATE bhost_admin SET username='$username_new', password='$password_new', fname='$fname', lname='$lname', email='$email'");

echo $head;
echo "
<h2>$admin_changepass1</h2>
$admin_changepass2
<br><br>
<form action='admin.php' method='POST'>
<input type='submit' class='button' value='$admin_changepass3'>
</form>
";

echo $foot;
exit();




} else {



echo $head;
echo "
<h2>$admin_changepass4</h2>
$admin_changepass5 
<br><br>
<form action='admin_changepass.php' method='POST'>

<table cellpadding='0' cellspacing='0'>
<tr>
<td>
$admin_changepass6<br>
<input type='text' class='text' name='username_new' value='$admin_info[username]'>&nbsp;
</td>
<td>
$admin_changepass7<br>
<input type='password' class='text' name='password_new' value='$admin_info[password]'>
</td></tr>
<tr><td colspan='2'>&nbsp;</td></tr>
<tr>
<td>
$admin_changepass8<br>
<input type='text' class='text' name='fname' value='$admin_info[fname]'>
</td>
<td>
$admin_changepass9<br>
<input type='text' class='text' name='lname' value='$admin_info[lname]'>
</td>
</tr>
<tr><td colspan='2'>&nbsp;</td></tr>
<tr>
<td colspan='2'>
$admin_changepass10<br>
<input type='text' class='text' name='email' value='$admin_info[email]'>
</td>
</tr>
</table>

<br>

<input type='submit' name='submit' class='button' value='$admin_changepass11'>
<input type='submit' name='submit' class='button' value='$admin_changepass12'>
<input type='hidden' name='task' value='changepass'>
</form>
";

echo $foot;
}

?>