<?php session_start();
include("header.php");
require_once('dbcon.php');
?>
<head>
<!-- Bootstrap -->
    <link href="vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
	</head>
	
<div class="container">
	 <div id="loginbox" style="display:block;margin-top:200px;" class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">                    
            <div class="panel panel-info" >
                    <div class="panel-heading" style="background-color:#ea7d09;color:#fff;font-weight:bold;" >
                        <div class="panel-title">USER SIGN IN</div>
                        <div style="float:right;font-size: 80%; position:relative;margin-top:-20px;font-weight:bold;"><a href="resetpword.php">Forgot password?</a></div>
                    </div>     

                    <div style="padding-top:30px" class="panel-body" >

                        <div style="display:none" id="login-alert" class="alert alert-danger col-sm-12"></div>
                            
                         <form  class="form-horizontal" role="form" method="post" action="dr.php">
                                    
                            <div style="margin-bottom: 25px" class="input-group">
                                        <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
                                        <input id="username" type="text" class="form-control" name="usernm" placeholder="Username" required>                                        
                            </div>
                                
                            <div style="margin-bottom: 25px" class="input-group">
                                        <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
                                        <input  id="password" type="password" class="form-control" name="pword" placeholder="Password" required>
                                    </div>
                                    

                                
                            <div class="input-group">
                                      <div class="checkbox">
                                        <label>
                                          <input id="login-remember" type="checkbox" name="rememberme" value="1"> Remember me
                                        </label>
                                      </div>
                                    </div>


                                <div style="margin-top:10px;margin-bottom:20px;" class="form-group">
                                    <!-- Button -->

                                    <div class="col-sm-12 controls">
                                   <input type="submit" name="submit1"  value="Login" id="btn-login"  class="btn btn-success pull-left"  />
									<button id="lft" type="button" class="btn btn-error pull-right"><i class="icon-hand-right"></i><a href="index.php"> &nbsp; <b><< Back </b></a></button>
                  

                                    </div>
                                </div>
								
<hr/>
                                <div class="form-group" style="margin-top:10px;margin-bottom:5px;">
                                    <div class="col-md-12 control">
                                         <a style="background-color:#ea7d09;color:#fff;font-weight:bold;"  rel="tooltip" title="Admin Login"  href="/admin"  class="btn btn-warning btn-sm pull-left"> <b>Admin Login</b> </a>
                                        <!--div style="border-top: 1px solid#888; padding-top:15px;font-size:85%" >    
                                        <a style="margin-left:150px;background-color:#ea7d09;color:black;font-weight:bold;" class="btn btn-" rel="tooltip" title="Admin Login"  href="signup.php"  >  &nbsp;&nbsp;New User? Register Now! </a>
										
                                        </div-->
                                    </div>
                                </div>    
                            </form>     
	


                        </div>                     
                    </div>  
        </div>
		
		
		
		<?php
$db_host="localhost"; //localhost server 
$db_user="ki223469_temp"; //database username
$db_password="m0bi.2018$"; //database password   
$db_name="ki223469_temp"; //database name

try
{
 $db=new PDO("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_password);
 $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOEXCEPTION $e)
{
 $e->getMessage();
}

?>
		
		
		<?php
if(isset($errorMsg))
{
 foreach($errorMsg as $error)
 {
 ?>
  <div class="alert alert-danger">
   <strong><?php echo $error; ?></strong>
  </div>
    <?php
 }
}
if(isset($loginMsg))
{
?>
 <div class="alert alert-success">
  <strong><?php echo $loginMsg; ?></strong>
 </div>
<?php
}
?>
		
		
		<?php

require_once 'connection.php';

session_start();
   if(isset($_POST['submit1'])){
//if(isset($_SESSION["user_login"])) //check condition session user login not direct back to index.php page
//{
 header("location: welcome.php");
}

if(isset($_REQUEST['btn_login'])) //button name is "btn_login" 
{

 $username =strip_tags($_REQUEST["usernm"]); //textbox name "txt_username_email"
 $email  =strip_tags($_REQUEST["txt_username_email"]); //textbox name "txt_username_email"
 $password =strip_tags($_REQUEST["pword"]);   //textbox name "txt_password"
  
 if(empty($username)){      
  $errorMsg[]="please enter username or email"; //check "username/email" textbox not empty 
 }
 else if(empty($email)){
  $errorMsg[]="please enter username or email"; //check "username/email" textbox not empty 
 }
 else if(empty($password)){
  $errorMsg[]="please enter password"; //check "passowrd" textbox not empty 
 }
 else
 {
  try
  {
      		// $query = mysql_query("select * from airtime_customer where username ='$usr' and password = '$password' and user_type='normal' ") or die (mysql_error());

   $select_stmt=$db->prepare("SELECT * FROM airtime_customer WHERE username=:uname and user_type='normal' "); //sql select query
   $select_stmt->execute(array(':uname'=>$username, ':uemail'=>$email)); //execute query with bind parameter
   $row=$select_stmt->fetch(PDO::FETCH_ASSOC);
   
   if($select_stmt->rowCount() > 0) //check condition database record greater zero after continue
   {
    if($username==$row["username"] OR $email==$row["email"]) //check condition user taypable "username or email" are both match from database "username or email" after continue
    {
     if(password_verify($password, $row["password"])) //check condition user taypable "password" are match from database "password" using password_verify() after continue
     {
      $_SESSION["user_login"] = $row["user_id"]; //session name is "user_login"
      $loginMsg = "Successfully Login...";  //user login success message
      header("refresh:2; welcome.php");   //refresh 2 second after redirect to "welcome.php" page
     }
     else
     {
      $errorMsg[]="wrong password";
     }
    }
    else
    {
     $errorMsg[]="wrong username or email";
    }
   }
   else
   {
    $errorMsg[]="wrong username or email";
   }
  }
  catch(PDOException $e)
  {
   $e->getMessage();
  }  
 }
}
?>
		
		
		
		
		
		
		
								<?php
    if(isset($_POST['submit1iiiiiiiii'])){
			
		 $usr = $_POST['usernm'];   
		 $password = $_POST['pword']; 
		 
		 
		 $query = mysql_query("select * from airtime_customer where username ='$usr' and password = '$password' and user_type='normal' ") or die (mysql_error());
		  $rws = mysql_fetch_array($query);
		   $nums = mysql_num_rows($query);
		   $pas = $rws['password'];
		  
		  
		  if (password_verify($password, $pas)) {
    // Success!  
    echo $pas;
    
    echo 'Password Matches';
    exit();
}else {
    	 echo  $pas = $rws['password'];
    	
    // Invalid credentials
    echo $pas;
    
    echo 'Password Mismatch';
     exit();
}
		  
		  
		  
		  
			  if ($nums > 0) {
				  // check whether user is active
				  if( $rws['status'] == "Active"){
					   $id = $rws['customer_id'];
						$_SESSION['id'] = $rws['customer_id']; 
						//insert logs
						$query2 = mysql_query("insert into airtime_logs(customer_id,login_date,login_time,user_actions) values('$id',Now(),Now(),'Logged into the System.') ") or die (mysql_error());
						if($query2){
							// save user log id
							$logid = mysql_insert_id();
							$_SESSION['log_id'] = $logid; 
							?>
								<script>
									window.location="homepage.php";
								</script>
							<?php
						}
						
				  }else{
					  ?>
						<script>
						   alert("Sorry! Your Account has been blocked. Please contact your Account Admin");
							window.location="login.php";
							</script>
						<?php
				  }
			
			}
			else {
				 ?>
				<script>
					alert("Error! Invalid Username or Password. Please try again."); 
				</script>
			<?php
			  /* echo ' <div class="col-md-offset-3 col-md-9">
                      <button id="btn-signup" type="button" class="btn btn-error"><i class="icon-hand-right"></i>Invalid Username or Password! </button>                  
                    </div>'; */
			}

	}

?>
</div>

   <!--?php include("footerlinks.php"); ?-->
	 
	  <script src="vendors/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="vendors/bootstrap/dist/js/bootstrap.min.js"></script>
	

