You are going to write the client-side code for a web-site that allows a person to vote for their favorite color. It does three things:
  1. When the page is loaded, it reads the colorballot.xml file on the server and updates all the labels for the radio buttons to the appropriate vote counts.
  2. Every 10 seconds it reads the color relation on the server and updates the vote counts.
  3. Whenever the user presses a radio button, it updates the color relation on the server and updates the vote count for that color.

The files you need can be found in /home/bvanderz/webhome/cgi-bin/colorBallot_db. Once you are finished you can either use different browsers or use different tabs to vote in different windows and make sure that each window gets appropriately updated every 10 seconds.

The files perform the following tasks:

  1. color.html: The main html page that shows the color ballot
  2. colorballot.sql: Sets up the color relation in the students database and enters sample data for each tuple.
  3. countballot.js: Contains event handlers for the onload and radio button press events and callback functions for handling the response from the server. The students should complete this file in class.
  4. getCounts.php: called when the page is loaded and every 10 seconds thereafter to get the vote counts for the different colors
  5. ballotcount.php: called in response to the onload event. It updates the vote count for the selected color and returns the new vote count. If other people have voted in the last 10 seconds, then the vote count might increase by more than 1.

Steps For You To Complete

You should complete these steps in the following order:

  1. Load colorballot.sql in the mysql interpreter to create the Colors relation in your database.
  2. Add your username, sql password, and sql database name to the getCounts.php and ballotcount.php files. If you want to see what their json output looks like, then you can run them as follows:
    	  php-cgi getCounts.php
    	  php-cgi ballotcount.php color='red'
    	
    You can of course use any of the 5 colors that are inserted into the Colors relation.
  3. Complete countballot.js.