| 1 | <?php |
| 2 | |
| 3 | if(!IsSet($poll)) |
| 4 | { |
| 5 | $q = "select id_poll from polls where forum_id = '$node_id' order by id_poll desc limit 1"; |
| 6 | $reslt = $kyberia->query($q); |
| 7 | if($reslt->getNumRows() > 0) $reslt->next(); |
| 8 | $poll = $reslt->getString('id_poll'); |
| 9 | } |
| 10 | |
| 11 | $query = "select * from user_poll where user_id='$user_id' and poll_id='$poll'"; |
| 12 | $result = $kyberia->query($query); |
| 13 | if($result->getNumRows()==0) define ('VOTE', true); |
| 14 | else define ('VOTE', false); |
| 15 | |
| 16 | if(IsSet($option)) |
| 17 | { |
| 18 | $sqlcmd="select * from user_poll where user_id='$user_id' and poll_id='$poll'"; |
| 19 | $result=$kyberia->query($sqlcmd); |
| 20 | if ($result->getNumRows()==0) { |
| 21 | $sqlcmd="update polls set responses=responses+1 where id_poll=$poll"; |
| 22 | $result=$kyberia->query($sqlcmd); |
| 23 | $sqlcmd="update poll_options set number=number+1 where id_option=$option"; |
| 24 | $result=$kyberia->query($sqlcmd); |
| 25 | $kyberia->query("insert into user_poll set user_id='$user_id',poll_id='$poll'"); |
| 26 | } |
| 27 | else echo "<br><center><font color='red'><b>brawco,v ankete uz si hlasoval!</b></font></center>"; |
| 28 | } |
| 29 | |
| 30 | $sqlcmd="select * from polls where forum_id='$node_id' order by id_poll desc |
| 31 | limit 1"; |
| 32 | $result=$kyberia->query($sqlcmd); |
| 33 | if ($result->getNumRows()>0) { |
| 34 | $result->next(); |
| 35 | echo "<table class=box><tr><td colspan=3 align=center>"; |
| 36 | echo $result->getString('question'); |
| 37 | $percent=$result->getString('responses')/100; |
| 38 | if (!$percent) $percent=1; |
| 39 | echo "</td></tr>"; |
| 40 | |
| 41 | $sqlcmd="select * from poll_options where id_poll='".$result->getString('id_poll')."'"; |
| 42 | $result2=$kyberia->query($sqlcmd); |
| 43 | while ($result2->next()) { |
| 44 | (int) $count = (int) ($result2->getString('number')/$percent); |
| 45 | $count2 =$count/2; |
| 46 | if(VOTE && !IsSet($option)) |
| 47 | echo "<tr><td><a href=$PHP_SELF?action=forum&node_id=$node_id&poll=",$result->getString('id_poll'),"&option=",$result2->getString('id_option'),">",$result2->getString('text'),"</a></td><td><table width=$count2 bgcolor=#6dae42 height=5><tr height=5><td height=5></tr></td></table></td><td>".$count."% </td></tr>"; |
| 48 | else |
| 49 | echo "<tr><td>".$result2->getString('text')."</td><td><table width=$count2 bgcolor=#6dae42 height=5><tr height=5><td height=5></tr></td></table></td><td>".$count."% </td></tr>"; |
| 50 | } |
| 51 | echo "<tr><td colspan=3 align=center><br>Spolu hlasovalo<br><b>".$result->getString('responses')."</b><br>ludi</td></tr>"; |
| 52 | echo "</table>"; |
| 53 | } |
| 54 | |
| 55 | ?> |