<?php
	
	require ("_common/global.php");
	require ("_common/conn.php");
	

	
   session_start();
   
   if( isset( $_SESSION['email'] ) ) {
      $_SESSION['email'] += 1;
	  $_SESSION['role'] += 1;
   }else {
      $_SESSION['email'] = 1;
	  $_SESSION['role'] += 1;
   }
	
$email=$_POST['email']; 
$pass=$_POST['pass'];

//$link = mysqli_connect("localhost", "root", "", "rmc_02");
//$userLastLoginDate = mysqli_real_escape_string($link, $_POST['userLastLoginDate']);

$sql="SELECT * FROM user WHERE email='$email' and pass='$pass'";
$result=mysql_query($sql);
$num_results = mysql_num_rows($result); 
//$sql2="INSERT INTO user (userLastLoginDate) VALUES('$userLastLoginDate') WHERE userName='$userName";
if ($num_results == 1) 
{  // ID and password correct
    $data = mysql_fetch_array($result);
	$_SESSION['email'] = $data["email"];
	$_SESSION['pass'] = $data["pass"];
	$_SESSION['role'] = $data["role"];
	
}



// Mysql_num_row is counting table row
/* $count=mysql_num_rows($result); */

// If result matched $myusername and $mypassword, table row must be 1 row
/* if($count==1) */

	/* $_SESSION['userName'] = $data["userName"];
	$_SESSION['userPass'] = $data["userPass"];} */
// Register $myusername, $mypassword and redirect to file "login_success.php"
// session_register("myusername");
// session_register("userPass"); 
	if ($data['status']== Active and $data['role']== Administrator) {  //Admin	
			$link = mysqli_connect("localhost", "dvsvigov_vacc", "DVSvacdos123", "dvsvigov_vacdos");
			if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error());}
			
			else{
			echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);} mysqli_close($link);
		header("Location:dashboard.php");
	} 
	else if ($data['status']== Active and $data['role']== Evaluator) {  //Admin	
			$link = mysqli_connect("localhost", "dvsvigov_vacc", "DVSvacdos123", "dvsvigov_vacdos");
			if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error());}
			
			else{
			echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);} mysqli_close($link);
		header("Location:ev/dashboard.php");
	}


  else {	
	session_destroy();
	header("Location: notregister.php");
  }
// redirect page after login
// header("location:1admin/index.php");

/* else {
echo "Wrong Username or Password"; 
} */



?>