| 1 | ################################################################################ |
1 | ################################################################################ |
| 2 | # WeBWorK mod_perl (c) 2000-2002 WeBWorK Project |
2 | # WeBWorK Online Homework Delivery System |
| 3 | # $Id$ |
3 | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
|
|
4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Problem.pm,v 1.133 2004/05/23 01:17:42 gage Exp $ |
|
|
5 | # |
|
|
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 |
|
|
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. |
|
|
10 | # |
|
|
11 | # This program is distributed in the hope that it will be useful, but WITHOUT |
|
|
12 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
|
13 | # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the |
|
|
14 | # Artistic License for more details. |
| 4 | ################################################################################ |
15 | ################################################################################ |
| 5 | |
16 | |
| 6 | package WeBWorK::ContentGenerator::Problem; |
17 | package WeBWorK::ContentGenerator::Problem; |
| 7 | use base qw(WeBWorK::ContentGenerator); |
18 | use base qw(WeBWorK::ContentGenerator); |
| 8 | |
19 | |
| 9 | =head1 NAME |
20 | =head1 NAME |
| 10 | |
21 | |
| 11 | WeBWorK::ContentGenerator::Problem - Allow a student to interact with a problem. |
22 | WeBWorK::ContentGenerator::Problem - Allow a student to interact with a problem. |
| 12 | |
23 | |
| 13 | =cut |
24 | =cut |
| 14 | |
25 | |
| 15 | use strict; |
26 | use strict; |
| 16 | use warnings; |
27 | use warnings; |
| 17 | use CGI qw(); |
28 | use CGI qw(); |
| 18 | use File::Temp qw(tempdir); |
29 | use File::Path qw(rmtree); |
| 19 | use WeBWorK::Form; |
30 | use WeBWorK::Form; |
| 20 | use WeBWorK::PG; |
31 | use WeBWorK::PG; |
|
|
32 | use WeBWorK::PG::ImageGenerator; |
| 21 | use WeBWorK::PG::IO; |
33 | use WeBWorK::PG::IO; |
| 22 | use WeBWorK::Utils qw(writeLog encodeAnswers decodeAnswers ref2string); |
34 | use WeBWorK::Utils qw(writeLog writeCourseLog encodeAnswers decodeAnswers ref2string makeTempDirectory); |
|
|
35 | use WeBWorK::DB::Utils qw(global2user user2global findDefaults); |
|
|
36 | use WeBWorK::Timing; |
|
|
37 | |
|
|
38 | use WeBWorK::Utils::Tasks qw(fake_set fake_problem); |
| 23 | |
39 | |
| 24 | ############################################################ |
40 | ############################################################ |
| 25 | # |
41 | # |
| 26 | # user |
42 | # user |
| 27 | # effectiveUser |
43 | # effectiveUser |
| … | |
… | |
| 37 | # |
53 | # |
| 38 | # redisplay - name of the "Redisplay Problem" button |
54 | # redisplay - name of the "Redisplay Problem" button |
| 39 | # submitAnswers - name of "Submit Answers" button |
55 | # submitAnswers - name of "Submit Answers" button |
| 40 | # checkAnswers - name of the "Check Answers" button |
56 | # checkAnswers - name of the "Check Answers" button |
| 41 | # previewAnswers - name of the "Preview Answers" button |
57 | # previewAnswers - name of the "Preview Answers" button |
|
|
58 | # |
|
|
59 | # FIXME: this table is heinously out of date |
| 42 | # |
60 | # |
| 43 | ############################################################ |
61 | ############################################################ |
| 44 | |
62 | |
|
|
63 | # FIXME: what is this? |
|
|
64 | sub templateName { |
|
|
65 | "problem"; |
|
|
66 | } |
|
|
67 | |
| 45 | sub pre_header_initialize { |
68 | sub pre_header_initialize { |
| 46 | my ($self, $setName, $problemNumber) = @_; |
69 | my ($self) = @_; |
| 47 | my $r = $self->{r}; |
70 | my $r = $self->r; |
| 48 | my $courseEnv = $self->{ce}; |
71 | my $ce = $r->ce; |
| 49 | my $db = $self->{db}; |
72 | my $db = $r->db; |
|
|
73 | my $urlpath = $r->urlpath; |
|
|
74 | |
|
|
75 | my $setName = $urlpath->arg("setID"); |
|
|
76 | my $problemNumber = $r->urlpath->arg("problemID"); |
| 50 | my $userName = $r->param('user'); |
77 | my $userName = $r->param('user'); |
| 51 | my $effectiveUserName = $r->param('effectiveUser'); |
78 | my $effectiveUserName = $r->param('effectiveUser'); |
|
|
79 | my $key = $r->param('key'); |
| 52 | |
80 | |
| 53 | my $user = $db->getUser($userName); |
81 | my $user = $db->getUser($userName); # checked |
|
|
82 | die "record for user $userName (real user) does not exist." |
|
|
83 | unless defined $user; |
|
|
84 | |
| 54 | my $effectiveUser = $db->getUser($effectiveUserName); |
85 | my $effectiveUser = $db->getUser($effectiveUserName); # checked |
|
|
86 | die "record for user $effectiveUserName (effective user) does not exist." |
|
|
87 | unless defined $effectiveUser; |
|
|
88 | |
|
|
89 | my $PermissionLevel = $db->getPermissionLevel($userName); # checked |
|
|
90 | die "permission level record for user $userName does not exist (but the user does? odd...)" |
|
|
91 | unless defined $PermissionLevel; |
|
|
92 | my $permissionLevel = $PermissionLevel->permission; |
|
|
93 | |
|
|
94 | # obtain the merged set for $effectiveUser |
| 55 | my $set = $db->getGlobalUserSet($effectiveUserName, $setName); |
95 | my $set = $db->getMergedSet($effectiveUserName, $setName); # checked |
|
|
96 | |
|
|
97 | # obtain the merged problem for $effectiveUser |
| 56 | my $problem = $db->getGlobalUserProblem($effectiveUserName, $setName, $problemNumber); |
98 | my $problem = $db->getMergedProblem($effectiveUserName, $setName, $problemNumber); # checked |
| 57 | my $psvn = $set->psvn(); |
99 | |
| 58 | my $permissionLevel = $db->getPermissionLevel($userName)->permission(); |
100 | my $editMode = $r->param("editMode"); |
| 59 | |
101 | |
|
|
102 | if ($permissionLevel > 0) { |
|
|
103 | # professors are allowed to fabricate sets and problems not |
|
|
104 | # assigned to them (or anyone). this allows them to use the |
|
|
105 | # editor to |
|
|
106 | |
|
|
107 | # if that is not yet defined obtain the global set, convert |
|
|
108 | # it to a user set, and add fake user data |
|
|
109 | unless (defined $set) { |
|
|
110 | my $userSetClass = $db->{set_user}->{record}; |
|
|
111 | my $globalSet = $db->getGlobalSet($setName); # checked |
|
|
112 | # if the global set doesn't exist either, bail! |
|
|
113 | if(not defined $globalSet) { |
|
|
114 | $set = fake_set($db); |
|
|
115 | } else { |
|
|
116 | $set = global2user($userSetClass, $globalSet); |
|
|
117 | $set->psvn(0); |
|
|
118 | |
|
|
119 | # FIXME: This is a temporary fix to fill in the database |
|
|
120 | # We want the published field to contain either 1 or 0 so if it has not been set to 0, default to 1 |
|
|
121 | # this will fill in all the empty fields but not change anything that has been specifically set to 1 or 0 |
|
|
122 | $globalSet->published("1") unless $globalSet->published eq "0"; |
|
|
123 | $db->putGlobalSet($globalSet); |
|
|
124 | } |
|
|
125 | } |
|
|
126 | |
|
|
127 | # if that is not yet defined obtain the global problem, |
|
|
128 | # convert it to a user problem, and add fake user data |
|
|
129 | unless (defined $problem) { |
|
|
130 | my $userProblemClass = $db->{problem_user}->{record}; |
|
|
131 | my $globalProblem = $db->getGlobalProblem($setName, $problemNumber); # checked |
|
|
132 | # if the global problem doesn't exist either, bail! |
|
|
133 | if(not defined $globalProblem) { |
|
|
134 | my $sourceFilePath = $r->param("sourceFilePath"); |
|
|
135 | die "Problem $problemNumber in set $setName does not exist" |
|
|
136 | unless defined $sourceFilePath; |
|
|
137 | $problem = fake_problem($db); |
|
|
138 | $problem->problem_id(1); |
|
|
139 | $problem->source_file($sourceFilePath); |
|
|
140 | $problem->user_id($effectiveUserName); |
|
|
141 | } else { |
|
|
142 | $problem = global2user($userProblemClass, $globalProblem); |
|
|
143 | $problem->user_id($effectiveUserName); |
|
|
144 | $problem->problem_seed(0); |
|
|
145 | $problem->status(0); |
|
|
146 | $problem->attempted(0); |
|
|
147 | $problem->last_answer(""); |
|
|
148 | $problem->num_correct(0); |
|
|
149 | $problem->num_incorrect(0); |
|
|
150 | } |
|
|
151 | } |
|
|
152 | |
|
|
153 | # now we're sure we have valid UserSet and UserProblem objects |
|
|
154 | # yay! |
|
|
155 | |
|
|
156 | # now deal with possible editor overrides: |
|
|
157 | |
|
|
158 | # if the caller is asking to override the source file, and |
|
|
159 | # editMode calls for a temporary file, do so |
|
|
160 | my $sourceFilePath = $r->param("sourceFilePath"); |
|
|
161 | if (defined $sourceFilePath and |
|
|
162 | (not defined $editMode or $editMode eq "temporaryFile")) { |
|
|
163 | $problem->source_file($sourceFilePath); |
|
|
164 | } |
|
|
165 | |
|
|
166 | # if the caller is asking to override the problem seed, do so |
|
|
167 | my $problemSeed = $r->param("problemSeed"); |
|
|
168 | if (defined $problemSeed) { |
|
|
169 | $problem->problem_seed($problemSeed); |
|
|
170 | } |
|
|
171 | |
|
|
172 | my $published = ($set->published) ? "Published" : "Unpublished"; |
|
|
173 | $self->addmessage(CGI::p("This set is " . CGI::font({class=>$published}, $published))); |
|
|
174 | } else { |
|
|
175 | |
|
|
176 | $self->addmessage(CGI::div({class=>"ResultsWithError"}, CGI::p("This problem will not count towards your grade."))) unless $problem->value;; |
|
|
177 | # students can't view problems not assigned to them |
|
|
178 | |
|
|
179 | # A set is valid if it exists and if it is either published or the user is privileged. |
|
|
180 | $self->{invalidSet} = (grep /$setName/, $db->listUserSets($effectiveUserName)) == 0 || !($set->published || $permissionLevel->permission > 0); # this is redundant because of the above if |
|
|
181 | $self->{invalidProblem} = (grep /$problemNumber/, $db->listUserProblems($effectiveUserName, $setName)) == 0 || !($set->published || $permissionLevel->permission > 0);; |
|
|
182 | |
|
|
183 | } |
|
|
184 | |
| 60 | $self->{userName} = $userName; |
185 | $self->{userName} = $userName; |
|
|
186 | $self->{effectiveUserName} = $effectiveUserName; |
| 61 | $self->{user} = $user; |
187 | $self->{user} = $user; |
| 62 | $self->{effectiveUser} = $effectiveUser; |
188 | $self->{effectiveUser} = $effectiveUser; |
| 63 | $self->{set} = $set; |
|
|
| 64 | $self->{problem} = $problem; |
|
|
| 65 | $self->{permissionLevel} = $permissionLevel; |
189 | $self->{permissionLevel} = $permissionLevel; |
|
|
190 | $self->{set} = $set; |
|
|
191 | $self->{problem} = $problem; |
|
|
192 | $self->{editMode} = $editMode; |
| 66 | |
193 | |
| 67 | ##### form processing ##### |
194 | ##### form processing ##### |
| 68 | |
195 | |
| 69 | # set options from form fields (see comment at top of file for names) |
196 | # set options from form fields (see comment at top of file for names) |
| 70 | my $displayMode = $r->param("displayMode") || $courseEnv->{pg}->{options}->{displayMode}; |
197 | my $displayMode = $r->param("displayMode") || $ce->{pg}->{options}->{displayMode}; |
| 71 | my $redisplay = $r->param("redisplay"); |
198 | my $redisplay = $r->param("redisplay"); |
| 72 | my $submitAnswers = $r->param("submitAnswers"); |
199 | my $submitAnswers = $r->param("submitAnswers"); |
| 73 | my $checkAnswers = $r->param("checkAnswers"); |
200 | my $checkAnswers = $r->param("checkAnswers"); |
| 74 | my $previewAnswers = $r->param("previewAnswers"); |
201 | my $previewAnswers = $r->param("previewAnswers"); |
| 75 | |
202 | |
| 76 | # coerce form fields into CGI::Vars format |
|
|
| 77 | my $formFields = { WeBWorK::Form->new_from_paramable($r)->Vars }; |
203 | my $formFields = { WeBWorK::Form->new_from_paramable($r)->Vars }; |
| 78 | |
204 | |
| 79 | $self->{displayMode} = $displayMode; |
205 | $self->{displayMode} = $displayMode; |
| 80 | $self->{redisplay} = $redisplay; |
206 | $self->{redisplay} = $redisplay; |
| 81 | $self->{submitAnswers} = $submitAnswers; |
207 | $self->{submitAnswers} = $submitAnswers; |
| 82 | $self->{checkAnswers} = $checkAnswers; |
208 | $self->{checkAnswers} = $checkAnswers; |
| 83 | $self->{previewAnswers} = $previewAnswers; |
209 | $self->{previewAnswers} = $previewAnswers; |
| 84 | $self->{formFields} = $formFields; |
210 | $self->{formFields} = $formFields; |
|
|
211 | |
|
|
212 | # get result and send to message |
|
|
213 | my $success = $r->param("sucess"); |
|
|
214 | my $failure = $r->param("failure"); |
|
|
215 | $self->addmessage(CGI::div({class=>"ResultsWithError"}, CGI::p($failure))) if $failure; |
|
|
216 | $self->addmessage(CGI::div({class=>"ResultsWithoutError"}, CGI::p($success))) if $success; |
|
|
217 | |
|
|
218 | # now that we've set all the necessary variables quit out if the set or problem is invalid |
|
|
219 | return if $self->{invalidSet} || $self->{invalidProblem}; |
| 85 | |
220 | |
| 86 | ##### permissions ##### |
221 | ##### permissions ##### |
| 87 | |
222 | |
| 88 | # are we allowed to view this problem? |
223 | # are we allowed to view this problem? |
| 89 | $self->{isOpen} = time >= $set->open_date || $permissionLevel > 0; |
224 | $self->{isOpen} = time >= $set->open_date || $permissionLevel > 0; |
| 90 | return unless $self->{isOpen}; |
225 | return unless $self->{isOpen}; |
| 91 | |
226 | |
| 92 | # what does the user want to do? |
227 | # what does the user want to do? |
| 93 | my %want = ( |
228 | my %want = ( |
| 94 | showOldAnswers => $r->param("showOldAnswers") || $courseEnv->{pg}->{options}->{showOldAnswers}, |
229 | showOldAnswers => $r->param("showOldAnswers") || $ce->{pg}->{options}->{showOldAnswers}, |
| 95 | showCorrectAnswers => $r->param("showCorrectAnswers") || $courseEnv->{pg}->{options}->{showCorrectAnswers}, |
230 | showCorrectAnswers => $r->param("showCorrectAnswers") || $ce->{pg}->{options}->{showCorrectAnswers}, |
| 96 | showHints => $r->param("showHints") || $courseEnv->{pg}->{options}->{showHints}, |
231 | showHints => $r->param("showHints") || $ce->{pg}->{options}->{showHints}, |
| 97 | showSolutions => $r->param("showSolutions") || $courseEnv->{pg}->{options}->{showSolutions}, |
232 | showSolutions => $r->param("showSolutions") || $ce->{pg}->{options}->{showSolutions}, |
| 98 | recordAnswers => $submitAnswers, |
233 | recordAnswers => $submitAnswers, |
| 99 | checkAnswers => $checkAnswers, |
234 | checkAnswers => $checkAnswers, |
| 100 | ); |
235 | ); |
| 101 | |
236 | |
| 102 | # are certain options enforced? |
237 | # are certain options enforced? |
| … | |
… | |
| 119 | $problem->max_attempts, $problem->num_correct + $problem->num_incorrect + 1), |
254 | $problem->max_attempts, $problem->num_correct + $problem->num_incorrect + 1), |
| 120 | # attempts=num_correct+num_incorrect+1, as this happens before updating $problem |
255 | # attempts=num_correct+num_incorrect+1, as this happens before updating $problem |
| 121 | checkAnswers => canCheckAnswers($permissionLevel, $set->answer_date), |
256 | checkAnswers => canCheckAnswers($permissionLevel, $set->answer_date), |
| 122 | ); |
257 | ); |
| 123 | |
258 | |
|
|
259 | # more complicated logic for showing check answer button: |
|
|
260 | # checkAnswers button shows up after due date -- once a student can't record anymore |
|
|
261 | # checkAnswers button always shows up when an instructor or TA is acting |
|
|
262 | # as someone else (the $user and $effectiveUserName aren't the same). |
|
|
263 | $can{checkAnswers} = ( |
|
|
264 | # $can{recordAnswers} will be false if the due date has passed OR the |
|
|
265 | # student has used up all of her attempts |
|
|
266 | ($can{checkAnswers} and not $can{recordAnswers}) |
|
|
267 | or |
|
|
268 | ( |
|
|
269 | # FIXME: this is not the right way to check for this. |
|
|
270 | # also, canCheckAnswers() will show this button if the permission |
|
|
271 | # level is positive, which is always true when an instructor is |
|
|
272 | # acting as a student |
|
|
273 | defined($userName) |
|
|
274 | and |
|
|
275 | defined($effectiveUserName) |
|
|
276 | and |
|
|
277 | ($userName ne $effectiveUserName) |
|
|
278 | ) |
|
|
279 | ); |
|
|
280 | |
|
|
281 | # more complicated logif for showing "submit answer" button: |
|
|
282 | # We hide the submit answer button if someone is acting as a student |
|
|
283 | # This prevents errors where you accidently submit the answer for a student |
|
|
284 | # Not sure whether this a feature or a bug |
|
|
285 | $can{recordAnswers} = ( |
|
|
286 | $can{recordAnswers} |
|
|
287 | and not |
|
|
288 | ( |
|
|
289 | # FIXME: this is not the right way to check for this. |
|
|
290 | defined($userName) |
|
|
291 | and |
|
|
292 | defined($effectiveUserName) |
|
|
293 | and |
|
|
294 | ($userName ne $effectiveUserName) |
|
|
295 | ) |
|
|
296 | ); |
|
|
297 | |
| 124 | # final values for options |
298 | # final values for options |
| 125 | my %will; |
299 | my %will; |
| 126 | foreach (keys %must) { |
300 | foreach (keys %must) { |
| 127 | $will{$_} = $can{$_} && ($want{$_} || $must{$_}); |
301 | $will{$_} = $can{$_} && ($want{$_} || $must{$_}); |
| 128 | } |
302 | } |
| 129 | |
303 | |
| 130 | ##### sticky answers ##### |
304 | ##### sticky answers ##### |
| 131 | |
305 | |
| 132 | if (not $submitAnswers and $will{showOldAnswers}) { |
306 | if (not ($submitAnswers or $previewAnswers or $checkAnswers) and $will{showOldAnswers}) { |
| 133 | # do this only if new answers are NOT being submitted |
307 | # do this only if new answers are NOT being submitted |
| 134 | my %oldAnswers = decodeAnswers($problem->last_answer); |
308 | my %oldAnswers = decodeAnswers($problem->last_answer); |
| 135 | $formFields->{$_} = $oldAnswers{$_} foreach keys %oldAnswers; |
309 | $formFields->{$_} = $oldAnswers{$_} foreach keys %oldAnswers; |
| 136 | } |
310 | } |
| 137 | |
311 | |
| 138 | ##### translation ##### |
312 | ##### translation ##### |
| 139 | |
313 | |
|
|
314 | $WeBWorK::timer->continue("begin pg processing") if defined($WeBWorK::timer); |
| 140 | my $pg = WeBWorK::PG->new( |
315 | my $pg = WeBWorK::PG->new( |
| 141 | $courseEnv, |
316 | $ce, |
| 142 | $effectiveUser, |
317 | $effectiveUser, |
| 143 | $r->param('key'), |
318 | $key, |
| 144 | $set, |
319 | $set, |
| 145 | $problem, |
320 | $problem, |
| 146 | $psvn, |
321 | $set->psvn, # FIXME: this field should be removed |
| 147 | $formFields, |
322 | $formFields, |
| 148 | { # translation options |
323 | { # translation options |
| 149 | displayMode => $displayMode, |
324 | displayMode => $displayMode, |
| 150 | showHints => $will{showHints}, |
325 | showHints => $will{showHints}, |
| 151 | showSolutions => $will{showSolutions}, |
326 | showSolutions => $will{showSolutions}, |
| 152 | refreshMath2img => $will{showHints} || $will{showSolutions}, |
327 | refreshMath2img => $will{showHints} || $will{showSolutions}, |
| 153 | processAnswers => 1, |
328 | processAnswers => 1, |
| 154 | }, |
329 | }, |
| 155 | ); |
330 | ); |
| 156 | |
331 | |
|
|
332 | $WeBWorK::timer->continue("end pg processing") if defined($WeBWorK::timer); |
| 157 | ##### fix hint/solution options ##### |
333 | ##### fix hint/solution options ##### |
| 158 | |
334 | |
| 159 | $can{showHints} &&= $pg->{flags}->{hintExists}; |
335 | $can{showHints} &&= $pg->{flags}->{hintExists} |
|
|
336 | &&= $pg->{flags}->{showHintLimit}<=$pg->{state}->{num_of_incorrect_ans}; |
| 160 | $can{showSolutions} &&= $pg->{flags}->{solutionExists}; |
337 | $can{showSolutions} &&= $pg->{flags}->{solutionExists}; |
| 161 | |
338 | |
| 162 | ##### store fields ##### |
339 | ##### store fields ##### |
| 163 | |
340 | |
| 164 | $self->{want} = \%want; |
341 | $self->{want} = \%want; |
| 165 | $self->{must} = \%must; |
342 | $self->{must} = \%must; |
| 166 | $self->{can} = \%can; |
343 | $self->{can} = \%can; |
| 167 | $self->{will} = \%will; |
344 | $self->{will} = \%will; |
| 168 | |
|
|
| 169 | $self->{pg} = $pg; |
345 | $self->{pg} = $pg; |
| 170 | } |
|
|
| 171 | |
|
|
| 172 | sub if_warnings($$) { |
|
|
| 173 | my ($self, $arg) = @_; |
|
|
| 174 | return 0 unless $self->{isOpen}; |
|
|
| 175 | return $self->{pg}->{warnings} ne ""; |
|
|
| 176 | } |
346 | } |
| 177 | |
347 | |
| 178 | sub if_errors($$) { |
348 | sub if_errors($$) { |
| 179 | my ($self, $arg) = @_; |
349 | my ($self, $arg) = @_; |
| 180 | return 0 unless $self->{isOpen}; |
350 | |
|
|
351 | if ($self->{isOpen}) { |
| 181 | return $self->{pg}->{flags}->{error_flag}; |
352 | return $self->{pg}->{flags}->{error_flag} ? $arg : !$arg; |
|
|
353 | } else { |
|
|
354 | return !$arg; |
|
|
355 | } |
| 182 | } |
356 | } |
| 183 | |
357 | |
| 184 | sub head { |
358 | sub head { |
| 185 | my $self = shift; |
359 | my ($self) = @_; |
|
|
360 | |
| 186 | return "" unless $self->{isOpen}; |
361 | return "" unless $self->{isOpen}; |
| 187 | return $self->{pg}->{head_text} if $self->{pg}->{head_text}; |
362 | return $self->{pg}->{head_text} if $self->{pg}->{head_text}; |
| 188 | } |
363 | } |
| 189 | |
364 | |
| 190 | sub path { |
365 | sub options { |
| 191 | my $self = shift; |
366 | my ($self) = @_; |
| 192 | my $args = $_[-1]; |
|
|
| 193 | my $setName = $self->{set}->set_id; |
|
|
| 194 | my $problemNumber = $self->{problem}->problem_id; |
|
|
| 195 | |
367 | |
| 196 | my $ce = $self->{ce}; |
368 | return "" if $self->{invalidProblem}; |
| 197 | my $root = $ce->{webworkURLs}->{root}; |
369 | |
| 198 | my $courseName = $ce->{courseName}; |
370 | return join("", |
| 199 | return $self->pathMacro($args, |
371 | CGI::start_form("POST", $self->{r}->uri), |
| 200 | "Home" => "$root", |
372 | $self->hidden_authen_fields, |
| 201 | $courseName => "$root/$courseName", |
373 | CGI::hr(), |
| 202 | $setName => "$root/$courseName/$setName", |
374 | CGI::start_div({class=>"viewOptions"}), |
| 203 | "Problem $problemNumber" => "", |
375 | $self->viewOptions(), |
|
|
376 | CGI::end_div(), |
|
|
377 | CGI::end_form() |
| 204 | ); |
378 | ); |
| 205 | } |
379 | } |
| 206 | |
380 | |
|
|
381 | #sub path { |
|
|
382 | # my $self = shift; |
|
|
383 | # my $args = $_[-1]; |
|
|
384 | # my $setName = $self->{set}->set_id; |
|
|
385 | # my $problemNumber = $self->{problem}->problem_id; |
|
|
386 | # |
|
|
387 | # my $ce = $self->{ce}; |
|
|
388 | # my $root = $ce->{webworkURLs}->{root}; |
|
|
389 | # my $courseName = $ce->{courseName}; |
|
|
390 | # return $self->pathMacro($args, |
|
|
391 | # "Home" => "$root", |
|
|
392 | # $courseName => "$root/$courseName", |
|
|
393 | # $setName => "$root/$courseName/$setName", |
|
|
394 | # "Problem $problemNumber" => "", |
|
|
395 | # ); |
|
|
396 | #} |
|
|
397 | |
| 207 | sub siblings { |
398 | sub siblings { |
| 208 | my $self = shift; |
399 | my ($self) = @_; |
|
|
400 | my $r = $self->r; |
|
|
401 | my $db = $r->db; |
|
|
402 | my $urlpath = $r->urlpath; |
|
|
403 | |
|
|
404 | # can't show sibling problems if the set is invalid |
|
|
405 | return "" if $self->{invalidSet}; |
|
|
406 | |
|
|
407 | my $courseID = $urlpath->arg("courseID"); |
| 209 | my $setName = $self->{set}->set_id; |
408 | my $setID = $self->{set}->set_id; |
| 210 | my $problemNumber = $self->{problem}->problem_id; |
|
|
| 211 | |
|
|
| 212 | my $ce = $self->{ce}; |
|
|
| 213 | my $db = $self->{db}; |
|
|
| 214 | my $root = $ce->{webworkURLs}->{root}; |
|
|
| 215 | my $courseName = $ce->{courseName}; |
|
|
| 216 | |
|
|
| 217 | print CGI::strong("Problems"), CGI::br(); |
|
|
| 218 | |
|
|
| 219 | my $effectiveUser = $self->{r}->param("effectiveUser"); |
409 | my $eUserID = $r->param("effectiveUser"); |
| 220 | my @problems; |
410 | my @problemIDs = sort { $a <=> $b } $db->listUserProblems($eUserID, $setID); |
| 221 | push @problems, $db->getGlobalUserProblem($effectiveUser, $setName, $_) |
411 | |
| 222 | foreach ($db->listUserProblems($effectiveUser, $setName)); |
412 | print CGI::start_ul({class=>"LinksMenu"}); |
| 223 | foreach my $problem (sort { $a->problem_id <=> $b->problem_id } @problems) { |
413 | print CGI::start_li(); |
| 224 | print CGI::a({-href=>"$root/$courseName/$setName/".$problem->problem_id."/?" |
414 | print CGI::span({style=>"font-size:larger"}, "Problems"); |
| 225 | . $self->url_authen_args . "&displayMode=" . $self->{displayMode}}, |
415 | print CGI::start_ul(); |
| 226 | "Problem ".$problem->problem_id), CGI::br(); |
416 | |
|
|
417 | foreach my $problemID (@problemIDs) { |
|
|
418 | my $problemPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::Problem", |
|
|
419 | courseID => $courseID, setID => $setID, problemID => $problemID); |
|
|
420 | print CGI::li(CGI::a({href=>$self->systemLink($problemPage)}, "Problem $problemID")); |
| 227 | } |
421 | } |
|
|
422 | |
|
|
423 | print CGI::end_ul(); |
|
|
424 | print CGI::end_li(); |
|
|
425 | print CGI::end_ul(); |
|
|
426 | |
|
|
427 | return ""; |
| 228 | } |
428 | } |
| 229 | |
429 | |
| 230 | sub nav { |
430 | sub nav { |
| 231 | my $self = shift; |
431 | my ($self, $args) = @_; |
| 232 | my $args = $_[-1]; |
|
|
| 233 | my $setName = $self->{set}->set_id; |
|
|
| 234 | my $problemNumber = $self->{problem}->problem_id; |
|
|
| 235 | |
|
|
| 236 | my $ce = $self->{ce}; |
432 | my $r = $self->r; |
| 237 | my $db = $self->{db}; |
433 | my $db = $r->db; |
| 238 | my $root = $ce->{webworkURLs}->{root}; |
434 | my $urlpath = $r->urlpath; |
| 239 | my $courseName = $ce->{courseName}; |
|
|
| 240 | |
435 | |
| 241 | my $wwdb = $self->{wwdb}; |
436 | my $courseID = $urlpath->arg("courseID"); |
|
|
437 | my $setID = $self->{set}->set_id if !($self->{invalidSet}); |
|
|
438 | my $problemID = $self->{problem}->problem_id if !($self->{invalidProblem}); |
| 242 | my $effectiveUser = $self->{r}->param("effectiveUser"); |
439 | my $eUserID = $r->param("effectiveUser"); |
|
|
440 | |
|
|
441 | my ($prevID, $nextID); |
|
|
442 | |
|
|
443 | if (!$self->{invalidProblem}) { |
|
|
444 | my @problemIDs = $db->listUserProblems($eUserID, $setID); |
|
|
445 | foreach my $id (@problemIDs) { |
|
|
446 | $prevID = $id if $id < $problemID |
|
|
447 | and (not defined $prevID or $id > $prevID); |
|
|
448 | $nextID = $id if $id > $problemID |
|
|
449 | and (not defined $nextID or $id < $nextID); |
|
|
450 | } |
|
|
451 | } |
|
|
452 | |
|
|
453 | my @links; |
|
|
454 | |
|
|
455 | if ($prevID) { |
|
|
456 | my $prevPage = $urlpath->newFromModule(__PACKAGE__, |
|
|
457 | courseID => $courseID, setID => $setID, problemID => $prevID); |
|
|
458 | push @links, "Previous Problem", $r->location . $prevPage->path, "navPrev"; |
|
|
459 | } else { |
|
|
460 | push @links, "Previous Problem", "", "navPrev"; |
|
|
461 | } |
|
|
462 | |
|
|
463 | push @links, "Problem List", $r->location . $urlpath->parent->path, "navProbList"; |
|
|
464 | |
|
|
465 | if ($nextID) { |
|
|
466 | my $nextPage = $urlpath->newFromModule(__PACKAGE__, |
|
|
467 | courseID => $courseID, setID => $setID, problemID => $nextID); |
|
|
468 | push @links, "Next Problem", $r->location . $nextPage->path, "navNext"; |
|
|
469 | } else { |
|
|
470 | push @links, "Next Problem", "", "navNext"; |
|
|
471 | } |
|
|
472 | |
| 243 | my $tail = "&displayMode=".$self->{displayMode}; |
473 | my $tail = "&displayMode=".$self->{displayMode}; |
| 244 | |
|
|
| 245 | my @links = ("Problem List" , "$root/$courseName/$setName", "navProbList"); |
|
|
| 246 | |
|
|
| 247 | my $prevProblem = $db->getGlobalUserProblem($effectiveUser, $setName, $problemNumber-1); |
|
|
| 248 | my $nextProblem = $db->getGlobalUserProblem($effectiveUser, $setName, $problemNumber+1); |
|
|
| 249 | unshift @links, "Previous Problem" , ($prevProblem |
|
|
| 250 | ? "$root/$courseName/$setName/".$prevProblem->problem_id |
|
|
| 251 | : "") , "navPrev"; |
|
|
| 252 | push @links, "Next Problem" , ($nextProblem |
|
|
| 253 | ? "$root/$courseName/$setName/".$nextProblem->problem_id |
|
|
| 254 | : "") , "navNext"; |
|
|
| 255 | |
|
|
| 256 | return $self->navMacro($args, $tail, @links); |
474 | return $self->navMacro($args, $tail, @links); |
| 257 | } |
475 | } |
| 258 | |
476 | |
| 259 | sub title { |
477 | sub title { |
| 260 | my $self = shift; |
478 | my ($self) = @_; |
|
|
479 | |
|
|
480 | # using the url arguments won't break if the set/problem are invalid |
|
|
481 | my $setID = $self->r->urlpath->arg("setID"); |
|
|
482 | my $problemID = $self->r->urlpath->arg("problemID"); |
|
|
483 | |
| 261 | my $setName = $self->{set}->set_id; |
484 | #my $setID = $self->{set}->set_id; |
| 262 | my $problemNumber = $self->{problem}->problem_id; |
485 | #my $problemID = $self->{problem}->problem_id; |
| 263 | |
486 | |
| 264 | return "$setName : Problem $problemNumber"; |
487 | return "$setID : $problemID"; |
| 265 | } |
488 | } |
| 266 | |
489 | |
| 267 | sub body { |
490 | sub body { |
| 268 | my $self = shift; |
491 | my $self = shift; |
|
|
492 | my $r = $self->r; |
|
|
493 | my $ce = $r->ce; |
|
|
494 | my $db = $r->db; |
|
|
495 | my $urlpath = $r->urlpath; |
|
|
496 | |
|
|
497 | if ($self->{invalidSet}) { |
|
|
498 | return CGI::div({class=>"ResultsWithError"}, |
|
|
499 | CGI::p("The selected problem set (" . $urlpath->arg("setID") . ") is not a valid set for " . $r->param("effectiveUser") . ".")); |
|
|
500 | } |
| 269 | |
501 | |
| 270 | return CGI::p(CGI::font({-color=>"red"}, "This problem is not available because the problem set that contains it is not yet open.")) |
502 | if ($self->{invalidProblem}) { |
|
|
503 | return CGI::div({class=>"ResultsWithError"}, |
|
|
504 | CGI::p("The selected problem (" . $urlpath->arg("problemID") . ") is not a valid problem for set " . $self->{set}->set_id . ".")); |
|
|
505 | } |
|
|
506 | |
| 271 | unless $self->{isOpen}; |
507 | unless ($self->{isOpen}) { |
| 272 | |
508 | return CGI::div({class=>"ResultsWithError"}, |
|
|
509 | CGI::p("This problem is not available because the problem set that contains it is not yet open.")); |
|
|
510 | } |
| 273 | # unpack some useful variables |
511 | # unpack some useful variables |
| 274 | my $r = $self->{r}; |
|
|
| 275 | my $db = $self->{db}; |
|
|
| 276 | my $set = $self->{set}; |
512 | my $set = $self->{set}; |
| 277 | my $problem = $self->{problem}; |
513 | my $problem = $self->{problem}; |
|
|
514 | my $editMode = $self->{editMode}; |
| 278 | my $permissionLevel = $self->{permissionLevel}; |
515 | my $permissionLevel = $self->{permissionLevel}; |
| 279 | my $submitAnswers = $self->{submitAnswers}; |
516 | my $submitAnswers = $self->{submitAnswers}; |
| 280 | my $checkAnswers = $self->{checkAnswers}; |
517 | my $checkAnswers = $self->{checkAnswers}; |
| 281 | my $previewAnswers = $self->{previewAnswers}; |
518 | my $previewAnswers = $self->{previewAnswers}; |
| 282 | my %want = %{ $self->{want} }; |
519 | my %want = %{ $self->{want} }; |
| 283 | my %can = %{ $self->{can} }; |
520 | my %can = %{ $self->{can} }; |
| 284 | my %must = %{ $self->{must} }; |
521 | my %must = %{ $self->{must} }; |
| 285 | my %will = %{ $self->{will} }; |
522 | my %will = %{ $self->{will} }; |
| 286 | my $pg = $self->{pg}; |
523 | my $pg = $self->{pg}; |
| 287 | |
524 | |
|
|
525 | #my $root = $ce->{webworkURLs}->{root}; |
|
|
526 | my $courseName = $urlpath->arg("courseID"); |
|
|
527 | |
|
|
528 | #####create Editor link ##### |
|
|
529 | ## print editor link if the user is an instructor AND the file is not in temporary editing mode |
|
|
530 | #my $editorLinkMessage = ''; |
|
|
531 | ## and ( (not defined($self->{editMode})) or $self->{editMode} eq 'savedFile') # FIXME is this needed? |
|
|
532 | #if ($self->{permissionLevel}>=10 ) { |
|
|
533 | # $editorLinkMessage = CGI::a({-href=>$ce->{webworkURLs}->{root}."/$courseName/instructor/pgProblemEditor/". |
|
|
534 | # $set->set_id.'/'.$problem->problem_id.'?'.$self->url_authen_args},'Edit this problem'); |
|
|
535 | #} |
|
|
536 | |
|
|
537 | my $editorLink = ""; |
|
|
538 | # if we are here without a real problem set, carry that through |
|
|
539 | my $forced_field = []; |
|
|
540 | $forced_field = ['sourceFilePath' => $r->param("sourceFilePath")] if |
|
|
541 | ($set->set_id eq 'Undefined_Set'); |
|
|
542 | if ($self->{permissionLevel}>=10) { |
|
|
543 | my $editorPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::Instructor::PGProblemEditor", |
|
|
544 | courseID => $courseName, setID => $set->set_id, problemID => $problem->problem_id); |
|
|
545 | my $editorURL = $self->systemLink($editorPage, params=>$forced_field); |
|
|
546 | $editorLink = CGI::a({href=>$editorURL}, "Edit this problem"); |
|
|
547 | } |
|
|
548 | |
| 288 | ##### translation errors? ##### |
549 | ##### translation errors? ##### |
| 289 | |
550 | |
| 290 | if ($pg->{flags}->{error_flag}) { |
551 | if ($pg->{flags}->{error_flag}) { |
| 291 | return $self->errorOutput($pg->{errors}, $pg->{body_text}); |
552 | print $self->errorOutput($pg->{errors}, $pg->{body_text}); |
|
|
553 | print $editorLink; |
|
|
554 | return ""; |
| 292 | } |
555 | } |
| 293 | |
556 | |
| 294 | ##### answer processing ##### |
557 | ##### answer processing ##### |
| 295 | |
558 | $WeBWorK::timer->continue("begin answer processing") if defined($WeBWorK::timer); |
| 296 | # if answers were submitted: |
559 | # if answers were submitted: |
|
|
560 | my $scoreRecordedMessage; |
|
|
561 | my $pureProblem; |
| 297 | if ($submitAnswers) { |
562 | if ($submitAnswers) { |
| 298 | # get a "pure" (unmerged) UserProblem to modify |
563 | # get a "pure" (unmerged) UserProblem to modify |
|
|
564 | # this will be undefined if the problem has not been assigned to this user |
| 299 | my $pureProblem = $db->getUserProblem($problem->user_id, $problem->set_id, $problem->problem_id); |
565 | $pureProblem = $db->getUserProblem($problem->user_id, $problem->set_id, $problem->problem_id); # checked |
|
|
566 | if (defined $pureProblem) { |
| 300 | # store answers in DB for sticky answers |
567 | # store answers in DB for sticky answers |
| 301 | my %answersToStore; |
568 | my %answersToStore; |
| 302 | my %answerHash = %{ $pg->{answers} }; |
569 | my %answerHash = %{ $pg->{answers} }; |
| 303 | $answersToStore{$_} = $answerHash{$_}->{original_student_ans} |
570 | $answersToStore{$_} = $self->{formFields}->{$_} #$answerHash{$_}->{original_student_ans} -- this may have been modified for fields with multiple values. Don't use it!! |
| 304 | foreach (keys %answerHash); |
571 | foreach (keys %answerHash); |
|
|
572 | |
|
|
573 | # There may be some more answers to store -- one which are auxiliary entries to a primary answer. Evaluating |
|
|
574 | # matrices works in this way, only the first answer triggers an answer evaluator, the rest are just inputs |
|
|
575 | # however we need to store them. Fortunately they are still in the input form. |
|
|
576 | my @extra_answer_names = @{ $pg->{flags}->{KEPT_EXTRA_ANSWERS}}; |
|
|
577 | $answersToStore{$_} = $self->{formFields}->{$_} foreach (@extra_answer_names); |
|
|
578 | |
|
|
579 | # Now let's encode these answers to store them -- append the extra answers to the end of answer entry order |
|
|
580 | my @answer_order = (@{$pg->{flags}->{ANSWER_ENTRY_ORDER}}, @extra_answer_names); |
| 305 | my $answerString = encodeAnswers(%answersToStore, |
581 | my $answerString = encodeAnswers(%answersToStore, |
| 306 | @{ $pg->{flags}->{ANSWER_ENTRY_ORDER} }); |
582 | @answer_order); |
|
|
583 | |
|
|
584 | # store last answer to database |
|
|
585 | $problem->last_answer($answerString); |
| 307 | $pureProblem->last_answer($answerString); |
586 | $pureProblem->last_answer($answerString); |
| 308 | $problem->last_answer($answerString); |
|
|
| 309 | $db->putUserProblem($pureProblem); |
|
|
| 310 | |
|
|
| 311 | # store state in DB if it makes sense |
|
|
| 312 | if ($will{recordAnswers}) { |
|
|
| 313 | $problem->status($pg->{state}->{recorded_score}); |
|
|
| 314 | $problem->attempted(1); |
|
|
| 315 | $problem->num_correct($pg->{state}->{num_of_correct_ans}); |
|
|
| 316 | $problem->num_incorrect($pg->{state}->{num_of_incorrect_ans}); |
|
|
| 317 | $pureProblem->status($pg->{state}->{recorded_score}); |
|
|
| 318 | $pureProblem->attempted(1); |
|
|
| 319 | $pureProblem->num_correct($pg->{state}->{num_of_correct_ans}); |
|
|
| 320 | $pureProblem->num_incorrect($pg->{state}->{num_of_incorrect_ans}); |
|
|
| 321 | $db->putUserProblem($pureProblem); |
587 | $db->putUserProblem($pureProblem); |
|
|
588 | |
|
|
589 | # store state in DB if it makes sense |
|
|
590 | if ($will{recordAnswers}) { |
|
|
591 | $problem->status($pg->{state}->{recorded_score}); |
|
|
592 | $problem->attempted(1); |
|
|
593 | $problem->num_correct($pg->{state}->{num_of_correct_ans}); |
|
|
594 | $problem->num_incorrect($pg->{state}->{num_of_incorrect_ans}); |
|
|
595 | $pureProblem->status($pg->{state}->{recorded_score}); |
|
|
596 | $pureProblem->attempted(1); |
|
|
597 | $pureProblem->num_correct($pg->{state}->{num_of_correct_ans}); |
|
|
598 | $pureProblem->num_incorrect($pg->{state}->{num_of_incorrect_ans}); |
|
|
599 | if ($db->putUserProblem($pureProblem)) { |
|
|
600 | $scoreRecordedMessage = "Your score was recorded."; |
|
|
601 | } else { |
|
|
602 | $scoreRecordedMessage = "Your score was not recorded because there was a failure in storing the problem record to the database."; |
|
|
603 | } |
| 322 | # write to the transaction log, just to make sure |
604 | # write to the transaction log, just to make sure |
| 323 | writeLog($self->{ce}, "transaction", |
605 | writeLog($self->{ce}, "transaction", |
| 324 | $problem->problem_id."\t". |
606 | $problem->problem_id."\t". |
| 325 | $problem->set_id."\t". |
607 | $problem->set_id."\t". |
| 326 | $problem->user_id."\t". |
608 | $problem->user_id."\t". |
| 327 | $problem->source_file."\t". |
609 | $problem->source_file."\t". |
| 328 | $problem->value."\t". |
610 | $problem->value."\t". |
| 329 | $problem->max_attempts."\t". |
611 | $problem->max_attempts."\t". |
| 330 | $problem->problem_seed."\t". |
612 | $problem->problem_seed."\t". |
| 331 | $pureProblem->status."\t". |
613 | $pureProblem->status."\t". |
| 332 | $pureProblem->attempted."\t". |
614 | $pureProblem->attempted."\t". |
| 333 | $pureProblem->last_answer."\t". |
615 | $pureProblem->last_answer."\t". |
| 334 | $pureProblem->num_correct."\t". |
616 | $pureProblem->num_correct."\t". |
| 335 | $pureProblem->num_incorrect |
617 | $pureProblem->num_incorrect |
| 336 | ); |
618 | ); |
|
|
619 | } else { |
|
|
620 | if (time < $set->open_date or time > $set->due_date) { |
|
|
621 | $scoreRecordedMessage = "Your score was not recorded because this problem set is closed."; |
|
|
622 | } else { |
|
|
623 | $scoreRecordedMessage = "Your score was not recorded."; |
|
|
624 | } |
|
|
625 | } |
|
|
626 | } else { |
|
|
627 | $scoreRecordedMessage = "Your score was not recorded because this problem has not been built for you."; |
| 337 | } |
628 | } |
| 338 | } |
629 | } |
|
|
630 | |
| 339 | # logging student answers |
631 | # logging student answers |
| 340 | my $pastAnswerLog = undef; |
632 | |
| 341 | if (defined( $self->{ce}->{webworkFiles}->{logs}->{'pastAnswerList'} )) { |
633 | my $answer_log = $self->{ce}->{courseFiles}->{logs}->{'answer_log'}; |
| 342 | |
634 | if ( defined($answer_log ) and defined($pureProblem)) { |
| 343 | $pastAnswerLog = $self->{ce}->{webworkFiles}->{logs}->{'pastAnswerList'}; |
635 | if ($submitAnswers ) { |
| 344 | |
|
|
| 345 | if ($submitAnswers and defined($pastAnswerLog) ) { |
|
|
| 346 | my $answerString = ""; |
636 | my $answerString = ""; |
| 347 | my %answerHash = %{ $pg->{answers} }; |
637 | my %answerHash = %{ $pg->{answers} }; |
| 348 | $answerString = $answerString . $answerHash{$_}->{original_student_ans}."\t" |
638 | # FIXME this is the line 552 error. make sure original student ans is defined. |
|
|
639 | # The fact that it is not defined is probably due to an error in some answer evaluator. |
|
|
640 | # But I think it is useful to suppress this error message in the log. |
| 349 | foreach (sort keys %answerHash); |
641 | foreach (sort keys %answerHash) { |
|
|
642 | my $student_ans = $answerHash{$_}->{original_student_ans} ||''; |
|
|
643 | $answerString .= $student_ans."\t" |
|
|
644 | } |
|
|
645 | $answerString = '' unless defined($answerString); # insure string is defined. |
| 350 | writeLog($self->{ce}, "pastAnswerList", |
646 | writeCourseLog($self->{ce}, "answer_log", |
|
|
647 | join("", |
| 351 | '|'.$problem->user_id. |
648 | '|', $problem->user_id, |
| 352 | '|'.$problem->set_id. |
649 | '|', $problem->set_id, |
| 353 | '|'.$problem->problem_id.'|'."\t". |
650 | '|', $problem->problem_id, |
|
|
651 | '|',"\t", |
| 354 | time()."\t". |
652 | time(),"\t", |
| 355 | $answerString, |
653 | $answerString, |
| 356 | |
654 | ), |
| 357 | ); |
655 | ); |
| 358 | |
656 | |
| 359 | } |
657 | } |
| 360 | |
|
|
| 361 | } |
658 | } |
| 362 | # end logging student answers |
659 | |
|
|
660 | $WeBWorK::timer->continue("end answer processing") if defined($WeBWorK::timer); |
| 363 | |
661 | |
| 364 | ##### output ##### |
662 | ##### output ##### |
|
|
663 | |
| 365 | print CGI::start_div({class=>"problemHeader"}); |
664 | print CGI::start_div({class=>"problemHeader"}); |
|
|
665 | |
|
|
666 | # custom message for editor |
|
|
667 | if ($permissionLevel >= 10 and defined $editMode) { |
|
|
668 | if ($editMode eq "temporaryFile") { |
|
|
669 | print CGI::p(CGI::i("Editing temporary file: ", $problem->source_file)); |
|
|
670 | } elsif ($editMode eq "savedFile") { |
|
|
671 | # FIXME: this is all done automatically if submitError exists. |
|
|
672 | #if ( defined($r->param('submiterror')) and $r->param('submiterror') ) { |
|
|
673 | # FIXME The following line doesn't work because the submiterror hook has already been called. |
|
|
674 | # The actions below should take place during the initialization phase. |
|
|
675 | # $self->{submiterror} .= $r->param('submiterror'); |
|
|
676 | # print CGI::p(CGI::div({class=>'ResultsWithError'},$self->{submiterror})); |
|
|
677 | #} else { |
|
|
678 | # print CGI::p(CGI::div({ class=>'ResultsWithoutError'}, "Problem saved to: ", $problem->source_file)); |
|
|
679 | #} |
|
|
680 | } |
|
|
681 | } |
|
|
682 | #FIXME we need error messages here if the problem was really not saved. |
| 366 | # attempt summary |
683 | # attempt summary |
| 367 | if ($submitAnswers or $will{showCorrectAnswers}) { |
684 | #FIXME -- the following is a kludge: if showPartialCorrectAnswers is negative don't show anything. |
|
|
685 | # until after the due date |
|
|
686 | # do I need to check $wills{howCorrectAnswers} to make preflight work?? |
|
|
687 | if (($pg->{flags}->{showPartialCorrectAnswers}>= 0 and $submitAnswers) ) { |
| 368 | # print this if user submitted answers OR requested correct answers |
688 | # print this if user submitted answers OR requested correct answers |
|
|
689 | |
| 369 | print $self->attemptResults($pg, $submitAnswers, |
690 | print $self->attemptResults($pg, 1, |
| 370 | $will{showCorrectAnswers}, |
691 | $will{showCorrectAnswers}, |
| 371 | $pg->{flags}->{showPartialCorrectAnswers}, 1, 0); |
692 | $pg->{flags}->{showPartialCorrectAnswers}, 1, 1); |
| 372 | } elsif ($checkAnswers) { |
693 | } elsif ($checkAnswers) { |
| 373 | # print this if user previewed answers |
694 | # print this if user previewed answers |
|
|
695 | print CGI::div({class=>'ResultsWithError'},"ANSWERS ONLY CHECKED -- ",CGI::br(),"ANSWERS NOT RECORDED", CGI::br() ); |
| 374 | print $self->attemptResults($pg, 1, 0, 1, 1, 0); |
696 | print $self->attemptResults($pg, 1, $will{showCorrectAnswers}, 1, 1, 1); |
| 375 | # show attempt answers |
697 | # show attempt answers |
| 376 | # don't show correct answers |
698 | # show correct answers if asked |
| 377 | # show attempt results (correctness) |
699 | # show attempt results (correctness) |
| 378 | # don't show attempt previews |
700 | # show attempt previews |
| 379 | } elsif ($previewAnswers) { |
701 | } elsif ($previewAnswers) { |
| 380 | # print this if user previewed answers |
702 | # print this if user previewed answers |
| 381 | print $self->attemptResults($pg, 1, 0, 0, 0, 1); |
703 | print CGI::div({class=>'ResultsWithError'},"PREVIEW ONLY -- NOT RECORDED"),CGI::br(),$self->attemptResults($pg, 1, 0, 0, 0, 1); |
| 382 | # show attempt answers |
704 | # show attempt answers |
| 383 | # don't show correct answers |
705 | # don't show correct answers |
| 384 | # don't show attempt results (correctness) |
706 | # don't show attempt results (correctness) |
| 385 | # show attempt previews |
707 | # show attempt previews |
| 386 | } |
708 | } |
| 387 | |
709 | |
| 388 | print CGI::end_div(); |
710 | print CGI::end_div(); |
| 389 | |
711 | |
| 390 | print CGI::start_div({class=>"problem"}); |
712 | print CGI::start_div({class=>"problem"}); |
| 391 | #print CGI::hr(); |
713 | |
| 392 | # main form |
714 | # main form |
| 393 | print |
715 | print |
| 394 | CGI::startform("POST", $r->uri), |
716 | CGI::startform("POST", $r->uri), |
| 395 | $self->hidden_authen_fields, |
717 | $self->hidden_authen_fields, |
| 396 | CGI::p($pg->{body_text}), |
718 | CGI::p($pg->{body_text}), |
| 397 | CGI::p($pg->{result}->{msg} ? CGI::b("Note: ") : "", CGI::i($pg->{result}->{msg})), |
719 | CGI::p($pg->{result}->{msg} ? CGI::b("Note: ") : "", CGI::i($pg->{result}->{msg})), |
| 398 | CGI::p( |
720 | CGI::p( |
|
|
721 | ($can{showCorrectAnswers} |
|
|
722 | ? CGI::checkbox( |
|
|
723 | -name => "showCorrectAnswers", |
|
|
724 | -checked => $will{showCorrectAnswers}, |
|
|
725 | -label => "Show correct answers", |
|
|
726 | ) ." " |
|
|
727 | : "" ), |
|
|
728 | ($can{showHints} |
|
|
729 | ? '<div style="color:red">'. CGI::checkbox( |
|
|
730 | -name => "showHints", |
|
|
731 | -checked => $will{showHints}, |
|
|
732 | -label => "Show Hints", |
|
|
733 | ) . "</div> " |
|
|
734 | : " " ), |
|
|
735 | ($can{showSolutions} |
|
|
736 | ? CGI::checkbox( |
|
|
737 | -name => "showSolutions", |
|
|
738 | -checked => $will{showSolutions}, |
|
|
739 | -label => "Show Solutions", |
|
|
740 | ) . " " |
|
|
741 | : " " ),CGI::br(), |
|
|
742 | CGI::submit(-name=>"previewAnswers", |
|
|
743 | -label=>"Preview Answers"), |
| 399 | ($can{recordAnswers} |
744 | ($can{recordAnswers} |
| 400 | ? CGI::submit(-name=>"submitAnswers", |
745 | ? CGI::submit(-name=>"submitAnswers", |
| 401 | -label=>"Submit Answers") |
746 | -label=>"Submit Answers") |
| 402 | : ""), |
747 | : ""), |
| 403 | ($can{checkAnswers} |
748 | ( $can{checkAnswers} |
| 404 | ? CGI::submit(-name=>"checkAnswers", |
749 | ? CGI::submit(-name=>"checkAnswers", |
| 405 | -label=>"Check Answers") |
750 | -label=>"Check Answers") |
| 406 | : ""), |
751 | : ""), |
| 407 | CGI::submit(-name=>"previewAnswers", |
|
|
| 408 | -label=>"Preview Answers"), |
|
|
| 409 | ); |
752 | ); |
| 410 | print CGI::end_div(); |
753 | print CGI::end_div(); |
| 411 | |
754 | |
| 412 | print CGI::start_div({class=>"scoreSummary"}); |
755 | print CGI::start_div({class=>"scoreSummary"}); |
|
|
756 | |
| 413 | # score summary |
757 | # score summary |
| 414 | my $attempts = $problem->num_correct + $problem->num_incorrect; |
758 | my $attempts = $problem->num_correct + $problem->num_incorrect; |
| 415 | my $attemptsNoun = $attempts != 1 ? "times" : "time"; |
759 | my $attemptsNoun = $attempts != 1 ? "times" : "time"; |
| 416 | my $lastScore = int ($problem->status * 100) . "%"; |
760 | my $lastScore = sprintf("%.0f%%", $problem->status * 100); # Round to whole number |
| 417 | my ($attemptsLeft, $attemptsLeftNoun); |
761 | my ($attemptsLeft, $attemptsLeftNoun); |
| 418 | if ($problem->max_attempts == -1) { |
762 | if ($problem->max_attempts == -1) { |
| 419 | # unlimited attempts |
763 | # unlimited attempts |
| 420 | $attemptsLeft = "unlimited"; |
764 | $attemptsLeft = "unlimited"; |
| 421 | $attemptsLeftNoun = "attempts"; |
765 | $attemptsLeftNoun = "attempts"; |
| … | |
… | |
| 428 | my $setClosedMessage; |
772 | my $setClosedMessage; |
| 429 | if (time < $set->open_date or time > $set->due_date) { |
773 | if (time < $set->open_date or time > $set->due_date) { |
| 430 | $setClosed = 1; |
774 | $setClosed = 1; |
| 431 | $setClosedMessage = "This problem set is closed."; |
775 | $setClosedMessage = "This problem set is closed."; |
| 432 | if ($permissionLevel > 0) { |
776 | if ($permissionLevel > 0) { |
| 433 | $setClosedMessage .= " Since you are a privileged user, additional attempts will be recorded."; |
777 | $setClosedMessage .= " However, since you are a privileged user, additional attempts will be recorded."; |
| 434 | } else { |
778 | } else { |
| 435 | $setClosedMessage .= " Additional attempts will not be recorded."; |
779 | $setClosedMessage .= " Additional attempts will not be recorded."; |
| 436 | } |
780 | } |
| 437 | } |
781 | } |
|
|
782 | |
|
|
783 | my $notCountedMessage = ($problem->value) ? "" : "(This problem will not count towards your grade.)"; |
| 438 | print CGI::p( |
784 | print CGI::p( |
|
|
785 | $submitAnswers ? $scoreRecordedMessage . CGI::br() : "", |
| 439 | "You have attempted this problem $attempts $attemptsNoun.", CGI::br(), |
786 | "You have attempted this problem $attempts $attemptsNoun.", CGI::br(), |
| 440 | $problem->attempted |
787 | $problem->attempted |
| 441 | ? "Your recorded score is $lastScore." . CGI::br() |
788 | ? "Your recorded score is $lastScore. $notCountedMessage" . CGI::br() |
| 442 | : "", |
789 | : "", |
| 443 | $setClosed ? $setClosedMessage : "You have $attemptsLeft $attemptsLeftNoun remaining." |
790 | $setClosed ? $setClosedMessage : "You have $attemptsLeft $attemptsLeftNoun remaining." |
| 444 | ); |
791 | ); |
| 445 | print CGI::end_div(); |
792 | print CGI::end_div(); |
| 446 | print CGI::hr(), CGI::start_div({class=>"viewOptions"}); |
793 | |
| 447 | print |
794 | # save state for viewOptions |
| 448 | $self->viewOptions(),CGI::end_div(), |
795 | print CGI::hidden( |
|
|
796 | -name => "showOldAnswers", |
|
|
797 | -value => $will{showOldAnswers} |
|
|
798 | ), |
|
|
799 | |
|
|
800 | CGI::hidden( |
|
|
801 | -name => "displayMode", |
|
|
802 | -value => $self->{displayMode} |
|
|
803 | ); |
|
|
804 | print( CGI::hidden( |
|
|
805 | -name => 'editMode', |
|
|
806 | -value => $self->{editMode}, |
|
|
807 | ) |
|
|
808 | ) if defined($self->{editMode}) and $self->{editMode} eq 'temporaryFile'; |
|
|
809 | print( CGI::hidden( |
|
|
810 | -name => 'sourceFilePath', |
|
|
811 | -value => $self->{problem}->{source_file} |
|
|
812 | )) if defined($self->{problem}->{source_file}); |
|
|
813 | |
|
|
814 | # end of main form |
| 449 | CGI::endform(); |
815 | print CGI::endform(); |
| 450 | |
816 | |
| 451 | print CGI::start_div({class=>"problemFooter"}); |
817 | print CGI::start_div({class=>"problemFooter"}); |
| 452 | # feedback form |
818 | |
| 453 | my $ce = $self->{ce}; |
819 | ## arguments for answer inspection button |
|
|
820 | #my $prof_url = $ce->{webworkURLs}->{oldProf}; |
| 454 | my $root = $ce->{webworkURLs}->{root}; |
821 | #my $webworkURL = $ce->{webworkURLs}->{root}; |
| 455 | my $courseName = $ce->{courseName}; |
822 | #my $cgi_url = $prof_url; |
|
|
823 | #$cgi_url=~ s|/[^/]*$||; # clip profLogin.pl |
|
|
824 | #my $authen_args = $self->url_authen_args(); |
|
|
825 | #my $showPastAnswersURL = "$webworkURL/$courseName/instructor/show_answers/"; |
|
|
826 | |
|
|
827 | my $pastAnswersPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::Instructor::ShowAnswers", |
|
|
828 | courseID => $courseName); |
|
|
829 | my $showPastAnswersURL = $self->systemLink($pastAnswersPage, authen => 0); # no authen info for form action |
|
|
830 | |
|
|
831 | # print answer inspection button |
|
|
832 | if ($self->{permissionLevel} > 0) { |
|
|
833 | print "\n", |
|
|
834 | CGI::start_form(-method=>"POST",-action=>$showPastAnswersURL,-target=>"information"),"\n", |
|
|
835 | $self->hidden_authen_fields,"\n", |
|
|
836 | CGI::hidden(-name => 'courseID', -value=>$courseName), "\n", |
|
|
837 | CGI::hidden(-name => 'problemID', -value=>$problem->problem_id), "\n", |
|
|
838 | CGI::hidden(-name => 'setID', -value=>$problem->set_id), "\n", |
|
|
839 | CGI::hidden(-name => 'studentUser', -value=>$problem->user_id), "\n", |
|
|
840 | CGI::p( {-align=>"left"}, |
|
|
841 | CGI::submit(-name => 'action', -value=>'Show Past Answers') |
|
|
842 | ), "\n", |
|
|
843 | CGI::endform(); |
|
|
844 | } |
|
|
845 | |
|
|
846 | ## arguments for feedback form |
| 456 | my $feedbackURL = "$root/$courseName/feedback/"; |
847 | #my $feedbackURL = "$root/$courseName/feedback/"; |
| 457 | |
848 | # |
| 458 | # arguments for answer inspection button |
849 | ##print feedback form |
| 459 | my $prof_url = $ce->{webworkURLs}->{oldProf}; |
850 | #print |
| 460 | my $cgi_url = $prof_url; |
851 | # CGI::start_form(-method=>"POST", -action=>$feedbackURL),"\n", |
| 461 | $cgi_url=~ s|/[^/]*$||; # clip profLogin.pl |
852 | # $self->hidden_authen_fields,"\n", |
| 462 | my $authen_args = $self->url_authen_args(); |
853 | # CGI::hidden("module", __PACKAGE__),"\n", |
| 463 | my $showPastAnswersURL = "$cgi_url/showPastAnswers.pl"; |
854 | # CGI::hidden("set", $set->set_id),"\n", |
|
|
855 | # CGI::hidden("problem", $problem->problem_id),"\n", |
|
|
856 | # CGI::hidden("displayMode", $self->{displayMode}),"\n", |
|
|
857 | # CGI::hidden("showOldAnswers", $will{showOldAnswers}),"\n", |
|
|
858 | # CGI::hidden("showCorrectAnswers", $will{showCorrectAnswers}),"\n", |
|
|
859 | # CGI::hidden("showHints", $will{showHints}),"\n", |
|
|
860 | # CGI::hidden("showSolutions", $will{showSolutions}),"\n", |
|
|
861 | # CGI::p({-align=>"left"}, |
|
|
862 | # CGI::submit(-name=>"feedbackForm", -label=>"Email instructor") |
|
|
863 | # ), |
|
|
864 | # CGI::endform(),"\n"; |
|
|
865 | |
|
|
866 | # feedback form url |
|
|
867 | my $feedbackPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::Feedback", |
|
|
868 | courseID => $courseName); |
|
|
869 | my $feedbackURL = $self->systemLink($feedbackPage, authen => 0); # no authen info for form action |
| 464 | |
870 | |
| 465 | #print feedback form |
871 | #print feedback form |
| 466 | print |
872 | print |
| 467 | CGI::start_form(-method=>"POST", -action=>$feedbackURL),"\n", |
873 | CGI::start_form(-method=>"POST", -action=>$feedbackURL),"\n", |
| 468 | $self->hidden_authen_fields,"\n", |
874 | $self->hidden_authen_fields,"\n", |
| … | |
… | |
| 472 | CGI::hidden("displayMode", $self->{displayMode}),"\n", |
878 | CGI::hidden("displayMode", $self->{displayMode}),"\n", |
| 473 | CGI::hidden("showOldAnswers", $will{showOldAnswers}),"\n", |
879 | CGI::hidden("showOldAnswers", $will{showOldAnswers}),"\n", |
| 474 | CGI::hidden("showCorrectAnswers", $will{showCorrectAnswers}),"\n", |
880 | CGI::hidden("showCorrectAnswers", $will{showCorrectAnswers}),"\n", |
| 475 | CGI::hidden("showHints", $will{showHints}),"\n", |
881 | CGI::hidden("showHints", $will{showHints}),"\n", |
| 476 | CGI::hidden("showSolutions", $will{showSolutions}),"\n", |
882 | CGI::hidden("showSolutions", $will{showSolutions}),"\n", |
| 477 | CGI::p({-align=>"right"}, |
883 | CGI::p({-align=>"left"}, |
| 478 | CGI::submit(-name=>"feedbackForm", -label=>"Send Feedback") |
884 | CGI::submit(-name=>"feedbackForm", -label=>"Email instructor") |
| 479 | ), |
885 | ), |
| 480 | CGI::endform(),"\n"; |
886 | CGI::endform(),"\n"; |
| 481 | # print answer inspection button |
|
|
| 482 | if ($self->{permissionLevel} >0) { |
|
|
| 483 | |
|
|
| 484 | |
|
|
| 485 | print "\n", |
|
|
| 486 | CGI::start_form(-method=>"POST",-action=>$showPastAnswersURL,-target=>"information"),"\n", |
|
|
| 487 | $self->hidden_authen_fields,"\n", |
|
|
| 488 | CGI::hidden(-name => 'course', -value=>$courseName), "\n", |
|
|
| 489 | CGI::hidden(-name => 'probNum', -value=>$problem->problem_id), "\n", |
|
|
| 490 | CGI::hidden(-name => 'setNum', -value=>$problem->set_id), "\n", |
|
|
| 491 | CGI::hidden(-name => 'User', -value=>$problem->user_id), "\n", |
|
|
| 492 | CGI::submit(-name => 'action', -value=>'Show Past Answers'), "\n", |
|
|
| 493 | CGI::endform(); |
|
|
| 494 | |
887 | |
|
|
888 | # FIXME print editor link |
|
|
889 | print $editorLink; #empty unless it is appropriate to have an editor link. |
| 495 | |
890 | |
| 496 | |
|
|
| 497 | } |
|
|
| 498 | print CGI::end_div(); |
891 | print CGI::end_div(); |
| 499 | # end answer inspection button |
892 | |
| 500 | # warning output |
893 | # warning output |
| 501 | if ($pg->{warnings} ne "") { |
894 | #if ($pg->{warnings} ne "") { |
| 502 | print CGI::hr(), $self->warningOutput($pg->{warnings}); |
895 | # print CGI::hr(), $self->warningOutput($pg->{warnings}); |
| 503 | } |
896 | #} |
| 504 | |
897 | |
| 505 | # debugging stuff |
898 | # debugging stuff |
| 506 | if (0) { |
899 | if (0) { |
| 507 | print |
900 | print |
| 508 | CGI::hr(), |
901 | CGI::hr(), |
| … | |
… | |
| 522 | return ""; |
915 | return ""; |
| 523 | } |
916 | } |
| 524 | |
917 | |
| 525 | ##### output utilities ##### |
918 | ##### output utilities ##### |
| 526 | |
919 | |
| 527 | sub attemptResults($$$$$$) { |
920 | sub attemptResults { |
| 528 | my $self = shift; |
921 | my $self = shift; |
| 529 | my $pg = shift; |
922 | my $pg = shift; |
| 530 | my $showAttemptAnswers = shift; |
923 | my $showAttemptAnswers = shift; |
| 531 | my $showCorrectAnswers = shift; |
924 | my $showCorrectAnswers = shift; |
| 532 | my $showAttemptResults = $showAttemptAnswers && shift; |
925 | my $showAttemptResults = $showAttemptAnswers && shift; |
| 533 | my $showSummary = shift; |
926 | my $showSummary = shift; |
| 534 | my $showAttemptPreview = shift || 0; |
927 | my $showAttemptPreview = shift || 0; |
|
|
928 | |
|
|
929 | my $ce = $self->r->ce; |
|
|
930 | |
| 535 | my $problemResult = $pg->{result}; # the overall result of the problem |
931 | my $problemResult = $pg->{result}; # the overall result of the problem |
| 536 | my @answerNames = @{ $pg->{flags}->{ANSWER_ENTRY_ORDER} }; |
932 | my @answerNames = @{ $pg->{flags}->{ANSWER_ENTRY_ORDER} }; |
| 537 | |
933 | |
| 538 | my $showMessages = $showAttemptAnswers && grep { $pg->{answers}->{$_}->{ans_message} } @answerNames; |
934 | my $showMessages = $showAttemptAnswers && grep { $pg->{answers}->{$_}->{ans_message} } @answerNames; |
| 539 | |
935 | |
|
|
936 | my $basename = "equation-" . $self->{set}->psvn. "." . $self->{problem}->problem_id . "-preview"; |
|
|
937 | my $imgGen = WeBWorK::PG::ImageGenerator->new( |
|
|
938 | tempDir => $ce->{webworkDirs}->{tmp}, |
|
|
939 | latex => $ce->{externalPrograms}->{latex}, |
|
|
940 | dvipng => $ce->{externalPrograms}->{dvipng}, |
|
|
941 | useCache => 1, |
|
|
942 | cacheDir => $ce->{webworkDirs}->{equationCache}, |
|
|
943 | cacheURL => $ce->{webworkURLs}->{equationCache}, |
|
|
944 | cacheDB => $ce->{webworkFiles}->{equationCacheDB}, |
|
|
945 | ); |
|
|
946 | |
|
|
947 | my $header; |
| 540 | my $header = CGI::th("Part"); |
948 | #$header .= CGI::th("Part"); |
| 541 | $header .= $showAttemptAnswers ? CGI::th("Entered") : ""; |
949 | $header .= $showAttemptAnswers ? CGI::th("Entered") : ""; |
| 542 | $header .= $showAttemptPreview ? CGI::th("Answer Preview") : ""; |
950 | $header .= $showAttemptPreview ? CGI::th("Answer Preview") : ""; |
| 543 | $header .= $showCorrectAnswers ? CGI::th("Correct") : ""; |
951 | $header .= $showCorrectAnswers ? CGI::th("Correct") : ""; |
| 544 | $header .= $showAttemptResults ? CGI::th("Result") : ""; |
952 | $header .= $showAttemptResults ? CGI::th("Result") : ""; |
| 545 | $header .= $showMessages ? CGI::th("messages") : ""; |
953 | $header .= $showMessages ? CGI::th("Messages") : ""; |
| 546 | my @tableRows = ( $header ); |
954 | my @tableRows = ( $header ); |
| 547 | my $numCorrect; |
955 | my $numCorrect; |
| 548 | foreach my $name (@answerNames) { |
956 | foreach my $name (@answerNames) { |
| 549 | my $answerResult = $pg->{answers}->{$name}; |
957 | my $answerResult = $pg->{answers}->{$name}; |
| 550 | my $studentAnswer = $answerResult->{student_ans}; # original_student_ans |
958 | my $studentAnswer = $answerResult->{student_ans}; # original_student_ans |
| 551 | my $preview = ($showAttemptPreview |
959 | my $preview = ($showAttemptPreview |
| 552 | ? $self->previewAnswer($answerResult) |
960 | ? $self->previewAnswer($answerResult, $imgGen) |
| 553 | : ""); |
961 | : ""); |
| 554 | my $correctAnswer = $answerResult->{correct_ans}; |
962 | my $correctAnswer = $answerResult->{correct_ans}; |
| 555 | my $answerScore = $answerResult->{score}; |
963 | my $answerScore = $answerResult->{score}; |
| 556 | my $answerMessage = $showMessages ? $answerResult->{ans_message} : ""; |
964 | my $answerMessage = $showMessages ? $answerResult->{ans_message} : ""; |
| 557 | |
965 | #FIXME --Can we be sure that $answerScore is an integer-- could the problem give partial credit? |
| 558 | $numCorrect += $answerScore > 0; |
966 | $numCorrect += $answerScore > 0; |
| 559 | my $resultString = $answerScore ? "correct" : "incorrect"; |
967 | my $resultString = $answerScore == 1 ? "correct" : "incorrect"; |
| 560 | |
968 | |
| 561 | # get rid of the goofy prefix on the answer names (supposedly, the format |
969 | # get rid of the goofy prefix on the answer names (supposedly, the format |
| 562 | # of the answer names is changeable. this only fixes it for "AnSwEr" |
970 | # of the answer names is changeable. this only fixes it for "AnSwEr" |
| 563 | $name =~ s/^AnSwEr//; |
971 | #$name =~ s/^AnSwEr//; |
| 564 | |
972 | |
|
|
973 | my $row; |
| 565 | my $row = CGI::td($name); |
974 | #$row .= CGI::td($name); |
| 566 | $row .= $showAttemptAnswers ? CGI::td($studentAnswer) : ""; |
975 | $row .= $showAttemptAnswers ? CGI::td($self->nbsp($studentAnswer)) : ""; |
| 567 | $row .= $showAttemptPreview ? CGI::td($preview) : ""; |
976 | $row .= $showAttemptPreview ? CGI::td($self->nbsp($preview)) : ""; |
| 568 | $row .= $showCorrectAnswers ? CGI::td($correctAnswer) : ""; |
977 | $row .= $showCorrectAnswers ? CGI::td($self->nbsp($correctAnswer)) : ""; |
| 569 | $row .= $showAttemptResults ? CGI::td($resultString) : ""; |
978 | $row .= $showAttemptResults ? CGI::td($self->nbsp($resultString)) : ""; |
| 570 | $row .= $answerMessage ? CGI::td($answerMessage) : ""; |
979 | $row .= $showMessages ? CGI::td($self->nbsp($answerMessage)) : ""; |
| 571 | push @tableRows, $row; |
980 | push @tableRows, $row; |
| 572 | } |
981 | } |
| 573 | |
982 | |
|
|
983 | # render equation images |
|
|
984 | $imgGen->render(refresh => 1); |
|
|
985 | |
| 574 | my $numIncorrectNoun = scalar @answerNames == 1 ? "question" : "questions"; |
986 | # my $numIncorrectNoun = scalar @answerNames == 1 ? "question" : "questions"; |
| 575 | my $scorePercent = int ($problemResult->{score} * 100) . "\%"; |
987 | my $scorePercent = sprintf("%.0f%%", $problemResult->{score} * 100); |
|
|
988 | # FIXME -- I left the old code in in case we have to back out. |
| 576 | my $summary = "On this attempt, you answered $numCorrect out of " |
989 | # my $summary = "On this attempt, you answered $numCorrect out of " |
| 577 | . scalar @answerNames . " $numIncorrectNoun correct, for a score of $scorePercent."; |
990 | # . scalar @answerNames . " $numIncorrectNoun correct, for a score of $scorePercent."; |
| 578 | return CGI::table({-class=>"attemptResults"}, CGI::Tr(\@tableRows)) . ($showSummary ? CGI::p($summary) : ""); |
991 | my $summary = ""; |
|
|
992 | if (scalar @answerNames == 1) { |
|
|
993 | if ($numCorrect == scalar @answerNames) { |
|
|
994 | $summary .= CGI::div({class=>"ResultsWithoutError"},"The above answer is correct."); |
|
|
995 | } else { |
|
|
996 | $summary .= CGI::div({class=>"ResultsWithError"},"The above answer is NOT correct."); |
|
|
997 | } |
|
|
998 | } else { |
|
|
999 | if ($numCorrect == scalar @answerNames) { |
|
|
1000 | $summary .= CGI::div({class=>"ResultsWithoutError"},"All of the above answers are correct."); |
|
|
1001 | } else { |
|
|
1002 | $summary .= CGI::div({class=>"ResultsWithError"},"At least one of the above answers is NOT correct."); |
|
|
1003 | } |
|
|
1004 | } |
|
|
1005 | |
|
|
1006 | return |
|
|
1007 | CGI::table({-class=>"attemptResults"}, CGI::Tr(\@tableRows)) |
|
|
1008 | . ($showSummary ? CGI::p({class=>'emphasis'},$summary) : ""); |
| 579 | } |
1009 | } |
| 580 | |
1010 | |
|
|
1011 | #sub nbsp { |
|
|
1012 | # my $str = shift; |
|
|
1013 | # ($str =~/\S/) ? $str : ' ' ; # returns non-breaking space for empty strings |
|
|
1014 | # # tricky cases: $str =0; |
|
|
1015 | # # $str is a complex number |
|
|
1016 | #} |
|
|
1017 | |
| 581 | sub viewOptions($) { |
1018 | sub viewOptions { |
| 582 | my $self = shift; |
1019 | my ($self) = @_; |
|
|
1020 | my $ce = $self->r->ce; |
|
|
1021 | |
| 583 | my $displayMode = $self->{displayMode}; |
1022 | my $displayMode = $self->{displayMode}; |
| 584 | my %must = %{ $self->{must} }; |
1023 | my %must = %{ $self->{must} }; |
| 585 | my %can = %{ $self->{can} }; |
1024 | my %can = %{ $self->{can} }; |
| 586 | my %will = %{ $self->{will} }; |
1025 | my %will = %{ $self->{will} }; |
| 587 | |
1026 | |
| 588 | my $optionLine; |
1027 | my $optionLine; |
| 589 | $can{showOldAnswers} and $optionLine .= join "", |
1028 | $can{showOldAnswers} and $optionLine .= join "", |
| 590 | "Show: ", |
1029 | "Show: ".CGI::br(), |
| 591 | CGI::checkbox( |
1030 | CGI::checkbox( |
| 592 | -name => "showOldAnswers", |
1031 | -name => "showOldAnswers", |
| 593 | -checked => $will{showOldAnswers}, |
1032 | -checked => $will{showOldAnswers}, |
| 594 | -label => "Saved answers", |
1033 | -label => "Saved answers", |
| 595 | ), " "; |
1034 | ), " ".CGI::br(); |
| 596 | $can{showCorrectAnswers} and $optionLine .= join "", |
1035 | |
| 597 | CGI::checkbox( |
|
|
| 598 | -name => "showCorrectAnswers", |
|
|
| 599 | -checked => $will{showCorrectAnswers}, |
|
|
| 600 | -label => "Correct answers", |
|
|
| 601 | ), " "; |
|
|
| 602 | $can{showHints} and $optionLine .= join "", |
|
|
| 603 | CGI::checkbox( |
|
|
| 604 | -name => "showHints", |
|
|
| 605 | -checked => $will{showHints}, |
|
|
| 606 | -label => "Hints", |
|
|
| 607 | ), " "; |
|
|
| 608 | $can{showSolutions} and $optionLine .= join "", |
|
|
| 609 | CGI::checkbox( |
|
|
| 610 | -name => "showSolutions", |
|
|
| 611 | -checked => $will{showSolutions}, |
|
|
| 612 | -label => "Solutions", |
|
|
| 613 | ), " "; |
|
|
| 614 | $optionLine and $optionLine .= join "", CGI::br(); |
1036 | $optionLine and $optionLine .= join "", CGI::br(); |
| 615 | |
1037 | |
|
|
1038 | my %display_modes = %{WeBWorK::PG::DISPLAY_MODES()}; |
|
|
1039 | my @active_modes = grep { exists $display_modes{$_} } |
|
|
1040 | @{$ce->{pg}->{displayModes}}; |
|
|
1041 | |
| 616 | return CGI::div({-style=>"border: thin groove; padding: 1ex; margin: 2ex"}, |
1042 | return CGI::div({-style=>"border: thin groove; padding: 1ex; margin: 2ex align: left"}, |
| 617 | "View equations as: ", |
1043 | "View equations as: ".CGI::br(), |
| 618 | CGI::radio_group( |
1044 | CGI::radio_group( |
| 619 | -name => "displayMode", |
1045 | -name => "displayMode", |
| 620 | -values => ['plainText', 'formattedText', 'images'], |
1046 | -values => \@active_modes, |
| 621 | -default => $displayMode, |
1047 | -default => $displayMode, |
|
|
1048 | -linebreak=>'true', |
| 622 | -labels => { |
1049 | -labels => { |
| 623 | plainText => "plain text", |
1050 | plainText => "plain", |
| 624 | formattedText => "formatted text", |
1051 | formattedText => "formatted", |
| 625 | images => "images", |
|
|
| 626 | } |
1052 | }, |
| 627 | ), CGI::br(), |
1053 | ), CGI::br(),CGI::hr(), |
| 628 | $optionLine, |
1054 | $optionLine, |
| 629 | CGI::submit(-name=>"redisplay", -label=>"Redisplay Problem"), |
1055 | CGI::submit(-name=>"redisplay", -label=>"Save Options"), |
| 630 | ); |
1056 | ); |
| 631 | } |
1057 | } |
| 632 | |
1058 | |
| 633 | sub previewAnswer($$) { |
1059 | sub previewAnswer { |
| 634 | my ($self, $answerResult) = @_; |
1060 | my ($self, $answerResult, $imgGen) = @_; |
| 635 | my $ce = $self->{ce}; |
1061 | my $ce = $self->r->ce; |
| 636 | my $effectiveUser = $self->{effectiveUser}; |
1062 | my $effectiveUser = $self->{effectiveUser}; |
| 637 | my $set = $self->{set}; |
1063 | my $set = $self->{set}; |
| 638 | my $problem = $self->{problem}; |
1064 | my $problem = $self->{problem}; |
| 639 | my $displayMode = $self->{displayMode}; |
1065 | my $displayMode = $self->{displayMode}; |
| 640 | |
1066 | |
| … | |
… | |
| 643 | # so we'll just deal with each case explicitly here. there's some code |
1069 | # so we'll just deal with each case explicitly here. there's some code |
| 644 | # duplication that can be dealt with later by abstracting out tth/dvipng/etc. |
1070 | # duplication that can be dealt with later by abstracting out tth/dvipng/etc. |
| 645 | |
1071 | |
| 646 | my $tex = $answerResult->{preview_latex_string}; |
1072 | my $tex = $answerResult->{preview_latex_string}; |
| 647 | |
1073 | |
| 648 | return "" if $tex eq ""; |
1074 | return "" unless defined $tex and $tex ne ""; |
| 649 | |
1075 | |
| 650 | if ($displayMode eq "plainText") { |
1076 | if ($displayMode eq "plainText") { |
| 651 | return $tex; |
1077 | return $tex; |
| 652 | } elsif ($displayMode eq "formattedText") { |
1078 | } elsif ($displayMode eq "formattedText") { |
| 653 | my $tthCommand = $ce->{externalPrograms}->{tth} |
1079 | my $tthCommand = $ce->{externalPrograms}->{tth} |
| … | |
… | |
| 660 | if ($?) { |
1086 | if ($?) { |
| 661 | return "<b>[tth failed: $? $@]</b>"; |
1087 | return "<b>[tth failed: $? $@]</b>"; |
| 662 | } |
1088 | } |
| 663 | return $result; |
1089 | return $result; |
| 664 | } elsif ($displayMode eq "images") { |
1090 | } elsif ($displayMode eq "images") { |
| 665 | # how are we going to name this? |
1091 | $imgGen->add($tex); |
| 666 | my $targetPathCommon = "/png/" |
1092 | } elsif ($displayMode eq "jsMath") { |
| 667 | . $effectiveUser->id . "." |
1093 | |
| 668 | . $set->set_id . "." |
1094 | return '<DIV CLASS="math">'.$tex.'</DIV>' ; |
| 669 | . $problem->problem_id . "." |
1095 | |
| 670 | . $answerResult->{ans_name} . ".png"; |
1096 | |
| 671 | |
1097 | |
| 672 | # figure out where to put things |
1098 | |
| 673 | my $wd = tempdir("webwork-dvipng-XXXXXXXX", DIR => $ce->{courseDirs}->{html_temp}); |
|
|
| 674 | my $latex = $ce->{externalPrograms}->{latex}; |
|
|
| 675 | my $dvipng = $ce->{externalPrograms}->{dvipng}; |
|
|
| 676 | my $targetPath = $ce->{courseDirs}->{html_temp} . $targetPathCommon; |
|
|
| 677 | # should use surePathToTmpFile, but we have to |
|
|
| 678 | # isolate it from the problem enivronment first |
|
|
| 679 | my $targetURL = $ce->{courseURLs}->{html_temp} . $targetPathCommon; |
|
|
| 680 | |
|
|
| 681 | # call dvipng to generate a preview |
|
|
| 682 | dvipng($wd, $latex, $dvipng, $tex, $targetPath); |
|
|
| 683 | if (-e $targetPath) { |
|
|
| 684 | return "<img src=\"$targetURL\" alt=\"$tex\" />"; |
|
|
| 685 | } else { |
|
|
| 686 | return "<b>[math2img failed]</b>"; |
|
|
| 687 | } |
|
|
| 688 | } |
1099 | } |
| 689 | } |
1100 | } |
| 690 | ##### logging subroutine #### |
|
|
| 691 | |
|
|
| 692 | |
|
|
| 693 | |
1101 | |
| 694 | ##### permission queries ##### |
1102 | ##### permission queries ##### |
| 695 | |
1103 | |
| 696 | # this stuff should be abstracted out into the permissions system |
1104 | # this stuff should be abstracted out into the permissions system |
| 697 | # however, the permission system only knows about things in the |
1105 | # however, the permission system only knows about things in the |
| 698 | # course environment and the username. hmmm... |
1106 | # course environment and the username. hmmm... |
| 699 | |
1107 | |
| 700 | # also, i should fix these so that they have a consistent calling |
1108 | # also, i should fix these so that they have a consistent calling |
| 701 | # format -- perhaps: |
1109 | # format -- perhaps: |
| 702 | # canPERM($courseEnv, $user, $set, $problem, $permissionLevel) |
1110 | # canPERM($ce, $user, $set, $problem, $permissionLevel) |
| 703 | |
1111 | |
| 704 | sub canShowCorrectAnswers($$) { |
1112 | sub canShowCorrectAnswers($$) { |
| 705 | my ($permissionLevel, $answerDate) = @_; |
1113 | my ($permissionLevel, $answerDate) = @_; |
| 706 | return $permissionLevel > 0 || time > $answerDate; |
1114 | return $permissionLevel > 0 || time > $answerDate; |
| 707 | } |
1115 | } |
| … | |
… | |
| 731 | sub mustRecordAnswers($) { |
1139 | sub mustRecordAnswers($) { |
| 732 | my ($permissionLevel) = @_; |
1140 | my ($permissionLevel) = @_; |
| 733 | return $permissionLevel == 0; |
1141 | return $permissionLevel == 0; |
| 734 | } |
1142 | } |
| 735 | |
1143 | |
|
|
1144 | |
|
|
1145 | # FIXME: does this even get used? |
|
|
1146 | sub submiterror { |
|
|
1147 | my $self = shift; |
|
|
1148 | my $submiterror = (defined($self->{submiterror}) ) ? $self->{submiterror} : ''; |
|
|
1149 | $submiterror; |
|
|
1150 | } |
| 736 | 1; |
1151 | 1; |