<?php
include 'config/config.php';
if(!isset($_SESSION)) 
session_start();
if(isset($_SESSION['admin_wsvc']))
{
header("location:settings.php");
}
else
{
include 'common/header.php';
$error = "";
 ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Reset Password: <?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>Reset Password</h1>
                <a href="#" onclick="window.history.back();" class="back-button big page-back"></a>
            </div>
        </div>


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

if((isset($_POST['email']) && $_POST['email']!="") || (isset($_POST['username']) && $_POST['username']!=""))
{
$email = "";
$username="";
if($_POST["email"]!="")
{
$email = $_POST["email"];
$username=$_POST["username"];
$match = "select username from settings"; 
$qry = mysql_query($match);
$num_rows = mysql_num_rows($qry); 
if ($num_rows > 0)
{
while($row = mysql_fetch_array($qry)) 
{
$username = $row['username'];
}
}
if(!checkEmail($email))
{
$error .="o. Invalid Email Address<br />";
}
if(!email_exists($email))
{
$error .="o. Email Doesn't Exists<br />";
}
}
else if($_POST["username"]!="")
{
$username=$_POST["username"];
$match = "select email from settings"; 
$qry = mysql_query($match);
$num_rows = mysql_num_rows($qry); 
if ($num_rows > 0)
{
while($row = mysql_fetch_array($qry)) 
{
$email = $row['email'];
}
}
else
{
$error .="o. Username Doesn't Exists<br />";
}
}
if(email_exists($email,0) && $error=="")
{
send_email(get_admin_email(),$email,"Password Reset Request",$username . " please click on the link below to reset your password\n" . rootpath() . "/reset.php?rid=" . sencrypt($email));
}
}
?>
<form action="reset.php" method="post">
<ul>
<h3>Enter Email</h3>
<div class="input-control text span5">
<input type="text" name="email" placeholder="Email" />
</div>
<div align="center"><h2>OR</h2></div>
<h3>Enter Username</h3>
<div class="input-control text span5">
<input type="text" name="username" placeholder="Username" />
</div>
<div id="login_buttons" class="span5">
<input type="submit" class="bg-color-green" value="Reset">
</div>
<?php
if($error!="")
{ 
$error = "<b>Error.</b> <br />" . $error;
?>
<span class="label important"><?php echo($error); ?></span>
<?php } 
else
{
if(isset($_GET['rid']) && $_GET['rid']!="")
{
$dec_email = sdecrypt($_GET['rid']);
if(email_exists($dec_email,0))
{
reset_pass($dec_email);
?>
<span class="label success">New Password Generated And Emailed To You !</span>
<?php }
else
{ ?>
<span class="label important">o. Request Session Timed Out Or Invalid Request</span>
<?php }
 }
else if($_POST['email'] || $_POST['username'])
{ ?>
<span class="label success">Password Reset Request Sent To Your Email !</span>
<?php }
 }?>
</ul>
</form>

</div>                </div>

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

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