| … | |
… | |
| 13 | |
13 | |
| 14 | use strict; |
14 | use strict; |
| 15 | use warnings; |
15 | use warnings; |
| 16 | use base qw(WeBWorK::ContentGenerator); |
16 | use base qw(WeBWorK::ContentGenerator); |
| 17 | use CGI qw(); |
17 | use CGI qw(); |
|
|
18 | use File::Temp qw(tempdir); |
| 18 | use WeBWorK::Form; |
19 | use WeBWorK::Form; |
| 19 | use WeBWorK::PG; |
20 | use WeBWorK::PG; |
|
|
21 | use WeBWorK::PG::IO; |
| 20 | use WeBWorK::Utils qw(writeLog encodeAnswers decodeAnswers ref2string); |
22 | use WeBWorK::Utils qw(writeLog encodeAnswers decodeAnswers ref2string); |
| 21 | |
23 | |
| 22 | ############################################################ |
24 | ############################################################ |
| 23 | # |
25 | # |
| 24 | # user |
26 | # user |
|
|
27 | # effectiveUser |
| 25 | # key |
28 | # key |
| 26 | # |
29 | # |
| 27 | # displayMode |
30 | # displayMode |
| 28 | # showOldAnswers |
31 | # showOldAnswers |
| 29 | # showCorrectAnswers |
32 | # showCorrectAnswers |
| … | |
… | |
| 40 | sub pre_header_initialize { |
43 | sub pre_header_initialize { |
| 41 | my ($self, $setName, $problemNumber) = @_; |
44 | my ($self, $setName, $problemNumber) = @_; |
| 42 | my $courseEnv = $self->{courseEnvironment}; |
45 | my $courseEnv = $self->{courseEnvironment}; |
| 43 | my $r = $self->{r}; |
46 | my $r = $self->{r}; |
| 44 | my $userName = $r->param('user'); |
47 | my $userName = $r->param('user'); |
|
|
48 | my $effectiveUserName = $r->param('effectiveUser'); |
| 45 | |
49 | |
| 46 | ##### database setup ##### |
50 | ##### database setup ##### |
| 47 | |
51 | |
| 48 | my $cldb = WeBWorK::DB::Classlist->new($courseEnv); |
52 | my $cldb = WeBWorK::DB::Classlist->new($courseEnv); |
| 49 | my $wwdb = WeBWorK::DB::WW->new($courseEnv); |
53 | my $wwdb = WeBWorK::DB::WW->new($courseEnv); |
| 50 | my $authdb = WeBWorK::DB::Auth->new($courseEnv); |
54 | my $authdb = WeBWorK::DB::Auth->new($courseEnv); |
| 51 | |
55 | |
| 52 | my $user = $cldb->getUser($userName); |
56 | my $user = $cldb->getUser($userName); |
|
|
57 | my $effectiveUser = $cldb->getUser($effectiveUserName); |
| 53 | my $set = $wwdb->getSet($userName, $setName); |
58 | my $set = $wwdb->getSet($effectiveUserName, $setName); |
| 54 | my $problem = $wwdb->getProblem($userName, $setName, $problemNumber); |
59 | my $problem = $wwdb->getProblem($effectiveUserName, $setName, $problemNumber); |
| 55 | my $psvn = $wwdb->getPSVN($userName, $setName); |
60 | my $psvn = $wwdb->getPSVN($effectiveUserName, $setName); |
| 56 | my $permissionLevel = $authdb->getPermissions($userName); |
61 | my $permissionLevel = $authdb->getPermissions($userName); |
| 57 | |
62 | |
| 58 | ##### form processing ##### |
63 | ##### form processing ##### |
| 59 | |
64 | |
| 60 | # set options from form fields (see comment at top of file for names) |
65 | # set options from form fields (see comment at top of file for names) |
| 61 | my $displayMode = $r->param("displayMode") || $courseEnv->{pg}->{options}->{displayMode}; |
66 | my $displayMode = $r->param("displayMode") || $courseEnv->{pg}->{options}->{displayMode}; |
| 62 | my $redisplay = $r->param("redisplay"); |
67 | my $redisplay = $r->param("redisplay"); |
| 63 | my $submitAnswers = $r->param("submitAnswers"); |
68 | my $submitAnswers = $r->param("submitAnswers"); |
|
|
69 | my $checkAnswers = $r->param("checkAnswers"); |
|
|
70 | my $previewAnswers = $r->param("previewAnswers"); |
| 64 | |
71 | |
| 65 | # coerce form fields into CGI::Vars format |
72 | # coerce form fields into CGI::Vars format |
| 66 | my $formFields = { WeBWorK::Form->new_from_paramable($r)->Vars }; |
73 | my $formFields = { WeBWorK::Form->new_from_paramable($r)->Vars }; |
| 67 | |
74 | |
| 68 | ##### permissions ##### |
75 | ##### permissions ##### |
| … | |
… | |
| 71 | my %want = ( |
78 | my %want = ( |
| 72 | showOldAnswers => $r->param("showOldAnswers") || $courseEnv->{pg}->{options}->{showOldAnswers}, |
79 | showOldAnswers => $r->param("showOldAnswers") || $courseEnv->{pg}->{options}->{showOldAnswers}, |
| 73 | showCorrectAnswers => $r->param("showCorrectAnswers") || $courseEnv->{pg}->{options}->{showCorrectAnswers}, |
80 | showCorrectAnswers => $r->param("showCorrectAnswers") || $courseEnv->{pg}->{options}->{showCorrectAnswers}, |
| 74 | showHints => $r->param("showHints") || $courseEnv->{pg}->{options}->{showHints}, |
81 | showHints => $r->param("showHints") || $courseEnv->{pg}->{options}->{showHints}, |
| 75 | showSolutions => $r->param("showSolutions") || $courseEnv->{pg}->{options}->{showSolutions}, |
82 | showSolutions => $r->param("showSolutions") || $courseEnv->{pg}->{options}->{showSolutions}, |
| 76 | recordAnswers => $r->param("recordAnswers") || 1, |
83 | #recordAnswers => $r->param("recordAnswers") || 1, |
|
|
84 | recordAnswers => $submitAnswers, |
| 77 | ); |
85 | ); |
| 78 | |
86 | |
| 79 | # are certain options enforced? |
87 | # are certain options enforced? |
| 80 | my %must = ( |
88 | my %must = ( |
| 81 | showOldAnswers => 0, |
89 | showOldAnswers => 0, |
| … | |
… | |
| 96 | # num_correct+num_incorrect+1 -- as this happens before updating $problem |
104 | # num_correct+num_incorrect+1 -- as this happens before updating $problem |
| 97 | ); |
105 | ); |
| 98 | |
106 | |
| 99 | # final values for options |
107 | # final values for options |
| 100 | my %will; |
108 | my %will; |
| 101 | foreach(keys %must) { |
109 | foreach (keys %must) { |
| 102 | $will{$_} = $can{$_} && ($want{$_} || $must{$_}); |
110 | $will{$_} = $can{$_} && ($want{$_} || $must{$_}); |
| 103 | } |
111 | } |
| 104 | |
112 | |
| 105 | ##### sticky answers ##### |
113 | ##### sticky answers ##### |
| 106 | |
114 | |
| … | |
… | |
| 112 | |
120 | |
| 113 | ##### translation ##### |
121 | ##### translation ##### |
| 114 | |
122 | |
| 115 | my $pg = WeBWorK::PG->new( |
123 | my $pg = WeBWorK::PG->new( |
| 116 | $courseEnv, |
124 | $courseEnv, |
| 117 | $user, |
125 | $effectiveUser, |
| 118 | $r->param('key'), |
126 | $r->param('key'), |
| 119 | $set, |
127 | $set, |
| 120 | $problem, |
128 | $problem, |
| 121 | $psvn, |
129 | $psvn, |
| 122 | $formFields, |
130 | $formFields, |
| 123 | { # translation options |
131 | { # translation options |
| 124 | displayMode => $displayMode, |
132 | displayMode => $displayMode, |
| 125 | showHints => $will{showHints}, |
133 | showHints => $will{showHints}, |
| 126 | showSolutions => $will{showSolutions}, |
134 | showSolutions => $will{showSolutions}, |
| 127 | refreshMath2img => $will{showHints} || $will{showSolutions}, |
135 | refreshMath2img => $will{showHints} || $will{showSolutions}, |
| 128 | # try leaving processAnswers on all the time? |
136 | processAnswers => 1, |
| 129 | processAnswers => 1, #$submitAnswers ? 1 : 0, |
|
|
| 130 | }, |
137 | }, |
| 131 | ); |
138 | ); |
|
|
139 | |
|
|
140 | ##### fix hint/solution options ##### |
|
|
141 | |
|
|
142 | $can{showHints} &&= $pg->{flags}->{hintExists}; |
|
|
143 | $can{showSolutions} &&= $pg->{flags}->{solutionExists}; |
| 132 | |
144 | |
| 133 | ##### store fields ##### |
145 | ##### store fields ##### |
| 134 | |
146 | |
| 135 | $self->{cldb} = $cldb; |
147 | $self->{cldb} = $cldb; |
| 136 | $self->{wwdb} = $wwdb; |
148 | $self->{wwdb} = $wwdb; |
| 137 | $self->{authdb} = $authdb; |
149 | $self->{authdb} = $authdb; |
| 138 | |
150 | |
|
|
151 | $self->{userName} = $userName; |
| 139 | $self->{user} = $user; |
152 | $self->{user} = $user; |
|
|
153 | $self->{effectiveUser} = $effectiveUser; |
| 140 | $self->{set} = $set; |
154 | $self->{set} = $set; |
| 141 | $self->{problem} = $problem; |
155 | $self->{problem} = $problem; |
| 142 | $self->{permissionLevel} = $permissionLevel; |
156 | $self->{permissionLevel} = $permissionLevel; |
| 143 | |
157 | |
| 144 | $self->{displayMode} = $displayMode; |
158 | $self->{displayMode} = $displayMode; |
| 145 | $self->{redisplay} = $redisplay; |
159 | $self->{redisplay} = $redisplay; |
| 146 | $self->{submitAnswers} = $submitAnswers; |
160 | $self->{submitAnswers} = $submitAnswers; |
|
|
161 | $self->{checkAnswers} = $checkAnswers; |
|
|
162 | $self->{previewAnswers} = $previewAnswers; |
| 147 | $self->{formFields} = $formFields; |
163 | $self->{formFields} = $formFields; |
| 148 | |
164 | |
| 149 | $self->{want} = \%want; |
165 | $self->{want} = \%want; |
| 150 | $self->{must} = \%must; |
166 | $self->{must} = \%must; |
| 151 | $self->{can} = \%can; |
167 | $self->{can} = \%can; |
| 152 | $self->{will} = \%will; |
168 | $self->{will} = \%will; |
| … | |
… | |
| 197 | my $courseName = $ce->{courseName}; |
213 | my $courseName = $ce->{courseName}; |
| 198 | |
214 | |
| 199 | print CGI::strong("Problems"), CGI::br(); |
215 | print CGI::strong("Problems"), CGI::br(); |
| 200 | |
216 | |
| 201 | my $wwdb = $self->{wwdb}; |
217 | my $wwdb = $self->{wwdb}; |
| 202 | my $user = $self->{r}->param("user"); |
218 | my $effectiveUser = $self->{r}->param("effectiveUser"); |
| 203 | my @problems; |
219 | my @problems; |
| 204 | push @problems, $wwdb->getProblem($user, $setName, $_) |
220 | push @problems, $wwdb->getProblem($effectiveUser, $setName, $_) |
| 205 | foreach ($wwdb->getProblems($user, $setName)); |
221 | foreach ($wwdb->getProblems($effectiveUser, $setName)); |
| 206 | foreach my $problem (sort { $a->id <=> $b->id } @problems) { |
222 | foreach my $problem (sort { $a->id <=> $b->id } @problems) { |
| 207 | print CGI::a({-href=>"$root/$courseName/$setName/".$problem->id."/?" |
223 | print CGI::a({-href=>"$root/$courseName/$setName/".$problem->id."/?" |
| 208 | . $self->url_authen_args}, "Problem ".$problem->id), CGI::br(); |
224 | . $self->url_authen_args . "&displayMode=" . $self->{displayMode}}, |
|
|
225 | "Problem ".$problem->id), CGI::br(); |
| 209 | } |
226 | } |
| 210 | } |
227 | } |
| 211 | |
228 | |
| 212 | sub nav { |
229 | sub nav { |
| 213 | my $self = shift; |
230 | my $self = shift; |
| … | |
… | |
| 217 | |
234 | |
| 218 | my $ce = $self->{courseEnvironment}; |
235 | my $ce = $self->{courseEnvironment}; |
| 219 | my $root = $ce->{webworkURLs}->{root}; |
236 | my $root = $ce->{webworkURLs}->{root}; |
| 220 | my $courseName = $ce->{courseName}; |
237 | my $courseName = $ce->{courseName}; |
| 221 | |
238 | |
| 222 | my $wwdb = $self->{wwdb}; |
239 | my $wwdb = $self->{wwdb}; |
| 223 | my $user = $self->{r}->param("user"); |
240 | my $effectiveUser = $self->{r}->param("effectiveUser"); |
|
|
241 | my $tail = "&displayMode=".$self->{displayMode}; |
| 224 | |
242 | |
| 225 | my @links = ("Problem List" => "$root/$courseName/$setName"); |
243 | my @links = ("Problem List" => "$root/$courseName/$setName"); |
| 226 | |
244 | |
| 227 | my $prevProblem = $wwdb->getProblem($user, $setName, $problemNumber-1); |
245 | my $prevProblem = $wwdb->getProblem($effectiveUser, $setName, $problemNumber-1); |
| 228 | my $nextProblem = $wwdb->getProblem($user, $setName, $problemNumber+1); |
246 | my $nextProblem = $wwdb->getProblem($effectiveUser, $setName, $problemNumber+1); |
| 229 | unshift @links, "Previous Problem" => $prevProblem |
247 | unshift @links, "Previous Problem" => $prevProblem |
| 230 | ? "$root/$courseName/$setName/".$prevProblem->id |
248 | ? "$root/$courseName/$setName/".$prevProblem->id |
| 231 | : ""; |
249 | : ""; |
| 232 | push @links, "Next Problem" => $nextProblem |
250 | push @links, "Next Problem" => $nextProblem |
| 233 | ? "$root/$courseName/$setName/".$nextProblem->id |
251 | ? "$root/$courseName/$setName/".$nextProblem->id |
| 234 | : ""; |
252 | : ""; |
| 235 | |
253 | |
| 236 | return $self->navMacro($args, @links); |
254 | return $self->navMacro($args, $tail, @links); |
| 237 | } |
255 | } |
| 238 | |
256 | |
| 239 | sub title { |
257 | sub title { |
| 240 | my $self = shift; |
258 | my $self = shift; |
| 241 | my $setName = $self->{set}->id; |
259 | my $setName = $self->{set}->id; |
| … | |
… | |
| 252 | my $wwdb = $self->{wwdb}; |
270 | my $wwdb = $self->{wwdb}; |
| 253 | my $set = $self->{set}; |
271 | my $set = $self->{set}; |
| 254 | my $problem = $self->{problem}; |
272 | my $problem = $self->{problem}; |
| 255 | my $permissionLevel = $self->{permissionLevel}; |
273 | my $permissionLevel = $self->{permissionLevel}; |
| 256 | my $submitAnswers = $self->{submitAnswers}; |
274 | my $submitAnswers = $self->{submitAnswers}; |
|
|
275 | my $checkAnswers = $self->{checkAnswers}; |
|
|
276 | my $previewAnswers = $self->{previewAnswers}; |
|
|
277 | my %want = %{ $self->{want} }; |
|
|
278 | my %can = %{ $self->{can} }; |
|
|
279 | my %must = %{ $self->{must} }; |
| 257 | my %will = %{ $self->{will} }; |
280 | my %will = %{ $self->{will} }; |
| 258 | my $pg = $self->{pg}; |
281 | my $pg = $self->{pg}; |
| 259 | |
282 | |
| 260 | ##### translation errors? ##### |
283 | ##### translation errors? ##### |
| 261 | |
284 | |
| 262 | if ($pg->{flags}->{error_flag}) { |
285 | if ($pg->{flags}->{error_flag}) { |
| 263 | return translationError($pg->{errors}, $pg->{body_text}); |
286 | return $self->errorOutput($pg->{errors}, $pg->{body_text}); |
| 264 | } |
287 | } |
| 265 | |
288 | |
| 266 | ##### answer processing ##### |
289 | ##### answer processing ##### |
| 267 | |
290 | |
| 268 | # if answers were submitted: |
291 | # if answers were submitted: |
| … | |
… | |
| 305 | ##### output ##### |
328 | ##### output ##### |
| 306 | |
329 | |
| 307 | # attempt summary |
330 | # attempt summary |
| 308 | if ($submitAnswers or $will{showCorrectAnswers}) { |
331 | if ($submitAnswers or $will{showCorrectAnswers}) { |
| 309 | # print this if user submitted answers OR requested correct answers |
332 | # print this if user submitted answers OR requested correct answers |
| 310 | print attemptResults($pg, $submitAnswers, $will{showCorrectAnswers}, |
333 | print $self->attemptResults($pg, $submitAnswers, |
|
|
334 | $will{showCorrectAnswers}, |
| 311 | $pg->{flags}->{showPartialCorrectAnswers}); |
335 | $pg->{flags}->{showPartialCorrectAnswers}, 0); |
|
|
336 | } elsif ($checkAnswers) { |
|
|
337 | # print this if user previewed answers |
|
|
338 | print $self->attemptResults($pg, 1, 0, 1, 0); |
|
|
339 | # show attempt answers |
|
|
340 | # don't show correct answers |
|
|
341 | # show attempt results (correctness) |
|
|
342 | # don't show attempt previews |
|
|
343 | } elsif ($previewAnswers) { |
|
|
344 | # print this if user previewed answers |
|
|
345 | print $self->attemptResults($pg, 1, 0, 0, 1); |
|
|
346 | # show attempt answers |
|
|
347 | # don't show correct answers |
|
|
348 | # don't show attempt results (correctness) |
|
|
349 | # show attempt previews |
| 312 | } |
350 | } |
| 313 | |
351 | |
| 314 | # score summary |
352 | # score summary |
| 315 | my $attempts = $problem->num_correct + $problem->num_incorrect; |
353 | my $attempts = $problem->num_correct + $problem->num_incorrect; |
| 316 | my $attemptsNoun = $attempts != 1 ? "times" : "time"; |
354 | my $attemptsNoun = $attempts != 1 ? "times" : "time"; |
| … | |
… | |
| 340 | : "", |
378 | : "", |
| 341 | "You have $attemptsLeft $attemptsLeftNoun remaining.", CGI::br(), |
379 | "You have $attemptsLeft $attemptsLeftNoun remaining.", CGI::br(), |
| 342 | $setClosedMessage, |
380 | $setClosedMessage, |
| 343 | ); |
381 | ); |
| 344 | |
382 | |
| 345 | # BY THE WAY.......... |
|
|
| 346 | # we have to figure out some way to tell the student if their NEW answer, |
|
|
| 347 | # on THIS attempt, has been recorded. however, this is decided in part by |
|
|
| 348 | # the grader, so is there any way for us to know? we can rule out several |
|
|
| 349 | # cases where the answer is NOT being recorded, because of things decided |
|
|
| 350 | # in &canRecordAnswers... |
|
|
| 351 | |
|
|
| 352 | print CGI::hr(); |
383 | print CGI::hr(); |
| 353 | |
384 | |
| 354 | # main form |
385 | # main form |
| 355 | print |
386 | print |
| 356 | CGI::startform("POST", $r->uri), |
387 | CGI::startform("POST", $r->uri), |
| 357 | $self->hidden_authen_fields, |
388 | $self->hidden_authen_fields, |
| 358 | $self->viewOptions, |
|
|
| 359 | CGI::p(CGI::i($pg->{result}->{msg})), |
389 | CGI::p(CGI::i($pg->{result}->{msg})), |
| 360 | CGI::p($pg->{body_text}), |
390 | CGI::p($pg->{body_text}), |
| 361 | CGI::p(CGI::submit(-name=>"submitAnswers", -label=>"Submit Answers")), |
391 | CGI::p( |
|
|
392 | ($can{recordAnswers} |
|
|
393 | ? CGI::submit(-name=>"submitAnswers", |
|
|
394 | -label=>"Submit Answers") |
|
|
395 | : ""), |
|
|
396 | ($can{recordAnswers} |
|
|
397 | ? CGI::submit(-name=>"checkAnswers", |
|
|
398 | -label=>"Check Answers") |
|
|
399 | : ""), |
|
|
400 | CGI::submit(-name=>"previewAnswers", |
|
|
401 | -label=>"Preview Answers"), |
|
|
402 | ), |
|
|
403 | $self->viewOptions(), |
|
|
404 | CGI::endform(); |
|
|
405 | |
|
|
406 | # feedback form |
|
|
407 | my $ce = $self->{courseEnvironment}; |
|
|
408 | my $root = $ce->{webworkURLs}->{root}; |
|
|
409 | my $courseName = $ce->{courseName}; |
|
|
410 | my $feedbackURL = "$root/$courseName/feedback/"; |
|
|
411 | print |
|
|
412 | CGI::startform("POST", $feedbackURL), |
|
|
413 | $self->hidden_authen_fields, |
|
|
414 | CGI::hidden("module", __PACKAGE__), |
|
|
415 | CGI::hidden("set", $set->id), |
|
|
416 | CGI::hidden("problem", $problem->id), |
|
|
417 | CGI::hidden("displayMode", $self->{displayMode}), |
|
|
418 | CGI::hidden("showOldAnswers", $will{showOldAnswers}), |
|
|
419 | CGI::hidden("showCorrectAnswers", $will{showCorrectAnswers}), |
|
|
420 | CGI::hidden("showHints", $will{showHints}), |
|
|
421 | CGI::hidden("showSolutions", $will{showSolutions}), |
|
|
422 | CGI::p({-align=>"right"}, |
|
|
423 | CGI::submit(-name=>"feedbackForm", -label=>"Send Feedback") |
|
|
424 | ), |
| 362 | CGI::endform(); |
425 | CGI::endform(); |
| 363 | |
426 | |
| 364 | # warning output |
427 | # warning output |
| 365 | if ($pg->{warnings} ne "") { |
428 | if ($pg->{warnings} ne "") { |
| 366 | print CGI::hr(), warningOutput($pg->{warnings}); |
429 | print CGI::hr(), $self->warningOutput($pg->{warnings}); |
| 367 | } |
430 | } |
| 368 | |
431 | |
| 369 | # debugging stuff |
432 | # debugging stuff |
| 370 | #print |
433 | #print |
| 371 | # hr(), |
434 | # CGI::hr(), |
| 372 | # h2("debugging information"), |
435 | # CGI::h2("debugging information"), |
| 373 | # h3("form fields"), |
436 | # CGI::h3("form fields"), |
| 374 | # ref2string($formFields), |
437 | # ref2string($self->{formFields}), |
| 375 | # h3("user object"), |
438 | # CGI::h3("user object"), |
| 376 | # ref2string($user), |
439 | # ref2string($self->{user}), |
| 377 | # h3("set object"), |
440 | # CGI::h3("set object"), |
| 378 | # ref2string($set), |
441 | # ref2string($set), |
| 379 | # h3("problem object"), |
442 | # CGI::h3("problem object"), |
| 380 | # ref2string($problem), |
443 | # ref2string($problem), |
| 381 | # h3("PG object"), |
444 | # CGI::h3("PG object"), |
| 382 | # ref2string($pg, {'WeBWorK::PG::Translator' => 1}); |
445 | # ref2string($pg, {'WeBWorK::PG::Translator' => 1}); |
| 383 | |
446 | |
| 384 | return ""; |
447 | return ""; |
| 385 | } |
448 | } |
| 386 | |
449 | |
| 387 | ##### output utilities ##### |
450 | ##### output utilities ##### |
| 388 | |
451 | |
| 389 | # this is used by ProblemSet.pm too, so don't fuck it up |
|
|
| 390 | sub translationError($$) { |
|
|
| 391 | my ($error, $details) = @_; |
|
|
| 392 | return |
|
|
| 393 | CGI::h2("Software Error"), |
|
|
| 394 | CGI::p(<<EOF), |
|
|
| 395 | WeBWorK has encountered a software error while attempting to process this problem. |
|
|
| 396 | It is likely that there is an error in the problem itself. |
|
|
| 397 | If you are a student, contact your professor to have the error corrected. |
|
|
| 398 | If you are a professor, please consut the error output below for more informaiton. |
|
|
| 399 | EOF |
|
|
| 400 | CGI::h3("Error messages"), CGI::blockquote(CGI::pre($error)), |
|
|
| 401 | CGI::h3("Error context"), CGI::blockquote(CGI::pre($details)); |
|
|
| 402 | } |
|
|
| 403 | |
|
|
| 404 | # this is used by ProblemSet.pm too, so don't fuck it up |
|
|
| 405 | sub warningOutput($) { |
|
|
| 406 | my $warnings = shift; |
|
|
| 407 | |
|
|
| 408 | return |
|
|
| 409 | CGI::h2("Software Warnings"), |
|
|
| 410 | CGI::p(<<EOF), |
|
|
| 411 | WeBWorK has encountered warnings while attempting to process this problem. |
|
|
| 412 | It is likely that this indicates an error or ambiguity in the problem itself. |
|
|
| 413 | If you are a student, contact your professor to have the problem corrected. |
|
|
| 414 | If you are a professor, please consut the error output below for more informaiton. |
|
|
| 415 | EOF |
|
|
| 416 | CGI::h3("Warning messages"), |
|
|
| 417 | CGI::blockquote(CGI::pre($warnings)), |
|
|
| 418 | ; |
|
|
| 419 | } |
|
|
| 420 | |
|
|
| 421 | sub attemptResults($$$) { |
452 | sub attemptResults($$$$$) { |
|
|
453 | my $self = shift; |
| 422 | my $pg = shift; |
454 | my $pg = shift; |
| 423 | my $showAttemptAnswers = shift; |
455 | my $showAttemptAnswers = shift; |
| 424 | my $showCorrectAnswers = shift; |
456 | my $showCorrectAnswers = shift; |
| 425 | my $showAttemptResults = $showAttemptAnswers && shift; |
457 | my $showAttemptResults = $showAttemptAnswers && shift; |
|
|
458 | my $showAttemptPreview = shift || 0; |
| 426 | my $problemResult = $pg->{result}; # the overall result of the problem |
459 | my $problemResult = $pg->{result}; # the overall result of the problem |
| 427 | my @answerNames = @{ $pg->{flags}->{ANSWER_ENTRY_ORDER} }; |
460 | my @answerNames = @{ $pg->{flags}->{ANSWER_ENTRY_ORDER} }; |
| 428 | |
461 | |
|
|
462 | my $showMessages = $showAttemptAnswers && grep { $pg->{answers}->{$_}->{ans_message} } @answerNames; |
|
|
463 | |
| 429 | my $header = CGI::th("answer"); |
464 | my $header = CGI::th("part"); |
| 430 | $header .= $showAttemptAnswers ? CGI::th("attempt") : ""; |
465 | $header .= $showAttemptAnswers ? CGI::th("entered") : ""; |
|
|
466 | $header .= $showAttemptPreview ? CGI::th("preview") : ""; |
| 431 | $header .= $showCorrectAnswers ? CGI::th("correct") : ""; |
467 | $header .= $showCorrectAnswers ? CGI::th("correct") : ""; |
| 432 | $header .= $showAttemptResults ? CGI::th("result") : ""; |
468 | $header .= $showAttemptResults ? CGI::th("result") : ""; |
| 433 | $header .= $showAttemptAnswers ? CGI::th("messages") : ""; |
469 | $header .= $showMessages ? CGI::th("messages") : ""; |
| 434 | my @tableRows = ( $header ); |
470 | my @tableRows = ( $header ); |
| 435 | my $numCorrect; |
471 | my $numCorrect; |
| 436 | foreach my $name (@answerNames) { |
472 | foreach my $name (@answerNames) { |
| 437 | my $answerResult = $pg->{answers}->{$name}; |
473 | my $answerResult = $pg->{answers}->{$name}; |
| 438 | my $studentAnswer = $answerResult->{student_ans}; # original_student_ans |
474 | my $studentAnswer = $answerResult->{student_ans}; # original_student_ans |
|
|
475 | my $preview = ($showAttemptPreview |
|
|
476 | ? $self->previewAnswer($answerResult) |
|
|
477 | : ""); |
| 439 | my $correctAnswer = $answerResult->{correct_ans}; |
478 | my $correctAnswer = $answerResult->{correct_ans}; |
| 440 | my $answerScore = $answerResult->{score}; |
479 | my $answerScore = $answerResult->{score}; |
| 441 | my $answerMessage = $showAttemptAnswers ? $answerResult->{ans_message} : ""; |
480 | my $answerMessage = $showMessages ? $answerResult->{ans_message} : ""; |
| 442 | |
481 | |
| 443 | $numCorrect += $answerScore > 0; |
482 | $numCorrect += $answerScore > 0; |
| 444 | my $resultString = $answerScore ? "correct" : "incorrect"; |
483 | my $resultString = $answerScore ? "correct" : "incorrect"; |
| 445 | |
484 | |
| 446 | # get rid of the goofy prefix on the answer names (supposedly, the format |
485 | # get rid of the goofy prefix on the answer names (supposedly, the format |
| 447 | # of the answer names is changeable. this only fixes |
486 | # of the answer names is changeable. this only fixes it for "AnSwEr" |
| 448 | $name =~ s/^AnSwEr//; |
487 | $name =~ s/^AnSwEr//; |
| 449 | |
488 | |
| 450 | my $row = CGI::td($name); |
489 | my $row = CGI::td($name); |
| 451 | $row .= $showAttemptAnswers ? CGI::td($studentAnswer) : ""; |
490 | $row .= $showAttemptAnswers ? CGI::td($studentAnswer) : ""; |
|
|
491 | $row .= $showAttemptPreview ? CGI::td($preview) : ""; |
| 452 | $row .= $showCorrectAnswers ? CGI::td($correctAnswer) : ""; |
492 | $row .= $showCorrectAnswers ? CGI::td($correctAnswer) : ""; |
| 453 | $row .= $showAttemptResults ? CGI::td($resultString) : ""; |
493 | $row .= $showAttemptResults ? CGI::td($resultString) : ""; |
| 454 | $row .= $answerMessage ? CGI::td($answerMessage) : ""; |
494 | $row .= $answerMessage ? CGI::td($answerMessage) : ""; |
| 455 | push @tableRows, $row; |
495 | push @tableRows, $row; |
| 456 | } |
496 | } |
| … | |
… | |
| 512 | $optionLine, |
552 | $optionLine, |
| 513 | CGI::submit(-name=>"redisplay", -label=>"Redisplay Problem"), |
553 | CGI::submit(-name=>"redisplay", -label=>"Redisplay Problem"), |
| 514 | ); |
554 | ); |
| 515 | } |
555 | } |
| 516 | |
556 | |
|
|
557 | sub previewAnswer($$) { |
|
|
558 | my ($self, $answerResult) = @_; |
|
|
559 | my $ce = $self->{courseEnvironment}; |
|
|
560 | my $effectiveUser = $self->{effectiveUser}; |
|
|
561 | my $set = $self->{set}; |
|
|
562 | my $problem = $self->{problem}; |
|
|
563 | my $displayMode = $self->{displayMode}; |
|
|
564 | |
|
|
565 | # note: right now, we have to do things completely differently when we are |
|
|
566 | # rendering math from INSIDE the translator and from OUTSIDE the translator. |
|
|
567 | # so we'll just deal with each case explicitly here. there's some code |
|
|
568 | # duplication that can be dealt with later by abstracting out tth/dvipng/etc. |
|
|
569 | |
|
|
570 | my $tex = $answerResult->{preview_latex_string}; |
|
|
571 | |
|
|
572 | return "" unless $tex; |
|
|
573 | |
|
|
574 | if ($displayMode eq "plainText") { |
|
|
575 | return $tex; |
|
|
576 | } elsif ($displayMode eq "formattedText") { |
|
|
577 | my $tthCommand = $ce->{externalPrograms}->{tth} |
|
|
578 | . " -L -f5 -r 2> /dev/null <<END_OF_INPUT; echo > /dev/null\n" |
|
|
579 | . "\\(".$tex."\\)\n" |
|
|
580 | . "END_OF_INPUT\n"; |
|
|
581 | |
|
|
582 | # call tth |
|
|
583 | my $result = `$tthCommand`; |
|
|
584 | if ($?) { |
|
|
585 | return "<b>[tth failed: $? $@]</b>"; |
|
|
586 | } |
|
|
587 | return $result; |
|
|
588 | } elsif ($displayMode eq "images") { |
|
|
589 | # how are we going to name this? |
|
|
590 | my $targetPathCommon = "/png/" |
|
|
591 | . $effectiveUser->id . "." |
|
|
592 | . $set->id . "." |
|
|
593 | . $problem->id . "." |
|
|
594 | . $answerResult->{ans_name} . ".png"; |
|
|
595 | |
|
|
596 | # figure out where to put things |
|
|
597 | my $wd = tempdir("webwork-dvipng-XXXXXXXX", DIR => $ce->{courseDirs}->{html_temp}); |
|
|
598 | my $latex = $ce->{externalPrograms}->{latex}; |
|
|
599 | my $dvipng = $ce->{externalPrograms}->{dvipng}; |
|
|
600 | my $targetPath = $ce->{courseDirs}->{html_temp} . $targetPathCommon; |
|
|
601 | # should use surePathToTmpFile, but we have to |
|
|
602 | # isolate it from the problem enivronment first |
|
|
603 | my $targetURL = $ce->{courseURLs}->{html_temp} . $targetPathCommon; |
|
|
604 | |
|
|
605 | # call dvipng to generate a preview |
|
|
606 | dvipng($wd, $latex, $dvipng, $tex, $targetPath); |
|
|
607 | if (-e $targetPath) { |
|
|
608 | return "<img src=\"$targetURL\" alt=\"$tex\" />"; |
|
|
609 | } else { |
|
|
610 | return "<b>[math2img failed]</b>"; |
|
|
611 | } |
|
|
612 | } |
|
|
613 | } |
|
|
614 | |
| 517 | ##### permission queries ##### |
615 | ##### permission queries ##### |
| 518 | |
616 | |
| 519 | # this stuff should be abstracted out into the permissions system |
617 | # this stuff should be abstracted out into the permissions system |
| 520 | # however, the permission system only knows about things in the |
618 | # however, the permission system only knows about things in the |
| 521 | # course environment and the username. hmmm... |
619 | # course environment and the username. hmmm... |
| … | |
… | |
| 536 | |
634 | |
| 537 | sub canRecordAnswers($$$$$) { |
635 | sub canRecordAnswers($$$$$) { |
| 538 | my ($permissionLevel, $openDate, $dueDate, $maxAttempts, $attempts) = @_; |
636 | my ($permissionLevel, $openDate, $dueDate, $maxAttempts, $attempts) = @_; |
| 539 | my $permHigh = $permissionLevel > 0; |
637 | my $permHigh = $permissionLevel > 0; |
| 540 | my $timeOK = time >= $openDate && time <= $dueDate; |
638 | my $timeOK = time >= $openDate && time <= $dueDate; |
| 541 | my $attemptsOK = $attempts <= $maxAttempts; |
639 | my $attemptsOK = $maxAttempts == -1 || $attempts <= $maxAttempts; |
| 542 | return $permHigh || ($timeOK && $attemptsOK); |
640 | my $recordAnswers = $permHigh || ($timeOK && $attemptsOK); |
|
|
641 | return $recordAnswers; |
| 543 | } |
642 | } |
| 544 | |
643 | |
| 545 | sub mustRecordAnswers($) { |
644 | sub mustRecordAnswers($) { |
| 546 | my ($permissionLevel) = @_; |
645 | my ($permissionLevel) = @_; |
| 547 | return $permissionLevel == 0; |
646 | return $permissionLevel == 0; |