<?php
// GET WS INFOS
$MATRICULE = "";
$APPID = "";
if (isset($_POST["matricule"])) $MATRICULE = $_POST["matricule"];
if (isset($_POST["app_id"])) $APPID = $_POST["app_id"];
$identifiants = $MATRICULE.'**'.$APPID;
$xml = "";
$xml = file_get_contents("http://ifp10-iucrprdapa.ca-technologies.fr:81/CRIF/auth_service/public/ws/getprofiluser?application_id=".$APPID."&matricule=".$MATRICULE);

// INITIALIZE XML STIRAGE VARIABLE
/*
switch($identifiants){
	case "M033562**BORNE_AA":
		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
		<response application=\"BORNE_AA\" matricule=\"M033562\">
			<status>1</status>
			<profil>
				<id_profil>ADMIN</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Administrateur</libelle>
				<description>ADMIN</description>
			</profil>
			<profil>
				<id_profil>SIEGE</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Siège</libelle>
				<description>SIEGE</description>
			</profil>
		</response>";
		break;
	
	case "M003725**BORNE_AA":
		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
		<response application=\"BORNE_AA\" matricule=\"M003725\">
			<status>1</status>
			<profil>
				<id_profil>DR</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Directeur régional</libelle>
				<description>DR</description>
			</profil>
			<profil>
				<id_profil>PRO</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Pôle professionnels</libelle>
				<description>PRO</description>
			</profil>
			<profil>
				<id_profil>RESEAU</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Réseau</libelle>
				<description>RESEAU</description>
			</profil>
		</response>";
		break;
	
	case "M003860**BORNE_AA":
		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
		<response application=\"BORNE_AA\" matricule=\"M003860\">
			<status>1</status>
			<profil>
				<id_profil>DS</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Directeur de secteur</libelle>
				<description>DS</description>
			</profil>
			<profil>
				<id_profil>RESEAU</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Réseau</libelle>
				<description>RESEAU</description>
			</profil>
		</response>";
		break;
	
	case "M003346**BORNE_AA":
		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
		<response application=\"BORNE_AA\" matricule=\"M003346\">
			<status>1</status>
			<profil>
				<id_profil>DA</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Directeur d'agence</libelle>
				<description>DA</description>
			</profil>
			<profil>
				<id_profil>RESEAU</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Réseau</libelle>
				<description>RESEAU</description>
			</profil>
		</response>";
		break;
	
	case "M008593**BORNE_AA":
		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
		<response application=\"BORNE_AA\" matricule=\"M008593\">
			<status>1</status>
			<profil>
				<id_profil>DAM</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Directeur d'agence mobile</libelle>
				<description>DAM</description>
			</profil>
			<profil>
				<id_profil>SIEGE</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Siège</libelle>
				<description>SIEGE</description>
			</profil>
		</response>";
		break;
	
	case "M034225**BORNE_AA":
		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
		<response application=\"BORNE_AA\" matricule=\"M034225\">
			<status>1</status>
			<profil>
				<id_profil>SIEGE</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Siège</libelle>
				<description>SIEGE</description>
			</profil>
		</response>";
		break;
	
	case "M030996**BORNE_AA":
		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
		<response application=\"BORNE_AA\" matricule=\"M030996\">
			<status>1</status>
			<profil>
				<id_profil>DAM</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Directeur d'agence mobile</libelle>
				<description>DAM</description>
			</profil>
			<profil>
				<id_profil>DA</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Directeur d'agence</libelle>
				<description>DA</description>
			</profil>
			<profil>
				<id_profil>RESEAU</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Réseau</libelle>
				<description>RESEAU</description>
			</profil>
			<profil>
				<id_profil>SIEGE</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Siège</libelle>
				<description>SIEGE</description>
			</profil>
		</response>";
		break;
	
	case "M031446**BORNE_AA":
		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
		<response application=\"BORNE_AA\" matricule=\"M031446\">
			<status>1</status>
			<profil>
				<id_profil>PRO</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Pôle porfessionel</libelle>
				<description>PRO</description>
			</profil>
			<profil>
				<id_profil>RESEAU</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Réseau</libelle>
				<description> RESEAU </description>
			</profil>
		</response>";
		break;
	
	case "M022705**BORNE_AA":
		$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
		<response application=\"BORNE_AA\" matricule=\"M022705\">
			<status>1</status>
			<profil>
				<id_profil>RESEAU</id_profil>
				<delegant/>
				<nom_delegant/>
				<parametre/>
				<libelle>Réseau</libelle>
				<description>RESEAU</description>
			</profil>
		</response>";
		break;
}
*/

if($xml!=""){
	// OPEN SESSION
	session_start();
	$_SESSION['auth'] = "ok";
	$_SESSION['matricule'] = $MATRICULE;
	$_SESSION['app_id'] = $APPID;
	// GET USER PROFILES FROM XML DATA
	$profiles = simplexml_load_string($xml);	
	$profiles = json_decode(json_encode((array) simplexml_load_string($xml)), 1);
	$user_profiles = array();
	print_r($profiles); exit;
	foreach($profiles->profil as $key => $value){
		$user_profiles[$key] = $value->id_profil;
	}
	//$_SESSION['profiles'] = (array) $profiles;
	// REDIRECT TO DASHBOARD
	//header("location:dashboard.php");
	echo "<li>Ok";
}
else{	
	// REDIRECT TO LOGIN
	header("location:index.php?e=1");
	echo "<li>Ko";
}

	
?>