| … | |
… | |
| 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 | |
| 9 | my $debugON=0; ## set this to 1 to save debugging information for errors in hardcopy output |
9 | my $debugON=1; ## set this to 1 to save debugging information for errors in hardcopy output |
| 10 | |
10 | |
| 11 | use lib '.'; use webworkInit; # WeBWorKInitLine |
11 | use lib '.'; use webworkInit; # WeBWorKInitLine |
| 12 | require 5.001; |
12 | require 5.001; |
| 13 | |
13 | |
| 14 | $/ ="\n"; |
14 | $/ ="\n"; |
| … | |
… | |
| 35 | } |
35 | } |
| 36 | # end Timing code |
36 | # end Timing code |
| 37 | |
37 | |
| 38 | # ## Setting these time out comstants to zeros removes the time constraint completely. (zero = infinity :=) ) |
38 | # ## 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 |
39 | $main::TIME_OUT_CONSTANT = 60; # one minute wait for on screen problems |
| 40 | $main::DOWNLOAD_TIME_OUT_CONSTANT = 300; # give it five minutes |
40 | # $main::DOWNLOAD_TIME_OUT_CONSTANT = 300; # give it five minutes |
| 41 | $main::CLASS_DOWNLOAD_TIME_OUT_CONSTANT = 1200; #twenty minutes |
41 | $main::CLASS_DOWNLOAD_TIME_OUT_CONSTANT = 1200; #twenty minutes |
| 42 | $main::DOWNLOAD_NICE = 2; |
42 | # $main::DOWNLOAD_NICE = 2; |
| 43 | $main::CLASS_DOWNLOAD_NICE = 5; # higher numbers indicated lower priorities |
43 | $main::CLASS_DOWNLOAD_NICE = 5; # higher numbers indicated lower priorities |
| 44 | |
44 | |
| 45 | # ## ATTENTION: The handlers PG_floating_point_exception_handler and PG_warnings_handler |
45 | # ## 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 |
46 | # ## 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 |
47 | # ## modifes the die and warn labels. Finding the right warning mechanism using these two |
| … | |
… | |
| 132 | attachCLRecord($login_name_for_psvn); |
132 | attachCLRecord($login_name_for_psvn); |
| 133 | |
133 | |
| 134 | my $setNumber=&getSetNumber($psvn); |
134 | my $setNumber=&getSetNumber($psvn); |
| 135 | $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 |
| 136 | |
136 | |
| 137 | |
137 | # keep strict happy |
|
|
138 | my $tempTexFileBaseName; |
| 138 | |
139 | |
| 139 | ###### check to see that it is after the open date |
140 | ###### check to see that it is after the open date |
| 140 | my ($currentTime,$odts,$ddts,$remainingTime, $TimeString); |
141 | my ($currentTime,$odts,$ddts,$remainingTime, $TimeString); |
| 141 | $currentTime = time; |
142 | $currentTime = time; |
| 142 | $odts=&getOpenDate($psvn); |
143 | $odts=&getOpenDate($psvn); |
| … | |
… | |
| 480 | # $PG_ANSWER_HASH_REF = $pt->rh_correct_answers; |
481 | # $PG_ANSWER_HASH_REF = $pt->rh_correct_answers; |
| 481 | $PG_EVALUATED_ANSWERS_REF = $pt->process_answers; |
482 | $PG_EVALUATED_ANSWERS_REF = $pt->process_answers; |
| 482 | $PG_FLAGS_REF = $pt ->rh_flags; |
483 | $PG_FLAGS_REF = $pt ->rh_flags; |
| 483 | |
484 | |
| 484 | |
485 | |
| 485 | print OUTPUT @{$PG_PROBLEM_TEXT_REF}; |
486 | # print OUTPUT @{$PG_PROBLEM_TEXT_REF}; |
| 486 | $texSource .= join '', @{$PG_PROBLEM_TEXT_REF}; |
487 | $texSource .= join '', @{$PG_PROBLEM_TEXT_REF}; |
| 487 | |
488 | |
| 488 | if (defined($PG_FLAGS_REF->{'error_flag'}) and $PG_FLAGS_REF->{'error_flag'} ==1) { |
489 | if (defined($PG_FLAGS_REF->{'error_flag'}) and $PG_FLAGS_REF->{'error_flag'} ==1) { |
| 489 | push(@PG_COMPILE_ERRORS, qq{<A HREF="#problem$probNum">$probNum</A>} ); |
490 | push(@PG_COMPILE_ERRORS, qq{<A HREF="#problem$probNum">$probNum</A>} ); |
| 490 | } |
491 | } |
| … | |
… | |
| 535 | return \$texSource, \@PG_COMPILE_ERRORS; |
536 | return \$texSource, \@PG_COMPILE_ERRORS; |
| 536 | } |
537 | } |
| 537 | |
538 | |
| 538 | ################### END main routine ################################## |
539 | ################### END main routine ################################## |
| 539 | |
540 | |
| 540 | sub downloadPS { |
541 | sub downloadAllSets { |
| 541 | my $psvn = shift; |
542 | system("/usr/bin/renice +$main::CLASS_DOWNLOAD_NICE -p $$ 1>/dev/null") && warn "Could not renice process. pid $$"; |
| 542 | my $texFile = shift; |
543 | alarm( $main::CLASS_DOWNLOAD_TIME_OUT_CONSTANT); |
| 543 | |
544 | |
|
|
545 | my $downloadMulti = "unknown"; |
|
|
546 | $downloadMulti = "multistudent" if $action eq "Get_all_copies"; |
|
|
547 | $downloadMulti = "multiset" if $action eq "Get_hard_copy"; |
|
|
548 | |
|
|
549 | my @psvns_to_download = $query->param('local_psvns'); |
|
|
550 | my $num_psvns_to_download = @psvns_to_download; |
|
|
551 | my $max_psvns_to_download = $Global::max_num_of_ps_downloads_allowed; |
|
|
552 | |
|
|
553 | if($num_psvns_to_download > 1 and $permissions != $Global::instructor_permissions) { |
|
|
554 | wwerror("Non-professors are not permitted to download more than one problem set at a time."); |
|
|
555 | } |
|
|
556 | |
|
|
557 | if(@psvns_to_download > $Global::max_num_of_ps_downloads_allowed) { |
|
|
558 | my $tooManyWhat = $downloadMulti eq "multiset" ? "problem sets" : "students"; |
|
|
559 | wwerror("Too many $tooManyWhat are selected for download.", |
|
|
560 | "The maximum number of $tooManyWhat which can be downloaded at one time is $Global::max_num_of_ps_downloads_allowed." |
|
|
561 | ." You selected $num_psvns_to_download. Go back and select fewer $tooManyWhat." |
|
|
562 | ." (This maximun is set by the variable \$max_num_of_ps_downloads_allowed in Global.pm.)"); |
|
|
563 | } |
|
|
564 | |
|
|
565 | my ($cumulativeTexSource, $currentTexSourceRef, $currentTexSource, $currentTexErrorRef); |
|
|
566 | |
|
|
567 | # this could be used when eliminating pre-foreach createTexSourceHandleErrors call |
|
|
568 | # s/\\end\{document\}.*?\\begin\{document\}/\n\\newpage\n/s; |
|
|
569 | |
|
|
570 | $tempTexFileBaseName = "${tempDirectory}Temp_downloadAllSets_$User"; |
|
|
571 | my $first_psvn = $psvns_to_download[0]; |
|
|
572 | |
|
|
573 | my $current_psvn = shift @psvns_to_download; |
| 544 | my ($texSourceRef, $errorRef) = &createTexSource($psvn); |
574 | ($currentTexSourceRef, $currentTexErrorRef) = createTexSource($current_psvn); |
| 545 | |
575 | @psvns_to_download = () if(@$currentTexErrorRef); |
| 546 | |
576 | $currentTexSource = $$currentTexSourceRef; |
| 547 | open(OUTPUT, ">${tempDirectory}${texFile}${psvn}.tex") |
577 | $currentTexSource =~ s|\\end\{document\}\s$|\n|s; |
| 548 | || wwerror("Can't create $tempDirectory${texFile}$psvn.tex\n"); |
578 | $cumulativeTexSource .= $currentTexSource; |
| 549 | print OUTPUT $$texSourceRef; |
579 | |
|
|
580 | foreach $current_psvn (@psvns_to_download) { |
|
|
581 | ($currentTexSourceRef, $currentTexErrorRef) = createTexSource($current_psvn); |
|
|
582 | @psvns_to_download = () if(@$currentTexErrorRef); |
|
|
583 | $currentTexSource = $$currentTexSourceRef; |
|
|
584 | $currentTexSource =~ s|^.*?\\begin\{document\}|\n\\newpage\n|s; |
|
|
585 | $currentTexSource =~ s|\\end\{document\}\s$|\n|s; |
|
|
586 | $cumulativeTexSource .= $currentTexSource; |
|
|
587 | } |
|
|
588 | |
|
|
589 | $cumulativeTexSource .= "\n\\end{document}\n"; |
|
|
590 | |
|
|
591 | open TEXOUTPUT, ">$tempTexFileBaseName.tex" |
|
|
592 | or wwerror("Can't open $tempTexFileBaseName.tex for output."); |
|
|
593 | print TEXOUTPUT $cumulativeTexSource; |
| 550 | close OUTPUT; |
594 | close TEXOUTPUT; |
|
|
595 | |
|
|
596 | if(@$currentTexErrorRef) { |
|
|
597 | PG_error_print($tempTexFileBaseName, $current_psvn, @$currentTexErrorRef); |
|
|
598 | } else { |
|
|
599 | $downloadType = lc $downloadType; |
|
|
600 | my $mimeType = prepareHardcopy($tempTexFileBaseName, $downloadType); |
|
|
601 | |
|
|
602 | my ($setName, $userName); |
|
|
603 | &attachProbSetRecord($first_psvn); |
|
|
604 | if($downloadMulti eq "multistudent") { |
|
|
605 | if($num_psvns_to_download == 1) { |
|
|
606 | $setName = getSetNumber($first_psvn); |
|
|
607 | $userName = getStudentLogin($first_psvn); |
|
|
608 | } else { |
|
|
609 | $setName = getSetNumber($first_psvn); |
|
|
610 | $userName = "multistudent"; |
|
|
611 | } |
|
|
612 | } elsif($downloadMulti eq "multiset") { |
|
|
613 | if($num_psvns_to_download == 1) { |
|
|
614 | $setName = getSetNumber($first_psvn); |
|
|
615 | $userName = getStudentLogin($first_psvn); |
|
|
616 | } else { |
|
|
617 | $setName = "multiset"; |
|
|
618 | $userName = getStudentLogin($first_psvn); |
|
|
619 | } |
|
|
620 | } |
|
|
621 | my $hardCopyName = "$Course.$userName.$setName.$downloadType"; |
|
|
622 | |
|
|
623 | open(TEXINPUT, "$tempTexFileBaseName.$downloadType") |
|
|
624 | or wwerror($0, "Can't open $tempTexFileBaseName.$downloadType: $!\n"); |
|
|
625 | print "Content-type: $mimeType\n"; |
|
|
626 | print "Content-disposition: attachment; filename=\"$hardCopyName\"\n\n"; |
|
|
627 | print while (<TEXINPUT>); |
|
|
628 | close TEXINPUT; |
|
|
629 | } |
|
|
630 | } |
| 551 | |
631 | |
| 552 | |
632 | sub prepareHardcopy |
| 553 | print STDERR "Finished making tex file $tempDirectory${texFile}$psvn.tex <br>\n\n" if $debugON; |
633 | { |
|
|
634 | my ($texFileBaseName, $targetFormat) = @_; |
|
|
635 | my $mimeType; |
|
|
636 | |
| 554 | # chdir "$tempDirectory"; |
637 | chdir $tempDirectory; |
| 555 | # umask(022); |
638 | |
| 556 | |
639 | my $dviCommandLine = "$Global::externalLatexPath $texFileBaseName.tex >/dev/null 2>/dev/null"; |
| 557 | # Now that the complete TeX version of the problem set has been |
640 | my $psCommandLine = "$Global::externalDvipsPath -o $texFileBaseName.ps $texFileBaseName.dvi >/dev/null 2>/dev/null"; |
| 558 | # constructed in the $tempDirectory We first attempt to convert it to |
641 | my $pdfCommandLine = "$Global::externalPs2pdfPath $texFileBaseName.ps $texFileBaseName.pdf"; |
| 559 | # postscript, first running TeX and then running dvips The system commands |
642 | |
| 560 | # for this are located in the file makePS which is in the script directory. |
643 | if($targetFormat eq "pdf") { |
| 561 | # If this command fails then an error is reported, otherwise &psPrint |
644 | system($dviCommandLine); -e "$texFileBaseName.dvi" or die "dvi generation failed."; |
| 562 | # ships the postscript file off to the client which requested the download. |
645 | system($psCommandLine); -e "$texFileBaseName.ps" or die "ps generation failed."; |
| 563 | my @PG_COMPILE_ERRORS = @$errorRef; |
646 | system($pdfCommandLine); -e "$texFileBaseName.pdf" or die "pdf generation failed."; |
| 564 | if ( @PG_COMPILE_ERRORS ) { |
647 | $mimeType = "application/pdf"; |
| 565 | &PG_error_print(@PG_COMPILE_ERRORS); |
648 | } elsif($targetFormat eq "ps") { |
| 566 | # $PG_COMPILE_ERRORS contains the number of the first problem with an error. |
649 | system($dviCommandLine); -e "$texFileBaseName.dvi" or die "dvi generation failed."; |
| 567 | return 'errors'; |
650 | system($psCommandLine); -e "$texFileBaseName.ps" or die "ps generation failed."; |
| 568 | } |
651 | $mimeType = "application/postscript"; |
| 569 | else {return 'no_errors';} |
652 | } elsif($targetFormat eq "dvi") { |
|
|
653 | system($dviCommandLine); -e "$texFileBaseName.dvi" or die "dvi generation failed."; |
|
|
654 | $mimeType = "application/x-dvi"; |
|
|
655 | } elsif($targetFormat eq "tex") { |
|
|
656 | $mimeType = "application/tex"; |
|
|
657 | } else { |
|
|
658 | die "unrecognized format: $targetFormat"; |
|
|
659 | } |
|
|
660 | |
|
|
661 | return $mimeType; |
| 570 | } |
662 | } |
| 571 | |
663 | |
| 572 | |
664 | sub PG_error_print |
| 573 | sub psPrint { |
665 | { |
| 574 | open(INPUT, "$tempDirectory${texFile}$psvn.ps") |
666 | my ($tempTexFileBaseName, $current_psvn, @errors) = @_; |
| 575 | or wwerror( $0, "Can't open $tempDirectory${texFile}$psvn.ps: $!\n", "", ""); |
667 | |
| 576 | |
668 | # get set name and student name from psvn |
| 577 | print "Content-disposition: attachment; filename= \"${login_name_for_psvn}_Set${setNumber}.ps\"\n"; |
669 | &attachProbSetRecord($current_psvn); |
| 578 | print "Content-type: application/postscript\n\n"; |
670 | my $userName = &getStudentLogin($current_psvn); |
|
|
671 | my $setName = &getSetNumber($current_psvn); |
|
|
672 | |
|
|
673 | # print error page header |
|
|
674 | print &htmlTOP("PG compile error"); |
|
|
675 | print "<H3>PG error while compiling problem number", (@errors>1) ? 's ' : ' ', |
|
|
676 | join(', ', @errors), " in problem set $setName for $userName.</H3>"; |
|
|
677 | print "<h3>TeX source file:</h3>"; |
|
|
678 | |
|
|
679 | # open temp tex file |
|
|
680 | if(open TEXINPUT, "$tempTexFileBaseName.tex") { |
|
|
681 | print "<pre>\n"; |
|
|
682 | my $lineNumber = 1; |
| 579 | while (<INPUT>) { |
683 | while(<TEXINPUT>) { |
| 580 | print; |
684 | if(/<A NAME/) { print $_; } |
| 581 | } |
685 | else { print protect_HTML("$lineNumber $_"), "\n"; } |
| 582 | close INPUT; |
686 | $lineNumber++; |
| 583 | print STDERR "Finished TeX $texFile for $login_name_for_psvn in $Course\n" if $debugON; |
687 | } |
| 584 | |
688 | print "</pre>\n"; |
|
|
689 | close TEXINPUT; |
|
|
690 | } else { |
|
|
691 | print "<p>Unable to open TeX source file:<br><tt>$tempTexFileBaseName.tex</tt></p>"; |
|
|
692 | } |
|
|
693 | |
|
|
694 | # print page footer |
|
|
695 | print &htmlBOTTOM("welcomeAction.pl", \%inputs); |
|
|
696 | exit; |
| 585 | } |
697 | } |
| 586 | |
698 | |
| 587 | sub pdfPrint { |
699 | # ----- |
| 588 | |
|
|
| 589 | system( "${scriptDirectory}makePDF $tempDirectory ${texFile}$psvn 1>&2" ) == 0 |
|
|
| 590 | or wwerror("$0", "Unable to create PDF output using makePDF file:<BR> ${scriptDirectory}makePDF $tempDirectory ${texFile}$psvn 1>&2<BR>Error is: $!", "", ""); |
|
|
| 591 | open(INPUT, "$tempDirectory${texFile}$psvn.pdf") |
|
|
| 592 | || wwerror("$0", "Can't open $tempDirectory${texFile}$psvn.pdf: $!\n","",""); |
|
|
| 593 | |
|
|
| 594 | print "Content-type: application/pdf\n\n" ; |
|
|
| 595 | print "Content-disposition: attachment; filename= \"${login_name_for_psvn}_Set${setNumber}.pdf\"\n"; |
|
|
| 596 | #print "Content-type: application/pdf\n\n" ; |
|
|
| 597 | while (<INPUT>) { |
|
|
| 598 | print; |
|
|
| 599 | } |
|
|
| 600 | close INPUT; |
|
|
| 601 | print STDERR "Finished TeX $texFile for $login_name_for_psvn in $Course\n" if $debugON; |
|
|
| 602 | |
|
|
| 603 | } |
|
|
| 604 | |
|
|
| 605 | sub texPrint { |
|
|
| 606 | open(INPUT, "$tempDirectory${texFile}$psvn.tex") || |
|
|
| 607 | wwerror("$0", "Can't open $tempDirectory${texFile}$psvn.tex:<BR> $!\n", "", ""); |
|
|
| 608 | |
|
|
| 609 | print "Content-disposition: attachment; filename= \"${login_name_for_psvn}_Set${setNumber}.tex\"\n"; |
|
|
| 610 | print "Content-type: application/tex\n\n"; |
|
|
| 611 | |
|
|
| 612 | while (<INPUT>) { |
|
|
| 613 | print; |
|
|
| 614 | } |
|
|
| 615 | close INPUT; |
|
|
| 616 | } |
|
|
| 617 | |
|
|
| 618 | sub dviPrint { |
|
|
| 619 | open(INPUT, "$tempDirectory${texFile}$psvn.dvi") || |
|
|
| 620 | wwerror("$0", "Can't open $tempDirectory${texFile}$psvn.dvi:<BR> $!\n", "", ""); |
|
|
| 621 | |
|
|
| 622 | print "Content-disposition: attachment; filename= \"${login_name_for_psvn}_Set${setNumber}.dvi\"\n"; |
|
|
| 623 | print "Content-type: application/x-dvi\n\n" ; |
|
|
| 624 | while (<INPUT>) { |
|
|
| 625 | print; |
|
|
| 626 | } |
|
|
| 627 | close INPUT; |
|
|
| 628 | } |
|
|
| 629 | |
700 | |
| 630 | sub logPrint { |
701 | sub logPrint { |
| 631 | print &htmlTOP("TeX Error or error in creating PostScript file"); |
702 | print &htmlTOP("TeX Error or error in creating PostScript file"); |
| 632 | open (LOGFILE, " $tempDirectory$texFile$psvn.log") |
703 | open (LOGFILE, " $tempDirectory$texFile$psvn.log") |
| 633 | || print "<H3>Can't open log file:</H3> path= $tempDirectory$texFile$psvn.log<BR>$!<BR><BR>" ; |
704 | || print "<H3>Can't open log file:</H3> path= $tempDirectory$texFile$psvn.log<BR>$!<BR><BR>" ; |
| … | |
… | |
| 667 | $line =~s/\&/&/g; |
738 | $line =~s/\&/&/g; |
| 668 | $line =~s/</</g; |
739 | $line =~s/</</g; |
| 669 | $line =~s/>/>/g; |
740 | $line =~s/>/>/g; |
| 670 | $line; |
741 | $line; |
| 671 | } |
742 | } |
| 672 | sub PG_error_print { |
|
|
| 673 | my @probNums = @_; |
|
|
| 674 | open (TEXFILE, "${tempDirectory}${texFile}${psvn}.tex") |
|
|
| 675 | || ! $debugON || print STDERR "Can't open $tempDirectory$texFile$psvn.tex" ; |
|
|
| 676 | print &htmlTOP("PG compile error"); |
|
|
| 677 | print "<H3>PG error while compiling problem number", |
|
|
| 678 | (@probNums>1) ? 's ' : ' ', |
|
|
| 679 | join(',', @probNums), |
|
|
| 680 | "</H3>"; |
|
|
| 681 | print "(Search for "ERROR" to find the line where the error occurs.)"; |
|
|
| 682 | print "<H3>TeX Source File:</H3>"; |
|
|
| 683 | print "<PRE>"; |
|
|
| 684 | my $lineNumber = 1; |
|
|
| 685 | local($/) = "\n"; |
|
|
| 686 | while (<TEXFILE>) { |
|
|
| 687 | if ( $_ =~/^<A NAME/ ) { # skip lines starting with a destination anchor |
|
|
| 688 | print $_; |
|
|
| 689 | } else { |
|
|
| 690 | print protect_HTML("$lineNumber $_")."\n"; |
|
|
| 691 | } |
|
|
| 692 | $lineNumber++; |
|
|
| 693 | } |
|
|
| 694 | close(TEXFILE); |
|
|
| 695 | print &htmlBOTTOM("downloadPS.pl", \%inputs); |
|
|
| 696 | } |
|
|
| 697 | |
|
|
| 698 | sub selectionError { |
743 | sub selectionError { |
| 699 | print &htmlTOP("Selection error"); |
744 | print &htmlTOP("Selection error"); |
| 700 | print"<H2>Error:</H2> You must first select a problem set in order to download a hard copy!\n"; |
745 | print"<H2>Error:</H2> You must first select a problem set in order to download a hard copy!\n"; |
| 701 | print "<FORM METHOD=POST ACTION=\"${Global::cgiWebworkURL}welcome.pl\"><P>"; |
746 | print "<FORM METHOD=POST ACTION=\"${Global::cgiWebworkURL}welcome.pl\"><P>"; |
| 702 | print &sessionKeyInputs(\%inputs); |
747 | print &sessionKeyInputs(\%inputs); |
| … | |
… | |
| 756 | </TD> |
801 | </TD> |
| 757 | </TABLE> |
802 | </TABLE> |
| 758 | }; |
803 | }; |
| 759 | $title_bar; |
804 | $title_bar; |
| 760 | } |
805 | } |
| 761 | |
|
|
| 762 | sub downloadIndividualSet { |
|
|
| 763 | system("/usr/bin/renice +$main::DOWNLOAD_NICE -p $$ 1>/dev/null") && warn "Could not renice process. pid $$"; |
|
|
| 764 | alarm( $main::DOWNLOAD_TIME_OUT_CONSTANT); |
|
|
| 765 | my $return_status=''; |
|
|
| 766 | eval {$return_status = downloadPS($psvn,$texFile)}; ## trap any errors |
|
|
| 767 | $save_errors=$@; ## errors will be printed out by END |
|
|
| 768 | if ($return_status eq 'errors') {exit;} |
|
|
| 769 | elsif ($return_status eq 'no_errors') { |
|
|
| 770 | if ($downloadType eq "TeX" ) { |
|
|
| 771 | &texPrint; |
|
|
| 772 | } |
|
|
| 773 | elsif (system( "${scriptDirectory}makePS $tempDirectory $texFile$psvn 1>&2" )) { |
|
|
| 774 | &logPrint; |
|
|
| 775 | # wwerror("$0", "downloadPS: Error in creating postscript file. <BR> |
|
|
| 776 | # System command ${scriptDirectory}makePS $tempDirectory $texFile$psvn 1>&2", "", ""); |
|
|
| 777 | } |
|
|
| 778 | else { # tex file has been processed successfully |
|
|
| 779 | if ($downloadType eq 'pdf') {&pdfPrint;} |
|
|
| 780 | elsif ($downloadType eq 'dvi') {&dviPrint;} |
|
|
| 781 | else {&psPrint;} |
|
|
| 782 | } |
|
|
| 783 | } |
|
|
| 784 | else {wwerror($0, "The subroutine downloadPS returned an unknown status");} |
|
|
| 785 | } |
|
|
| 786 | |
|
|
| 787 | sub downloadAllSets { |
|
|
| 788 | system("/usr/bin/renice +$main::CLASS_DOWNLOAD_NICE -p $$ 1>/dev/null") && warn "Could not renice process. pid $$"; |
|
|
| 789 | alarm( $main::CLASS_DOWNLOAD_TIME_OUT_CONSTANT); |
|
|
| 790 | my $localpsvn; ## psvn numbers for individual students |
|
|
| 791 | my $return_status=''; |
|
|
| 792 | my $texSource =''; |
|
|
| 793 | my $individualTexSource =''; |
|
|
| 794 | my ($texSourceRef, $errorRef); |
|
|
| 795 | |
|
|
| 796 | my @local_psvns = $query -> param('local_psvns'); |
|
|
| 797 | |
|
|
| 798 | my $max = $Global::max_num_of_ps_downloads_allowed; |
|
|
| 799 | |
|
|
| 800 | ## make sure non professors can not download more than one set by submitting an altered form |
|
|
| 801 | @local_psvns = ($local_psvns[0]) unless $permissions == $Global::instructor_permissions; |
|
|
| 802 | |
|
|
| 803 | my $length = @local_psvns; |
|
|
| 804 | |
|
|
| 805 | if ($length > $max) { |
|
|
| 806 | wwerror ("Too many students selected", "The maximun number of sets which can be downloaded at one time is $max. You selected $length. |
|
|
| 807 | Go back and select fewer students. This maximun is set by the variable |
|
|
| 808 | \$max_num_of_ps_downloads_allowed in Global.pm."); |
|
|
| 809 | } |
|
|
| 810 | $localpsvn = shift @local_psvns; ## get first set which will contain TeX header info |
|
|
| 811 | # attachProbSetRecord($localpsvn); |
|
|
| 812 | ($texSourceRef, $errorRef) = &createTexSource($localpsvn); |
|
|
| 813 | ## don't do anything with $errorRef at this time |
|
|
| 814 | ## only contains prob numbers of bad problems |
|
|
| 815 | $texSource = $$texSourceRef; ## contains initial header info |
|
|
| 816 | $texSource =~ s|\\end\{document\}\s$|\n|s; ## remove end{document} statement |
|
|
| 817 | |
|
|
| 818 | foreach $localpsvn (@local_psvns) { ## get the rest of the sets and strip TeX header info |
|
|
| 819 | # attachProbSetRecord($localpsvn); |
|
|
| 820 | ($texSourceRef, $errorRef) = &createTexSource($localpsvn); |
|
|
| 821 | ## don't do anything with $errorRef at this time |
|
|
| 822 | ## only contains prob numbers of bad problems |
|
|
| 823 | $individualTexSource = $$texSourceRef; |
|
|
| 824 | $individualTexSource =~ s|^.*?\\begin\{document\}|\n\\newpage\n|s; ## remove header material and start new page |
|
|
| 825 | $individualTexSource =~ s|\\end\{document\}\s$|\n|s; ## remove end{document} statement |
|
|
| 826 | $texSource .= $individualTexSource; |
|
|
| 827 | } |
|
|
| 828 | $texSource .= "\n\\end{document}\n"; ## append end{document} statement |
|
|
| 829 | |
|
|
| 830 | $psvn = -1; |
|
|
| 831 | $texFile = "set${setNumber}.tempTex-CGIscript"; |
|
|
| 832 | $login_name_for_psvn = 'all_students'; |
|
|
| 833 | |
|
|
| 834 | open(OUTPUT, ">${tempDirectory}${texFile}${psvn}.tex") |
|
|
| 835 | || wwerror("Can't create $tempDirectory${texFile}$psvn.tex\n"); |
|
|
| 836 | print OUTPUT $texSource; |
|
|
| 837 | close OUTPUT; |
|
|
| 838 | |
|
|
| 839 | # so here we are. we've just generated a whole crapload of TeX source and saved it |
|
|
| 840 | # to a temporary file. Now we're ready to convert it to one of several output formats. |
|
|
| 841 | |
|
|
| 842 | # TeX: this is the easiest. All we have to do is add some headers and spit it back. |
|
|
| 843 | # PostScript: |
|
|
| 844 | |
|
|
| 845 | if ($downloadType eq "TeX" ) { |
|
|
| 846 | &texPrint; |
|
|
| 847 | } |
|
|
| 848 | elsif (system( "${scriptDirectory}makePS $tempDirectory $texFile$psvn 1>&2" )) { |
|
|
| 849 | &logPrint; |
|
|
| 850 | } |
|
|
| 851 | else { # tex file has been processed successfully |
|
|
| 852 | if ($downloadType eq 'pdf') {&pdfPrint;} |
|
|
| 853 | elsif ($downloadType eq 'dvi') {&dviPrint;} |
|
|
| 854 | else {&psPrint;} |
|
|
| 855 | } |
|
|
| 856 | } |
|
|
| 857 | |
|
|
| 858 | |
|
|
| 859 | |
|
|
| 860 | |
806 | |
| 861 | sub hackerError { ## prints hacker error message |
807 | sub hackerError { ## prints hacker error message |
| 862 | |
808 | |
| 863 | my $msg = "Attempt to hack into WeBWorK \n Remote Host is: ". remote_host()."\n"; |
809 | my $msg = "Attempt to hack into WeBWorK \n Remote Host is: ". remote_host()."\n"; |
| 864 | $msg .= query_string; |
810 | $msg .= query_string; |
| … | |
… | |
| 991 | unless (defined($action ) and ($action eq 'Do problem set' or $action eq 'Do_problem_set')) { |
937 | unless (defined($action ) and ($action eq 'Do problem set' or $action eq 'Do_problem_set')) { |
| 992 | my $ERRORS = $save_errors; |
938 | my $ERRORS = $save_errors; |
| 993 | unless ($debugON) { #clean up the directory |
939 | unless ($debugON) { #clean up the directory |
| 994 | eval { |
940 | eval { |
| 995 | chdir $tempDirectory; |
941 | chdir $tempDirectory; |
| 996 | unlink("$texFile$psvn.dvi", "$texFile$psvn.ps","$texFile$psvn.pdf", |
942 | unlink( |
| 997 | "$texFile$psvn.log", "$texFile$psvn.aux", |
943 | "#tempTexFileBaseName.dvi", |
|
|
944 | "$tempTexFileBaseName.ps", |
|
|
945 | "$tempTexFileBaseName.pdf", |
|
|
946 | "$tempTexFileBaseName.log", |
|
|
947 | "$tempTexFileBaseName.aux", |
| 998 | "$texFile$psvn.tex",); |
948 | "$tempTexFileBaseName.tex" |
|
|
949 | ); |
| 999 | unlink("${tempDirectory}eps/${login_name_for_psvn}*.eps"); |
950 | unlink("${tempDirectory}eps/${login_name_for_psvn}*.eps"); |
| 1000 | }; # clean up |
951 | }; # clean up |
| 1001 | $ERRORS .= $ERRORS . $@; |
952 | $ERRORS .= $ERRORS . $@; |
| 1002 | } |
953 | } |
| 1003 | my $query = query_string(); |
954 | my $query = query_string(); |
| … | |
… | |
| 1073 | } |
1024 | } |
| 1074 | # end Timing code |
1025 | # end Timing code |
| 1075 | cleanup_downloadPS(); |
1026 | cleanup_downloadPS(); |
| 1076 | } |
1027 | } |
| 1077 | |
1028 | |
| 1078 | |
|
|
| 1079 | ######## DEBUGGING TOOLS |
|
|
| 1080 | |
|
|
| 1081 | # sub downloadPS_dumpvar { |
|
|
| 1082 | # my ($packageName) = @_; |
|
|
| 1083 | # |
|
|
| 1084 | # local(*alias); |
|
|
| 1085 | # |
|
|
| 1086 | # |
|
|
| 1087 | # *stash = *{"${packageName}::"}; |
|
|
| 1088 | # $, = " "; |
|
|
| 1089 | # |
|
|
| 1090 | # print OUTPUT "Content-type: text/html\n\n<PRE>\n"; |
|
|
| 1091 | # |
|
|
| 1092 | # |
|
|
| 1093 | # while ( ($varName, $globValue) = each %stash) { |
|
|
| 1094 | # print OUTPUT "$varName =================================\n"; |
|
|
| 1095 | # |
|
|
| 1096 | # *alias = $globValue; |
|
|
| 1097 | # next if $varName=~/main/; |
|
|
| 1098 | # next unless $varName =~/::/; |
|
|
| 1099 | # |
|
|
| 1100 | # if (defined($alias) ) { |
|
|
| 1101 | # print OUTPUT "\t \$$varName $alias \n"; |
|
|
| 1102 | # } |
|
|
| 1103 | # |
|
|
| 1104 | # if ( defined(@alias) ) { |
|
|
| 1105 | # print OUTPUT "\t \@$varName @alias \n"; |
|
|
| 1106 | # } |
|
|
| 1107 | # if (defined(%alias) ) { |
|
|
| 1108 | # print OUTPUT "\t \%$varName \n"; |
|
|
| 1109 | # foreach $key (keys %alias) { |
|
|
| 1110 | # print OUTPUT "\t\t $key => $alias{$key}\n"; |
|
|
| 1111 | # } |
|
|
| 1112 | # |
|
|
| 1113 | # |
|
|
| 1114 | # } |
|
|
| 1115 | # } |
|
|
| 1116 | # |
|
|
| 1117 | # |
|
|
| 1118 | # |
|
|
| 1119 | # } |
|
|
| 1120 | |
|
|
| 1121 | |
|
|
| 1122 | 1; |
1029 | 1; |