[system] / trunk / webwork-modperl / lib / WeBWorK / ContentGenerator / Problem.pm Repository:
ViewVC logotype

Diff of /trunk/webwork-modperl/lib/WeBWorK/ContentGenerator/Problem.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 719 Revision 809
40# 40#
41############################################################ 41############################################################
42 42
43sub pre_header_initialize { 43sub pre_header_initialize {
44 my ($self, $setName, $problemNumber) = @_; 44 my ($self, $setName, $problemNumber) = @_;
45 my $courseEnv = $self->{courseEnvironment}; 45 my $courseEnv = $self->{ce};
46 my $r = $self->{r}; 46 my $r = $self->{r};
47 my $userName = $r->param('user'); 47 my $userName = $r->param('user');
48 my $effectiveUserName = $r->param('effectiveUser'); 48 my $effectiveUserName = $r->param('effectiveUser');
49 49
50 ##### database setup ##### 50 ##### database setup #####
58 my $set = $wwdb->getSet($effectiveUserName, $setName); 58 my $set = $wwdb->getSet($effectiveUserName, $setName);
59 my $problem = $wwdb->getProblem($effectiveUserName, $setName, $problemNumber); 59 my $problem = $wwdb->getProblem($effectiveUserName, $setName, $problemNumber);
60 my $psvn = $wwdb->getPSVN($effectiveUserName, $setName); 60 my $psvn = $wwdb->getPSVN($effectiveUserName, $setName);
61 my $permissionLevel = $authdb->getPermissions($userName); 61 my $permissionLevel = $authdb->getPermissions($userName);
62 62
63 $self->{cldb} = $cldb;
64 $self->{wwdb} = $wwdb;
65 $self->{authdb} = $authdb;
66
67 $self->{userName} = $userName;
68 $self->{user} = $user;
69 $self->{effectiveUser} = $effectiveUser;
70 $self->{set} = $set;
71 $self->{problem} = $problem;
72 $self->{permissionLevel} = $permissionLevel;
73
63 ##### form processing ##### 74 ##### form processing #####
64 75
65 # set options from form fields (see comment at top of file for names) 76 # set options from form fields (see comment at top of file for names)
66 my $displayMode = $r->param("displayMode") || $courseEnv->{pg}->{options}->{displayMode}; 77 my $displayMode = $r->param("displayMode") || $courseEnv->{pg}->{options}->{displayMode};
67 my $redisplay = $r->param("redisplay"); 78 my $redisplay = $r->param("redisplay");
70 my $previewAnswers = $r->param("previewAnswers"); 81 my $previewAnswers = $r->param("previewAnswers");
71 82
72 # coerce form fields into CGI::Vars format 83 # coerce form fields into CGI::Vars format
73 my $formFields = { WeBWorK::Form->new_from_paramable($r)->Vars }; 84 my $formFields = { WeBWorK::Form->new_from_paramable($r)->Vars };
74 85
86 $self->{displayMode} = $displayMode;
87 $self->{redisplay} = $redisplay;
88 $self->{submitAnswers} = $submitAnswers;
89 $self->{checkAnswers} = $checkAnswers;
90 $self->{previewAnswers} = $previewAnswers;
91 $self->{formFields} = $formFields;
92
75 ##### permissions ##### 93 ##### permissions #####
94
95 # are we allowed to view this problem?
96 $self->{isOpen} = time >= $set->open_date || $permissionLevel > 0;
97 return unless $self->{isOpen};
76 98
77 # what does the user want to do? 99 # what does the user want to do?
78 my %want = ( 100 my %want = (
79 showOldAnswers => $r->param("showOldAnswers") || $courseEnv->{pg}->{options}->{showOldAnswers}, 101 showOldAnswers => $r->param("showOldAnswers") || $courseEnv->{pg}->{options}->{showOldAnswers},
80 showCorrectAnswers => $r->param("showCorrectAnswers") || $courseEnv->{pg}->{options}->{showCorrectAnswers}, 102 showCorrectAnswers => $r->param("showCorrectAnswers") || $courseEnv->{pg}->{options}->{showCorrectAnswers},
81 showHints => $r->param("showHints") || $courseEnv->{pg}->{options}->{showHints}, 103 showHints => $r->param("showHints") || $courseEnv->{pg}->{options}->{showHints},
82 showSolutions => $r->param("showSolutions") || $courseEnv->{pg}->{options}->{showSolutions}, 104 showSolutions => $r->param("showSolutions") || $courseEnv->{pg}->{options}->{showSolutions},
83 #recordAnswers => $r->param("recordAnswers") || 1,
84 recordAnswers => $submitAnswers, 105 recordAnswers => $submitAnswers,
106 checkAnswers => $checkAnswers,
85 ); 107 );
86 108
87 # are certain options enforced? 109 # are certain options enforced?
88 my %must = ( 110 my %must = (
89 showOldAnswers => 0, 111 showOldAnswers => 0,
90 showCorrectAnswers => 0, 112 showCorrectAnswers => 0,
91 showHints => 0, 113 showHints => 0,
92 showSolutions => 0, 114 showSolutions => 0,
93 recordAnswers => mustRecordAnswers($permissionLevel), 115 recordAnswers => mustRecordAnswers($permissionLevel),
116 checkAnswers => 0,
94 ); 117 );
95 118
96 # does the user have permission to use certain options? 119 # does the user have permission to use certain options?
97 my %can = ( 120 my %can = (
98 showOldAnswers => 1, 121 showOldAnswers => 1,
99 showCorrectAnswers => canShowCorrectAnswers($permissionLevel, $set->answer_date), 122 showCorrectAnswers => canShowCorrectAnswers($permissionLevel, $set->answer_date),
100 showHints => 1, 123 showHints => 1,
101 showSolutions => canShowSolutions($permissionLevel, $set->answer_date), 124 showSolutions => canShowSolutions($permissionLevel, $set->answer_date),
102 recordAnswers => canRecordAnswers($permissionLevel, $set->open_date, $set->due_date, 125 recordAnswers => canRecordAnswers($permissionLevel, $set->open_date, $set->due_date,
103 $problem->max_attempts, $problem->num_correct + $problem->num_incorrect + 1), 126 $problem->max_attempts, $problem->num_correct + $problem->num_incorrect + 1),
104 # num_correct+num_incorrect+1 -- as this happens before updating $problem 127 # attempts=num_correct+num_incorrect+1, as this happens before updating $problem
128 checkAnswers => canCheckAnswers($permissionLevel, $set->answer_date),
105 ); 129 );
106 130
107 # final values for options 131 # final values for options
108 my %will; 132 my %will;
109 foreach (keys %must) { 133 foreach (keys %must) {
142 $can{showHints} &&= $pg->{flags}->{hintExists}; 166 $can{showHints} &&= $pg->{flags}->{hintExists};
143 $can{showSolutions} &&= $pg->{flags}->{solutionExists}; 167 $can{showSolutions} &&= $pg->{flags}->{solutionExists};
144 168
145 ##### store fields ##### 169 ##### store fields #####
146 170
147 $self->{cldb} = $cldb;
148 $self->{wwdb} = $wwdb;
149 $self->{authdb} = $authdb;
150
151 $self->{userName} = $userName;
152 $self->{user} = $user;
153 $self->{effectiveUser} = $effectiveUser;
154 $self->{set} = $set;
155 $self->{problem} = $problem;
156 $self->{permissionLevel} = $permissionLevel;
157
158 $self->{displayMode} = $displayMode;
159 $self->{redisplay} = $redisplay;
160 $self->{submitAnswers} = $submitAnswers;
161 $self->{checkAnswers} = $checkAnswers;
162 $self->{previewAnswers} = $previewAnswers;
163 $self->{formFields} = $formFields;
164
165 $self->{want} = \%want; 171 $self->{want} = \%want;
166 $self->{must} = \%must; 172 $self->{must} = \%must;
167 $self->{can} = \%can; 173 $self->{can} = \%can;
168 $self->{will} = \%will; 174 $self->{will} = \%will;
169 175
170 $self->{pg} = $pg; 176 $self->{pg} = $pg;
171} 177}
172 178
173sub if_warnings($$) { 179sub if_warnings($$) {
174 my ($self, $arg) = @_; 180 my ($self, $arg) = @_;
181 return 0 unless $self->{isOpen};
175 return $self->{pg}->{warnings} ne ""; 182 return $self->{pg}->{warnings} ne "";
176} 183}
177 184
178sub if_errors($$) { 185sub if_errors($$) {
179 my ($self, $arg) = @_; 186 my ($self, $arg) = @_;
187 return 0 unless $self->{isOpen};
180 return $self->{pg}->{flags}->{error_flag}; 188 return $self->{pg}->{flags}->{error_flag};
181} 189}
182 190
183sub head { 191sub head {
184 my $self = shift; 192 my $self = shift;
185 193 return "" unless $self->{isOpen};
186 return $self->{pg}->{head_text} if $self->{pg}->{head_text}; 194 return $self->{pg}->{head_text} if $self->{pg}->{head_text};
187} 195}
188 196
189sub path { 197sub path {
190 my $self = shift; 198 my $self = shift;
191 my $args = $_[-1]; 199 my $args = $_[-1];
192 my $setName = $self->{set}->id; 200 my $setName = $self->{set}->id;
193 my $problemNumber = $self->{problem}->id; 201 my $problemNumber = $self->{problem}->id;
194 202
195 my $ce = $self->{courseEnvironment}; 203 my $ce = $self->{ce};
196 my $root = $ce->{webworkURLs}->{root}; 204 my $root = $ce->{webworkURLs}->{root};
197 my $courseName = $ce->{courseName}; 205 my $courseName = $ce->{courseName};
198 return $self->pathMacro($args, 206 return $self->pathMacro($args,
199 "Home" => "$root", 207 "Home" => "$root",
200 $courseName => "$root/$courseName", 208 $courseName => "$root/$courseName",
206sub siblings { 214sub siblings {
207 my $self = shift; 215 my $self = shift;
208 my $setName = $self->{set}->id; 216 my $setName = $self->{set}->id;
209 my $problemNumber = $self->{problem}->id; 217 my $problemNumber = $self->{problem}->id;
210 218
211 my $ce = $self->{courseEnvironment}; 219 my $ce = $self->{ce};
212 my $root = $ce->{webworkURLs}->{root}; 220 my $root = $ce->{webworkURLs}->{root};
213 my $courseName = $ce->{courseName}; 221 my $courseName = $ce->{courseName};
214 222
215 print CGI::strong("Problems"), CGI::br(); 223 print CGI::strong("Problems"), CGI::br();
216 224
230 my $self = shift; 238 my $self = shift;
231 my $args = $_[-1]; 239 my $args = $_[-1];
232 my $setName = $self->{set}->id; 240 my $setName = $self->{set}->id;
233 my $problemNumber = $self->{problem}->id; 241 my $problemNumber = $self->{problem}->id;
234 242
235 my $ce = $self->{courseEnvironment}; 243 my $ce = $self->{ce};
236 my $root = $ce->{webworkURLs}->{root}; 244 my $root = $ce->{webworkURLs}->{root};
237 my $courseName = $ce->{courseName}; 245 my $courseName = $ce->{courseName};
238 246
239 my $wwdb = $self->{wwdb}; 247 my $wwdb = $self->{wwdb};
240 my $effectiveUser = $self->{r}->param("effectiveUser"); 248 my $effectiveUser = $self->{r}->param("effectiveUser");
241 my $tail = "&displayMode=".$self->{displayMode}; 249 my $tail = "&displayMode=".$self->{displayMode};
242 250
243 my @links = ("Problem List" => "$root/$courseName/$setName"); 251 my @links = ("Problem List" , "$root/$courseName/$setName", "navProbList");
244 252
245 my $prevProblem = $wwdb->getProblem($effectiveUser, $setName, $problemNumber-1); 253 my $prevProblem = $wwdb->getProblem($effectiveUser, $setName, $problemNumber-1);
246 my $nextProblem = $wwdb->getProblem($effectiveUser, $setName, $problemNumber+1); 254 my $nextProblem = $wwdb->getProblem($effectiveUser, $setName, $problemNumber+1);
247 unshift @links, "Previous Problem" => $prevProblem 255 unshift @links, "Previous Problem" , ($prevProblem
248 ? "$root/$courseName/$setName/".$prevProblem->id 256 ? "$root/$courseName/$setName/".$prevProblem->id
249 : ""; 257 : "") , "navPrev";
250 push @links, "Next Problem" => $nextProblem 258 push @links, "Next Problem" , ($nextProblem
251 ? "$root/$courseName/$setName/".$nextProblem->id 259 ? "$root/$courseName/$setName/".$nextProblem->id
252 : ""; 260 : "") , "navNext";
253 261
254 return $self->navMacro($args, $tail, @links); 262 return $self->navMacro($args, $tail, @links);
255} 263}
256 264
257sub title { 265sub title {
262 return "$setName : Problem $problemNumber"; 270 return "$setName : Problem $problemNumber";
263} 271}
264 272
265sub body { 273sub body {
266 my $self = shift; 274 my $self = shift;
275
276 return CGI::p(CGI::font({-color=>"red"}, "This problem is not available because the problem set that contains it is not yet open."))
277 unless $self->{isOpen};
267 278
268 # unpack some useful variables 279 # unpack some useful variables
269 my $r = $self->{r}; 280 my $r = $self->{r};
270 my $wwdb = $self->{wwdb}; 281 my $wwdb = $self->{wwdb};
271 my $set = $self->{set}; 282 my $set = $self->{set};
281 my $pg = $self->{pg}; 292 my $pg = $self->{pg};
282 293
283 ##### translation errors? ##### 294 ##### translation errors? #####
284 295
285 if ($pg->{flags}->{error_flag}) { 296 if ($pg->{flags}->{error_flag}) {
286 return translationError($pg->{errors}, $pg->{body_text}); 297 return $self->errorOutput($pg->{errors}, $pg->{body_text});
287 } 298 }
288 299
289 ##### answer processing ##### 300 ##### answer processing #####
290 301
291 # if answers were submitted: 302 # if answers were submitted:
306 $problem->status($pg->{state}->{recorded_score}); 317 $problem->status($pg->{state}->{recorded_score});
307 $problem->num_correct($pg->{state}->{num_of_correct_ans}); 318 $problem->num_correct($pg->{state}->{num_of_correct_ans});
308 $problem->num_incorrect($pg->{state}->{num_of_incorrect_ans}); 319 $problem->num_incorrect($pg->{state}->{num_of_incorrect_ans});
309 $wwdb->setProblem($problem); 320 $wwdb->setProblem($problem);
310 # write to the transaction log, just to make sure 321 # write to the transaction log, just to make sure
311 writeLog($self->{courseEnvironment}, "transaction", 322 writeLog($self->{ce}, "transaction",
312 $problem->id."\t". 323 $problem->id."\t".
313 $problem->set_id."\t". 324 $problem->set_id."\t".
314 $problem->login_id."\t". 325 $problem->login_id."\t".
315 $problem->source_file."\t". 326 $problem->source_file."\t".
316 $problem->value."\t". 327 $problem->value."\t".
322 $problem->num_correct."\t". 333 $problem->num_correct."\t".
323 $problem->num_incorrect 334 $problem->num_incorrect
324 ); 335 );
325 } 336 }
326 } 337 }
338 # logging student answers
339 my $pastAnswerLog = undef;
340 if (defined( $self->{ce}->{webworkFiles}->{logs}->{'pastAnswerList'} )) {
341
342 $pastAnswerLog = $self->{ce}->{webworkFiles}->{logs}->{'pastAnswerList'};
343
344 if ($submitAnswers and defined($pastAnswerLog) ) {
345 my $answerString = "";
346 my %answerHash = %{ $pg->{answers} };
347 $answerString = $answerString . $answerHash{$_}->{original_student_ans}."\t"
348 foreach (sort keys %answerHash);
349 writeLog($self->{ce}, "pastAnswerList",
350 '|'.$problem->login_id.
351 '|'.$problem->set_id.
352 '|'.$problem->id.'|'."\t".
353 time()."\t".
354 $answerString,
355
356 );
357
358 }
359
360 }
361 # end logging student answers
327 362
328 ##### output ##### 363 ##### output #####
329 364 print CGI::start_div({class=>"problemHeader"});
330 # attempt summary 365 # attempt summary
331 if ($submitAnswers or $will{showCorrectAnswers}) { 366 if ($submitAnswers or $will{showCorrectAnswers}) {
332 # print this if user submitted answers OR requested correct answers 367 # print this if user submitted answers OR requested correct answers
333 print $self->attemptResults($pg, $submitAnswers, 368 print $self->attemptResults($pg, $submitAnswers,
334 $will{showCorrectAnswers}, 369 $will{showCorrectAnswers},
335 $pg->{flags}->{showPartialCorrectAnswers}, 0); 370 $pg->{flags}->{showPartialCorrectAnswers}, 1, 0);
336 } elsif ($checkAnswers) { 371 } elsif ($checkAnswers) {
337 # print this if user previewed answers 372 # print this if user previewed answers
338 print $self->attemptResults($pg, 1, 0, 1, 0); 373 print $self->attemptResults($pg, 1, 0, 1, 1, 0);
339 # show attempt answers 374 # show attempt answers
340 # don't show correct answers 375 # don't show correct answers
341 # show attempt results (correctness) 376 # show attempt results (correctness)
342 # don't show attempt previews 377 # don't show attempt previews
343 } elsif ($previewAnswers) { 378 } elsif ($previewAnswers) {
344 # print this if user previewed answers 379 # print this if user previewed answers
345 print $self->attemptResults($pg, 1, 0, 0, 1); 380 print $self->attemptResults($pg, 1, 0, 0, 0, 1);
346 # show attempt answers 381 # show attempt answers
347 # don't show correct answers 382 # don't show correct answers
348 # don't show attempt results (correctness) 383 # don't show attempt results (correctness)
349 # show attempt previews 384 # show attempt previews
350 } 385 }
351 386
387 print CGI::end_div();
388
389 print CGI::start_div({class=>"problem"});
390 #print CGI::hr();
391 # main form
392 print
393 CGI::startform("POST", $r->uri),
394 $self->hidden_authen_fields,
395 CGI::p($pg->{body_text}),
396 CGI::p($pg->{result}->{msg} ? CGI::b("Note: ") : "", CGI::i($pg->{result}->{msg})),
397 CGI::p(
398 ($can{recordAnswers}
399 ? CGI::submit(-name=>"submitAnswers",
400 -label=>"Submit Answers")
401 : ""),
402 ($can{checkAnswers}
403 ? CGI::submit(-name=>"checkAnswers",
404 -label=>"Check Answers")
405 : ""),
406 CGI::submit(-name=>"previewAnswers",
407 -label=>"Preview Answers"),
408 );
409 print CGI::end_div();
410
411 print CGI::start_div({class=>"scoreSummary"});
352 # score summary 412 # score summary
353 my $attempts = $problem->num_correct + $problem->num_incorrect; 413 my $attempts = $problem->num_correct + $problem->num_incorrect;
354 my $attemptsNoun = $attempts != 1 ? "times" : "time"; 414 my $attemptsNoun = $attempts != 1 ? "times" : "time";
355 my $lastScore = int ($problem->status * 100) . "%"; 415 my $lastScore = int ($problem->status * 100) . "%";
356 my ($attemptsLeft, $attemptsLeftNoun); 416 my ($attemptsLeft, $attemptsLeftNoun);
360 $attemptsLeftNoun = "attempts"; 420 $attemptsLeftNoun = "attempts";
361 } else { 421 } else {
362 $attemptsLeft = $problem->max_attempts - $attempts; 422 $attemptsLeft = $problem->max_attempts - $attempts;
363 $attemptsLeftNoun = $attemptsLeft == 1 ? "attempt" : "attempts"; 423 $attemptsLeftNoun = $attemptsLeft == 1 ? "attempt" : "attempts";
364 } 424 }
425
426 my $setClosed = 0;
365 my $setClosedMessage; 427 my $setClosedMessage;
366 if (time < $set->open_date or time > $set->due_date) { 428 if (time < $set->open_date or time > $set->due_date) {
429 $setClosed = 1;
367 $setClosedMessage = "This problem set is closed."; 430 $setClosedMessage = "This problem set is closed.";
368 if ($permissionLevel > 0) { 431 if ($permissionLevel > 0) {
369 $setClosedMessage .= " Since you are a privileged user, additional attempts will be recorded."; 432 $setClosedMessage .= " Since you are a privileged user, additional attempts will be recorded.";
370 } else { 433 } else {
371 $setClosedMessage .= " Additional attempts will not be recorded."; 434 $setClosedMessage .= " Additional attempts will not be recorded.";
374 print CGI::p( 437 print CGI::p(
375 "You have attempted this problem $attempts $attemptsNoun.", CGI::br(), 438 "You have attempted this problem $attempts $attemptsNoun.", CGI::br(),
376 $problem->attempted 439 $problem->attempted
377 ? "Your recorded score is $lastScore." . CGI::br() 440 ? "Your recorded score is $lastScore." . CGI::br()
378 : "", 441 : "",
379 "You have $attemptsLeft $attemptsLeftNoun remaining.", CGI::br(), 442 $setClosed ? $setClosedMessage : "You have $attemptsLeft $attemptsLeftNoun remaining."
380 $setClosedMessage,
381 ); 443 );
382
383 print CGI::hr(); 444 print CGI::end_div();
384 445 print CGI::hr(), CGI::start_div({class=>"viewOptions"});
385 # main form
386 print 446 print
387 CGI::startform("POST", $r->uri),
388 $self->hidden_authen_fields,
389 CGI::p(CGI::i($pg->{result}->{msg})),
390 CGI::p($pg->{body_text}),
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(), 447 $self->viewOptions(),CGI::end_div(),
404 CGI::endform(); 448 CGI::endform();
405 449
450 print CGI::start_div({class=>"problemFooter"});
406 # feedback form 451 # feedback form
407 my $ce = $self->{courseEnvironment}; 452 my $ce = $self->{ce};
408 my $root = $ce->{webworkURLs}->{root}; 453 my $root = $ce->{webworkURLs}->{root};
409 my $courseName = $ce->{courseName}; 454 my $courseName = $ce->{courseName};
410 my $feedbackURL = "$root/$courseName/feedback/"; 455 my $feedbackURL = "$root/$courseName/feedback/";
456
457 # arguments for answer inspection button
458 my $prof_url = $ce->{webworkURLs}->{oldProf};
459 my $cgi_url = $prof_url;
460 $cgi_url=~ s|/[^/]*$||; # clip profLogin.pl
461 my $authen_args = $self->url_authen_args();
462 my $showPastAnswersURL = "$cgi_url/showPastAnswers.pl";
463
464 #print feedback form
411 print 465 print
412 CGI::startform("POST", $feedbackURL), 466 CGI::start_form(-method=>"POST", -action=>$feedbackURL),"\n",
413 $self->hidden_authen_fields, 467 $self->hidden_authen_fields,"\n",
414 CGI::hidden("module", __PACKAGE__), 468 CGI::hidden("module", __PACKAGE__),"\n",
415 CGI::hidden("set", $set->id), 469 CGI::hidden("set", $set->id),"\n",
416 CGI::hidden("problem", $problem->id), 470 CGI::hidden("problem", $problem->id),"\n",
417 CGI::hidden("displayMode", $self->{displayMode}), 471 CGI::hidden("displayMode", $self->{displayMode}),"\n",
418 CGI::hidden("showOldAnswers", $will{showOldAnswers}), 472 CGI::hidden("showOldAnswers", $will{showOldAnswers}),"\n",
419 CGI::hidden("showCorrectAnswers", $will{showCorrectAnswers}), 473 CGI::hidden("showCorrectAnswers", $will{showCorrectAnswers}),"\n",
420 CGI::hidden("showHints", $will{showHints}), 474 CGI::hidden("showHints", $will{showHints}),"\n",
421 CGI::hidden("showSolutions", $will{showSolutions}), 475 CGI::hidden("showSolutions", $will{showSolutions}),"\n",
422 CGI::p({-align=>"right"}, 476 CGI::p({-align=>"right"},
423 CGI::submit(-name=>"feedbackForm", -label=>"Send Feedback") 477 CGI::submit(-name=>"feedbackForm", -label=>"Send Feedback")
424 ), 478 ),
479 CGI::endform(),"\n";
480 # print answer inspection button
481 if ($self->{permissionLevel} >0) {
482
483
484 print "\n",
485 CGI::start_form(-method=>"POST",-action=>$showPastAnswersURL,-target=>"information"),"\n",
486 $self->hidden_authen_fields,"\n",
487 CGI::hidden(-name => 'course', -value=>$courseName), "\n",
488 CGI::hidden(-name => 'probNum', -value=>$problem->id), "\n",
489 CGI::hidden(-name => 'setNum', -value=>$problem->set_id), "\n",
490 CGI::hidden(-name => 'User', -value=>$problem->login_id), "\n",
491 CGI::submit(-name => 'action', -value=>'Show Past Answers'), "\n",
425 CGI::endform(); 492 CGI::endform();
426 493
494
495
496 }
497 print CGI::end_div();
498 # end answer inspection button
427 # warning output 499 # warning output
428 if ($pg->{warnings} ne "") { 500 if ($pg->{warnings} ne "") {
429 print CGI::hr(), warningOutput($pg->{warnings}); 501 print CGI::hr(), $self->warningOutput($pg->{warnings});
430 } 502 }
431 503
432 # debugging stuff 504 # debugging stuff
505 if (0) {
433 #print 506 print
434 # CGI::hr(), 507 CGI::hr(),
435 # CGI::h2("debugging information"), 508 CGI::h2("debugging information"),
436 # CGI::h3("form fields"), 509 CGI::h3("form fields"),
437 # ref2string($self->{formFields}), 510 ref2string($self->{formFields}),
438 # CGI::h3("user object"), 511 CGI::h3("user object"),
439 # ref2string($self->{user}), 512 ref2string($self->{user}),
440 # CGI::h3("set object"), 513 CGI::h3("set object"),
441 # ref2string($set), 514 ref2string($set),
442 # CGI::h3("problem object"), 515 CGI::h3("problem object"),
443 # ref2string($problem), 516 ref2string($problem),
444 # CGI::h3("PG object"), 517 CGI::h3("PG object"),
445 # ref2string($pg, {'WeBWorK::PG::Translator' => 1}); 518 ref2string($pg, {'WeBWorK::PG::Translator' => 1});
519 }
446 520
447 return ""; 521 return "";
448} 522}
449 523
450##### output utilities ##### 524##### output utilities #####
451 525
452# this is used by ProblemSet.pm too, so don't fuck it up
453sub translationError($$) {
454 my ($error, $details) = @_;
455 return
456 CGI::h2("Software Error"),
457 CGI::p(<<EOF),
458WeBWorK has encountered a software error while attempting to process this problem.
459It is likely that there is an error in the problem itself.
460If you are a student, contact your professor to have the error corrected.
461If you are a professor, please consut the error output below for more informaiton.
462EOF
463 CGI::h3("Error messages"), CGI::blockquote(CGI::pre($error)),
464 CGI::h3("Error context"), CGI::blockquote(CGI::pre($details));
465}
466
467# this is used by ProblemSet.pm too, so don't fuck it up
468sub warningOutput($) {
469 my $warnings = shift;
470
471 return
472 CGI::h2("Software Warnings"),
473 CGI::p(<<EOF),
474WeBWorK has encountered warnings while attempting to process this problem.
475It is likely that this indicates an error or ambiguity in the problem itself.
476If you are a student, contact your professor to have the problem corrected.
477If you are a professor, please consut the error output below for more informaiton.
478EOF
479 CGI::h3("Warning messages"),
480 CGI::blockquote(CGI::pre($warnings)),
481 ;
482}
483
484sub attemptResults($$$$$) { 526sub attemptResults($$$$$$) {
485 my $self = shift; 527 my $self = shift;
486 my $pg = shift; 528 my $pg = shift;
487 my $showAttemptAnswers = shift; 529 my $showAttemptAnswers = shift;
488 my $showCorrectAnswers = shift; 530 my $showCorrectAnswers = shift;
489 my $showAttemptResults = $showAttemptAnswers && shift; 531 my $showAttemptResults = $showAttemptAnswers && shift;
532 my $showSummary = shift;
490 my $showAttemptPreview = shift || 0; 533 my $showAttemptPreview = shift || 0;
491 my $problemResult = $pg->{result}; # the overall result of the problem 534 my $problemResult = $pg->{result}; # the overall result of the problem
492 my @answerNames = @{ $pg->{flags}->{ANSWER_ENTRY_ORDER} }; 535 my @answerNames = @{ $pg->{flags}->{ANSWER_ENTRY_ORDER} };
493 536
494 my $showMessages = $showAttemptAnswers && grep { $pg->{answers}->{$_}->{ans_message} } @answerNames; 537 my $showMessages = $showAttemptAnswers && grep { $pg->{answers}->{$_}->{ans_message} } @answerNames;
495 538
496 my $header = CGI::th("part"); 539 my $header = CGI::th("Part");
497 $header .= $showAttemptAnswers ? CGI::th("entered") : ""; 540 $header .= $showAttemptAnswers ? CGI::th("Entered") : "";
498 $header .= $showAttemptPreview ? CGI::th("preview") : ""; 541 $header .= $showAttemptPreview ? CGI::th("Answer Preview") : "";
499 $header .= $showCorrectAnswers ? CGI::th("correct") : ""; 542 $header .= $showCorrectAnswers ? CGI::th("Correct") : "";
500 $header .= $showAttemptResults ? CGI::th("result") : ""; 543 $header .= $showAttemptResults ? CGI::th("Result") : "";
501 $header .= $showMessages ? CGI::th("messages") : ""; 544 $header .= $showMessages ? CGI::th("messages") : "";
502 my @tableRows = ( $header ); 545 my @tableRows = ( $header );
503 my $numCorrect; 546 my $numCorrect;
504 foreach my $name (@answerNames) { 547 foreach my $name (@answerNames) {
505 my $answerResult = $pg->{answers}->{$name}; 548 my $answerResult = $pg->{answers}->{$name};
525 $row .= $showAttemptResults ? CGI::td($resultString) : ""; 568 $row .= $showAttemptResults ? CGI::td($resultString) : "";
526 $row .= $answerMessage ? CGI::td($answerMessage) : ""; 569 $row .= $answerMessage ? CGI::td($answerMessage) : "";
527 push @tableRows, $row; 570 push @tableRows, $row;
528 } 571 }
529 572
530 my $numCorrectNoun = $numCorrect == 1 ? "question" : "questions"; 573 my $numIncorrectNoun = scalar @answerNames == 1 ? "question" : "questions";
531 my $scorePercent = int ($problemResult->{score} * 100) . "\%"; 574 my $scorePercent = int ($problemResult->{score} * 100) . "\%";
532 my $summary = "On this attempt, you answered $numCorrect $numCorrectNoun out of " 575 my $summary = "On this attempt, you answered $numCorrect out of "
533 . scalar @answerNames . " correct, for a score of $scorePercent."; 576 . scalar @answerNames . " $numIncorrectNoun correct, for a score of $scorePercent.";
534 return CGI::table({-border=>1}, CGI::Tr(\@tableRows)) . CGI::p($summary); 577 return CGI::table({-class=>"attemptResults"}, CGI::Tr(\@tableRows)) . ($showSummary ? CGI::p($summary) : "");
535} 578}
536 579
537sub viewOptions($) { 580sub viewOptions($) {
538 my $self = shift; 581 my $self = shift;
539 my $displayMode = $self->{displayMode}; 582 my $displayMode = $self->{displayMode};
586 ); 629 );
587} 630}
588 631
589sub previewAnswer($$) { 632sub previewAnswer($$) {
590 my ($self, $answerResult) = @_; 633 my ($self, $answerResult) = @_;
591 my $ce = $self->{courseEnvironment}; 634 my $ce = $self->{ce};
592 my $effectiveUser = $self->{effectiveUser}; 635 my $effectiveUser = $self->{effectiveUser};
593 my $set = $self->{set}; 636 my $set = $self->{set};
594 my $problem = $self->{problem}; 637 my $problem = $self->{problem};
595 my $displayMode = $self->{displayMode}; 638 my $displayMode = $self->{displayMode};
596 639
598 # rendering math from INSIDE the translator and from OUTSIDE the translator. 641 # rendering math from INSIDE the translator and from OUTSIDE the translator.
599 # so we'll just deal with each case explicitly here. there's some code 642 # so we'll just deal with each case explicitly here. there's some code
600 # duplication that can be dealt with later by abstracting out tth/dvipng/etc. 643 # duplication that can be dealt with later by abstracting out tth/dvipng/etc.
601 644
602 my $tex = $answerResult->{preview_latex_string}; 645 my $tex = $answerResult->{preview_latex_string};
646
647 return "" unless $tex;
603 648
604 if ($displayMode eq "plainText") { 649 if ($displayMode eq "plainText") {
605 return $tex; 650 return $tex;
606 } elsif ($displayMode eq "formattedText") { 651 } elsif ($displayMode eq "formattedText") {
607 my $tthCommand = $ce->{externalPrograms}->{tth} 652 my $tthCommand = $ce->{externalPrograms}->{tth}
608 . " -L -f5 -r 2> /dev/null <<END_OF_INPUT; echo > /dev/null\n" 653 . " -L -f5 -r 2> /dev/null <<END_OF_INPUT; echo > /dev/null\n"
609 . "\\($tex\\)\n" 654 . "\\(".$tex."\\)\n"
610 . "END_OF_INPUT\n"; 655 . "END_OF_INPUT\n";
611
612 656
613 # call tth 657 # call tth
614 my $result = `$tthCommand`; 658 my $result = `$tthCommand`;
615 if ($?) { 659 if ($?) {
616 return "<b>[tth failed: $? $@]</b>"; 660 return "<b>[tth failed: $? $@]</b>";
632 # should use surePathToTmpFile, but we have to 676 # should use surePathToTmpFile, but we have to
633 # isolate it from the problem enivronment first 677 # isolate it from the problem enivronment first
634 my $targetURL = $ce->{courseURLs}->{html_temp} . $targetPathCommon; 678 my $targetURL = $ce->{courseURLs}->{html_temp} . $targetPathCommon;
635 679
636 # call dvipng to generate a preview 680 # call dvipng to generate a preview
681 warn $tex;
637 dvipng($wd, $latex, $dvipng, $tex, $targetPath); 682 dvipng($wd, $latex, $dvipng, $tex, $targetPath);
638 if (-e $targetPath) { 683 if (-e $targetPath) {
639 return "<img src=\"$targetURL\" alt=\"$tex\" />"; 684 return "<img src=\"$targetURL\" alt=\"$tex\" />";
640 } else { 685 } else {
641 return "<b>[math2img failed]</b>"; 686 return "<b>[math2img failed]</b>";
642 } 687 }
643 } 688 }
644} 689}
690##### logging subroutine ####
691
692
645 693
646##### permission queries ##### 694##### permission queries #####
647 695
648# this stuff should be abstracted out into the permissions system 696# this stuff should be abstracted out into the permissions system
649# however, the permission system only knows about things in the 697# however, the permission system only knows about things in the
670 my $attemptsOK = $maxAttempts == -1 || $attempts <= $maxAttempts; 718 my $attemptsOK = $maxAttempts == -1 || $attempts <= $maxAttempts;
671 my $recordAnswers = $permHigh || ($timeOK && $attemptsOK); 719 my $recordAnswers = $permHigh || ($timeOK && $attemptsOK);
672 return $recordAnswers; 720 return $recordAnswers;
673} 721}
674 722
723sub canCheckAnswers($$) {
724 my ($permissionLevel, $answerDate) = @_;
725 my $permHigh = $permissionLevel > 0;
726 my $timeOK = time >= $answerDate;
727 my $recordAnswers = $permHigh || $timeOK;
728 return $recordAnswers;
729}
730
675sub mustRecordAnswers($) { 731sub mustRecordAnswers($) {
676 my ($permissionLevel) = @_; 732 my ($permissionLevel) = @_;
677 return $permissionLevel == 0; 733 return $permissionLevel == 0;
678} 734}
679 735

Legend:
Removed from v.719  
changed lines
  Added in v.809

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9