1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
   | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>star</title>
		<link rel="stylesheet" type="text/css" href="voteCSS.css" />
		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
	</head>
	<body>
		<div id="vote">
			<?php $id=1; ?>
			<div id="texteVote">
				Donnez votre avis !
			</div>
			<div class="icone-vote">
				<button type="button" onclick="traitementVote(1, <?php echo $id; ?>)">1</button>
				<button type="button" onclick="traitementVote(2, <?php echo $id; ?>)">2</button>
				<button type="button" onclick="traitementVote(3, <?php echo $id; ?>)">3</button>
				<button type="button" onclick="traitementVote(4, <?php echo $id; ?>)">4</button>
				<button type="button" onclick="traitementVote(5, <?php echo $id; ?>)">5</button>
			</div>
			<?php 
			/***************************************/
			/**** Connection au serveur et base ****/
			/***************************************/
			$serveur = mysql_connect("localhost","root","");												   
			if (!$serveur)
			{
				die('Non connecte : ' . mysql_error());
			} 
 
			$db_basevote = mysql_select_db('basevote', $serveur);												   
			if (!$db_basevote)
			{
				die ('Impossible d\'utiliser la base : ' . mysql_error());
			}                          
			/***************************************/
			/***************************************/
 
			/**************************************/
			/* Recup ip utilisateur et ip sotckee */
			/**************************************/
 
			$ip = $_SERVER['REMOTE_ADDR'];
 
			$sql = "SELECT ip FROM basevote WHERE id = '$id' AND vote = 1";                                                 
			$envoi = @mysql_query($sql);																         
			$line = @mysql_fetch_row($envoi);
			$ipCompare = $line[0];
 
 
			$testVote = 0;
			if ($ip == $ipCompare) {
				$testVote = 1;
			}
 
			/***************************************/
			/***************************************/
 
			/*******************************************/
			/** Recup des votes dans la BDD et calculs */
			/*******************************************/
 
			$sql = "SELECT nombreVotes FROM basevote WHERE id='$id'";                                          
			$envoi = mysql_query($sql);
			$nbrVoteX = array();
			$i = 0;
			while ($lines = mysql_fetch_object($envoi)) {
				$nbrVoteX[$i] = $lines->nombreVotes;
				$i++;
			}
			$nbrVote1 = $nbrVoteX[0];
			$nbrVote2 = $nbrVoteX[1];
			$nbrVote3 = $nbrVoteX[2];
			$nbrVote4 = $nbrVoteX[3];
			$nbrVote5 = $nbrVoteX[4];
 
			$totalVote = $nbrVote1 + $nbrVote2 + $nbrVote3 + $nbrVote4 + $nbrVote5; 						
			$valeurVote = $nbrVote1 + $nbrVote2*2 + $nbrVote3*3 + $nbrVote4*4 + $nbrVote5*5;                              
			$moyenneVoteBrut = $valeurVote/$totalVote;
			$moyenneVote = number_format($moyenneVoteBrut,2); 
 
			/***************************************/
			/***************************************/
 
			/*******************************************/
			/** Affichage des donnees */
			/*******************************************/
 
			$info = "rating : $moyenneVote /5 ($totalVote votes cast)" ;									
			$vote = "Vous avez voté !";
			if ( $testVote == 1) {
				echo $info;
				?> <br /> <?php
                                echo $vote;
                        }
                        else {
                                echo $info;
                        }
                ?>
		</div>
		<script>
			function traitementVote(choixVote, idSite) {
				var xhr = new XMLHttpRequest();
 
				data="vote="+choixVote+"&id="+idSite;
				xhr.open('POST',votePhP.php);
				xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");     
				xhr.send(data); 
			}				
		</script>
	</body>
</html> | 
Partager