SO 1-final
[specialops1.git] / viewpoll.php
blobb6942749b22aab56814c021a864e402fce7857f1
1 <?php
2 $page_name = 'Current Poll';
3 require ('config.php');
4 if (!empty ($_POST['submit']))
6 $require_login = true;
7 $level_restriction = NEW_USER;
9 require ('top.inc.php');
11 $current_poll = mysql_result (mysql_query ('SELECT `pollid` FROM `poll` ORDER BY `pollid` DESC LIMIT 1'), 0);
12 $polls = isset ($_GET['pollid']) ?
13 mysql_query ('SELECT * FROM `poll` WHERE `pollname` != \'\' AND `pollid` <= '.intval ($_GET['pollid']).' ORDER BY `pollid` DESC'):
14 mysql_query ('SELECT * FROM `poll` WHERE `pollname` != \'\' ORDER BY `pollid` DESC');
15 $pollinfo = mysql_fetch_row ($polls);
16 if (!$pollinfo)
17 stop ('Invalid poll ID.');
18 $prev_poll = mysql_query ('SELECT `pollid` FROM `poll` WHERE `pollname` != \'\' AND `pollid` < '.$pollinfo[0].' ORDER BY `pollid` DESC LIMIT 1');
19 $next_poll = mysql_query ('SELECT `pollid` FROM `poll` WHERE `pollname` != \'\' AND `pollid` > '.$pollinfo[0].' ORDER BY `pollid` ASC LIMIT 1');
22 if (isset ($_POST['submit']))
24 if ($userinfo['lastpoll'] == $pollinfo[0])
25 echo '<div class="alert">You have already voted in the current poll.</div>
27 elseif (!isset ($userinfo['username']))
28 echo '<div class="alert">You must be logged in to vote.</div>
30 elseif (!$pollinfo[$_POST['voteid'] + 1])
31 echo '<div class="alert">Invalid poll option.</div>
33 else
35 $voteid = intval ($_POST['voteid']);
36 mysql_query ('UPDATE `poll` SET `votes'.$voteid.'` = (`votes'.$voteid.'` + 1) WHERE `pollid` = '.$pollinfo[0]);
37 mysql_query ('UPDATE `users` SET `lastpoll` = '.$pollinfo[0].', `lastvote` = '.$voteid.' WHERE `lastacip` = \''.$_SERVER['REMOTE_ADDR'].'\'');
38 echo '<div class="alert">Vote submitted.</div>
40 $pollinfo = mysql_fetch_row (mysql_query ('SELECT * FROM `poll` ORDER BY `pollid` DESC'));
44 $sum = array_sum (array_slice ($pollinfo, 10, 8));
45 echo '<div class="c3">'.$pollinfo[1].': '.$sum.' votes, started '.date2 ($pollinfo[18]).'</div>
46 <table>
47 <tr><th style="width:20%">Option</th><th colspan="2">Votes</th></tr>
49 for ($optnum = 2; $optnum < 10; $optnum++)
51 $widthpc = $sum ? round ($pollinfo[($optnum + 8)] / $sum * 90, 1) : 0;
52 if ($pollinfo[$optnum] != '')
54 echo '<tr class='.colour().'><td title="'.($optnum-1).'">'.$pollinfo[$optnum].'</td><td style="width:2em">'.$pollinfo[($optnum + 8)].'</td>
55 <td><div class="alert" style="width:',$widthpc,'%;white-space:normal;overflow:visible">';
56 if ($userinfo['level'] >= MOD && $current_poll == $pollinfo[0])
58 $voteusers = mysql_query ('SELECT `userid` FROM `users` WHERE `lastpoll` = '.$pollinfo[0].' AND `lastvote` = '.($optnum - 1));
59 for ($un = 0; $usr = mysql_fetch_row ($voteusers); ++$un)
60 echo ($un ? ', ' : 'Users: ').userlink($usr[0]);
62 else
63 echo '&nbsp;';
64 echo '</div></td></tr>
68 echo '</table>
69 <div class="c3">';
70 if (mysql_num_rows ($prev_poll))
71 echo '<a href="?pollid='.mysql_result ($prev_poll, 0).'" rel="previous">&larr; Previous</a>';
72 if (mysql_num_rows ($next_poll))
73 echo ' | <a href="?pollid='.mysql_result ($next_poll, 0).'" rel="next">Next &rarr;</a> | <a href="poll.php">Current Poll</a>';
75 echo '</div>';
77 echo '<h2>Full List</h2>
78 <ol class="plain-list">';
79 $polls = mysql_query ('SELECT * FROM `poll` WHERE `pollname` != \'\' ORDER BY `pollid` DESC');
80 while ($pollinfo = mysql_fetch_row ($polls))
81 echo '<li class='.colour().'><a href="?pollid='.$pollinfo[0].'">'.date2 ($pollinfo[18]).': '.$pollinfo[1].'</a></li>'."\n";
82 echo '</ol>';
84 require ('foot.php');