<?
require('../include/startup.php');
$formAction="forgot_password";
$buttonValue = "Submit";
#################################   FORGOT PASSWORD     #########################################
if(isset($_REQUEST['action']) && $_REQUEST['action']=='forgot_password'){
	$email = $_REQUEST['email'];
	if(empty($email)){
		$message = "Please enter email";
	}else{		
		global $db,$conn;
		$getUser = $db->query("SELECT * FROM job WHERE email='".$email."' ");
		if ($db->num_rows($getUser) > 0){		
			$rowUser	= $db->next_record($getUser);
			
			$password = $rowUser["password"];
			$first_name = $rowUser["first_name1"];
			$last_name = $rowUser["last_name1"];
			$username = $rowUser["email"];
			$client_name = $first_name." ".$last_name;
			$site_name = $config->siteName;
			
			$subject 	= utility::getTableFieldById("mail_format","mail_format_subject","mail_format_name","forget_password");
			$mail_body 	= utility::getTableFieldById("mail_format","mail_format_body","mail_format_name","forget_password");$find_array = array("[site_name]","[client_name]","[username]","[password]");
			$replace_array = array($site_name,$client_name,$username,$password);
			$mail_body = str_replace($find_array, $replace_array, $mail_body);
			//echo $functions->HTMLemail($mail_body);
			//die;
			$file_path 		= array();
			$site_email = $config->siteEmail;
			//mail($email, $subject , $functions->HTMLemail($mail_body) ,$headers );	
			if(utility::mailSMTP($email, $subject, $functions->HTMLemailWithoutSignatureBlock($mail_body), $file_path,$site_email,$site_email,"","")){
				$message = "An email conataining your password has been sent to your email address";
				$msg_color = "success";
			}else{
				$message = "There is some error.";
				$msg_color = "danger";
			}
		}else{
			$message = "Invalid user ! ";
			$msg_color = "danger";
		}
	}
}
#################################   END FORGOT PASSWORD    #########################################
?>

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>:: BEB ::</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="<?php echo $siteURL ?>/bootstrap/css/bootstrap.css">
    <!-- Font Awesome -->
    <!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">-->
    <!-- Ionicons -->
    <!--<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">-->
    <!-- iCheck for checkboxes and radio inputs -->
    <link rel="stylesheet" href="<?php echo $siteURL ?>/plugins/iCheck/all.css">
	<!-- Theme style -->
    <link rel="stylesheet" href="<?php echo $siteURL ?>/dist/css/AdminLTE.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="<?php echo $siteURL ?>/plugins/iCheck/square/blue.css">

</head>
<body class="hold-transition login-page">
<div class="login-box">
  <div class="login-logo">
	<img id="" src="<?php echo $siteURL ?>/images/logo.png" style="width: 180px;"><br>
  </div><!-- /.login-logo -->
  <div class="login-box-body">
	<? if(isset($message) && $message!=''){?>
	<div class="callout callout-<?=$msg_color;?>">
	  <?=$message;?>
	</div>
	<? }else{ ?>
		<div class="callout callout-info">Sign in to start your session</div>
	<? } ?>
	<form name="form1" method="post" action="?action=<?php echo $formAction; ?>">
	  <div class="form-group has-feedback">
		<input type="email" class="form-control" name="email" placeholder="email" required>
		<span class="glyphicon glyphicon-user form-control-feedback"></span>
	  </div>          
	  <div class="row">
		<div class="col-xs-8">
		  
		</div><!-- /.col -->
		<div class="col-xs-4">
		  <!--<button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button>-->
		  <input name="submit" class="btn btn-primary btn-block btn-flat" type="submit" value="Submit">
		</div><!-- /.col -->
	  </div>
	</form>
	<a href="<?=$config->siteURL;?>/index">Login</a><br>
  </div><!-- /.login-box-body -->
</div><!-- /.login-box -->
<!-- jQuery 2.1.4 -->
    <script src="<?php echo $siteURL ?>/plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="<?php echo $siteURL ?>/bootstrap/js/bootstrap.min.js"></script>
    <!-- iCheck -->
    <script src="<?php echo $siteURL ?>/plugins/iCheck/icheck.min.js"></script>
</body>
</html>
<style>
.login-box, .register-box{
	  margin: 4% auto;
}	
</style>