<title><?php echo Config::$_SITE_NAME; ?></title>
<?php
if(!defined('panel'))
	die('Nope.');	

if(!isset(Config::$_url[1])) {
	echo '
<title>Error! Invalid ID</title>
	</div>
	<div class="main-content">	
			<div class="breadcrumbs" id="breadcrumbs">
				<script type="text/javascript">
					try{ace.settings.check("breadcrumbs" , "fixed")}catch(e){}
				</script>

				<ul class="breadcrumb">
					<li>
						<i class="ace-icon fa fa-home home-icon"></i>
						<a href="<?php echo Config::$_PAGE_URL; ?>">Home</a>
					</li>
				</ul><!-- /.breadcrumb -->

				<div class="nav-search" id="nav-search">
					<form method="POST" action="<?php echo Config::$_PAGE_URL; ?>search">
						<span class="input-icon">
							<input type="text" placeholder="Search ..." name="sname" id="username" type="submit" class="nav-search-input" autocomplete="on"> 
							<i class="ace-icon fa fa-search nav-search-icon"></i>
						</span>
					</form>
				</div> <!-- /.nav-search -->
			</div>

	<div class="page-content">	
	<div class="alert alert-danger">Error! Invalid ID.</div>';
	echo '<meta http-equiv="refresh" content="0;URL=\''.Config::$_PAGE_URL.'\'/>';
	return;
}
?>
</div>
	<div class="main-content">
			<div class="breadcrumbs" id="breadcrumbs">
				<script type="text/javascript">
					try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
				</script>

				<ul class="breadcrumb">
					<li>
						<i class="ace-icon fa fa-home home-icon"></i>
						<a href="<?php echo Config::$_PAGE_URL; ?>">Home</a>
					</li>
					<li class="active">Password recovery</li>
				</ul><!-- /.breadcrumb -->

				<div class="nav-search" id="nav-search">
					<form method="POST" action="<?php echo Config::$_PAGE_URL; ?>search">
						<span class="input-icon">
							<input type="text" placeholder="Search ..." name="sname" id="username" type="submit" class="nav-search-input" autocomplete="on"> 
							<i class="ace-icon fa fa-search nav-search-icon"></i>
						</span>
					</form>
				</div> <!-- /.nav-search -->
			</div>	
<div class="page-content">
<div class="row-fluid">
<div class="span12">
<?php 
	$q = Config::$g_con->prepare('SELECT * FROM `recover` WHERE `RecoverKey` = ?'); 
	$q->execute(array(Config::$_url[1]));
	if($row = $q->fetch(PDO::FETCH_OBJ)) {
if(isset($_POST['submit'])) {
	if(!$_POST['password']) {
		echo '<div class="alert alert-block alert-danger">Complete the field.</div>';
	} else {
	$q = Config::$g_con->prepare('UPDATE `users` SET `password` = ? WHERE `name` = ?');
	$q->execute(array(htmlspecialchars($_POST['password']),$row->name));	
	
	$dele = Config::$g_con->prepare("DELETE FROM recover WHERE RecoverKey='".Config::$_url[1]."'");
	$dele->execute();
	
	die("<div class='alert alert-block alert-success'>Password changed!<br />
Your password has been changed!<br />
Your new password is ". htmlspecialchars($_POST['password']) ."</div>");
}
}
?>
<center>
<div class="alert alert-info">
<h4>Change your password</h4>
You can now chooose a new password!
</div>
<form method="POST" action="" accept-charset="UTF-8">
<label for="password">New password:</label><br />
<input placeholder="Type your new password here.." name="password" type="text" value="" id="password"><br /><br/>
<input class="btn btn-inverse" name="submit" type="submit" value="Change password">
</form>
</center>
<?php } else { ?>
<div class="alert alert-danger">
<h4>Invalid recovery code.</h4>
The recovery link is invalid. Please try again.<br/>
The links expire after 2 days. You can request a new password recovery <a href="<?php echo Config::$_PAGE_URL; ?>recover">here</a>.
</div>
<?php } ?>