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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 112 - (download) (as text) (annotate)
Fri Aug 10 15:35:24 2001 UTC (18 years, 6 months ago) by sh002i
File size: 41906 byte(s)
1. Fixed prepareHardcopy. Actually works now.
2. Incorporated old error reporting code into downloadAllSets
This file is incredibly hairy and should be cleaned up/split up a.s.a.p...

    1 #!/usr/local/bin/webwork-perl
    2 
    3 
    4 ################################################################
    5 #  Copyright @1995-1999 by Michael E. Gage, Arnold K. Pizer and
    6 #  WeBWorK at the University of Rochester. All rights reserved.
    7 ################################################################
    8 
    9 my $debugON=0;      ## set this to 1 to save debugging information for errors in hardcopy output
   10 
   11 use lib '.'; use webworkInit; # WeBWorKInitLine
   12 require 5.001;
   13 
   14 $/ ="\n";
   15 
   16 use strict;
   17 use Global;
   18 use Auth;
   19 use CGI qw(:standard);
   20 use Net::SMTP;
   21 use Safe;
   22 
   23 
   24 use PGtranslator;
   25 #use sigtrap;
   26 BEGIN {
   27   # set to 1 to enable timing_log
   28   # (contains information about time taken by scripts to run)
   29   $main::logTimingData = 0;
   30 
   31   # begin Timing code
   32   if( $main::logTimingData == 1 ) {
   33     use Benchmark;
   34     $main::beginTime = new Benchmark;
   35   }
   36   # end Timing code
   37 
   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
   40    $main::DOWNLOAD_TIME_OUT_CONSTANT = 300;         # give it five minutes
   41    $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
   44 
   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
   47 # ## modifes the die and warn labels. Finding the right warning mechanism using these two
   48 # ## methods bears further investigation
   49 # ## They are defined in Global.pm
   50    $SIG{'FPE'}  = \&Global::PG_floating_point_exception_handler;
   51    $SIG{__WARN__}=\&Global::PG_warnings_handler;
   52    $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"; };
   54    $SIG{ALRM} = sub { $main::SIG_TIME_OUT = 1; exit(0) };
   55 
   56    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.
   58 #
   59 };
   60 
   61 use vars qw ($modules_to_evaluate $extra_packages_to_be_loaded
   62   );
   63 
   64 &CGI::ReadParse;
   65 my %inputs=%main::in;
   66 
   67 my $query = $main::in{CGI};
   68 
   69 # verify that the rest of the information has been received
   70 my $Course = $inputs{'course'};
   71 my $User = $inputs{'user'};
   72 
   73 #my $psvn = $inputs{'probSetKey'};
   74 
   75 my @local_psvns = $query -> param('local_psvns');
   76 my $psvn = $local_psvns[0]; ## get the first one for doing problem sets
   77 $inputs{'probSetKey'} = $psvn;  ## only used by htmlBOTTOM
   78 my $Session_key = $inputs{'key'};
   79 
   80 
   81 &Global::getCourseEnvironment($Course);
   82 
   83 my $scriptDirectory       = getWebworkScriptDirectory();    #$Global::scriptDirectory;
   84 my $databaseDirectory     = getCourseDatabaseDirectory();   #$Global::databaseDirectory;
   85 my $courseScriptsDirectory  = getCourseScriptsDirectory();    #$Global::courseScriptsDirectory;
   86 my $templateDirectory     = getCourseTemplateDirectory();         #$Global::templateDirectory;
   87 
   88 # this is globally defined for the file, since it is needed for cleanup in END
   89 my $tempDirectory            = getCourseTempDirectory();
   90 
   91 eval{require "${courseScriptsDirectory}$Global::displayMacros_pl";} ;
   92 eval{require "${scriptDirectory}$Global::DBglue_pl";};
   93 eval{require "${scriptDirectory}$Global::classlist_DBglue_pl";};
   94 eval{require "${scriptDirectory}$Global::HTMLglue_pl";};
   95 eval{require "${scriptDirectory}$Global::FILE_pl";} ;
   96 
   97 
   98 
   99 ####################################################################
  100 # load the modules to be used in PGtranslator
  101 
  102 require "${courseScriptsDirectory}PG_module_list.pl" or
  103     wwerror($0, "Can't read ${courseScriptsDirectory}PG_module_list.pl");
  104 ####################################################################
  105 
  106 my $keyFile = &Global::getCourseKeyFile($Course);
  107 my $permissionsFile = &getCoursePermissionsFile($Course);
  108 
  109 ## check to see if prob set has been selected ##
  110 verifyInput();
  111 
  112 ##############################################
  113 sub verifyInput {
  114 
  115     if(!defined($psvn)  || $psvn eq "") {
  116   &selectionError; # The calling script did not specify a problem set.
  117         #die "Content-type: text/html\n\nThe calling script did not specify a problem set.";
  118         exit();
  119     }
  120 }
  121 
  122 # log access
  123   &Global::log_info('', query_string);
  124 
  125 
  126 &verify_key($inputs{'user'}, $Session_key, $keyFile, $Course);
  127 
  128 my $permissions = &get_permissions($User,$permissionsFile);
  129 
  130 &attachProbSetRecord($psvn);
  131 my $login_name_for_psvn = &getStudentLogin($psvn);
  132 attachCLRecord($login_name_for_psvn);
  133 
  134 my $setNumber=&getSetNumber($psvn);
  135 $setNumber = $inputs{'setNo'} if defined $inputs{'setNo'};  ## script called from profChangeDates.pl
  136 
  137 
  138 
  139 ###### check to see that it is after the open date
  140 my ($currentTime,$odts,$ddts,$remainingTime, $TimeString);
  141 $currentTime = time;
  142 $odts=&getOpenDate($psvn);
  143 $ddts=&getDueDate($psvn);
  144 $remainingTime=$ddts-$currentTime;
  145 
  146 if($currentTime<$odts && $permissions !=$Global::instructor_permissions) {
  147   print &htmlTOP("Before open date error");
  148   print "<CENTER><h2>Sorry, cannot download or do problem set $setNumber yet.
  149   <BR>It is before the open date.</h2></CENTER>";
  150   print &htmlBOTTOM("downloadPS.pl",\%inputs);
  151     exit(0);
  152 }
  153 
  154 my %PSVNHashForSet = %{getPSVNHashForSet($setNumber)};
  155 my $action = $inputs{'action'};
  156 my $downloadType= $inputs{'downloadType'}; # either pdf, ps, tex, or dvi
  157 
  158 # Verify that the problem set has been created if a psvn number has been passed
  159 unless ($action eq 'Get_all_copies') {
  160     unless (defined $PSVNHashForSet{$psvn} ) {
  161       print   &htmlTOP("Problem set version number $psvn not created");
  162         print ( "Pin number $psvn was not created for set $setNumber");
  163         print   &htmlBOTTOM("downloadPS.pl", \%inputs);
  164         exit(0);
  165     }
  166 }
  167 
  168 my $texFile = "${login_name_for_psvn}.tempTex-CGIscript";
  169 my $save_errors='';
  170 
  171 if ($action eq 'Do problem set' or $action eq 'Do_problem_set') {displayProbSet();}
  172 #elsif ($action eq 'Get hard copy' or $action eq 'Get_hard_copy') {downloadIndividualSet();}
  173 elsif ($action eq 'Get hard copy' or $action eq 'Get_hard_copy') {downloadAllSets();}
  174 elsif ($action eq 'Get_all_copies') {downloadAllSets();}
  175 else {wwerror($0, "Unknown action: $action");}
  176 
  177 
  178 # begin Timing code
  179 # my $endTime = new Benchmark;
  180 # &Global::logTimingInfo($main::beginTime,$endTime,$0,$Course,$User);
  181 # end Timing code
  182 
  183  exit;
  184 #############################################
  185 
  186 sub displayProbSet {
  187     my $studentName=&CL_getStudentName($login_name_for_psvn);
  188     my $probHeaderFileName = &getProbHeaderFileName($psvn);
  189 
  190     my @problems=sort numerical &getAllProblemsForProbSetRecord($psvn);
  191     sub numerical { $a <=> $b};
  192 
  193     my $numberOfProblems=0;
  194     my $prob;
  195     foreach $prob (@problems) {$numberOfProblems++;}
  196 
  197 
  198     print &probSet_htmlTOP("Problem Set $setNumber from  $inputs{'course'} for $studentName");
  199             #see subroutines at the bottom of this file
  200                     #this allows the use of a small gif for the webwork logo
  201                     #and takes up less screen real estate.
  202 
  203     print &probSet_titleBar("Problem Set $setNumber from  $inputs{'course'} for $studentName");
  204 
  205     print <<"ENDOFHTML";
  206 <TABLE BORDER=1>
  207   <TR>
  208     <!-- Row 1 Column 1 -->
  209     <TD>
  210 
  211 Select one of the $numberOfProblems problems to try:
  212 <FORM METHOD=POST ACTION="$Global::processProblem_CGI">
  213 <INPUT TYPE=HIDDEN NAME=probSetKey VALUE=$psvn>
  214 <P>
  215 <SELECT NAME=probNum SIZE=11>
  216 ENDOFHTML
  217 
  218     my ($problem,$problemAttempted, $problemStatus,$longProblemStatus);
  219     foreach $problem(@problems) {
  220       $problemStatus = getProblemStatus($problem,$psvn);
  221       $problemAttempted = getProblemAttempted($problem,$psvn);
  222 
  223       if (!$problemAttempted) {
  224         $longProblemStatus  = '';  # default value
  225       }   elsif   ($problemStatus  >= 0 and $problemStatus <=1 ) {
  226           my $percentCorr = int(100*$problemStatus+.5);
  227         $longProblemStatus    = "${percentCorr}\% correct"
  228       } else  {
  229         $longProblemStatus  = 'unknown status';  # default value
  230       }
  231       print "<OPTION VALUE=$problem>Problem $problem -- $longProblemStatus </OPTION>\n";
  232   }
  233 
  234   ## nice note to warn if there's less than one day left to complete problem set
  235     if ($remainingTime<86400 && $remainingTime>0)  {
  236       $TimeString = "<BR><RM>Note: you have less than one day left
  237              to complete this problem set</EM>";
  238     }
  239     else  {
  240       $TimeString = "";
  241     }
  242 
  243     print <<"ENDOFHTML";
  244 </SELECT>
  245 <BR>
  246 ENDOFHTML
  247 
  248 
  249   my $practiceUser = $Global::practiceUser;
  250   if (($currentTime > $ddts) or ($User =~ /^$practiceUser/)) {
  251     print q!<INPUT type="checkbox" name="show_old_answers" value=1> Show my old answers<BR>!;
  252   }
  253   else {
  254     print q!<INPUT type="checkbox" name="show_old_answers" checked value=1> Show my old answers<BR>!;
  255   }
  256 
  257     print &sessionKeyInputs(\%inputs);
  258     my $mode = $inputs{'Mode'};
  259     $mode = $Global::htmlModeDefault unless ($mode);
  260     &displaySelectModeLine($mode);    ## displays mode select buttons
  261             ## the sub displaySelectModeLine is in
  262             ## "${courseScriptsDirectory}$Global::displayMacros_pl"
  263     print <<"ENDOFHTML";
  264 <BR>
  265 <INPUT TYPE=SUBMIT VALUE="Get Problem">
  266 $TimeString
  267 
  268 </FORM>
  269 
  270 ENDOFHTML
  271 
  272     print "<FORM METHOD=POST ACTION=\"${Global::cgiWebworkURL}welcome.pl\"><P>";
  273     print &sessionKeyInputs(\%inputs);
  274 
  275     print <<"ENDOFHTML";
  276 <INPUT TYPE=HIDDEN NAME="probSetKey" VALUE=$psvn>
  277 <INPUT TYPE=SUBMIT VALUE="Problem Sets">
  278 </FORM>
  279 
  280 
  281     </TD>
  282     <!-- Row 1 Column 2 -->
  283     <TD>
  284 ENDOFHTML
  285 
  286 
  287 ##  process problem and save @printlines
  288     my $probHeader = $Global::PROB_HEADER;  # default value
  289 
  290     if ( (defined($probHeaderFileName)) and  ($probHeaderFileName =~ /\S/)) {
  291       $probHeader = $probHeaderFileName;
  292     }
  293         ## use $probHeader as default unless $probHeaderFileName is defined
  294         ## in the set definition file
  295     my $source;
  296     if (-e "${templateDirectory}$probHeader" ) {
  297         unless (-r "${templateDirectory}$probHeader") {
  298           wwerror($0, "Can't read ${templateDirectory}$probHeader");
  299         }
  300         open(PROB,"<${templateDirectory}$probHeader");
  301         $source = join("",<PROB>);
  302         close(PROB);
  303     }
  304     my %envir=defineProblemEnvir($mode,0,$psvn,$Course);
  305          my $pt = new PGtranslator;  #pt stands for problem translator;
  306          $pt->environment(\%envir);
  307        $pt->initialize();
  308        $pt-> set_mask();
  309        $pt->source_string($source);
  310        $pt -> unrestricted_load("${courseScriptsDirectory}PG.pl");
  311          $pt -> unrestricted_load("${courseScriptsDirectory}dangerousMacros.pl");
  312        $pt ->translate();
  313        my $PG_PROBLEM_TEXT_REF = $pt->ra_text();
  314        my $PG_HEADER_TEXT_REF = $pt->r_header;#\$PG_HEADER_TEXT;
  315        my $PG_ANSWER_HASH_REF = $pt->rh_correct_answers;
  316        my $PG_FLAGS_REF =$pt ->rh_flags;
  317 
  318 
  319 
  320     my @printlines;
  321     if($mode eq "HTML" || $mode eq 'HTML_tth') {
  322       @printlines=@{$pt->ra_text()};
  323     }
  324     elsif ($mode eq 'Latex2HTML') {
  325       @printlines = &createDisplayedInsert($setNumber,
  326                     $probHeader,$psvn,$Course,$pt->ra_text());
  327     }
  328     print @printlines;
  329     print <<"ENDOFHTML";
  330     </TD>
  331   </TR>
  332 </TABLE>
  333 ENDOFHTML
  334 print &htmlBOTTOM('welcomeAction.pl', \%inputs,'probSetHelp.html');
  335 exit;
  336 } ## end of problem selection form and end of sub displayProbSet
  337 
  338 ####################
  339 ## subroutines
  340 ####################
  341 
  342 $/ = "\n";
  343 sub createTexSource {
  344     my $psvn = shift;
  345 
  346     # check that the psvn corresponds to the user and that it is after the open
  347     # date.  This should only fail if someone is trying to break into WeBWorK.
  348 
  349     &attachProbSetRecord($psvn);
  350     $login_name_for_psvn = &getStudentLogin($psvn);
  351   attachCLRecord($login_name_for_psvn);
  352 
  353     if ( ( ( $User ne &getStudentLogin($psvn)) ||($currentTime < $odts) )
  354             and ($permissions != $Global::instructor_permissions)
  355                 and ($permissions != $Global::TA_permissions)
  356         )   {
  357     &hackerError;
  358     exit;
  359   }
  360 
  361     my $probSetHeader = $Global::SET_HEADER;
  362 
  363     my $setHeaderFileName = &getSetHeaderFileName($psvn);
  364 
  365     my $answersRequestedQ = 0;
  366   $answersRequestedQ=  $inputs{'ShowAns'} if defined($inputs{'ShowAns'});
  367 
  368     my $adts=&getAnswerDate($psvn);
  369     my $displayCorrectAnswersQ = 0;  #initialize
  370     $displayCorrectAnswersQ =1 if  $answersRequestedQ && ($currentTime > $adts);
  371   $displayCorrectAnswersQ =1 if $answersRequestedQ && ($permissions == $Global::instructor_permissions);
  372 
  373 
  374 #    chdir "$tempDirectory";
  375 #    umask(022);
  376 
  377     my $texSource ='';
  378 
  379 #   open(OUTPUT, ">${tempDirectory}${texFile}${psvn}.tex")
  380 #|| wwerror("Can't create $tempDirectory${texFile}$psvn.tex\n");
  381 
  382 
  383 
  384     print STDERR "%%Creating a tex version of set $setNumber<BR>\n" if $debugON;
  385     print STDERR "%%For", &CL_getStudentName($login_name_for_psvn), "psvn=$psvn<BR>\n" if $debugON;
  386 
  387 
  388     # input TeX preamble
  389 #   print OUTPUT &texInput($Global::TEX_SET_PREAMBLE);
  390     $texSource = &texInput($Global::TEX_SET_PREAMBLE);
  391 
  392     # print TeX Header
  393 #   print OUTPUT &texInput($Global::TEX_SET_HEADER);
  394     $texSource .= &texInput($Global::TEX_SET_HEADER);
  395 
  396     # Print setheader
  397     my $mode = "TeX";
  398     my @PG_COMPILE_ERRORS = ();
  399   if ( (defined($setHeaderFileName)) and  $setHeaderFileName =~ /\S/) {
  400     $probSetHeader = $setHeaderFileName;
  401   }
  402         ## use $probSetHeader as default unless $setHeaderFileName is defined
  403         ## in the set definition file
  404     if ( open(INPUT,"${templateDirectory}$probSetHeader") ) {
  405 
  406 #                 ##Determine language
  407 
  408         $probSetHeader =~ /\.([^\.]*)$/;
  409         my $displayMode = $1;
  410 
  411         if ($displayMode eq 'pg') {
  412       my %envir=defineProblemEnvir($mode,0, $psvn,$Course,undef());
  413       my $input_string=  join("",<INPUT> );
  414             my ($PG_PROBLEM_TEXT_REF, $PG_HEADER_TEXT_REF, $PG_ANSWER_HASH_REF, $PG_FLAGS_REF);
  415             my $pt = new PGtranslator;  #pt stands for problem translator;
  416       $pt -> evaluate_modules( @{main::modules_to_evaluate}) ;
  417           $pt -> load_extra_packages(@{main::extra_packages_to_be_loaded});
  418 
  419           # The variables in the two preceding lines are  defined in PG_module_list.pl
  420           # require "${courseScriptsDirectory}PG_module_list.pl";
  421           # (Modules are defined by  require statement above found near the top of this file, outside the loop.)
  422             $pt->environment(\%envir);
  423       $pt->initialize();
  424       $pt-> set_mask();
  425       $pt->source_string($input_string);
  426         $pt -> unrestricted_load("${courseScriptsDirectory}PG.pl");
  427         $pt -> unrestricted_load("${courseScriptsDirectory}dangerousMacros.pl");
  428         $pt ->translate();
  429         $PG_PROBLEM_TEXT_REF = $pt->ra_text();
  430       $PG_HEADER_TEXT_REF = $pt->r_header;#\$PG_HEADER_TEXT;
  431       $PG_ANSWER_HASH_REF = $pt->rh_correct_answers;
  432       $PG_FLAGS_REF =$pt ->rh_flags;
  433 #             print OUTPUT @{$PG_PROBLEM_TEXT_REF};
  434             $texSource .= join '', @{$PG_PROBLEM_TEXT_REF};
  435 
  436         } else {
  437 #         print OUTPUT "Don't understand languages with extension $displayMode.<BR>\n";
  438             $texSource .= "Don't understand languages with extension $displayMode.<BR>\n";
  439         }
  440     close INPUT;
  441     } else {
  442     print STDERR ( "Can't open ${templateDirectory}${probSetHeader}\n") if $debugON;
  443       wwerror("$0", "\n######## Could not open the set header file: ${templateDirectory}${probSetHeader}","","");
  444     }
  445 
  446 
  447     # Print problems
  448     my @problems = sort {$a <=> $b } &getAllProblemsForProbSetRecord($psvn);
  449     my @refSubmittedAnswers = ();
  450    # print "content-type: text/plain\n\nproblems @problems";
  451 
  452     my $probNum;
  453     foreach $probNum (@problems) {
  454       my $source;
  455         my $probFileName    =   &getProblemFileName($probNum,$psvn);
  456       if (-e "${templateDirectory}$probFileName" ) {
  457         unless (-r "${templateDirectory}$probFileName") {
  458           wwerror($0, "Can't read ${templateDirectory}$probFileName");
  459         }
  460         open(PROB,"<${templateDirectory}$probFileName");
  461         $source = join("",<PROB>);
  462         close(PROB);
  463       }
  464       local($^W) =0;   ##########CHANGE THIS BACK!!!!
  465       my %envir=defineProblemEnvir('TeX',$probNum,$psvn,$Course,undef());
  466         my ($PG_PROBLEM_TEXT_REF, $PG_HEADER_TEXT_REF, $PG_ANSWER_HASH_REF, $PG_FLAGS_REF,$PG_EVALUATED_ANSWERS_REF);
  467 #
  468          my $pt = new PGtranslator;  #pt stands for problem translator;
  469          $pt->environment(\%envir) ;
  470        $pt->initialize();
  471        $pt-> set_mask();
  472        $pt->source_string($source);
  473        $pt -> unrestricted_load("${courseScriptsDirectory}PG.pl");
  474          $pt -> unrestricted_load("${courseScriptsDirectory}dangerousMacros.pl");
  475        $pt ->translate();
  476 
  477         $PG_PROBLEM_TEXT_REF    = $pt->ra_text();
  478       $PG_HEADER_TEXT_REF     = $pt->r_header;#\$PG_HEADER_TEXT;
  479 
  480 #       $PG_ANSWER_HASH_REF     = $pt->rh_correct_answers;
  481         $PG_EVALUATED_ANSWERS_REF       = $pt->process_answers;
  482       $PG_FLAGS_REF           = $pt ->rh_flags;
  483 
  484 
  485         print OUTPUT @{$PG_PROBLEM_TEXT_REF};
  486           $texSource .= join '', @{$PG_PROBLEM_TEXT_REF};
  487 
  488       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       }
  491       if ($displayCorrectAnswersQ) {
  492       my %correctAnswerHash = ();
  493 
  494 
  495       my @correctAnswerList = ();
  496 
  497       my %submittedAnswerHash = ();
  498       if ( ref($PG_EVALUATED_ANSWERS_REF) eq 'HASH' ) {
  499         %correctAnswerHash = %$PG_EVALUATED_ANSWERS_REF;
  500       } else {
  501           warn "ERROR: Please pass the PG answer list as a hash not a list.";
  502       }
  503 
  504       # insert answers (if any)
  505 
  506           if ( %correctAnswerHash ) {
  507             $texSource .= "Correct Answers:\\par\\begin{itemize}\n";
  508           my ($correctFlag,$normalizedCorrectAnswer,
  509              $normalizedSubmittedAnswer,
  510              $answerMessage) = ();
  511           # determine the correct order for the answers
  512           my @answer_entry_order = ( defined($pt->{PG_FLAGS_REF}->{ANSWER_ENTRY_ORDER}) ) ?
  513                         @{$pt->{PG_FLAGS_REF}->{ANSWER_ENTRY_ORDER}} :  keys %{$pt->rh_evaluated_answers}  ;
  514 
  515           foreach  my $ky (@answer_entry_order) {
  516 
  517           $normalizedCorrectAnswer = $correctAnswerHash{$ky}->{correct_ans};
  518                   $normalizedCorrectAnswer =~ s/\^/\\\^\{\}/g;
  519                 $normalizedCorrectAnswer =~ s/\_/\\\_/g;
  520           $texSource .= "\\item $normalizedCorrectAnswer\n";
  521 
  522           }
  523 
  524               $texSource .= "\\end{itemize} \\par\n";
  525             }
  526       }
  527 
  528 
  529     }
  530 
  531     #  print Tex postamble
  532 #    print OUTPUT &texInput($Global::TEX_SET_FOOTER);
  533     $texSource .= &texInput($Global::TEX_SET_FOOTER);
  534 
  535     return \$texSource, \@PG_COMPILE_ERRORS;
  536 }
  537 
  538 ################### END main routine ##################################
  539 
  540 # sub downloadPS {
  541 #     my $psvn = shift;
  542 #     my $texFile = shift;
  543 #
  544 #     my ($texSourceRef, $errorRef) = &createTexSource($psvn);
  545 #
  546 #
  547 #     open(OUTPUT, ">${tempDirectory}${texFile}${psvn}.tex")
  548 #         || wwerror("Can't create $tempDirectory${texFile}$psvn.tex\n");
  549 #     print OUTPUT $$texSourceRef;
  550 #     close OUTPUT;
  551 #
  552 #
  553 #     print STDERR "Finished making tex file $tempDirectory${texFile}$psvn.tex <br>\n\n" if $debugON;
  554 #  #   chdir "$tempDirectory";
  555 #  #   umask(022);
  556 #
  557 #     # Now that the complete TeX version of the problem set has been
  558 #     # constructed in the $tempDirectory We first attempt to convert it to
  559 #     # postscript, first running TeX and then running dvips The system commands
  560 #     # for this are located in the file makePS which is in the script directory.
  561 #     # If this command fails then an error is reported, otherwise &psPrint
  562 #     # ships the postscript file off to the client which requested the download.
  563 #     my @PG_COMPILE_ERRORS = @$errorRef;
  564 #     if ( @PG_COMPILE_ERRORS ) {
  565 #       &PG_error_print(@PG_COMPILE_ERRORS);
  566 #       # $PG_COMPILE_ERRORS contains the number of the first problem with an error.
  567 #       return 'errors';
  568 #     }
  569 #     else {return 'no_errors';}
  570 # }
  571 
  572 
  573 # sub psPrint {
  574 #     open(INPUT, "$tempDirectory${texFile}$psvn.ps")
  575 #   or wwerror( $0, "Can't open $tempDirectory${texFile}$psvn.ps: $!\n", "", "");
  576 #
  577 #     print "Content-disposition: attachment; filename= \"${login_name_for_psvn}_Set${setNumber}.ps\"\n";
  578 #     print "Content-type: application/postscript\n\n";
  579 #     while (<INPUT>) {
  580 #   print;
  581 #     }
  582 #     close INPUT;
  583 #     print STDERR "Finished TeX $texFile for $login_name_for_psvn in $Course\n" if $debugON;
  584 #
  585 # }
  586 #
  587 # sub pdfPrint {
  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 
  630 sub logPrint {
  631     print &htmlTOP("TeX Error or error in creating PostScript file");
  632     open (LOGFILE, " $tempDirectory$texFile$psvn.log")
  633   || print  "<H3>Can't open log file:</H3> path= $tempDirectory$texFile$psvn.log<BR>$!<BR><BR>"  ;
  634 
  635 
  636     print "<H3>TeX Error Log:</H3>";
  637     my $print_error_switch = ($debugON) ? 1: 0;
  638     my $out='';
  639     #warn ord $/, ord  "\n", ord "\r";
  640     #warn "length of separator = ", length($/);
  641     $/ = "\n";
  642     #warn ord $/, ord  "\n", ord "\r";
  643     while (<LOGFILE>) {
  644       $out = $_;
  645       $print_error_switch = 1 if $out =~ /^!/;  # after a fatal error start printing messages
  646     print protect_HTML($out)."<BR>\n" if $print_error_switch;
  647     }
  648     close(LOGFILE);
  649 
  650     open (TEXFILE, "${tempDirectory}${texFile}${psvn}.tex")
  651   || print "<H3>Can't open tex source file:</H3> path= ${tempDirectory}${texFile}${psvn}.tex:<BR> $!<BR><BR>\n";
  652     print "<BR>\n<H3>TeX Source File:</H3><BR>\n";
  653     print "<PRE>";
  654 
  655     my $lineNumber = 1;
  656     while (<TEXFILE>) {
  657     print protect_HTML("$lineNumber $_")."\n";
  658         $lineNumber++;
  659     }
  660     close(TEXFILE);
  661     print "</PRE>";
  662     print &htmlBOTTOM("downloadPS.pl", \%inputs);
  663 }
  664 sub protect_HTML {
  665   my $line = shift;
  666   chomp($line);
  667   $line =~s/\&/&amp;/g;
  668   $line =~s/</&lt;/g;
  669   $line =~s/>/&gt;/g;
  670   $line;
  671 }
  672 sub PG_error_print {
  673   my @probNums = @_;
  674   my $dummy_psvn = -1;
  675   &attachProbSetRecord($psvn);
  676   my $userName = &getStudentLogin($psvn);
  677   my $setName = &getSetNumber($psvn);
  678   print &htmlTOP("PG compile error");
  679   print "<H3>PG error while compiling problem number",
  680         (@probNums>1) ? 's ' : ' ',
  681         join(',', @probNums),
  682         " in problem set $setName for $userName",
  683         "</H3>";
  684   print "(Search for &quot;ERROR&quot; to find the line where the error occurs.)";
  685   print "<H3>TeX Source File:</H3>";
  686   print "<PRE>";
  687 # print "openedFile = ${tempDirectory}${texFile}${dummy_psvn}.tex\n",
  688 #       "userName = $userName\n",
  689 #       "setName = $setName\n";
  690 
  691   open (TEXFILE, "${tempDirectory}${texFile}${dummy_psvn}.tex")
  692     or print STDERR "Can't open $tempDirectory$texFile$dummy_psvn.tex\n";
  693   my $lineNumber = 1;
  694   local($/) = "\n";
  695   while (<TEXFILE>) {
  696     if ( $_ =~/^<A NAME/ ) {   # skip lines starting with a destination anchor
  697       print $_;
  698     } else {
  699       print protect_HTML("$lineNumber $_")."\n";
  700     }
  701     $lineNumber++;
  702   }
  703   close(TEXFILE);
  704   print &htmlBOTTOM("downloadPS.pl", \%inputs);
  705 }
  706 
  707 sub selectionError {
  708     print &htmlTOP("Selection error");
  709     print"<H2>Error:</H2>  You must first select a problem set in order to download a hard copy!\n";
  710     print "<FORM METHOD=POST ACTION=\"${Global::cgiWebworkURL}welcome.pl\"><P>";
  711     print &sessionKeyInputs(\%inputs);
  712     print <<"ENDOFHTML";
  713   <INPUT TYPE=SUBMIT VALUE="Return to Welcome Page">
  714 </FORM>
  715 ENDOFHTML
  716     print &htmlBOTTOM("welcomeAction.pl", \%inputs);
  717 }
  718 
  719 sub probSet_htmlTOP {
  720     my ($title, $bg_url) = @_;
  721     my $background_url = $bg_url || $Global::background_plain_url;
  722 
  723 
  724     my $out = <<ENDhtmlTOP;
  725 content-type: text/html
  726 Expires: 0
  727 
  728 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
  729 <HTML>
  730 <HEAD>
  731 <TITLE>$title</TITLE>
  732 </HEAD>
  733 <BODY BACKGROUND="$background_url"><p>
  734 <P>
  735 
  736 ENDhtmlTOP
  737     $out;
  738 }
  739 
  740 sub probSet_titleBar {
  741   my ($title) = @_;
  742   my $title_bar = "";
  743   $title_bar .= qq{
  744     <TABLE BORDER="0" WIDTH="100%">
  745     <TR ALIGN=CENTER  >
  746     <TD ALIGN=LEFT >
  747     <A HREF="$Global::webworkDocsURL">
  748     <IMG SRC="$Global::squareWebworkGif" BORDER=1 ALT="WeBWorK"></A>
  749     </TD>
  750     <TD VALIGN=MIDDLE>
  751     <H2 ALIGN=CENTER>
  752     $title
  753     </H2>
  754     </TD>
  755     <TD ALIGN=RIGHT >
  756     <FORM METHOD=POST ACTION=\"${Global::cgiWebworkURL}welcome.pl\"><P>
  757   };
  758   my $inputkeys = &sessionKeyInputs(\%inputs);
  759 
  760   $title_bar .= qq{
  761     $inputkeys
  762     <INPUT TYPE=HIDDEN NAME=\"probSetKey\" VALUE=$psvn>
  763     <INPUT TYPE=SUBMIT VALUE=\"Problem Sets\">
  764     </FORM>
  765     </TD>
  766       </TABLE>
  767   };
  768   $title_bar;
  769 }
  770 
  771 # sub downloadIndividualSet {
  772 #     system("/usr/bin/renice +$main::DOWNLOAD_NICE -p $$ 1>/dev/null") && warn "Could not renice process. pid $$";
  773 #     alarm( $main::DOWNLOAD_TIME_OUT_CONSTANT);
  774 #     my $return_status='';
  775 #     eval {$return_status = downloadPS($psvn,$texFile)}; ## trap any errors
  776 #   $save_errors=$@;                                    ## errors will be printed out by END
  777 #   if ($return_status eq 'errors') {exit;}
  778 #     elsif ($return_status eq 'no_errors') {
  779 #       if ($downloadType eq "TeX"  ) {
  780 #           &texPrint;
  781 #         }
  782 #         elsif (system( "${scriptDirectory}makePS $tempDirectory $texFile$psvn 1>&2" )) {
  783 #         &logPrint;
  784 #         #   wwerror("$0",  "downloadPS:  Error in creating postscript file. <BR>
  785 #           # System command ${scriptDirectory}makePS $tempDirectory $texFile$psvn 1>&2", "", "");
  786 #         }
  787 #         else  {  # tex file has been processed successfully
  788 #         if ($downloadType eq 'pdf') {&pdfPrint;}
  789 #         elsif ($downloadType eq 'dvi') {&dviPrint;}
  790 #         else {&psPrint;}
  791 #         }
  792 #     }
  793 #     else {wwerror($0, "The subroutine downloadPS returned an unknown status");}
  794 # }
  795 
  796 sub downloadAllSets {
  797     system("/usr/bin/renice +$main::CLASS_DOWNLOAD_NICE -p $$ 1>/dev/null") && warn "Could not renice process. pid $$";
  798     alarm( $main::CLASS_DOWNLOAD_TIME_OUT_CONSTANT);
  799     my $localpsvn;       ## psvn numbers for individual students
  800     my $return_status='';
  801     my $texSource ='';
  802     my $individualTexSource ='';
  803     my ($texSourceRef, $errorRef);
  804 
  805     my @local_psvns = $query -> param('local_psvns');
  806 
  807     my $max = $Global::max_num_of_ps_downloads_allowed;
  808 
  809     ## make sure non professors can not download more than one set by submitting an altered form
  810     @local_psvns = ($local_psvns[0]) unless $permissions == $Global::instructor_permissions;
  811 
  812     my $length = @local_psvns;
  813 
  814     if ($length > $max) {
  815     wwerror ("Too many students selected", "The maximun number of sets which can be downloaded at one time is $max. You selected $length.
  816 Go back and select fewer students.  This maximun is set by the variable
  817 \$max_num_of_ps_downloads_allowed in Global.pm.");
  818   }
  819     $localpsvn = shift @local_psvns;     ## get first set which will contain TeX header info
  820 #    attachProbSetRecord($localpsvn);
  821     ($texSourceRef, $errorRef) = &createTexSourceHandleErrors($localpsvn);
  822                                         ## don't do anything with $errorRef at this time
  823                                         ## only contains prob numbers of bad problems
  824     $texSource = $$texSourceRef;                ## contains initial header info
  825     $texSource =~ s|\\end\{document\}\s$|\n|s;  ## remove end{document} statement
  826 
  827     foreach $localpsvn (@local_psvns) {  ## get the rest of the sets and strip TeX header info
  828 #        attachProbSetRecord($localpsvn);
  829         ($texSourceRef, $errorRef) = &createTexSourceHandleErrors($localpsvn);
  830                                         ## don't do anything with $errorRef at this time
  831                                         ## only contains prob numbers of bad problems
  832         $individualTexSource = $$texSourceRef;
  833         $individualTexSource =~ s|^.*?\\begin\{document\}|\n\\newpage\n|s;  ## remove header material and start new page
  834         $individualTexSource =~ s|\\end\{document\}\s$|\n|s;  ## remove end{document} statement
  835         $texSource .= $individualTexSource;
  836     }
  837     $texSource .= "\n\\end{document}\n";        ## append end{document} statement
  838 
  839     $psvn = -1;
  840     $texFile = "set${setNumber}.tempTex-CGIscript";
  841     $login_name_for_psvn = 'all_students';
  842 
  843     open(OUTPUT, ">${tempDirectory}${texFile}${psvn}.tex")
  844         || wwerror("Can't create $tempDirectory${texFile}$psvn.tex\n");
  845     print OUTPUT $texSource;
  846     close OUTPUT;
  847 
  848     # This code replaces the psPrint, pdfPrint, dviPrint, texPrint, subs
  849     # and the scripts/makePS and scripts/makePDF files
  850 
  851   $downloadType = lc $downloadType;
  852     my $texFileBaseName = "${tempDirectory}${texFile}${psvn}";
  853     my $mimeType = prepareHardcopy($texFileBaseName, $downloadType);
  854 
  855   open(INPUT, "$texFileBaseName.$downloadType")
  856     or wwerror($0, "Can't open $texFileBaseName.$downloadType: $!\n");
  857   print "Content-type: $mimeType\n";
  858   print "Content-disposition: attachment; filename=\"${login_name_for_psvn}_Set${setNumber}.$downloadType\"\n\n";
  859   print while (<INPUT>);
  860   close INPUT;
  861 }
  862 
  863 sub createTexSourceHandleErrors {
  864   # wraps call to createTexSource to handle PGtranslator errors
  865   # if an error is found, &PG_error_print is called
  866 
  867   my $psvn = shift;
  868 
  869   my ($texSourceRef, $errorRef) = &createTexSource($psvn);
  870 
  871   my @errors = @$errorRef;
  872   if(@errors) {
  873     PG_error_print(@errors);
  874   }
  875 
  876   return ($texSourceRef, $errorRef);
  877 }
  878 
  879 sub prepareHardcopy
  880 {
  881   my ($texFileBaseName, $targetFormat) = @_;
  882   my $mimeType;
  883 
  884   chdir $tempDirectory;
  885 
  886   my $dviCommandLine = "$Global::$Global::externalLatexPath $texFileBaseName.tex >/dev/null 2>/dev/null";
  887   my $psCommandLine = "$Global::externalDvipsPath -o $texFileBaseName.ps $texFileBaseName.dvi";
  888   my $pdfCommandLine = "$Global::externalPs2pdfPath $texFileBaseName.ps $texFileBaseName.pdf";
  889 
  890   if($targetFormat eq "pdf") {
  891     system($dviCommandLine) and die "dvi generation failed.";
  892     system($psCommandLine) and die "ps generation failed.";
  893     system($pdfCommandLine) and die "pdf generation failed.";
  894     $mimeType = "application/pdf";
  895   } elsif($targetFormat eq "ps") {
  896     system($dviCommandLine) and die "dvi generation failed.";
  897     system($psCommandLine) and die "ps generation failed.";
  898     $mimeType = "application/postscript";
  899   } elsif($targetFormat eq "dvi") {
  900     system($dviCommandLine) and die "dvi generation failed.";
  901     $mimeType = "application/x-dvi";
  902   } elsif($targetFormat eq "tex") {
  903     $mimeType = "application/tex";
  904   } else {
  905     die "unrecognized format: $targetFormat";
  906   }
  907 
  908   return $mimeType;
  909 }
  910 
  911 sub hackerError  { ## prints hacker error message
  912 
  913     my $msg = "Attempt to hack into WeBWorK \n Remote Host is: ". remote_host()."\n";
  914     $msg .= query_string;
  915     &Global::log_error('hacker error', $msg);   ## log attempt
  916 
  917     ## notify by email
  918 
  919    my $toAdd = $Global::feedbackAddress;
  920 
  921     my $emailMsg = "To: $toAdd
  922 Subject: Attempt to hack into WeBWorK
  923 
  924 Here are the details on the attempt to hack into weBWorK:\n
  925 $msg
  926 \n";
  927 
  928   my $smtp = Net::SMTP->new($Global::smtpServer, Timeout=>20);
  929   $smtp->mail($Global::webmaster);
  930   $smtp->recipient($Global::feedbackAddress);
  931   $smtp->data($msg);
  932   $smtp->quit;
  933 
  934 
  935 #    my $SENDMAIL = $Global::SENDMAIL;
  936 #    open (MAIL,"|$SENDMAIL");
  937 #    print MAIL "$emailMsg";
  938 #    close (MAIL);
  939 
  940     print   &htmlTOP("Hacker Error"),
  941                         "<H2>Error:Please do not try to hack into WeBWorK!</H2>",
  942                         startform(-action=>"${Global::cgiWebworkURL}${Global::welcomeAction_CGI}"),
  943                         "<p>",
  944                         &sessionKeyInputs(\%inputs),
  945                         hidden(-name=>'local_psvns', -value=>$psvn),
  946                         hidden(-name=>'action', -value=>'Do_problem_set'),
  947                         submit(-value=>"Return to Problem Set"),
  948                         endform(),
  949                         &htmlBOTTOM($0, \%inputs);
  950 }
  951 
  952 sub defineProblemEnvir {
  953     my ($mode,$probNum,$psvn,$courseName,$refSubmittedAnswers)      =   @_;
  954     my %envir=();
  955     my $loginName = &getStudentLogin($psvn);
  956   ##how to put an array submittedAnswers in a hash??
  957     $envir{'refSubmittedAnswers'}   =   $refSubmittedAnswers if defined($refSubmittedAnswers);
  958     $envir{'psvnNumber'}        =   $psvn;
  959     $envir{'psvn'}            =   $psvn;
  960     $envir{'studentName'}       =   &CL_getStudentName($loginName);
  961   $envir{'studentLogin'}        = $loginName;
  962   $envir{'sectionName'}       = &CL_getClassSection($loginName);
  963   $envir{'sectionNumber'}       = &CL_getClassSection($loginName);
  964   $envir{'recitationName'}      = &CL_getClassRecitation($loginName);
  965   $envir{'recitationNumber'}      = &CL_getClassRecitation($loginName);
  966   $envir{'setNumber'}         = &getSetNumber($psvn);
  967   $envir{'questionNumber'}        = $probNum;
  968   $envir{'probNum'}           = $probNum;
  969   $envir{'openDate'}          = &getOpenDate($psvn);
  970   $envir{'formatedOpenDate'}      = &formatDateAndTime(&getOpenDate($psvn));
  971   $envir{'formattedOpenDate'}     = &formatDateAndTime(&getOpenDate($psvn));
  972   $envir{'dueDate'}           = &getDueDate($psvn);
  973   $envir{'formatedDueDate'}       = &formatDateAndTime(&getDueDate($psvn));
  974   $envir{'formattedDueDate'}      = &formatDateAndTime(&getDueDate($psvn));
  975   $envir{'answerDate'}        = &getAnswerDate($psvn);
  976   $envir{'formatedAnswerDate'}    = &formatDateAndTime(&getAnswerDate($psvn));
  977   $envir{'formattedAnswerDate'}   = &formatDateAndTime(&getAnswerDate($psvn));
  978   $envir{'problemValue'}        = &getProblemValue($probNum,$psvn);
  979   $envir{'fileName'}          = &getProblemFileName($probNum,$psvn);
  980   $envir{'probFileName'}        = &getProblemFileName($probNum,$psvn);
  981   $envir{'languageMode'}        = $mode;
  982   $envir{'displayMode'}       = $mode;
  983   $envir{'outputMode'}        = $mode;
  984   $envir{'courseName'}        = $courseName;
  985   $envir{'sessionKey'}        = ( defined($inputs{'key'}) ) ?$inputs{'key'} : " ";
  986 
  987   # initialize constants for PGanswermacros.pl
  988   $envir{'numRelPercentTolDefault'}   =     getNumRelPercentTolDefault();
  989   $envir{'numZeroLevelDefault'}   =     getNumZeroLevelDefault();
  990   $envir{'numZeroLevelTolDefault'}  =     getNumZeroLevelTolDefault();
  991   $envir{'numAbsTolDefault'}      =     getNumAbsTolDefault();
  992   $envir{'numFormatDefault'}      =     getNumFormatDefault();
  993   $envir{'functRelPercentTolDefault'} =     getFunctRelPercentTolDefault();
  994   $envir{'functZeroLevelDefault'}   =     getFunctZeroLevelDefault();
  995   $envir{'functZeroLevelTolDefault'}  =     getFunctZeroLevelTolDefault();
  996   $envir{'functAbsTolDefault'}    =     getFunctAbsTolDefault();
  997   $envir{'functNumOfPoints'}      =     getFunctNumOfPoints();
  998   $envir{'functVarDefault'}       =     getFunctVarDefault();
  999   $envir{'functLLimitDefault'}    =     getFunctLLimitDefault();
 1000   $envir{'functULimitDefault'}    =     getFunctULimitDefault();
 1001   $envir{'functMaxConstantOfIntegration'} = getFunctMaxConstantOfIntegration();
 1002   $envir{'numOfAttempts'}             =     undef(); # this is defined only for problems
 1003 
 1004   # defining directorys and URLs
 1005   $envir{'templateDirectory'}       = &getCourseTemplateDirectory();
 1006   $envir{'classDirectory'}        = $Global::classDirectory;
 1007   $envir{'cgiDirectory'}        = $Global::cgiDirectory;
 1008   $envir{'macroDirectory'}        = getCourseMacroDirectory();
 1009   $envir{'courseScriptsDirectory'}    = getCourseScriptsDirectory();
 1010   $envir{'htmlDirectory'}             =   getCourseHtmlDirectory();
 1011   $envir{'htmlURL'}           = getCourseHtmlURL();
 1012   $envir{'tempDirectory'}             =   getCourseTempDirectory();
 1013   $envir{'tempURL'}                   =   getCourseTempURL();
 1014   $envir{'scriptDirectory'}       = $Global::scriptDirectory;
 1015   $envir{'webworkDocsURL'}        = $Global::webworkDocsURL;
 1016   $envir{'externalTTHPath'}       = $Global::externalTTHPath;
 1017 
 1018 
 1019   $envir{'inputs_ref'}                =  \%inputs;
 1020 
 1021 
 1022   my $seed    = &getProblemSeed($probNum, $psvn);
 1023   $seed     = 1111 unless defined($seed);
 1024   $envir{'problemSeed'}     =   $seed if defined($seed);
 1025 
 1026   # here is a way to pass environment variables defined in webworkCourse.ph
 1027   my $k;
 1028   foreach $k (keys %Global::PG_environment ) {
 1029     $envir{$k} = $Global::PG_environment{$k};
 1030   }
 1031   %envir;
 1032 }
 1033 
 1034 BEGIN {
 1035 
 1036 
 1037 # This subroutine cleans up temporary files after the postscript copy has been created.
 1038 #
 1039   sub cleanup_downloadPS {
 1040 
 1041       unless (defined($action ) and ($action eq 'Do problem set' or $action eq 'Do_problem_set')) {
 1042           my $ERRORS = $save_errors;
 1043           unless ($debugON) {  #clean up the directory
 1044           eval {
 1045                   chdir $tempDirectory;
 1046                   unlink("$texFile$psvn.dvi", "$texFile$psvn.ps","$texFile$psvn.pdf",
 1047                 "$texFile$psvn.log", "$texFile$psvn.aux",
 1048                 "$texFile$psvn.tex",);
 1049                   unlink("${tempDirectory}eps/${login_name_for_psvn}*.eps");
 1050               };  # clean up
 1051           $ERRORS .= $ERRORS . $@;
 1052         }
 1053         my $query =   query_string();
 1054         $query = "" unless defined($query);
 1055         wwerror("$0", "ERROR: in downloadPS subroutine of welcomeAction.pl $ERRORS","","",$query) if $ERRORS;
 1056       }
 1057   }
 1058 }
 1059 
 1060 END {
 1061    if (defined($main::SIG_TIME_OUT) && $main::SIG_TIME_OUT == 1) {
 1062       alarm(0);  # turn off the alarm
 1063   my $hard_copy_message = qq{Content-type: text/html\n\n
 1064       <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
 1065       <HTML><BODY BGCOLOR = "FF99CC">
 1066       <BLOCKQUOTE><H3>WeBWorK hard copy download time out.</H3>\n
 1067     <H4>This download was cancelled because it took more than $main::TIME_OUT_CONSTANT seconds.</H4>  This may be because the
 1068     WeBWorK server is extraordinarily busy, or because there was an error in the problem,
 1069     or because you tried to download a set with too many  problems (more than 50).<P>\n
 1070         Use the back button to return to the previous page and try again.<BR>\n
 1071         If the problem is repeated you can report this to your instructor using the feedback button.
 1072         <P>
 1073         Because the WeBWorK server at the Unversity of Rochester is experiencing heavy use we have made downloading
 1074         hard copies a low priority during the times of very heavy useage.  It will be helpful if you
 1075         download hard copies during times when the load is not too heavy.
 1076         <P>
 1077         The load is usually heaviest in the evenings , particularly a few hours before assignments
 1078         are due.  The best times to download hard copies are in the morning and afternoon
 1079          -- or an hour after the due date and time of the previous assignment -- nobody is using the system then :-)
 1080          </BLOCKQUOTE></BODY></HTML>
 1081         };
 1082      my $do_problem_message = qq{Content-type: text/html\n\n
 1083         <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
 1084         <HTML><BODY BGCOLOR = "FF99CC">
 1085       <BLOCKQUOTE><H3>WeBWorK heavy useage time out.</H3>\n
 1086     <H4>Your request (action = $action) was cancelled because it took more than $main::TIME_OUT_CONSTANT seconds.</H4>
 1087     This is probably because the
 1088     WeBWorK server is extraordinarily busy.<P>\n
 1089     You should be warned that WeBWorK response will be unusually slow.  If possible you should try
 1090     to use WeBWorK at another time when the load is not as high.  The highest useage periods are in the
 1091     evening, particularly in the two hours before assignments are due.<P>\n
 1092         Use the back button to return to the previous page and try again.<P>\n
 1093         If the high useage problem continues you can report this to your instructor using the feedback button.
 1094         <P>
 1095 
 1096          </BLOCKQUOTE></BODY></HTML>
 1097         };
 1098      if ($action eq 'Get hard copy' or $action eq 'Get_hard_copy')  {
 1099       print $hard_copy_message;
 1100      } else{
 1101       print $do_problem_message;
 1102      }
 1103 
 1104 
 1105    }
 1106 
 1107   # begin Timing code
 1108   if( $main::logTimingData == 1 ) {
 1109     my $endTime = new Benchmark;
 1110     my $error_str='';
 1111 
 1112     if ($main::SIGPIPE) {
 1113       $error_str = 'broken PIPE--';
 1114     }
 1115     elsif ($main::SIG_TIME_OUT) {
 1116       $error_str = "TIME_OUT after $main::TIME_OUT_CONSTANT secs --";
 1117     }
 1118     elsif ($action eq 'Get hard copy' or $action eq 'Get_hard_copy') {
 1119       $error_str = 'successful download --  ';
 1120     }
 1121 
 1122     &Global::logTimingInfo($main::beginTime,$endTime,$error_str.'welcomeAction.pl',$Course,$User);
 1123   }
 1124   # end Timing code
 1125   cleanup_downloadPS();
 1126 }
 1127 
 1128 
 1129 ######## DEBUGGING TOOLS
 1130 
 1131 # sub downloadPS_dumpvar {
 1132 #     my ($packageName) = @_;
 1133 #
 1134 #     local(*alias);
 1135 #
 1136 #
 1137 #     *stash = *{"${packageName}::"};
 1138 #     $, = "  ";
 1139 #
 1140 #     print OUTPUT  "Content-type: text/html\n\n<PRE>\n";
 1141 #
 1142 #
 1143 #     while ( ($varName, $globValue) = each %stash) {
 1144 #         print OUTPUT  "$varName =================================\n";
 1145 #
 1146 #   *alias = $globValue;
 1147 #     next if $varName=~/main/;
 1148 #     next unless $varName =~/::/;
 1149 #
 1150 #   if (defined($alias) ) {
 1151 #       print OUTPUT  "\t \$$varName $alias \n";
 1152 #   }
 1153 #
 1154 #   if ( defined(@alias) ) {
 1155 #       print OUTPUT  "\t \@$varName @alias \n";
 1156 #   }
 1157 #   if (defined(%alias) ) {
 1158 #       print OUTPUT  "\t \%$varName \n";
 1159 #       foreach $key (keys %alias) {
 1160 #           print OUTPUT  "\t\t $key => $alias{$key}\n";
 1161 #       }
 1162 #
 1163 #
 1164 #   }
 1165 #     }
 1166 #
 1167 #
 1168 #
 1169 # }
 1170 
 1171 
 1172 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9