| 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-2006 The WeBWorK Project, http://openwebwork.sf.net/ |
| 4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/PG.pm,v 1.53 2004/06/21 19:07:08 gage Exp $ |
4 | # $CVSHeader: webwork2/lib/WeBWorK/PG.pm,v 1.70 2006/11/27 18:37:21 sh002i 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 Safe::Hole; |
| 28 | use WeBWorK::PG::ImageGenerator; |
29 | use WeBWorK::PG::ImageGenerator; |
| 29 | use WeBWorK::Utils qw(runtime_use formatDateTime makeTempDirectory); |
30 | use WeBWorK::Utils qw(runtime_use formatDateTime makeTempDirectory); |
|
|
31 | use WeBWorK::Utils::RestrictedClosureClass; |
| 30 | |
32 | |
| 31 | use constant DISPLAY_MODES => { |
33 | use constant DISPLAY_MODES => { |
| 32 | # display name # mode name |
34 | # display name # mode name |
| 33 | tex => "TeX", |
35 | tex => "TeX", |
| 34 | plainText => "HTML", |
36 | plainText => "HTML", |
| 35 | formattedText => "HTML_tth", |
37 | formattedText => "HTML_tth", |
| 36 | images => "HTML_dpng", |
38 | images => "HTML_dpng", |
| 37 | jsMath => "HTML_jsMath", |
39 | jsMath => "HTML_jsMath", |
| 38 | asciimath => "HTML_asciimath", |
40 | asciimath => "HTML_asciimath", |
|
|
41 | LaTeXMathML => "HTML_LaTeXMathML", |
| 39 | }; |
42 | }; |
| 40 | |
43 | |
| 41 | sub new { |
44 | sub new { |
| 42 | shift; # throw away invocant -- we don't need it |
45 | shift; # throw away invocant -- we don't need it |
| 43 | my ($ce, $user, $key, $set, $problem, $psvn, $formFields, |
46 | my ($ce, $user, $key, $set, $problem, $psvn, $formFields, |
| … | |
… | |
| 59 | $set, |
62 | $set, |
| 60 | $problem, |
63 | $problem, |
| 61 | $psvn, |
64 | $psvn, |
| 62 | $formFields, |
65 | $formFields, |
| 63 | $options, |
66 | $options, |
|
|
67 | $extras, |
| 64 | ) = @_; |
68 | ) = @_; |
| 65 | |
69 | |
| 66 | my %envir; |
70 | my %envir; |
| 67 | |
71 | |
| 68 | # ---------------------------------------------------------------------- |
72 | # ---------------------------------------------------------------------- |
| … | |
… | |
| 91 | |
95 | |
| 92 | # Problem Information |
96 | # Problem Information |
| 93 | # ADDED: courseName, formatedDueDate |
97 | # ADDED: courseName, formatedDueDate |
| 94 | |
98 | |
| 95 | $envir{openDate} = $set->open_date; |
99 | $envir{openDate} = $set->open_date; |
| 96 | $envir{formattedOpenDate} = formatDateTime($envir{openDate}); |
100 | $envir{formattedOpenDate} = formatDateTime($envir{openDate}, $ce->{siteDefaults}{timezone}); |
| 97 | $envir{dueDate} = $set->due_date; |
101 | $envir{dueDate} = $set->due_date; |
| 98 | $envir{formattedDueDate} = formatDateTime($envir{dueDate}); |
102 | $envir{formattedDueDate} = formatDateTime($envir{dueDate}, $ce->{siteDefaults}{timezone}); |
| 99 | $envir{formatedDueDate} = $envir{formattedDueDate}; # typo in many header files |
103 | $envir{formatedDueDate} = $envir{formattedDueDate}; # typo in many header files |
| 100 | $envir{answerDate} = $set->answer_date; |
104 | $envir{answerDate} = $set->answer_date; |
| 101 | $envir{formattedAnswerDate} = formatDateTime($envir{answerDate}); |
105 | $envir{formattedAnswerDate} = formatDateTime($envir{answerDate}, $ce->{siteDefaults}{timezone}); |
| 102 | $envir{numOfAttempts} = ($problem->num_correct || 0) + ($problem->num_incorrect || 0); |
106 | $envir{numOfAttempts} = ($problem->num_correct || 0) + ($problem->num_incorrect || 0); |
| 103 | $envir{problemValue} = $problem->value; |
107 | $envir{problemValue} = $problem->value; |
| 104 | $envir{sessionKey} = $key; |
108 | $envir{sessionKey} = $key; |
| 105 | $envir{courseName} = $ce->{courseName}; |
109 | $envir{courseName} = $ce->{courseName}; |
| 106 | |
110 | |
| … | |
… | |
| 129 | $envir{externalLaTeXPath} = $ce->{externalPrograms}->{latex}; |
133 | $envir{externalLaTeXPath} = $ce->{externalPrograms}->{latex}; |
| 130 | $envir{externalDvipngPath} = $ce->{externalPrograms}->{dvipng}; |
134 | $envir{externalDvipngPath} = $ce->{externalPrograms}->{dvipng}; |
| 131 | $envir{externalGif2EpsPath} = $ce->{externalPrograms}->{gif2eps}; |
135 | $envir{externalGif2EpsPath} = $ce->{externalPrograms}->{gif2eps}; |
| 132 | $envir{externalPng2EpsPath} = $ce->{externalPrograms}->{png2eps}; |
136 | $envir{externalPng2EpsPath} = $ce->{externalPrograms}->{png2eps}; |
| 133 | $envir{externalGif2PngPath} = $ce->{externalPrograms}->{gif2png}; |
137 | $envir{externalGif2PngPath} = $ce->{externalPrograms}->{gif2png}; |
| 134 | |
138 | $envir{externalCheckUrl} = $ce->{externalPrograms}->{checkurl}; |
| 135 | # Directories and URLs |
139 | # Directories and URLs |
| 136 | # REMOVED: courseName |
140 | # REMOVED: courseName |
| 137 | # ADDED: dvipngTempDir |
141 | # ADDED: dvipngTempDir |
| 138 | # ADDED: jsMathURL |
142 | # ADDED: jsMathURL |
| 139 | # ADDED: asciimathURL |
143 | # ADDED: asciimathURL |
|
|
144 | # ADDED: macrosPath |
|
|
145 | # REMOVED: macrosDirectory, courseScriptsDirectory |
|
|
146 | # ADDED: LaTeXMathML |
| 140 | |
147 | |
| 141 | $envir{cgiDirectory} = undef; |
148 | $envir{cgiDirectory} = undef; |
| 142 | $envir{cgiURL} = undef; |
149 | $envir{cgiURL} = undef; |
| 143 | $envir{classDirectory} = undef; |
150 | $envir{classDirectory} = undef; |
| 144 | $envir{courseScriptsDirectory} = $ce->{pg}->{directories}->{macros}."/"; |
151 | $envir{macrosPath} = $ce->{pg}->{directories}{macrosPath}; |
|
|
152 | $envir{appletPath} = $ce->{pg}->{directories}{appletPath}; |
|
|
153 | $envir{pgDirectories} = $ce->{pg}->{directories}; |
| 145 | $envir{htmlDirectory} = $ce->{courseDirs}->{html}."/"; |
154 | $envir{htmlDirectory} = $ce->{courseDirs}->{html}."/"; |
| 146 | $envir{htmlURL} = $ce->{courseURLs}->{html}."/"; |
155 | $envir{htmlURL} = $ce->{courseURLs}->{html}."/"; |
| 147 | $envir{macroDirectory} = $ce->{courseDirs}->{macros}."/"; |
|
|
| 148 | $envir{templateDirectory} = $ce->{courseDirs}->{templates}."/"; |
156 | $envir{templateDirectory} = $ce->{courseDirs}->{templates}."/"; |
| 149 | $envir{tempDirectory} = $ce->{courseDirs}->{html_temp}."/"; |
157 | $envir{tempDirectory} = $ce->{courseDirs}->{html_temp}."/"; |
| 150 | $envir{tempURL} = $ce->{courseURLs}->{html_temp}."/"; |
158 | $envir{tempURL} = $ce->{courseURLs}->{html_temp}."/"; |
| 151 | $envir{scriptDirectory} = undef; |
159 | $envir{scriptDirectory} = undef; |
| 152 | $envir{webworkDocsURL} = $ce->{webworkURLs}->{docs}."/"; |
160 | $envir{webworkDocsURL} = $ce->{webworkURLs}->{docs}."/"; |
| 153 | $envir{localHelpURL} = $ce->{webworkURLs}->{local_help}."/"; |
161 | $envir{localHelpURL} = $ce->{webworkURLs}->{local_help}."/"; |
| 154 | $envir{jsMathURL} = $ce->{webworkURLs}->{jsMath}; |
162 | $envir{jsMathURL} = $ce->{webworkURLs}->{jsMath}; |
| 155 | $envir{asciimathURL} = $ce->{webworkURLs}->{asciimath}; |
163 | $envir{asciimathURL} = $ce->{webworkURLs}->{asciimath}; |
|
|
164 | $envir{LaTeXMathMLURL} = $ce->{webworkURLs}->{LaTeXMathML}; |
|
|
165 | $envir{server_root_url} = $ce->{apache_root_url}; |
| 156 | |
166 | |
| 157 | # Information for sending mail |
167 | # Information for sending mail |
| 158 | |
168 | |
| 159 | $envir{mailSmtpServer} = $ce->{mail}->{smtpServer}; |
169 | $envir{mailSmtpServer} = $ce->{mail}->{smtpServer}; |
| 160 | $envir{mailSmtpSender} = $ce->{mail}->{smtpSender}; |
170 | $envir{mailSmtpSender} = $ce->{mail}->{smtpSender}; |
| … | |
… | |
| 165 | my $ansEvalDefaults = $ce->{pg}->{ansEvalDefaults}; |
175 | my $ansEvalDefaults = $ce->{pg}->{ansEvalDefaults}; |
| 166 | $envir{$_} = $ansEvalDefaults->{$_} foreach (keys %$ansEvalDefaults); |
176 | $envir{$_} = $ansEvalDefaults->{$_} foreach (keys %$ansEvalDefaults); |
| 167 | |
177 | |
| 168 | # ---------------------------------------------------------------------- |
178 | # ---------------------------------------------------------------------- |
| 169 | |
179 | |
| 170 | my $basename = "equation-$envir{psvn}.$envir{probNum}"; |
180 | # ADDED: ImageGenerator for images mode |
| 171 | $basename .= ".$envir{problemSeed}" if $envir{problemSeed}; |
181 | if (defined $extras->{image_generator}) { |
| 172 | |
182 | #$envir{imagegen} = $extras->{image_generator}; |
| 173 | # Object for generating equation images |
183 | # only allow access to the add() method |
| 174 | $envir{imagegen} = WeBWorK::PG::ImageGenerator->new( |
184 | $envir{imagegen} = new WeBWorK::Utils::RestrictedClosureClass($extras->{image_generator}, "add"); |
| 175 | tempDir => $ce->{webworkDirs}->{tmp}, # global temp dir |
185 | } |
| 176 | latex => $envir{externalLaTeXPath}, |
186 | |
| 177 | dvipng => $envir{externalDvipngPath}, |
187 | if (defined $extras->{mailer}) { |
| 178 | useCache => 1, |
188 | #my $rmailer = new WeBWorK::Utils::RestrictedClosureClass($extras->{mailer}, |
| 179 | cacheDir => $ce->{webworkDirs}->{equationCache}, |
189 | # qw/Open SendEnc Close Cancel skipped_recipients error error_msg/); |
| 180 | cacheURL => $ce->{webworkURLs}->{equationCache}, |
190 | #my $safe_hole = new Safe::Hole {}; |
| 181 | cacheDB => $ce->{webworkFiles}->{equationCacheDB}, |
191 | #$envir{mailer} = $safe_hole->wrap($rmailer); |
| 182 | ); |
192 | $envir{mailer} = new WeBWorK::Utils::RestrictedClosureClass($extras->{mailer}, "add_message"); |
|
|
193 | } |
|
|
194 | |
|
|
195 | # ADDED: jsMath options |
|
|
196 | $envir{jsMath} = {%{$ce->{pg}{displayModeOptions}{jsMath}}}; |
| 183 | |
197 | |
| 184 | # Other things... |
198 | # Other things... |
| 185 | $envir{QUIZ_PREFIX} = $options->{QUIZ_PREFIX}; # used by quizzes |
199 | $envir{QUIZ_PREFIX} = $options->{QUIZ_PREFIX}; # used by quizzes |
| 186 | $envir{PROBLEM_GRADER_TO_USE} = $ce->{pg}->{options}->{grader}; |
200 | $envir{PROBLEM_GRADER_TO_USE} = $ce->{pg}->{options}->{grader}; |
| 187 | $envir{PRINT_FILE_NAMES_FOR} = $ce->{pg}->{specialPGEnvironmentVars}->{PRINT_FILE_NAMES_FOR}; |
201 | $envir{PRINT_FILE_NAMES_FOR} = $ce->{pg}->{specialPGEnvironmentVars}->{PRINT_FILE_NAMES_FOR}; |
|
|
202 | |
|
|
203 | # ADDED: __files__ |
|
|
204 | # an array for mapping (eval nnn) to filenames in error messages |
|
|
205 | $envir{__files__} = { |
|
|
206 | root => $ce->{webworkDirs}{root}, # used to shorten filenames |
|
|
207 | pg => $ce->{pg}{directories}{root}, # ditto |
|
|
208 | tmpl => $ce->{courseDirs}{templates}, # ditto |
|
|
209 | }; |
| 188 | |
210 | |
| 189 | # variables for interpreting capa problems and other things to be |
211 | # variables for interpreting capa problems and other things to be |
| 190 | # seen in a pg file |
212 | # seen in a pg file |
| 191 | my $specialPGEnvironmentVarHash = $ce->{pg}->{specialPGEnvironmentVars}; |
213 | my $specialPGEnvironmentVarHash = $ce->{pg}->{specialPGEnvironmentVars}; |
| 192 | for my $SPGEV (keys %{$specialPGEnvironmentVarHash}) { |
214 | for my $SPGEV (keys %{$specialPGEnvironmentVarHash}) { |