Parent Directory
|
Revision Log
Revision 6149 -
(view)
(download)
(as text)
Original Path: trunk/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm
| 1 : | sh002i | 449 | ################################################################################ |
| 2 : | sh002i | 1663 | # WeBWorK Online Homework Delivery System |
| 3 : | sh002i | 5319 | # Copyright © 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ |
| 4 : | apizer | 6149 | # $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/Problem.pm,v 1.218 2009/07/18 02:52:51 gage Exp $ |
| 5 : | sh002i | 1663 | # |
| 6 : | # This program is free software; you can redistribute it and/or modify it under | ||
| 7 : | # the terms of either: (a) the GNU General Public License as published by the | ||
| 8 : | # Free Software Foundation; either version 2, or (at your option) any later | ||
| 9 : | # version, or (b) the "Artistic License" which comes with this package. | ||
| 10 : | # | ||
| 11 : | # This program is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 : | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 13 : | # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the | ||
| 14 : | # Artistic License for more details. | ||
| 15 : | sh002i | 449 | ################################################################################ |
| 16 : | |||
| 17 : | malsyned | 353 | package WeBWorK::ContentGenerator::Problem; |
| 18 : | sh002i | 818 | use base qw(WeBWorK::ContentGenerator); |
| 19 : | malsyned | 396 | |
| 20 : | sh002i | 455 | =head1 NAME |
| 21 : | gage | 1039 | |
| 22 : | sh002i | 455 | WeBWorK::ContentGenerator::Problem - Allow a student to interact with a problem. |
| 23 : | |||
| 24 : | =cut | ||
| 25 : | sh002i | 1536 | |
| 26 : | malsyned | 396 | use strict; |
| 27 : | use warnings; | ||
| 28 : | gage | 4235 | #use CGI qw(-nosticky ); |
| 29 : | use WeBWorK::CGI; | ||
| 30 : | sh002i | 919 | use File::Path qw(rmtree); |
| 31 : | sh002i | 3485 | use WeBWorK::Debug; |
| 32 : | sh002i | 455 | use WeBWorK::Form; |
| 33 : | use WeBWorK::PG; | ||
| 34 : | sh002i | 1234 | use WeBWorK::PG::ImageGenerator; |
| 35 : | sh002i | 623 | use WeBWorK::PG::IO; |
| 36 : | sh002i | 4504 | use WeBWorK::Utils qw(readFile writeLog writeCourseLog encodeAnswers decodeAnswers |
| 37 : | ref2string makeTempDirectory path_is_subdir sortByName before after between); | ||
| 38 : | sh002i | 4566 | use WeBWorK::DB::Utils qw(global2user user2global); |
| 39 : | gage | 3034 | use URI::Escape; |
| 40 : | sh002i | 1223 | |
| 41 : | jj | 2415 | use WeBWorK::Utils::Tasks qw(fake_set fake_problem); |
| 42 : | sh002i | 1536 | |
| 43 : | sh002i | 2505 | ################################################################################ |
| 44 : | # CGI param interface to this module (up-to-date as of v1.153) | ||
| 45 : | ################################################################################ | ||
| 46 : | |||
| 47 : | # Standard params: | ||
| 48 : | sh002i | 449 | # |
| 49 : | sh002i | 2505 | # user - user ID of real user |
| 50 : | # key - session key | ||
| 51 : | # effectiveUser - user ID of effective user | ||
| 52 : | sh002i | 415 | # |
| 53 : | sh002i | 2505 | # Integration with PGProblemEditor: |
| 54 : | sh002i | 415 | # |
| 55 : | sh002i | 2505 | # editMode - if set, indicates alternate problem source location. |
| 56 : | # can be "temporaryFile" or "savedFile". | ||
| 57 : | sh002i | 425 | # |
| 58 : | sh002i | 2505 | # sourceFilePath - path to file to be edited |
| 59 : | # problemSeed - force problem seed to value | ||
| 60 : | # success - success message to display | ||
| 61 : | # failure - failure message to display | ||
| 62 : | toenail | 2398 | # |
| 63 : | sh002i | 2505 | # Rendering options: |
| 64 : | # | ||
| 65 : | # displayMode - name of display mode to use | ||
| 66 : | # | ||
| 67 : | # showOldAnswers - request that last entered answer be shown (if allowed) | ||
| 68 : | # showCorrectAnswers - request that correct answers be shown (if allowed) | ||
| 69 : | # showHints - request that hints be shown (if allowed) | ||
| 70 : | # showSolutions - request that solutions be shown (if allowed) | ||
| 71 : | # | ||
| 72 : | # Problem interaction: | ||
| 73 : | # | ||
| 74 : | # AnSwEr# - answer blanks in problem | ||
| 75 : | # | ||
| 76 : | # redisplay - name of the "Redisplay Problem" button | ||
| 77 : | # submitAnswers - name of "Submit Answers" button | ||
| 78 : | # checkAnswers - name of the "Check Answers" button | ||
| 79 : | # previewAnswers - name of the "Preview Answers" button | ||
| 80 : | gage | 392 | |
| 81 : | sh002i | 2505 | ################################################################################ |
| 82 : | # "can" methods | ||
| 83 : | ################################################################################ | ||
| 84 : | malsyned | 1426 | |
| 85 : | sh002i | 2505 | # Subroutines to determine if a user "can" perform an action. Each subroutine is |
| 86 : | # called with the following arguments: | ||
| 87 : | # | ||
| 88 : | sh002i | 2762 | # ($self, $User, $EffectiveUser, $Set, $Problem) |
| 89 : | sh002i | 2505 | |
| 90 : | glarose | 3377 | # Note that significant parts of the "can" methods are lifted into the |
| 91 : | # GatewayQuiz module. It isn't direct, however, because of the necessity | ||
| 92 : | # of dealing with versioning there. | ||
| 93 : | |||
| 94 : | sh002i | 2505 | sub can_showOldAnswers { |
| 95 : | sh002i | 2762 | #my ($self, $User, $EffectiveUser, $Set, $Problem) = @_; |
| 96 : | sh002i | 2505 | |
| 97 : | return 1; | ||
| 98 : | } | ||
| 99 : | |||
| 100 : | sub can_showCorrectAnswers { | ||
| 101 : | sh002i | 2762 | my ($self, $User, $EffectiveUser, $Set, $Problem) = @_; |
| 102 : | sh002i | 2505 | my $authz = $self->r->authz; |
| 103 : | |||
| 104 : | return | ||
| 105 : | after($Set->answer_date) | ||
| 106 : | || | ||
| 107 : | $authz->hasPermissions($User->user_id, "show_correct_answers_before_answer_date") | ||
| 108 : | ; | ||
| 109 : | } | ||
| 110 : | |||
| 111 : | sub can_showHints { | ||
| 112 : | sh002i | 2762 | #my ($self, $User, $EffectiveUser, $Set, $Problem) = @_; |
| 113 : | sh002i | 2505 | |
| 114 : | return 1; | ||
| 115 : | } | ||
| 116 : | |||
| 117 : | sub can_showSolutions { | ||
| 118 : | sh002i | 2762 | my ($self, $User, $EffectiveUser, $Set, $Problem) = @_; |
| 119 : | sh002i | 2505 | my $authz = $self->r->authz; |
| 120 : | |||
| 121 : | return | ||
| 122 : | after($Set->answer_date) | ||
| 123 : | || | ||
| 124 : | $authz->hasPermissions($User->user_id, "show_solutions_before_answer_date") | ||
| 125 : | ; | ||
| 126 : | } | ||
| 127 : | |||
| 128 : | sub can_recordAnswers { | ||
| 129 : | sh002i | 2762 | my ($self, $User, $EffectiveUser, $Set, $Problem, $submitAnswers) = @_; |
| 130 : | sh002i | 2505 | my $authz = $self->r->authz; |
| 131 : | jj | 2685 | my $thisAttempt = $submitAnswers ? 1 : 0; |
| 132 : | sh002i | 2505 | if ($User->user_id ne $EffectiveUser->user_id) { |
| 133 : | return $authz->hasPermissions($User->user_id, "record_answers_when_acting_as_student"); | ||
| 134 : | } | ||
| 135 : | if (before($Set->open_date)) { | ||
| 136 : | return $authz->hasPermissions($User->user_id, "record_answers_before_open_date"); | ||
| 137 : | } elsif (between($Set->open_date, $Set->due_date)) { | ||
| 138 : | my $max_attempts = $Problem->max_attempts; | ||
| 139 : | jj | 2685 | my $attempts_used = $Problem->num_correct + $Problem->num_incorrect + $thisAttempt; |
| 140 : | sh002i | 2505 | if ($max_attempts == -1 or $attempts_used < $max_attempts) { |
| 141 : | return $authz->hasPermissions($User->user_id, "record_answers_after_open_date_with_attempts"); | ||
| 142 : | } else { | ||
| 143 : | return $authz->hasPermissions($User->user_id, "record_answers_after_open_date_without_attempts"); | ||
| 144 : | } | ||
| 145 : | sh002i | 2512 | } elsif (between($Set->due_date, $Set->answer_date)) { |
| 146 : | sh002i | 2505 | return $authz->hasPermissions($User->user_id, "record_answers_after_due_date"); |
| 147 : | sh002i | 2512 | } elsif (after($Set->answer_date)) { |
| 148 : | sh002i | 2505 | return $authz->hasPermissions($User->user_id, "record_answers_after_answer_date"); |
| 149 : | } | ||
| 150 : | } | ||
| 151 : | |||
| 152 : | sub can_checkAnswers { | ||
| 153 : | sh002i | 2762 | my ($self, $User, $EffectiveUser, $Set, $Problem, $submitAnswers) = @_; |
| 154 : | sh002i | 2505 | my $authz = $self->r->authz; |
| 155 : | jj | 2685 | my $thisAttempt = $submitAnswers ? 1 : 0; |
| 156 : | sh002i | 2505 | |
| 157 : | if (before($Set->open_date)) { | ||
| 158 : | return $authz->hasPermissions($User->user_id, "check_answers_before_open_date"); | ||
| 159 : | } elsif (between($Set->open_date, $Set->due_date)) { | ||
| 160 : | my $max_attempts = $Problem->max_attempts; | ||
| 161 : | jj | 2685 | my $attempts_used = $Problem->num_correct + $Problem->num_incorrect + $thisAttempt; |
| 162 : | sh002i | 2505 | if ($max_attempts == -1 or $attempts_used < $max_attempts) { |
| 163 : | return $authz->hasPermissions($User->user_id, "check_answers_after_open_date_with_attempts"); | ||
| 164 : | } else { | ||
| 165 : | return $authz->hasPermissions($User->user_id, "check_answers_after_open_date_without_attempts"); | ||
| 166 : | } | ||
| 167 : | sh002i | 2512 | } elsif (between($Set->due_date, $Set->answer_date)) { |
| 168 : | sh002i | 2505 | return $authz->hasPermissions($User->user_id, "check_answers_after_due_date"); |
| 169 : | sh002i | 2512 | } elsif (after($Set->answer_date)) { |
| 170 : | sh002i | 2505 | return $authz->hasPermissions($User->user_id, "check_answers_after_answer_date"); |
| 171 : | } | ||
| 172 : | } | ||
| 173 : | |||
| 174 : | jj | 3564 | # Reset the default in some cases |
| 175 : | sub set_showOldAnswers_default { | ||
| 176 : | my ($self, $ce, $userName, $authz, $set) = @_; | ||
| 177 : | jj | 3580 | # these people always use the system/course default, so don't |
| 178 : | # override the value of ...->{showOldAnswers} | ||
| 179 : | return if $authz->hasPermissions($userName, "can_always_use_show_old_answers_default"); | ||
| 180 : | jj | 3564 | # this person should always default to 0 |
| 181 : | $ce->{pg}->{options}->{showOldAnswers} = 0 | ||
| 182 : | unless ($authz->hasPermissions($userName, "can_show_old_answers_by_default")); | ||
| 183 : | # we are after the due date, so default to not showing it | ||
| 184 : | dpvc | 3567 | $ce->{pg}->{options}->{showOldAnswers} = 0 if $set->{due_date} && after($set->{due_date}); |
| 185 : | jj | 3564 | } |
| 186 : | |||
| 187 : | sh002i | 2505 | ################################################################################ |
| 188 : | # output utilities | ||
| 189 : | ################################################################################ | ||
| 190 : | |||
| 191 : | glarose | 3377 | # Note: the substance of attemptResults is lifted into GatewayQuiz.pm, |
| 192 : | # with some changes to the output format | ||
| 193 : | |||
| 194 : | sh002i | 2505 | sub attemptResults { |
| 195 : | my $self = shift; | ||
| 196 : | my $pg = shift; | ||
| 197 : | my $showAttemptAnswers = shift; | ||
| 198 : | my $showCorrectAnswers = shift; | ||
| 199 : | my $showAttemptResults = $showAttemptAnswers && shift; | ||
| 200 : | my $showSummary = shift; | ||
| 201 : | my $showAttemptPreview = shift || 0; | ||
| 202 : | |||
| 203 : | my $ce = $self->r->ce; | ||
| 204 : | |||
| 205 : | my $problemResult = $pg->{result}; # the overall result of the problem | ||
| 206 : | my @answerNames = @{ $pg->{flags}->{ANSWER_ENTRY_ORDER} }; | ||
| 207 : | |||
| 208 : | my $showMessages = $showAttemptAnswers && grep { $pg->{answers}->{$_}->{ans_message} } @answerNames; | ||
| 209 : | |||
| 210 : | my $basename = "equation-" . $self->{set}->psvn. "." . $self->{problem}->problem_id . "-preview"; | ||
| 211 : | |||
| 212 : | # to make grabbing these options easier, we'll pull them out now... | ||
| 213 : | my %imagesModeOptions = %{$ce->{pg}->{displayModeOptions}->{images}}; | ||
| 214 : | |||
| 215 : | my $imgGen = WeBWorK::PG::ImageGenerator->new( | ||
| 216 : | tempDir => $ce->{webworkDirs}->{tmp}, | ||
| 217 : | latex => $ce->{externalPrograms}->{latex}, | ||
| 218 : | dvipng => $ce->{externalPrograms}->{dvipng}, | ||
| 219 : | useCache => 1, | ||
| 220 : | cacheDir => $ce->{webworkDirs}->{equationCache}, | ||
| 221 : | cacheURL => $ce->{webworkURLs}->{equationCache}, | ||
| 222 : | cacheDB => $ce->{webworkFiles}->{equationCacheDB}, | ||
| 223 : | dvipng_align => $imagesModeOptions{dvipng_align}, | ||
| 224 : | dvipng_depth_db => $imagesModeOptions{dvipng_depth_db}, | ||
| 225 : | ); | ||
| 226 : | |||
| 227 : | my $header; | ||
| 228 : | #$header .= CGI::th("Part"); | ||
| 229 : | $header .= $showAttemptAnswers ? CGI::th("Entered") : ""; | ||
| 230 : | $header .= $showAttemptPreview ? CGI::th("Answer Preview") : ""; | ||
| 231 : | $header .= $showCorrectAnswers ? CGI::th("Correct") : ""; | ||
| 232 : | $header .= $showAttemptResults ? CGI::th("Result") : ""; | ||
| 233 : | $header .= $showMessages ? CGI::th("Messages") : ""; | ||
| 234 : | sh002i | 2761 | my $fully = ''; |
| 235 : | sh002i | 2505 | my @tableRows = ( $header ); |
| 236 : | my $numCorrect = 0; | ||
| 237 : | gage | 3391 | my $numBlanks =0; |
| 238 : | sh002i | 3356 | my $tthPreambleCache; |
| 239 : | sh002i | 2505 | foreach my $name (@answerNames) { |
| 240 : | my $answerResult = $pg->{answers}->{$name}; | ||
| 241 : | my $studentAnswer = $answerResult->{student_ans}; # original_student_ans | ||
| 242 : | my $preview = ($showAttemptPreview | ||
| 243 : | sh002i | 3356 | ? $self->previewAnswer($answerResult, $imgGen, \$tthPreambleCache) |
| 244 : | sh002i | 2505 | : ""); |
| 245 : | my $correctAnswer = $answerResult->{correct_ans}; | ||
| 246 : | my $answerScore = $answerResult->{score}; | ||
| 247 : | my $answerMessage = $showMessages ? $answerResult->{ans_message} : ""; | ||
| 248 : | sh002i | 2767 | $answerMessage =~ s/\n/<BR>/g; |
| 249 : | sh002i | 2761 | $numCorrect += $answerScore >= 1; |
| 250 : | dpvc | 3653 | $numBlanks++ unless $studentAnswer =~/\S/ || $answerScore >= 1; # unless student answer contains entry |
| 251 : | sh002i | 2761 | my $resultString = $answerScore >= 1 ? "correct" : |
| 252 : | $answerScore > 0 ? int($answerScore*100)."% correct" : | ||
| 253 : | "incorrect"; | ||
| 254 : | $fully = 'completely ' if $answerScore >0 and $answerScore < 1; | ||
| 255 : | sh002i | 2505 | |
| 256 : | # get rid of the goofy prefix on the answer names (supposedly, the format | ||
| 257 : | # of the answer names is changeable. this only fixes it for "AnSwEr" | ||
| 258 : | #$name =~ s/^AnSwEr//; | ||
| 259 : | |||
| 260 : | my $row; | ||
| 261 : | #$row .= CGI::td($name); | ||
| 262 : | $row .= $showAttemptAnswers ? CGI::td($self->nbsp($studentAnswer)) : ""; | ||
| 263 : | $row .= $showAttemptPreview ? CGI::td($self->nbsp($preview)) : ""; | ||
| 264 : | $row .= $showCorrectAnswers ? CGI::td($self->nbsp($correctAnswer)) : ""; | ||
| 265 : | $row .= $showAttemptResults ? CGI::td($self->nbsp($resultString)) : ""; | ||
| 266 : | sh002i | 2767 | $row .= $showMessages ? CGI::td({-class=>"Message"},$self->nbsp($answerMessage)) : ""; |
| 267 : | sh002i | 2505 | push @tableRows, $row; |
| 268 : | } | ||
| 269 : | |||
| 270 : | # render equation images | ||
| 271 : | $imgGen->render(refresh => 1); | ||
| 272 : | |||
| 273 : | # my $numIncorrectNoun = scalar @answerNames == 1 ? "question" : "questions"; | ||
| 274 : | my $scorePercent = sprintf("%.0f%%", $problemResult->{score} * 100); | ||
| 275 : | # FIXME -- I left the old code in in case we have to back out. | ||
| 276 : | # my $summary = "On this attempt, you answered $numCorrect out of " | ||
| 277 : | # . scalar @answerNames . " $numIncorrectNoun correct, for a score of $scorePercent."; | ||
| 278 : | my $summary = ""; | ||
| 279 : | gage | 3391 | unless (defined($problemResult->{summary}) and $problemResult->{summary} =~ /\S/) { |
| 280 : | if (scalar @answerNames == 1) { #default messages | ||
| 281 : | if ($numCorrect == scalar @answerNames) { | ||
| 282 : | dpvc | 4158 | $summary .= CGI::div({class=>"ResultsWithoutError"},"The answer above is correct."); |
| 283 : | gage | 3391 | } else { |
| 284 : | dpvc | 4158 | $summary .= CGI::div({class=>"ResultsWithError"},"The answer above is NOT ${fully}correct."); |
| 285 : | gage | 3391 | } |
| 286 : | } else { | ||
| 287 : | if ($numCorrect == scalar @answerNames) { | ||
| 288 : | dpvc | 4158 | $summary .= CGI::div({class=>"ResultsWithoutError"},"All of the answers above are correct."); |
| 289 : | gage | 3391 | } |
| 290 : | unless ($numCorrect + $numBlanks == scalar( @answerNames)) { | ||
| 291 : | dpvc | 4158 | $summary .= CGI::div({class=>"ResultsWithError"},"At least one of the answers above is NOT ${fully}correct."); |
| 292 : | gage | 3391 | } |
| 293 : | if ($numBlanks) { | ||
| 294 : | my $s = ($numBlanks>1)?'':'s'; | ||
| 295 : | $summary .= CGI::div({class=>"ResultsAlert"},"$numBlanks of the questions remain$s unanswered."); | ||
| 296 : | } | ||
| 297 : | } | ||
| 298 : | sh002i | 2505 | } else { |
| 299 : | gage | 3391 | $summary = $problemResult->{summary}; # summary has been defined by grader |
| 300 : | sh002i | 2505 | } |
| 301 : | return | ||
| 302 : | CGI::table({-class=>"attemptResults"}, CGI::Tr(\@tableRows)) | ||
| 303 : | sh002i | 3768 | . ($showSummary ? CGI::p({class=>'attemptResultsSummary'},$summary) : ""); |
| 304 : | sh002i | 2505 | } |
| 305 : | |||
| 306 : | |||
| 307 : | glarose | 3377 | # Note: previewAnswer is lifted into GatewayQuiz.pm |
| 308 : | |||
| 309 : | sh002i | 2505 | sub previewAnswer { |
| 310 : | sh002i | 3356 | my ($self, $answerResult, $imgGen, $tthPreambleCache) = @_; |
| 311 : | sh002i | 2505 | my $ce = $self->r->ce; |
| 312 : | my $effectiveUser = $self->{effectiveUser}; | ||
| 313 : | my $set = $self->{set}; | ||
| 314 : | my $problem = $self->{problem}; | ||
| 315 : | my $displayMode = $self->{displayMode}; | ||
| 316 : | |||
| 317 : | # note: right now, we have to do things completely differently when we are | ||
| 318 : | # rendering math from INSIDE the translator and from OUTSIDE the translator. | ||
| 319 : | # so we'll just deal with each case explicitly here. there's some code | ||
| 320 : | # duplication that can be dealt with later by abstracting out tth/dvipng/etc. | ||
| 321 : | |||
| 322 : | my $tex = $answerResult->{preview_latex_string}; | ||
| 323 : | |||
| 324 : | return "" unless defined $tex and $tex ne ""; | ||
| 325 : | |||
| 326 : | if ($displayMode eq "plainText") { | ||
| 327 : | return $tex; | ||
| 328 : | } elsif ($displayMode eq "formattedText") { | ||
| 329 : | sh002i | 3356 | |
| 330 : | # read the TTH preamble, or use the cached copy passed in from the caller | ||
| 331 : | glarose | 3570 | my $tthPreamble=''; |
| 332 : | sh002i | 3356 | if (defined $$tthPreambleCache) { |
| 333 : | $tthPreamble = $$tthPreambleCache; | ||
| 334 : | } else { | ||
| 335 : | my $tthPreambleFile = $ce->{courseDirs}->{templates} . "/tthPreamble.tex"; | ||
| 336 : | if (-r $tthPreambleFile) { | ||
| 337 : | $tthPreamble = readFile($tthPreambleFile); | ||
| 338 : | # thanks to Jim Martino. each line in the definition file should end with | ||
| 339 : | #a % to prevent adding supurious paragraphs to output: | ||
| 340 : | $tthPreamble =~ s/(.)\n/$1%\n/g; | ||
| 341 : | # solves the problem if the file doesn't end with a return: | ||
| 342 : | $tthPreamble .="%\n"; | ||
| 343 : | # store preamble in cache: | ||
| 344 : | $$tthPreambleCache = $tthPreamble; | ||
| 345 : | } else { | ||
| 346 : | } | ||
| 347 : | } | ||
| 348 : | |||
| 349 : | # construct TTH command line | ||
| 350 : | sh002i | 2505 | my $tthCommand = $ce->{externalPrograms}->{tth} |
| 351 : | dpvc | 3362 | . " -L -f5 -u -r 2> /dev/null <<END_OF_INPUT; echo > /dev/null\n" |
| 352 : | . $tthPreamble . "\\[" . $tex . "\\]\n" | ||
| 353 : | sh002i | 2505 | . "END_OF_INPUT\n"; |
| 354 : | |||
| 355 : | # call tth | ||
| 356 : | my $result = `$tthCommand`; | ||
| 357 : | if ($?) { | ||
| 358 : | return "<b>[tth failed: $? $@]</b>"; | ||
| 359 : | } else { | ||
| 360 : | dpvc | 3362 | # avoid border problems in tables and remove unneeded initial <br> |
| 361 : | $result =~ s/(<table [^>]*)>/$1 CLASS="ArrayLayout">/gi; | ||
| 362 : | $result =~ s!\s*<br clear="all" />!!; | ||
| 363 : | sh002i | 2505 | return $result; |
| 364 : | } | ||
| 365 : | sh002i | 3356 | |
| 366 : | sh002i | 2505 | } elsif ($displayMode eq "images") { |
| 367 : | $imgGen->add($tex); | ||
| 368 : | } elsif ($displayMode eq "jsMath") { | ||
| 369 : | dpvc | 4071 | $tex =~ s/</</g; $tex =~ s/>/>/g; |
| 370 : | dpvc | 3337 | return '<SPAN CLASS="math">\\displaystyle{'.$tex.'}</SPAN>'; |
| 371 : | sh002i | 2505 | } |
| 372 : | } | ||
| 373 : | |||
| 374 : | ################################################################################ | ||
| 375 : | # Template escape implementations | ||
| 376 : | ################################################################################ | ||
| 377 : | |||
| 378 : | sh002i | 476 | sub pre_header_initialize { |
| 379 : | sh002i | 1841 | my ($self) = @_; |
| 380 : | sh002i | 1908 | my $r = $self->r; |
| 381 : | my $ce = $r->ce; | ||
| 382 : | my $db = $r->db; | ||
| 383 : | toenail | 2349 | my $authz = $r->authz; |
| 384 : | sh002i | 1908 | my $urlpath = $r->urlpath; |
| 385 : | |||
| 386 : | my $setName = $urlpath->arg("setID"); | ||
| 387 : | sh002i | 1841 | my $problemNumber = $r->urlpath->arg("problemID"); |
| 388 : | sh002i | 1908 | my $userName = $r->param('user'); |
| 389 : | my $effectiveUserName = $r->param('effectiveUser'); | ||
| 390 : | my $key = $r->param('key'); | ||
| 391 : | sh002i | 3816 | my $editMode = $r->param("editMode"); |
| 392 : | gage | 1007 | |
| 393 : | sh002i | 1636 | my $user = $db->getUser($userName); # checked |
| 394 : | die "record for user $userName (real user) does not exist." | ||
| 395 : | unless defined $user; | ||
| 396 : | |||
| 397 : | my $effectiveUser = $db->getUser($effectiveUserName); # checked | ||
| 398 : | die "record for user $effectiveUserName (effective user) does not exist." | ||
| 399 : | unless defined $effectiveUser; | ||
| 400 : | |||
| 401 : | sh002i | 1197 | # obtain the merged set for $effectiveUser |
| 402 : | sh002i | 1636 | my $set = $db->getMergedSet($effectiveUserName, $setName); # checked |
| 403 : | sh002i | 2738 | |
| 404 : | jj | 3564 | $self->set_showOldAnswers_default($ce, $userName, $authz, $set); |
| 405 : | |||
| 406 : | sh002i | 2738 | # Database fix (in case of undefined published values) |
| 407 : | # this is only necessary because some people keep holding to ww1.9 which did not have a published field | ||
| 408 : | # make sure published is set to 0 or 1 | ||
| 409 : | if ( $set and $set->published ne "0" and $set->published ne "1") { | ||
| 410 : | my $globalSet = $db->getGlobalSet($set->set_id); | ||
| 411 : | $globalSet->published("1"); # defaults to published | ||
| 412 : | $db->putGlobalSet($globalSet); | ||
| 413 : | $set = $db->getMergedSet($effectiveUserName, $setName); | ||
| 414 : | } else { | ||
| 415 : | # don't do anything just yet, maybe we're a professor and we're | ||
| 416 : | # fabricating a set or haven't assigned it to ourselves just yet | ||
| 417 : | } | ||
| 418 : | gage | 992 | |
| 419 : | sh002i | 1197 | # obtain the merged problem for $effectiveUser |
| 420 : | sh002i | 1636 | my $problem = $db->getMergedProblem($effectiveUserName, $setName, $problemNumber); # checked |
| 421 : | toenail | 2097 | |
| 422 : | toenail | 2349 | if ($authz->hasPermissions($userName, "modify_problem_sets")) { |
| 423 : | sh002i | 1197 | # professors are allowed to fabricate sets and problems not |
| 424 : | # assigned to them (or anyone). this allows them to use the | ||
| 425 : | # editor to | ||
| 426 : | sh002i | 2738 | |
| 427 : | # if a User Set does not exist for this user and this set | ||
| 428 : | # then we check the Global Set | ||
| 429 : | # if that does not exist we create a fake set | ||
| 430 : | # if it does, we add fake user data | ||
| 431 : | sh002i | 1197 | unless (defined $set) { |
| 432 : | my $userSetClass = $db->{set_user}->{record}; | ||
| 433 : | sh002i | 1636 | my $globalSet = $db->getGlobalSet($setName); # checked |
| 434 : | sh002i | 2738 | |
| 435 : | if (not defined $globalSet) { | ||
| 436 : | jj | 2020 | $set = fake_set($db); |
| 437 : | } else { | ||
| 438 : | $set = global2user($userSetClass, $globalSet); | ||
| 439 : | $set->psvn(0); | ||
| 440 : | } | ||
| 441 : | sh002i | 1197 | } |
| 442 : | |||
| 443 : | # if that is not yet defined obtain the global problem, | ||
| 444 : | # convert it to a user problem, and add fake user data | ||
| 445 : | unless (defined $problem) { | ||
| 446 : | my $userProblemClass = $db->{problem_user}->{record}; | ||
| 447 : | sh002i | 1636 | my $globalProblem = $db->getGlobalProblem($setName, $problemNumber); # checked |
| 448 : | # if the global problem doesn't exist either, bail! | ||
| 449 : | jj | 2020 | if(not defined $globalProblem) { |
| 450 : | my $sourceFilePath = $r->param("sourceFilePath"); | ||
| 451 : | sh002i | 4051 | die "sourceFilePath is unsafe!" unless path_is_subdir($sourceFilePath, $ce->{courseDirs}->{templates}, 1); # 1==path can be relative to dir |
| 452 : | jj | 2421 | # These are problems from setmaker. If declared invalid, they won't come up |
| 453 : | jj | 2422 | $self->{invalidProblem} = $self->{invalidSet} = 1 unless defined $sourceFilePath; |
| 454 : | toenail | 2398 | # die "Problem $problemNumber in set $setName does not exist" unless defined $sourceFilePath; |
| 455 : | jj | 2020 | $problem = fake_problem($db); |
| 456 : | $problem->problem_id(1); | ||
| 457 : | $problem->source_file($sourceFilePath); | ||
| 458 : | $problem->user_id($effectiveUserName); | ||
| 459 : | } else { | ||
| 460 : | $problem = global2user($userProblemClass, $globalProblem); | ||
| 461 : | $problem->user_id($effectiveUserName); | ||
| 462 : | $problem->problem_seed(0); | ||
| 463 : | $problem->status(0); | ||
| 464 : | $problem->attempted(0); | ||
| 465 : | $problem->last_answer(""); | ||
| 466 : | $problem->num_correct(0); | ||
| 467 : | $problem->num_incorrect(0); | ||
| 468 : | } | ||
| 469 : | sh002i | 1197 | } |
| 470 : | |||
| 471 : | # now we're sure we have valid UserSet and UserProblem objects | ||
| 472 : | # yay! | ||
| 473 : | |||
| 474 : | # now deal with possible editor overrides: | ||
| 475 : | |||
| 476 : | # if the caller is asking to override the source file, and | ||
| 477 : | # editMode calls for a temporary file, do so | ||
| 478 : | my $sourceFilePath = $r->param("sourceFilePath"); | ||
| 479 : | sh002i | 4015 | if (defined $editMode and $editMode eq "temporaryFile" and defined $sourceFilePath) { |
| 480 : | sh002i | 4051 | die "sourceFilePath is unsafe!" unless path_is_subdir($sourceFilePath, $ce->{courseDirs}->{templates}, 1); # 1==path can be relative to dir |
| 481 : | sh002i | 1197 | $problem->source_file($sourceFilePath); |
| 482 : | } | ||
| 483 : | |||
| 484 : | toenail | 2398 | # if the problem does not have a source file or no source file has been passed in |
| 485 : | # then this is really an invalid problem (probably from a bad URL) | ||
| 486 : | $self->{invalidProblem} = not (defined $sourceFilePath or $problem->source_file); | ||
| 487 : | |||
| 488 : | sh002i | 1197 | # if the caller is asking to override the problem seed, do so |
| 489 : | my $problemSeed = $r->param("problemSeed"); | ||
| 490 : | if (defined $problemSeed) { | ||
| 491 : | $problem->problem_seed($problemSeed); | ||
| 492 : | } | ||
| 493 : | toenail | 2097 | |
| 494 : | toenail | 2244 | my $publishedClass = ($set->published) ? "Published" : "Unpublished"; |
| 495 : | toenail | 2278 | my $publishedText = ($set->published) ? "visible to students." : "hidden from students."; |
| 496 : | gage | 5644 | $self->addmessage(CGI::span("This set is " . CGI::font({class=>$publishedClass}, $publishedText))); |
| 497 : | glarose | 3377 | |
| 498 : | glarose | 4909 | # test for additional problem validity if it's not already invalid |
| 499 : | glarose | 3377 | } else { |
| 500 : | sh002i | 2738 | $self->{invalidProblem} = !(defined $problem and ($set->published || $authz->hasPermissions($userName, "view_unpublished_sets"))); |
| 501 : | |||
| 502 : | toenail | 2398 | $self->addbadmessage(CGI::p("This problem will not count towards your grade.")) if $problem and not $problem->value and not $self->{invalidProblem}; |
| 503 : | sh002i | 1197 | } |
| 504 : | toenail | 2398 | |
| 505 : | sh002i | 1197 | $self->{userName} = $userName; |
| 506 : | $self->{effectiveUserName} = $effectiveUserName; | ||
| 507 : | $self->{user} = $user; | ||
| 508 : | $self->{effectiveUser} = $effectiveUser; | ||
| 509 : | $self->{set} = $set; | ||
| 510 : | $self->{problem} = $problem; | ||
| 511 : | $self->{editMode} = $editMode; | ||
| 512 : | sh002i | 429 | |
| 513 : | ##### form processing ##### | ||
| 514 : | |||
| 515 : | sh002i | 425 | # set options from form fields (see comment at top of file for names) |
| 516 : | sh002i | 1908 | my $displayMode = $r->param("displayMode") || $ce->{pg}->{options}->{displayMode}; |
| 517 : | sh002i | 425 | my $redisplay = $r->param("redisplay"); |
| 518 : | sh002i | 429 | my $submitAnswers = $r->param("submitAnswers"); |
| 519 : | sh002i | 719 | my $checkAnswers = $r->param("checkAnswers"); |
| 520 : | sh002i | 623 | my $previewAnswers = $r->param("previewAnswers"); |
| 521 : | gage | 388 | |
| 522 : | sh002i | 449 | my $formFields = { WeBWorK::Form->new_from_paramable($r)->Vars }; |
| 523 : | |||
| 524 : | sh002i | 738 | $self->{displayMode} = $displayMode; |
| 525 : | $self->{redisplay} = $redisplay; | ||
| 526 : | $self->{submitAnswers} = $submitAnswers; | ||
| 527 : | $self->{checkAnswers} = $checkAnswers; | ||
| 528 : | $self->{previewAnswers} = $previewAnswers; | ||
| 529 : | $self->{formFields} = $formFields; | ||
| 530 : | toenail | 2011 | |
| 531 : | toenail | 2093 | # get result and send to message |
| 532 : | gage | 3034 | my $status_message = $r->param("status_message"); |
| 533 : | gage | 3055 | $self->addmessage(CGI::p("$status_message")) if $status_message; |
| 534 : | toenail | 2093 | |
| 535 : | toenail | 2011 | # now that we've set all the necessary variables quit out if the set or problem is invalid |
| 536 : | return if $self->{invalidSet} || $self->{invalidProblem}; | ||
| 537 : | sh002i | 738 | |
| 538 : | sh002i | 449 | ##### permissions ##### |
| 539 : | glarose | 4909 | |
| 540 : | sh002i | 449 | # what does the user want to do? |
| 541 : | gage | 2998 | #FIXME There is a problem with checkboxes -- if they are not checked they are invisible. Hence if the default mode in $ce is 1 |
| 542 : | # there is no way to override this. Probably this is ok for the last three options, but it was definitely not ok for showing | ||
| 543 : | # saved answers which is normally on, but you want to be able to turn it off! This section should be moved to ContentGenerator | ||
| 544 : | # so that you can set these options anywhere. We also need mechanisms for making them sticky. | ||
| 545 : | jj | 3564 | # Note: ProblemSet and ProblemSets might set showOldAnswers to '', which |
| 546 : | # needs to be treated as if it is not set. | ||
| 547 : | sh002i | 431 | my %want = ( |
| 548 : | jj | 3564 | showOldAnswers => (defined($r->param("showOldAnswers")) and $r->param("showOldAnswers") ne '') ? $r->param("showOldAnswers") : $ce->{pg}->{options}->{showOldAnswers}, |
| 549 : | sh002i | 1908 | showCorrectAnswers => $r->param("showCorrectAnswers") || $ce->{pg}->{options}->{showCorrectAnswers}, |
| 550 : | showHints => $r->param("showHints") || $ce->{pg}->{options}->{showHints}, | ||
| 551 : | showSolutions => $r->param("showSolutions") || $ce->{pg}->{options}->{showSolutions}, | ||
| 552 : | sh002i | 719 | recordAnswers => $submitAnswers, |
| 553 : | sh002i | 747 | checkAnswers => $checkAnswers, |
| 554 : | jj | 2685 | getSubmitButton => 1, |
| 555 : | sh002i | 431 | ); |
| 556 : | sh002i | 429 | |
| 557 : | sh002i | 431 | # are certain options enforced? |
| 558 : | my %must = ( | ||
| 559 : | showOldAnswers => 0, | ||
| 560 : | showCorrectAnswers => 0, | ||
| 561 : | showHints => 0, | ||
| 562 : | showSolutions => 0, | ||
| 563 : | sh002i | 2505 | recordAnswers => ! $authz->hasPermissions($userName, "avoid_recording_answers"), |
| 564 : | sh002i | 747 | checkAnswers => 0, |
| 565 : | jj | 2685 | getSubmitButton => 0, |
| 566 : | sh002i | 431 | ); |
| 567 : | gage | 3000 | |
| 568 : | sh002i | 429 | # does the user have permission to use certain options? |
| 569 : | sh002i | 2762 | my @args = ($user, $effectiveUser, $set, $problem); |
| 570 : | sh002i | 431 | my %can = ( |
| 571 : | sh002i | 2505 | showOldAnswers => $self->can_showOldAnswers(@args), |
| 572 : | showCorrectAnswers => $self->can_showCorrectAnswers(@args), | ||
| 573 : | showHints => $self->can_showHints(@args), | ||
| 574 : | showSolutions => $self->can_showSolutions(@args), | ||
| 575 : | jj | 2685 | recordAnswers => $self->can_recordAnswers(@args, 0), |
| 576 : | checkAnswers => $self->can_checkAnswers(@args, $submitAnswers), | ||
| 577 : | getSubmitButton => $self->can_recordAnswers(@args, $submitAnswers), | ||
| 578 : | sh002i | 431 | ); |
| 579 : | sh002i | 1908 | |
| 580 : | sh002i | 429 | # final values for options |
| 581 : | sh002i | 431 | my %will; |
| 582 : | sh002i | 617 | foreach (keys %must) { |
| 583 : | sh002i | 431 | $will{$_} = $can{$_} && ($want{$_} || $must{$_}); |
| 584 : | gage | 5636 | #warn "final values for options $_ is can $can{$_}, want $want{$_}, must $must{$_}, will $will{$_}"; |
| 585 : | sh002i | 431 | } |
| 586 : | sh002i | 429 | |
| 587 : | ##### sticky answers ##### | ||
| 588 : | |||
| 589 : | sh002i | 1234 | if (not ($submitAnswers or $previewAnswers or $checkAnswers) and $will{showOldAnswers}) { |
| 590 : | sh002i | 431 | # do this only if new answers are NOT being submitted |
| 591 : | sh002i | 429 | my %oldAnswers = decodeAnswers($problem->last_answer); |
| 592 : | $formFields->{$_} = $oldAnswers{$_} foreach keys %oldAnswers; | ||
| 593 : | } | ||
| 594 : | |||
| 595 : | ##### translation ##### | ||
| 596 : | gage | 1202 | |
| 597 : | sh002i | 3485 | debug("begin pg processing"); |
| 598 : | sh002i | 424 | my $pg = WeBWorK::PG->new( |
| 599 : | sh002i | 1908 | $ce, |
| 600 : | malsyned | 704 | $effectiveUser, |
| 601 : | gage | 1038 | $key, |
| 602 : | sh002i | 502 | $set, |
| 603 : | $problem, | ||
| 604 : | sh002i | 1197 | $set->psvn, # FIXME: this field should be removed |
| 605 : | sh002i | 502 | $formFields, |
| 606 : | sh002i | 424 | { # translation options |
| 607 : | sh002i | 434 | displayMode => $displayMode, |
| 608 : | showHints => $will{showHints}, | ||
| 609 : | showSolutions => $will{showSolutions}, | ||
| 610 : | refreshMath2img => $will{showHints} || $will{showSolutions}, | ||
| 611 : | dpvc | 5314 | processAnswers => 1, |
| 612 : | gage | 5715 | permissionLevel => $db->getPermissionLevel($userName)->permission, |
| 613 : | gage | 6086 | effectivePermissionLevel => $db->getPermissionLevel($effectiveUserName)->permission, |
| 614 : | sh002i | 424 | }, |
| 615 : | ); | ||
| 616 : | gage | 5715 | |
| 617 : | sh002i | 3485 | debug("end pg processing"); |
| 618 : | sh002i | 2505 | |
| 619 : | sh002i | 684 | ##### fix hint/solution options ##### |
| 620 : | |||
| 621 : | gage | 1582 | $can{showHints} &&= $pg->{flags}->{hintExists} |
| 622 : | &&= $pg->{flags}->{showHintLimit}<=$pg->{state}->{num_of_incorrect_ans}; | ||
| 623 : | sh002i | 684 | $can{showSolutions} &&= $pg->{flags}->{solutionExists}; |
| 624 : | |||
| 625 : | sh002i | 449 | ##### store fields ##### |
| 626 : | |||
| 627 : | $self->{want} = \%want; | ||
| 628 : | $self->{must} = \%must; | ||
| 629 : | $self->{can} = \%can; | ||
| 630 : | $self->{will} = \%will; | ||
| 631 : | $self->{pg} = $pg; | ||
| 632 : | } | ||
| 633 : | |||
| 634 : | sh002i | 558 | sub if_errors($$) { |
| 635 : | my ($self, $arg) = @_; | ||
| 636 : | sh002i | 1908 | |
| 637 : | if ($self->{isOpen}) { | ||
| 638 : | return $self->{pg}->{flags}->{error_flag} ? $arg : !$arg; | ||
| 639 : | } else { | ||
| 640 : | return !$arg; | ||
| 641 : | } | ||
| 642 : | sh002i | 558 | } |
| 643 : | |||
| 644 : | sh002i | 562 | sub head { |
| 645 : | sh002i | 1908 | my ($self) = @_; |
| 646 : | glarose | 4909 | |
| 647 : | return "" if ( $self->{invalidSet} ); | ||
| 648 : | sh002i | 555 | return $self->{pg}->{head_text} if $self->{pg}->{head_text}; |
| 649 : | } | ||
| 650 : | sh002i | 476 | |
| 651 : | sh002i | 3481 | sub options { |
| 652 : | my ($self) = @_; | ||
| 653 : | #warn "doing options in Problem"; | ||
| 654 : | |||
| 655 : | # don't show options if we don't have anything to show | ||
| 656 : | sh002i | 3798 | return "" if $self->{invalidSet} or $self->{invalidProblem}; |
| 657 : | sh002i | 3481 | |
| 658 : | my $displayMode = $self->{displayMode}; | ||
| 659 : | my %can = %{ $self->{can} }; | ||
| 660 : | |||
| 661 : | my @options_to_show = "displayMode"; | ||
| 662 : | push @options_to_show, "showOldAnswers" if $can{showOldAnswers}; | ||
| 663 : | push @options_to_show, "showHints" if $can{showHints}; | ||
| 664 : | push @options_to_show, "showSolutions" if $can{showSolutions}; | ||
| 665 : | |||
| 666 : | return $self->optionsMacro( | ||
| 667 : | options_to_show => \@options_to_show, | ||
| 668 : | extra_params => ["editMode", "sourceFilePath"], | ||
| 669 : | ); | ||
| 670 : | } | ||
| 671 : | sh002i | 1131 | |
| 672 : | sh002i | 476 | sub siblings { |
| 673 : | sh002i | 1908 | my ($self) = @_; |
| 674 : | my $r = $self->r; | ||
| 675 : | my $db = $r->db; | ||
| 676 : | my $urlpath = $r->urlpath; | ||
| 677 : | sh002i | 476 | |
| 678 : | toenail | 2011 | # can't show sibling problems if the set is invalid |
| 679 : | return "" if $self->{invalidSet}; | ||
| 680 : | |||
| 681 : | sh002i | 1908 | my $courseID = $urlpath->arg("courseID"); |
| 682 : | my $setID = $self->{set}->set_id; | ||
| 683 : | my $eUserID = $r->param("effectiveUser"); | ||
| 684 : | my @problemIDs = sort { $a <=> $b } $db->listUserProblems($eUserID, $setID); | ||
| 685 : | sh002i | 526 | |
| 686 : | sh002i | 3963 | print CGI::start_div({class=>"info-box", id=>"fisheye"}); |
| 687 : | print CGI::h2("Problems"); | ||
| 688 : | sh002i | 3836 | #print CGI::start_ul({class=>"LinksMenu"}); |
| 689 : | #print CGI::start_li(); | ||
| 690 : | #print CGI::span({style=>"font-size:larger"}, "Problems"); | ||
| 691 : | sh002i | 1908 | print CGI::start_ul(); |
| 692 : | toenail | 2211 | |
| 693 : | sh002i | 1908 | foreach my $problemID (@problemIDs) { |
| 694 : | my $problemPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::Problem", | ||
| 695 : | courseID => $courseID, setID => $setID, problemID => $problemID); | ||
| 696 : | gage | 2998 | print CGI::li(CGI::a( {href=>$self->systemLink($problemPage, |
| 697 : | params=>{ displayMode => $self->{displayMode}, | ||
| 698 : | gage | 3000 | showOldAnswers => $self->{will}->{showOldAnswers} |
| 699 : | gage | 2998 | })}, "Problem $problemID") |
| 700 : | ); | ||
| 701 : | sh002i | 476 | } |
| 702 : | dpvc | 5966 | |
| 703 : | sh002i | 1908 | print CGI::end_ul(); |
| 704 : | sh002i | 3836 | #print CGI::end_li(); |
| 705 : | #print CGI::end_ul(); | ||
| 706 : | sh002i | 3963 | print CGI::end_div(); |
| 707 : | dpvc | 5966 | |
| 708 : | sh002i | 1223 | return ""; |
| 709 : | sh002i | 476 | } |
| 710 : | |||
| 711 : | sub nav { | ||
| 712 : | sh002i | 1908 | my ($self, $args) = @_; |
| 713 : | my $r = $self->r; | ||
| 714 : | my $db = $r->db; | ||
| 715 : | my $urlpath = $r->urlpath; | ||
| 716 : | dpvc | 5966 | |
| 717 : | glarose | 4909 | return "" if ( $self->{invalidSet} ); |
| 718 : | |||
| 719 : | sh002i | 1908 | my $courseID = $urlpath->arg("courseID"); |
| 720 : | toenail | 2011 | my $setID = $self->{set}->set_id if !($self->{invalidSet}); |
| 721 : | my $problemID = $self->{problem}->problem_id if !($self->{invalidProblem}); | ||
| 722 : | sh002i | 1908 | my $eUserID = $r->param("effectiveUser"); |
| 723 : | dpvc | 5966 | |
| 724 : | sh002i | 1908 | my ($prevID, $nextID); |
| 725 : | toenail | 2011 | |
| 726 : | dpvc | 5966 | if (!$self->{invalidProblem}) { |
| 727 : | toenail | 2011 | my @problemIDs = $db->listUserProblems($eUserID, $setID); |
| 728 : | foreach my $id (@problemIDs) { | ||
| 729 : | $prevID = $id if $id < $problemID | ||
| 730 : | and (not defined $prevID or $id > $prevID); | ||
| 731 : | $nextID = $id if $id > $problemID | ||
| 732 : | and (not defined $nextID or $id < $nextID); | ||
| 733 : | } | ||
| 734 : | sh002i | 1223 | } |
| 735 : | dpvc | 5966 | |
| 736 : | sh002i | 1908 | my @links; |
| 737 : | dpvc | 5966 | |
| 738 : | sh002i | 1908 | if ($prevID) { |
| 739 : | my $prevPage = $urlpath->newFromModule(__PACKAGE__, | ||
| 740 : | courseID => $courseID, setID => $setID, problemID => $prevID); | ||
| 741 : | push @links, "Previous Problem", $r->location . $prevPage->path, "navPrev"; | ||
| 742 : | } else { | ||
| 743 : | dpvc | 5605 | push @links, "Previous Problem", "", "navPrevGrey"; |
| 744 : | sh002i | 1908 | } |
| 745 : | dpvc | 5966 | |
| 746 : | if (defined($setID) && $setID ne 'Undefined_Set') { | ||
| 747 : | push @links, "Problem List", $r->location . $urlpath->parent->path, "navProbList"; | ||
| 748 : | } else { | ||
| 749 : | push @links, "Problem List", "", "navProbListGrey"; | ||
| 750 : | } | ||
| 751 : | |||
| 752 : | sh002i | 1908 | if ($nextID) { |
| 753 : | my $nextPage = $urlpath->newFromModule(__PACKAGE__, | ||
| 754 : | courseID => $courseID, setID => $setID, problemID => $nextID); | ||
| 755 : | push @links, "Next Problem", $r->location . $nextPage->path, "navNext"; | ||
| 756 : | } else { | ||
| 757 : | dpvc | 5605 | push @links, "Next Problem", "", "navNextGrey"; |
| 758 : | sh002i | 1908 | } |
| 759 : | dpvc | 5966 | |
| 760 : | sh002i | 3798 | my $tail = ""; |
| 761 : | dpvc | 5966 | |
| 762 : | sh002i | 3798 | $tail .= "&displayMode=".$self->{displayMode} if defined $self->{displayMode}; |
| 763 : | $tail .= "&showOldAnswers=".$self->{will}->{showOldAnswers} | ||
| 764 : | if defined $self->{will}->{showOldAnswers}; | ||
| 765 : | sh002i | 1908 | return $self->navMacro($args, $tail, @links); |
| 766 : | sh002i | 476 | } |
| 767 : | |||
| 768 : | sh002i | 449 | sub title { |
| 769 : | sh002i | 1908 | my ($self) = @_; |
| 770 : | toenail | 2011 | |
| 771 : | # using the url arguments won't break if the set/problem are invalid | ||
| 772 : | jj | 3533 | my $setID = WeBWorK::ContentGenerator::underscore2nbsp($self->r->urlpath->arg("setID")); |
| 773 : | toenail | 2011 | my $problemID = $self->r->urlpath->arg("problemID"); |
| 774 : | dpvc | 5966 | |
| 775 : | sh002i | 2767 | return "$setID: Problem $problemID"; |
| 776 : | sh002i | 449 | } |
| 777 : | |||
| 778 : | sub body { | ||
| 779 : | my $self = shift; | ||
| 780 : | sh002i | 1908 | my $r = $self->r; |
| 781 : | my $ce = $r->ce; | ||
| 782 : | my $db = $r->db; | ||
| 783 : | toenail | 2349 | my $authz = $r->authz; |
| 784 : | sh002i | 1908 | my $urlpath = $r->urlpath; |
| 785 : | toenail | 2349 | my $user = $r->param('user'); |
| 786 : | sh002i | 2507 | my $effectiveUser = $r->param('effectiveUser'); |
| 787 : | toenail | 2011 | |
| 788 : | glarose | 4909 | if ( $self->{invalidSet} ) { |
| 789 : | toenail | 2011 | return CGI::div({class=>"ResultsWithError"}, |
| 790 : | glarose | 4909 | CGI::p("The selected problem set (" . |
| 791 : | $urlpath->arg("setID") . ") is not " . | ||
| 792 : | "a valid set for $effectiveUser:"), | ||
| 793 : | CGI::p($self->{invalidSet})); | ||
| 794 : | } | ||
| 795 : | sh002i | 449 | |
| 796 : | toenail | 2011 | if ($self->{invalidProblem}) { |
| 797 : | return CGI::div({class=>"ResultsWithError"}, | ||
| 798 : | CGI::p("The selected problem (" . $urlpath->arg("problemID") . ") is not a valid problem for set " . $self->{set}->set_id . ".")); | ||
| 799 : | } | ||
| 800 : | |||
| 801 : | sh002i | 449 | # unpack some useful variables |
| 802 : | sh002i | 476 | my $set = $self->{set}; |
| 803 : | my $problem = $self->{problem}; | ||
| 804 : | sh002i | 1197 | my $editMode = $self->{editMode}; |
| 805 : | sh002i | 476 | my $submitAnswers = $self->{submitAnswers}; |
| 806 : | sh002i | 719 | my $checkAnswers = $self->{checkAnswers}; |
| 807 : | sh002i | 623 | my $previewAnswers = $self->{previewAnswers}; |
| 808 : | sh002i | 719 | my %want = %{ $self->{want} }; |
| 809 : | sh002i | 1197 | my %can = %{ $self->{can} }; |
| 810 : | sh002i | 719 | my %must = %{ $self->{must} }; |
| 811 : | sh002i | 476 | my %will = %{ $self->{will} }; |
| 812 : | my $pg = $self->{pg}; | ||
| 813 : | sh002i | 449 | |
| 814 : | sh002i | 1908 | my $courseName = $urlpath->arg("courseID"); |
| 815 : | gage | 1592 | |
| 816 : | sh002i | 2505 | # FIXME: move editor link to top, next to problem number. |
| 817 : | # format as "[edit]" like we're doing with course info file, etc. | ||
| 818 : | # add edit link for set as well. | ||
| 819 : | sh002i | 1908 | my $editorLink = ""; |
| 820 : | dpvc | 4158 | # if we are here without a real homework set, carry that through |
| 821 : | jj | 2020 | my $forced_field = []; |
| 822 : | $forced_field = ['sourceFilePath' => $r->param("sourceFilePath")] if | ||
| 823 : | ($set->set_id eq 'Undefined_Set'); | ||
| 824 : | toenail | 2398 | if ($authz->hasPermissions($user, "modify_problem_sets")) { |
| 825 : | sh002i | 1908 | my $editorPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::Instructor::PGProblemEditor", |
| 826 : | courseID => $courseName, setID => $set->set_id, problemID => $problem->problem_id); | ||
| 827 : | jj | 2020 | my $editorURL = $self->systemLink($editorPage, params=>$forced_field); |
| 828 : | gage | 3888 | $editorLink = CGI::p(CGI::a({href=>$editorURL,target =>'WW_Editor'}, "Edit this problem")); |
| 829 : | gage | 1592 | } |
| 830 : | sh002i | 1908 | |
| 831 : | sh002i | 449 | ##### translation errors? ##### |
| 832 : | gage | 2861 | |
| 833 : | sh002i | 425 | if ($pg->{flags}->{error_flag}) { |
| 834 : | sh002i | 3795 | if ($authz->hasPermissions($user, "view_problem_debugging_info")) { |
| 835 : | print $self->errorOutput($pg->{errors}, $pg->{body_text}); | ||
| 836 : | } else { | ||
| 837 : | print $self->errorOutput($pg->{errors}, "You do not have permission to view the details of this error."); | ||
| 838 : | } | ||
| 839 : | sh002i | 1908 | print $editorLink; |
| 840 : | return ""; | ||
| 841 : | sh002i | 425 | } |
| 842 : | sh002i | 415 | |
| 843 : | sh002i | 429 | ##### answer processing ##### |
| 844 : | sh002i | 3485 | debug("begin answer processing"); |
| 845 : | sh002i | 429 | # if answers were submitted: |
| 846 : | sh002i | 1227 | my $scoreRecordedMessage; |
| 847 : | jjholt | 2156 | my $pureProblem; |
| 848 : | sh002i | 429 | if ($submitAnswers) { |
| 849 : | sh002i | 818 | # get a "pure" (unmerged) UserProblem to modify |
| 850 : | gage | 1007 | # this will be undefined if the problem has not been assigned to this user |
| 851 : | jjholt | 2156 | $pureProblem = $db->getUserProblem($problem->user_id, $problem->set_id, $problem->problem_id); # checked |
| 852 : | sh002i | 1227 | if (defined $pureProblem) { |
| 853 : | # store answers in DB for sticky answers | ||
| 854 : | my %answersToStore; | ||
| 855 : | my %answerHash = %{ $pg->{answers} }; | ||
| 856 : | gage | 1539 | $answersToStore{$_} = $self->{formFields}->{$_} #$answerHash{$_}->{original_student_ans} -- this may have been modified for fields with multiple values. Don't use it!! |
| 857 : | sh002i | 1227 | foreach (keys %answerHash); |
| 858 : | sh002i | 1908 | |
| 859 : | gage | 1507 | # There may be some more answers to store -- one which are auxiliary entries to a primary answer. Evaluating |
| 860 : | # matrices works in this way, only the first answer triggers an answer evaluator, the rest are just inputs | ||
| 861 : | # however we need to store them. Fortunately they are still in the input form. | ||
| 862 : | my @extra_answer_names = @{ $pg->{flags}->{KEPT_EXTRA_ANSWERS}}; | ||
| 863 : | gage | 1539 | $answersToStore{$_} = $self->{formFields}->{$_} foreach (@extra_answer_names); |
| 864 : | gage | 1507 | |
| 865 : | # Now let's encode these answers to store them -- append the extra answers to the end of answer entry order | ||
| 866 : | my @answer_order = (@{$pg->{flags}->{ANSWER_ENTRY_ORDER}}, @extra_answer_names); | ||
| 867 : | sh002i | 1227 | my $answerString = encodeAnswers(%answersToStore, |
| 868 : | gage | 1507 | @answer_order); |
| 869 : | sh002i | 1227 | |
| 870 : | # store last answer to database | ||
| 871 : | $problem->last_answer($answerString); | ||
| 872 : | gage | 1007 | $pureProblem->last_answer($answerString); |
| 873 : | $db->putUserProblem($pureProblem); | ||
| 874 : | sh002i | 1227 | |
| 875 : | gage | 1007 | # store state in DB if it makes sense |
| 876 : | if ($will{recordAnswers}) { | ||
| 877 : | $problem->status($pg->{state}->{recorded_score}); | ||
| 878 : | apizer | 6149 | $problem->sub_status($pg->{state}->{sub_recorded_score}); |
| 879 : | gage | 1007 | $problem->attempted(1); |
| 880 : | $problem->num_correct($pg->{state}->{num_of_correct_ans}); | ||
| 881 : | $problem->num_incorrect($pg->{state}->{num_of_incorrect_ans}); | ||
| 882 : | $pureProblem->status($pg->{state}->{recorded_score}); | ||
| 883 : | apizer | 6149 | $pureProblem->sub_status($pg->{state}->{sub_recorded_score}); |
| 884 : | gage | 1007 | $pureProblem->attempted(1); |
| 885 : | $pureProblem->num_correct($pg->{state}->{num_of_correct_ans}); | ||
| 886 : | $pureProblem->num_incorrect($pg->{state}->{num_of_incorrect_ans}); | ||
| 887 : | sh002i | 1227 | if ($db->putUserProblem($pureProblem)) { |
| 888 : | $scoreRecordedMessage = "Your score was recorded."; | ||
| 889 : | } else { | ||
| 890 : | $scoreRecordedMessage = "Your score was not recorded because there was a failure in storing the problem record to the database."; | ||
| 891 : | } | ||
| 892 : | gage | 1007 | # write to the transaction log, just to make sure |
| 893 : | writeLog($self->{ce}, "transaction", | ||
| 894 : | $problem->problem_id."\t". | ||
| 895 : | $problem->set_id."\t". | ||
| 896 : | $problem->user_id."\t". | ||
| 897 : | $problem->source_file."\t". | ||
| 898 : | $problem->value."\t". | ||
| 899 : | $problem->max_attempts."\t". | ||
| 900 : | $problem->problem_seed."\t". | ||
| 901 : | $pureProblem->status."\t". | ||
| 902 : | $pureProblem->attempted."\t". | ||
| 903 : | $pureProblem->last_answer."\t". | ||
| 904 : | $pureProblem->num_correct."\t". | ||
| 905 : | $pureProblem->num_incorrect | ||
| 906 : | ); | ||
| 907 : | sh002i | 1227 | } else { |
| 908 : | sh002i | 2505 | if (before($set->open_date) or after($set->due_date)) { |
| 909 : | sh002i | 3357 | $scoreRecordedMessage = "Your score was not recorded because this homework set is closed."; |
| 910 : | sh002i | 1227 | } else { |
| 911 : | $scoreRecordedMessage = "Your score was not recorded."; | ||
| 912 : | } | ||
| 913 : | gage | 1007 | } |
| 914 : | sh002i | 1227 | } else { |
| 915 : | sh002i | 2505 | $scoreRecordedMessage = "Your score was not recorded because this problem has not been assigned to you."; |
| 916 : | sh002i | 431 | } |
| 917 : | sh002i | 425 | } |
| 918 : | sh002i | 1227 | |
| 919 : | gage | 794 | # logging student answers |
| 920 : | gage | 1387 | |
| 921 : | my $answer_log = $self->{ce}->{courseFiles}->{logs}->{'answer_log'}; | ||
| 922 : | jjholt | 2156 | if ( defined($answer_log ) and defined($pureProblem)) { |
| 923 : | dpvc | 2735 | if ($submitAnswers && !$authz->hasPermissions($effectiveUser, "dont_log_past_answers")) { |
| 924 : | my $answerString = ""; my $scores = ""; | ||
| 925 : | gage | 794 | my %answerHash = %{ $pg->{answers} }; |
| 926 : | gage | 1775 | # FIXME this is the line 552 error. make sure original student ans is defined. |
| 927 : | # The fact that it is not defined is probably due to an error in some answer evaluator. | ||
| 928 : | # But I think it is useful to suppress this error message in the log. | ||
| 929 : | apizer | 4030 | foreach (sortByName(undef, keys %answerHash)) { |
| 930 : | sh002i | 2635 | my $orig_ans = $answerHash{$_}->{original_student_ans}; |
| 931 : | my $student_ans = defined $orig_ans ? $orig_ans : ''; | ||
| 932 : | dpvc | 2735 | $answerString .= $student_ans."\t"; |
| 933 : | $scores .= $answerHash{$_}->{score} >= 1 ? "1" : "0"; | ||
| 934 : | gage | 1776 | } |
| 935 : | $answerString = '' unless defined($answerString); # insure string is defined. | ||
| 936 : | gage | 1387 | writeCourseLog($self->{ce}, "answer_log", |
| 937 : | join("", | ||
| 938 : | '|', $problem->user_id, | ||
| 939 : | '|', $problem->set_id, | ||
| 940 : | '|', $problem->problem_id, | ||
| 941 : | dpvc | 2735 | '|', $scores, "\t", |
| 942 : | gage | 1387 | time(),"\t", |
| 943 : | $answerString, | ||
| 944 : | ), | ||
| 945 : | ); | ||
| 946 : | |||
| 947 : | gage | 794 | } |
| 948 : | sh002i | 1223 | } |
| 949 : | |||
| 950 : | sh002i | 3485 | debug("end answer processing"); |
| 951 : | sh002i | 1223 | |
| 952 : | sh002i | 429 | ##### output ##### |
| 953 : | sh002i | 1197 | # custom message for editor |
| 954 : | toenail | 2349 | if ($authz->hasPermissions($user, "modify_problem_sets") and defined $editMode) { |
| 955 : | sh002i | 1197 | if ($editMode eq "temporaryFile") { |
| 956 : | gage | 3034 | print CGI::p(CGI::div({class=>'temporaryFile'}, "Viewing temporary file: ", $problem->source_file)); |
| 957 : | sh002i | 1197 | } elsif ($editMode eq "savedFile") { |
| 958 : | toenail | 2349 | # taken care of in the initialization phase |
| 959 : | sh002i | 1197 | } |
| 960 : | } | ||
| 961 : | gage | 3034 | print CGI::start_div({class=>"problemHeader"}); |
| 962 : | |||
| 963 : | |||
| 964 : | toenail | 2349 | |
| 965 : | sh002i | 431 | # attempt summary |
| 966 : | gage | 1480 | #FIXME -- the following is a kludge: if showPartialCorrectAnswers is negative don't show anything. |
| 967 : | # until after the due date | ||
| 968 : | toenail | 2398 | # do I need to check $will{showCorrectAnswers} to make preflight work?? |
| 969 : | sh002i | 2505 | if (($pg->{flags}->{showPartialCorrectAnswers} >= 0 and $submitAnswers) ) { |
| 970 : | sh002i | 431 | # print this if user submitted answers OR requested correct answers |
| 971 : | gage | 1480 | |
| 972 : | gage | 1507 | print $self->attemptResults($pg, 1, |
| 973 : | sh002i | 719 | $will{showCorrectAnswers}, |
| 974 : | gage | 939 | $pg->{flags}->{showPartialCorrectAnswers}, 1, 1); |
| 975 : | sh002i | 719 | } elsif ($checkAnswers) { |
| 976 : | # print this if user previewed answers | ||
| 977 : | sh002i | 2767 | print CGI::div({class=>'ResultsWithError'},"ANSWERS ONLY CHECKED -- ANSWERS NOT RECORDED"), CGI::br(); |
| 978 : | gage | 1507 | print $self->attemptResults($pg, 1, $will{showCorrectAnswers}, 1, 1, 1); |
| 979 : | sh002i | 719 | # show attempt answers |
| 980 : | gage | 1507 | # show correct answers if asked |
| 981 : | sh002i | 719 | # show attempt results (correctness) |
| 982 : | gage | 1507 | # show attempt previews |
| 983 : | sh002i | 623 | } elsif ($previewAnswers) { |
| 984 : | # print this if user previewed answers | ||
| 985 : | sh002i | 2767 | print CGI::div({class=>'ResultsWithError'},"PREVIEW ONLY -- ANSWERS NOT RECORDED"),CGI::br(),$self->attemptResults($pg, 1, 0, 0, 0, 1); |
| 986 : | sh002i | 719 | # show attempt answers |
| 987 : | sh002i | 623 | # don't show correct answers |
| 988 : | sh002i | 719 | # don't show attempt results (correctness) |
| 989 : | # show attempt previews | ||
| 990 : | sh002i | 431 | } |
| 991 : | gage | 392 | |
| 992 : | malsyned | 755 | print CGI::end_div(); |
| 993 : | |||
| 994 : | sh002i | 2505 | # main form |
| 995 : | gage | 4090 | print "\n"; |
| 996 : | gage | 5678 | print CGI::start_form(-method=>"POST", -action=> $r->uri,-name=>"problemMainForm", onsubmit=>"submitAction()"); |
| 997 : | sh002i | 2505 | print $self->hidden_authen_fields; |
| 998 : | gage | 4090 | print "\n"; |
| 999 : | malsyned | 755 | print CGI::start_div({class=>"problem"}); |
| 1000 : | sh002i | 2505 | print CGI::p($pg->{body_text}); |
| 1001 : | gage | 4235 | print CGI::p(CGI::b("Note: "). CGI::i($pg->{result}->{msg})) if $pg->{result}->{msg}; |
| 1002 : | sh002i | 3626 | print $editorLink; # this is empty unless it is appropriate to have an editor link. |
| 1003 : | sh002i | 2505 | print CGI::end_div(); |
| 1004 : | |||
| 1005 : | print CGI::start_p(); | ||
| 1006 : | |||
| 1007 : | if ($can{showCorrectAnswers}) { | ||
| 1008 : | print CGI::checkbox( | ||
| 1009 : | -name => "showCorrectAnswers", | ||
| 1010 : | -checked => $will{showCorrectAnswers}, | ||
| 1011 : | -label => "Show correct answers", | ||
| 1012 : | gage | 5636 | -value => 1, |
| 1013 : | malsyned | 755 | ); |
| 1014 : | sh002i | 2505 | } |
| 1015 : | if ($can{showHints}) { | ||
| 1016 : | print CGI::div({style=>"color:red"}, | ||
| 1017 : | CGI::checkbox( | ||
| 1018 : | -name => "showHints", | ||
| 1019 : | -checked => $will{showHints}, | ||
| 1020 : | -label => "Show Hints", | ||
| 1021 : | gage | 5636 | -value =>1, |
| 1022 : | sh002i | 2505 | ) |
| 1023 : | ); | ||
| 1024 : | } | ||
| 1025 : | if ($can{showSolutions}) { | ||
| 1026 : | print CGI::checkbox( | ||
| 1027 : | -name => "showSolutions", | ||
| 1028 : | -checked => $will{showSolutions}, | ||
| 1029 : | -label => "Show Solutions", | ||
| 1030 : | gage | 5636 | -value => 1, |
| 1031 : | sh002i | 2505 | ); |
| 1032 : | } | ||
| 1033 : | |||
| 1034 : | if ($can{showCorrectAnswers} or $can{showHints} or $can{showSolutions}) { | ||
| 1035 : | print CGI::br(); | ||
| 1036 : | } | ||
| 1037 : | |||
| 1038 : | print CGI::submit(-name=>"previewAnswers", -label=>"Preview Answers"); | ||
| 1039 : | if ($can{checkAnswers}) { | ||
| 1040 : | print CGI::submit(-name=>"checkAnswers", -label=>"Check Answers"); | ||
| 1041 : | } | ||
| 1042 : | jj | 2685 | if ($can{getSubmitButton}) { |
| 1043 : | sh002i | 2507 | if ($user ne $effectiveUser) { |
| 1044 : | # if acting as a student, make it clear that answer submissions will | ||
| 1045 : | # apply to the student's records, not the professor's. | ||
| 1046 : | print CGI::submit(-name=>"submitAnswers", -label=>"Submit Answers for $effectiveUser"); | ||
| 1047 : | } else { | ||
| 1048 : | gage | 5678 | #print CGI::submit(-name=>"submitAnswers", -label=>"Submit Answers", -onclick=>"alert('submit button clicked')"); |
| 1049 : | print CGI::submit(-name=>"submitAnswers", -label=>"Submit Answers", -onclick=>""); | ||
| 1050 : | # FIXME for unknown reasons the -onclick label seems to have to be there in order to allow the forms onsubmit to trigger | ||
| 1051 : | # WFT??? | ||
| 1052 : | sh002i | 2507 | } |
| 1053 : | sh002i | 2505 | } |
| 1054 : | |||
| 1055 : | print CGI::end_p(); | ||
| 1056 : | |||
| 1057 : | gage | 794 | print CGI::start_div({class=>"scoreSummary"}); |
| 1058 : | sh002i | 1131 | |
| 1059 : | sh002i | 431 | # score summary |
| 1060 : | my $attempts = $problem->num_correct + $problem->num_incorrect; | ||
| 1061 : | my $attemptsNoun = $attempts != 1 ? "times" : "time"; | ||
| 1062 : | gage | 2875 | my $problem_status = $problem->status || 0; |
| 1063 : | my $lastScore = sprintf("%.0f%%", $problem_status * 100); # Round to whole number | ||
| 1064 : | sh002i | 431 | my ($attemptsLeft, $attemptsLeftNoun); |
| 1065 : | if ($problem->max_attempts == -1) { | ||
| 1066 : | # unlimited attempts | ||
| 1067 : | $attemptsLeft = "unlimited"; | ||
| 1068 : | $attemptsLeftNoun = "attempts"; | ||
| 1069 : | } else { | ||
| 1070 : | $attemptsLeft = $problem->max_attempts - $attempts; | ||
| 1071 : | $attemptsLeftNoun = $attemptsLeft == 1 ? "attempt" : "attempts"; | ||
| 1072 : | } | ||
| 1073 : | malsyned | 755 | |
| 1074 : | my $setClosed = 0; | ||
| 1075 : | sh002i | 476 | my $setClosedMessage; |
| 1076 : | sh002i | 2505 | if (before($set->open_date) or after($set->due_date)) { |
| 1077 : | malsyned | 755 | $setClosed = 1; |
| 1078 : | sh002i | 3318 | if (before($set->open_date)) { |
| 1079 : | sh002i | 3357 | $setClosedMessage = "This homework set is not yet open."; |
| 1080 : | sh002i | 3318 | } elsif (after($set->due_date)) { |
| 1081 : | sh002i | 3357 | $setClosedMessage = "This homework set is closed."; |
| 1082 : | sh002i | 476 | } |
| 1083 : | } | ||
| 1084 : | sh002i | 3318 | #if (before($set->open_date) or after($set->due_date)) { |
| 1085 : | # $setClosed = 1; | ||
| 1086 : | sh002i | 3357 | # $setClosedMessage = "This homework set is closed."; |
| 1087 : | sh002i | 3318 | # if ($authz->hasPermissions($user, "view_answers")) { |
| 1088 : | # $setClosedMessage .= " However, since you are a privileged user, additional attempts will be recorded."; | ||
| 1089 : | # } else { | ||
| 1090 : | # $setClosedMessage .= " Additional attempts will not be recorded."; | ||
| 1091 : | # } | ||
| 1092 : | #} | ||
| 1093 : | gage | 3391 | unless (defined( $pg->{state}->{state_summary_msg}) and $pg->{state}->{state_summary_msg}=~/\S/) { |
| 1094 : | my $notCountedMessage = ($problem->value) ? "" : "(This problem will not count towards your grade.)"; | ||
| 1095 : | gage | 4235 | print CGI::p(join("", |
| 1096 : | gage | 3391 | $submitAnswers ? $scoreRecordedMessage . CGI::br() : "", |
| 1097 : | "You have attempted this problem $attempts $attemptsNoun.", CGI::br(), | ||
| 1098 : | $submitAnswers ?"You received a score of ".sprintf("%.0f%%", $pg->{result}->{score} * 100)." for this attempt.".CGI::br():'', | ||
| 1099 : | $problem->attempted | ||
| 1100 : | ? "Your overall recorded score is $lastScore. $notCountedMessage" . CGI::br() | ||
| 1101 : | : "", | ||
| 1102 : | $setClosed ? $setClosedMessage : "You have $attemptsLeft $attemptsLeftNoun remaining." | ||
| 1103 : | gage | 4235 | )); |
| 1104 : | gage | 3391 | }else { |
| 1105 : | print CGI::p($pg->{state}->{state_summary_msg}); | ||
| 1106 : | } | ||
| 1107 : | gage | 794 | print CGI::end_div(); |
| 1108 : | malsyned | 755 | |
| 1109 : | sh002i | 1131 | # save state for viewOptions |
| 1110 : | gage | 1591 | print CGI::hidden( |
| 1111 : | -name => "showOldAnswers", | ||
| 1112 : | -value => $will{showOldAnswers} | ||
| 1113 : | ), | ||
| 1114 : | gage | 1479 | |
| 1115 : | gage | 1591 | CGI::hidden( |
| 1116 : | -name => "displayMode", | ||
| 1117 : | -value => $self->{displayMode} | ||
| 1118 : | ); | ||
| 1119 : | print( CGI::hidden( | ||
| 1120 : | -name => 'editMode', | ||
| 1121 : | -value => $self->{editMode}, | ||
| 1122 : | ) | ||
| 1123 : | ) if defined($self->{editMode}) and $self->{editMode} eq 'temporaryFile'; | ||
| 1124 : | print( CGI::hidden( | ||
| 1125 : | -name => 'sourceFilePath', | ||
| 1126 : | -value => $self->{problem}->{source_file} | ||
| 1127 : | )) if defined($self->{problem}->{source_file}); | ||
| 1128 : | jj | 2251 | |
| 1129 : | print( CGI::hidden( | ||
| 1130 : | -name => 'problemSeed', | ||
| 1131 : | -value => $r->param("problemSeed") | ||
| 1132 : | )) if defined($r->param("problemSeed")); | ||
| 1133 : | gage | 1591 | |
| 1134 : | sh002i | 1131 | # end of main form |
| 1135 : | print CGI::endform(); | ||
| 1136 : | |||
| 1137 : | print CGI::start_div({class=>"problemFooter"}); | ||
| 1138 : | |||
| 1139 : | sh002i | 1908 | ## arguments for answer inspection button |
| 1140 : | #my $prof_url = $ce->{webworkURLs}->{oldProf}; | ||
| 1141 : | #my $webworkURL = $ce->{webworkURLs}->{root}; | ||
| 1142 : | #my $cgi_url = $prof_url; | ||
| 1143 : | #$cgi_url=~ s|/[^/]*$||; # clip profLogin.pl | ||
| 1144 : | #my $authen_args = $self->url_authen_args(); | ||
| 1145 : | #my $showPastAnswersURL = "$webworkURL/$courseName/instructor/show_answers/"; | ||
| 1146 : | gage | 794 | |
| 1147 : | sh002i | 1908 | my $pastAnswersPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::Instructor::ShowAnswers", |
| 1148 : | courseID => $courseName); | ||
| 1149 : | my $showPastAnswersURL = $self->systemLink($pastAnswersPage, authen => 0); # no authen info for form action | ||
| 1150 : | |||
| 1151 : | gage | 794 | # print answer inspection button |
| 1152 : | toenail | 2398 | if ($authz->hasPermissions($user, "view_answers")) { |
| 1153 : | gage | 794 | print "\n", |
| 1154 : | dpvc | 4389 | CGI::start_form(-method=>"POST",-action=>$showPastAnswersURL,-target=>"WW_Info"),"\n", |
| 1155 : | sh002i | 1131 | $self->hidden_authen_fields,"\n", |
| 1156 : | gage | 1937 | CGI::hidden(-name => 'courseID', -value=>$courseName), "\n", |
| 1157 : | CGI::hidden(-name => 'problemID', -value=>$problem->problem_id), "\n", | ||
| 1158 : | CGI::hidden(-name => 'setID', -value=>$problem->set_id), "\n", | ||
| 1159 : | gage | 1395 | CGI::hidden(-name => 'studentUser', -value=>$problem->user_id), "\n", |
| 1160 : | sh002i | 1131 | CGI::p( {-align=>"left"}, |
| 1161 : | CGI::submit(-name => 'action', -value=>'Show Past Answers') | ||
| 1162 : | ), "\n", | ||
| 1163 : | CGI::endform(); | ||
| 1164 : | } | ||
| 1165 : | sh002i | 667 | |
| 1166 : | sh002i | 3626 | ## feedback form url |
| 1167 : | #my $feedbackPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::Feedback", | ||
| 1168 : | # courseID => $courseName); | ||
| 1169 : | #my $feedbackURL = $self->systemLink($feedbackPage, authen => 0); # no authen info for form action | ||
| 1170 : | # | ||
| 1171 : | ##print feedback form | ||
| 1172 : | |||
| 1173 : | # CGI::start_form(-method=>"POST", -action=>$feedbackURL),"\n", | ||
| 1174 : | # $self->hidden_authen_fields,"\n", | ||
| 1175 : | # CGI::hidden("module", __PACKAGE__),"\n", | ||
| 1176 : | # CGI::hidden("set", $set->set_id),"\n", | ||
| 1177 : | # CGI::hidden("problem", $problem->problem_id),"\n", | ||
| 1178 : | # CGI::hidden("displayMode", $self->{displayMode}),"\n", | ||
| 1179 : | # CGI::hidden("showOldAnswers", $will{showOldAnswers}),"\n", | ||
| 1180 : | # CGI::hidden("showCorrectAnswers", $will{showCorrectAnswers}),"\n", | ||
| 1181 : | # CGI::hidden("showHints", $will{showHints}),"\n", | ||
| 1182 : | # CGI::hidden("showSolutions", $will{showSolutions}),"\n", | ||
| 1183 : | # CGI::p({-align=>"left"}, | ||
| 1184 : | # CGI::submit(-name=>"feedbackForm", -label=>"Email instructor") | ||
| 1185 : | # ), | ||
| 1186 : | # CGI::endform(),"\n"; | ||
| 1187 : | gage | 794 | |
| 1188 : | sh002i | 3626 | print $self->feedbackMacro( |
| 1189 : | module => __PACKAGE__, | ||
| 1190 : | set => $self->{set}->set_id, | ||
| 1191 : | problem => $problem->problem_id, | ||
| 1192 : | displayMode => $self->{displayMode}, | ||
| 1193 : | showOldAnswers => $will{showOldAnswers}, | ||
| 1194 : | showCorrectAnswers => $will{showCorrectAnswers}, | ||
| 1195 : | showHints => $will{showHints}, | ||
| 1196 : | showSolutions => $will{showSolutions}, | ||
| 1197 : | gage | 6041 | pg_object => $pg, |
| 1198 : | sh002i | 3626 | ); |
| 1199 : | sh002i | 1908 | |
| 1200 : | sh002i | 1131 | print CGI::end_div(); |
| 1201 : | gage | 940 | |
| 1202 : | sh002i | 424 | # debugging stuff |
| 1203 : | sh002i | 747 | if (0) { |
| 1204 : | sh002i | 738 | |
| 1205 : | CGI::hr(), | ||
| 1206 : | CGI::h2("debugging information"), | ||
| 1207 : | CGI::h3("form fields"), | ||
| 1208 : | ref2string($self->{formFields}), | ||
| 1209 : | CGI::h3("user object"), | ||
| 1210 : | ref2string($self->{user}), | ||
| 1211 : | CGI::h3("set object"), | ||
| 1212 : | ref2string($set), | ||
| 1213 : | CGI::h3("problem object"), | ||
| 1214 : | ref2string($problem), | ||
| 1215 : | CGI::h3("PG object"), | ||
| 1216 : | ref2string($pg, {'WeBWorK::PG::Translator' => 1}); | ||
| 1217 : | } | ||
| 1218 : | gage | 392 | |
| 1219 : | sh002i | 424 | return ""; |
| 1220 : | malsyned | 353 | } |
| 1221 : | |||
| 1222 : | jj | 2539 | 1; |
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |