<?php
session_start();
include_once('../../../db_connect/db.php');
	 $email=htmlspecialchars($_POST['email'],ENT_QUOTES);
	 $password=mysqli_real_escape_string($conn_1,$_POST['password']);
	$p_password=mysqli_real_escape_string($conn_1,md5($password));

$user_ip=$_SERVER['REMOTE_ADDR'];
	$sqlmg=mysqli_query($conn_1, "SELECT * FROM admin_users where ( email='$email' OR staff_id='$email' ) and password='$p_password' ");
									if($sqlmg){
										$sqlmg_row=mysqli_num_rows($sqlmg);
											if($sqlmg_row >0){
												$row=mysqli_fetch_assoc($sqlmg);
													$admin_user_id=$row['admin_user_id'];
													$admin_group_id=$row['admin_group_id'];
													$admin_role_id=$row['admin_role_id'];
													$admin_user_status=$row['admin_user_status'];

													if( $admin_user_status == '1' ){

														$_SESSION['admin_user_id']=$admin_user_id;
														$_SESSION['admin_group_id']=$admin_group_id;
														$_SESSION['admin_role_id']=$admin_role_id;
														$_SESSION['last_time']=time();
														$qry = "UPDATE admin_users SET online_status = 1, last_login = NOW(), last_login_ip = '$user_ip'
																  WHERE admin_user_id = '$admin_user_id'";

															$rst = mysqli_query($conn_1, $qry);

														echo 1;

													}elseif( $admin_user_status == '2' ){
														echo '<div class="alert alert-danger">
																			  <strong>Error!</strong> Account Suspended , Please contact Admin
																			</div>';
													}
												}else{


													echo '<div class="alert alert-danger">
  <strong>Error!</strong> Invalid Login details
</div>';
												}

											}

	?>
