CSCI 4230
 Internet Application Development
 Spring 2001
 Homework #4

Due date: March 19, 2001.

This program is much more difficult than the previous ones and will be counted as two assignments.  Be sure that you reserve at least twice as much time for development.

It took me about 6 hours to code the solution, 2 to 3 times that of homework #3.  The brightest students may do better as I give away detailed tips on most tricky issues.  For the average students, be prepared to spend significantly more time.

(1)    Write a CGI program IsMyCodeHotOrNot.pl.  This program is a simulation of the site: http://AmIHotOrNot.com.  Instead of allowing users to submit photos for voting, the program stores program code, with choice of languages: Perl, Java, C and Visual Basic.

Because of the relative size of the homework, it is not necessary for you to handle exception (such as user input error).  Code and their voting are stored in a database and should be accessed through DBI::ODBC.  The following sequence of screen shots explains the functionality of the program.  You should write your program to mimic the screen shots as much as possible.  Unlike the real world application, it is not necessary to ensure a user to vote on a code only once.

You must use CGI.pm with its HTML functions.

Shot 1:  Initial access to the page IsMyCodeHotOrNot.pl.  Since there is no vote, the user cannot vote on any code.  Instead, t a code submission page is display after the welcome message.

Shot 2: The user enters the correct data into the form and submit it.  Note that the code file is not used and that the selected language is Java.  It is not necessary to check input data correctness.

Shot 3: The submission is successful and a simple page is displayed, with a link for the user to go to the voting page.

Shot 4:  The user clicks on the link to go to the voting page.

Shot 5:  The program displays the code for voting (from 1 to 10, implemented as links).  It also has a link to submit code.  Note the format of the code display, which includes a submission time.

Shot 6: Instead of voting, the user selects to submit more code.

Shot 7:  The user inputs another code.  This time, the code file (c:/temp/array.pl) is used instead of the code text area.  The program uploads the file when the form is submitted.

Shot 8: The form is submitted and the user follows the voting link to come to the following screen.  In case both code and code file is submitted, code file has the precedence and its content will be stored as the code.  Note that the code entered most recently is display for voting first.

Shot 9: The user selects to vote a '6'.

Shot 10:  The result of voting is shown with three numbers: the user's own rating, the total number of votes and the average rating.  Note that the average rating has two decimal points.  The page also displays the next code for voting, which is the next most recent code, a Java program by Dr. Giarratano.

Shot 11:  The user selects to vote an 8 on the next code by Dr. Giarratano.

Shot 12: The result of the voting is display.  The next code is shown for voting.  Since there are only two votes stored in the database (the voting result is on the earliest code), the next code to display is the most recent code again (a Perl program by Yue).   Code is display for voting in a cyclic manner.  The user selects to vote a 10.

Shot 13: The voting result is tabulated and display.  The average rating is now 8 ((6+10)/2). The next code to display is now the Java program by Dr. Giarratano.

Shot 14: The users selects a 5, thus the average rating is now 6.5 ((8+5)/2).  Now is the time to vote on Yue's Perl program again.

Tips

General tips:

This program is quite realistic and can be used with modifications, including error handling and avoiding multiple voting on the same code.  Thus, the program is significantly more difficult to implement.  You are encouraged to post as many questions as you like in the message board as early as possible.

Tips on CGI.pm:

Tips on Database Schema: Tips on SQL:

For the IsMyCodeHotOrNot table:

To get the largest pid in the table that is smaller than 10.  (Note that it is not necessary 9 as the code may be deleted administratively).

select max(pid) from IsMyCodeHotOrNot
where pid < 10

For the IsMyCodeHotOrNotVote table:

To get the average rating of the pid 3:

select sum(vote*votecount)/sum(votecount)
from IsMyCodeHotOrNotVote
where pid = 3
group by pid

To update the votecount of the vote 4 of pid 5 to 10:

update IsMyCodeHotOrNotVote
set votecount = 10
where pid = 5 and vote = 4

To insert a new row (pid=6, vote=8, votecount=1):

insert into IsMyCodeHotOrNotVote(pid, vote, votecount)
values(6,8,1)

Tips on DBI::ODBC:

Tips on Result display: Tips on HTTP parameters, form submission and link query strings: Miscellaneous tips: