habe erfolgreich diesen leicht umgearbeiteten (im Orig. werden Mehrfacheinträge durch Cookies vermieden - bekam ich nicht zum Laufen -> flog raus) Vote auf meiner Seite (Cont. 4.6)laufen.
Das ganze läuft im geschützten Frontend, d.h. es können nur User voten, die eingeloggt sind. Nach dem Voten greift auch eine IP-Sperre, mit neuer IP kann aber später wieder gevotet werden. Ich würde es jetzt gerne so haben, dass pro Mitglied halt nur einmal gevotet werden kann.
So wie ich das sehe müssen die if-Bedingungen in Zeile 324 und 121 irgendwie erweitert werden. Leider komm ich hier aber mit meinen derzeitigen Kenntnis nicht weiter. Hätte evtl. an ein zusätzliches Attribut in der Tabelle gedacht, aber das wird ja bei vielen Votes nicht mehr machbar?!
Schon mal besten Dank für Hilfe
P.S.: Vielleicht kann man auch mit der poll_log arbeiten, mmhh, komm da aber auch nicht weiter
Code: Alles auswählen
<?php
/********************************************************
* CONTENIDO MODUL - OUTPUT
*
* Modulname : Umfrage
* Author : Alexander Höhn
* Copyright : art & weise medienproduktion
info@auw-media.de
* Created : 16-09-2002
* Modified : 04-07-2003
* Modified again & again until: Apr. 28th 2004 by Lars D. Forseth <lars@forseth.de>
*********************************************************/
/* set this to "yes" if you want to run script in debugging mode */
$debugging = "no";
/* end "set this to "yes" if you want to run script in debugging mode" */
/* get only vars accepted by POST or GET */
$poll_action = $_POST['poll_action'];
$given_answer = $_POST['given_answer'];
$poll_stats = $_GET['poll_stats'];
if ($debugging == "yes") echo "- poll_action: $poll_action<br>";
if ($debugging == "yes") echo "- given_answer: $given_answer<br>";
if ($debugging == "yes") echo "- poll_stats: $poll_stats<br>";
/* end "get only vars accepted by POST or GET" */
$db1 = new DB_Contenido;
/* lock tables */
$db1->query("LOCK TABLES poll WRITE,poll_log WRITE;");
/* end "lock tables" */
/* get * from active poll */
$db1->query("SELECT * FROM poll WHERE poll_active=1 LIMIT 1;");
$db1->next_record();
$poll_id_active = $db1->f("poll_id");
/* no active poll in DB */
if (!isset($poll_id_active)) {echo "Keine aktive Umfrage in der DB vorhanden!";}
/* end "no active poll in DB" */
/* there is an active poll in DB */
else {
$poll_question_active = $db1->f("poll_question");
$poll_answer1_active = $db1->f("poll_answer1");
$poll_answer2_active = $db1->f("poll_answer2");
$poll_answer3_active = $db1->f("poll_answer3");
$poll_answer4_active = $db1->f("poll_answer4");
$poll_answer5_active = $db1->f("poll_answer5");
$poll_answer6_active = $db1->f("poll_answer6");
if ($debugging == "yes") echo "- poll_id_active: $poll_id_active<br>";
/* end "get od from active poll" */
/* get user's ip and proxy ip */
$user_ip = $_SERVER['REMOTE_ADDR'];
$user_proxy = $_SERVER['HTTP_X_FORWARDED_FOR'];
/* end "get user's ip and proxy ip" */
/* user is only allowed to vote if cookies are enabled and his IP isn't blocked (anymore) */
if ($poll_stats == "yes") {$poll_action = "vote"; $given_answer = 666;}
if ($poll_action == "vote") {
$db0 = new DB_Contenido;
$sql = "SELECT poll_log_id,user_time FROM poll_log WHERE poll_id=$poll_id_active ".
"and user_ip='$user_ip' ORDER BY user_time DESC LIMIT 1;";
$db0->query($sql);
$db0->next_record();
$poll_log_id = $db0->f("poll_log_id");
$user_time = $db0->f("user_time");
if ($debugging == "yes") {
echo "- poll_action: $poll_action<br>";
echo "- poll_id_active: $poll_id_active<br>";
echo "- user_time: $user_time<br>- poll_log_id: $poll_log_id<br>";
} // end if ($debugging == "yes")
if ((isset($user_time)) and (isset($poll_log_id))) {
if ($debugging == "yes") echo "- user_time: $user_time<br>- poll_log_id: $poll_log_id<br>";
$block_seconds = 0;
$block_minutes = 15;
$block_hours = 0;
$block_days = 0;
$block_months = 0;
$block_total = ($block_seconds + ($block_minutes * 60) + ($block_hours * 60 * 60)
+ ($block_days * 60 * 60 * 24) + ($block_months * 60 * 60 * 24 * 30));
// IP is still blocked
if ((time()) < ($user_time + $block_total)) {
$poll_stats = "yes";
$given_answer = 666;
if ($debugging == "yes") echo "- poll_stats: $poll_stats<br>- given_answer: $given_answer<br>";
$db0->query("UPDATE poll_log SET user_time=UNIX_TIMESTAMP() WHERE poll_log_id=$poll_log_id;");
} // end if
} // end if
} // end if
/* end "user is only allowed to vote if cookies are enabled" and his IP isn't blocked (anymore) */
echo "
<!-- umfragenmodul -->
";
/* allowed to vote and no form data given -> show poll form */
if(($poll_action != "vote") and ($poll_stats != "yes")){
$links = explode('?',$auth->url());
$links2 = explode('&',$links[1]);
$link = $links[0].'?'.$links2[0];
if ($debugging == "yes") echo "- link: $link<br>";
echo "
<form action=\"$link\" method=\"post\" name=\"poll_form\">";
echo "
<table width=\"165\" cellspacing=\"0\" cellpadding=\"2\" class=\"poll\">
<tr>
<td colspan=\"2\" align=\"left\" class=\"poll_question\">$poll_question_active<br></td>
</tr>
<tr><td colspan=\"2\"> </td></tr>
<tr class=\"text\">
<td width=\"25\"></td><td><input value=\"1\" type=\"radio\" name=\"given_answer\"> $poll_answer1_active</td>
</tr>
<tr class=\"text\">
<td width=\"25\" ></td><td><input value=\"2\" type=\"radio\" name=\"given_answer\"> $poll_answer2_active</td>
</tr>";
// poll_answer3 to poll_answer6 are optional...
if(strlen($poll_answer3_active) > 1)
echo "
<tr class=\"text\">
<td width=\"25\" ></td><td><input value=\"3\" type=\"radio\" name=\"given_answer\"> $poll_answer3_active</td>
</tr>";
if(strlen($poll_answer4_active) > 1)
echo "
<tr class=\"text\">
<td width=\"25\" ></td><td><input value=\"4\" type=\"radio\" name=\"given_answer\"> $poll_answer4_active</td>
</tr>";
if(strlen($poll_answer5_active) > 1)
echo "
<tr class=\"text\">
<td width=\"25\" ></td><td><input value=\"5\" type=\"radio\" name=\"given_answer\"> $poll_answer5_active</td>
</tr>";
if(strlen($poll_answer6_active) > 1)
echo "
<tr class=\"text\">
<td width=\"25\" ></td><td><input value=\"6\" type=\"radio\" name=\"given_answer\"> $poll_answer6_active</td>
</tr>";
echo "<tr>
<td> </td><td> </td>
</tr class=\"text\">
<tr>
<td colspan =\"2\">
<input type=\"hidden\" name=\"poll_id\" value=\"".$poll_id_active."\">
<input type=\"hidden\" name=\"poll_action\" value=\"vote\">
<center><input type=\"submit\" class=\"poll_button\" value=\"Abstimmen\"><br>
<!-- end of poll_form -->
</form>
<!-- -->
</tr>";
} /* end "allowed to vote and no form data given -> show poll form" */
/* show poll stats and store vote if there was one given */
else {
$db = new DB_Contenido;
// if given_answer is valid, store it in poll_log
if ((ereg("^[1-6]{1}$",$given_answer)) and ($poll_stats != "yes")) {
if ($debugging == "yes") echo "- given_answer: $given_answer<br>- poll_stats: $poll_stats<br>";
$sql = "INSERT INTO poll_log VALUES (\"\",$poll_id_active,".
"$given_answer,\"$user_ip\",\"$user_proxy\",UNIX_TIMESTAMP());";
$db->query($sql);
} // end if
$db->query("SELECT COUNT(*) FROM poll_log WHERE poll_id=$poll_id_active and user_vote=1;");
$db->next_record();
$result1 = $db->f("COUNT(*)");
$db->query("SELECT COUNT(*) FROM poll_log WHERE poll_id=$poll_id_active and user_vote=2;");
$db->next_record();
$result2 = $db->f("COUNT(*)");
$db->query("SELECT COUNT(*) FROM poll_log WHERE poll_id=$poll_id_active and user_vote=3;");
$db->next_record();
$result3 = $db->f("COUNT(*)");
$db->query("SELECT COUNT(*) FROM poll_log WHERE poll_id=$poll_id_active and user_vote=4;");
$db->next_record();
$result4 = $db->f("COUNT(*)");
$db->query("SELECT COUNT(*) FROM poll_log WHERE poll_id=$poll_id_active and user_vote=5;");
$db->next_record();
$result5 = $db->f("COUNT(*)");
$db->query("SELECT COUNT(*) FROM poll_log WHERE poll_id=$poll_id_active and user_vote=6;");
$db->next_record();
$result6 = $db->f("COUNT(*)");
$total = $result1+$result2+$result3+$result4+$result5+$result6;
echo "
<table width=\"165\" cellspacing=\"0\" cellpadding=\"2\" class=\"poll\">";
echo "
<tr class=\"poll_question\"><td>".$poll_question_active."</td></tr><tr><td> </td></tr>";
echo "
<tr class=\"text\"><td><i><u>Gesamt:</u> ".$total." Stimmen</i></td></tr><tr><td> </td></tr>";
if (($result1 > 0) and ($total > 0)) $percent = round(((100*$result1)/$total), 2);
if($result1!="0") $color1= "cornflowerblue";
if ($percent < 5.00) $color1 = "";
echo "
<tr class=\"text\"><td>\"<b>".$poll_answer1_active."</b>\" (".$result1.") :</td></tr>";
echo "
<tr><td>
<table><tr class=\"text\"><td bgcolor=\"".$color1."\" width=\"".$percent."\"> </td></tr></table>";
echo "
</td></tr>
";
if (($result2 > 0) and ($total > 0)) $percent = round(((100*$result2)/$total), 2);
if($result2!="0") $color2= "skyblue";
if ($percent < 5.00) $color2 = "";
echo "
<tr class=\"text\"><td>\"<b>".$poll_answer2_active."</b>\" (".$result2.") :</td></tr>";
echo "
<tr><td>
<table><tr class=\"text\"><td bgcolor=\"".$color2."\" width=\"".$percent."\"> </td></tr></table>";
echo "
</td></tr>
";
if(strlen($poll_answer3_active) > 1){
if (($result3 > 0) and ($total > 0)) $percent = round(((100*$result3)/$total), 2);
if($result3!="0") $color3= "lightskyblue";
if ($percent < 5.00) $color3 = "";
echo "
<tr class=\"text\"><td>\"<b>".$poll_answer3_active."</b>\" (".$result3.") :</td></tr>";
echo "
<tr><td>
<table><tr class=\"text\"><td bgcolor=\"".$color3."\" width=\"".$percent."\"> </td></tr></table>";
echo "
</td></tr>
";
}
if(strlen($poll_answer4_active) > 1){
if (($result4 > 0) and ($total > 0)) $percent = round(((100*$result4)/$total), 2);
if($result4!="0") $color4= "lightblue";
if ($percent < 5.00) $color4 = "";
echo "
<tr class=\"text\"><td>\"<b>".$poll_answer4_active."</b>\" (".$result4.") :</td></tr>";
echo "
<tr><td>
<table><tr class=\"text\"><td bgcolor=\"".$color4."\" width=\"".$percent."\"> </td></tr></table>";
echo "
</td></tr>
";
}
if(strlen($poll_answer5_active) > 1){
if (($result5 > 0) and ($total > 0)) $percent = round(((100*$result5)/$total), 2);
if($result5!="0") $color5= "lightsteelblue";
if ($percent < 5.00) $color5 = "";
echo "
<tr class=\"text\"><td>\"<b>".$poll_answer5_active."</b>\" (".$result5.") :</td></tr>";
echo "
<tr><td>
<table><tr class=\"text\"><td bgcolor=\"".$color5."\" width=\"".$percent."\"> </td></tr></table>";
echo "
</td></tr>
";
}
if(strlen($poll_answer6_active) > 1){
if (($result6 > 0) and ($total > 0)) $percent = round(((100*$result6)/$total), 2);
if($result6!="0") $color6= "darkgray";
if ($percent < 5.00) $color6 = "";
echo "
<tr class=\"text\"><td>\"<b>".$poll_answer6_active."</b>\" (".$result6.") :</td></tr>";
echo "
<tr><td>
<table><tr class=\"text\"><td bgcolor=\"".$color6."\" width=\"".$percent."\"> </td></tr></table>";
echo "
</td></tr>
";
}
} // end else
echo "
</table>
";
/* print stats link only if stats aren't displayed already */
if (($poll_action != "vote") and ($poll_stats != "yes")) {
echo "
<!-- poll_stats button -->
<div align=\"center\"><a href=\"$PHP_SELF?idcat=$idcat&poll_stats=yes\">Statistik »</a></div>
<!-- end poll_stats button -->";
}
/* end "print stats link only if stats aren't displayed already" */
}
/* end "there is an active poll in DB" */
echo "
<!-- end umfragenmodul -->
";
/* unlock tables */
$db1->query("UNLOCK TABLES;");
/* end "unlock tables" */
?>