<title>Recover password / Recuperare parola - <?php echo Config::$_SITE_NAME; ?></title>
<?php
if(!defined('panel'))
	die('Nope.');
if(isset($_SESSION['user'])) echo '<meta http-equiv="refresh" content="0;URL=\''.Config::$_PAGE_URL.'\'/>';
?>
</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">
<?php
		$ipaddress = getenv("REMOTE_ADDR") ; 
		$now = date("Y-m-d H:i:s");

if(isset($_POST['submit'])) {
	if(!$_POST['recover']) {
		echo '<div class="alert alert-block alert-danger">Complete the field.</div>';
	} else {
		$q = Config::$g_con->prepare('SELECT * FROM `users` WHERE `name` = ?');
		$q->execute(array($_POST['recover']));
		while($row = $q->fetch(PDO::FETCH_OBJ))
		if($q->rowCount()) {
			$d = Config::$g_con->prepare('SELECT * FROM `recover` WHERE `name` = ?');
			$d->execute(array($_POST['recover']));
			if($d->rowCount()) {
				echo '<div class="alert alert-block alert-danger">Ai mai f&#259;cut deja o cerere de recuperare a parolei.</div>';
			}
			elseif($row->Email == "") {
				echo '<div class="alert alert-block alert-danger">Acest cont nu are o adres&#259; de Email.</div>';
			}
			else {
				
				$email = $row->Email;
				$user = $row->name;

				$first = md5(uniqid());
				$final_key = $first . md5($first);
				
				$s = Config::$g_con->prepare("INSERT INTO recover (RecoverKey, name, email) VALUES (?, ?, ?)");
				$s->execute(array($final_key, $user, $email));

require 'inc/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'link mail firma de webhost';
$mail->SMTPAuth = false;
$mail->Username = 'user mail webhost;
$mail->Password = 'pass mail webhost';
$mail->SMTPSecure = 'tls';
$mail->Port = 25;
$mail->setFrom('user mail webhost', 'site link');
$mail->addAddress($email);
$mail->Subject = 'nume site - password recovery / recuperare parola';
$mail->Body    = "$user,
[RO] Ai primit acest email pentru ca ai solicitat resetarea parolei pe serverul nume server
Daca nu doresti sa iti schimbi parola, poti ignora/sterge acest email.
Pentru a-ti schimba parola, da click pe link-ul de mai jos: 
".Config::$_PAGE_URL."change/".$final_key."


[EN] You have recived this email because you have requested a reset of your password on nume server
If you don't want to change your password, please ignore this email. 
To change your password, please click the link above this message.

Cu stima,
Echipa nume server
Contact: mailu tau";
if(!$mail->send()) {
    echo 'Email could not be sent.';
} else {
$email1 = explode('@', $email);				
$first_part = $email1[0];					
$domain = $email1[1];
$newemail = substr($first_part, 0, 4) . "****@" . substr($domain, 0, 10);
echo "<div class='alert alert-block alert-success'><center>Code sent!<br />The verification code was sent to ". $newemail ."!<br />Please check your email. Also check the Spam folder!</center></div>";
}
					
					
			}
			
		}
		else echo '<div class="alert alert-block alert-danger">Nume incorect.</div>';
	}
}


?>

<div class="row-fluid">
<div class="span12">
<center>
<form method="POST" action="" accept-charset="UTF-8">
<label>Username:</label><br />
<input type="text" name="recover"><br />
<br>
<input class="btn btn-inverse" name="submit" type="submit" value="Recover password">
</form>
</center>
