[system] / trunk / webwork / system / cgi / cgi-scripts / welcomeAction.pl Repository:
ViewVC logotype

Diff of /trunk/webwork/system/cgi/cgi-scripts/welcomeAction.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 154 Revision 155
1#!/usr/local/bin/webwork-perl 1#!/usr/local/bin/webwork-perl
2
3 2
4################################################################ 3################################################################
5# Copyright @1995-1999 by Michael E. Gage, Arnold K. Pizer and 4# Copyright @1995-1999 by Michael E. Gage, Arnold K. Pizer and
6# WeBWorK at the University of Rochester. All rights reserved. 5# WeBWorK at the University of Rochester. All rights reserved.
7################################################################ 6################################################################
8 7
9my $debugON=0; ## set this to 1 to save debugging information for errors in hardcopy output 8my $debugON=0;
10 9
11use lib '.'; use webworkInit; # WeBWorKInitLine 10use lib '.'; use webworkInit; # WeBWorKInitLine
11
12require 5.001; 12require 5.001;
13
14$/ ="\n";
15
16use strict; 13use strict;
17use Global; 14use Global;
18use Auth; 15use Auth;
19use CGI qw(:standard); 16use CGI qw(:standard);
20use Net::SMTP; 17use Net::SMTP;
21use Safe; 18use Safe;
22 19
23
24use PGtranslator; 20use PGtranslator;
25#use sigtrap; 21use vars qw($modules_to_evaluate $extra_packages_to_be_loaded);
22
23$/ ="\n";
24
26BEGIN { 25BEGIN {
27 # set to 1 to enable timing_log 26 # set to 1 to enable timing_log
28 # (contains information about time taken by scripts to run) 27 # (contains information about time taken by scripts to run)
29 $main::logTimingData = 0; 28 $main::logTimingData = 0;
30 29
33 use Benchmark; 32 use Benchmark;
34 $main::beginTime = new Benchmark; 33 $main::beginTime = new Benchmark;
35 } 34 }
36 # end Timing code 35 # end Timing code
37 36
38# ## Setting these time out comstants to zeros removes the time constraint completely. (zero = infinity :=) ) 37 # Setting these time out comstants to zeros removes the time constraint completely. (zero = infinity :=) )
39 $main::TIME_OUT_CONSTANT = 60; # one minute wait for on screen problems 38 $main::TIME_OUT_CONSTANT = 60; # one minute wait for on screen problems
40# $main::DOWNLOAD_TIME_OUT_CONSTANT = 300; # give it five minutes
41 $main::CLASS_DOWNLOAD_TIME_OUT_CONSTANT = 1200; #twenty minutes 39 $main::CLASS_DOWNLOAD_TIME_OUT_CONSTANT = 1200; #twenty minutes
42# $main::DOWNLOAD_NICE = 2;
43 $main::CLASS_DOWNLOAD_NICE = 5; # higher numbers indicated lower priorities 40 $main::CLASS_DOWNLOAD_NICE = 5; # higher numbers indicated lower priorities
41 # $main::DOWNLOAD_TIME_OUT_CONSTANT = 300; # give it five minutes
42 # $main::DOWNLOAD_NICE = 2;
44 43
45# ## ATTENTION: The handlers PG_floating_point_exception_handler and PG_warnings_handler 44 # ATTENTION: The handlers PG_floating_point_exception_handler and PG_warnings_handler
46# ## have to be installed after CGI::Carp is called since it also 45 # have to be installed after CGI::Carp is called since it also
47# ## modifes the die and warn labels. Finding the right warning mechanism using these two 46 # modifes the die and warn labels. Finding the right warning mechanism using these two
48# ## methods bears further investigation 47 # methods bears further investigation
49# ## They are defined in Global.pm 48 # They are defined in Global.pm
50 $SIG{'FPE'} = \&Global::PG_floating_point_exception_handler; 49 $SIG{'FPE'} = \&Global::PG_floating_point_exception_handler;
51 $SIG{__WARN__}=\&Global::PG_warnings_handler; 50 $SIG{__WARN__}=\&Global::PG_warnings_handler;
52 $SIG{'TERM'} = sub {die '[',scalar(localtime),"] Caught a SIGTERM, Error: $! stopped at $0\n"; }; 51 $SIG{'TERM'} = sub {die '[',scalar(localtime),"] Caught a SIGTERM, Error: $! stopped at $0\n"; };
53 $SIG{'PIPE'} = sub {$main::SIGPIPE = 1, die '[',scalar(localtime),"] Caught a SIGPIPE, Error: $! stopped at $0\n"; }; 52 $SIG{'PIPE'} = sub {$main::SIGPIPE = 1, die '[',scalar(localtime),"] Caught a SIGPIPE, Error: $! stopped at $0\n"; };
54 $SIG{ALRM} = sub { $main::SIG_TIME_OUT = 1; exit(0) }; 53 $SIG{ALRM} = sub { $main::SIG_TIME_OUT = 1; exit(0) };
55 54
56 alarm($main::TIME_OUT_CONSTANT); 55 alarm($main::TIME_OUT_CONSTANT);
57# By explicitly catching the signals and dieing one forces the execution of the END statements which clean up the files. 56 # By explicitly catching the signals and dieing one forces the execution of the END statements which clean up the files.
58#
59}; 57};
60 58
61use vars qw ($modules_to_evaluate $extra_packages_to_be_loaded 59################################################################################
62 ); 60# main #########################################################################
61################################################################################
63 62
64&CGI::ReadParse; 63&CGI::ReadParse;
65my %inputs=%main::in; 64my %inputs=%main::in;
66
67my $query = $main::in{CGI}; 65my $query = $main::in{CGI};
68 66
69# verify that the rest of the information has been received 67# verify that the rest of the information has been received
70my $Course = $inputs{'course'}; 68my $Course = $inputs{'course'};
71my $User = $inputs{'user'}; 69my $User = $inputs{'user'};
72 70
73#my $psvn = $inputs{'probSetKey'};
74
75my @local_psvns = $query -> param('local_psvns'); 71my @local_psvns = $query -> param('local_psvns');
76my $psvn = $local_psvns[0]; ## get the first one for doing problem sets 72my $psvn = $local_psvns[0]; # get the first one for doing problem sets
77$inputs{'probSetKey'} = $psvn; ## only used by htmlBOTTOM 73$inputs{'probSetKey'} = $psvn; # only used by htmlBOTTOM
78my $Session_key = $inputs{'key'}; 74my $Session_key = $inputs{'key'};
79 75
80
81&Global::getCourseEnvironment($Course); 76&Global::getCourseEnvironment($Course);
82 77
83my $scriptDirectory = getWebworkScriptDirectory(); #$Global::scriptDirectory; 78my $scriptDirectory = getWebworkScriptDirectory();
84my $databaseDirectory = getCourseDatabaseDirectory(); #$Global::databaseDirectory; 79my $databaseDirectory = getCourseDatabaseDirectory();
85my $courseScriptsDirectory = getCourseScriptsDirectory(); #$Global::courseScriptsDirectory; 80my $courseScriptsDirectory = getCourseScriptsDirectory();
86my $templateDirectory = getCourseTemplateDirectory(); #$Global::templateDirectory; 81my $templateDirectory = getCourseTemplateDirectory();
87
88# this is globally defined for the file, since it is needed for cleanup in END
89my $tempDirectory = getCourseTempDirectory(); 82my $tempDirectory = getCourseTempDirectory();
90 83
91eval{require "${courseScriptsDirectory}$Global::displayMacros_pl";} ; 84eval{require "${courseScriptsDirectory}$Global::displayMacros_pl";};
92eval{require "${scriptDirectory}$Global::DBglue_pl";}; 85eval{require "${scriptDirectory}$Global::DBglue_pl";};
93eval{require "${scriptDirectory}$Global::classlist_DBglue_pl";}; 86eval{require "${scriptDirectory}$Global::classlist_DBglue_pl";};
94eval{require "${scriptDirectory}$Global::HTMLglue_pl";}; 87eval{require "${scriptDirectory}$Global::HTMLglue_pl";};
95eval{require "${scriptDirectory}$Global::FILE_pl";} ; 88eval{require "${scriptDirectory}$Global::FILE_pl";};
96 89
97
98
99####################################################################
100# load the modules to be used in PGtranslator 90# load the modules to be used in PGtranslator
101
102require "${courseScriptsDirectory}PG_module_list.pl" or 91require "${courseScriptsDirectory}PG_module_list.pl"
103 wwerror($0, "Can't read ${courseScriptsDirectory}PG_module_list.pl"); 92 or wwerror($0, "Can't read ${courseScriptsDirectory}PG_module_list.pl");
104####################################################################
105 93
106my $keyFile = &Global::getCourseKeyFile($Course); 94my $keyFile = &Global::getCourseKeyFile($Course);
107my $permissionsFile = &getCoursePermissionsFile($Course); 95my $permissionsFile = &getCoursePermissionsFile($Course);
108 96
109## check to see if prob set has been selected ## 97# check to see if prob set has been selected
110verifyInput();
111
112##############################################
113sub verifyInput {
114
115 if(!defined($psvn) || $psvn eq "") { 98if(not defined($psvn) or $psvn eq "") {
116 &selectionError; # The calling script did not specify a problem set. 99 selectionError();
117 #die "Content-type: text/html\n\nThe calling script did not specify a problem set."; 100 exit;
118 exit();
119 }
120} 101}
121 102
122# log access 103# log access
123 &Global::log_info('', query_string); 104&Global::log_info('', query_string);
124
125 105
126&verify_key($inputs{'user'}, $Session_key, $keyFile, $Course); 106&verify_key($inputs{'user'}, $Session_key, $keyFile, $Course);
127
128my $permissions = &get_permissions($User,$permissionsFile); 107my $permissions = &get_permissions($User,$permissionsFile);
129 108
130&attachProbSetRecord($psvn); 109&attachProbSetRecord($psvn);
131my $login_name_for_psvn = &getStudentLogin($psvn); 110my $login_name_for_psvn = &getStudentLogin($psvn);
132attachCLRecord($login_name_for_psvn); 111attachCLRecord($login_name_for_psvn);
133 112
134my $setNumber=&getSetNumber($psvn); 113my $setNumber=&getSetNumber($psvn);
135$setNumber = $inputs{'setNo'} if defined $inputs{'setNo'}; ## script called from profChangeDates.pl 114$setNumber = $inputs{'setNo'} if defined $inputs{'setNo'}; ## script called from profChangeDates.pl
136 115
137# keep strict happy 116# keep strict happy -sh
138my $tempTexFileBaseName; 117my $tempTexFileBaseName;
139 118
140###### check to see that it is after the open date 119# check to see that it is after the open date
141my ($currentTime,$odts,$ddts,$remainingTime, $TimeString); 120my ($currentTime,$odts,$ddts,$remainingTime, $TimeString);
142$currentTime = time; 121$currentTime = time;
143$odts=&getOpenDate($psvn); 122$odts=&getOpenDate($psvn);
144$ddts=&getDueDate($psvn); 123$ddts=&getDueDate($psvn);
145$remainingTime=$ddts-$currentTime; 124$remainingTime=$ddts-$currentTime;
164 print &htmlBOTTOM("downloadPS.pl", \%inputs); 143 print &htmlBOTTOM("downloadPS.pl", \%inputs);
165 exit(0); 144 exit(0);
166 } 145 }
167} 146}
168 147
169my $texFile = "${login_name_for_psvn}.tempTex-CGIscript";
170my $save_errors=''; 148my $save_errors = '';
171 149
172if ($action eq 'Do problem set' or $action eq 'Do_problem_set') {displayProbSet();} 150if ($action eq 'Do problem set' or $action eq 'Do_problem_set') { displayProbSet(); }
173#elsif ($action eq 'Get hard copy' or $action eq 'Get_hard_copy') {downloadIndividualSet();}
174elsif ($action eq 'Get hard copy' or $action eq 'Get_hard_copy') {downloadAllSets();} 151elsif ($action eq 'Get hard copy' or $action eq 'Get_hard_copy') { downloadAllSets(); }
175elsif ($action eq 'Get_all_copies') {downloadAllSets();} 152elsif ($action eq 'Get_all_copies') { downloadAllSets(); }
176else {wwerror($0, "Unknown action: $action");} 153else { wwerror($0, "Unknown action: $action"); }
177
178 154
179# begin Timing code 155# begin Timing code
180# my $endTime = new Benchmark; 156#my $endTime = new Benchmark;
181# &Global::logTimingInfo($main::beginTime,$endTime,$0,$Course,$User); 157#&Global::logTimingInfo($main::beginTime,$endTime,$0,$Course,$User);
182# end Timing code 158# end Timing code
183 159
184 exit; 160exit;
185#############################################
186 161
162################################################################################
163# displayProbSet ###############################################################
164################################################################################
165
187sub displayProbSet { 166sub displayProbSet
167{
188 my $studentName=&CL_getStudentName($login_name_for_psvn); 168 my $studentName=&CL_getStudentName($login_name_for_psvn);
189 my $probHeaderFileName = &getProbHeaderFileName($psvn); 169 my $probHeaderFileName = &getProbHeaderFileName($psvn);
190 170
171 sub numerical { $a <=> $b};
191 my @problems=sort numerical &getAllProblemsForProbSetRecord($psvn); 172 my @problems=sort numerical &getAllProblemsForProbSetRecord($psvn);
192 sub numerical { $a <=> $b}; 173 my $numberOfProblems = @problems;
193
194 my $numberOfProblems=0;
195 my $prob;
196 foreach $prob (@problems) {$numberOfProblems++;}
197
198 174
199 print &probSet_htmlTOP("Problem Set $setNumber from $inputs{'course'} for $studentName"); 175 print &probSet_htmlTOP("Problem Set $setNumber from $inputs{'course'} for $studentName");
200 #see subroutines at the bottom of this file 176 #see subroutines at the bottom of this file
201 #this allows the use of a small gif for the webwork logo 177 #this allows the use of a small gif for the webwork logo
202 #and takes up less screen real estate. 178 #and takes up less screen real estate.
206 print <<"ENDOFHTML"; 182 print <<"ENDOFHTML";
207<TABLE BORDER=1> 183<TABLE BORDER=1>
208 <TR> 184 <TR>
209 <!-- Row 1 Column 1 --> 185 <!-- Row 1 Column 1 -->
210 <TD> 186 <TD>
211
212Select one of the $numberOfProblems problems to try: 187Select one of the $numberOfProblems problems to try:
213<FORM METHOD=POST ACTION="$Global::processProblem_CGI"> 188<FORM METHOD=POST ACTION="$Global::processProblem_CGI">
214<INPUT TYPE=HIDDEN NAME=probSetKey VALUE=$psvn> 189<INPUT TYPE=HIDDEN NAME=probSetKey VALUE=$psvn>
215<P> 190<P>
216<SELECT NAME=probNum SIZE=11> 191<SELECT NAME=probNum SIZE=11>
217ENDOFHTML 192ENDOFHTML
218 193
219 my ($problem,$problemAttempted, $problemStatus,$longProblemStatus); 194 my ($problemAttempted, $problemStatus, $longProblemStatus);
220 foreach $problem(@problems) { 195 foreach my $problem (@problems) {
221 $problemStatus = getProblemStatus($problem,$psvn); 196 $problemStatus = getProblemStatus($problem,$psvn);
222 $problemAttempted = getProblemAttempted($problem,$psvn); 197 $problemAttempted = getProblemAttempted($problem,$psvn);
223 198
224 if (!$problemAttempted) { 199 if (!$problemAttempted) {
225 $longProblemStatus = ''; # default value 200 $longProblemStatus = '';
226 } elsif ($problemStatus >= 0 and $problemStatus <=1 ) { 201 } elsif ($problemStatus >= 0 and $problemStatus <=1 ) {
227 my $percentCorr = int(100*$problemStatus+.5); 202 my $percentCorr = int(100*$problemStatus+.5);
228 $longProblemStatus = "${percentCorr}\% correct" 203 $longProblemStatus = "${percentCorr}\% correct"
229 } else { 204 } else {
230 $longProblemStatus = 'unknown status'; # default value 205 $longProblemStatus = 'unknown status'; # default value
231 } 206 }
232 print "<OPTION VALUE=$problem>Problem $problem -- $longProblemStatus </OPTION>\n"; 207 print "<OPTION VALUE=\"$problem\">Problem $problem -- $longProblemStatus</OPTION>\n";
233 } 208 }
234 209
235 ## nice note to warn if there's less than one day left to complete problem set 210 # nice note to warn if there's less than one day left to complete problem set
236 if ($remainingTime<86400 && $remainingTime>0) { 211 if ($remainingTime < 86400 and $remainingTime > 0) {
237 $TimeString = "<BR><RM>Note: you have less than one day left 212 $TimeString = "<BR><EM>Note: you have less than one day left to complete this problem set</EM>";
238 to complete this problem set</EM>";
239 }
240 else { 213 } else {
241 $TimeString = ""; 214 $TimeString = "";
242 } 215 }
243 216
244 print <<"ENDOFHTML"; 217 print "</SELECT><BR>";
245</SELECT>
246<BR>
247ENDOFHTML
248
249 218
250 my $practiceUser = $Global::practiceUser; 219 my $practiceUser = $Global::practiceUser;
251 if (($currentTime > $ddts) or ($User =~ /^$practiceUser/)) { 220 if (($currentTime > $ddts) or ($User =~ /^$practiceUser/)) {
252 print q!<INPUT type="checkbox" name="show_old_answers" value=1> Show my old answers<BR>!; 221 print '<INPUT type="checkbox" name="show_old_answers" value="1"> Show my old answers<BR>';
253 } 222 }
254 else { 223 else {
255 print q!<INPUT type="checkbox" name="show_old_answers" checked value=1> Show my old answers<BR>!; 224 print '<INPUT type="checkbox" name="show_old_answers" value="1" checked> Show my old answers<BR>';
256 } 225 }
257 226
258 print &sessionKeyInputs(\%inputs); 227 print &sessionKeyInputs(\%inputs);
228
259 my $mode = $inputs{'Mode'}; 229 my $mode = $inputs{'Mode'};
260 $mode = $Global::htmlModeDefault unless ($mode); 230 $mode = $Global::htmlModeDefault unless ($mode);
261 &displaySelectModeLine($mode); ## displays mode select buttons 231 &displaySelectModeLine($mode); ## displays mode select buttons
262 ## the sub displaySelectModeLine is in
263 ## "${courseScriptsDirectory}$Global::displayMacros_pl" 232 ## displaySelectModeLine() is in "${courseScriptsDirectory}$Global::displayMacros_pl"
264 print <<"ENDOFHTML"; 233 print <<"ENDOFHTML";
265<BR> 234<BR>
266<INPUT TYPE=SUBMIT VALUE="Get Problem"> 235<INPUT TYPE=SUBMIT VALUE="Get Problem">
267$TimeString 236$TimeString
268
269</FORM> 237</FORM>
270
271ENDOFHTML 238ENDOFHTML
272 239
273 print "<FORM METHOD=POST ACTION=\"${Global::cgiWebworkURL}welcome.pl\"><P>"; 240 print "<FORM METHOD=POST ACTION=\"${Global::cgiWebworkURL}welcome.pl\"><P>";
274 print &sessionKeyInputs(\%inputs); 241 print &sessionKeyInputs(\%inputs);
275 242
276 print <<"ENDOFHTML"; 243 print <<"ENDOFHTML";
277<INPUT TYPE=HIDDEN NAME="probSetKey" VALUE=$psvn> 244<INPUT TYPE=HIDDEN NAME="probSetKey" VALUE=$psvn>
278<INPUT TYPE=SUBMIT VALUE="Problem Sets"> 245<INPUT TYPE=SUBMIT VALUE="Problem Sets">
279</FORM> 246</FORM>
280
281
282 </TD> 247 </TD>
283 <!-- Row 1 Column 2 --> 248 <!-- Row 1 Column 2 -->
284 <TD> 249 <TD>
285ENDOFHTML 250ENDOFHTML
286 251
287 252
288## process problem and save @printlines 253 # process problem and save @printlines
289 my $probHeader = $Global::PROB_HEADER; # default value 254 my $probHeader = $Global::PROB_HEADER; # default value
290
291 if ( (defined($probHeaderFileName)) and ($probHeaderFileName =~ /\S/)) { 255 if ((defined($probHeaderFileName)) and ($probHeaderFileName =~ /\S/)) {
292 $probHeader = $probHeaderFileName; 256 $probHeader = $probHeaderFileName;
293 } 257 }
258
294 ## use $probHeader as default unless $probHeaderFileName is defined 259 # use $probHeader as default unless $probHeaderFileName is defined in the set definition file
295 ## in the set definition file
296 my $source; 260 my $source;
297 if (-e "${templateDirectory}$probHeader" ) { 261 if (-e "${templateDirectory}$probHeader") {
298 unless (-r "${templateDirectory}$probHeader") { 262 unless (-r "${templateDirectory}$probHeader") {
299 wwerror($0, "Can't read ${templateDirectory}$probHeader"); 263 wwerror($0, "Can't read ${templateDirectory}$probHeader");
300 } 264 }
301 open(PROB,"<${templateDirectory}$probHeader"); 265 open(PROB,"<${templateDirectory}$probHeader");
302 $source = join("",<PROB>); 266 $source = join("",<PROB>);
303 close(PROB); 267 close(PROB);
304 } 268 }
305 my %envir=defineProblemEnvir($mode,0,$psvn,$Course);
306 my $pt = new PGtranslator; #pt stands for problem translator;
307 $pt->environment(\%envir);
308 $pt->initialize();
309 $pt-> set_mask();
310 $pt->source_string($source);
311 $pt -> unrestricted_load("${courseScriptsDirectory}PG.pl");
312 $pt -> unrestricted_load("${courseScriptsDirectory}dangerousMacros.pl");
313 $pt ->translate();
314 my $PG_PROBLEM_TEXT_REF = $pt->ra_text();
315 my $PG_HEADER_TEXT_REF = $pt->r_header;#\$PG_HEADER_TEXT;
316 my $PG_ANSWER_HASH_REF = $pt->rh_correct_answers;
317 my $PG_FLAGS_REF =$pt ->rh_flags;
318
319
320
321 my @printlines;
322 if($mode eq "HTML" || $mode eq 'HTML_tth') {
323 @printlines=@{$pt->ra_text()};
324 }
325 elsif ($mode eq 'Latex2HTML') {
326 @printlines = &createDisplayedInsert($setNumber,
327 $probHeader,$psvn,$Course,$pt->ra_text());
328 }
329 print @printlines;
330 print <<"ENDOFHTML";
331 </TD>
332 </TR>
333</TABLE>
334ENDOFHTML
335print &htmlBOTTOM('welcomeAction.pl', \%inputs,'probSetHelp.html');
336exit;
337} ## end of problem selection form and end of sub displayProbSet
338
339####################
340## subroutines
341####################
342
343$/ = "\n";
344sub createTexSource {
345 my $psvn = shift;
346
347 # check that the psvn corresponds to the user and that it is after the open
348 # date. This should only fail if someone is trying to break into WeBWorK.
349 269
350 &attachProbSetRecord($psvn); 270 # translate the problem header file
351 $login_name_for_psvn = &getStudentLogin($psvn);
352 attachCLRecord($login_name_for_psvn);
353
354 if ( ( ( $User ne &getStudentLogin($psvn)) ||($currentTime < $odts) )
355 and ($permissions != $Global::instructor_permissions)
356 and ($permissions != $Global::TA_permissions)
357 ) {
358 &hackerError;
359 exit;
360 }
361
362 my $probSetHeader = $Global::SET_HEADER;
363
364 my $setHeaderFileName = &getSetHeaderFileName($psvn);
365
366 my $answersRequestedQ = 0;
367 $answersRequestedQ= $inputs{'ShowAns'} if defined($inputs{'ShowAns'});
368
369 my $adts=&getAnswerDate($psvn);
370 my $displayCorrectAnswersQ = 0; #initialize
371 $displayCorrectAnswersQ =1 if $answersRequestedQ && ($currentTime > $adts);
372 $displayCorrectAnswersQ =1 if $answersRequestedQ && ($permissions == $Global::instructor_permissions);
373
374
375# chdir "$tempDirectory";
376# umask(022);
377
378 my $texSource ='';
379
380# open(OUTPUT, ">${tempDirectory}${texFile}${psvn}.tex")
381#|| wwerror("Can't create $tempDirectory${texFile}$psvn.tex\n");
382
383
384
385 print STDERR "%%Creating a tex version of set $setNumber<BR>\n" if $debugON;
386 print STDERR "%%For", &CL_getStudentName($login_name_for_psvn), "psvn=$psvn<BR>\n" if $debugON;
387
388
389 # input TeX preamble
390# print OUTPUT &texInput($Global::TEX_SET_PREAMBLE);
391 $texSource = &texInput($Global::TEX_SET_PREAMBLE);
392
393 # print TeX Header
394# print OUTPUT &texInput($Global::TEX_SET_HEADER);
395 $texSource .= &texInput($Global::TEX_SET_HEADER);
396
397 # Print setheader
398 my $mode = "TeX";
399 my @PG_COMPILE_ERRORS = ();
400 if ( (defined($setHeaderFileName)) and $setHeaderFileName =~ /\S/) {
401 $probSetHeader = $setHeaderFileName;
402 }
403 ## use $probSetHeader as default unless $setHeaderFileName is defined
404 ## in the set definition file
405 if ( open(INPUT,"${templateDirectory}$probSetHeader") ) {
406
407# ##Determine language
408
409 $probSetHeader =~ /\.([^\.]*)$/;
410 my $displayMode = $1;
411
412 if ($displayMode eq 'pg') {
413 my %envir=defineProblemEnvir($mode,0, $psvn,$Course,undef()); 271 my %envir=defineProblemEnvir($mode,0,$psvn,$Course);
414 my $input_string= join("",<INPUT> ); 272
415 my ($PG_PROBLEM_TEXT_REF, $PG_HEADER_TEXT_REF, $PG_ANSWER_HASH_REF, $PG_FLAGS_REF);
416 my $pt = new PGtranslator; #pt stands for problem translator; 273 my $pt = new PGtranslator; # pt stands for problem translator;
417 $pt -> evaluate_modules( @{main::modules_to_evaluate}) ;
418 $pt -> load_extra_packages(@{main::extra_packages_to_be_loaded});
419
420 # The variables in the two preceding lines are defined in PG_module_list.pl
421 # require "${courseScriptsDirectory}PG_module_list.pl";
422 # (Modules are defined by require statement above found near the top of this file, outside the loop.)
423 $pt->environment(\%envir); 274 $pt->environment(\%envir);
424 $pt->initialize(); 275 $pt->initialize();
425 $pt-> set_mask(); 276 $pt->set_mask();
426 $pt->source_string($input_string); 277 $pt->source_string($source);
427 $pt -> unrestricted_load("${courseScriptsDirectory}PG.pl"); 278 $pt->unrestricted_load("${courseScriptsDirectory}PG.pl");
428 $pt -> unrestricted_load("${courseScriptsDirectory}dangerousMacros.pl"); 279 $pt->unrestricted_load("${courseScriptsDirectory}dangerousMacros.pl");
429 $pt ->translate(); 280 $pt->translate();
281
430 $PG_PROBLEM_TEXT_REF = $pt->ra_text(); 282 my $PG_PROBLEM_TEXT_REF = $pt->ra_text();
431 $PG_HEADER_TEXT_REF = $pt->r_header;#\$PG_HEADER_TEXT; 283 my $PG_HEADER_TEXT_REF = $pt->r_header; #\$PG_HEADER_TEXT;
432 $PG_ANSWER_HASH_REF = $pt->rh_correct_answers; 284 my $PG_ANSWER_HASH_REF = $pt->rh_correct_answers;
433 $PG_FLAGS_REF =$pt ->rh_flags;
434# print OUTPUT @{$PG_PROBLEM_TEXT_REF};
435 $texSource .= join '', @{$PG_PROBLEM_TEXT_REF};
436 if (defined($PG_FLAGS_REF->{'error_flag'}) and $PG_FLAGS_REF->{'error_flag'} ==1) {
437 push(@PG_COMPILE_ERRORS, qq{<A HREF="#problem0">$probSetHeader</A>} );
438 }
439 if (defined($Global::WARNINGS) and $Global::WARNINGS) {
440 my $warnings = '{\\bf WARNINGS:\par{\\tiny ' . $Global::WARNINGS . ' }}';
441 $warnings =~ s|/|\\\-/|g; #allow linebreaks in the middle of URLs
442 $warnings =~ s/<br>/\\par\n/ig; #introduce breaks at linebreaks and paragraphs
443 $warnings =~ s/<p>/\\par\n/ig;
444 $warnings =~ s/\#/\\\#/g; #protect against some of the symbols which are reserved in tex
445 $warnings =~ s/\_/\\\_/g;
446 $warnings =~ s/\>/\\\>/g;
447 $warnings =~ s/\</\\\</g;
448 $texSource .= $warnings;
449 }
450 $Global::WARNINGS = ''; #reset the Global::WARNINGS parameter
451
452 } else {
453# print OUTPUT "Don't understand languages with extension $displayMode.<BR>\n";
454 $texSource .= "Don't understand languages with extension $displayMode.<BR>\n";
455 }
456 close INPUT;
457 } else {
458 print STDERR ( "Can't open ${templateDirectory}${probSetHeader}\n") if $debugON;
459 wwerror("$0", "\n######## Could not open the set header file: ${templateDirectory}${probSetHeader}","","");
460 }
461
462
463 # Print problems
464 my @problems = sort {$a <=> $b } &getAllProblemsForProbSetRecord($psvn);
465 my @refSubmittedAnswers = ();
466 # print "content-type: text/plain\n\nproblems @problems";
467
468 my $probNum;
469 foreach $probNum (@problems) {
470 my $source;
471 my $probFileName = &getProblemFileName($probNum,$psvn);
472 if (-e "${templateDirectory}$probFileName" ) {
473 unless (-r "${templateDirectory}$probFileName") {
474 wwerror($0, "Can't read ${templateDirectory}$probFileName");
475 }
476 open(PROB,"<${templateDirectory}$probFileName");
477 $source = join("",<PROB>);
478 close(PROB);
479 }
480 local($^W) =0; ##########CHANGE THIS BACK!!!!
481 my %envir=defineProblemEnvir('TeX',$probNum,$psvn,$Course,undef());
482 my ($PG_PROBLEM_TEXT_REF, $PG_HEADER_TEXT_REF, $PG_ANSWER_HASH_REF, $PG_FLAGS_REF,$PG_EVALUATED_ANSWERS_REF);
483#
484 my $pt = new PGtranslator; #pt stands for problem translator;
485 $pt->environment(\%envir) ;
486 $pt->initialize();
487 $pt-> set_mask();
488 $pt->source_string($source);
489 $pt -> unrestricted_load("${courseScriptsDirectory}PG.pl");
490 $pt -> unrestricted_load("${courseScriptsDirectory}dangerousMacros.pl");
491 $pt ->translate();
492
493 $PG_PROBLEM_TEXT_REF = $pt->ra_text();
494 $PG_HEADER_TEXT_REF = $pt->r_header;#\$PG_HEADER_TEXT;
495
496# $PG_ANSWER_HASH_REF = $pt->rh_correct_answers;
497 $PG_EVALUATED_ANSWERS_REF = $pt->process_answers;
498 $PG_FLAGS_REF = $pt ->rh_flags; 285 my $PG_FLAGS_REF = $pt->rh_flags;
286
287 my @printlines;
288 if($mode eq "HTML" || $mode eq 'HTML_tth') {
289 @printlines = @{$PG_PROBLEM_TEXT_REF};
290 #@printlines = @{$pt->ra_text()};
291 }
292 elsif ($mode eq 'Latex2HTML') {
293 @printlines =
294 &createDisplayedInsert($setNumber,$probHeader,$psvn,$Course,$PG_PROBLEM_TEXT_REF);
295 }
296 print @printlines;
297 print "</TD></TR></TABLE>";
499 298
500 299 print &htmlBOTTOM('welcomeAction.pl', \%inputs,'probSetHelp.html');
501# print OUTPUT @{$PG_PROBLEM_TEXT_REF};
502 $texSource .= join '', @{$PG_PROBLEM_TEXT_REF};
503
504 if (defined($PG_FLAGS_REF->{'error_flag'}) and $PG_FLAGS_REF->{'error_flag'} ==1) {
505 push(@PG_COMPILE_ERRORS, qq{<A HREF="#problem$probNum">$probNum</A>} );
506 }
507 if ($displayCorrectAnswersQ) {
508 my %correctAnswerHash = ();
509
510
511 my @correctAnswerList = ();
512
513 my %submittedAnswerHash = ();
514 if ( ref($PG_EVALUATED_ANSWERS_REF) eq 'HASH' ) {
515 %correctAnswerHash = %$PG_EVALUATED_ANSWERS_REF;
516 } else {
517 warn "ERROR: Please pass the PG answer list as a hash not a list.";
518 }
519
520 # insert answers (if any)
521
522 if ( %correctAnswerHash ) {
523 $texSource .= "Correct Answers:\\par\\begin{itemize}\n";
524 my ($correctFlag,$normalizedCorrectAnswer,
525 $normalizedSubmittedAnswer,
526 $answerMessage) = ();
527 # determine the correct order for the answers
528 my @answer_entry_order = ( defined($pt->{PG_FLAGS_REF}->{ANSWER_ENTRY_ORDER}) ) ?
529 @{$pt->{PG_FLAGS_REF}->{ANSWER_ENTRY_ORDER}} : keys %{$pt->rh_evaluated_answers} ;
530
531 foreach my $ky (@answer_entry_order) {
532
533 $normalizedCorrectAnswer = $correctAnswerHash{$ky}->{correct_ans};
534 $normalizedCorrectAnswer =~ s/\^/\\\^\{\}/g;
535 $normalizedCorrectAnswer =~ s/\_/\\\_/g;
536 $texSource .= "\\item $normalizedCorrectAnswer\n";
537
538 }
539
540 $texSource .= "\\end{itemize} \\par\n";
541 }
542 if (defined($Global::WARNINGS) and $Global::WARNINGS) {
543 my $warnings = '{\\bf WARNINGS:\par{\\tiny ' . $Global::WARNINGS . ' }}';
544 unless (@PG_COMPILE_ERRORS) { # prepare warnings for TeX output in this case
545 $warnings =~ s|/|\\\-/|g; #allow linebreaks in the middle of URLs
546 $warnings =~ s/<br>/\\par\n/ig; #introduce breaks at linebreaks and paragraphs
547 $warnings =~ s/<p>/\\par\n/ig;
548 $warnings =~ s/\#/\\\#/g; #protect against some of the symbols which are reserved in tex
549 $warnings =~ s/\_/\\\_/g;
550 $warnings =~ s/\>/\\\>/g;
551 $warnings =~ s/\</\\\</g;
552 $texSource .= $warnings;
553 }
554 }
555 $Global::WARNINGS = ''; #reset the Global::WARNINGS parameter
556 }
557
558
559 }
560
561 # print Tex postamble
562# print OUTPUT &texInput($Global::TEX_SET_FOOTER);
563 $texSource .= &texInput($Global::TEX_SET_FOOTER);
564
565 return \$texSource, \@PG_COMPILE_ERRORS;
566} 300}
567 301
568################### END main routine ################################## 302################################################################################
303# downloadAllSets (and related subroutines) ####################################
304################################################################################
305
306###################
307# downloadAllSets #
308###################
569 309
570sub downloadAllSets { 310sub downloadAllSets {
571 system("/usr/bin/renice +$main::CLASS_DOWNLOAD_NICE -p $$ 1>/dev/null") && warn "Could not renice process. pid $$"; 311 system("/usr/bin/renice +$main::CLASS_DOWNLOAD_NICE -p $$ 1>/dev/null") && warn "Could not renice process. pid $$";
572 alarm( $main::CLASS_DOWNLOAD_TIME_OUT_CONSTANT); 312 alarm( $main::CLASS_DOWNLOAD_TIME_OUT_CONSTANT);
573 313
656 print while (<TEXINPUT>); 396 print while (<TEXINPUT>);
657 close TEXINPUT; 397 close TEXINPUT;
658 } 398 }
659} 399}
660 400
401###################
402# createTexSource #
403###################
404
405sub createTexSource {
406 my $psvn = shift;
407
408 # Check that the psvn corresponds to the user and that it is after the open date.
409 # This should only fail if someone is trying to break into WeBWorK.
410 &attachProbSetRecord($psvn);
411 $login_name_for_psvn = &getStudentLogin($psvn);
412 attachCLRecord($login_name_for_psvn);
413
414 if ((($User ne &getStudentLogin($psvn)) ||($currentTime < $odts))
415 and ($permissions != $Global::instructor_permissions)
416 and ($permissions != $Global::TA_permissions))
417 {
418 &hackerError;
419 exit;
420 }
421
422 my $probSetHeader = $Global::SET_HEADER;
423 my $setHeaderFileName = &getSetHeaderFileName($psvn);
424
425 my $answersRequestedQ = 0;
426 $answersRequestedQ= $inputs{'ShowAns'} if defined($inputs{'ShowAns'});
427
428 my $adts=&getAnswerDate($psvn);
429 my $displayCorrectAnswersQ = 0; #initialize
430 $displayCorrectAnswersQ =1 if $answersRequestedQ && ($currentTime > $adts);
431 $displayCorrectAnswersQ =1 if $answersRequestedQ && ($permissions == $Global::instructor_permissions);
432
433 my $texSource ='';
434
435 print STDERR "%%Creating a tex version of set $setNumber<BR>\n" if $debugON;
436 print STDERR "%%For", &CL_getStudentName($login_name_for_psvn), "psvn=$psvn<BR>\n" if $debugON;
437
438 # print TeX preamble and header
439 $texSource .= &texInput($Global::TEX_SET_PREAMBLE);
440 $texSource .= &texInput($Global::TEX_SET_HEADER);
441
442 # print set header
443 my $mode = "TeX";
444 my @PG_COMPILE_ERRORS = ();
445 if ((defined($setHeaderFileName)) and $setHeaderFileName =~ /\S/) {
446 $probSetHeader = $setHeaderFileName;
447 }
448 if (open(INPUT,"${templateDirectory}$probSetHeader")) {
449 $probSetHeader =~ /\.([^\.]*)$/;
450 my $displayMode = $1;
451
452 if ($displayMode eq 'pg') {
453 my %envir=defineProblemEnvir($mode, 0, $psvn, $Course, undef());
454 my $input_string= join("",<INPUT>);
455 my ($PG_PROBLEM_TEXT_REF, $PG_HEADER_TEXT_REF, $PG_ANSWER_HASH_REF, $PG_FLAGS_REF);
456
457 my $pt = new PGtranslator;
458 $pt -> evaluate_modules( @{main::modules_to_evaluate}) ;
459 $pt -> load_extra_packages(@{main::extra_packages_to_be_loaded});
460 # The variables in the two preceding lines are defined in PG_module_list.pl
461 # require "${courseScriptsDirectory}PG_module_list.pl";
462 # (Modules are defined by require statement above found near the top of this file)
463 $pt->environment(\%envir);
464 $pt->initialize();
465 $pt->set_mask();
466 $pt->source_string($input_string);
467 $pt->unrestricted_load("${courseScriptsDirectory}PG.pl");
468 $pt->unrestricted_load("${courseScriptsDirectory}dangerousMacros.pl");
469 $pt->translate();
470
471 $PG_PROBLEM_TEXT_REF = $pt->ra_text();
472 $PG_HEADER_TEXT_REF = $pt->r_header;#\$PG_HEADER_TEXT;
473 $PG_ANSWER_HASH_REF = $pt->rh_correct_answers;
474 $PG_FLAGS_REF = $pt->rh_flags;
475
476 $texSource .= join '', @{$PG_PROBLEM_TEXT_REF};
477 if (defined($PG_FLAGS_REF->{'error_flag'}) and $PG_FLAGS_REF->{'error_flag'} == 1) {
478 push(@PG_COMPILE_ERRORS, qq{<A HREF="#problem0">$probSetHeader</A>} );
479 }
480
481 if (defined($Global::WARNINGS) and $Global::WARNINGS) {
482 my $warnings = '{\\bf WARNINGS:\par{\\tiny ' . $Global::WARNINGS . ' }}';
483 $warnings =~ s|/|\\\-/|g; # allow linebreaks in the middle of URLs
484 $warnings =~ s/<br>/\\par\n/ig; # introduce breaks at linebreaks and paragraphs
485 $warnings =~ s/<p>/\\par\n/ig;
486 $warnings =~ s/\#/\\\#/g; # protect against some of the symbols which are reserved in tex
487 $warnings =~ s/\_/\\\_/g;
488 $warnings =~ s/\>/\\\>/g;
489 $warnings =~ s/\</\\\</g;
490 $texSource .= $warnings;
491 }
492
493 $Global::WARNINGS = ''; # reset the Global::WARNINGS parameter
494 } else {
495 $texSource .= "Don't understand languages with extension $displayMode.<BR>\n";
496 }
497 close INPUT;
498 } else {
499 print STDERR ( "Can't open ${templateDirectory}${probSetHeader}\n") if $debugON;
500 wwerror("$0", "\n######## Could not open the set header file: ${templateDirectory}${probSetHeader}","","");
501 }
502
503 # Print problems
504 my @problems = sort { $a <=> $b } &getAllProblemsForProbSetRecord($psvn);
505 my @refSubmittedAnswers = ();
506
507 my $probNum;
508 foreach $probNum (@problems) {
509 my $source;
510 my $probFileName = &getProblemFileName($probNum,$psvn);
511 if (-e "${templateDirectory}$probFileName") {
512 unless (-r "${templateDirectory}$probFileName") {
513 wwerror($0, "Can't read ${templateDirectory}$probFileName");
514 }
515 open(PROB,"<${templateDirectory}$probFileName");
516 $source = join("",<PROB>);
517 close(PROB);
518 }
519 local($^W) =0; ##########CHANGE THIS BACK!!!! # what do you mean by that?
520 my %envir=defineProblemEnvir('TeX',$probNum,$psvn,$Course,undef());
521 my ($PG_PROBLEM_TEXT_REF, $PG_HEADER_TEXT_REF, $PG_ANSWER_HASH_REF, $PG_FLAGS_REF,$PG_EVALUATED_ANSWERS_REF);
522
523# BEGIN fork
524 if (open TEX_PIPE, "-|") {
525 # parent:
526 local $/ = "\n";
527 my $curr_pg_compile_error = <TEX_PIPE>;
528 chomp $curr_pg_compile_error;
529 push @PG_COMPILE_ERRORS, $curr_pg_compile_error if $curr_pg_compile_error;
530
531 undef $/;
532 $texSource .= <TEX_PIPE>;
533 } else {
534 # child:
535 $texSource = ''; # clear this at beginning of fork
536 @PG_COMPILE_ERRORS = (); # clear this as well
537# -----
538 my $pt = new PGtranslator; #pt stands for problem translator;
539 $pt->environment(\%envir) ;
540 $pt->initialize();
541 $pt-> set_mask();
542 $pt->source_string($source);
543 $pt->unrestricted_load("${courseScriptsDirectory}PG.pl");
544 $pt->unrestricted_load("${courseScriptsDirectory}dangerousMacros.pl");
545 $pt->translate();
546
547 $PG_PROBLEM_TEXT_REF = $pt->ra_text();
548 $PG_HEADER_TEXT_REF = $pt->r_header;#\$PG_HEADER_TEXT;
549 #$PG_ANSWER_HASH_REF = $pt->rh_correct_answers;
550 $PG_EVALUATED_ANSWERS_REF = $pt->process_answers;
551 $PG_FLAGS_REF = $pt ->rh_flags;
552
553 $texSource .= join '', @{$PG_PROBLEM_TEXT_REF};
554
555# begin non-FORK code
556# if (defined($PG_FLAGS_REF->{'error_flag'}) and $PG_FLAGS_REF->{'error_flag'} ==1) {
557# push(@PG_COMPILE_ERRORS, qq{<A HREF="#problem$probNum">$probNum</A>} );
558# }
559# end non-FORK code
560
561# begin FORK-only code
562 my $stupid_forked_error_string;
563 if (defined($PG_FLAGS_REF->{'error_flag'}) and $PG_FLAGS_REF->{'error_flag'} ==1) {
564 $texSource = qq{<A HREF="#problem$probNum">$probNum</A>} . "\n" . $texSource;
565 } else {
566 $texSource = "\n" . $texSource;
567 }
568# end FORK code
569
570 if ($displayCorrectAnswersQ) {
571 my %correctAnswerHash = ();
572 my @correctAnswerList = ();
573 my %submittedAnswerHash = ();
574
575 if (ref($PG_EVALUATED_ANSWERS_REF) eq 'HASH') {
576 %correctAnswerHash = %$PG_EVALUATED_ANSWERS_REF;
577 } else {
578 warn "ERROR: Please pass the PG answer list as a hash not a list.";
579 }
580
581 if (%correctAnswerHash) {
582 my ($correctFlag,$normalizedCorrectAnswer,
583 $normalizedSubmittedAnswer,
584 $answerMessage) = ();
585
586 # determine the correct order for the answers
587 my @answer_entry_order =
588 (defined($pt->{PG_FLAGS_REF}->{ANSWER_ENTRY_ORDER}))
589 ? @{$pt->{PG_FLAGS_REF}->{ANSWER_ENTRY_ORDER}}
590 : keys %{$pt->rh_evaluated_answers};
591
592 $texSource .= "Correct Answers:\\par\\begin{itemize}\n";
593 foreach my $ky (@answer_entry_order) {
594 $normalizedCorrectAnswer = $correctAnswerHash{$ky}->{correct_ans};
595 $normalizedCorrectAnswer =~ s/\^/\\\^\{\}/g;
596 $normalizedCorrectAnswer =~ s/\_/\\\_/g;
597 $texSource .= "\\item $normalizedCorrectAnswer\n";
598
599 }
600 $texSource .= "\\end{itemize} \\par\n";
601 }
602 }
603
604 if (defined($Global::WARNINGS) and $Global::WARNINGS) {
605 my $warnings = '{\\bf WARNINGS:\par{\\tiny ' . $Global::WARNINGS . ' }}';
606 unless (@PG_COMPILE_ERRORS) { # prepare warnings for TeX output in this case
607 $warnings =~ s|/|\\\-/|g; # allow linebreaks in the middle of URLs
608 $warnings =~ s/<br>/\\par\n/ig; # introduce breaks at linebreaks and paragraphs
609 $warnings =~ s/<p>/\\par\n/ig;
610 $warnings =~ s/\#/\\\#/g; # protect against some of the symbols which are reserved in tex
611 $warnings =~ s/\_/\\\_/g;
612 $warnings =~ s/\>/\\\>/g;
613 $warnings =~ s/\</\\\</g;
614 $texSource .= $warnings;
615 }
616 }
617 $Global::WARNINGS = ''; #reset the Global::WARNINGS parameter
618# -----
619 print $texSource;
620 exit;
621 }
622# END fork
623 } # this is the end of the foreach problem loop
624
625 # print Tex postamble
626 $texSource .= &texInput($Global::TEX_SET_FOOTER);
627
628 return \$texSource, \@PG_COMPILE_ERRORS;
629}
630
631###################
632# prepareHardcopy #
633###################
634
661sub prepareHardcopy 635sub prepareHardcopy
662{ 636{
663 my ($texFileBaseName, $targetFormat) = @_; 637 my ($texFileBaseName, $targetFormat) = @_;
664 my $mimeType; 638 my $mimeType;
665 639
670 my $pdfCommandLine = "$Global::externalPs2pdfPath $texFileBaseName.ps $texFileBaseName.pdf"; 644 my $pdfCommandLine = "$Global::externalPs2pdfPath $texFileBaseName.ps $texFileBaseName.pdf";
671 645
672 # make sure that you are not using old copies of the following files: 646 # make sure that you are not using old copies of the following files:
673 unlink("$texFileBaseName.dvi","$texFileBaseName.ps", "$texFileBaseName.pdf"); 647 unlink("$texFileBaseName.dvi","$texFileBaseName.ps", "$texFileBaseName.pdf");
674 648
649 # we use logPrint() for TeX->DVI errors as they are usually caused
675 if($targetFormat eq "pdf") { 650 if($targetFormat eq "pdf") {
676 #system($dviCommandLine); -e "$texFileBaseName.dvi" or die "dvi generation failed.";
677 system($dviCommandLine); -e "$texFileBaseName.dvi" or &logPrint($texFileBaseName); 651 system($dviCommandLine); -e "$texFileBaseName.dvi" or &logPrint($texFileBaseName);
678 # this gives more information about pure TeX errors
679 # (i.e. the .pg file has compiled but the resulting TeX is not well formed.)
680
681 # The following commands don't usually give very useful error messages anyway so just report failure.
682 system($psCommandLine); -e "$texFileBaseName.ps" or die "ps generation failed."; 652 system($psCommandLine); -e "$texFileBaseName.ps" or die "ps generation failed.";
683 system($pdfCommandLine); -e "$texFileBaseName.pdf" or die "pdf generation failed."; 653 system($pdfCommandLine); -e "$texFileBaseName.pdf" or die "pdf generation failed.";
684 $mimeType = "application/pdf"; 654 $mimeType = "application/pdf";
685 } elsif($targetFormat eq "ps") { 655 } elsif($targetFormat eq "ps") {
686 #system($dviCommandLine); -e "$texFileBaseName.dvi" or die "dvi generation failed.";
687 system($dviCommandLine); -e "$texFileBaseName.dvi" or &logPrint($texFileBaseName); 656 system($dviCommandLine); -e "$texFileBaseName.dvi" or &logPrint($texFileBaseName);
688 # this gives more information about pure TeX errors
689 # (i.e. the .pg file has compiled but the resulting TeX is not well formed.)
690 system($psCommandLine); -e "$texFileBaseName.ps" or die "ps generation failed."; 657 system($psCommandLine); -e "$texFileBaseName.ps" or die "ps generation failed.";
691 $mimeType = "application/postscript"; 658 $mimeType = "application/postscript";
692 } elsif($targetFormat eq "dvi") { 659 } elsif($targetFormat eq "dvi") {
693 #system($dviCommandLine); -e "$texFileBaseName.dvi" or die "dvi generation failed.";
694 system($dviCommandLine); -e "$texFileBaseName.dvi" or &logPrint($texFileBaseName); 660 system($dviCommandLine); -e "$texFileBaseName.dvi" or &logPrint($texFileBaseName);
695 # this gives more information about pure TeX errors
696 # (i.e. the .pg file has compiled but the resulting TeX is not well formed.)
697 $mimeType = "application/x-dvi"; 661 $mimeType = "application/x-dvi";
698 } elsif($targetFormat eq "tex") { 662 } elsif($targetFormat eq "tex") {
699 $mimeType = "application/tex"; 663 $mimeType = "application/tex";
700 } else { 664 } else {
701 die "unrecognized format: $targetFormat"; 665 die "unrecognized format: $targetFormat";
702 } 666 }
703 667
704 return $mimeType; 668 return $mimeType;
705} 669}
670
671##################
672# PG_error_print #
673##################
706 674
707sub PG_error_print 675sub PG_error_print
708{ 676{
709 my ($tempTexFileBaseName, $current_psvn, @errors) = @_; 677 my ($tempTexFileBaseName, $current_psvn, @errors) = @_;
710 678
736 704
737 # print page footer 705 # print page footer
738 print &htmlBOTTOM("welcomeAction.pl", \%inputs); 706 print &htmlBOTTOM("welcomeAction.pl", \%inputs);
739 exit; 707 exit;
740} 708}
741
742# -----
743 709
744sub logPrint { 710sub logPrint {
745 my $texFileBaseName=shift; 711 my $texFileBaseName=shift;
746 print &htmlTOP("TeX Error or error in creating PostScript file"); 712 print &htmlTOP("TeX Error or error in creating PostScript file");
747 open (LOGFILE, " $texFileBaseName.log") 713 open (LOGFILE, " $texFileBaseName.log")
969 $envir{$k} = $Global::PG_environment{$k}; 935 $envir{$k} = $Global::PG_environment{$k};
970 } 936 }
971 %envir; 937 %envir;
972} 938}
973 939
940################################################################################
941# cleanup routines #############################################################
942################################################################################
943
974BEGIN { 944BEGIN {
975
976
977# This subroutine cleans up temporary files after the postscript copy has been created. 945 # This subroutine cleans up temporary files after the postscript copy has been created.
978#
979 sub cleanup_downloadPS { 946 sub cleanup_downloadPS {
980
981 unless (defined($action ) and ($action eq 'Do problem set' or $action eq 'Do_problem_set')) { 947 unless (defined($action) and ($action eq 'Do problem set' or $action eq 'Do_problem_set')) {
982 my $ERRORS = $save_errors; 948 my $ERRORS = $save_errors;
983 unless ($debugON) { #clean up the directory 949 unless ($debugON) {
984 eval { 950 eval {
985 chdir $tempDirectory; 951 chdir $tempDirectory;
986 unlink( 952 unlink(
987 "#tempTexFileBaseName.dvi", 953 "#tempTexFileBaseName.dvi",
988 "$tempTexFileBaseName.ps", 954 "$tempTexFileBaseName.ps",
990 "$tempTexFileBaseName.log", 956 "$tempTexFileBaseName.log",
991 "$tempTexFileBaseName.aux", 957 "$tempTexFileBaseName.aux",
992 "$tempTexFileBaseName.tex" 958 "$tempTexFileBaseName.tex"
993 ); 959 );
994 unlink("${tempDirectory}eps/${login_name_for_psvn}*.eps"); 960 unlink("${tempDirectory}eps/${login_name_for_psvn}*.eps");
995 }; # clean up 961 };
996 $ERRORS .= $ERRORS . $@; 962 $ERRORS .= $ERRORS . $@;
997 } 963 }
998 my $query = query_string(); 964 my $query = query_string();
999 $query = "" unless defined($query); 965 $query = "" unless defined($query);
1000 wwerror("$0", "ERROR: in downloadPS subroutine of welcomeAction.pl $ERRORS","","",$query) if $ERRORS; 966 wwerror("$0", "ERROR: in downloadPS subroutine of welcomeAction.pl $ERRORS","","",$query) if $ERRORS;
1001 } 967 }
1002 } 968 }
1003} 969}
1054 my $endTime = new Benchmark; 1020 my $endTime = new Benchmark;
1055 my $error_str=''; 1021 my $error_str='';
1056 1022
1057 if ($main::SIGPIPE) { 1023 if ($main::SIGPIPE) {
1058 $error_str = 'broken PIPE--'; 1024 $error_str = 'broken PIPE--';
1059 }
1060 elsif ($main::SIG_TIME_OUT) { 1025 } elsif ($main::SIG_TIME_OUT) {
1061 $error_str = "TIME_OUT after $main::TIME_OUT_CONSTANT secs --"; 1026 $error_str = "TIME_OUT after $main::TIME_OUT_CONSTANT secs --";
1062 }
1063 elsif ($action eq 'Get hard copy' or $action eq 'Get_hard_copy') { 1027 } elsif ($action eq 'Get hard copy' or $action eq 'Get_hard_copy') {
1064 $error_str = 'successful download -- '; 1028 $error_str = 'successful download -- ';
1065 } 1029 }
1066 1030
1067 &Global::logTimingInfo($main::beginTime,$endTime,$error_str.'welcomeAction.pl',$Course,$User); 1031 &Global::logTimingInfo($main::beginTime,$endTime,$error_str.'welcomeAction.pl',$Course,$User);
1068 } 1032 }
1069 # end Timing code 1033 # end Timing code
1034
1070 cleanup_downloadPS(); 1035 cleanup_downloadPS();
1071} 1036}
1072 1037
10731; 10381;

Legend:
Removed from v.154  
changed lines
  Added in v.155

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9