<?php 
if(!isset($_SESSION)) 
session_start();
if(!isset($_SESSION['admin_wsvc']))
{
header("location: admin.php");
}
include 'common/header.php';
$error = "";
 ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- TemplateBeginEditable name="doctitle" -->
<title>Edit Login Details: <?php echo(get_title()) ?></title>
</head>
<body class="metrouicss" onload="prettyPrint()">
<div class="container" style="width:940px;margin: auto">
<div class="page">
<div class="nav-bar" style="background:<?php echo(retColor()); ?>">
    <div class="nav-bar-inner padding10">
        <span class="pull-menu"></span>

        <a href="<?php echo(rootpath()) ?>"><span class="element brand">
            <img class="place-left" src="images/logo32.png" style="height: 20px"/>
            <?php echo(get_title()) ?>
        </span></a>
    </div>
</div>
</div>

    <div class="page secondary with-sidebar">
        <div class="page-header">
            <div class="page-header-content">
                <h1>Login Details</h1>
                <a href="#" onclick="window.history.back();" class="back-button big page-back"></a>
            </div>
        </div>

        <?php include 'inc/sidebar.php'; ?>

        <div class="page-region">
            <div class="page-region-content">
                <div class="span5" style="padding-top:50px">
                     <div class="grid">
					 <div class="row">
					 <?php

if(isset($_POST['username']) && isset($_POST['oldpassword']) && isset($_POST['email']))
{
$username = $_POST["username"];
$oldpassword = md5($_POST["oldpassword"]);
$match = "select password from settings"; 
$qry = mysql_query($match);
$num_rows = mysql_num_rows($qry); 
$row = mysql_fetch_array($qry);
if($row['password']!=$oldpassword || $_POST['oldpassword']=="")
$error .="o. Invalid Password User Details Can't Be Changed<br />";
if(isset($_POST['password']) && $_POST['password']!="")
$password = md5($_POST["password"]);
$email = $_POST["email"];
if(!is_alpha($username))
{
$error .="o. Username Can Only Contain Letters a-Z<br />";
}
if(strlen($username)<5 || strlen($username)>15)
{
$error .="o. Username Length Must Be Between 5 to 15 Characters<br />";
}
if(strlen($_POST["password"])<6 || strlen($_POST["password"])>18)
{
if($_POST["password"]!="")
$error .="o. Password Length Must Be Between 6 to 18 Characters<br />";
}

if(!checkEmail($email))
{
$error .="o. Invalid Email Address<br />";
}
if($error=="")
{
update_user($username,$password,$email);
}
}
$match = "select username,email from settings"; 
$qry = mysql_query($match);
$num_rows = mysql_num_rows($qry); 
if ($num_rows > 0)
{
$row = mysql_fetch_array($qry) 
?>
<form action="user.php" method="post">
<ul>
<h2>Username</h2>
<div class="input-control text span5">
<input type="text" name="username" placeholder="Username" value="<?php echo($row['username']); ?>"/>
</div>
<h2>Email Address</h2>
<div class="input-control text span5">
<input type="text" name="email" placeholder="Email" value="<?php echo($row['email']); ?>"/>
</div>
<h2>Current Password</h2>
<div class="input-control password text span5">
<input type="password" name="oldpassword" placeholder="Enter Password" />
</div>
<h2>New Password</h2>
<div class="input-control password text span5">
<input type="password" name="password" placeholder="New Password (Optional)" />
</div>
	<div id="login_buttons">
<input type="submit" class="bg-color-green" value="Update">
</div>
<?php }
if($error!="")
{ 
$error = "<b>Error.</b> <br />" . $error;
?>
<span class="label important"><?php echo($error); ?></span>
<?php } 
else
{
if(isset($_POST['username']))
{
?>
<span class="label success">User Updated Successfully</span>
<?php } }?>
</ul>
</form>
</div>                </div>

				</div>
            </div>
        </div>
    </div>

<?php include 'common/footer.php'; ?>