| 1 | ################################################################################ |
1 | ################################################################################ |
| 2 | # WeBWorK Online Homework Delivery System |
2 | # WeBWorK Online Homework Delivery System |
| 3 | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
3 | # Copyright © 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ |
| 4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Problem.pm,v 1.168 2004/11/18 16:00:37 gage Exp $ |
4 | # $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/Problem.pm,v 1.220 2009/11/02 16:53:50 apizer Exp $ |
| 5 | # |
5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify it under |
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 |
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 |
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. |
9 | # version, or (b) the "Artistic License" which comes with this package. |
| … | |
… | |
| 23 | |
23 | |
| 24 | =cut |
24 | =cut |
| 25 | |
25 | |
| 26 | use strict; |
26 | use strict; |
| 27 | use warnings; |
27 | use warnings; |
| 28 | use CGI qw(); |
28 | #use CGI qw(-nosticky ); |
|
|
29 | use WeBWorK::CGI; |
| 29 | use File::Path qw(rmtree); |
30 | use File::Path qw(rmtree); |
|
|
31 | use WeBWorK::Debug; |
| 30 | use WeBWorK::Form; |
32 | use WeBWorK::Form; |
| 31 | use WeBWorK::PG; |
33 | use WeBWorK::PG; |
| 32 | use WeBWorK::PG::ImageGenerator; |
34 | use WeBWorK::PG::ImageGenerator; |
| 33 | use WeBWorK::PG::IO; |
35 | use WeBWorK::PG::IO; |
| 34 | use WeBWorK::Utils qw(writeLog writeCourseLog encodeAnswers decodeAnswers ref2string makeTempDirectory); |
36 | use WeBWorK::Utils qw(readFile writeLog writeCourseLog encodeAnswers decodeAnswers |
|
|
37 | ref2string makeTempDirectory path_is_subdir sortByName before after between); |
| 35 | use WeBWorK::DB::Utils qw(global2user user2global findDefaults); |
38 | use WeBWorK::DB::Utils qw(global2user user2global); |
| 36 | use WeBWorK::Timing; |
|
|
| 37 | use URI::Escape; |
39 | use URI::Escape; |
| 38 | |
40 | |
| 39 | use WeBWorK::Utils::Tasks qw(fake_set fake_problem); |
41 | use WeBWorK::Utils::Tasks qw(fake_set fake_problem); |
| 40 | |
42 | |
| 41 | ################################################################################ |
43 | ################################################################################ |
| … | |
… | |
| 83 | # Subroutines to determine if a user "can" perform an action. Each subroutine is |
85 | # Subroutines to determine if a user "can" perform an action. Each subroutine is |
| 84 | # called with the following arguments: |
86 | # called with the following arguments: |
| 85 | # |
87 | # |
| 86 | # ($self, $User, $EffectiveUser, $Set, $Problem) |
88 | # ($self, $User, $EffectiveUser, $Set, $Problem) |
| 87 | |
89 | |
|
|
90 | # 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 | |
| 88 | sub can_showOldAnswers { |
94 | sub can_showOldAnswers { |
| 89 | #my ($self, $User, $EffectiveUser, $Set, $Problem) = @_; |
95 | #my ($self, $User, $EffectiveUser, $Set, $Problem) = @_; |
| 90 | |
96 | |
| 91 | return 1; |
97 | return 1; |
| 92 | } |
98 | } |
| … | |
… | |
| 163 | } elsif (after($Set->answer_date)) { |
169 | } elsif (after($Set->answer_date)) { |
| 164 | return $authz->hasPermissions($User->user_id, "check_answers_after_answer_date"); |
170 | return $authz->hasPermissions($User->user_id, "check_answers_after_answer_date"); |
| 165 | } |
171 | } |
| 166 | } |
172 | } |
| 167 | |
173 | |
| 168 | # Helper functions for calculating times |
174 | # Reset the default in some cases |
| 169 | sub before { return time <= $_[0] } |
175 | sub set_showOldAnswers_default { |
| 170 | sub after { return time >= $_[0] } |
176 | my ($self, $ce, $userName, $authz, $set) = @_; |
| 171 | sub between { my $t = time; return $t > $_[0] && $t < $_[1] } |
177 | # 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 | # 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 | $ce->{pg}->{options}->{showOldAnswers} = 0 if $set->{due_date} && after($set->{due_date}); |
|
|
185 | } |
| 172 | |
186 | |
| 173 | ################################################################################ |
187 | ################################################################################ |
| 174 | # output utilities |
188 | # output utilities |
| 175 | ################################################################################ |
189 | ################################################################################ |
|
|
190 | |
|
|
191 | # Note: the substance of attemptResults is lifted into GatewayQuiz.pm, |
|
|
192 | # with some changes to the output format |
| 176 | |
193 | |
| 177 | sub attemptResults { |
194 | sub attemptResults { |
| 178 | my $self = shift; |
195 | my $self = shift; |
| 179 | my $pg = shift; |
196 | my $pg = shift; |
| 180 | my $showAttemptAnswers = shift; |
197 | my $showAttemptAnswers = shift; |
| … | |
… | |
| 215 | $header .= $showAttemptResults ? CGI::th("Result") : ""; |
232 | $header .= $showAttemptResults ? CGI::th("Result") : ""; |
| 216 | $header .= $showMessages ? CGI::th("Messages") : ""; |
233 | $header .= $showMessages ? CGI::th("Messages") : ""; |
| 217 | my $fully = ''; |
234 | my $fully = ''; |
| 218 | my @tableRows = ( $header ); |
235 | my @tableRows = ( $header ); |
| 219 | my $numCorrect = 0; |
236 | my $numCorrect = 0; |
|
|
237 | my $numBlanks =0; |
|
|
238 | my $tthPreambleCache; |
| 220 | foreach my $name (@answerNames) { |
239 | foreach my $name (@answerNames) { |
| 221 | my $answerResult = $pg->{answers}->{$name}; |
240 | my $answerResult = $pg->{answers}->{$name}; |
| 222 | my $studentAnswer = $answerResult->{student_ans}; # original_student_ans |
241 | my $studentAnswer = $answerResult->{student_ans}; # original_student_ans |
| 223 | my $preview = ($showAttemptPreview |
242 | my $preview = ($showAttemptPreview |
| 224 | ? $self->previewAnswer($answerResult, $imgGen) |
243 | ? $self->previewAnswer($answerResult, $imgGen, \$tthPreambleCache) |
| 225 | : ""); |
244 | : ""); |
| 226 | my $correctAnswer = $answerResult->{correct_ans}; |
245 | my $correctAnswer = $answerResult->{correct_ans}; |
| 227 | my $answerScore = $answerResult->{score}; |
246 | my $answerScore = $answerResult->{score}; |
| 228 | my $answerMessage = $showMessages ? $answerResult->{ans_message} : ""; |
247 | my $answerMessage = $showMessages ? $answerResult->{ans_message} : ""; |
| 229 | $answerMessage =~ s/\n/<BR>/g; |
248 | $answerMessage =~ s/\n/<BR>/g; |
| 230 | $numCorrect += $answerScore >= 1; |
249 | $numCorrect += $answerScore >= 1; |
|
|
250 | $numBlanks++ unless $studentAnswer =~/\S/ || $answerScore >= 1; # unless student answer contains entry |
| 231 | my $resultString = $answerScore >= 1 ? "correct" : |
251 | my $resultString = $answerScore >= 1 ? "correct" : |
| 232 | $answerScore > 0 ? int($answerScore*100)."% correct" : |
252 | $answerScore > 0 ? int($answerScore*100)."% correct" : |
| 233 | "incorrect"; |
253 | "incorrect"; |
| 234 | $fully = 'completely ' if $answerScore >0 and $answerScore < 1; |
254 | $fully = 'completely ' if $answerScore >0 and $answerScore < 1; |
| 235 | |
255 | |
| … | |
… | |
| 254 | my $scorePercent = sprintf("%.0f%%", $problemResult->{score} * 100); |
274 | my $scorePercent = sprintf("%.0f%%", $problemResult->{score} * 100); |
| 255 | # FIXME -- I left the old code in in case we have to back out. |
275 | # FIXME -- I left the old code in in case we have to back out. |
| 256 | # my $summary = "On this attempt, you answered $numCorrect out of " |
276 | # my $summary = "On this attempt, you answered $numCorrect out of " |
| 257 | # . scalar @answerNames . " $numIncorrectNoun correct, for a score of $scorePercent."; |
277 | # . scalar @answerNames . " $numIncorrectNoun correct, for a score of $scorePercent."; |
| 258 | my $summary = ""; |
278 | my $summary = ""; |
|
|
279 | unless (defined($problemResult->{summary}) and $problemResult->{summary} =~ /\S/) { |
| 259 | if (scalar @answerNames == 1) { |
280 | if (scalar @answerNames == 1) { #default messages |
| 260 | if ($numCorrect == scalar @answerNames) { |
281 | if ($numCorrect == scalar @answerNames) { |
| 261 | $summary .= CGI::div({class=>"ResultsWithoutError"},"The above answer is correct."); |
282 | $summary .= CGI::div({class=>"ResultsWithoutError"},"The answer above is correct."); |
| 262 | } else { |
283 | } else { |
| 263 | $summary .= CGI::div({class=>"ResultsWithError"},"The above answer is NOT ${fully}correct."); |
284 | $summary .= CGI::div({class=>"ResultsWithError"},"The answer above is NOT ${fully}correct."); |
| 264 | } |
285 | } |
|
|
286 | } else { |
|
|
287 | if ($numCorrect == scalar @answerNames) { |
|
|
288 | $summary .= CGI::div({class=>"ResultsWithoutError"},"All of the answers above are correct."); |
|
|
289 | } |
|
|
290 | unless ($numCorrect + $numBlanks == scalar( @answerNames)) { |
|
|
291 | $summary .= CGI::div({class=>"ResultsWithError"},"At least one of the answers above is NOT ${fully}correct."); |
|
|
292 | } |
|
|
293 | if ($numBlanks) { |
|
|
294 | my $s = ($numBlanks>1)?'':'s'; |
|
|
295 | $summary .= CGI::div({class=>"ResultsAlert"},"$numBlanks of the questions remain$s unanswered."); |
|
|
296 | } |
|
|
297 | } |
| 265 | } else { |
298 | } else { |
| 266 | if ($numCorrect == scalar @answerNames) { |
299 | $summary = $problemResult->{summary}; # summary has been defined by grader |
| 267 | $summary .= CGI::div({class=>"ResultsWithoutError"},"All of the above answers are correct."); |
|
|
| 268 | } else { |
|
|
| 269 | $summary .= CGI::div({class=>"ResultsWithError"},"At least one of the above answers is NOT ${fully}correct."); |
|
|
| 270 | } |
|
|
| 271 | } |
300 | } |
| 272 | |
|
|
| 273 | return |
301 | return |
| 274 | CGI::table({-class=>"attemptResults"}, CGI::Tr(\@tableRows)) |
302 | CGI::table({-class=>"attemptResults"}, CGI::Tr(\@tableRows)) |
| 275 | . ($showSummary ? CGI::p({class=>'emphasis'},$summary) : ""); |
303 | . ($showSummary ? CGI::p({class=>'attemptResultsSummary'},$summary) : ""); |
| 276 | } |
304 | } |
| 277 | |
305 | |
|
|
306 | |
|
|
307 | # Note: previewAnswer is lifted into GatewayQuiz.pm |
| 278 | |
308 | |
| 279 | sub previewAnswer { |
309 | sub previewAnswer { |
| 280 | my ($self, $answerResult, $imgGen) = @_; |
310 | my ($self, $answerResult, $imgGen, $tthPreambleCache) = @_; |
| 281 | my $ce = $self->r->ce; |
311 | my $ce = $self->r->ce; |
| 282 | my $effectiveUser = $self->{effectiveUser}; |
312 | my $effectiveUser = $self->{effectiveUser}; |
| 283 | my $set = $self->{set}; |
313 | my $set = $self->{set}; |
| 284 | my $problem = $self->{problem}; |
314 | my $problem = $self->{problem}; |
| 285 | my $displayMode = $self->{displayMode}; |
315 | my $displayMode = $self->{displayMode}; |
| … | |
… | |
| 294 | return "" unless defined $tex and $tex ne ""; |
324 | return "" unless defined $tex and $tex ne ""; |
| 295 | |
325 | |
| 296 | if ($displayMode eq "plainText") { |
326 | if ($displayMode eq "plainText") { |
| 297 | return $tex; |
327 | return $tex; |
| 298 | } elsif ($displayMode eq "formattedText") { |
328 | } elsif ($displayMode eq "formattedText") { |
|
|
329 | |
|
|
330 | # read the TTH preamble, or use the cached copy passed in from the caller |
|
|
331 | my $tthPreamble=''; |
|
|
332 | 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 |
| 299 | my $tthCommand = $ce->{externalPrograms}->{tth} |
350 | my $tthCommand = $ce->{externalPrograms}->{tth} |
| 300 | . " -L -f5 -r 2> /dev/null <<END_OF_INPUT; echo > /dev/null\n" |
351 | . " -L -f5 -u -r 2> /dev/null <<END_OF_INPUT; echo > /dev/null\n" |
| 301 | . "\\(".$tex."\\)\n" |
352 | . $tthPreamble . "\\[" . $tex . "\\]\n" |
| 302 | . "END_OF_INPUT\n"; |
353 | . "END_OF_INPUT\n"; |
| 303 | |
354 | |
| 304 | # call tth |
355 | # call tth |
| 305 | my $result = `$tthCommand`; |
356 | my $result = `$tthCommand`; |
| 306 | if ($?) { |
357 | if ($?) { |
| 307 | return "<b>[tth failed: $? $@]</b>"; |
358 | return "<b>[tth failed: $? $@]</b>"; |
| 308 | } else { |
359 | } else { |
|
|
360 | # 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" />!!; |
| 309 | return $result; |
363 | return $result; |
| 310 | } |
364 | } |
|
|
365 | |
| 311 | } elsif ($displayMode eq "images") { |
366 | } elsif ($displayMode eq "images") { |
| 312 | $imgGen->add($tex); |
367 | $imgGen->add($tex); |
| 313 | } elsif ($displayMode eq "jsMath") { |
368 | } elsif ($displayMode eq "jsMath") { |
| 314 | return '<DIV CLASS="math">'.$tex.'</DIV>' ; |
369 | $tex =~ s/</</g; $tex =~ s/>/>/g; |
|
|
370 | return '<SPAN CLASS="math">\\displaystyle{'.$tex.'}</SPAN>'; |
| 315 | } |
371 | } |
| 316 | } |
372 | } |
| 317 | |
373 | |
| 318 | ################################################################################ |
374 | ################################################################################ |
| 319 | # Template escape implementations |
375 | # Template escape implementations |
| … | |
… | |
| 330 | my $setName = $urlpath->arg("setID"); |
386 | my $setName = $urlpath->arg("setID"); |
| 331 | my $problemNumber = $r->urlpath->arg("problemID"); |
387 | my $problemNumber = $r->urlpath->arg("problemID"); |
| 332 | my $userName = $r->param('user'); |
388 | my $userName = $r->param('user'); |
| 333 | my $effectiveUserName = $r->param('effectiveUser'); |
389 | my $effectiveUserName = $r->param('effectiveUser'); |
| 334 | my $key = $r->param('key'); |
390 | my $key = $r->param('key'); |
|
|
391 | my $editMode = $r->param("editMode"); |
| 335 | |
392 | |
| 336 | my $user = $db->getUser($userName); # checked |
393 | my $user = $db->getUser($userName); # checked |
| 337 | die "record for user $userName (real user) does not exist." |
394 | die "record for user $userName (real user) does not exist." |
| 338 | unless defined $user; |
395 | unless defined $user; |
| 339 | |
396 | |
| … | |
… | |
| 341 | die "record for user $effectiveUserName (effective user) does not exist." |
398 | die "record for user $effectiveUserName (effective user) does not exist." |
| 342 | unless defined $effectiveUser; |
399 | unless defined $effectiveUser; |
| 343 | |
400 | |
| 344 | # obtain the merged set for $effectiveUser |
401 | # obtain the merged set for $effectiveUser |
| 345 | my $set = $db->getMergedSet($effectiveUserName, $setName); # checked |
402 | my $set = $db->getMergedSet($effectiveUserName, $setName); # checked |
|
|
403 | |
|
|
404 | $self->set_showOldAnswers_default($ce, $userName, $authz, $set); |
| 346 | |
405 | |
| 347 | # Database fix (in case of undefined published values) |
406 | # Database fix (in case of undefined published values) |
| 348 | # this is only necessary because some people keep holding to ww1.9 which did not have a published field |
407 | # this is only necessary because some people keep holding to ww1.9 which did not have a published field |
| 349 | # make sure published is set to 0 or 1 |
408 | # make sure published is set to 0 or 1 |
| 350 | if ( $set and $set->published ne "0" and $set->published ne "1") { |
409 | if ( $set and $set->published ne "0" and $set->published ne "1") { |
| … | |
… | |
| 354 | $set = $db->getMergedSet($effectiveUserName, $setName); |
413 | $set = $db->getMergedSet($effectiveUserName, $setName); |
| 355 | } else { |
414 | } else { |
| 356 | # don't do anything just yet, maybe we're a professor and we're |
415 | # don't do anything just yet, maybe we're a professor and we're |
| 357 | # fabricating a set or haven't assigned it to ourselves just yet |
416 | # fabricating a set or haven't assigned it to ourselves just yet |
| 358 | } |
417 | } |
|
|
418 | # When a set is created enable_reduced_scoring is null, so we have to set it |
|
|
419 | if ( $set and $set->enable_reduced_scoring ne "0" and $set->enable_reduced_scoring ne "1") { |
|
|
420 | my $globalSet = $db->getGlobalSet($set->set_id); |
|
|
421 | $globalSet->enable_reduced_scoring("0"); # defaults to disabled |
|
|
422 | $db->putGlobalSet($globalSet); |
|
|
423 | $set = $db->getMergedSet($effectiveUserName, $setName); |
|
|
424 | } |
|
|
425 | |
| 359 | |
426 | |
| 360 | # obtain the merged problem for $effectiveUser |
427 | # obtain the merged problem for $effectiveUser |
| 361 | my $problem = $db->getMergedProblem($effectiveUserName, $setName, $problemNumber); # checked |
428 | my $problem = $db->getMergedProblem($effectiveUserName, $setName, $problemNumber); # checked |
| 362 | |
429 | |
| 363 | my $editMode = $r->param("editMode"); |
|
|
| 364 | |
|
|
| 365 | if ($authz->hasPermissions($userName, "modify_problem_sets")) { |
430 | if ($authz->hasPermissions($userName, "modify_problem_sets")) { |
| 366 | # professors are allowed to fabricate sets and problems not |
431 | # professors are allowed to fabricate sets and problems not |
| 367 | # assigned to them (or anyone). this allows them to use the |
432 | # assigned to them (or anyone). this allows them to use the |
| 368 | # editor to |
433 | # editor to |
| 369 | |
434 | |
| … | |
… | |
| 389 | my $userProblemClass = $db->{problem_user}->{record}; |
454 | my $userProblemClass = $db->{problem_user}->{record}; |
| 390 | my $globalProblem = $db->getGlobalProblem($setName, $problemNumber); # checked |
455 | my $globalProblem = $db->getGlobalProblem($setName, $problemNumber); # checked |
| 391 | # if the global problem doesn't exist either, bail! |
456 | # if the global problem doesn't exist either, bail! |
| 392 | if(not defined $globalProblem) { |
457 | if(not defined $globalProblem) { |
| 393 | my $sourceFilePath = $r->param("sourceFilePath"); |
458 | my $sourceFilePath = $r->param("sourceFilePath"); |
|
|
459 | die "sourceFilePath is unsafe!" unless path_is_subdir($sourceFilePath, $ce->{courseDirs}->{templates}, 1); # 1==path can be relative to dir |
| 394 | # These are problems from setmaker. If declared invalid, they won't come up |
460 | # These are problems from setmaker. If declared invalid, they won't come up |
| 395 | $self->{invalidProblem} = $self->{invalidSet} = 1 unless defined $sourceFilePath; |
461 | $self->{invalidProblem} = $self->{invalidSet} = 1 unless defined $sourceFilePath; |
| 396 | # die "Problem $problemNumber in set $setName does not exist" unless defined $sourceFilePath; |
462 | # die "Problem $problemNumber in set $setName does not exist" unless defined $sourceFilePath; |
| 397 | $problem = fake_problem($db); |
463 | $problem = fake_problem($db); |
| 398 | $problem->problem_id(1); |
464 | $problem->problem_id(1); |
| … | |
… | |
| 416 | # now deal with possible editor overrides: |
482 | # now deal with possible editor overrides: |
| 417 | |
483 | |
| 418 | # if the caller is asking to override the source file, and |
484 | # if the caller is asking to override the source file, and |
| 419 | # editMode calls for a temporary file, do so |
485 | # editMode calls for a temporary file, do so |
| 420 | my $sourceFilePath = $r->param("sourceFilePath"); |
486 | my $sourceFilePath = $r->param("sourceFilePath"); |
| 421 | if (defined $sourceFilePath and |
487 | if (defined $editMode and $editMode eq "temporaryFile" and defined $sourceFilePath) { |
| 422 | (not defined $editMode or $editMode eq "temporaryFile")) { |
488 | die "sourceFilePath is unsafe!" unless path_is_subdir($sourceFilePath, $ce->{courseDirs}->{templates}, 1); # 1==path can be relative to dir |
| 423 | $problem->source_file($sourceFilePath); |
489 | $problem->source_file($sourceFilePath); |
| 424 | } |
490 | } |
| 425 | |
491 | |
| 426 | # if the problem does not have a source file or no source file has been passed in |
492 | # if the problem does not have a source file or no source file has been passed in |
| 427 | # then this is really an invalid problem (probably from a bad URL) |
493 | # then this is really an invalid problem (probably from a bad URL) |
| … | |
… | |
| 433 | $problem->problem_seed($problemSeed); |
499 | $problem->problem_seed($problemSeed); |
| 434 | } |
500 | } |
| 435 | |
501 | |
| 436 | my $publishedClass = ($set->published) ? "Published" : "Unpublished"; |
502 | my $publishedClass = ($set->published) ? "Published" : "Unpublished"; |
| 437 | my $publishedText = ($set->published) ? "visible to students." : "hidden from students."; |
503 | my $publishedText = ($set->published) ? "visible to students." : "hidden from students."; |
| 438 | $self->addmessage(CGI::p("This set is " . CGI::font({class=>$publishedClass}, $publishedText))); |
504 | $self->addmessage(CGI::span("This set is " . CGI::font({class=>$publishedClass}, $publishedText))); |
| 439 | } else { |
505 | |
| 440 | |
506 | # test for additional problem validity if it's not already invalid |
| 441 | # A set is valid if it exists and if it is either published or the user is privileged. |
507 | } else { |
| 442 | $self->{invalidSet} = !(defined $set and ($set->published || $authz->hasPermissions($userName, "view_unpublished_sets"))); |
|
|
| 443 | $self->{invalidProblem} = !(defined $problem and ($set->published || $authz->hasPermissions($userName, "view_unpublished_sets"))); |
508 | $self->{invalidProblem} = !(defined $problem and ($set->published || $authz->hasPermissions($userName, "view_unpublished_sets"))); |
| 444 | |
509 | |
| 445 | $self->addbadmessage(CGI::p("This problem will not count towards your grade.")) if $problem and not $problem->value and not $self->{invalidProblem}; |
510 | $self->addbadmessage(CGI::p("This problem will not count towards your grade.")) if $problem and not $problem->value and not $self->{invalidProblem}; |
| 446 | } |
511 | } |
| 447 | |
512 | |
| … | |
… | |
| 470 | $self->{checkAnswers} = $checkAnswers; |
535 | $self->{checkAnswers} = $checkAnswers; |
| 471 | $self->{previewAnswers} = $previewAnswers; |
536 | $self->{previewAnswers} = $previewAnswers; |
| 472 | $self->{formFields} = $formFields; |
537 | $self->{formFields} = $formFields; |
| 473 | |
538 | |
| 474 | # get result and send to message |
539 | # get result and send to message |
| 475 | # my $success = $r->param("success"); |
|
|
| 476 | # my $failure = $r->param("failure"); |
|
|
| 477 | my $status_message = $r->param("status_message"); |
540 | my $status_message = $r->param("status_message"); |
| 478 | # $self->addbadmessage(CGI::p($failure)) if $failure; |
|
|
| 479 | # $self->addgoodmessage(CGI::p($success)) if $success; |
|
|
| 480 | $self->addgoodmessage(CGI::p("$status_message")) if $status_message; |
541 | $self->addmessage(CGI::p("$status_message")) if $status_message; |
| 481 | |
542 | |
| 482 | # now that we've set all the necessary variables quit out if the set or problem is invalid |
543 | # now that we've set all the necessary variables quit out if the set or problem is invalid |
| 483 | return if $self->{invalidSet} || $self->{invalidProblem}; |
544 | return if $self->{invalidSet} || $self->{invalidProblem}; |
| 484 | |
545 | |
| 485 | ##### permissions ##### |
546 | ##### permissions ##### |
| 486 | |
547 | |
| 487 | # are we allowed to view this problem? |
|
|
| 488 | $self->{isOpen} = after($set->open_date) || $authz->hasPermissions($userName, "view_unopened_sets"); |
|
|
| 489 | return unless $self->{isOpen}; |
|
|
| 490 | |
|
|
| 491 | # what does the user want to do? |
548 | # what does the user want to do? |
| 492 | #FIXME There is a problem with checkboxes -- if they are not checked they are invisible. Hence if the default mode in $ce is 1 |
549 | #FIXME There is a problem with checkboxes -- if they are not checked they are invisible. Hence if the default mode in $ce is 1 |
| 493 | # there is no way to override this. Probably this is ok for the last three options, but it was definitely not ok for showing |
550 | # there is no way to override this. Probably this is ok for the last three options, but it was definitely not ok for showing |
| 494 | # saved answers which is normally on, but you want to be able to turn it off! This section should be moved to ContentGenerator |
551 | # saved answers which is normally on, but you want to be able to turn it off! This section should be moved to ContentGenerator |
| 495 | # so that you can set these options anywhere. We also need mechanisms for making them sticky. |
552 | # so that you can set these options anywhere. We also need mechanisms for making them sticky. |
|
|
553 | # Note: ProblemSet and ProblemSets might set showOldAnswers to '', which |
|
|
554 | # needs to be treated as if it is not set. |
| 496 | my %want = ( |
555 | my %want = ( |
| 497 | showOldAnswers => defined($r->param("showOldAnswers")) ? $r->param("showOldAnswers") : $ce->{pg}->{options}->{showOldAnswers}, |
556 | showOldAnswers => (defined($r->param("showOldAnswers")) and $r->param("showOldAnswers") ne '') ? $r->param("showOldAnswers") : $ce->{pg}->{options}->{showOldAnswers}, |
| 498 | showCorrectAnswers => $r->param("showCorrectAnswers") || $ce->{pg}->{options}->{showCorrectAnswers}, |
557 | showCorrectAnswers => $r->param("showCorrectAnswers") || $ce->{pg}->{options}->{showCorrectAnswers}, |
| 499 | showHints => $r->param("showHints") || $ce->{pg}->{options}->{showHints}, |
558 | showHints => $r->param("showHints") || $ce->{pg}->{options}->{showHints}, |
| 500 | showSolutions => $r->param("showSolutions") || $ce->{pg}->{options}->{showSolutions}, |
559 | showSolutions => $r->param("showSolutions") || $ce->{pg}->{options}->{showSolutions}, |
| 501 | recordAnswers => $submitAnswers, |
560 | recordAnswers => $submitAnswers, |
| 502 | checkAnswers => $checkAnswers, |
561 | checkAnswers => $checkAnswers, |
| … | |
… | |
| 528 | |
587 | |
| 529 | # final values for options |
588 | # final values for options |
| 530 | my %will; |
589 | my %will; |
| 531 | foreach (keys %must) { |
590 | foreach (keys %must) { |
| 532 | $will{$_} = $can{$_} && ($want{$_} || $must{$_}); |
591 | $will{$_} = $can{$_} && ($want{$_} || $must{$_}); |
|
|
592 | #warn "final values for options $_ is can $can{$_}, want $want{$_}, must $must{$_}, will $will{$_}"; |
| 533 | } |
593 | } |
| 534 | |
594 | |
| 535 | ##### sticky answers ##### |
595 | ##### sticky answers ##### |
| 536 | |
596 | |
| 537 | if (not ($submitAnswers or $previewAnswers or $checkAnswers) and $will{showOldAnswers}) { |
597 | if (not ($submitAnswers or $previewAnswers or $checkAnswers) and $will{showOldAnswers}) { |
| … | |
… | |
| 540 | $formFields->{$_} = $oldAnswers{$_} foreach keys %oldAnswers; |
600 | $formFields->{$_} = $oldAnswers{$_} foreach keys %oldAnswers; |
| 541 | } |
601 | } |
| 542 | |
602 | |
| 543 | ##### translation ##### |
603 | ##### translation ##### |
| 544 | |
604 | |
| 545 | $WeBWorK::timer->continue("begin pg processing") if defined($WeBWorK::timer); |
605 | debug("begin pg processing"); |
| 546 | my $pg = WeBWorK::PG->new( |
606 | my $pg = WeBWorK::PG->new( |
| 547 | $ce, |
607 | $ce, |
| 548 | $effectiveUser, |
608 | $effectiveUser, |
| 549 | $key, |
609 | $key, |
| 550 | $set, |
610 | $set, |
| … | |
… | |
| 555 | displayMode => $displayMode, |
615 | displayMode => $displayMode, |
| 556 | showHints => $will{showHints}, |
616 | showHints => $will{showHints}, |
| 557 | showSolutions => $will{showSolutions}, |
617 | showSolutions => $will{showSolutions}, |
| 558 | refreshMath2img => $will{showHints} || $will{showSolutions}, |
618 | refreshMath2img => $will{showHints} || $will{showSolutions}, |
| 559 | processAnswers => 1, |
619 | processAnswers => 1, |
|
|
620 | permissionLevel => $db->getPermissionLevel($userName)->permission, |
|
|
621 | effectivePermissionLevel => $db->getPermissionLevel($effectiveUserName)->permission, |
| 560 | }, |
622 | }, |
| 561 | ); |
623 | ); |
| 562 | |
624 | |
| 563 | $WeBWorK::timer->continue("end pg processing") if defined($WeBWorK::timer); |
625 | debug("end pg processing"); |
| 564 | |
626 | |
| 565 | ##### fix hint/solution options ##### |
627 | ##### fix hint/solution options ##### |
| 566 | |
628 | |
| 567 | $can{showHints} &&= $pg->{flags}->{hintExists} |
629 | $can{showHints} &&= $pg->{flags}->{hintExists} |
| 568 | &&= $pg->{flags}->{showHintLimit}<=$pg->{state}->{num_of_incorrect_ans}; |
630 | &&= $pg->{flags}->{showHintLimit}<=$pg->{state}->{num_of_incorrect_ans}; |
| … | |
… | |
| 587 | } |
649 | } |
| 588 | } |
650 | } |
| 589 | |
651 | |
| 590 | sub head { |
652 | sub head { |
| 591 | my ($self) = @_; |
653 | my ($self) = @_; |
| 592 | |
654 | |
| 593 | return "" unless $self->{isOpen}; |
655 | return "" if ( $self->{invalidSet} ); |
| 594 | return $self->{pg}->{head_text} if $self->{pg}->{head_text}; |
656 | return $self->{pg}->{head_text} if $self->{pg}->{head_text}; |
| 595 | } |
657 | } |
| 596 | |
658 | |
| 597 | # sub options { |
659 | sub options { |
| 598 | # my ($self) = @_; |
660 | my ($self) = @_; |
| 599 | # warn "doing options in Problem"; |
661 | #warn "doing options in Problem"; |
|
|
662 | |
|
|
663 | # don't show options if we don't have anything to show |
| 600 | # return "" if $self->{invalidProblem}; |
664 | return "" if $self->{invalidSet} or $self->{invalidProblem}; |
| 601 | # my $sourceFilePathfield = ''; |
665 | |
| 602 | # if($self->r->param("sourceFilePath")) { |
666 | my $displayMode = $self->{displayMode}; |
| 603 | # $sourceFilePathfield = CGI::hidden(-name => "sourceFilePath", |
667 | my %can = %{ $self->{can} }; |
| 604 | # -value => $self->r->param("sourceFilePath")); |
668 | |
| 605 | # } |
669 | my @options_to_show = "displayMode"; |
| 606 | # |
670 | push @options_to_show, "showOldAnswers" if $can{showOldAnswers}; |
| 607 | # return join("", |
671 | push @options_to_show, "showHints" if $can{showHints}; |
| 608 | # CGI::start_form("POST", $self->{r}->uri), |
672 | push @options_to_show, "showSolutions" if $can{showSolutions}; |
| 609 | # $self->hidden_authen_fields, |
673 | |
| 610 | # $sourceFilePathfield, |
674 | return $self->optionsMacro( |
| 611 | # CGI::hr(), |
675 | options_to_show => \@options_to_show, |
| 612 | # CGI::start_div({class=>"viewOptions"}), |
676 | extra_params => ["editMode", "sourceFilePath"], |
| 613 | # $self->viewOptions(), |
|
|
| 614 | # CGI::end_div(), |
|
|
| 615 | # CGI::end_form() |
|
|
| 616 | # ); |
677 | ); |
| 617 | # } |
678 | } |
| 618 | |
679 | |
| 619 | sub siblings { |
680 | sub siblings { |
| 620 | my ($self) = @_; |
681 | my ($self) = @_; |
| 621 | my $r = $self->r; |
682 | my $r = $self->r; |
| 622 | my $db = $r->db; |
683 | my $db = $r->db; |
| … | |
… | |
| 628 | my $courseID = $urlpath->arg("courseID"); |
689 | my $courseID = $urlpath->arg("courseID"); |
| 629 | my $setID = $self->{set}->set_id; |
690 | my $setID = $self->{set}->set_id; |
| 630 | my $eUserID = $r->param("effectiveUser"); |
691 | my $eUserID = $r->param("effectiveUser"); |
| 631 | my @problemIDs = sort { $a <=> $b } $db->listUserProblems($eUserID, $setID); |
692 | my @problemIDs = sort { $a <=> $b } $db->listUserProblems($eUserID, $setID); |
| 632 | |
693 | |
|
|
694 | print CGI::start_div({class=>"info-box", id=>"fisheye"}); |
|
|
695 | print CGI::h2("Problems"); |
| 633 | print CGI::start_ul({class=>"LinksMenu"}); |
696 | #print CGI::start_ul({class=>"LinksMenu"}); |
| 634 | print CGI::start_li(); |
697 | #print CGI::start_li(); |
| 635 | print CGI::span({style=>"font-size:larger"}, "Problems"); |
698 | #print CGI::span({style=>"font-size:larger"}, "Problems"); |
| 636 | print CGI::start_ul(); |
699 | print CGI::start_ul(); |
| 637 | |
700 | |
| 638 | foreach my $problemID (@problemIDs) { |
701 | foreach my $problemID (@problemIDs) { |
| 639 | my $problemPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::Problem", |
702 | my $problemPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::Problem", |
| 640 | courseID => $courseID, setID => $setID, problemID => $problemID); |
703 | courseID => $courseID, setID => $setID, problemID => $problemID); |
| … | |
… | |
| 642 | params=>{ displayMode => $self->{displayMode}, |
705 | params=>{ displayMode => $self->{displayMode}, |
| 643 | showOldAnswers => $self->{will}->{showOldAnswers} |
706 | showOldAnswers => $self->{will}->{showOldAnswers} |
| 644 | })}, "Problem $problemID") |
707 | })}, "Problem $problemID") |
| 645 | ); |
708 | ); |
| 646 | } |
709 | } |
| 647 | |
710 | |
| 648 | print CGI::end_ul(); |
711 | print CGI::end_ul(); |
| 649 | print CGI::end_li(); |
712 | #print CGI::end_li(); |
| 650 | print CGI::end_ul(); |
713 | #print CGI::end_ul(); |
| 651 | |
714 | print CGI::end_div(); |
|
|
715 | |
| 652 | return ""; |
716 | return ""; |
| 653 | } |
717 | } |
| 654 | |
718 | |
| 655 | sub nav { |
719 | sub nav { |
| 656 | my ($self, $args) = @_; |
720 | my ($self, $args) = @_; |
| 657 | my $r = $self->r; |
721 | my $r = $self->r; |
| 658 | my $db = $r->db; |
722 | my $db = $r->db; |
| 659 | my $urlpath = $r->urlpath; |
723 | my $urlpath = $r->urlpath; |
| 660 | |
724 | |
|
|
725 | return "" if ( $self->{invalidSet} ); |
|
|
726 | |
| 661 | my $courseID = $urlpath->arg("courseID"); |
727 | my $courseID = $urlpath->arg("courseID"); |
| 662 | my $setID = $self->{set}->set_id if !($self->{invalidSet}); |
728 | my $setID = $self->{set}->set_id if !($self->{invalidSet}); |
| 663 | my $problemID = $self->{problem}->problem_id if !($self->{invalidProblem}); |
729 | my $problemID = $self->{problem}->problem_id if !($self->{invalidProblem}); |
| 664 | my $eUserID = $r->param("effectiveUser"); |
730 | my $eUserID = $r->param("effectiveUser"); |
| 665 | |
731 | |
| 666 | my ($prevID, $nextID); |
732 | my ($prevID, $nextID); |
| 667 | |
733 | |
| 668 | if (!$self->{invalidProblem}) { |
734 | if (!$self->{invalidProblem}) { |
| 669 | my @problemIDs = $db->listUserProblems($eUserID, $setID); |
735 | my @problemIDs = $db->listUserProblems($eUserID, $setID); |
| 670 | foreach my $id (@problemIDs) { |
736 | foreach my $id (@problemIDs) { |
| 671 | $prevID = $id if $id < $problemID |
737 | $prevID = $id if $id < $problemID |
| 672 | and (not defined $prevID or $id > $prevID); |
738 | and (not defined $prevID or $id > $prevID); |
| 673 | $nextID = $id if $id > $problemID |
739 | $nextID = $id if $id > $problemID |
| 674 | and (not defined $nextID or $id < $nextID); |
740 | and (not defined $nextID or $id < $nextID); |
| 675 | } |
741 | } |
| 676 | } |
742 | } |
| 677 | |
743 | |
| 678 | my @links; |
744 | my @links; |
| 679 | |
745 | |
| 680 | if ($prevID) { |
746 | if ($prevID) { |
| 681 | my $prevPage = $urlpath->newFromModule(__PACKAGE__, |
747 | my $prevPage = $urlpath->newFromModule(__PACKAGE__, |
| 682 | courseID => $courseID, setID => $setID, problemID => $prevID); |
748 | courseID => $courseID, setID => $setID, problemID => $prevID); |
| 683 | push @links, "Previous Problem", $r->location . $prevPage->path, "navPrev"; |
749 | push @links, "Previous Problem", $r->location . $prevPage->path, "navPrev"; |
| 684 | } else { |
750 | } else { |
| 685 | push @links, "Previous Problem", "", "navPrev"; |
751 | push @links, "Previous Problem", "", "navPrevGrey"; |
| 686 | } |
752 | } |
| 687 | |
753 | |
|
|
754 | if (defined($setID) && $setID ne 'Undefined_Set') { |
| 688 | push @links, "Problem List", $r->location . $urlpath->parent->path, "navProbList"; |
755 | push @links, "Problem List", $r->location . $urlpath->parent->path, "navProbList"; |
| 689 | |
756 | } else { |
|
|
757 | push @links, "Problem List", "", "navProbListGrey"; |
|
|
758 | } |
|
|
759 | |
| 690 | if ($nextID) { |
760 | if ($nextID) { |
| 691 | my $nextPage = $urlpath->newFromModule(__PACKAGE__, |
761 | my $nextPage = $urlpath->newFromModule(__PACKAGE__, |
| 692 | courseID => $courseID, setID => $setID, problemID => $nextID); |
762 | courseID => $courseID, setID => $setID, problemID => $nextID); |
| 693 | push @links, "Next Problem", $r->location . $nextPage->path, "navNext"; |
763 | push @links, "Next Problem", $r->location . $nextPage->path, "navNext"; |
| 694 | } else { |
764 | } else { |
| 695 | push @links, "Next Problem", "", "navNext"; |
765 | push @links, "Next Problem", "", "navNextGrey"; |
| 696 | } |
766 | } |
| 697 | |
767 | |
| 698 | my $tail = "&displayMode=".$self->{displayMode}."&showOldAnswers=".$self->{will}->{showOldAnswers}; |
768 | my $tail = ""; |
|
|
769 | |
|
|
770 | $tail .= "&displayMode=".$self->{displayMode} if defined $self->{displayMode}; |
|
|
771 | $tail .= "&showOldAnswers=".$self->{will}->{showOldAnswers} |
|
|
772 | if defined $self->{will}->{showOldAnswers}; |
| 699 | return $self->navMacro($args, $tail, @links); |
773 | return $self->navMacro($args, $tail, @links); |
| 700 | } |
774 | } |
| 701 | |
775 | |
| 702 | sub title { |
776 | sub title { |
| 703 | my ($self) = @_; |
777 | my ($self) = @_; |
| 704 | |
778 | |
| 705 | # using the url arguments won't break if the set/problem are invalid |
779 | # using the url arguments won't break if the set/problem are invalid |
| 706 | my $setID = $self->r->urlpath->arg("setID"); |
780 | my $setID = WeBWorK::ContentGenerator::underscore2nbsp($self->r->urlpath->arg("setID")); |
| 707 | my $problemID = $self->r->urlpath->arg("problemID"); |
781 | my $problemID = $self->r->urlpath->arg("problemID"); |
| 708 | |
782 | |
| 709 | return "$setID: Problem $problemID"; |
783 | return "$setID: Problem $problemID"; |
| 710 | } |
784 | } |
| 711 | |
785 | |
| 712 | sub body { |
786 | sub body { |
| 713 | my $self = shift; |
787 | my $self = shift; |
| … | |
… | |
| 717 | my $authz = $r->authz; |
791 | my $authz = $r->authz; |
| 718 | my $urlpath = $r->urlpath; |
792 | my $urlpath = $r->urlpath; |
| 719 | my $user = $r->param('user'); |
793 | my $user = $r->param('user'); |
| 720 | my $effectiveUser = $r->param('effectiveUser'); |
794 | my $effectiveUser = $r->param('effectiveUser'); |
| 721 | |
795 | |
| 722 | if ($self->{invalidSet}) { |
796 | if ( $self->{invalidSet} ) { |
| 723 | return CGI::div({class=>"ResultsWithError"}, |
797 | return CGI::div({class=>"ResultsWithError"}, |
| 724 | CGI::p("The selected problem set (" . $urlpath->arg("setID") . ") is not a valid set for " . $r->param("effectiveUser") . ".")); |
798 | CGI::p("The selected problem set (" . |
|
|
799 | $urlpath->arg("setID") . ") is not " . |
|
|
800 | "a valid set for $effectiveUser:"), |
|
|
801 | CGI::p($self->{invalidSet})); |
| 725 | } |
802 | } |
| 726 | |
803 | |
| 727 | if ($self->{invalidProblem}) { |
804 | if ($self->{invalidProblem}) { |
| 728 | return CGI::div({class=>"ResultsWithError"}, |
805 | return CGI::div({class=>"ResultsWithError"}, |
| 729 | CGI::p("The selected problem (" . $urlpath->arg("problemID") . ") is not a valid problem for set " . $self->{set}->set_id . ".")); |
806 | CGI::p("The selected problem (" . $urlpath->arg("problemID") . ") is not a valid problem for set " . $self->{set}->set_id . ".")); |
| 730 | } |
807 | } |
| 731 | |
808 | |
| 732 | unless ($self->{isOpen}) { |
|
|
| 733 | return CGI::div({class=>"ResultsWithError"}, |
|
|
| 734 | CGI::p("This problem is not available because the problem set that contains it is not yet open.")); |
|
|
| 735 | } |
|
|
| 736 | # unpack some useful variables |
809 | # unpack some useful variables |
| 737 | my $set = $self->{set}; |
810 | my $set = $self->{set}; |
| 738 | my $problem = $self->{problem}; |
811 | my $problem = $self->{problem}; |
| 739 | my $editMode = $self->{editMode}; |
812 | my $editMode = $self->{editMode}; |
| 740 | my $submitAnswers = $self->{submitAnswers}; |
813 | my $submitAnswers = $self->{submitAnswers}; |
| … | |
… | |
| 750 | |
823 | |
| 751 | # FIXME: move editor link to top, next to problem number. |
824 | # FIXME: move editor link to top, next to problem number. |
| 752 | # format as "[edit]" like we're doing with course info file, etc. |
825 | # format as "[edit]" like we're doing with course info file, etc. |
| 753 | # add edit link for set as well. |
826 | # add edit link for set as well. |
| 754 | my $editorLink = ""; |
827 | my $editorLink = ""; |
| 755 | # if we are here without a real problem set, carry that through |
828 | # if we are here without a real homework set, carry that through |
| 756 | my $forced_field = []; |
829 | my $forced_field = []; |
| 757 | $forced_field = ['sourceFilePath' => $r->param("sourceFilePath")] if |
830 | $forced_field = ['sourceFilePath' => $r->param("sourceFilePath")] if |
| 758 | ($set->set_id eq 'Undefined_Set'); |
831 | ($set->set_id eq 'Undefined_Set'); |
| 759 | if ($authz->hasPermissions($user, "modify_problem_sets")) { |
832 | if ($authz->hasPermissions($user, "modify_problem_sets")) { |
| 760 | my $editorPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::Instructor::PGProblemEditor", |
833 | my $editorPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::Instructor::PGProblemEditor", |
| 761 | courseID => $courseName, setID => $set->set_id, problemID => $problem->problem_id); |
834 | courseID => $courseName, setID => $set->set_id, problemID => $problem->problem_id); |
| 762 | my $editorURL = $self->systemLink($editorPage, params=>$forced_field); |
835 | my $editorURL = $self->systemLink($editorPage, params=>$forced_field); |
| 763 | $editorLink = CGI::a({href=>$editorURL}, "Edit this problem"); |
836 | $editorLink = CGI::p(CGI::a({href=>$editorURL,target =>'WW_Editor'}, "Edit this problem")); |
| 764 | } |
837 | } |
| 765 | |
838 | |
| 766 | ##### translation errors? ##### |
839 | ##### translation errors? ##### |
| 767 | |
840 | |
| 768 | if ($pg->{flags}->{error_flag}) { |
841 | if ($pg->{flags}->{error_flag}) { |
|
|
842 | if ($authz->hasPermissions($user, "view_problem_debugging_info")) { |
| 769 | print $self->errorOutput($pg->{errors}, $pg->{body_text}); |
843 | print $self->errorOutput($pg->{errors}, $pg->{body_text}); |
|
|
844 | } else { |
|
|
845 | print $self->errorOutput($pg->{errors}, "You do not have permission to view the details of this error."); |
|
|
846 | } |
| 770 | print $editorLink; |
847 | print $editorLink; |
| 771 | return ""; |
848 | return ""; |
| 772 | } |
849 | } |
| 773 | |
850 | |
| 774 | ##### answer processing ##### |
851 | ##### answer processing ##### |
| 775 | $WeBWorK::timer->continue("begin answer processing") if defined($WeBWorK::timer); |
852 | debug("begin answer processing"); |
| 776 | # if answers were submitted: |
853 | # if answers were submitted: |
| 777 | my $scoreRecordedMessage; |
854 | my $scoreRecordedMessage; |
| 778 | my $pureProblem; |
855 | my $pureProblem; |
| 779 | if ($submitAnswers) { |
856 | if ($submitAnswers) { |
| 780 | # get a "pure" (unmerged) UserProblem to modify |
857 | # get a "pure" (unmerged) UserProblem to modify |
| … | |
… | |
| 804 | $db->putUserProblem($pureProblem); |
881 | $db->putUserProblem($pureProblem); |
| 805 | |
882 | |
| 806 | # store state in DB if it makes sense |
883 | # store state in DB if it makes sense |
| 807 | if ($will{recordAnswers}) { |
884 | if ($will{recordAnswers}) { |
| 808 | $problem->status($pg->{state}->{recorded_score}); |
885 | $problem->status($pg->{state}->{recorded_score}); |
|
|
886 | $problem->sub_status($pg->{state}->{sub_recorded_score}); |
| 809 | $problem->attempted(1); |
887 | $problem->attempted(1); |
| 810 | $problem->num_correct($pg->{state}->{num_of_correct_ans}); |
888 | $problem->num_correct($pg->{state}->{num_of_correct_ans}); |
| 811 | $problem->num_incorrect($pg->{state}->{num_of_incorrect_ans}); |
889 | $problem->num_incorrect($pg->{state}->{num_of_incorrect_ans}); |
| 812 | $pureProblem->status($pg->{state}->{recorded_score}); |
890 | $pureProblem->status($pg->{state}->{recorded_score}); |
|
|
891 | $pureProblem->sub_status($pg->{state}->{sub_recorded_score}); |
| 813 | $pureProblem->attempted(1); |
892 | $pureProblem->attempted(1); |
| 814 | $pureProblem->num_correct($pg->{state}->{num_of_correct_ans}); |
893 | $pureProblem->num_correct($pg->{state}->{num_of_correct_ans}); |
| 815 | $pureProblem->num_incorrect($pg->{state}->{num_of_incorrect_ans}); |
894 | $pureProblem->num_incorrect($pg->{state}->{num_of_incorrect_ans}); |
| 816 | if ($db->putUserProblem($pureProblem)) { |
895 | if ($db->putUserProblem($pureProblem)) { |
| 817 | $scoreRecordedMessage = "Your score was recorded."; |
896 | $scoreRecordedMessage = "Your score was recorded."; |
| … | |
… | |
| 833 | $pureProblem->num_correct."\t". |
912 | $pureProblem->num_correct."\t". |
| 834 | $pureProblem->num_incorrect |
913 | $pureProblem->num_incorrect |
| 835 | ); |
914 | ); |
| 836 | } else { |
915 | } else { |
| 837 | if (before($set->open_date) or after($set->due_date)) { |
916 | if (before($set->open_date) or after($set->due_date)) { |
| 838 | $scoreRecordedMessage = "Your score was not recorded because this problem set is closed."; |
917 | $scoreRecordedMessage = "Your score was not recorded because this homework set is closed."; |
| 839 | } else { |
918 | } else { |
| 840 | $scoreRecordedMessage = "Your score was not recorded."; |
919 | $scoreRecordedMessage = "Your score was not recorded."; |
| 841 | } |
920 | } |
| 842 | } |
921 | } |
| 843 | } else { |
922 | } else { |
| … | |
… | |
| 853 | my $answerString = ""; my $scores = ""; |
932 | my $answerString = ""; my $scores = ""; |
| 854 | my %answerHash = %{ $pg->{answers} }; |
933 | my %answerHash = %{ $pg->{answers} }; |
| 855 | # FIXME this is the line 552 error. make sure original student ans is defined. |
934 | # FIXME this is the line 552 error. make sure original student ans is defined. |
| 856 | # The fact that it is not defined is probably due to an error in some answer evaluator. |
935 | # The fact that it is not defined is probably due to an error in some answer evaluator. |
| 857 | # But I think it is useful to suppress this error message in the log. |
936 | # But I think it is useful to suppress this error message in the log. |
| 858 | foreach (sort keys %answerHash) { |
937 | foreach (sortByName(undef, keys %answerHash)) { |
| 859 | my $orig_ans = $answerHash{$_}->{original_student_ans}; |
938 | my $orig_ans = $answerHash{$_}->{original_student_ans}; |
| 860 | my $student_ans = defined $orig_ans ? $orig_ans : ''; |
939 | my $student_ans = defined $orig_ans ? $orig_ans : ''; |
| 861 | $answerString .= $student_ans."\t"; |
940 | $answerString .= $student_ans."\t"; |
| 862 | $scores .= $answerHash{$_}->{score} >= 1 ? "1" : "0"; |
941 | $scores .= $answerHash{$_}->{score} >= 1 ? "1" : "0"; |
| 863 | } |
942 | } |
| … | |
… | |
| 874 | ); |
953 | ); |
| 875 | |
954 | |
| 876 | } |
955 | } |
| 877 | } |
956 | } |
| 878 | |
957 | |
| 879 | $WeBWorK::timer->continue("end answer processing") if defined($WeBWorK::timer); |
958 | debug("end answer processing"); |
| 880 | |
959 | |
| 881 | ##### output ##### |
960 | ##### output ##### |
| 882 | # custom message for editor |
961 | # custom message for editor |
| 883 | if ($authz->hasPermissions($user, "modify_problem_sets") and defined $editMode) { |
962 | if ($authz->hasPermissions($user, "modify_problem_sets") and defined $editMode) { |
| 884 | if ($editMode eq "temporaryFile") { |
963 | if ($editMode eq "temporaryFile") { |
| … | |
… | |
| 919 | } |
998 | } |
| 920 | |
999 | |
| 921 | print CGI::end_div(); |
1000 | print CGI::end_div(); |
| 922 | |
1001 | |
| 923 | # main form |
1002 | # main form |
| 924 | print CGI::startform("POST", $r->uri); |
1003 | print "\n"; |
|
|
1004 | print CGI::start_form(-method=>"POST", -action=> $r->uri,-name=>"problemMainForm", onsubmit=>"submitAction()"); |
| 925 | print $self->hidden_authen_fields; |
1005 | print $self->hidden_authen_fields; |
| 926 | |
1006 | print "\n"; |
| 927 | print CGI::start_div({class=>"problem"}); |
1007 | print CGI::start_div({class=>"problem"}); |
| 928 | print CGI::p($pg->{body_text}); |
1008 | print CGI::p($pg->{body_text}); |
| 929 | print CGI::p(CGI::b("Note: "), CGI::i($pg->{result}->{msg})) if $pg->{result}->{msg}; |
1009 | print CGI::p(CGI::b("Note: "). CGI::i($pg->{result}->{msg})) if $pg->{result}->{msg}; |
|
|
1010 | print $editorLink; # this is empty unless it is appropriate to have an editor link. |
| 930 | print CGI::end_div(); |
1011 | print CGI::end_div(); |
| 931 | |
1012 | |
| 932 | print CGI::start_p(); |
1013 | print CGI::start_p(); |
| 933 | |
1014 | |
| 934 | if ($can{showCorrectAnswers}) { |
1015 | if ($can{showCorrectAnswers}) { |
| 935 | print CGI::checkbox( |
1016 | print CGI::checkbox( |
| 936 | -name => "showCorrectAnswers", |
1017 | -name => "showCorrectAnswers", |
| 937 | -checked => $will{showCorrectAnswers}, |
1018 | -checked => $will{showCorrectAnswers}, |
| 938 | -label => "Show correct answers", |
1019 | -label => "Show correct answers", |
|
|
1020 | -value => 1, |
| 939 | ); |
1021 | ); |
| 940 | } |
1022 | } |
| 941 | if ($can{showHints}) { |
1023 | if ($can{showHints}) { |
| 942 | print CGI::div({style=>"color:red"}, |
1024 | print CGI::div({style=>"color:red"}, |
| 943 | CGI::checkbox( |
1025 | CGI::checkbox( |
| 944 | -name => "showHints", |
1026 | -name => "showHints", |
| 945 | -checked => $will{showHints}, |
1027 | -checked => $will{showHints}, |
| 946 | -label => "Show Hints", |
1028 | -label => "Show Hints", |
|
|
1029 | -value =>1, |
| 947 | ) |
1030 | ) |
| 948 | ); |
1031 | ); |
| 949 | } |
1032 | } |
| 950 | if ($can{showSolutions}) { |
1033 | if ($can{showSolutions}) { |
| 951 | print CGI::checkbox( |
1034 | print CGI::checkbox( |
| 952 | -name => "showSolutions", |
1035 | -name => "showSolutions", |
| 953 | -checked => $will{showSolutions}, |
1036 | -checked => $will{showSolutions}, |
| 954 | -label => "Show Solutions", |
1037 | -label => "Show Solutions", |
|
|
1038 | -value => 1, |
| 955 | ); |
1039 | ); |
| 956 | } |
1040 | } |
| 957 | |
1041 | |
| 958 | if ($can{showCorrectAnswers} or $can{showHints} or $can{showSolutions}) { |
1042 | if ($can{showCorrectAnswers} or $can{showHints} or $can{showSolutions}) { |
| 959 | print CGI::br(); |
1043 | print CGI::br(); |
| … | |
… | |
| 967 | if ($user ne $effectiveUser) { |
1051 | if ($user ne $effectiveUser) { |
| 968 | # if acting as a student, make it clear that answer submissions will |
1052 | # if acting as a student, make it clear that answer submissions will |
| 969 | # apply to the student's records, not the professor's. |
1053 | # apply to the student's records, not the professor's. |
| 970 | print CGI::submit(-name=>"submitAnswers", -label=>"Submit Answers for $effectiveUser"); |
1054 | print CGI::submit(-name=>"submitAnswers", -label=>"Submit Answers for $effectiveUser"); |
| 971 | } else { |
1055 | } else { |
|
|
1056 | #print CGI::submit(-name=>"submitAnswers", -label=>"Submit Answers", -onclick=>"alert('submit button clicked')"); |
| 972 | print CGI::submit(-name=>"submitAnswers", -label=>"Submit Answers"); |
1057 | print CGI::submit(-name=>"submitAnswers", -label=>"Submit Answers", -onclick=>""); |
|
|
1058 | # FIXME for unknown reasons the -onclick label seems to have to be there in order to allow the forms onsubmit to trigger |
|
|
1059 | # WFT??? |
| 973 | } |
1060 | } |
| 974 | } |
1061 | } |
| 975 | |
1062 | |
| 976 | print CGI::end_p(); |
1063 | print CGI::end_p(); |
| 977 | |
1064 | |
| … | |
… | |
| 994 | |
1081 | |
| 995 | my $setClosed = 0; |
1082 | my $setClosed = 0; |
| 996 | my $setClosedMessage; |
1083 | my $setClosedMessage; |
| 997 | if (before($set->open_date) or after($set->due_date)) { |
1084 | if (before($set->open_date) or after($set->due_date)) { |
| 998 | $setClosed = 1; |
1085 | $setClosed = 1; |
|
|
1086 | if (before($set->open_date)) { |
|
|
1087 | $setClosedMessage = "This homework set is not yet open."; |
|
|
1088 | } elsif (after($set->due_date)) { |
| 999 | $setClosedMessage = "This problem set is closed."; |
1089 | $setClosedMessage = "This homework set is closed."; |
|
|
1090 | } |
|
|
1091 | } |
|
|
1092 | #if (before($set->open_date) or after($set->due_date)) { |
|
|
1093 | # $setClosed = 1; |
|
|
1094 | # $setClosedMessage = "This homework set is closed."; |
| 1000 | if ($authz->hasPermissions($user, "view_answers")) { |
1095 | # if ($authz->hasPermissions($user, "view_answers")) { |
| 1001 | $setClosedMessage .= " However, since you are a privileged user, additional attempts will be recorded."; |
1096 | # $setClosedMessage .= " However, since you are a privileged user, additional attempts will be recorded."; |
| 1002 | } else { |
1097 | # } else { |
| 1003 | $setClosedMessage .= " Additional attempts will not be recorded."; |
1098 | # $setClosedMessage .= " Additional attempts will not be recorded."; |
| 1004 | } |
1099 | # } |
| 1005 | } |
1100 | #} |
| 1006 | |
1101 | unless (defined( $pg->{state}->{state_summary_msg}) and $pg->{state}->{state_summary_msg}=~/\S/) { |
| 1007 | my $notCountedMessage = ($problem->value) ? "" : "(This problem will not count towards your grade.)"; |
1102 | my $notCountedMessage = ($problem->value) ? "" : "(This problem will not count towards your grade.)"; |
| 1008 | print CGI::p( |
1103 | print CGI::p(join("", |
| 1009 | $submitAnswers ? $scoreRecordedMessage . CGI::br() : "", |
1104 | $submitAnswers ? $scoreRecordedMessage . CGI::br() : "", |
| 1010 | "You have attempted this problem $attempts $attemptsNoun.", CGI::br(), |
1105 | "You have attempted this problem $attempts $attemptsNoun.", CGI::br(), |
|
|
1106 | $submitAnswers ?"You received a score of ".sprintf("%.0f%%", $pg->{result}->{score} * 100)." for this attempt.".CGI::br():'', |
| 1011 | $problem->attempted |
1107 | $problem->attempted |
| 1012 | ? "Your recorded score is $lastScore. $notCountedMessage" . CGI::br() |
1108 | ? "Your overall recorded score is $lastScore. $notCountedMessage" . CGI::br() |
| 1013 | : "", |
1109 | : "", |
| 1014 | $setClosed ? $setClosedMessage : "You have $attemptsLeft $attemptsLeftNoun remaining." |
1110 | $setClosed ? $setClosedMessage : "You have $attemptsLeft $attemptsLeftNoun remaining." |
| 1015 | ); |
1111 | )); |
|
|
1112 | }else { |
|
|
1113 | print CGI::p($pg->{state}->{state_summary_msg}); |
|
|
1114 | } |
| 1016 | print CGI::end_div(); |
1115 | print CGI::end_div(); |
| 1017 | |
1116 | |
| 1018 | # save state for viewOptions |
1117 | # save state for viewOptions |
| 1019 | print CGI::hidden( |
1118 | print CGI::hidden( |
| 1020 | -name => "showOldAnswers", |
1119 | -name => "showOldAnswers", |
| … | |
… | |
| 1028 | print( CGI::hidden( |
1127 | print( CGI::hidden( |
| 1029 | -name => 'editMode', |
1128 | -name => 'editMode', |
| 1030 | -value => $self->{editMode}, |
1129 | -value => $self->{editMode}, |
| 1031 | ) |
1130 | ) |
| 1032 | ) if defined($self->{editMode}) and $self->{editMode} eq 'temporaryFile'; |
1131 | ) if defined($self->{editMode}) and $self->{editMode} eq 'temporaryFile'; |
|
|
1132 | |
|
|
1133 | # this is a security risk -- students can use this to find the source code for the problem |
| 1033 | print( CGI::hidden( |
1134 | # print( CGI::hidden( |
| 1034 | -name => 'sourceFilePath', |
1135 | # -name => 'sourceFilePath', |
| 1035 | -value => $self->{problem}->{source_file} |
1136 | # -value => $self->{problem}->{source_file} |
| 1036 | )) if defined($self->{problem}->{source_file}); |
1137 | # )) if defined($self->{problem}->{source_file}); |
| 1037 | |
1138 | |
| 1038 | print( CGI::hidden( |
1139 | # print( CGI::hidden( |
| 1039 | -name => 'problemSeed', |
1140 | # -name => 'problemSeed', |
| 1040 | -value => $r->param("problemSeed") |
1141 | # -value => $r->param("problemSeed") |
| 1041 | )) if defined($r->param("problemSeed")); |
1142 | # )) if defined($r->param("problemSeed")); |
| 1042 | |
1143 | |
| 1043 | # end of main form |
1144 | # end of main form |
| 1044 | print CGI::endform(); |
1145 | print CGI::endform(); |
| 1045 | |
1146 | |
| 1046 | print CGI::start_div({class=>"problemFooter"}); |
1147 | print CGI::start_div({class=>"problemFooter"}); |
| … | |
… | |
| 1058 | my $showPastAnswersURL = $self->systemLink($pastAnswersPage, authen => 0); # no authen info for form action |
1159 | my $showPastAnswersURL = $self->systemLink($pastAnswersPage, authen => 0); # no authen info for form action |
| 1059 | |
1160 | |
| 1060 | # print answer inspection button |
1161 | # print answer inspection button |
| 1061 | if ($authz->hasPermissions($user, "view_answers")) { |
1162 | if ($authz->hasPermissions($user, "view_answers")) { |
| 1062 | print "\n", |
1163 | print "\n", |
| 1063 | CGI::start_form(-method=>"POST",-action=>$showPastAnswersURL,-target=>"information"),"\n", |
1164 | CGI::start_form(-method=>"POST",-action=>$showPastAnswersURL,-target=>"WW_Info"),"\n", |
| 1064 | $self->hidden_authen_fields,"\n", |
1165 | $self->hidden_authen_fields,"\n", |
| 1065 | CGI::hidden(-name => 'courseID', -value=>$courseName), "\n", |
1166 | CGI::hidden(-name => 'courseID', -value=>$courseName), "\n", |
| 1066 | CGI::hidden(-name => 'problemID', -value=>$problem->problem_id), "\n", |
1167 | CGI::hidden(-name => 'problemID', -value=>$problem->problem_id), "\n", |
| 1067 | CGI::hidden(-name => 'setID', -value=>$problem->set_id), "\n", |
1168 | CGI::hidden(-name => 'setID', -value=>$problem->set_id), "\n", |
| 1068 | CGI::hidden(-name => 'studentUser', -value=>$problem->user_id), "\n", |
1169 | CGI::hidden(-name => 'studentUser', -value=>$problem->user_id), "\n", |
| … | |
… | |
| 1070 | CGI::submit(-name => 'action', -value=>'Show Past Answers') |
1171 | CGI::submit(-name => 'action', -value=>'Show Past Answers') |
| 1071 | ), "\n", |
1172 | ), "\n", |
| 1072 | CGI::endform(); |
1173 | CGI::endform(); |
| 1073 | } |
1174 | } |
| 1074 | |
1175 | |
| 1075 | # feedback form url |
|
|
| 1076 | my $feedbackPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::Feedback", |
|
|
| 1077 | courseID => $courseName); |
|
|
| 1078 | my $feedbackURL = $self->systemLink($feedbackPage, authen => 0); # no authen info for form action |
|
|
| 1079 | |
1176 | |
| 1080 | #print feedback form |
1177 | print $self->feedbackMacro( |
| 1081 | print |
1178 | module => __PACKAGE__, |
| 1082 | CGI::start_form(-method=>"POST", -action=>$feedbackURL),"\n", |
1179 | set => $self->{set}->set_id, |
| 1083 | $self->hidden_authen_fields,"\n", |
1180 | problem => $problem->problem_id, |
| 1084 | CGI::hidden("module", __PACKAGE__),"\n", |
1181 | displayMode => $self->{displayMode}, |
| 1085 | CGI::hidden("set", $set->set_id),"\n", |
1182 | showOldAnswers => $will{showOldAnswers}, |
| 1086 | CGI::hidden("problem", $problem->problem_id),"\n", |
|
|
| 1087 | CGI::hidden("displayMode", $self->{displayMode}),"\n", |
|
|
| 1088 | CGI::hidden("showOldAnswers", $will{showOldAnswers}),"\n", |
|
|
| 1089 | CGI::hidden("showCorrectAnswers", $will{showCorrectAnswers}),"\n", |
1183 | showCorrectAnswers => $will{showCorrectAnswers}, |
| 1090 | CGI::hidden("showHints", $will{showHints}),"\n", |
1184 | showHints => $will{showHints}, |
| 1091 | CGI::hidden("showSolutions", $will{showSolutions}),"\n", |
1185 | showSolutions => $will{showSolutions}, |
| 1092 | CGI::p({-align=>"left"}, |
1186 | pg_object => $pg, |
| 1093 | CGI::submit(-name=>"feedbackForm", -label=>"Email instructor") |
1187 | ); |
| 1094 | ), |
|
|
| 1095 | CGI::endform(),"\n"; |
|
|
| 1096 | |
|
|
| 1097 | # FIXME print editor link |
|
|
| 1098 | print $editorLink; #empty unless it is appropriate to have an editor link. |
|
|
| 1099 | |
1188 | |
| 1100 | print CGI::end_div(); |
1189 | print CGI::end_div(); |
| 1101 | |
1190 | |
| 1102 | # debugging stuff |
1191 | # debugging stuff |
| 1103 | if (0) { |
1192 | if (0) { |