Temos pavadinimas: WordPress, Shopify ir PHPFusion programuotojų bendruomenė :: vote kas 24

Parašė aiwis· 2009 Kov. 17 05:03:37
#3

na o kaip ta laiko limita padaryti
<?
begin_block("Apklausa");

if (!function_exists("srt")) {
   function srt($a,$b){
      if ($a[0] > $b[0]) return -1;
      if ($a[0] < $b[0]) return 1;
      return 0;
   }
}

if ($_SERVER["REQUEST_METHOD"] == "POST" && $CURUSER && $_POST["act"] == "takepoll"){
   $choice = $_POST["choice"];
   if ($choice != "" && $choice < 256 && $choice == floor($choice)){
      $res = mysql_query("SELECT * FROM polls ORDER BY added DESC LIMIT 1") or die(mysql_error());
      $arr = mysql_fetch_assoc($res) or show_error_msg("Error", "No Poll",1);

      $pollid = $arr["id"];
      $userid = $CURUSER["id"];

      $res = mysql_query("SELECT * FROM pollanswers WHERE pollid=$pollid && userid=$userid") or die(mysql_error());
      $arr = mysql_fetch_assoc($res);

      if ($arr){
         show_error_msg("Error", "You have already voted!", 0);
      }else{

         mysql_query("INSERT INTO pollanswers VALUES(0, $pollid, $userid, $choice)") or die(mysql_error());
         if (mysql_affected_rows() != 1)
               show_error_msg("Error", "An error occured. Your vote has not been counted.", 0);
      }
      //bonus comment
if($CURUSER['id'] != $arr["owner"]) {
$bonusf = 5;
      mysql_query("UPDATE users SET seedbonus = seedbonus + '$bonusf' WHERE id=".$CURUSER["id"]) or sqlerr();
      }
//end bonus comment
   }else{
      show_error_msg("Error", "Please select an option.", 0);
   }
}

// Get current poll
if ($CURUSER){
   $res = mysql_query("SELECT * FROM polls ORDER BY added DESC LIMIT 1") or die(mysql_error());

   if($pollok=(mysql_num_rows($res))) {
      $arr = mysql_fetch_assoc($res);
      $pollid = $arr["id"];
      $userid = $CURUSER["id"];
      $question = $arr["question"];

      $o = array($arr["option0"], $arr["option1"], $arr["option2"], $arr["option3"], $arr["option4"],
       $arr["option5"], $arr["option6"], $arr["option7"], $arr["option8"], $arr["option9"],
       $arr["option10"], $arr["option11"], $arr["option12"], $arr["option13"], $arr["option14"],
       $arr["option15"], $arr["option16"], $arr["option17"], $arr["option18"], $arr["option19"]);

      // Check if user has already voted
        $res = mysql_query("SELECT * FROM pollanswers WHERE pollid=$pollid AND userid=$userid") or die(mysql_error());
        $arr2 = mysql_fetch_assoc($res);
   }

   //Display Current Poll
   if($pollok) {
      print("<p align=center><b>$question</b></p>\n");
        $voted = $arr2;

      // If member has voted already show results
        if ($voted) {
          if ($arr["selection"])
               $uservote = $arr["selection"];
          else
               $uservote = -1;

         // we reserve 255 for blank vote.
          $res = mysql_query("SELECT selection FROM pollanswers WHERE pollid=$pollid AND selection < 20") or die(mysql_error());

          $tvotes = mysql_num_rows($res);

          $vs = array(); // array of
          $os = array();

          // Count votes
          while ($arr2 = mysql_fetch_row($res))
            $vs[$arr2[0]] += 1;

          reset($o);
          for ($i = 0; $i < count($o); ++$i)
            if ($o[$i])
              $os[$i] = array($vs[$i], $o[$i]);

          // now os is an array like this: array(array(123, "Option 1"), array(45, "Option 2"))
          if ($arr["sort"] == "yes")
             usort($os, srt);

          print("<table width=100% border=0 cellspacing=0 cellpadding=0>\n");
          $i = 0;

          while ($a = $os[$i]){
               if ($i == $uservote)
                 $a[1] .= "&nbsp;*";
               if ($tvotes == 0)
                  $p = 0;
               else
                  $p = round($a[0] / $tvotes * 100);
               if ($i % 2)
                 $c = "";
               else
                 $c = " bgcolor=#ECE9D8";
               print("<tr><td width=1% $c>" . format_comment($a[1]) . "&nbsp;&nbsp;</td><td width=99% $c><img src=".$site_config["SITEURL"]."/images/bar_left.gif><img src=".$site_config["SITEURL"]."/images/bar.gif height=9 width=" . ($p / 2) . "><img src=".$site_config["SITEURL"]."/images/bar_right.gif>$p%</td></tr>\n");
               ++$i;
          }

      print("</table>\n");
      $tvotes = number_format($tvotes);
       print("<p align=center>Balsavo: $tvotes</p>\n");

     }else{//User has not voted, show options

       print("<form method=post action='?$_SERVER[QUERY_STRING]'>\n");
   print("<input type=hidden name=act value='takepoll'>");
       $i = 0;

       while ($a = $o[$i]){
            print("<input type=radio name=choice value=$i>".format_comment($a)."<br>\n");
            ++$i;
       }

       print("<br>");
       print("<input type=radio name=choice value=255>tik pažiurėti rezultatus<br>\n");
       print("<p align=center><input type=submit value='Balsuoti!' class=btn></p></form>");
     }

   } else {
        echo"<BR><BR><CENTER>nera apklausos</CENTER><BR><BR>\n";
   }
} else {
   echo"<BR><BR><CENTER>Jūs turite būti registruotas apžiūrėti apklausas</CENTER><BR><BR>\n";
}

end_block();
?>



Redagavo aiwis· 2009 Kov. 17 06:03:30