﻿
<html>
<head>
<title>Tk - vote ok</title>
<link rel="stylesheet" media="screen" type="text/css" title="Mon design" href="design.css" />
</head>
<body>

<! -- <a href="createur.php"> créer un sondage</a>
<br/>
<a href="liste_sondages.php"> liste des sondages</a><br/>
<fieldset>
<h1>----------bravooo tu as voté!---------- </h1>

<?php
include('securisation.php');
//print_r($_POST);
// ENREGISTREMENT -------------------------------
// $donnees[0] = id
// $donnees[1] = date
// $donnees[2] = id_sondage
// $donnees[3] = titre_sondage
// $donnees[4] = sous_titre_sondage
// $donnees[5] = ordre_questions
// $donnees[6] = nature_q
// $donnees[7] = texte_q
// $donnees[8] = contenu_q
// $donnees[9] = pour_le_sondage_numero
// $donnees[10] = num_q
// $donnees[11] = reponse
// $donnees[12] = adress-ip
// $donnees[13] = authuserID
$id_sondage =$_POST['id'];
echo" :::: enregistrements :::<br/>";
		//récup du nombre de votes (colonne reponse)
		include('connexion.php');

		$recup=mysql_query("SELECT reponse from tk_sondages WHERE id_sondage=".$_POST['id']."");
		$tadam=mysql_fetch_array($recup)or die( $recup." <br/>". mysql_error()) ;
		$num_vote = $tadam[0]+1;
		if ($tadam[0]==NULL){$tadam[0]=0;}
		echo"<br/><span class=\"notice\">Il y a  $tadam[0] votes avant d'ajouter celui-ci. qui sera le $num_vote </span> <br/>";
		//ajout de 1 vote
		$ajout ="UPDATE `tykayn`.`tk_sondages` SET `reponse` = '".$num_vote."' WHERE id_sondage='".$id_sondage."' AND pour_le_sondage_numero='' LIMIT 1";
		mysql_query($ajout) or die( $ajout." <br/>". mysql_error()) ;;

		$age = $genre = $pseudo="";
	
//recherche du pseudo     print_r($_POST);            //si y'en a pas, $pseudo vaut NULL
foreach ( $_POST AS $k => $v)
		{
		$analyse_reponse = explode("_",$k);
		if (isset($analyse_reponse[2]) AND $analyse_reponse[2] =="pseudo"){$pseudo=$v;}
		if (isset($analyse_reponse[2]) AND $analyse_reponse[2] =="genre"){$genre=$v;}
		if (isset($analyse_reponse[2]) AND $analyse_reponse[2] =="age"){$age=$v;}

		}



$sql ="INSERT INTO tk_sondages VALUES";
		//$analyse_reponse[0]  =  n° du sondage
		//$analyse_reponse[1]  =  n° question
		// $v = réponse
		$ip_adress = $_SERVER['REMOTE_ADDR'];
		foreach ( $_POST AS $k => $v)
		{
		$v = htmlspecialchars($v);
			if ($k != 'id')
			{
				$analyse_reponse = explode("_",$k);
				$sql .='(NULL,NOW(),"","","","","","","","'.$analyse_reponse[0].'","'.$analyse_reponse[1].'","'.$v.'","'.$ip_adress.'","'.$num_vote.'_'.$pseudo.'_'.$genre.'_'.$age.'"),';
			}
			
			//réponse à vote
			if ($k != 'id' AND $k == 'reponse')
			{
				$analyse_reponse = explode("_",$k);
				$sql .='(NULL,NOW(),"","","","","","","","'.$analyse_reponse[0].'","'.$analyse_reponse[1].'","'.$v.'","'.$ip_adress.'","'.$num_vote.'_'.$pseudo.'"),';
			}
			
			
		
		}
			
		//enlever la dernière virgule pour fermer la requete SQL
		$sql=substr($sql,0,-1);
		
//echo" ";

mysql_query($sql) or die( $sql." <br/>". mysql_error()) ;
/////////////////////////////////////////////////////////<span class=\"notice\"> <strong>AJOUT:</strong>		'.$ajout.'<br/></span><br/>		
$id_sondage =$_POST['id'];

		 echo '
		----------	<a href="affichage_resultats_sondage.php?id='.$id_sondage.'">Voir les statistiques des '.$num_vote.' réponses à ce sondage</a>';




mysql_close();
?>
 merci d'avoir voté! \o/
</fieldset>
<a href="liste_sondages.php"> liste des sondages</a><br/>
</body>
</html>