Old stuff/old_sites/www/include/sondages.php
(Deskargatu)
<div class="full">
<h3>Le sondage du moment</h3>
<?
if (empty($axx)) { echo "<p>Vous devez être identifiés pour accéder aux sondages</p>"; }
else
{
$ip = $REMOTE_ADDR;
$var = ip_read("sondages");
if (empty($_POST['vote']) and empty($var[$ip]))
{
$query = "SELECT * FROM mp_sondages ORDER BY id DESC LIMIT 1";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
echo "<form action=\"index.php?page=sondages&id=".$row{'id'}."\" method=\"post\">
";
echo "<dl>
<dt>Question</dt><dd>".$row{'question'}."</dd>
<dt>Réponses</dt><dd><select name=\"vote\">";
foreach(array("a","b","c","d","e","f") as $key)
{ if (!empty($row{$key})) { echo "<option value=\"".$key."\">".$row{$key}."</option>\n"; } }
echo "</select></dd>
<dt>Validation</dt><dd><input type=\"submit\" value=\"Ok\" /></dd>
</dl>
</form>";
}
elseif(empty($var["$ip"]))
{
$vote = preg_replace("[^abcdef]","",$_POST['vote']);
$id = preg_replace("/\D/","",$_GET['id']);
$query = "UPDATE mp_sondages_rep set $vote = $vote+1";
mysql_query($query) or die(mysql_error());
$var["$ip"]["pseudo"]= $nick;
ip_write("sondages",$var);
echo "<p>Votre vote a bien été pris en compte !</p>";
}
else
{
echo "<p>Vous avez déjà voté</p>";
}
?>
<h3>Les résultats</h3>
<?
$query = "SELECT * FROM mp_sondages ORDER BY id DESC LIMIT 1";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$query = "SELECT * FROM mp_sondages_rep WHERE ref='".$row{'id'}."'";
$result = mysql_query($query) or die(mysql_error());
$rep = mysql_fetch_assoc($result);
echo "<dl>
<dt>Question</dt><dd>".$row{'question'}."</dd>
</dl>
<ul>";
foreach(array("a","b","c","d","e","f") as $key)
{
if (!empty($row{$key}))
{
echo "<li>".$row{$key}." : ".$rep{$key}." vote(s)</li>\n";
}
}
echo "</ul>";
}
?>
</div>