<?php
	//print("<pre>" . print_r($_POST, true) . "</pre>");

	/*
	$response = $_POST["g-recaptcha-response"];
	$url = 'https://www.google.com/recaptcha/api/siteverify';
	$data = array(
		'secret' => '6Leb9ToUAAAAABwQMG2g5cSI7JN-0E6w5A9WFPZi',
		'response' => $_POST["g-recaptcha-response"]
	);
	$options = array(
		'http' => array (
			'method' => 'POST',
			'content' => http_build_query($data)
		)
	);
	$context  = stream_context_create($options);
	$verify = file_get_contents($url, false, $context);
	$captcha_success = json_decode($verify);

	if ($captcha_success->success == false)
	{
		echo "<p>You are a bot! Go away!</p>";
	}
	else if ($captcha_success->success==true)
	{
		echo "<p>You are not not a bot!</p>";*/
		include 'connexion.php';

		$niveauForm = '';

		if (isset($_POST['niveauForm']))
			$niveauForm = $_POST['niveauForm'];
		else
			$niveauForm = $_POST['niveau'];

		$requeteInsert = "INSERT INTO isoactif_t_usager_ecole (
		u_login,
		u_pwd,
		u_prenom,
		u_nom,
		u_fct,
		u_courriel,
		u_tel_travail,
		u_tel_residence,
		u_tel_cell,
		u_e_id_fk,
		u_e_nb_etud_g,
		u_e_nb_etud_f,
		u_g_prisec
		)
		VALUES (
		\"" . escapeValue($_POST['login']) . "\",
		\"" . escapeValue($_POST['password']) . "\",
		\"" . escapeValue($_POST['prenom']) . "\",
		\"" . escapeValue($_POST['nom']) . "\",
		\"" . escapeValue($_POST['fonction']) . "\",
		\"" . escapeValue($_POST['courriel']) . "\",
		\"" . escapeValue($_POST['telBur']) . "\",
		\"" . escapeValue($_POST['telRes']) . "\",
		\"" . escapeValue($_POST['telCell']) . "\",
		\"" . escapeValue($_POST['idEcole']) . "\",
		\"" . escapeValue($_POST['nbEtudiantsGarcons']) . "\",
		\"" . escapeValue($_POST['nbEtudiantsFilles']) . "\",
		\"" . escapeValue($niveauForm) . "\"
		)";

		if(!$resultatInsert = $connexion->query($requeteInsert)) { die('There was an error running the query : Insert new account'); }


		// UPDATE BOTTIN SCOLAIRE
		$nom_bottin_scolaire = $_POST['prenom'] . ' ' . $_POST['nom'];
		$requeteUpdateBottin = "UPDATE t_liste_ecoles_08 SET
		NOM_ISO = \"" . escapeValue($nom_bottin_scolaire) . "\",
		FCT_ISO = \"" . escapeValue($_POST['fonction']) . "\",
		TELBUR_ISO = \"" . escapeValue($_POST['telBur']) . "\",
		TELRES_ISO = \"" . escapeValue($_POST['telRes']) . "\",
		TELCELL_ISO = \"" . escapeValue($_POST['telCell']) . "\",
		EMAIL_ISO = \"" . escapeValue($_POST['courriel']) . "\",
		PRISEC = \"" . escapeValue($_POST['niveau']) . "\",
		NBETUD = \"" . escapeValue($_POST['nbEtudiants']) . "\"
		WHERE ID = \"" . escapeValue($_POST['idEcole']) . "\"";

		if(!$resultatUpdateBottin = $connexion->query($requeteUpdateBottin)){}


		$connexion->close();
		//die;
		//exit;
		header ("Location: ../index.php?accountCreated");
	//}
?>
