2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto */
9 /* This program is free software. You can redistribute it and/or */
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /************************************************************************/
15 if (!defined('AT_INCLUDE_PATH')) { exit; }
16 global $_base_path, $include_all, $include_one;
20 if (isset($_POST['poll_submit'], $_POST['choice'])) {
21 $poll_id = intval($_POST['poll_id']);
23 $sql = "INSERT INTO ".TABLE_PREFIX."polls_members VALUES($poll_id, $_SESSION[member_id])";
24 if ($result = mysql_query($sql, $db)) {
25 $n = intval($_POST['choice']);
27 $sql = "UPDATE ".TABLE_PREFIX."polls SET count$n=count$n+1, total=total+1 WHERE poll_id=$poll_id AND course_id=$_SESSION[course_id]";
28 $result = mysql_query($sql, $db);
34 if (!isset($include_all, $include_one)) {
35 $include_one = ' checked="checked"';
38 $sql = "SELECT * FROM ".TABLE_PREFIX."polls WHERE course_id=$_SESSION[course_id] ORDER BY created_date DESC LIMIT 1";
39 $result = mysql_query($sql, $db);
41 if ($row = mysql_fetch_assoc($result)) {
42 echo '<table width="100%">';
44 if (!authenticate(AT_PRIV_POLLS, AT_PRIV_RETURN)) {
45 $sql = "SELECT * FROM ".TABLE_PREFIX."polls_members WHERE poll_id=$row[poll_id] AND member_id=$_SESSION[member_id]";
46 $result = mysql_query($sql, $db);
48 if (authenticate(AT_PRIV_POLLS, AT_PRIV_RETURN) || ($my_row = mysql_fetch_assoc($result))) {
50 echo '<td valign="top" class="dropdown-heading" align="left"><strong>' . AT_print($row['question'], 'polls.question') . '</strong>';
54 for ($i=1; $i<= AT_NUM_POLL_CHOICES; $i++) {
55 if ($row['choice' . $i]) {
57 $width = round($row['count' . $i] / $row['total'] * 110);
63 echo '<td valign="top" class="dropdown" align="left">';
64 echo '<small>' . AT_print($row['choice' . $i], 'polls.choice') . '</small><br />';
65 echo '<img src="'.$_base_path . 'images/blue.gif" height="5" width="'.$width.'" alt="" /> '.$row['count' . $i];
70 // show the form to vote
72 echo '<td valign="top" class="dropdown" align="left"><strong>' . AT_print($row['question'], 'polls.question') . '</strong>';
73 echo '<form method="post" action="'.htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES).'"><input type="hidden" name="poll_id" value="'.$row['poll_id'].'" />';
74 echo '<table width="100%" border="0" cellspacing="0" cellpadding="0" summary="">';
75 for ($i=1; $i<= AT_NUM_POLL_CHOICES; $i++) {
76 if ($row['choice' . $i]) {
78 echo '<td valign="top" align="left">';
79 echo '<small><input type="radio" name="choice" value="'.$i.'" id="c'.$i.'" /><label for="c'.$i.'">' . AT_print($row['choice' . $i], 'polls.choice') . '</label></small></td></tr>';
84 echo '<td valign="top" align="center"><input type="submit" name="poll_submit" value="'._AT('submit').'" class="button" />';
85 echo '<br /><small>'._AT('vote_to_see_results').'</small>';
88 echo '</table></form></td></tr>';
93 echo '<em>'._AT('none_found').'</em><br />';
96 $savant->assign('dropdown_contents', ob_get_contents());
99 $savant->assign('title', _AT('polls'));
100 $savant->display('include/box.tmpl.php');