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 // global $course_id is set when a guest accessing a public course.
21 // This is to solve the issue that the google indexing fails as the session vars are lost.
23 if (isset($_SESSION['course_id'])) $course_id = $_SESSION['course_id'];
25 if (isset($_POST['poll_submit'], $_POST['choice'])) {
26 $poll_id = intval($_POST['poll_id']);
28 $sql = "INSERT INTO ".TABLE_PREFIX."polls_members VALUES($poll_id, $_SESSION[member_id])";
29 if ($result = mysql_query($sql, $db)) {
30 $n = intval($_POST['choice']);
32 $sql = "UPDATE ".TABLE_PREFIX."polls SET count$n=count$n+1, total=total+1 WHERE poll_id=$poll_id AND course_id=$course_id";
33 $result = mysql_query($sql, $db);
39 if (!isset($include_all, $include_one)) {
40 $include_one = ' checked="checked"';
43 $sql = "SELECT * FROM ".TABLE_PREFIX."polls WHERE course_id=$course_id ORDER BY created_date DESC LIMIT 1";
44 $result = mysql_query($sql, $db);
46 if ($row = mysql_fetch_assoc($result)) {
47 echo '<table width="100%">';
49 if (!authenticate(AT_PRIV_POLLS, AT_PRIV_RETURN)) {
50 $sql = "SELECT * FROM ".TABLE_PREFIX."polls_members WHERE poll_id=$row[poll_id] AND member_id=$_SESSION[member_id]";
51 $result = mysql_query($sql, $db);
53 if (authenticate(AT_PRIV_POLLS, AT_PRIV_RETURN) || ($my_row = mysql_fetch_assoc($result))) {
55 echo '<td valign="top" class="dropdown-heading" align="left"><strong>' . AT_print($row['question'], 'polls.question') . '</strong>';
59 for ($i=1; $i<= AT_NUM_POLL_CHOICES; $i++) {
60 if ($row['choice' . $i]) {
62 $width = round($row['count' . $i] / $row['total'] * 110);
68 echo '<td valign="top" class="dropdown" align="left">';
69 echo '<small>' . AT_print($row['choice' . $i], 'polls.choice') . '</small><br />';
70 echo '<img src="'.$_base_path . 'images/blue.gif" height="5" width="'.$width.'" alt="" /> '.$row['count' . $i];
75 // show the form to vote
77 echo '<td valign="top" class="dropdown" align="left"><strong>' . AT_print($row['question'], 'polls.question') . '</strong>';
78 echo '<form method="post" action="'.htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES).'"><input type="hidden" name="poll_id" value="'.$row['poll_id'].'" />';
79 echo '<table width="100%" border="0" cellspacing="0" cellpadding="0" summary="">';
80 for ($i=1; $i<= AT_NUM_POLL_CHOICES; $i++) {
81 if ($row['choice' . $i]) {
83 echo '<td valign="top" align="left">';
84 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>';
89 echo '<td valign="top" align="center"><input type="submit" name="poll_submit" value="'._AT('submit').'" class="button" />';
90 echo '<br /><small>'._AT('vote_to_see_results').'</small>';
93 echo '</table></form></td></tr>';
98 echo '<em>'._AT('none_found').'</em><br />';
101 $savant->assign('dropdown_contents', ob_get_contents());
104 $savant->assign('title', _AT('polls'));
105 $savant->display('include/box.tmpl.php');