<?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">Admin Login</div>
                        <div style="float:right;font-size: 80%; position:relative;margin-top:-20px;color:black;font-weight:bold;" ><a href="#">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 id="loginform" name="form" class="form-horizontal" role="form" method="post" action="">
                                    
                            <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="eml" 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="submitx"  value="Login" id="btn-login" class="btn btn-success"  />
									<!--button id="lft" type="button" class="btn btn-error"><i class="icon-hand-right"></i><a href="login.php"> &nbsp Cancel </a></button-->
                  

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


                        </div>                     
                    </div>  
        </div>
		
								<?php

     
    if(isset($_POST['submitx'])){
			
		 $usr = $_POST['eml'];   
		 $password = $_POST['pword']; 
		 
		 
		 /////////////////////////////////////////////////////////////////////////////////////////////////////////
        try{
            $hostname = "localhost";
            $database = "ki223469_temp";
            $dbusername = "ki223469_temp";
            $dbpass = "m0bi.2018$";
            
            $pdo = new PDO("mysql:host=$hostname;dbname=$database", $dbusername, $dbpass);
            $sql = $pdo->prepare('SELECT * FROM airtime_customer WHERE username=:uname and user_type=:utype');
            $sql->execute(array(':uname' => $usr,':utype'=>'Admin'));
            $rws = $sql->fetch();
            
            $pas = $rws['password'];
		   
		   if (password_verify($password, $rws['password']))
		   {
		       
				  // 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="adminpage.php";
								</script>
							<?php
						}
						
				  }else{
					  ?>
						<script>
						   alert("Sorry! Your Account has been blocked. Please contact your Mobisky Admin");
							window.location="index.php";
							</script>
						<?php
				  }
			
		
		   }
		   else{
		       ?>
						<script>
						   alert("Sorry! Your Account has been blocked. Please contact your Mobisky Admin");
							window.location="index.php";
							</script>
						<?php
		   }
            
            
        }
        catch(Exception $e)
        {
                                var_dump($e->getMessage());
                                $user['error'] = var_dump($e->getMessage());
                                echo var_dump($e->getMessage());
                                //file_put_contents("feedback.log",$e->getMessage(),FILE_APPEND);
        }
		
			/*	$query = mysql_query("select * from airtime_customer where username = '$usr' and user_type = 'Admin' ") or die (mysql_error());
							$nums = mysql_num_rows($query);
							$rows = mysql_fetch_array($query);
							
						//	echo $nums;
		                if (password_verify($password, $rows['password']))
		                {
							if ($nums > 0) {
							    //echo "Reached";
								  // check whether user is active
								if( $rows['status'] == "Active"){
								   // echo $rows['status'];
									$id = $rows['customer_id'];
									$_SESSION['id'] = $rows['customer_id'];
									?>
										<script>
											window.location="adminpage.php";
										</script>
									<?php
									//insert logs
										$querys = mysql_query("insert into airtime_logs values('','$id', Now(), Now(), '','') ");
											if($querys){
												// save user log id
												$logid = mysql_insert_id();
												$_SESSION['log_id'] = $logid; 
													
											}
									
									}else{
										?>
										<script>
											alert("Sorry! Your Account has been blocked. Please contact Mobisky Admin for help.");
											window.location="index.php";
										</script>
										<?php
									}
									
								}
		                }
								else {
										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>
	

