[system] / branches / rel-2-4-patches / webwork-modperl / lib / WeBWorK / PG.pm Repository:
ViewVC logotype

Diff of /branches/rel-2-4-patches/webwork-modperl/lib/WeBWorK/PG.pm

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

Revision 1703 Revision 2983
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.46 2003/12/09 01:12:30 sh002i Exp $ 4# $CVSHeader: webwork-modperl/lib/WeBWorK/PG.pm,v 1.58 2004/09/13 19:29:55 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.
25 25
26use strict; 26use strict;
27use warnings; 27use warnings;
28use WeBWorK::PG::ImageGenerator; 28use WeBWorK::PG::ImageGenerator;
29use WeBWorK::Utils qw(runtime_use formatDateTime makeTempDirectory); 29use WeBWorK::Utils qw(runtime_use formatDateTime makeTempDirectory);
30
31use 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 asciimath => "HTML_asciimath",
39};
30 40
31sub new { 41sub new {
32 shift; # throw away invocant -- we don't need it 42 shift; # throw away invocant -- we don't need it
33 my ($ce, $user, $key, $set, $problem, $psvn, $formFields, 43 my ($ce, $user, $key, $set, $problem, $psvn, $formFields,
34 $translationOptions) = @_; 44 $translationOptions) = @_;
60 # PG environment variables 70 # PG environment variables
61 # from docs/pglanguage/pgreference/environmentvariables as of 06/25/2002 71 # from docs/pglanguage/pgreference/environmentvariables as of 06/25/2002
62 # any changes are noted by "ADDED:" or "REMOVED:" 72 # any changes are noted by "ADDED:" or "REMOVED:"
63 73
64 # Vital state information 74 # Vital state information
65 # ADDED: displayHintsQ, displaySolutionsQ, refreshMath2img, 75 # ADDED: displayModeFailover, displayHintsQ, displaySolutionsQ,
66 # texDisposition 76 # refreshMath2img, texDisposition
67 77
68 $envir{psvn} = $set->psvn; 78 $envir{psvn} = $set->psvn;
69 $envir{psvnNumber} = $envir{psvn}; 79 $envir{psvnNumber} = $envir{psvn};
70 $envir{probNum} = $problem->problem_id; 80 $envir{probNum} = $problem->problem_id;
71 $envir{questionNumber} = $envir{probNum}; 81 $envir{questionNumber} = $envir{probNum};
72 $envir{fileName} = $problem->source_file; 82 $envir{fileName} = $problem->source_file;
73 $envir{probFileName} = $envir{fileName}; 83 $envir{probFileName} = $envir{fileName};
74 $envir{problemSeed} = $problem->problem_seed; 84 $envir{problemSeed} = $problem->problem_seed;
75 $envir{displayMode} = translateDisplayModeNames($options->{displayMode}); 85 $envir{displayMode} = translateDisplayModeNames($options->{displayMode});
76 $envir{languageMode} = $envir{displayMode}; 86 $envir{languageMode} = $envir{displayMode};
77 $envir{outputMode} = $envir{displayMode}; 87 $envir{outputMode} = $envir{displayMode};
78 $envir{displayHintsQ} = $options->{showHints}; 88 $envir{displayHintsQ} = $options->{showHints};
79 $envir{displaySolutionsQ} = $options->{showSolutions}; 89 $envir{displaySolutionsQ} = $options->{showSolutions};
80 $envir{texDisposition} = "pdf"; # in webwork2, we use pdflatex 90 $envir{texDisposition} = "pdf"; # in webwork2, we use pdflatex
81 91
82 # Problem Information 92 # Problem Information
83 # ADDED: courseName, formatedDueDate 93 # ADDED: courseName, formatedDueDate
84 94
85 $envir{openDate} = $set->open_date; 95 $envir{openDate} = $set->open_date;
86 $envir{formattedOpenDate} = formatDateTime($envir{openDate}); 96 $envir{formattedOpenDate} = formatDateTime($envir{openDate}, $ce->{siteDefaults}{timezone});
87 $envir{dueDate} = $set->due_date; 97 $envir{dueDate} = $set->due_date;
88 $envir{formattedDueDate} = formatDateTime($envir{dueDate}); 98 $envir{formattedDueDate} = formatDateTime($envir{dueDate}, $ce->{siteDefaults}{timezone});
89 $envir{formatedDueDate} = $envir{formattedDueDate}; # typo in many header files 99 $envir{formatedDueDate} = $envir{formattedDueDate}; # typo in many header files
90 $envir{answerDate} = $set->answer_date; 100 $envir{answerDate} = $set->answer_date;
91 $envir{formattedAnswerDate} = formatDateTime($envir{answerDate}); 101 $envir{formattedAnswerDate} = formatDateTime($envir{answerDate}, $ce->{siteDefaults}{timezone});
92 $envir{numOfAttempts} = ($problem->num_correct || 0) + ($problem->num_incorrect || 0); 102 $envir{numOfAttempts} = ($problem->num_correct || 0) + ($problem->num_incorrect || 0);
93 $envir{problemValue} = $problem->value; 103 $envir{problemValue} = $problem->value;
94 $envir{sessionKey} = $key; 104 $envir{sessionKey} = $key;
95 $envir{courseName} = $ce->{courseName}; 105 $envir{courseName} = $ce->{courseName};
96 106
123 $envir{externalGif2PngPath} = $ce->{externalPrograms}->{gif2png}; 133 $envir{externalGif2PngPath} = $ce->{externalPrograms}->{gif2png};
124 134
125 # Directories and URLs 135 # Directories and URLs
126 # REMOVED: courseName 136 # REMOVED: courseName
127 # ADDED: dvipngTempDir 137 # ADDED: dvipngTempDir
138 # ADDED: jsMathURL
139 # ADDED: asciimathURL
128 140
129 $envir{cgiDirectory} = undef; 141 $envir{cgiDirectory} = undef;
130 $envir{cgiURL} = undef; 142 $envir{cgiURL} = undef;
131 $envir{classDirectory} = undef; 143 $envir{classDirectory} = undef;
132 $envir{courseScriptsDirectory} = $ce->{pg}->{directories}->{macros}."/"; 144 $envir{courseScriptsDirectory} = $ce->{pg}->{directories}->{macros}."/";
136 $envir{templateDirectory} = $ce->{courseDirs}->{templates}."/"; 148 $envir{templateDirectory} = $ce->{courseDirs}->{templates}."/";
137 $envir{tempDirectory} = $ce->{courseDirs}->{html_temp}."/"; 149 $envir{tempDirectory} = $ce->{courseDirs}->{html_temp}."/";
138 $envir{tempURL} = $ce->{courseURLs}->{html_temp}."/"; 150 $envir{tempURL} = $ce->{courseURLs}->{html_temp}."/";
139 $envir{scriptDirectory} = undef; 151 $envir{scriptDirectory} = undef;
140 $envir{webworkDocsURL} = $ce->{webworkURLs}->{docs}."/"; 152 $envir{webworkDocsURL} = $ce->{webworkURLs}->{docs}."/";
153 $envir{localHelpURL} = $ce->{webworkURLs}->{local_help}."/";
154 $envir{jsMathURL} = $ce->{webworkURLs}->{jsMath};
155 $envir{asciimathURL} = $ce->{webworkURLs}->{asciimath};
141 156
142 # Information for sending mail 157 # Information for sending mail
143 158
144 $envir{mailSmtpServer} = $ce->{mail}->{smtpServer}; 159 $envir{mailSmtpServer} = $ce->{mail}->{smtpServer};
145 $envir{mailSmtpSender} = $ce->{mail}->{smtpSender}; 160 $envir{mailSmtpSender} = $ce->{mail}->{smtpSender};
152 167
153 # ---------------------------------------------------------------------- 168 # ----------------------------------------------------------------------
154 169
155 my $basename = "equation-$envir{psvn}.$envir{probNum}"; 170 my $basename = "equation-$envir{psvn}.$envir{probNum}";
156 $basename .= ".$envir{problemSeed}" if $envir{problemSeed}; 171 $basename .= ".$envir{problemSeed}" if $envir{problemSeed};
157 172
173 # to make grabbing these options easier, we'll pull them out now...
174 my %imagesModeOptions = %{$ce->{pg}->{displayModeOptions}->{images}};
175
158 # Object for generating equation images 176 # Object for generating equation images
159 $envir{imagegen} = WeBWorK::PG::ImageGenerator->new( 177 $envir{imagegen} = WeBWorK::PG::ImageGenerator->new(
160 tempDir => $ce->{webworkDirs}->{tmp}, # global temp dir 178 tempDir => $ce->{webworkDirs}->{tmp}, # global temp dir
161 latex => $envir{externalLaTeXPath}, 179 latex => $envir{externalLaTeXPath},
162 dvipng => $envir{externalDvipngPath}, 180 dvipng => $envir{externalDvipngPath},
163 useCache => 1, 181 useCache => 1,
164 cacheDir => $ce->{webworkDirs}->{equationCache}, 182 cacheDir => $ce->{webworkDirs}->{equationCache},
165 cacheURL => $ce->{webworkURLs}->{equationCache}, 183 cacheURL => $ce->{webworkURLs}->{equationCache},
166 cacheDB => $ce->{webworkFiles}->{equationCacheDB}, 184 cacheDB => $ce->{webworkFiles}->{equationCacheDB},
185 useMarkers => ($imagesModeOptions{dvipng_align} && $imagesModeOptions{dvipng_align} eq 'mysql'),
186 dvipng_align => $imagesModeOptions{dvipng_align},
187 dvipng_depth_db => $imagesModeOptions{dvipng_depth_db},
167 ); 188 );
189
190 # ADDED: jsMath options
191 $envir{jsMath} = {%{$ce->{pg}{displayModeOptions}{jsMath}}};
168 192
169 # Other things... 193 # Other things...
170 $envir{QUIZ_PREFIX} = $options->{QUIZ_PREFIX}; # used by quizzes 194 $envir{QUIZ_PREFIX} = $options->{QUIZ_PREFIX}; # used by quizzes
171 $envir{PROBLEM_GRADER_TO_USE} = $ce->{pg}->{options}->{grader}; 195 $envir{PROBLEM_GRADER_TO_USE} = $ce->{pg}->{options}->{grader};
172 $envir{PRINT_FILE_NAMES_FOR} = $ce->{pg}->{specialPGEnvironmentVars}->{PRINT_FILE_NAMES_FOR}; 196 $envir{PRINT_FILE_NAMES_FOR} = $ce->{pg}->{specialPGEnvironmentVars}->{PRINT_FILE_NAMES_FOR};
197
198 # ADDED: __files__
199 # an array for mapping (eval nnn) to filenames in error messages
200 $envir{__files__} = {
201 root => $ce->{webworkDirs}{root}, # used to shorten filenames
202 pg => $ce->{pg}{directories}{root}, # ditto
203 tmpl => $ce->{courseDirs}{templates}, # ditto
204 };
173 205
174 # variables for interpreting capa problems. 206 # variables for interpreting capa problems and other things to be
175 $envir{CAPA_Tools} = $ce->{pg}->{specialPGEnvironmentVars}->{CAPA_Tools}; 207 # seen in a pg file
176 $envir{CAPA_MCTools} = $ce->{pg}->{specialPGEnvironmentVars}->{CAPA_MCTools}; 208 my $specialPGEnvironmentVarHash = $ce->{pg}->{specialPGEnvironmentVars};
177 $envir{CAPA_Graphics_URL} = $ce->{pg}->{specialPGEnvironmentVars}->{CAPA_Graphics_URL}; 209 for my $SPGEV (keys %{$specialPGEnvironmentVarHash}) {
178 $envir{CAPA_GraphicsDirectory} = $ce->{pg}->{specialPGEnvironmentVars}->{CAPA_GraphicsDirectory}; 210 $envir{$SPGEV} = $specialPGEnvironmentVarHash->{$SPGEV};
211 }
179 212
180 return \%envir; 213 return \%envir;
181} 214}
182 215
183sub translateDisplayModeNames($) { 216sub translateDisplayModeNames($) {
184 my $name = shift; 217 my $name = shift;
185 return { 218 return DISPLAY_MODES()->{$name};
186 tex => "TeX",
187 plainText => "HTML",
188 formattedText => "HTML_tth",
189 images => "HTML_dpng", # "HTML_img",
190 }->{$name};
191} 219}
192 220
193sub oldSafetyFilter { 221sub oldSafetyFilter {
194 my $answer = shift; # accepts one answer and checks it 222 my $answer = shift; # accepts one answer and checks it
195 my $submittedAnswer = $answer; 223 my $submittedAnswer = $answer;

Legend:
Removed from v.1703  
changed lines
  Added in v.2983

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9