CGI scripts
This section treats the scripts residing at the server side of the system,
it also treats the communication between the client and the server.
Below is a general description of the communication followed by a short
description of each script. To ease the overview of the scripts they are
divided into three categories (retrieval, storage and command).
General description
All computer-computer communication within the package is done using
cgi scripts. All but one of the script used handles applet-server communication,
the odd one out is the script used to save a students answers on the server
(web page-server communication). To tell a cgi script what to do a number
of variables are sent with the call, in most calls the information sent
to the server are just some variable strings so the GET method is sufficient.
However for some of the calls, when a lot of information has to be transferred
to the script, the POST method is used. From the script perspective it
does not matter if POST or GET is used as all the scripts can handle them
both in a similar manner. The same applies for the encoding of the variables
done by the calling side. The only difference lies in that while the variables
are put in the URL for GET, they have to be transferred through a URL connection
stream when using POST. (for a discussion on GET vs. POST see the document
Problems).
The response data from a script is sent to an applet as an (HTML) page.
This page is then parsed by the applet. With pages in this discussion are
meant text documents starting with "Content-type: text/html\n\n". There
are however no HTML code in the pages.
The general coding for the responses from the scripts are: If the response
starts with a zero ("0"), the script failed to perform ( this could for
example be due to that a file failed to open a file), if the response starts
with a one ("1"), the script call was successful.
Data retrieval scripts
The retrieving scripts are used to get data from the server. These kind
of scripts do not change the state on the server (i.e. nothing is changed
on the server).
The scripts that falls into the retrieval category are:
getAllDataFiles.perl
-
Usage: Gets information about all the subquestions, for all QuestionPages
in a subject. This information is used by the Applets to display the QuestionPages.
-
Variables: subject
-
Reads file: All files with the extension .data in the
PageData directory for the subject.
-
Writes file: result.txt in the PageData
directory. (this file is used for debugging, and is exactly the same
as the page sent)
-
Out: A page with data about the subjects QuestionPages. The page sent is
for simplicity reasons very similar to how the QuestionPage is stored on
file. In fact the page contains all QuestionPage files separated with "***",
see the chapter Directory
structure for more details. Below is an example how the page looks
like, note that all three QuestionPage types are present.
alt //The type of QuestionPage
Mundial2_space //The
title of the QuestionPage
auto //The feedback type of the QuestionPage
//Two
empty lines, these could be used to put more information in future
Quien hacia mas goles?#Ronaldo@Kluivert@Platini@Suker@Andersson@#4#//1st
sub question
Quien habia dicho antes del mundial: Voy a hacer 13
goles?#Ronaldo@Kluivert@Suker@#1#
Como se llama el arcero del equipo Holandes?#Zubizareta@Taffarel@Van
der Jerscaxzyen@Van der Saal@Van der deberia ha tomado el maldito penal@#4#
//3rd subquestion
Que jugador argentino saco la tarjeta roja, al final
del partido cuarto final?#Maradona@Batistuta@Ortega@Veron@#3# //
4th subquestion
Quien gano el mundial en 1930#Brasil@Italia@Uruguay@Ningun
se jugaban el primer en 1934@#3# //5th subquestion
*** //QuestionPage delimiter.
written
WrittenPage
send
This is where the question should be placed.<BR>The
TextArea below is where the student will place his answer.<BR># #-5#
***
cross
A_cross_page
auto
Quien gano el mundial?#Francia#5#
Que equipo hacia mas goles?#Brasil#1#
Argentina perdio el cuarto del final. Contra quien?#Holanda#4#
Que equipo habia ganado si solo habia clasifiquado?#Suecia#7#
Que equipo africano subio a la segunda ronda?#Nigeria#2#
Jamaica hacia un gol, contra quien?#Croacia#3#
Como se dice Que cuando se habla sobre numeros#Cuanto#6#
***
getAllAnswers.perl
-
Usage: Get information about all the students answers for all the QuestionPages
in a subject.
-
Variables: subject
-
Reads file: All files .data in the PageData
directory for the selected subject. All files .answer in the
StudentAnswers
directory for the selected subject.
-
Writes file: result.txt in the StudentAnswer directory (this file
is used for debugging, and is exactly the same as the page sent)
-
Out: A page with data about all the students answers to the different QuestionPages
as well as an integer telling if the sub questions where correctly answered.
See description below or look at the file result.txt in the StudentAnswer
directory. Students are sorted in decreasing cedula order. The student
answer is a number for QuestionPages of type alt and cross. For type written
it's a text string. The grade is an integer bigger than 0 if the subquestion
was correctly answered, 0 if not. Note that all written answers are 0 by
default.
<PageTitle>(<QuestionPage type>)
<The cedula of the first student that has answered this QuestionPage>
\t<No. of subquestion>\t<Student answer for the subquestion>\t<grade>
\t<No. of subquestion>\t<Student answer for the subquestion>\t<grade>
.................................
\t<Last subquestion>\t<Student answer for the subquestion>\t<grade>
<The
cedula of the next student that has answeres this QuestionPage>
\t<No. of subquestion>\t<Student answer for the subquestion>\t<grade>
\t<No. of subquestion>\t<Student answer for the subquestion>\t<grade>
.................................
\t<Last subquestion>\t<Student answer for the subquestion>\t<grade>
<New line separating QuestionPages>
<PageTitle of next QuestionPage>(<QuestionPage type>)
<The cedula of the first student that has answered this QuestionPage>
\t<No. of subquestion>\t<Student answer for the subquestion>\t<grade>
\t<No. of subquestion>\t<Student answer for the subquestion>\t<grade>
.................................
\t<Last subquestion>\t<Student answer for the subquestion>\t<grade>
<The
cedula of the next student that has answeres this QuestionPage>
\t<No. of subquestion>\t<Student answer for the subquestion>\t<grade>
\t<No. of subquestion>\t<Student answer for the subquestion>\t<grade>
.................................
\t<Last subquestion>\t<Student answer for the subquestion>\t<grade>
getStudents.perl
-
Usage: Get information about the students for a given subject.
-
Variables: subject
-
Reads file: students in the selected subject directory.
-
Writes file: none
-
Out: A page with data about all the students, see example below.
2#donald#duck
4#daisy#duck
100#sport#goofy
103#naomi#campbell
109#cindy#crawfoord
112#emma#sjoberg
doCourseInfo.perl
checkPassword.perl
-
Usage: Checking of username/password.
-
Variables: username,password,subject(optional).
-
Reads file: passwords, username.acc both in the directory Courses/Users/
-
Writes file: none
-
Out: The correctness of the username and password, plus if
subject is given: if the teacher has access to subject, if subject
isn't given: all the courses that the teacher has access to.
The script runs like this: First a check is done if the user name/password
is correct. If this is not true, a message beginning with 0 is returned.
If this is true the script proceeds with a subject check. If subject is
given as an argument it checks if the teacher has access to subject,
if so an answer beginning with 11 is returned, if not the answer returned
begins with 10. If subject is not given, then all courses that the teacher
has access to are returned, with the answer line starting with 11.
Examples of events and responses:
| Event: |
Response from script: |
| user name/password not correct |
0Invalid user name/password |
| password file couldn't be opened |
2Couldn't open the password file ... etc. |
| subject given, subject didn't exist in acc file |
10Password correct but user do not ...etc. |
| subject given, subject did exist in acc file |
11subject |
| subject given/not given, failed to open acc file |
12Password correct but failed to open access file. |
| subject not given |
11"all the subjects for teacher" |
Data storage scripts
The data storage scripts are called by applets and QuestionPages when
they need to store information on the server e.g. the MakePageApplet storing
a new QuestionPage or the CreateCourseApplet registering students.
The scripts that falls into the data storage category are:
makeDataFile.perl
-
Usage: To create a new QuestionPage data file on the server.
-
Variables: subject, title - the title of the QuestionPage,
type - the type of QuestionPage, feedback - the type of feedback,
noOfQuestion - the number of subquestions, row1;row2..row3
- lines with the subquestions, the syntax of the rows should be "Question#Answer#"
-
Reads file: none.
-
Out: A page telling if the operations went all right. If everything went
all right a line starting with "1" is returned otherwise a line starting
with "0".
-
Writes file: title.data in the PageData directory, see chapter Directory
Structure and file syntax on server. Also creates a new .answer
file for the page in the StudentAnswer directory, the reason for this is
that if the QuestionPage already existed which is the case if it has been
modified it may happen that students already have given answers. As the
new page may be completely different from the old one the .answer
file must be overwritten to avoid consistency problem e.g. students having
answered questions that in the new QuestionPage does not exist.
distans.perl
-
Usage: To transfer the students answers from the QuestionPage to the server.
Besides this the script also checks that the student is registered to the
course and that he has not answered the QuestionPage before.
-
Variables: The variables are encoded to make it more difficult for a student
with computer knowledge to cheat. a - the answers separated with
"#@[", b - the total number of questions, c - the cedula
of the student, d - the title of the QuestionPage, e - the
subject.
-
Reads files: d.answer in the StudentAnswers
directory, students and courseinfo in the subject directory.
-
Writes files: Writes the student answer to file d.answer in the
StudentAnswer
directory.
-
Out: A HTML page giving the student information that his answers have been
saved successfully, that he is not registered on the course, or that he
has already answered the QuestionPage.
registerStudents.perl
-
Usage: Registration of students on the server for a specific course/subject.
-
Variables: subject, students - subject is the name of the course
to which the students are to be registered.
-
Reads file: students ( Note! this is not the value of the variable
students but a file litterarly named student ) in the /Courses/subject/
directory.
-
Writes file: students in the /Courses/subject/ directory.
-
Out: Success/failure of the registration of the students.
Note! It is important that the students in the variable students
are ordered in increasing cedula number.
The variable students should look like this:
cedula number#first name#last name$cedula number#first
name#last name$etc.
Example:
100#John#Sjoberg$105#David#Lilljegren$Eduardo#Fernandez
deleteStudents.perl
-
Usage: Removal of students on the server for a specific course/subject.
-
Variables: subject, students - subject is the name of the course
from which the students are to be removed.
-
Reads file: students ( Note! this is not the value of the variable
students but a file litterarly named student ) in the /Courses/subject/
directory.
-
Writes file: students in the /Courses/subject/ directory.
-
Out: Success/failure of the removal of the students.
Note! It is important that the students in the variable students
are ordered in increasing cedula number.
The variable students should look like this:
cedula number#first name#last name$cedula number#first
name#last name$ etc.
Example: 100#John#Sjoberg$105#David#Lilljegren$Eduardo#Fernandez
Command scripts
The command scripts are used by an applet to perform a specific action
on the server e.g. delete a QuestionPage, add a new teacher access, etc.
The scripts that falls into the retrieval category are:
makeCross.perl
-
Usage: To create a new cross QuestionPage html file on the server, the
file is created using data stored in a .data file previously created
by calling makeData.perl
-
Variables: subject title - the name of the QuestionPage
-
Reads file: title.data in the PageData
directory given by the subject.
-
Writes file: title.html in the QuestionPages
directory.
-
Uses file: cross.js which contain the HTML/JavaScript code
that is common to all QuestionPages of type cross.
-
Out: A page telling if the operations went well. If everything went all
right a line starting with "1" is returned otherwise a line starting with
"0".
makeAlt.perl
-
Usage: To create a new alt QuestionPage page html file on the server, the
file is created using data stored in a .data file previously created by
calling makeData.perl
-
Variables: subject title - the name of the QuestionPage
-
Reads file: title.data in the PageData
directory given by the subject.
-
Writes file: title.html in the QuestionPages
directory.
-
Uses file: alt.js which contain the HTML/JavaScript code that
is common to all QuestionPages of type alt.
-
Out: A page telling if the operations went well. If everything went all
right a line starting with "1" is returned otherwise a line starting with
"0".
makeWritten.perl
-
Usage: To create a new written QuestionPage page html file on the server,
the file is created using data stored in a .data file previously created
by calling makeData.perl
-
Variables: subject, title - the name of the QuestionPage
-
Reads file: title.data in the PageData
directory given by the subject.
-
Writes file: title.html in the QuestionPages
directory.
-
Uses file: written.js which contain the HTML/JavaScript code
that is common to all QuestionPages of type alt.
-
Out: A page telling if the operations went well. If everything went all
right a line starting with "1" is returned otherwise a line starting with
"0.
rmPage.perl
-
Usage: To remove the three file that are associated with a QuestionPage.
-
Variables: subject, page - the name of the QuestionPage.
-
Reads file: none
-
Writes file: Deletes the files page.data, page.answer and page.html.
The files are located in the directories PageData,
StudentAnswers
and QuestionPages.
mkCourse.perl
The script mkCourse.perl is built up as a transaction, which means
that if something goes bad in the creation process then everything created
is removed to put the server in the state that is was before the creation
started. That is, the final result is that either everything is performed
and carried out as it should or nothing is changed on the server.
-
Usage: Creation of new courses on the server.
-
Variables: subject, username - subject is the name of the new course,
username is the user name of the teacher that creates it.
-
Reads file: none
-
Creates directories: subject in WWW/ and Courses/; QuestionPages
in WWW/subject/; StudentAnswers and PageData in Courses/subject/.
-
Writes file: courseInfo, students (an empty file) in the
recently created directory Courses/subject/.
-
Out: Success/failure of the creation of direcories/files.
rmCourse.perl
-
Usage: Deletion of courses on the server.
-
Variables: subject - subject is the name of the course.
-
Reads file: none
-
Deletes directories: subject and all its sub directories in WWW/
and Courses/.
-
Writes file: none.
-
Out: Success/failure of the deletion of direcories/files.
addCourseAccess.perl
-
Usage: Granting of course access for teachers to courses.
-
Variables: subject, username - subject is the name
of the course that should be added to the teacher with username access
list.
-
Reads file: username.acc in the Courses/Users/ directory
and courseInfo in the Course/subject/ directory.
-
Writes file: The same files as it read but modified.
-
Out: Success/failure of the accesses removal.
removeCourseAccess.perl
-
Usage: Removal of course access for teachers to courses.
-
Variables: courses, users - courses are the names
of the courses that should be removed from the teachers with user names
users access lists.
-
Reads file: user1.acc, user2.acc ...etc. in the Courses/Users/
directory and courseInfo in the Course/course1/, Course/course2/
...etc. directories.
-
Writes file: The same files as it reads.
-
Out: Success/failure of the accesses removal.
The variable courses should look like this:
course1#course2#course3#etc.
The variable users should look like this:
username1#username2#username3#etc.