<?php
require('connect.php');
//define(DOC_ROOT,dirname(__FILE__)); // To properly get the config.php file
$username = $_POST['username']; //Set UserName
$password = $_POST['password']; //Set Password
$msg ='';
$super = '';
//session_start();



if(isset($username, $password)) {
    ob_start();
    // include('includes/config.php');

    $myusername = stripslashes($username);
    $mypassword = stripslashes($password);
    $myusername = mysqli_real_escape_string($dbC, $myusername);
	$mypassword = mysqli_real_escape_string($dbC, $mypassword);



	  $sql="SELECT * FROM vapos_users WHERE ALogin='".$myusername."' and APasswd='".$mypassword."' ";
    $result=mysqli_query($dbC, $sql);
    // Mysql_num_row is counting table row
    $count=mysqli_num_rows($result);
    // If result matched $myusername and $mypassword, table row must be 1 row
    if($count==1){
        $row = mysqli_fetch_array($result);
        global $username;		
      
		$_SESSION['sid2'] = $row['CUSCODE'];
		
		$sid = $row['CUSCODE'];
	
		    $msg = "Username ". $myusername . " Connected!";
		if(trim($_SESSION['susername'],' \/.,')=='sel' && $_SESSION['susername']!=''){
		    header("location:control.php?type=viewall");
		} else {
		    header('location:medscan2/index.php?'.$sid );
		}
        
    }
    else {
        session_destroy();
        $msg = "Wrong Username or Password. Please retry" . $myusername . "--" . $count;
        header("location:index.php?invalid_login=1");
    }
    ob_end_flush();
}
else {
	session_destroy();
    header("location:index.php");
}
// store session data
global $username;
global $sid;







?>
