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

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

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

Revision 738 Revision 739
171 } 171 }
172 print CGI::end_p(); 172 print CGI::end_p();
173 173
174 print CGI::start_form(-method=>"POST", -action=>$r->uri); 174 print CGI::start_form(-method=>"POST", -action=>$r->uri);
175 print $self->hidden_authen_fields(); 175 print $self->hidden_authen_fields();
176 warn "showHints=", $r->param("showHints"), "\n"; 176 print CGI::h3("Options");
177 print CGI::p("You may choose to show any of the following data. Correct answers and solutions are only available to privileged users or after the answer date of the problem set.");
177 print CGI::p( 178 print CGI::p(
178 CGI::checkbox( 179 CGI::checkbox(
179 -name => "showCorrectAnswers", 180 -name => "showCorrectAnswers",
180 -checked => $r->param("showCorrectAnswers") || 0, 181 -checked => $r->param("showCorrectAnswers") || 0,
181 -label => "Correct answers", 182 -label => "Correct answers",
193 ); 194 );
194 print CGI::start_table({-width=>"100%"}), CGI::start_Tr({-valign=>"top"}); 195 print CGI::start_table({-width=>"100%"}), CGI::start_Tr({-valign=>"top"});
195 196
196 my $multiSet = $self->{permissionLevel} > 0; 197 my $multiSet = $self->{permissionLevel} > 0;
197 my $multiUser = $self->{permissionLevel} > 0; 198 my $multiUser = $self->{permissionLevel} > 0;
199 my $preOpenSets = $self->{permissionLevel} > 0;
198 200
199 # set selection menu 201 # set selection menu
200 { 202 {
201 print CGI::start_td(); 203 print CGI::start_td();
202 print CGI::h3("Sets"); 204 print CGI::h3("Sets");
206 foreach ($self->{wwdb}->getSets($self->{effectiveUser}->id)); 208 foreach ($self->{wwdb}->getSets($self->{effectiveUser}->id));
207 @sets = sort { $a->id cmp $b->id } @sets; 209 @sets = sort { $a->id cmp $b->id } @sets;
208 foreach my $set (@sets) { 210 foreach my $set (@sets) {
209 my $checked = grep { $_ eq $set->id } @{$self->{sets}}; 211 my $checked = grep { $_ eq $set->id } @{$self->{sets}};
210 my $control; 212 my $control;
211 if (time < $set->open_date) { 213 if (time < $set->open_date and not $preOpenSets) {
212 $control = ""; 214 $control = "";
213 } else { 215 } else {
214 if ($multiSet) { 216 if ($multiSet) {
215 $control = CGI::checkbox( 217 $control = CGI::checkbox(
216 -name=>"hcSet", 218 -name=>"hcSet",
343 close TEX; 345 close TEX;
344 346
345 # call pdflatex - we don't want to chdir in the mod_perl process, as 347 # call pdflatex - we don't want to chdir in the mod_perl process, as
346 # that might step on the feet of other things (esp. in Apache 2.0) 348 # that might step on the feet of other things (esp. in Apache 2.0)
347 my $pdflatex = $ce->{externalPrograms}->{pdflatex}; 349 my $pdflatex = $ce->{externalPrograms}->{pdflatex};
348 system "cd $wd && $pdflatex $texFile" and die "Failed to call pdflatex: $!\n"; 350 my $pdflatexResult = system "cd $wd && $pdflatex $texFile";
351 if ($pdflatexResult) {
352 # something bad happened
353 my $textErrorMessage = "Call to $pdflatex failed: $!\n";
354 if (-e $logFile) {
355 $textErrorMessage .= "pdflatex ran, but did not succeed. This suggests an error in the TeX\n";
356 $textErrorMessage .= "version of one of the problems, or a problem with the pdflatex system.\n";
357 my $logFileContents = eval { readFile($logFile) };
358 if ($@) {
359 $textErrorMessage .= "Additionally, the pdflatex log file could not be read, though it exists.\n";
360 } else {
361 $textErrorMessage .= "The contents of the TeX log are as follows:\n\n";
362 $textErrorMessage .= "$logFileContents\n\n";
363 }
364 } else {
365 $textErrorMessage .= "No log file was created, suggesting that pdflatex never ran. Check the WeBWorK\n";
366 $textErrorMessage .= "configuration to ensure that the path to pdflatex is correct.\n";
367 }
368 die $textErrorMessage;
369 }
349 370
350 if (-e $pdfFile) { 371 if (-e $pdfFile) {
351 # move resulting PDF file to appropriate location 372 # move resulting PDF file to appropriate location
352 system "/bin/mv", $pdfFile, $finalFile and die "Failed to mv: $!\n"; 373 system "/bin/mv", $pdfFile, $finalFile and die "Failed to mv: $!\n";
353 } 374 }
448 source_file => $pgFile, 469 source_file => $pgFile,
449 # the rest of Problem's fields are not needed, i think 470 # the rest of Problem's fields are not needed, i think
450 ); 471 );
451 } 472 }
452 473
453 # *** right here, figure out if we're allowed to get solutions and call PG->new accordingly. 474 # figure out if we're allowed to get solutions and call PG->new accordingly.
454 my $showCorrectAnswers = $r->param("showCorrectAnswers") || 0; 475 my $showCorrectAnswers = $r->param("showCorrectAnswers") || 0;
455 my $showHints = $r->param("showHints") || 0; 476 my $showHints = $r->param("showHints") || 0;
456 my $showSolutions = $r->param("showSolutions") || 0; 477 my $showSolutions = $r->param("showSolutions") || 0;
457 unless ($permissionLevel > 0 or time > $set->due_date) { 478 unless ($permissionLevel > 0 or time > $set->answer_date) {
458 $showCorrectAnswers = 0; 479 $showCorrectAnswers = 0;
459 $showSolutions = 0; 480 $showSolutions = 0;
460 } 481 }
461 482
462 my $pg = WeBWorK::PG->new( 483 my $pg = WeBWorK::PG->new(
467 $problem, 488 $problem,
468 $psvn, 489 $psvn,
469 {}, # no form fields! 490 {}, # no form fields!
470 { # translation options 491 { # translation options
471 displayMode => "tex", 492 displayMode => "tex",
472 showHints => 0, 493 showHints => $showHints,
473 showSolutions => 0, 494 showSolutions => $showSolutions,
474 processAnswers => 0, 495 processAnswers => $showCorrectAnswers,
475 }, 496 },
476 ); 497 );
477 498
478 if ($pg->{warnings} ne "") { 499 if ($pg->{warnings} ne "") {
479 push @{$self->{warnings}}, { 500 push @{$self->{warnings}}, {
491 context => $pg->{body_text}, 512 context => $pg->{body_text},
492 }; 513 };
493 # if there was an error, body_text contains 514 # if there was an error, body_text contains
494 # the error context, not TeX code 515 # the error context, not TeX code
495 $pg->{body_text} = undef; 516 $pg->{body_text} = undef;
496 } 517 } else {
497
498 # *** right here, append list of correct answers to body text 518 # append list of correct answers to body text
499 519 if ($showCorrectAnswers && $problemNumber != 0) {
520 my $correctTeX = "Correct Answers:\\par\\begin{itemize}\n";
521 foreach my $ansName (@{$pg->{flags}->{ANSWER_ENTRY_ORDER}}) {
522 my $correctAnswer = $pg->{answers}->{$ansName}->{correct_ans};
523 $correctAnswer =~ s/\^/\\\^\{\}/g;
524 $correctAnswer =~ s/\_/\\\_/g;
525 $correctTeX .= "\\item $correctAnswer\n";
526 }
527 $correctTeX .= "\\end{itemize} \\par\n";
528 $pg->{body_text} .= $correctTeX;
529 }
530 }
531 warn "BODY TEXT=\n", $pg->{body_text}, "\n\n";
500 return $pg->{body_text}; 532 return $pg->{body_text};
501} 533}
502 534
503sub texInclude { 535sub texInclude {
504 my ($self, $texFile) = @_; 536 my ($self, $texFile) = @_;
514 546
515 return $tex; 547 return $tex;
516} 548}
517 549
5181; 5501;
519
520__END__
521
522sub body {
523 my $self = shift;
524
525 STUFF: {
526 my $courseName = $self->{courseEnvironment}->{courseName};
527 my $effectiveUserName = $self->{r}->param("effectiveUser");
528 my @sets = @{$self->{sets}};
529
530 unless (@sets) {
531 print CGI::p("No problem sets were specified.");
532 last STUFF;
533 }
534
535 # determine where hardcopy is going to go
536 my $tempDir = $self->{courseEnvironment}->{courseDirs}->{html_temp}
537 . "/hardcopy";
538 my $tempURL = $self->{courseEnvironment}->{courseURLs}->{html_temp}
539 . "/hardcopy";
540
541 # make sure tempDir exists
542 unless (-e $tempDir) {
543 if (system "mkdir", "-p", $tempDir) {
544 print CGI::p("An error occured while trying to generate your PDF hardcopy:");
545 print CGI::blockquote(CGI::pre("Failed to mkdir $tempDir: $!\n"));
546 }
547 }
548
549 # determine name of PDF file
550 my $fileName;
551 if (@sets > 1) {
552 # multiset output
553 $fileName = "$courseName.$effectiveUserName.multiset.pdf"
554 } elsif (@sets == 1) {
555 # only one set
556 my $setName = $sets[0];
557 $fileName = "$courseName.$effectiveUserName.$setName.pdf";
558 } else {
559 $fileName = "$courseName.$effectiveUserName.pdf";
560 }
561
562 # determine full URL
563 my $fullURL = "$tempURL/$fileName";
564
565 # generate TeX from sets
566 my $tex = $self->getMultiSetTeX(@sets);
567 #print CGI::pre($tex);
568
569 # check for PG errors (fatal)
570 if (@{$self->{errors}}) {
571 my @errors = @{$self->{errors}};
572 print CGI::h2("Software Errors");
573 print CGI::p(<<EOF);
574WeBWorK has encountered one or more software errors while attempting to process these sets.
575It is likely that there are error(s) in the problem itself.
576If you are a student, contact your professor to have the error(s) corrected.
577If you are a professor, please consut the error output below for more informaiton.
578EOF
579 foreach my $error (@errors) {
580 print CGI::h3("Set: ", $error->{set}, ", Problem: ", $error->{problem});
581 print CGI::h4("Error messages"), CGI::blockquote(CGI::pre($error->{message}));
582 print CGI::h4("Error context"), CGI::blockquote(CGI::pre($error->{context}));
583 }
584
585 last STUFF;
586 }
587
588 # "try" to generate hardcopy
589 eval { $self->latex2pdf($tex, $tempDir, $fileName) };
590 if ($@) {
591 print CGI::p("An error occured while trying to generate your PDF hardcopy:");
592 print CGI::blockquote(CGI::pre($@));
593 last STUFF;
594 } else {
595 print CGI::p({-align=>"center"},
596 CGI::big(CGI::a({-href=>$fullURL}, "Download PDF Hardcopy"))
597 );
598 }
599
600 # check for PG warnings (non-fatal)
601 if (@{$self->{warnings}}) {
602 my @warnings = @{$self->{warnings}};
603 print CGI::h2("Software Warnings");
604 print CGI::p(<<EOF);
605WeBWorK has encountered warnings while attempting to process these sets.
606It is likely that this indicates an error or ambiguity in the problem(s) themselves.
607If you are a student, contact your professor to have the problem(s) corrected.
608If you are a professor, please consut the error output below for more informaiton.
609EOF
610 foreach my $warning (@warnings) {
611 print CGI::h3("Set: ", $warning->{set}, ", Problem: ", $warning->{problem});
612 print CGI::h4("Warning messages"), CGI::blockquote(CGI::pre($warning->{message}));
613 }
614 }
615 }
616
617 # feedback form
618 my $ce = $self->{courseEnvironment};
619 my $root = $ce->{webworkURLs}->{root};
620 my $courseName = $ce->{courseName};
621 my $feedbackURL = "$root/$courseName/feedback/";
622 print
623 CGI::startform("POST", $feedbackURL),
624 $self->hidden_authen_fields,
625 CGI::hidden("module", __PACKAGE__),
626 CGI::p({-align=>"right"},
627 CGI::submit(-name=>"feedbackForm", -label=>"Send Feedback")
628 ),
629 CGI::endform();
630
631 return "";
632}

Legend:
Removed from v.738  
changed lines
  Added in v.739

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9