<?php
include "../includes/config.php";
include "../includes/database.php";
include "../includes/function.php";
include "../includes/keyword.php";
$addon_path="../";


if ($_SERVER[REQUEST_METHOD] == 'POST') {



     
        
        
                
           $query_check="SELECT * FROM t_".$key_table_prefix."_user ";
           $query_check=$query_check." WHERE usr_name='".$_REQUEST["user_name"]."'  ";	
		 $query_check=$query_check." AND usr_password='".md5($_REQUEST["user_password"])."'  ";	
		
           $result_check = mysqli_query($dbconn,$query_check) or die("Checking failed- Err msg  ". mysqli_error($dbconn));
           if($line_check=mysqli_fetch_array($result_check,MYSQLI_ASSOC))
           {
                    session_start();			
                    $_SESSION[$sys_session_prefix.'_is_logon']="YES";
                    $_SESSION[$sys_session_prefix.'_user_full_name'] = $line_check["usr_name"];
                    $_SESSION[$sys_session_prefix.'_user_group'] = $line_check["usr_group_id"];
                    $_SESSION[$sys_session_prefix.'_user_id'] = $line_check["usr_id"];
                    
				
				
				
				$query_update = " update t_".$key_table_prefix."_user
							set usr_last_login_date = '".date("Y-m-d H:i:s")."' 
				 			where usr_id = '".$line_check["usr_id"]."'  ";
				$result_update = mysqli_query($dbconn,$query_update);
				
				
				
				
				
				
				$query_group = " select * from t_".$key_table_prefix."_user_group
				 			where grp_id = '".$line_check["usr_group_id"]."'  ";
				$result_group = mysqli_query($dbconn,$query_group);
				if($line_group = mysqli_fetch_array($result_group,MYSQLI_ASSOC))
				{
					
					foreach($line_group as $grp_key => $grp_value)
					{
						$_SESSION[$sys_session_prefix.'_acl'][$grp_key] = $grp_value;	
						
					}
					
				}
				
				
				
				
				
                    header("Location: ".$addon_path."");
          
		}
	   	else
	   	{

	               $message="Invalid login information!";
	           
	       
	   	}
  	
}


?>


<html>
<head>
<title><?php echo $sys_browser_title; ?></title>
<LINK REL="SHORTCUT ICON" HREF="../images/pcart_logo.png" >

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">

        
<meta http-equiv=content-type content="text/html; charset=GB2312">
    
<LINK href="<?php print $addon_path."theme/desktop/".$cssPath1; ?>" rel=stylesheet media="(min-width: 641px)">
<LINK href="<?php print $addon_path."theme/desktop/".$cssPath2; ?>" rel=stylesheet media="(min-width: 641px)">
<LINK href="<?php print $addon_path."theme/desktop/".$cssPath3; ?>" rel=stylesheet media="(min-width: 641px)">
<LINK href="<?php print $addon_path."theme/desktop/".$cssPath4; ?>" rel=stylesheet media="(min-width: 641px)">


<LINK href="<?php print $addon_path."theme/mobile/".$cssPath1; ?>" rel=stylesheet media="(max-width: 640px)">
<LINK href="<?php print $addon_path."theme/mobile/".$cssPath2; ?>" rel=stylesheet media="(max-width: 640px)">
<LINK href="<?php print $addon_path."theme/mobile/".$cssPath3; ?>" rel=stylesheet media="(max-width: 640px)">
<LINK href="<?php print $addon_path."theme/mobile/".$cssPath4; ?>" rel=stylesheet media="(max-width: 640px)">


<LINK href="<?php print $addon_path.$fontPath; ?>" rel=stylesheet>
    
    
    
    
    
<script language="javascript" src="<?php print $addon_path.$jsPath1; ?>"></script>
<script language="javascript" src="<?php print $addon_path.$jsPath2; ?>"></script>
<script language="javascript" src="<?php print $addon_path.$jsPath3; ?>"></script>
<script language="javascript" src="<?php print $addon_path.$jsPath4; ?>"></script>
   
</head>



<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 class='login_body' >


<div width=100% height=100% align=center>
	
		<form name="login_form" action="" method="POST">
                    
		<div  class='login_panel' >
                    
                                
						  <img src='../images/pcart_logo.png' width=80  ><br>
                                <font class='login_system_name'><?php echo $sys_system_title; ?></font>
                                <font class='login_title' ><br><span class='fa fa-mobile fa-1x'></span> <?php echo $sys_mobile_version; ?> </font>
                                <br>
                                <br>
                                <br>
                                            
                    
				<font color=FF0000><?php echo $message;?></font>
		
				
				<div class='form_field_row' >
					<div class='form_field_label' >
						<font class='login_label' >Username</font>
					</div>
				
					<div class='form_field_input' >
						<input type=text class='textbox textbox-m' name="user_name" value="<?php echo $_REQUEST["user_name"]?>">	
					</div>
				</div>
					
					
				<div class='form_field_row' >
					<div class='form_field_label' >
						<font class='login_label' >Password</font>
					</div>
				
					<div class='form_field_input' >
						<input type=password class='textbox textbox-m' name="user_password">			
					</div>
				</div>
					
				<div class='form_field_row' >
					<div class='form_field_label' >
						
					</div>
				
					<div class='form_field_input' >
						<input type=submit class='button button-blue' value="Sign In" >
						<input type=reset class='button button-red' value="Cancel" >		
					</div>
				</div>		
				 
				
				
				<?php 
				/*
				<div   style='float:left;text-align:center;padding:2%;width:96%;margin:0px;'>
				
						<br><br>
						<font color=#fff >	<span class='fa fa-download fa-lg '></span> PCart Inventory App Download: <br><a style='color:#888;' href='http://download.pcloud.com.my/files/pcartinventoryv1.0.0.apk' >http://download.pcloud.com.my/files/pcartinventoryv1.0.0.apk </a></font>
						
				</div>		
				*/
				
				 ?>
				
				
				
		</div>
		
		
	</form>
	
	<br>
	

		
</div>
	
