<?php

// define('LBROOT',getcwd()); // LegoBox Root ... the server root
// include("core/controller/Database.php");

if(!isset($_SESSION["client_id"])) {
$user = $_POST['username'];
$pass = sha1(md5($_POST['password']));

$base = new Database();
$con = $base->connect();
$sql = "select * from person where (email1= \"".$user."\") and password= \"".$pass."\" and is_active_access=1";
//print $sql;
$query = $con->query($sql);
$found = false;
$userid = null;
$kind = null;
while($r = $query->fetch_array()){
	$found = true ;
	$userid = $r['id'];
	$kind = $r['kind'];
}

$home = "";
$access = "";

if($kind==1){ $home= "waiterhome"; $access="waiteraccess"; }

if($found==true) {
	$_SESSION['client_id']=$userid ;
	print "Cargando ... $user";
	print "<script>window.location='index.php?view=$home';</script>";
}else {
	print "<script>window.location='index.php?view=$access';</script>";
}

}else{
	print "<script>window.location='./';</script>";
	
}
?>