|
Home About
FAQs
General Admin Assist Student
Docs
Admin Assistant
CGI
Admin Assistant Download Form Student
Packages
AdminInterface Assignments AssistantInterface Form Interface Record Roster StudentInterface SystemVariables Teams VincentFile VincentLog |
|
0 #!/usr/bin/perl -w -I /l/vincent3/modules/
1 #Copyright 2000 Matt Jadud
2 #This program is free software; you can redistribute it and/or
3 #modify it under the terms of the GNU General Public License
4 #as published by the Free Software Foundation; either version 2
5 #of the License, or (at your option) any later version.
6 #
7 #This program is distributed in the hope that it will be useful,
8 #but WITHOUT ANY WARRANTY; without even the implied warranty of
9 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 #GNU General Public License for more details.
11 #
12 #You should have received a copy of the GNU General Public License
13 #along with this program; if not, write to the Free Software
14 #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15
16 #Turn debugging on or off.
17 $DEBUG = 1;
18
19 #Perl libraries that will come in handy. Get these out of the way...
20 use CGI qw(:standard); # import shortcuts
21 use Fcntl qw(:flock); # imports LOCK_EX, LOCK_SH, LOCK_NB
22
23 use SystemVariables;
24 use Record;
25 use Form;
26 use Assignments;
27 use StudentInterface;
28 use AdminInterface;
29 use AssistantInterface;
30 use VincentLog;
31 use File::Copy;
32
33 my ( $username,
34 $query,
35 $Dispatch,
36 $dispatched,
37 $choice
38 );
39
40 #Grab the CGI Query
41 $query = CGI->new();
42 #Print the header to start a good dialog
43 # between the server and client browser
44 print header;
45 #The username is stored in the environment
46 $username = $ENV{REMOTE_USER};
47
48 #Dispatch table
49 %Dispatch = ("FORMSTEP1" => &createFormOne,
50 "FORMSTEP2" => &createFormTwo,
51 "WRITEFORM" => &writeForm,
52 "do" => &doForm,
53 "HANDINFORM" => &handinForm,
54 "ANSWERSELECTION" => &answerSelection,
55 "DISPLAYQUESTIONS" => &displayQuestions,
56 "PROCESSFORMGRADES" => &processFormGrades);
57
58 $dispatched = 0;
59
60 #foreach $k (sort {$a cmp $b} $query->param()) {
61 foreach $k ($query->param()) {
62
63 if(!$dispatched) {
64 dispatcher($k, %Dispatch);
65 }
66 }
67
68 if(!$dispatched) {
69 Form::mainMenu($username);
70 }
71
72 sub processFormGrades {
73
74 my($student,
75 $question,
76 $grade,
77 @users,
78 %Grade,
79 $sysID,
80 $numquestions,
81 $sum,
82 $i);
83
84
85 @users = Record::getAllStudentUsernames();
86 $numquestions = $query->param("NUMBEROFQUESTIONS");
87 $sysID = $query->param("SYSID");
88
89 foreach $student (@users) {
90 $sum = 0;
91 $submitgrade = 0;
92
93 #Sum up the questions that are defined;
94 # if any scores are defined (even zeros),
95 # submit that score to the student's record.
96 for($i=0;$i<$numquestions;$i++) {
97
98 if(defined($query->param($student . $i))
99 && ($query->param($student . $i) =~ /d+/) ) {
100 $sum += $query->param($student . $i);
101 $submitgrade = 1;
102 }
103
104 }
105
106 if($submitgrade) {
107 SystemVariables::DEBUG("form.cgi", "Submitting grade for $student to $sum");
108 $Grade{$sysID . "_GRADE"} = $sum;
109 Record::updateStudentRecord($student, %Grade);
110 }
111
112 }
113
114 #Branch the linkback script based on the class
115 # of the user.
116 if (Record::isAdministrator($username)
117 || Record::isGod($username)) {
118 AdminInterface::mainMenu($username);
119 } elsif (Record::isAssistant($username)) {
120 AssistantInterface::mainMenu($username);
121 } else {
122 StudentInterface::mainMenu($username);
123 }
124
125
126 }
127
128 sub displayQuestions {
129
130 my($form,
131 $sectionbool,
132 $section,
133 @questions,
134 $i,
135 $numquestions);
136
137 VincentLog::clickLog("FORMS", "Displayed questions.");
138
139 Form::mainMenu($username,
140 "displayQuestions",
141 $query);
142
143 }
144
145
146 sub answerSelection {
147
148 my($form,
149 $sectionbool,
150 $section);
151
152 $form = $query->param("_formname");
153 $sectionbool = $query->param("_sectionnumberboolean");
154 $section = $query->param("_sectionnumber");
155
156 VincentLog::clickLog("FORMS", "Selecting answers to view from $form.");
157
158 Form::mainMenu($username,
159 "answerSelection",
160 $form,
161 $sectionbool,
162 $section);
163 }
164
165 sub handinForm {
166
167 my($configpath,
168 $form,
169 $key,
170 $val,
171 $tempfile,
172 $index,
173 $sysfilename,
174 $path,
175 $ontime,
176 $slipused,
177 $answer);
178
179 $form = $query->param("_ASSIGNID");
180 chomp $form;
181
182 $configpath = SystemVariables::getCourseConfigPath();
183 $data = Assignments::getAssignmentData($form);
184 $username = $ENV{REMOTE_USER};
185
186 foreach $key (keys %{$data}) {
187 $val = $$data{$key};
188 chomp $val;
189 #$val =~ s/r//g;
190 $val =~ s/015//;
191 $val =~ s/012//g;
192 $$data{$key} = $val;
193 #print STDERR "Stripping $val\n";
194 }
195
196 #print STDERR "Writing form " . $$data{"_DESCRIPTION"\} . " for $username n";
197
198 $tempfile = "/tmp/$username" . $$;
199 open(TEMPFILE, ">$tempfile");
200
201 $index = 0;
202 while(defined($$data{"QUESTION$index"})) {
203 SystemVariables::DEBUG("form.cgi", "Writing " . $$data{"QUESTION$index"});
204
205 #Print questions and answers to the tempfile
206 print TEMPFILE "##QUESTION$index##n";
207 print TEMPFILE $$data{"QUESTION$index"}, "n";
208 print TEMPFILE "##ANSWER$index##n";
209
210 if($$data{"QUESTION$index" . "TYPE"} =~ /MANY/) {
211
212 $found = 0;
213 for($i=0;$i<$$data{"QUESTION$index" . "ANSWERFIELDS"};$i++) {
214
215 SystemVariables::DEBUG("form.cgi", "Considering " . $$data{"QUESTION$index" . "ANSWER$i"});
216
217 if(defined( $query->param("ANSWER$index-$i") ) ) {
218
219 SystemVariables::DEBUG("form.cgi", "Found one at " . $$data{"QUESTION$index" . "ANSWER$i"});
220
221 if($found == 0) {
222 #$answer = $query->param("ANSWER$index-$i");
223 $answer = $$data{"QUESTION$index" . "ANSWER$i"};
224 $found = 1;
225 } else {
226 #$answer .= "\n" . $query->param("ANSWER$index-$i");
227 $answer .= "n" . $$data{"QUESTION$index" . "ANSWER$i"};
228 }
229 }
230 }
231 } elsif ($$data{"QUESTION$index" . "TYPE"} =~ /ONE/) {
232
233 SystemVariables::DEBUG("form.cgi", "Its a onner...");
234 $answer = $$data{"QUESTION$index" . "ANSWER" . $query->param("ANSWER$index")};
235
236 } elsif ($$data{"QUESTION$index" . "TYPE"} =~ /URL/) {
237
238 my($url);
239 $url = $query->param("ANSWER$index");
240 $answer = "<A HREF="$url">$url</A>";
241
242 } else {
243
244 $answer = $query->param("ANSWER$index");
245 }
246
247 #The only offensive thing they could have here is
248 # two ##'s in a row. Everything else should be legal...
249 $answer =~ s/##//g;
250 SystemVariables::DEBUG("form.cgi", "Answer is... $answer");
251 print TEMPFILE $answer, "n";
252
253 $index++;
254 }
255
256 close(TEMPFILE);
257
258 $sysfilename = Record::getNextFilename($username);
259 $path = SystemVariables::getStudentRecordPath($username);
260
261 copy($tempfile, $path . $sysfilename);
262
263 SystemVariables::DEBUG("form.cgi", "Checking assignment $form ontime.");
264
265 #print STDERR "Checking assignment $form ontime.\n";
266
267 ($ontime, $slipused) = Assignments::checkAssignmentOnTime($form);
268
269
270 VincentLog::clickLog("FORMS", "Handing in " . $$data{"_DESCRIPTION"} . ". Ontime: $ontime " . "Slip: $slipused");
271
272 $assignid = $$data{"_ASSIGNID"};
273 $desc = $$data{"_DESCRIPTION"};
274
275 chomp $assignid;
276 chomp $desc;
277
278 $assignid =~ s/r//g;
279 $assignid =~ s/n//g;
280 $desc =~ s/r//g;
281 $desc =~ s/n//g;
282
283 #print STDERR "$assignid and $desc\n";
284
285 VincentLog::fileLog($username,
286 $$data{"_ASSIGNID"},
287 $sysfilename,
288 $$data{"_DESCRIPTION"},
289 $ontime,
290 $slipused);
291
292
293
294 unlink($tempfile);
295
296
297 #Branch the linkback script based on the class
298 # of the user.
299 if (Record::isAssistant($username)) {
300 AssistantInterface::mainMenu($username);
301 } elsif (Record::isAdministrator($username)
302 || Record::isGod($username)) {
303
304 AdminInterface::mainMenu($username);
305 } else {
306 StudentInterface::mainMenu($username);
307 }
308
309 }
310
311 sub doForm {
312
313 VincentLog::clickLog("FORMS", "Doing form " . $query->param("do"));
314
315 Form::mainMenu("do", $query->param("do"));
316
317 }
318
319
320 sub createFormOne {
321
322 Form::mainMenu("createFormOne", $query);
323 }
324
325 sub createFormTwo {
326 Form::mainMenu("createFormTwo", $query);
327 }
328
329 sub writeForm {
330
331 my ($configpath,
332 $nextID,
333 $key,
334 $val,
335 %Form);
336
337 $nextID = Form::getNextFormID();
338 $configpath = SystemVariables::getCourseConfigPath();
339 print "<STRONG>$nextID</STRONG><HR>";
340
341 foreach $key ($query->param()) {
342 if($key =~ /^(_|QUESTION)/) {
343 if(defined($query->param($key))) {
344
345 #Clean up the input.
346 $val = $query->param($key);
347 $val =~ s/_//g;
348 $val =~ s/n//g;
349 $val =~ s/|//g;
350 $val =~ s/#//g;
351 $val =~ s/r//g;
352 SystemVariables::DEBUG("form.cgi", "$key :: $val<P>");
353
354 if(length($val) >= 1) {
355 $Form{$key} = $val;
356 }
357
358 }
359 }
360 }
361
362 $Form{"_SYSID"} = $nextID;
363
364 #This calls writeAssignment (to put it in the
365 # config directory) and also updates
366 # all student records.
367 Assignments::updateAssignment($nextID, %Form);
368
369 Form::mainMenu();
370
371 }
372
373
374
375 sub dispatcher {
376
377 my( $dispatch_id,
378 $dispatch_hash
379 );
380
381 $dispatch_id = $_[0];
382 chomp $dispatch_id;
383
384 $dispatch_hash = $_[1];
385
386 SystemVariables::DEBUG("form.cgi", "DispatchID: ", $dispatch_id);
387
388 #Pass on the ID - this is the key to the
389 # $query hash!
390 if($$dispatch_hash{$dispatch_id}) {
391
392 SystemVariables::DEBUG("form.cgi", "Dispatch exists!");
393 $dispatched = 1;
394 $$dispatch_hash{$dispatch_id}->($dispatch_id);
395 }
396 }
397
398
399 sub useDebugging())'>DEBUG { if(SystemVariables::useDebugging()) { print "form.cgi: ", @_, "n<P>"; } }
400 #sub DEBUG { if(1) { print "form.cgi: ", @_, "\n<P>"; } }
401
402
|
|
Last update: 1/6/01; 9:32:31 AM |