#!/usr/local/bin/webwork-perl # This file is processProblem8.pl # This is a special version of processProblem.pl # made to be used as an editor # It is called from a form with inputs # 'user', # 'key' # 'course' # 'probSetKey' and # 'probNum' # and in addition # 'Mode' (for either TeX mode or HTML mode or Latex2HTML mode) # 'show_old_answers' (whether or not student's old answers should be filled in) # 'ShowAns' (asks for answer to be shown -- only available for instructors) # 'answer$i' (the answers -- if any --provided to the questions) # 'showEdit' (checks if the ShowEditor button should be shown and clicked) # 'showSol' (checks if the solution button ishould be shown and clicked) # as well as # 'source' when an edited source is provided by a web based editor # 'seed' when a new seed is provided by a web based editor # 'readSourceFromHTMLQ' # 'action' which can be 'Save updated version' or 'Read problem from disk' or # 'Submit Answers' or 'Preview Answers' or 'Preview Again' # 'probFileName' # 'languageType' use strict; use lib '.'; use webworkInit; # WeBWorKInitLine use CGI qw(:standard); use Net::SMTP; use Global; use Auth; use Safe; use MIME::Base64 qw( encode_base64 decode_base64) ; use WeBWorK::PG::Translator; use PGtranslator; # this is now a stub use WeBWorK::PG::ImageGenerator; BEGIN { # set to 1 to enable timing_log # (contains debugging info about time taken by scripts to run) $main::logTimingData = 1; # begin Timing code if( $main::logTimingData == 1 ) { use Benchmark; $main::beginTime = new Benchmark; } # end Timing code $main::TIME_OUT_CONSTANT = 60; # one minute wait for on screen problems $SIG{'TERM'} = sub {die '[',scalar(localtime),"] Caught a SIGTERM, Error: $! stopped at $0\n";}; $SIG{'PIPE'} = sub {$main::SIGPIPE = 1, die '[',scalar(localtime),"] Caught a SIGPIPE, Error: $! stopped at $0\n"; }; $SIG{ALRM} = sub { $main::SIG_TIME_OUT = 1; exit(0) }; # ## ATTENTION: The handlers PG_floating_point_exception_handler and PG_warnings_handler # ## have to be installed after CGI::Carp is called since it also # ## modifes the die and warn labels. Finding the right warning mechanism using these two # ## methods bears further investigation # ## They are defined in Global.pm $SIG{'FPE'} = \&Global::PG_floating_point_exception_handler; $SIG{__WARN__}=\&Global::PG_warnings_handler; alarm($main::TIME_OUT_CONSTANT); }; use vars qw ( $questionNumber $STRINGforOUTPUT $languageMode $ansCount $openDate $cgiURL $studentName $pinNumber $submittedAnswers $setNumber $answerDate $dueDate $studentLogin $problemValue $safeCompartment $psvnNumber $fileName $probNum $sectionName $sectionNumber $recitationName $recitationNumber $sessionKey $courseName $modules_to_evaluate $extra_packages_to_be_loaded ); eval { # This hardwires access to these modules/objects. ################################################ #switched to object-oriented interface with CGI #DME 6/15/2000 my $cgi = new CGI; if( $CGI::VERSION < 2.5 ) { die "This version of WeBWorK requires at least version 2.50 of the CGI.pm library"; } my %inputs = $cgi -> Vars(); # get information from CGI inputs (see also below for additional information) my $Course = $inputs{'course'}; my $User = $inputs{'user'}; # define these for the timingLogInfo $main::Course = $Course; $main::User = $User; $main::Action = $inputs{'action'}; my $Session_key = $inputs{'key'}; my $randpsvn = 22222; #int rand(1111,9999); my $psvn = $inputs{'probSetKey'}; #psvn stands for Problem Set Version Number my $probNum = 1; $probNum = $inputs{'probNum'} if defined($inputs{'probNum'}); my $nextProbNum = $probNum +1 if defined($probNum); my $previousProbNum = $probNum -1 if defined($probNum); my $mode = "HTML"; $mode = $inputs{'Mode'} if defined( $inputs{'Mode'} ); $main::display_mode = $mode; # this is only used for the timing messages. my $showEdit = $inputs{'showEdit'}; my $show_old_answers = 0; $show_old_answers = $inputs{'show_old_answers'} if defined($inputs{'show_old_answers'}); # verify that information has been received unless($Course && $User && $Session_key && $psvn) { my $error_msg = $cgi -> remote_host() . ' ' . $cgi -> user_agent() . ' ' . $cgi -> query_string(); &wwerror("$0, missing data", "The script did not receive the proper input data. Course is $Course, user is $User, session key is $Session_key, psvn is $psvn",'','',$error_msg ); } # establish environment for this script &Global::getCourseEnvironment($Course); my $macroDirectory = getCourseMacroDirectory(); my $databaseDirectory = getCourseDatabaseDirectory(); my $htmlDirectory = getCourseHtmlDirectory(); my $htmlURL = getCourseHtmlURL(); my $scriptDirectory = getWebworkScriptDirectory(); my $templateDirectory = getCourseTemplateDirectory(); my $courseScriptsDirectory = getCourseScriptsDirectory(); require "${courseScriptsDirectory}$Global::displayMacros_pl"; require "${scriptDirectory}$Global::DBglue_pl"; require "${scriptDirectory}$Global::classlist_DBglue_pl"; require "${scriptDirectory}$Global::HTMLglue_pl"; require "${scriptDirectory}$Global::FILE_pl"; my $permissionsFile = &Global::getCoursePermissionsFile($Course); my $permissions = &get_permissions($User,$permissionsFile); my $keyFile = &Global::getCourseKeyFile($Course); #################################################################### # load the modules to be used in PGtranslator # # we need to support the above file, but we've changed how # evaluate_modules and load_extra_packages work so that they use an # instance variable. so what we do is use a stub PGtranslator class to # store the list of included modules in a package variable for later # retrieveal. require "${courseScriptsDirectory}PG_module_list.pl" or wwerror($0, "Can't read ${courseScriptsDirectory}PG_module_list.pl"); #################################################################### # log access &Global::log_info('', $cgi -> query_string); unless ($User eq "practice666" ) { #verify session key &verify_key($User, $Session_key, "$keyFile", $Course, \%inputs); } ##right now $probNum cannot possibly be "", because its default is 1 ##is that how it should be? ###Should problemBank2 be substituted by some Global variable???### if($probNum eq "" && ($Course ne "problemBank2") ) { &selectionError; die "Content-type: text/html\n\n ERROR: in $Global::processProblem_CGI near &selectionError"; } # get the rest of the information from the CGI script # get language type my $displayMode = defined($inputs{'languageType'}) ?$inputs{'languageType'}:'pg'; # get answers # Decide whether answers have been submitted. my $answers_submitted =0; $answers_submitted = 1 if defined($inputs{answer_form_submitted}) and 1 == $inputs{answer_form_submitted}; $answers_submitted = 0 if defined($inputs{'action'}) and ( $inputs{'action'} =~ /Paste Answer/ ); # Decide whether preview_mode has been selected my $preview_mode =0; $preview_mode = 1 if defined($inputs{'action'}) and (( $inputs{'action'} =~ /Preview Answer/ ) or ( $inputs{'action'} =~ /Preview Again/ )); my $answersRequestedQ = 0; $answersRequestedQ= $inputs{'ShowAns'} if defined($inputs{'ShowAns'}); my $solutionsRequestedQ= 0; $solutionsRequestedQ= $inputs{'ShowSol'} if defined($inputs{'ShowSol'}); my $hintsRequestedQ= 0; $hintsRequestedQ= $inputs{'ShowHint'} if defined($inputs{'ShowHint'}); my $doNotRecordAnsRequestedQ= 0; $doNotRecordAnsRequestedQ= $inputs{'doNotRecordAns'} if defined($inputs{'doNotRecordAns'}); # # # cache information about the problem set (from the webwork-database) # and begin constructing the environment for constructing and displaying the problem &attachProbSetRecord($psvn); &attachCLRecord(&getStudentLogin($psvn)); # Get information from database my ($currentTime,$odts,$ddts,$adts); $currentTime = time; $odts = &getOpenDate($psvn); $ddts = &getDueDate($psvn); $adts = &getAnswerDate($psvn); my ($setNumber,$numberOfProblems); $setNumber = &getSetNumber($psvn); $numberOfProblems = &getAllProblemsForProbSetRecord($psvn); my $setNumber_display = $setNumber; $setNumber_display =~ s/_/ /g; # If answers have not been submitted and previous answers have been saved, patch them in # unless $show_old_answers = 0 unless ($answers_submitted or !$show_old_answers) { my $student_answers = getProblemStudentAnswer($probNum,$psvn); if (defined $student_answers) { my $rh_answer_hash = decode_submitted_answers($student_answers); my %answer_hash = %$rh_answer_hash; my ($label, $value); foreach $label (keys %answer_hash) {$inputs{$label} = $answer_hash{$label};} } } $show_old_answers = $inputs{'original_show_old_answers'} if defined( $inputs{'original_show_old_answers'} ); ## if returning from previewing, restore the original_show_old_answers mode # Determine language from the file extension(e.g. file.pg or file.pz) $displayMode = &getProblemFileName($probNum,$psvn); $displayMode = $inputs{'probFileName'} if defined($inputs{'probFileName'}); $displayMode =~ s/^.*\.([^\.]*)$/$1/; # get problem name my $probFileName = &getProblemFileName($probNum,$psvn); $probFileName = $inputs{'probFileName'} if defined($inputs{'probFileName'}); # determine time status. # check that the psvn corresponds to the user and that it is after the open # date. This should only fail if someone is trying to break into WeBWorK. if ( ( ( $User ne &getStudentLogin($psvn)) ||($currentTime < $odts) ) and ($permissions != $Global::instructor_permissions) and ($permissions != $Global::TA_permissions) ) { &hackerError; exit; } ## check to see if it is after due + answer date, if so, put note by ## submit answer button (below) my $dueDateNote = ""; my $answerNote = ""; if($currentTime>$ddts) {$dueDateNote=" Note: it is after the due date.\n";} if($currentTime>$adts) {$answerNote= " Answers available.\n";} # determine display defaults my ($displayCorrectAnswersQ,$displayShowAnswerLineQ); $displayShowAnswerLineQ = ($permissions == $Global::instructor_permissions) || ($currentTime > $adts) ; $displayCorrectAnswersQ = 1 if $answersRequestedQ && ($currentTime > $adts); $displayCorrectAnswersQ = 1 if $answersRequestedQ && ($permissions == $Global::instructor_permissions); my $displaySolutionsQ = 0; $displaySolutionsQ = 1 if $solutionsRequestedQ && ($currentTime > $adts); $displaySolutionsQ = 1 if $solutionsRequestedQ && ($permissions == $Global::instructor_permissions); my $displayHintsQ = 0; $displayHintsQ = 1 if $hintsRequestedQ; #check if we need to save the updated version of the text my $problem_has_been_saved = ''; if ( defined($inputs{'action'}) && ( $inputs{'action'} eq 'Save updated version' ) && ($permissions == $Global::instructor_permissions) && defined($inputs{'source'}) ) { my $temp_source = decodeSource($inputs{'source'}); $temp_source=~ s/\r\n/\n/g; #$temp_source = $cgi -> unescape( $temp_source ); saveProblem($temp_source, $probFileName); $problem_has_been_saved = "
When using Netscape 4 or greater on a Macintosh computer, set your fonts by choosing
View -->Encoding-->Western(MacRoman) from the menu. This will make square root signs
and integral signs display correctly.
| "; print $cgi -> startform(-action=>"$Global::problemEditor_CGI", -target=>'editor'), &sessionKeyInputs(\%inputs), $cgi -> hidden( -name =>'source_encoded_using', -value => $sourceAsHTMLEncodingMethod, -override =>1), "\r\n", $cgi -> hidden( -name =>'source', -value => $sourceAsHTML, -override =>1), "\r\n", $cgi -> submit( -name =>'action', -value => "Show Editor", -style=> $button_style), "\r\n", $cgi -> hidden( -name =>'probSetKey', -value => $psvn), "\r\n", $cgi -> hidden( -name =>'probNum', -value => $probNum), "\n", $cgi -> hidden( -name =>'Mode', -value => $mode, -override =>1), "\r\n", $cgi -> hidden( -name =>'seed', -value => $seed, -override =>1), "\r\n", $cgi -> endform(); # Code for logging students's answers to allow inspection of answer history. if ($Global::logCourseAnswerData) { print " | \n"; print $cgi->startform(-action=>"$Global::showPastAnswers_CGI", -target=>'information'), &sessionKeyInputs(\%inputs), $cgi->hidden(-name => 'probNum', -value=>$probNum), "\n", $cgi->hidden(-name => 'setNum', -value=>$setNumber), "\n", $cgi->hidden(-name => 'User', -value=>getStudentLogin($psvn)), "\n", $cgi->submit(-name => 'action', -value=>'Show Past Answers', -style=> $button_style), "\n", $cgi->endform(); print " |
!; print $problem_message, "\n"; } # begin Timing code if( $main::logTimingData == 1 ) { my $endTime = new Benchmark; my $error_str=''; if ($main::SIGPIPE) { $error_str = 'broken PIPE--'; } elsif ($main::SIG_TIME_OUT) { $error_str = "TIME_OUT after $main::TIME_OUT_CONSTANT secs --"; } &Global::logTimingInfo($main::beginTime,$endTime,$error_str.'processProb8.pl '. "(mode: $main::display_mode, action: $main::Action)",$main::Course,$main::User); } # end Timing code }WeBWorK heavy useage time out.
\nYour request for a WeBWorK problem was cancelled because it took more than $main::TIME_OUT_CONSTANT seconds.
If this occurs for only this problem, it is likely that there is a programing error in this problem, maybe an infinite loop. Please report this to your instructor.\n If you get this error on several different problems, it is probably because the WeBWorK server is extraordinarily busy.\n In this case you should be warned that WeBWorK response will be unusually slow. If possible you should try to use WeBWorK at another time when the load is not as high. The highest useage periods are in the evening, particularly in the two hours before assignments are due.\n Use the back button to return to the previous page and try again.\n If the high useage problem continues you can report this to your instructor using the feedback button. Script: $Global::processProblem_CGI