[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 5 Revision 6
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3 3
4################################################################ 4################################################################
5# Copyright @1995-1999 by Michael E. Gage, Arnold K. Pizer and 5# Copyright @1995-1999 by Michael E. Gage, Arnold K. Pizer and
6# WeBWorK at the University of Rochester. All rights reserved. 6# WeBWorK at the University of Rochester. All rights reserved.
7################################################################ 7################################################################
8 8
9my $debugON=0; ## set this to 1 to save debugging information for errors in hardcopy output 9my $debugON=0; ## set this to 1 to save debugging information for errors in hardcopy output
10 10
11use lib '/ww/webwork/development/'; # mainWeBWorKDirectory; 11use lib '/ww/webwork/gage_system/webwork/system/lib/'; # mainWeBWorKDirectory
12require 5.001; 12require 5.001;
13 13
14$/ ="\n"; 14$/ ="\n";
15 15
16use strict; 16use strict;
88# this is globally defined for the file, since it is needed for cleanup in END 88# this is globally defined for the file, since it is needed for cleanup in END
89my $tempDirectory = getCourseTempDirectory(); 89my $tempDirectory = getCourseTempDirectory();
90 90
91eval{require "${courseScriptsDirectory}$Global::displayMacros_pl";} ; 91eval{require "${courseScriptsDirectory}$Global::displayMacros_pl";} ;
92eval{require "${scriptDirectory}$Global::DBglue_pl";}; 92eval{require "${scriptDirectory}$Global::DBglue_pl";};
93eval{require "${scriptDirectory}$Global::classlist_DBglue_pl";};
93eval{require "${scriptDirectory}$Global::HTMLglue_pl";}; 94eval{require "${scriptDirectory}$Global::HTMLglue_pl";};
94eval{require "${scriptDirectory}$Global::FILE_pl";} ; 95eval{require "${scriptDirectory}$Global::FILE_pl";} ;
95 96
96 97
97 98
125&verify_key($inputs{'user'}, $Session_key, $keyFile, $Course); 126&verify_key($inputs{'user'}, $Session_key, $keyFile, $Course);
126 127
127my $permissions = &get_permissions($User,$permissionsFile); 128my $permissions = &get_permissions($User,$permissionsFile);
128 129
129&attachProbSetRecord($psvn); 130&attachProbSetRecord($psvn);
131my $login_name_for_psvn = &getStudentLogin($psvn);
132attachCLRecord($login_name_for_psvn);
130 133
131my $setNumber=&getSetNumber($psvn); 134my $setNumber=&getSetNumber($psvn);
132$setNumber = $inputs{'setNo'} if defined $inputs{'setNo'}; ## script called from profChangeDates.pl 135$setNumber = $inputs{'setNo'} if defined $inputs{'setNo'}; ## script called from profChangeDates.pl
133 136
134 137
138$currentTime = time; 141$currentTime = time;
139$odts=&getOpenDate($psvn); 142$odts=&getOpenDate($psvn);
140$ddts=&getDueDate($psvn); 143$ddts=&getDueDate($psvn);
141$remainingTime=$ddts-$currentTime; 144$remainingTime=$ddts-$currentTime;
142 145
143
144
145if($currentTime<$odts && $permissions !=$Global::instructor_permissions) { 146if($currentTime<$odts && $permissions !=$Global::instructor_permissions) {
146 print &htmlTOP("Before open date error"); 147 print &htmlTOP("Before open date error");
147 print "<CENTER><h2>Sorry, cannot download or do problem set $setNumber yet. 148 print "<CENTER><h2>Sorry, cannot download or do problem set $setNumber yet.
148 <BR>It is before the open date.</h2></CENTER>"; 149 <BR>It is before the open date.</h2></CENTER>";
149 print &htmlBOTTOM("downloadPS.pl",\%inputs); 150 print &htmlBOTTOM("downloadPS.pl",\%inputs);
150 exit(0); 151 exit(0);
151} 152}
152 153
153my @allSetKeys = &getAllProbSetKeysForSetSortedBySectionThenByName($setNumber); 154my %PSVNHashForSet = %{getPSVNHashForSet($setNumber)};
154my $action = $inputs{'action'}; 155my $action = $inputs{'action'};
155my $downloadType= $inputs{'downloadType'}; # either pdf, ps, tex, or dvi 156my $downloadType= $inputs{'downloadType'}; # either pdf, ps, tex, or dvi
156 157
157# Verify that the problem set has been created if a psvn number has been passed 158# Verify that the problem set has been created if a psvn number has been passed
158unless ($action eq 'Get_all_copies') { 159unless ($action eq 'Get_all_copies') {
159 if (! grep (/$psvn/, @allSetKeys) ) { 160 unless (defined $PSVNHashForSet{$psvn} ) {
160 print &htmlTOP("Problem set version number $psvn not created"); 161 print &htmlTOP("Problem set version number $psvn not created");
161 print ( "Pin number $psvn was not created for set $setNumber"); 162 print ( "Pin number $psvn was not created for set $setNumber");
162 print &htmlBOTTOM("downloadPS.pl", \%inputs); 163 print &htmlBOTTOM("downloadPS.pl", \%inputs);
163 exit(0); 164 exit(0);
164 } 165 }
165} 166}
166 167
167my $login_name_for_psvn = &getStudentLogin($psvn);
168my $texFile = "${login_name_for_psvn}.tempTex-CGIscript"; 168my $texFile = "${login_name_for_psvn}.tempTex-CGIscript";
169my $save_errors=''; 169my $save_errors='';
170 170
171if ($action eq 'Do_problem_set') {displayProbSet();} 171if ($action eq 'Do problem set' or $action eq 'Do_problem_set') {displayProbSet();}
172#elsif ($action eq 'Get_hard_copy') {downloadIndividualSet();} 172#elsif ($action eq 'Get hard copy' or $action eq 'Get_hard_copy') {downloadIndividualSet();}
173elsif ($action eq 'Get_hard_copy') {downloadAllSets();} 173elsif ($action eq 'Get hard copy' or $action eq 'Get_hard_copy') {downloadAllSets();}
174elsif ($action eq 'Get_all_copies') {downloadAllSets();} 174elsif ($action eq 'Get_all_copies') {downloadAllSets();}
175else {wwerror($0, "Unknown action: $action");} 175else {wwerror($0, "Unknown action: $action");}
176 176
177 177
178# begin Timing code 178# begin Timing code
182 182
183 exit; 183 exit;
184############################################# 184#############################################
185 185
186sub displayProbSet { 186sub displayProbSet {
187 my $studentName=&getStudentName($psvn); 187 my $studentName=&CL_getStudentName($login_name_for_psvn);
188 my $probHeaderFileName = &getProbHeaderFileName($psvn); 188 my $probHeaderFileName = &getProbHeaderFileName($psvn);
189 189
190 my @problems=sort numerical &getAllProblemsForProbSetRecord($psvn); 190 my @problems=sort numerical &getAllProblemsForProbSetRecord($psvn);
191 sub numerical { $a <=> $b}; 191 sub numerical { $a <=> $b};
192 192
335sub createTexSource { 335sub createTexSource {
336 my $psvn = shift; 336 my $psvn = shift;
337 337
338 # check that the psvn corresponds to the user and that it is after the open 338 # check that the psvn corresponds to the user and that it is after the open
339 # date. This should only fail if someone is trying to break into WeBWorK. 339 # date. This should only fail if someone is trying to break into WeBWorK.
340
341 &attachProbSetRecord($psvn);
342 $login_name_for_psvn = &getStudentLogin($psvn);
343 attachCLRecord($login_name_for_psvn);
340 344
341 if ( ( ( $User ne &getStudentLogin($psvn)) ||($currentTime < $odts) ) 345 if ( ( ( $User ne &getStudentLogin($psvn)) ||($currentTime < $odts) )
342 and ($permissions != $Global::instructor_permissions) 346 and ($permissions != $Global::instructor_permissions)
343 and ($permissions != $Global::TA_permissions) 347 and ($permissions != $Global::TA_permissions)
344 ) { 348 ) {
365 my $texSource =''; 369 my $texSource ='';
366 370
367# open(OUTPUT, ">${tempDirectory}${texFile}${psvn}.tex") 371# open(OUTPUT, ">${tempDirectory}${texFile}${psvn}.tex")
368#|| wwerror("Can't create $tempDirectory${texFile}$psvn.tex\n"); 372#|| wwerror("Can't create $tempDirectory${texFile}$psvn.tex\n");
369 373
370 &attachProbSetRecord($psvn); 374
375
371 print STDERR "%%Creating a tex version of set $setNumber<BR>\n" if $debugON; 376 print STDERR "%%Creating a tex version of set $setNumber<BR>\n" if $debugON;
372 print STDERR "%%For", &getStudentName($psvn), "psvn=$psvn<BR>\n" if $debugON; 377 print STDERR "%%For", &CL_getStudentName($login_name_for_psvn), "psvn=$psvn<BR>\n" if $debugON;
373 378
374 379
375 # input TeX preamble 380 # input TeX preamble
376# print OUTPUT &texInput($Global::TEX_SET_PREAMBLE); 381# print OUTPUT &texInput($Global::TEX_SET_PREAMBLE);
377 $texSource = &texInput($Global::TEX_SET_PREAMBLE); 382 $texSource = &texInput($Global::TEX_SET_PREAMBLE);
393# ##Determine language 398# ##Determine language
394 399
395 $probSetHeader =~ /\.([^\.]*)$/; 400 $probSetHeader =~ /\.([^\.]*)$/;
396 my $displayMode = $1; 401 my $displayMode = $1;
397 402
398 if ($displayMode eq 'qz') {
399# print OUTPUT "Can't read the qz language anymore";
400 $texSource .= "Can't read the qz language anymore";
401 } elsif ($displayMode eq 'pg') { 403 if ($displayMode eq 'pg') {
402
403
404 my %envir=defineProblemEnvir($mode,0, $psvn,$Course,undef()); 404 my %envir=defineProblemEnvir($mode,0, $psvn,$Course,undef());
405 my $input_string= join("",<INPUT> ); 405 my $input_string= join("",<INPUT> );
406 my ($PG_PROBLEM_TEXT_REF, $PG_HEADER_TEXT_REF, $PG_ANSWER_HASH_REF, $PG_FLAGS_REF); 406 my ($PG_PROBLEM_TEXT_REF, $PG_HEADER_TEXT_REF, $PG_ANSWER_HASH_REF, $PG_FLAGS_REF);
407 my $pt = new PGtranslator; #pt stands for problem translator; 407 my $pt = new PGtranslator; #pt stands for problem translator;
408 $pt -> evaluate_modules( @{main::modules_to_evaluate}) ; 408 $pt -> evaluate_modules( @{main::modules_to_evaluate}) ;
480 if (defined($PG_FLAGS_REF->{'error_flag'}) and $PG_FLAGS_REF->{'error_flag'} ==1) { 480 if (defined($PG_FLAGS_REF->{'error_flag'}) and $PG_FLAGS_REF->{'error_flag'} ==1) {
481 push(@PG_COMPILE_ERRORS, qq{<A HREF="#problem$probNum">$probNum</A>} ); 481 push(@PG_COMPILE_ERRORS, qq{<A HREF="#problem$probNum">$probNum</A>} );
482 } 482 }
483 if ($displayCorrectAnswersQ) { 483 if ($displayCorrectAnswersQ) {
484 my %correctAnswerHash = (); 484 my %correctAnswerHash = ();
485 485
486 486
487 my @correctAnswerList = (); 487 my @correctAnswerList = ();
488 488
489 my %submittedAnswerHash = (); 489 my %submittedAnswerHash = ();
490 if ( ref($PG_EVALUATED_ANSWERS_REF) eq 'HASH' ) { 490 if ( ref($PG_EVALUATED_ANSWERS_REF) eq 'HASH' ) {
581 system( "${scriptDirectory}makePDF $tempDirectory ${texFile}$psvn 1>&2" ) == 0 581 system( "${scriptDirectory}makePDF $tempDirectory ${texFile}$psvn 1>&2" ) == 0
582 or wwerror("$0", "Unable to create PDF output using makePDF file:<BR> ${scriptDirectory}makePDF $tempDirectory ${texFile}$psvn 1>&2<BR>Error is: $!", "", ""); 582 or wwerror("$0", "Unable to create PDF output using makePDF file:<BR> ${scriptDirectory}makePDF $tempDirectory ${texFile}$psvn 1>&2<BR>Error is: $!", "", "");
583 open(INPUT, "$tempDirectory${texFile}$psvn.pdf") 583 open(INPUT, "$tempDirectory${texFile}$psvn.pdf")
584 || wwerror("$0", "Can't open $tempDirectory${texFile}$psvn.pdf: $!\n","",""); 584 || wwerror("$0", "Can't open $tempDirectory${texFile}$psvn.pdf: $!\n","","");
585 585
586 print "Content-type: application/pdf\n\n" ;
586 print "Content-disposition: attachment; filename= \"${login_name_for_psvn}_Set${setNumber}.pdf\"\n"; 587 print "Content-disposition: attachment; filename= \"${login_name_for_psvn}_Set${setNumber}.pdf\"\n";
587 print "Content-type: application/pdf\n\n" ; 588 #print "Content-type: application/pdf\n\n" ;
588 while (<INPUT>) { 589 while (<INPUT>) {
589 print; 590 print;
590 } 591 }
591 close INPUT; 592 close INPUT;
592 print STDERR "Finished TeX $texFile for $login_name_for_psvn in $Course\n" if $debugON; 593 print STDERR "Finished TeX $texFile for $login_name_for_psvn in $Course\n" if $debugON;
797 wwerror ("Too many students selected", "The maximun number of sets which can be downloaded at one time is $max. You selected $length. 798 wwerror ("Too many students selected", "The maximun number of sets which can be downloaded at one time is $max. You selected $length.
798Go back and select fewer students. This maximun is set by the variable 799Go back and select fewer students. This maximun is set by the variable
799\$max_num_of_ps_downloads_allowed in Global.pm."); 800\$max_num_of_ps_downloads_allowed in Global.pm.");
800 } 801 }
801 $localpsvn = shift @local_psvns; ## get first set which will contain TeX header info 802 $localpsvn = shift @local_psvns; ## get first set which will contain TeX header info
802 attachProbSetRecord($localpsvn); 803# attachProbSetRecord($localpsvn);
803 ($texSourceRef, $errorRef) = &createTexSource($localpsvn); 804 ($texSourceRef, $errorRef) = &createTexSource($localpsvn);
804 ## don't do anything with $errorRef at this time 805 ## don't do anything with $errorRef at this time
805 ## only contains prob numbers of bad problems 806 ## only contains prob numbers of bad problems
806 $texSource = $$texSourceRef; ## contains initial header info 807 $texSource = $$texSourceRef; ## contains initial header info
807 $texSource =~ s|\\end\{document\}\s$|\n|s; ## remove end{document} statement 808 $texSource =~ s|\\end\{document\}\s$|\n|s; ## remove end{document} statement
808 809
809 foreach $localpsvn (@local_psvns) { ## get the rest of the sets and strip TeX header info 810 foreach $localpsvn (@local_psvns) { ## get the rest of the sets and strip TeX header info
810 attachProbSetRecord($localpsvn); 811# attachProbSetRecord($localpsvn);
811 ($texSourceRef, $errorRef) = &createTexSource($localpsvn); 812 ($texSourceRef, $errorRef) = &createTexSource($localpsvn);
812 ## don't do anything with $errorRef at this time 813 ## don't do anything with $errorRef at this time
813 ## only contains prob numbers of bad problems 814 ## only contains prob numbers of bad problems
814 $individualTexSource = $$texSourceRef; 815 $individualTexSource = $$texSourceRef;
815 $individualTexSource =~ s|^.*?\\begin\{document\}|\n\\newpage\n|s; ## remove header material and start new page 816 $individualTexSource =~ s|^.*?\\begin\{document\}|\n\\newpage\n|s; ## remove header material and start new page
885} 886}
886 887
887sub defineProblemEnvir { 888sub defineProblemEnvir {
888 my ($mode,$probNum,$psvn,$courseName,$refSubmittedAnswers) = @_; 889 my ($mode,$probNum,$psvn,$courseName,$refSubmittedAnswers) = @_;
889 my %envir=(); 890 my %envir=();
891 my $loginName = &getStudentLogin($psvn);
890 ##how to put an array submittedAnswers in a hash?? 892 ##how to put an array submittedAnswers in a hash??
891 $envir{'refSubmittedAnswers'} = $refSubmittedAnswers if defined($refSubmittedAnswers); 893 $envir{'refSubmittedAnswers'} = $refSubmittedAnswers if defined($refSubmittedAnswers);
892 $envir{'psvnNumber'} = $psvn; 894 $envir{'psvnNumber'} = $psvn;
893 $envir{'psvn'} = $psvn; 895 $envir{'psvn'} = $psvn;
894 $envir{'studentName'} = &getStudentName($psvn); 896 $envir{'studentName'} = &CL_getStudentName($loginName);
895 $envir{'studentLogin'} = &getStudentLogin($psvn); 897 $envir{'studentLogin'} = $loginName;
896 $envir{'sectionName'} = &getClassSection($psvn); 898 $envir{'sectionName'} = &CL_getClassSection($loginName);
897 $envir{'sectionNumber'} = &getClassSection($psvn); 899 $envir{'sectionNumber'} = &CL_getClassSection($loginName);
898 $envir{'recitationName'} = &getClassRecitation($psvn); 900 $envir{'recitationName'} = &CL_getClassRecitation($loginName);
899 $envir{'recitationNumber'} = &getClassRecitation($psvn); 901 $envir{'recitationNumber'} = &CL_getClassRecitation($loginName);
900 $envir{'setNumber'} = &getSetNumber($psvn); 902 $envir{'setNumber'} = &getSetNumber($psvn);
901 $envir{'questionNumber'} = $probNum; 903 $envir{'questionNumber'} = $probNum;
902 $envir{'probNum'} = $probNum; 904 $envir{'probNum'} = $probNum;
903 $envir{'openDate'} = &getOpenDate($psvn); 905 $envir{'openDate'} = &getOpenDate($psvn);
904 $envir{'formatedOpenDate'} = &formatDateAndTime(&getOpenDate($psvn)); 906 $envir{'formatedOpenDate'} = &formatDateAndTime(&getOpenDate($psvn));
969 971
970# This subroutine cleans up temporary files after the postscript copy has been created. 972# This subroutine cleans up temporary files after the postscript copy has been created.
971# 973#
972 sub cleanup_downloadPS { 974 sub cleanup_downloadPS {
973 975
974 unless (defined($action ) and $action eq 'Do_problem_set') { 976 unless (defined($action ) and ($action eq 'Do problem set' or $action eq 'Do_problem_set')) {
975 my $ERRORS = $save_errors; 977 my $ERRORS = $save_errors;
976 unless ($debugON) { #clean up the directory 978 unless ($debugON) { #clean up the directory
977 eval { 979 eval {
978 chdir $tempDirectory; 980 chdir $tempDirectory;
979 unlink("$texFile$psvn.dvi", "$texFile$psvn.ps","$texFile$psvn.pdf", 981 unlink("$texFile$psvn.dvi", "$texFile$psvn.ps","$texFile$psvn.pdf",
1026 If the high useage problem continues you can report this to your instructor using the feedback button. 1028 If the high useage problem continues you can report this to your instructor using the feedback button.
1027 <P> 1029 <P>
1028 1030
1029 </BLOCKQUOTE></BODY></HTML> 1031 </BLOCKQUOTE></BODY></HTML>
1030 }; 1032 };
1031 if ($action eq 'Get_hard_copy') { 1033 if ($action eq 'Get hard copy' or $action eq 'Get_hard_copy') {
1032 print $hard_copy_message; 1034 print $hard_copy_message;
1033 } else{ 1035 } else{
1034 print $do_problem_message; 1036 print $do_problem_message;
1035 } 1037 }
1036 1038
1046 $error_str = 'broken PIPE--'; 1048 $error_str = 'broken PIPE--';
1047 } 1049 }
1048 elsif ($main::SIG_TIME_OUT) { 1050 elsif ($main::SIG_TIME_OUT) {
1049 $error_str = "TIME_OUT after $main::TIME_OUT_CONSTANT secs --"; 1051 $error_str = "TIME_OUT after $main::TIME_OUT_CONSTANT secs --";
1050 } 1052 }
1051 elsif ($action eq 'Get_hard_copy') { 1053 elsif ($action eq 'Get hard copy' or $action eq 'Get_hard_copy') {
1052 $error_str = 'successful download -- '; 1054 $error_str = 'successful download -- ';
1053 } 1055 }
1054 1056
1055 &Global::logTimingInfo($main::beginTime,$endTime,$error_str.'welcomeAction.pl',$Course,$User); 1057 &Global::logTimingInfo($main::beginTime,$endTime,$error_str.'welcomeAction.pl',$Course,$User);
1056 } 1058 }

Legend:
Removed from v.5  
changed lines
  Added in v.6

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9