Student Online Voting

Around exam time, it's pretty common to want to take a poll to see what possible review session times work for students. Here's a script that was designed to handle this on the course webpage. It's general enough to work for any kind of online poll.

integrated screenshot

A typical deployment with integrated look and feel is shown in the image above.

How to use it

In order to use it, you will need to modify your .htaccess file, download the vote.php and vote.shtml files and set up a vote/voteconfig.txt file. Votes are currently restricted to students registered in the course, and course staff, so you'll also need to vote/permissions.php, as explained in the Restricting Permissions section below.

When students vote, the actual data is stored in a file vote/votedata.csv (relative to vote.php). To change the locations of where vote.php looks for these files, modify the globals TIME_DATA_FILE and VOTE_DATA_FILE in vote.php.

The default layout of files is shown below:

layout of files

Modifying .htaccess

Add the following lines to your .htaccess file. If this file does not exist, create it.

<FilesMatch "vote\.(shtml|php)">
  AddHandler cgi-script .php
  PerlAuthenHandler Apache::AuthenURL
  Require valid-user
  SSLRequireSSL
</FilesMatch>

Here is a sample .htaccess file.

Download vote.php and vote.shtml

If you are trying to integrate the poll into a standard styled website, like CS 136's (as shown in the image at the start of this page), download vote.php and vote.shtml. Note that if you rename vote.php to something else, you will need to edit where the form posts to by modifying the global FORM_POST_FILE in vote.php. If you rename vote.shtml, you'll have to modify the REDIRECT_AFTER_POST_FILE global. You will also need to modify the .htaccess file accordingly.

If you're just interested in a standalone copy that does not try to fit into the standard look and feel, download vote_standalone.php. You can rename this file to whatever you like without having to modify the code, but you will still need to ensure the .htaccess file matches the filename.

Be sure to chmod a+x vote.php!

Set-up a voteconfig.txt file

By default, the script looks for this in vote/voteconfig.txt, so if you have your vote.php|shtml files in ~cs136/public_html/vote.php|shtml, put this in ~cs136/public_html/vote/voteconfig.txt (create the vote subdirectory if necessary). This is the same location where the vote data will be stored. It is a good idea to chmod o-r vote to disallow students from reading that directory.

The format of this text file is:

Title of page
Option 1
Option 2
...
Option n

For example:

Midterm Review Session Times
Wednesday, June 16, 4:30pm
Wednesday, June 16, 6:30pm
Thursday, June 17, 4:30pm
Thursday, June 17, 6:30pm
Friday, June 18, 4:30pm

Download a sample voteconfig.txt.

Disabling a vote (VOTE_RUNNING)

When the vote is over, to stop users from voting, but allow them to see the result, simply modify the variable VOTE_RUNNING at the top of vote.php. A value of true means users can continue to vote, while a value of false means the vote is closed.

Restricting Permissions

The default for vote.php is to have access to it restricted to students enrolled in the course, and the course staff. To change this, you'll need to modify these lines at the start of vote.php:

require_once "vote/permissions.php";

$allowed = array("isc", "instructor", "tutor", "ta", "student");
ensure_permissions(USER_ID, $allowed);

This requires a coursestaff.term file to exist in order to work. This file must be created manually under your course's home directory. For details on the format of this file, see ClassListPerlModule.

For documentation on the permissions.php itself, see RestrictingWebAccessToCourse.

Troubleshooting

See TroubleshootingPHP.
Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng file_layout.png r3 r2 r1 manage 10.4 K 2010-06-20 - 13:30 PeterBeshai layout of directory structure
Unknown file formatext htaccess r1 manage 0.2 K 2010-06-10 - 20:45 PeterBeshai sample .htaccess file
Texttxt vote.renametophp.txt r4 r3 r2 r1 manage 5.5 K 2010-06-20 - 13:27 PeterBeshai vote.php for integration with vote.shtml
HTMLshtml vote.shtml r2 r1 manage 0.5 K 2010-06-15 - 12:30 PeterBeshai vote.shtml for integration with standard look and feel
GIFgif vote_screenshot.gif r1 manage 30.6 K 2010-06-10 - 18:40 PeterBeshai integrated screenshot
Texttxt vote_standalone.renametophp.txt r3 r2 r1 manage 5.3 K 2010-06-20 - 13:27 PeterBeshai vote.php that works on its own
Texttxt voteconfig.txt r1 manage 0.2 K 2010-06-10 - 20:39 PeterBeshai sample voteconfig.txt to be put in vote/voteconfig.txt
Edit | Attach | Watch | Print version | History: r9 < r8 < r7 < r6 < r5 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r9 - 2010-06-20 - PeterBeshai
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback