<?php 
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Traitement des réponses
$tab_rep=array(180);
$date = new DateTime(date("Y-m-d"));
$compt = 0;
$nom= $_POST["nom_prenom"];
$societe= $_POST["societe"];
$tp1 = 0;
$tp2 = 0;
$tp3 = 0;
$tp4 = 0;
$tp5 = 0;
$tp6 = 0;
$tp7 = 0;
$tp8 = 0;
$tp9 = 0;

for($i=1;$i<181;$i++){
	$tab_rep[$i-1]=$_POST["A".$i];
	$compt++;

	switch($tab_rep[$i-1]){

		case 1:
				$tp1++;
				break;	
		case 2:
				$tp2++;
				break;
		case 3:
				$tp3++;
				break;
		case 4:
				$tp4++;
				break;
		case 5:
				$tp5++;
				break;
		case 6:
				$tp6++;
				break;
		case 7:
				$tp7++;
				break;
		case 8:
				$tp8++;
				break;
		case 9:
				$tp9++;
				break;
	}
}

$_SESSION["type1"]=$tp1;
$_SESSION["type2"]=$tp2;
$_SESSION["type3"]=$tp3;
$_SESSION["type4"]=$tp4;
$_SESSION["type5"]=$tp5;
$_SESSION["type6"]=$tp6;
$_SESSION["type7"]=$tp7;
$_SESSION["type8"]=$tp8;
$_SESSION["type9"]=$tp9;


	//feuille de style des résultats graphiques
	echo"
	<style type=\"text/css\">
		body {
		 background-color: white; 
		 font-family: Verdana, sans-serif; 
		 font-size: 100%;
		}
		h1 {
		 font-size: 200%; 
		 color: red; 
		 text-align: center;
		 }
		h2 {
		 font-size: 150%; 
		 color: navy; 
		 padding-left: 15px;
		 }
		h3 {
		 font-size: 120%; 
		 color: navy; 
		 padding-left: 15px;
		 }
		p,ul,li,td {
		 font-size: 100%; 
		 color: black;
		}	
		.note {
		color: grey;	
		font-size:80%;
		}
		table {
		 border: medium solid #000000;
		 border-collapse: collapse;
		}
		th {
		 border: thin solid #333333;
		 padding: 5px;
		}
		td {
		 border: thin solid #666666;
		 padding: 10px;
		 text-align: center;
		 background-color: #FFFFFF;
		}
		.titre1 {
		 border: thin solid #666666;
		 padding: 10px;
		 text-align: center;
		 background-color: #999999;
		}
		.titre2 {
		 border: thin solid #666666;
		 padding: 10px;
		 text-align: center;
		 background-color: #CCCCCC;
		}
		
		caption {
		 font-size:150%;
		}
	
	</style>";
	
	echo "<div align='center'>";
	echo "<h1>Voici votre profil NPM&copy</h1>";
	echo "<h2>Merci ".$_POST['nom_prenom']." d'avoir rempli le questionnaire</h2>";
	echo "<table border='1' width='600px'>";
	echo "<caption>Répartitions des items</caption>";
	echo "
		<tr>
			<td class='titre1'> CENTRE </td>
			<td class='titre2' colspan='3'>INSTINCT : ".$instinct."</td>
			<td class='titre2' colspan='3'>EMOTION : ".$emotion."</td>
			<td class='titre2' colspan='3'>MENTAL : ".$mental."</td>
		</tr>
		
		<tr>
			<td class='titre1'> TYPE </td>
			<td>8</td>
			<td>9</td>
			<td>1</td>
			<td>2</td>
			<td>3</td>
			<td>4</td>
			<td>5</td>
			<td>6</td>
			<td>7</td>
		</tr>
		<tr>
			<td class='titre1'> TOTAL </td>
			<td>".$tp8."</td>
			<td>".$tp9."</td>
			<td>".$tp1."</td>
			<td>".$tp2."</td>
			<td>".$tp3."</td>
			<td>".$tp4."</td>
			<td>".$tp5."</td>
			<td>".$tp6."</td>
			<td>".$tp7."</td>
		</tr>

	</table>
	<p> </p>
	<p> </p>";
	
	echo "<p class='note'>
	ATTENTION ! L'auteur ne saurait être tenu pour responsable d'une mauvaise utilisation des résultats obtenus à l'issue du questionnaire qui est <bold>STRICTEMENT CONFIDENTIEL</bold></br>
	Il nécessite d'être interprété par une personne compétente dans ce domaine. Si tel n'est pas votre cas, vous pouvez nous contacter via le formulaire de contact.</br>
	</p>";
	
	$sujet = 'questionnaire NPM rempli par une personne sur le site : A Chacun Son Cerveau';
	$message = 'Bonjour,
        Ceci est un message automatique signalant que le questionnaire du NPM a été rempli par ** '.$nom.' ** de ** '.$societe.' **.
        Voici les scores par bases :
        | 8 = '.$tp8.' | 9 = '.$tp9.' | 1 = '.$tp1.' | 2 = '.$tp2.' | 3 = '.$tp3.' | 4 = '.$tp4.' | 5 = '.$tp5.' | 6 = '.$tp6.' | 7 = '.$tp7.' |.';
	$destinataire = 'contact@achacunsoncerveau.pro';
	$headers = "From: \"A chacun son cerveau - NPM\"<contact@achacunsoncerveau.pro>\n";
	$headers .= "Reply-To: contact@achacunsoncerveau.pro\n";
	$headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"";
	if(mail($destinataire,$sujet,$message,$headers))
	{
	        echo "<p style="font-size: 20px; font-weight: bold; font-color:blue;">Un courriel a été envoyé un expert pour analyser votre profil.</p>";
	}
	else
	{
	        echo "<p style="font-size: 20px; font-weight: bold; font-color:red;">Une erreur c'est produite lors de l'envois de l'email.</p>";
	}

	echo "</div>";

	?>