3.21 Internet Programming. SAMPLE EXAMINATION PAPER.1.5 hours.

Answer ALL questions. Percentages given are percentages of overall exam mark.

1. You are provided with XHTML code A, representing a web-page used by a hypothetical video-hire company for reserving videos prior to hire.

a) There are five errors in this code that prevent it from being valid transitional XHTML. Identify them. (10%)

b) Study the XHTML code and draw, as accurately as you can, how you would expect a browser to render this page. Assume that the errors from 1a have been fixed. (20%)

c) Suppose the form needed to be modified to include a password field. Give the XHTML code that would be required to produce this, and explain where it would need to be inserted. (5%)

d) What is the problem with the way that the user is asked to select DVD or VHS on this form? Suggest a better approach to gathering this data. (5%)

2. Javascript code Brepresents code inserted into the head section of XHTML code A to get the 'film' drop-down working. When the user selects a classification, the film box needs to be emptied and then repopulated with available films. The code sets up three arrays (the first containing film names, the second classifications, and the third the codes that the form should submit if the user reserves that film), and defines three functions, the final one incomplete.

a) What does the function called 'c' do? (3%)

b) What does the function called 'n' do? (3%)

c) What needs to be inserted into XHTML code A (and where) to call the function called 'dochange' when they user changes the 'classbox' drop-down? (2%)

d) Write code to be inserted at the point in Javascript code B marked with [a] to get the function 'dochange' to correctly update the 'film' drop-down. (22%)

3.You are required to write a PHP file that will check a user's name and password, which are provided to the file as 'post' data,with variable names 'user' and 'password'. If the username and password are recognised, the file will acknowledge this, set a session variable called 'clearance' to the appropriate level, and provide a link to a file called 'main.php'. Otherwise it will tell the user that their username/password is not valid, and provide a link back to the login page, 'login.htm'. The allowable usernames, passwords and clearance levels (in that order) reside in a CSV file called 'passwords.csv', the first two lines of which hence look like:

"mark","rrtg123",5

"john","0ge244",2

Pseudocode for the PHP code is as follows:

Initiate Session, set 'nomatch' flag to true, and open CSV file

Get first line of data, then do the following until data line is empty (i.e. end of file)

{

Check to see if data line matches user and password. If so:

{

Set 'clearance' session variable to value from data line

Set 'nomatch' flag to false

Tell user they are logged in, provide link to main.htm

}

Get next data line

}

if nomatch flag is true, tell user their username/password was invalid, provide link to login.htm

Write the PHP file to implement this pseudocode. You may omit the XHTML header - begin your answer with the <body> tag. (30%)

XHTML CODE A

<!DOCTYPE html PUBLIC

"-//W3C//DTD XHTML 1.0 Transitional//EN"

"

<html xmlns="

xml:lang="en" lang="en">

<head>

<meta http-equiv="Content-Type"

content="text/html; charset=iso-8859-1" />

<h3> Choose your hire options and click submit </h3>

<form id="myform" action="process.php" method="put">

<table border=1>

<tr>

<td> <u>Membership Number</u> </td>

<td> <input type="text" name="memnum" maxlength="8" size="12" /> </td>

</tr>

<tr>

<td> DVD? <input type="checkbox" name="dvd" value="yes" /> </td>

</td>

<td rowspan="2" align="center">Nights required<br />

<select name="nights"

<option>1</option> <option>2</option

<option>3</option> </select>

</td>

<tr>

<td> VHS? <input type="checkbox" name="vhs" value="yes" /> </td>

</tr>

<tr>

<td colspan="2" align="center">

<select id="classbox"

<option value="1">Choose classification</option>

<option value="2">PG and below </option>

<option value="3">12 and below</option>

<option value="4">15 and below</option>

<option value="5">18 and below</option> </select>

</td>

</tr>

<tr>

<td colspan="2" align="center">

<select name="film" id="filmbox"

<option value="NON">Select film to reserve</option>

</select>

</tr>

</td>

</table>

<br />

<br />

<input type="submit" value="Reserve Video"/

</form>

</body>

</html>
JAVASCRIPT CODE B

<script type="text/javascript">

//<![CDATA[

//Define film name array

var filmarray = new Array("Charlie And The Chocolate Factory",

"Mr & Mrs Smith","Fantastic Four","Wedding Crashers, The",

"Corpse Bride","Island, The","War Of The Worlds",

"Batman Begins", "Bewitched", "40 Year Old Virgin",

"WolfCreek","SinCity","Madagascar","Polar Express");

//Define film classification array

var filmclass = new Array("12","15","PG","15","PG","12","12",

"12","PG","15","18","18","U","U");

//Define film database codes

var filmclass = new Array("CHA","MRA","FAN","WED","COR","ISL","WAR",

"BAT","BEW","40Y","WOL","SIN","MAD","POL");

function c()

{

var x;

for (x = document.forms.myform.elements.filmbox.length; x >= 0; x--)

{

document.forms.myform.elements.filmbox[x] = null;

}

}

function n(val, text)

{

var next;

next = document.forms.myform.elements.filmbox.length;

document.forms.myform.elements.filmbox[next] = new Option(text, val);

}

function dochange()

{

var i;

var cat = document.forms.myform.elements.classbox.value;

//Set the drop-down 'filmbox' to the films allowed by selection in 'classbox'

[a]

}

//]]>

</script>