<?php
session_start();
require($_SERVER['DOCUMENT_ROOT'].'/site/config/php/lib.inc.php');
require($_SERVER['DOCUMENT_ROOT'].'/site/config/php/var.inc.php');
require($_SERVER['DOCUMENT_ROOT'].'/espace_personnel/php/lib.php');

//echo "<pre>";print_r($_POST);echo "</pre>";

$login	= addslashes($_POST['login']);
$pass	= addslashes($_POST['pass']);
$_SESSION['entreprise']['id'] = 0;

// Recherche de l'id 
	
	// Connexion par login/mdp

	$sql = dbquery("SELECT * FROM site_entreprises WHERE identifiant = '".$login."' AND password = '".$pass."' ");

	$validation = dbresult_utf8($sql,0,"validation");
	
	if(dbnumrows($sql)>0)	{
		if($validation == "R" || $validation == "O"){
			Header("Location: index.php?connexion=inactive");
			exit();
		}
		else{
			$_SESSION['entreprise']['id'] = dbresult_utf8($sql,0,"id_entreprise");
			$_SESSION['entreprise']['session'] = 1;
		}
	}
	else{
		Header("Location: index.php?connexion=fail");
		exit();
	}

// Récupération données relatives à l'entreprise

	$sql = dbquery("SELECT * FROM site_entreprises WHERE id_entreprise = '".$_SESSION['entreprise']['id']."'");

	$_SESSION['entreprise']['id']				= dbresult_utf8($sql,0,"id_entreprise");
	$_SESSION['entreprise']['nom']				= dbresult_utf8($sql,0,"nom");
	$_SESSION['entreprise']['contact_mail']		= dbresult_utf8($sql,0,"contact_mail");
	$_SESSION["entreprise"]["agent"]			= $_SERVER['HTTP_USER_AGENT'];

	Header("Location: /espace_personnel/entreprises/accueil/index.php");
	exit();

	
	//echo "<pre>";print_r($_SESSION);echo "</pre>";

?>