<?php include 'inc_classes.php';?>
<?php
////==== CODE FOR LOGOUT AUTOMATICALLY===
$select_acitve_logins = " select last_login_time, admin_id from site_setting where 1  "; // status= 'Active'
$ptr_activr = mysql_query($select_acitve_logins);
if(mysql_num_rows($ptr_activr))
{
	$found_active_login = 'n';
	while($data_active = mysql_fetch_array($ptr_activr))
	{
		$timess = strtotime ($data_active['last_login_time']);
		//echo date('Y-m-d H:i:s')."<br />";
		$time_diff =time()-$timess ;
		
		if($time_diff>1800)//30 min
		{
			$my_query_status="UPDATE site_setting SET status = 'Inactive' WHERE admin_id='".$data_active['admin_id']."'";
			$ptr_query_status=mysql_query($my_query_status);
			$sel_histroy_id = " select login_id from  login_history where  admin_id='".$data_active['admin_id']."' order by login_id desc limit 0,1  ";
			$ptr_lastId = mysql_query($sel_histroy_id);
			if(mysql_num_rows($ptr_lastId))
			{
			$data_histroy_id = mysql_fetch_array($ptr_lastId);
			$update_histroy = "Update login_history set logout_time='".date('Y-m-d H:i:s')."', status='expired' where login_id='".$data_histroy_id['login_id']."'  ";		
			$ptr_update = mysql_query($update_histroy);	
			if($data_active['admin_id']==$_SESSION['admin_id'])
			{
				$found_active_login='y';
			}
			}
		}
		else
		{
			if($data_active['admin_id']==$_SESSION['admin_id'])
			$my_query_status="UPDATE site_setting SET last_login_time = '".date('Y-m-d H:i:s')."' WHERE admin_id='".$_SESSION['admin_id']."'";
			$ptr_query_status=mysql_query($my_query_status);
		}
		
		
	}
	
}
///========================================================================================================

$msg="";
if($_GET['action']=='logout')
{
	$my_query_status="UPDATE site_setting SET status = 'Inactive' WHERE admin_id='".$_SESSION['admin_id']."'";
	$ptr_query_status=mysql_query($my_query_status);
	
	 $update_histroy = " Update login_history set logout_time='".date('Y-m-d H:i:s')."', status='logout' where login_id='".$_SESSION['histroy_id']."'  ";
	
	$ptr_update = mysql_query($update_histroy);			
	session_destroy();
	$msg='Logout Successfully.';
	?><script type="text/javascript">window.location.href='login.php?msg=You have signed out';</script><?php
}
if(isset($_GET['msg']) && $_GET['msg']!=="")
{
	$msg=$_GET['msg'];
}

?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>ISAS | Log in</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.7 -->
  <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
  <!-- iCheck -->
  <link rel="stylesheet" href="plugins/iCheck/square/blue.css">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->

  <!-- Google Font -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<?php
if(isset($_POST['submit']))
{
	$type=$_POST['type'];
	$username=addslashes($_POST['username']);
	$pass=addslashes($_POST['pass']);
	//$captch= $_POST['captcha'];
	//if($type=='admin')
	//{	
	if($username && $pass) //&& $captch 
	{
		/*$sql_notification= "SELECT * FROM stud_regi where not_status='signs_off' ";
		$ptr_notification=mysql_query($sql_notification);
		$_SESSION['not_count']=mysql_num_rows($ptr_notification);*/
		
		///==== S- super admin 
		///-- A - center manage
		///=   C - councellor
		//= B = BOP
		/// F = Faculty
		
		$sql_site_setting= "SELECT username, email,  type, admin_id, designation, cm_id, branch_name, status FROM site_setting where username='".$username."' and pass='".$pass."'";
		$ptr_site_setting=mysql_query($sql_site_setting);
	   // echo $sql_site_setting;
		if(mysql_num_rows($ptr_site_setting))
		{
			/*if((trim(strtolower($_POST['captcha'])) == $_SESSION['captcha']))
			{*/
				$row_site_setting=mysql_fetch_array($ptr_site_setting);
				$cookiess_name='isas_user_'.$username;
				//echo "cookies- ".$_COOKIE[$cookiess_name];
				/*if($_COOKIE[$cookiess_name]==$username || $row_site_setting['type']=="S")
				{*/
					/*if($row_site_setting['status']=='Inactive')
					{*/
						$_SESSION['name']=$row_site_setting['username'];
						$_SESSION['email_id']=$row_site_setting['email'];
						$_SESSION['account_type']=$row_site_setting['type'];
						$_SESSION['admin_id']=$row_site_setting['admin_id'];               
						$_SESSION['type']=$row_site_setting['type'];
						$_SESSION['type_admin']='admin';
						$_SESSION['designation']=$row_site_setting['designation'];
						$_SESSION['cm_id']=$row_site_setting['cm_id'];
						$_SESSION['branch_name']=$row_site_setting['branch_name'];
						
						
						$select_last="select last_login_time,logout_time,last_login_ip,status from login_history where admin_id='".$_SESSION['admin_id']."' order by login_id desc limit 0,1";
						$ptr_last=mysql_query($select_last);
						$data_last=mysql_fetch_array($ptr_last);
						$_SESSION['last_login_time']=$data_last['last_login_time'];
						$_SESSION['logout_time']=$data_last['logout_time'];
						$_SESSION['status']=$data_last['status'];
						
						
						$ip = $_SERVER['REMOTE_ADDR'];				
						$my_query_status="UPDATE site_setting SET status = 'Active', last_login_time = '".date('Y-m-d H:i:s')."'  WHERE admin_id='".$row_site_setting['admin_id']."'";
						$ptr_query_status=mysql_query($my_query_status);
								
							
						$ins_login="insert into login_history (`last_login_time`,`last_login_ip`,`admin_id`) values('".date('Y-m-d H:i:s')."','$ip','".$row_site_setting['admin_id']."')";
						$query_login=mysql_query($ins_login);
						$_SESSION['histroy_id']= mysql_insert_id();
						
						
						$sel_branch_addr= "SELECT branch_address,gst_no,innocent_address FROM branch where branch_name='".$row_site_setting['branch_name']."'";
						$ptr_branch_addr=mysql_query($sel_branch_addr);
						if(mysql_num_rows($ptr_branch_addr))
						{
							$data_branch=mysql_fetch_array($ptr_branch_addr);
							$_SESSION['branch_address']=$data_branch['branch_address'];
							$_SESSION['innocent_address']=$data_branch['innocent_address'];
							$_SESSION['gst_no']=$data_branch['gst_no'];
							//$_SESSION['installment_tax']=$data_branch['installment_course_percentage'];
						}
						
						
						$sel_tax= "SELECT * FROM general_settings where branch_name='".$row_site_setting['branch_name']."' order by setting_id desc limit 0,1";
						$ptr_tax=mysql_query($sel_tax);
						if(mysql_num_rows($ptr_tax))
						{
							$data_tax=mysql_fetch_array($ptr_tax);
							$_SESSION['service_tax']=$data_tax['service_tax'];
							$_SESSION['installment_tax']=$data_tax['installment_course_percentage'];
							$_SESSION['cgst']=$data_tax['cgst'];
							$_SESSION['sgst']=$data_tax['sgst'];
						}
						if($row_site_setting['type']=='S')
						{
							$select_prev= " select privilege_id from staff_previleges where 1 and privilege_id='112'" ;
							$ptr_prev = mysql_query($select_prev);
							$n=0;
							while($data_staff_prev1=mysql_fetch_array($ptr_prev))
							{
								$staff_previ[$n]= $data_staff_prev1['privilege_id'];
								$n++;
							}
							$_SESSION['staff_prev']=$staff_previ;
						}
						/*if($row_site_setting['type']=='S')
						{
							$select_prev_admin= " select * from previleges where privilege_parent_id=0" ;
							$ptr_previlege = mysql_query($select_prev_admin);
							$array_previ =array();
							$array_previ_parent =array();
							$k=0;
							while($data_prevo = mysql_fetch_array($ptr_previlege))
							{
								
								"<br/>".$select_prev= " select privilege_id from previleges where previlege_parent_id='".$data_prevo['previlege_parent_id']."'" ;
								$ptr_prev = mysql_query($select_prev);
								$s=0;
								while($data_prev1=mysql_fetch_array($ptr_prev))
								{
									$array_previ[$k][$s]['privilege_id']= $data_prev1['privilege_id'];
									$s++;
								}
								
								$array_previ_parent[$k]['privilege_id']= $data_prevo['previlege_parent_id'];
								
								$k++;
							}
							
							$_SESSION['privilege_id'] =$array_previ;
							$_SESSION['privilege_id_parent'] =$array_previ_parent;
						}*/
						if($row_site_setting['type']=='A')
						{
							$select_prev_admin= " select DISTINCT(previlege_parent_id) from admin_previleges where admin_id='".$_SESSION['admin_id']."'" ;
							$ptr_previlege = mysql_query($select_prev_admin);
							$array_previ =array();
							$array_previ_parent =array();
							$k=0;
							while($data_prevo = mysql_fetch_array($ptr_previlege))
							{
								$select_prev= "SELECT u.privilege_id,u.previlege_parent_id,u.admin_id,o.privilege_parent_id ,o.privilege_id,o.seq_no FROM admin_previleges u, previleges o where 1 AND admin_id='".$_SESSION['admin_id']."' AND u.previlege_parent_id='".$data_prevo['previlege_parent_id']."' AND o.privilege_id =u.privilege_id AND o.privilege_parent_id =u.previlege_parent_id ORDER BY o.seq_no ASC"; 
								$ptr_prev = mysql_query($select_prev);
								$s=0;
								
								while($data_prev1=mysql_fetch_array($ptr_prev))
								{
									$array_previ[$k][$s]['privilege_id']= $data_prev1['privilege_id'];
									$s++;
								}
								$array_previ_parent[$k]['privilege_id']= $data_prevo['previlege_parent_id'];
								$k++;
							}
							$_SESSION['privilege_id'] =$array_previ;
							$_SESSION['privilege_id_parent'] =$array_previ_parent;
							
							$select_prev= " select privilege_id from staff_previleges where admin_id='".$_SESSION['admin_id']."' " ;
							$ptr_prev = mysql_query($select_prev);
							$n=0;
							while($data_staff_prev1=mysql_fetch_array($ptr_prev))
							{
								$staff_previ[$n]= $data_staff_prev1['privilege_id'];
								$n++;
							}
							$_SESSION['staff_prev']=$staff_previ;
						}
						elseif($row_site_setting['type']=='C')
						{
							$select_prev_admin= " select DISTINCT(previlege_parent_id) from admin_previleges where admin_id='".$_SESSION['admin_id']."'" ;
							$ptr_previlege = mysql_query($select_prev_admin);
							$array_previ =array();
							$array_previ_parent =array();
							$k=0;
							while($data_prevo = mysql_fetch_array($ptr_previlege))
							{
								
								$select_prev= "SELECT u.privilege_id,u.previlege_parent_id,u.admin_id,o.privilege_parent_id ,o.privilege_id,o.seq_no FROM admin_previleges u, previleges o where 1 AND admin_id='".$_SESSION['admin_id']."' AND u.previlege_parent_id='".$data_prevo['previlege_parent_id']."' AND o.privilege_id =u.privilege_id AND o.privilege_parent_id =u.previlege_parent_id ORDER BY o.seq_no ASC"; 
								$ptr_prev = mysql_query($select_prev);
								$s=0;
								while($data_prev1=mysql_fetch_array($ptr_prev))
								{
									$array_previ[$k][$s]['privilege_id']= $data_prev1['privilege_id'];
									$s++;
								}
								
								$array_previ_parent[$k]['privilege_id']= $data_prevo['previlege_parent_id'];
								
								$k++;
							}
							
							$_SESSION['privilege_id'] =$array_previ;
							$_SESSION['privilege_id_parent'] =$array_previ_parent;
							
							$select_prev= " select privilege_id from staff_previleges where admin_id='".$_SESSION['admin_id']."' " ;
							$ptr_prev = mysql_query($select_prev);
							$n=0;
							while($data_staff_prev1=mysql_fetch_array($ptr_prev))
							{
								$staff_previ[$n]= $data_staff_prev1['privilege_id'];
								$n++;
							}
							$_SESSION['staff_prev']=$staff_previ;
						}
						elseif($row_site_setting['type']=='F')
						{
							$select_prev_admin= " select DISTINCT(previlege_parent_id) from admin_previleges where admin_id='".$_SESSION['admin_id']."'" ;
							$ptr_previlege = mysql_query($select_prev_admin);
							$array_previ =array();
							$array_previ_parent =array();
							$staff_previ=array();
							$k=0;
							while($data_prevo = mysql_fetch_array($ptr_previlege))
							{
								
								$select_prev= "SELECT u.privilege_id,u.previlege_parent_id,u.admin_id,o.privilege_parent_id ,o.privilege_id,o.seq_no FROM admin_previleges u, previleges o where 1 AND admin_id='".$_SESSION['admin_id']."' AND u.previlege_parent_id='".$data_prevo['previlege_parent_id']."' AND o.privilege_id =u.privilege_id AND o.privilege_parent_id =u.previlege_parent_id ORDER BY o.seq_no ASC"; 
								$ptr_prev = mysql_query($select_prev);
								$s=0;
								while($data_prev1=mysql_fetch_array($ptr_prev))
								{
									$array_previ[$k][$s]['privilege_id']= $data_prev1['privilege_id'];
									$s++;
								}
								
								$array_previ_parent[$k]['privilege_id']= $data_prevo['previlege_parent_id'];
								$k++;
							}
							$_SESSION['privilege_id'] =$array_previ;
							$_SESSION['privilege_id_parent'] =$array_previ_parent;
							
							
							$select_prev= " select privilege_id from staff_previleges where admin_id='".$_SESSION['admin_id']."' " ;
							$ptr_prev = mysql_query($select_prev);
							$n=0;
							while($data_staff_prev1=mysql_fetch_array($ptr_prev))
							{
								$staff_previ[$n]= $data_staff_prev1['privilege_id'];
								$n++;
							}
							$_SESSION['staff_prev']=$staff_previ;
							
						}
						elseif($row_site_setting['type']=='B')
						{
							 $select_prev_admin= " select DISTINCT(previlege_parent_id) from admin_previleges where admin_id='".$_SESSION['admin_id']."'" ;
							$ptr_previlege = mysql_query($select_prev_admin);
							$array_previ =array();
							$array_previ_parent =array();
							$k=0;
							while($data_prevo = mysql_fetch_array($ptr_previlege))
							{
								$select_prev= "SELECT u.privilege_id,u.previlege_parent_id,u.admin_id,o.privilege_parent_id ,o.privilege_id,o.seq_no FROM admin_previleges u, previleges o where 1 AND admin_id='".$_SESSION['admin_id']."' AND u.previlege_parent_id='".$data_prevo['previlege_parent_id']."' AND o.privilege_id =u.privilege_id AND o.privilege_parent_id =u.previlege_parent_id ORDER BY o.seq_no ASC"; 
								$ptr_prev = mysql_query($select_prev);
								$s=0;
								while($data_prev1=mysql_fetch_array($ptr_prev))
								{
									$array_previ[$k][$s]['privilege_id']= $data_prev1['privilege_id'];
									$s++;
								}
								$array_previ_parent[$k]['privilege_id']= $data_prevo['previlege_parent_id'];
								$k++;
							}
							
							$_SESSION['privilege_id'] =$array_previ;
							$_SESSION['privilege_id_parent'] =$array_previ_parent;
							
							 $select_prev= " select privilege_id from staff_previleges where admin_id='".$_SESSION['admin_id']."' " ;
							$ptr_prev = mysql_query($select_prev);
							$n=0;
							while($data_staff_prev1=mysql_fetch_array($ptr_prev))
							{
								$staff_previ[$n]= $data_staff_prev1['privilege_id'];
								$n++;
							}
							$_SESSION['staff_prev']=$staff_previ;
						}
						elseif($row_site_setting['type']=='ST')
						{
							$select_prev_admin= " select DISTINCT(previlege_parent_id) from admin_previleges where admin_id='".$_SESSION['admin_id']."'" ;
							$ptr_previlege = mysql_query($select_prev_admin);
							$array_previ =array();
							$array_previ_parent =array();
							$staff_previ=array();
							$k=0;
							while($data_prevo = mysql_fetch_array($ptr_previlege))
							{
								
								$select_prev= "SELECT u.privilege_id,u.previlege_parent_id,u.admin_id,o.privilege_parent_id ,o.privilege_id,o.seq_no FROM admin_previleges u, previleges o where 1 AND admin_id='".$_SESSION['admin_id']."' AND u.previlege_parent_id='".$data_prevo['previlege_parent_id']."' AND o.privilege_id =u.privilege_id AND o.privilege_parent_id =u.previlege_parent_id ORDER BY o.seq_no ASC"; 
								$ptr_prev = mysql_query($select_prev);
								$s=0;
								while($data_prev1=mysql_fetch_array($ptr_prev))
								{
									$array_previ[$k][$s]['privilege_id']= $data_prev1['privilege_id'];
									$s++;
								}
								
								$array_previ_parent[$k]['privilege_id']= $data_prevo['previlege_parent_id'];
								$k++;
							}
							
							$_SESSION['privilege_id'] =$array_previ;
							$_SESSION['privilege_id_parent'] =$array_previ_parent;
							
							$select_prev= " select privilege_id from staff_previleges where admin_id='".$_SESSION['admin_id']."' " ;
							$ptr_prev = mysql_query($select_prev);
							$n=0;
							while($data_staff_prev1=mysql_fetch_array($ptr_prev))
							{
								$staff_previ[$n]= $data_staff_prev1['privilege_id'];
								$n++;
							}
							$_SESSION['staff_prev']=$staff_previ;
							
						}
						elseif($row_site_setting['type']=='AC')
						{
							$select_prev_admin= " select DISTINCT(previlege_parent_id) from admin_previleges where admin_id='".$_SESSION['admin_id']."'" ;
							$ptr_previlege = mysql_query($select_prev_admin);
							$array_previ =array();
							$array_previ_parent =array();
							$k=0;
							while($data_prevo = mysql_fetch_array($ptr_previlege))
							{
								//"<br/>".$select_prev= " select privilege_id from admin_previleges where admin_id='".$_SESSION['admin_id']."' and  previlege_parent_id='".$data_prevo['previlege_parent_id']."'" ;
								
								 $select_prev= "SELECT u.privilege_id,u.previlege_parent_id,u.admin_id,o.privilege_parent_id ,o.privilege_id,o.seq_no FROM admin_previleges u, previleges o where 1 AND admin_id='".$_SESSION['admin_id']."' AND u.previlege_parent_id='".$data_prevo['previlege_parent_id']."' AND o.privilege_id =u.privilege_id AND o.privilege_parent_id =u.previlege_parent_id ORDER BY o.seq_no ASC"; 
								
								$ptr_prev = mysql_query($select_prev);
								$s=0;
								
								while($data_prev1=mysql_fetch_array($ptr_prev))
								{
									$array_previ[$k][$s]['privilege_id']= $data_prev1['privilege_id'];
									$s++;
								}
								$array_previ_parent[$k]['privilege_id']= $data_prevo['previlege_parent_id'];
								$k++;
							}
							$_SESSION['privilege_id'] =$array_previ;
							$_SESSION['privilege_id_parent'] =$array_previ_parent;
							
							$select_prev= " select privilege_id from staff_previleges where admin_id='".$_SESSION['admin_id']."' " ;
							$ptr_prev = mysql_query($select_prev);
							$n=0;
							while($data_staff_prev1=mysql_fetch_array($ptr_prev))
							{
								$staff_previ[$n]= $data_staff_prev1['privilege_id'];
								$n++;
							}
							$_SESSION['staff_prev']=$staff_previ;
						}
						elseif($row_site_setting['type']=='Q')
						{
							$select_prev_admin= " select DISTINCT(previlege_parent_id) from admin_previleges where admin_id='".$_SESSION['admin_id']."'" ;
							$ptr_previlege = mysql_query($select_prev_admin);
							$array_previ =array();
							$array_previ_parent =array();
							$staff_previ=array();
							$k=0;
							while($data_prevo = mysql_fetch_array($ptr_previlege))
							{
								$select_prev= "SELECT u.privilege_id,u.previlege_parent_id,u.admin_id,o.privilege_parent_id ,o.privilege_id,o.seq_no FROM admin_previleges u, previleges o where 1 AND admin_id='".$_SESSION['admin_id']."' AND u.previlege_parent_id='".$data_prevo['previlege_parent_id']."' AND o.privilege_id =u.privilege_id AND o.privilege_parent_id =u.previlege_parent_id ORDER BY o.seq_no ASC"; 
								$ptr_prev = mysql_query($select_prev);
								$s=0;
								while($data_prev1=mysql_fetch_array($ptr_prev))
								{
									$array_previ[$k][$s]['privilege_id']= $data_prev1['privilege_id'];
									$s++;
								}
								$array_previ_parent[$k]['privilege_id']= $data_prevo['previlege_parent_id'];
								$k++;
							}
							
								$_SESSION['privilege_id'] =$array_previ;
							$_SESSION['privilege_id_parent'] =$array_previ_parent;
							
							
							$select_prev= " select privilege_id from staff_previleges where admin_id='".$_SESSION['admin_id']."' " ;
							$ptr_prev = mysql_query($select_prev);
							$n=0;
							while($data_staff_prev1=mysql_fetch_array($ptr_prev))
							{
								$staff_previ[$n]= $data_staff_prev1['privilege_id'];
								$n++;
							}
							$_SESSION['staff_prev']=$staff_previ;
							
						}
						elseif($row_site_setting['type']=='PK')
						{
							$select_prev_admin= " select DISTINCT(previlege_parent_id) from admin_previleges where admin_id='".$_SESSION['admin_id']."'" ;
							$ptr_previlege = mysql_query($select_prev_admin);
							$array_previ =array();
							$array_previ_parent =array();
							$staff_previ=array();
							$k=0;
							while($data_prevo = mysql_fetch_array($ptr_previlege))
							{
								$select_prev= "SELECT u.privilege_id,u.previlege_parent_id,u.admin_id,o.privilege_parent_id ,o.privilege_id,o.seq_no FROM admin_previleges u, previleges o where 1 AND admin_id='".$_SESSION['admin_id']."' AND u.previlege_parent_id='".$data_prevo['previlege_parent_id']."' AND o.privilege_id =u.privilege_id AND o.privilege_parent_id =u.previlege_parent_id ORDER BY o.seq_no ASC"; 
								$ptr_prev = mysql_query($select_prev);
								$s=0;
								while($data_prev1=mysql_fetch_array($ptr_prev))
								{
									$array_previ[$k][$s]['privilege_id']= $data_prev1['privilege_id'];
									$s++;
								}
								$array_previ_parent[$k]['privilege_id']= $data_prevo['previlege_parent_id'];
								$k++;
							}
							$_SESSION['privilege_id'] =$array_previ;
							$_SESSION['privilege_id_parent'] =$array_previ_parent;
							
							$select_prev= " select privilege_id from staff_previleges where admin_id='".$_SESSION['admin_id']."' " ;
							$ptr_prev = mysql_query($select_prev);
							$n=0;
							while($data_staff_prev1=mysql_fetch_array($ptr_prev))
							{
								$staff_previ[$n]= $data_staff_prev1['privilege_id'];
								$n++;
							}
							$_SESSION['staff_prev']=$staff_previ;
							
						}
						elseif($row_site_setting['type']=='DL')
						{
							$select_prev_admin= " select DISTINCT(previlege_parent_id) from admin_previleges where admin_id='".$_SESSION['admin_id']."'" ;
							$ptr_previlege = mysql_query($select_prev_admin);
							$array_previ =array();
							$array_previ_parent =array();
							$staff_previ=array();
							$k=0;
							while($data_prevo = mysql_fetch_array($ptr_previlege))
							{
								$select_prev= "SELECT u.privilege_id,u.previlege_parent_id,u.admin_id,o.privilege_parent_id ,o.privilege_id,o.seq_no FROM admin_previleges u, previleges o where 1 AND admin_id='".$_SESSION['admin_id']."' AND u.previlege_parent_id='".$data_prevo['previlege_parent_id']."' AND o.privilege_id =u.privilege_id AND o.privilege_parent_id =u.previlege_parent_id ORDER BY o.seq_no ASC"; 
								$ptr_prev = mysql_query($select_prev);
								$s=0;
								while($data_prev1=mysql_fetch_array($ptr_prev))
								{
									$array_previ[$k][$s]['privilege_id']= $data_prev1['privilege_id'];
									$s++;
								}
								$array_previ_parent[$k]['privilege_id']= $data_prevo['previlege_parent_id'];
								$k++;
							}
							
							$_SESSION['privilege_id'] =$array_previ;
							$_SESSION['privilege_id_parent'] =$array_previ_parent;
							
							$select_prev= " select privilege_id from staff_previleges where admin_id='".$_SESSION['admin_id']."' " ;
							$ptr_prev = mysql_query($select_prev);
							$n=0;
							while($data_staff_prev1=mysql_fetch_array($ptr_prev))
							{
								$staff_previ[$n]= $data_staff_prev1['privilege_id'];
								$n++;
							}
							$_SESSION['staff_prev']=$staff_previ;
							
						}
						?>
						<script language="javascript">window.location='index.php';</script><?
					/*}
					else
					{
						$msg= "Your login session is active from another machine. wait for expired it or logout from another machine first";	
					}*/
				/*}
				else
				{
					$msg="Please Contact your administrator to setup in your machine";
				}*/
			/*}
			else
			{
				$msg="Please Enter Valid Security Code";
			}*/
		}
		else
		{
			?>
			<div class="callout callout-danger">
        	<h4>Warning!</h4>
        	<p>Please Enter Valid Username and Password</p>
        	</div>
			<?php
			///$msg= "Please Enter Valid Username Or Password";	
		}
	  // $msg='Enter username and password';
	}
	 else 
	{
		?>
        <div class="callout callout-danger">
        <h4>Warning!</h4>
        <p>Please Enter Username and Password</p>
        </div>
        <?php
		//$msg= "Please Enter Username Or Password Or Security Code";
	}	
}
?>
<body class="hold-transition login-page" style="background-image:url(images/bg-1.jpg); background-repeat:no-repeat;background-size: auto;">
<div class="login-box" style=" margin-top:7%;">
  <div class="login-logo">
    <a href="index.php" style="color:#FFF"><b>ISAS Beauty School</b></a>
  </div>
  <!-- /.login-logo -->
  <div class="login-box-body" style=" background-color:transparent;">
    <p class="login-box-msg" style="color:#FFF">Sign in to start your session</p> 

    <form method="post" name="sign_in">
      <div class="form-group has-feedback">
        <input type="text" name="username" id="username" class="form-control" placeholder="Username">
        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input type="password" name="pass" id="password" class="form-control" placeholder="Password">
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
      </div>
      <div class="row">
        <div class="col-xs-8">
          <div class="checkbox icheck">
            <label>
              <input type="checkbox"><span style="color:#FFF !important">Remember Me </span>
            </label>
          </div>
        </div>
        <!-- /.col -->
        <div class="col-xs-4">
          <button type="submit"  name="submit" id="submit" class="btn btn-primary btn-block btn-flat" >Sign In</button>
        </div>
        <!-- /.col -->
      </div>
    </form>

    <!--<div class="social-auth-links text-center">
      <p>- OR -</p>
      <a href="#" class="btn btn-block btn-social btn-facebook btn-flat"><i class="fa fa-facebook"></i> Sign in using
        Facebook</a>
      <a href="#" class="btn btn-block btn-social btn-google btn-flat"><i class="fa fa-google-plus"></i> Sign in using
        Google+</a>
    </div>-->
    <!-- /.social-auth-links -->

    <a href="#">I forgot my password</a><br>
    <a href="register.html" class="text-center">Register a new membership</a>

  </div>
  <!-- /.login-box-body -->
</div>
<!-- /.login-box -->

<!-- jQuery 3 -->
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- iCheck -->
<script src="plugins/iCheck/icheck.min.js"></script>
<script>
  $(function () {
    $('input').iCheck({
      checkboxClass: 'icheckbox_square-blue',
      radioClass: 'iradio_square-blue',
      increaseArea: '20%' /* optional */
    });
  });
</script>
</body>
</html>