Web Programming
|
Having found during the past few years, and especially this summer, how scarce and therefore marketable programming skills are still in many Third World countries (and indeed in First World countries too ...,) I decided to run an Activity to help students develop some of these skills.
There used to be quite a few students every year who were keen on and often extremely good at writing programs, but now hardly anybody seems to do that kind of 'playing around,' largely perhaps because Microsoft programs are designed to hide that side of things from the user.
But there is, I have found, a lot of fun to be had -- rather more than from just playing computer games, even for non-nerds. In the Activity we are also trying to do something useful, by designing and hopefully maintaining a website for the Growing Businesses Foundation, a Nigerian micro-finance corporation founded by an AC ex-student.
The two major browsers (or 'user agents',) IE and NN, used to have different conventions,
but over the last few years there has been some convergence, and the latest versions largely support the W3C's HTML 4.01 and Cascading Style Sheets, level 1 specifications, so that pages can be written that are rendered similarly on different browsers.
A good learning resource for both HTML and JavaScript are the W3Schools Online Web Tutorials.
Students will, in small groups, write small programs, all with some international theme, taking as their starting point a simple sample of JavaScript. To understand the basics, it will be enough to write the scripts so that they display well in the recent W3C DOM (= Document Object Model) compliant browsers (IE5+, NN6+.)
To find out about JavaScript, there are a Core JavaScript Guide 1.5 from Netscape, a JScript User's Guide from Microsoft, and a list of other articles, including some basic introductions, but some of them for older versions of the language or the browsers, from WebReference.
To see the script use 'View' > 'Source'.
Still to do:
Every Perl-installation comes with a very full set of documentation, but here are Rex Swain's HTMLified Perl 5 Reference Guide and a link to a useful site, perldoc.com .
#!/usr/bin/perl -w
# use diagnostics;
use CGI qw(:all);
@month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
open(LastChange,"pl-ex0.txt");
@last = <LastChange>;
close(LastChange);
chomp(@last);
$now = time;
@now = gmtime($now);
$mnth = $month[$now[4]];
$year = $now[5] + 1900;
$past = $now - $last[0];
if ((!param) or (param('newcol') eq 'none') or (param('newcol') eq $last[1])) {
$line = "The background colour was last changed <b>$past</b> seconds ago.";
}
else {
$last[1] = param('newcol');
$line = "You have just changed the background colour to <b>$last[1]</b>.";
open(LastChange,">pl-ex0.txt");
print LastChange "$now\n$last[1]\n";
close(LastChange);
}
print "Content-type: text/html\n\n";
print <<end
<html>
<head>
<title>Demo of 'pl-ex0.pl'</title>
<meta http-equiv="expires" content="0">
<meta http-equiv="pragma" content="no-cache">
</head>
<body bgcolor=$last[1]>
The date is <b>$now[3] $mnth $year</b>.<br>
The time is <b>$now[2]:$now[1]:$now[0] GMT</b>.<br>
(Refresh the page if it is not current.)<p>
$line<p>
<form action=pl-ex0.pl>
You can change the background colour now:
<select name=newcol size=1>
<option value=none>no change</option>
<option value=none>-----------------</option>
<option value=gray>gray</option>
<option value=silver>silver</option>
<option value=white>white</option>
<option value=yellow>yellow</option>
</select>
<input type=hidden name=time value=$now>
<input type=submit value="Submit."><p>
<input type=button value="Close." onClick="window.close()">
</form>
</body>
</html>
end
|
(Note that since 'file locking' is not used, the file pl-ex0.txt on the server could become corrupted if more than one user changed the background colour at the same time.)
We will together plan the structure of a CGI script, and then write the program in Perl, to read a multiple choice test from a file on the server and display it in a browser, with the questions and answers in random order, and with the option for the student at the end to submit their score to a list that the teacher can access.