<?php
	session_start();
	
	include('config_inc.php'); 
	
	if($_SESSION['database']=="local")
	  {
	     $db_host    = "localhost";
	     $db_user   = "root";
	     $db_pass   = "";
     	     $db_name   = "gestion_projet";

	 }
	
	if($_SESSION['database']=="public")
	  {
  	     $db_host    = "sql2";
   	     $db_user   = "analogde";
 	     $db_pass   = "rainbow";
    	     //$db_type   = "mysql";
	     $db_name   = "analogde";
	 }


			  if(isset($_POST) && isset($_POST['identifiant']) && isset($_POST['password']) )
			    {                                                                       
       				if( !empty($_POST['identifiant']) && !empty($_POST['password']) )
         			  {
				       extract($_POST);
					$connexion = mysql_connect($db_host,$db_user,$db_pass); 			
			    	       if(!$connexion)
        	  			 { die('Could not connect: ' . mysql_error());
			            	 }
  
			        	mysql_select_db($db_name, $connexion);
					$sql = "select * from administration where identifiant='".$identifiant."'";
					$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
			                $data = mysql_fetch_assoc($req);


					if($data['identifiant'] != $identifiant) 
					  {
					    echo '<p>Mauvais identifiant. Merci de recommencer</p>';
					    exit;
					  }

					if($data['password'] != $password) 
					  {
					    echo '<p>Mauvais password. Merci de recommencer</p>';
					    exit;
					  }
					  
					  
        			  
        			  	if($data['password'] == $password && $identifiant == "admin") 
                                          {
						$_SESSION['admin_identifiant'] = $data["identifiant"];
    						$_SESSION['connexion'] = "ON";
    						$_SESSION['ROOT'] = "logged";
    						
    						
    						//$_SESSION['password'] = $data["password"];
    						//$_SESSION['prenom'] = $data["prenom"];
						//$_SESSION['id'] = $data["id"];
						//$_SESSION['utilisateur_login']= "valide";
       			                        header('Location: administration.php');
       			                        //header('Location: root.php');
      			                          
			                 }
        			  
        			  
        		   
        		                if($data['password'] == $password && $identifiant != "admin") 
                                          {
						$_SESSION['admin_identifiant'] = $data["identifiant"];
    						$_SESSION['connexion'] = "ON";
    						
    						
    						
    						//$_SESSION['password'] = $data["password"];
    						//$_SESSION['prenom'] = $data["prenom"];
						//$_SESSION['id'] = $data["id"];
						//$_SESSION['utilisateur_login']= "valide";
       			                        header('Location: administration.php');
      			                          
			                 }
			        }
    			
  		             
   			   else {  echo 'Il manque quelque chose ?.'; 
   			        }                                                 
                                                                           
                        }               

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr" lang="fr">

<head>
<title> Gestion de projet - Identification</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <link href="default.css" rel="stylesheet" type="text/css" />
</head>
<body>

	<div id="header"><h1>Gestion de projet</h1></div>

	<table cellspacing="5" cellpadding="6" id="login">
  	<tr>
    	<td colspan="2" style="font-size: 14px;">
    	</td>
  	</tr>

  	<tr>
    	<td>
    	<img src="images/login.png" />
    	</td>
    	<td id="login_form">
      	<form action="login.php" method="POST">
        <table cellpadding="1">
        <tr><td>Identifiant</td></tr>
        <tr><td><input type="text" name="identifiant" /></td></tr>
        <tr><td>Mot de passe</td></tr>
        <tr><td><input type="password" name="password" /></td></tr>
        <tr><td><input type="submit" value="Login" id="login_button" /></td></tr>
        </table>

        </form>
        </td>
        </tr>
	</table>

</body>
</html>
