<?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:black;font-weight:bold;" >
                        <div class="panel-title">USER SIGN IN</div>
                        <div style="float:right;font-size: 80%; position:relative;margin-top:-20px;color:black;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="">
                                    
                            <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">
                                    <div class="col-md-12 control">
                                        <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

     
    if(isset($_POST['submit1'])){
			
		 $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 ($nums > 0) {
				  // check whether user is active
				  if( $rws['status'] == "Active"){
					   $id = $rws['customer_id'];
					   echo "Am here."
						$_SESSION['id'] = $rws['customer_id']; 
						//insert logs
						$query = mysql_query("insert into airtime_logs values('','$id', Now(), Now(), 'Logged into the System.','') ");
						if($query){
							// 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>
	

