| 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-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
| 4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/PG.pm,v 1.48 2004/05/22 22:14:07 dpvc Exp $ |
4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/PG.pm,v 1.49 2004/05/23 01:15:28 jj 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. |
| … | |
… | |
| 25 | |
25 | |
| 26 | use strict; |
26 | use strict; |
| 27 | use warnings; |
27 | use warnings; |
| 28 | use WeBWorK::PG::ImageGenerator; |
28 | use WeBWorK::PG::ImageGenerator; |
| 29 | use WeBWorK::Utils qw(runtime_use formatDateTime makeTempDirectory); |
29 | use WeBWorK::Utils qw(runtime_use formatDateTime makeTempDirectory); |
|
|
30 | |
|
|
31 | use constant DISPLAY_MODES => { |
|
|
32 | # display name # mode name |
|
|
33 | tex => "TeX", |
|
|
34 | plainText => "HTML", |
|
|
35 | formattedText => "HTML_tth", |
|
|
36 | images => "HTML_dpng", |
|
|
37 | jsMath => "HTML_jsMath", |
|
|
38 | }; |
|
|
39 | |
|
|
40 | use constant DISPLAY_MODE_FAILOVER => { |
|
|
41 | TeX => [], |
|
|
42 | HTML => [], |
|
|
43 | HTML_tth => [ "HTML", ], |
|
|
44 | HTML_dpng => [ "HTML_tth", "HTML", ], |
|
|
45 | HTML_jsMath => [ "HTML_dpng", "HTML_tth", "HTML", ], |
|
|
46 | # legacy modes -- these are not supported, but some problems might try to |
|
|
47 | # set the display mode to one of these values manually and some macros may |
|
|
48 | # provide rendered versions for these modes but not the one we want. |
|
|
49 | Latex2HTML => [ "TeX", "HTML", ], |
|
|
50 | HTML_img => [ "HTML_dpng", "HTML_tth", "HTML", ], |
|
|
51 | }; |
| 30 | |
52 | |
| 31 | sub new { |
53 | sub new { |
| 32 | shift; # throw away invocant -- we don't need it |
54 | shift; # throw away invocant -- we don't need it |
| 33 | my ($ce, $user, $key, $set, $problem, $psvn, $formFields, |
55 | my ($ce, $user, $key, $set, $problem, $psvn, $formFields, |
| 34 | $translationOptions) = @_; |
56 | $translationOptions) = @_; |
| … | |
… | |
| 60 | # PG environment variables |
82 | # PG environment variables |
| 61 | # from docs/pglanguage/pgreference/environmentvariables as of 06/25/2002 |
83 | # from docs/pglanguage/pgreference/environmentvariables as of 06/25/2002 |
| 62 | # any changes are noted by "ADDED:" or "REMOVED:" |
84 | # any changes are noted by "ADDED:" or "REMOVED:" |
| 63 | |
85 | |
| 64 | # Vital state information |
86 | # Vital state information |
| 65 | # ADDED: displayHintsQ, displaySolutionsQ, refreshMath2img, |
87 | # ADDED: displayModeFailover, displayHintsQ, displaySolutionsQ, |
| 66 | # texDisposition |
88 | # refreshMath2img, texDisposition |
| 67 | |
89 | |
| 68 | $envir{psvn} = $set->psvn; |
90 | $envir{psvn} = $set->psvn; |
| 69 | $envir{psvnNumber} = $envir{psvn}; |
91 | $envir{psvnNumber} = $envir{psvn}; |
| 70 | $envir{probNum} = $problem->problem_id; |
92 | $envir{probNum} = $problem->problem_id; |
| 71 | $envir{questionNumber} = $envir{probNum}; |
93 | $envir{questionNumber} = $envir{probNum}; |
| 72 | $envir{fileName} = $problem->source_file; |
94 | $envir{fileName} = $problem->source_file; |
| 73 | $envir{probFileName} = $envir{fileName}; |
95 | $envir{probFileName} = $envir{fileName}; |
| 74 | $envir{problemSeed} = $problem->problem_seed; |
96 | $envir{problemSeed} = $problem->problem_seed; |
| 75 | $envir{displayMode} = translateDisplayModeNames($options->{displayMode}); |
97 | $envir{displayMode} = translateDisplayModeNames($options->{displayMode}); |
| 76 | $envir{languageMode} = $envir{displayMode}; |
98 | $envir{languageMode} = $envir{displayMode}; |
| 77 | $envir{outputMode} = $envir{displayMode}; |
99 | $envir{outputMode} = $envir{displayMode}; |
|
|
100 | $envir{displayModeFailover} = DISPLAY_MODE_FAILOVER(); |
| 78 | $envir{displayHintsQ} = $options->{showHints}; |
101 | $envir{displayHintsQ} = $options->{showHints}; |
| 79 | $envir{displaySolutionsQ} = $options->{showSolutions}; |
102 | $envir{displaySolutionsQ} = $options->{showSolutions}; |
| 80 | $envir{texDisposition} = "pdf"; # in webwork2, we use pdflatex |
103 | $envir{texDisposition} = "pdf"; # in webwork2, we use pdflatex |
| 81 | |
104 | |
| 82 | # Problem Information |
105 | # Problem Information |
| 83 | # ADDED: courseName, formatedDueDate |
106 | # ADDED: courseName, formatedDueDate |
| 84 | |
107 | |
| 85 | $envir{openDate} = $set->open_date; |
108 | $envir{openDate} = $set->open_date; |
| … | |
… | |
| 183 | return \%envir; |
206 | return \%envir; |
| 184 | } |
207 | } |
| 185 | |
208 | |
| 186 | sub translateDisplayModeNames($) { |
209 | sub translateDisplayModeNames($) { |
| 187 | my $name = shift; |
210 | my $name = shift; |
| 188 | return { |
211 | return DISPLAY_MODES()->{$name}; |
| 189 | tex => "TeX", |
|
|
| 190 | plainText => "HTML", |
|
|
| 191 | formattedText => "HTML_tth", |
|
|
| 192 | images => "HTML_dpng", # "HTML_img", |
|
|
| 193 | jsMath => "HTML_jsMath", |
|
|
| 194 | }->{$name}; |
|
|
| 195 | } |
212 | } |
| 196 | |
213 | |
| 197 | sub oldSafetyFilter { |
214 | sub oldSafetyFilter { |
| 198 | my $answer = shift; # accepts one answer and checks it |
215 | my $answer = shift; # accepts one answer and checks it |
| 199 | my $submittedAnswer = $answer; |
216 | my $submittedAnswer = $answer; |