<?php
session_start();
include './core.php';
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$login = addslashes($_REQUEST['username']);
$password = addslashes($_REQUEST['password']);

//print_r($cfgWeb);

//echo "Password : ".$password ;

$managerDtls = $dba->getManagerDetails($login);

//print_r($managerDtls);

if(strcmp(md5($password), $managerDtls['password_v'])==0){
    $_SESSION['login'] = $login;
    $_SESSION['ownerId'] = $managerDtls['user_id_n'];
    $_SESSION['identity'] = $managerDtls['last_name_v']."  ".$managerDtls['first_name_v'];
    $_SESSION['right'] = $managerDtls['profile_id_n'];
    $_SESSION['sequence'] = 1;
	$_SESSION['leftActiveItem'] = 1;
	$_SESSION['basedir']= __DIR__.DIRECTORY_SEPARATOR ;
	
	if($managerDtls['profile_id_n']=="1") $_SESSION['accntType']="Administrateur";
	else $_SESSION['accntType']="Utilisateur";
	
    $_SESSION['firstName'] = $managerDtls['first_name_v'];
	$_SESSION['lastName'] = $managerDtls['last_name_v'];
	$_SESSION['phone'] = $managerDtls['mobile_phone_v'];
	$_SESSION['email'] = $managerDtls['email_v']; 
	$_SESSION['pid'] = $managerDtls['password_v'];
	$_SESSION['cfg'] = $cfg;
	
	//$managerDtls = $dba->addPresence($_SESSION['ownerId']);
	
     // header("Location:main.php",false); 
        
        //################ Inserting logging Information #############
        // Method = 0 -- Login/Loggout     , Event =0 -- Login /1 Loggout
        // Method = 1 -- Pause/Unpaus     , Event =0 -- Pause /1 Unpause
        
         $dba->UploadEventInformation($managerDtls['user_id_n'], 0, 0);
        
        //############################################################
	 
	 echo '{"errorCode":0, "errorMessage" : "Success"}';
}
elseif($managerDtls == -1){
	
	echo '{"errorCode":2, "errorMessage" : "<b style=\"color:red\" >Impossible de se connecter à la base de données !</b>"}';
	
}
else {
	
	 echo '{"errorCode":1, "errorMessage" : "<b style=\"color:red\" >Login ou Mot de passe incorrect!</b>"}';
  // $_SESSION['errorMessage']= "Login ou Password Incorrect!";
  // header("Location:index.php?errorMessage=Erreur de connexion");
}






?>
