| … | |
… | |
| 6 | use CGI qw(:html :form); |
6 | use CGI qw(:html :form); |
| 7 | use WeBWorK::Utils qw(ref2string); |
7 | use WeBWorK::Utils qw(ref2string); |
| 8 | use WeBWorK::PG; |
8 | use WeBWorK::PG; |
| 9 | use WeBWorK::Form; |
9 | use WeBWorK::Form; |
| 10 | |
10 | |
| 11 | # NEW form fields |
|
|
| 12 | # |
|
|
| 13 | # user |
11 | # user |
| 14 | # key |
12 | # key |
| 15 | # |
13 | # |
| 16 | # displayMode |
14 | # displayMode |
| 17 | # showOldAnswers |
15 | # showOldAnswers |
| 18 | # showCorrectAnswers |
16 | # showCorrectAnswers |
| 19 | # showHints |
17 | # showHints |
| 20 | # showSolutions |
18 | # showSolutions |
| 21 | # |
19 | # |
|
|
20 | # AnSwEr# - answer blanks in problem |
|
|
21 | # |
|
|
22 | # redisplay - name of the "Redisplay" button |
| 22 | # submitAnswers - name of "Submit Answers" button |
23 | # processAnswers - name of "Submit Answers" button |
| 23 | |
24 | |
| 24 | sub title { |
25 | sub title { |
| 25 | my ($self, $setName, $problemNumber) = @_; |
26 | my ($self, $setName, $problemNumber) = @_; |
| 26 | my $userName = $self->{r}->param('user'); |
27 | my $userName = $self->{r}->param('user'); |
| 27 | return "Problem $problemNumber of problem set $setName for $userName"; |
28 | return "Problem $problemNumber of problem set $setName for $userName"; |
| … | |
… | |
| 44 | my $user = $classlist->getUser($userName); |
45 | my $user = $classlist->getUser($userName); |
| 45 | my $set = $wwdb->getSet($userName, $setName); |
46 | my $set = $wwdb->getSet($userName, $setName); |
| 46 | my $problem = $wwdb->getProblem($userName, $setName, $problemNumber); |
47 | my $problem = $wwdb->getProblem($userName, $setName, $problemNumber); |
| 47 | my $psvn = $wwdb->getPSVN($userName, $setName); |
48 | my $psvn = $wwdb->getPSVN($userName, $setName); |
| 48 | |
49 | |
| 49 | # set options from form fields |
50 | # set options from form fields (see comment at top of file for names) |
| 50 | my $displayMode = $r->param("displayMode") || $courseEnv->{pg}->{options}->{displayMode}; |
51 | my $displayMode = $r->param("displayMode") || $courseEnv->{pg}->{options}->{displayMode}; |
| 51 | my $showOldAnswers = $r->param("showOldAnswers") || $courseEnv->{pg}->{options}->{showOldAnswers}; |
52 | my $showOldAnswers = $r->param("showOldAnswers") || $courseEnv->{pg}->{options}->{showOldAnswers}; |
| 52 | my $showCorrectAnswers = $r->param("showCorrectAnswers") || $courseEnv->{pg}->{options}->{showCorrectAnswers}; |
53 | my $showCorrectAnswers = $r->param("showCorrectAnswers") || $courseEnv->{pg}->{options}->{showCorrectAnswers}; |
| 53 | my $showHints = $r->param("showHints") || $courseEnv->{pg}->{options}->{showHints}; |
54 | my $showHints = $r->param("showHints") || $courseEnv->{pg}->{options}->{showHints}; |
| 54 | my $showSolutions = $r->param("showSolutions") || $courseEnv->{pg}->{options}->{showSolutions}; |
55 | my $showSolutions = $r->param("showSolutions") || $courseEnv->{pg}->{options}->{showSolutions}; |
|
|
56 | my $redisplay = $r->param("redisplay"); |
| 55 | my $processAnswers = $r->param("submitAnswers"); |
57 | my $processAnswers = $r->param("submitAnswers"); |
| 56 | |
58 | |
| 57 | # coerce form fields into CGI::Vars format |
59 | # coerce form fields into CGI::Vars format |
| 58 | my $formFields = { WeBWorK::Form->new_from_paramable($r)->Vars }; |
60 | my $formFields = { WeBWorK::Form->new_from_paramable($r)->Vars }; |
| 59 | |
61 | |
| … | |
… | |
| 65 | # 3. Latex2HTML massaging code |
67 | # 3. Latex2HTML massaging code |
| 66 | # 4. store submitted answers hash in database for sticky answers |
68 | # 4. store submitted answers hash in database for sticky answers |
| 67 | # 5. deal with the results of answer evaluation and grading :p |
69 | # 5. deal with the results of answer evaluation and grading :p |
| 68 | # 6. introduce a recordAnswers option, which works on the same principle as |
70 | # 6. introduce a recordAnswers option, which works on the same principle as |
| 69 | # the other priv-based options |
71 | # the other priv-based options |
|
|
72 | # 7. make warnings work |
| 70 | |
73 | |
| 71 | my $pg = WeBWorK::PG->new( |
74 | my $pg = WeBWorK::PG->new( |
| 72 | $courseEnv, |
75 | $courseEnv, |
| 73 | $r->param('user'), |
76 | $r->param('user'), |
| 74 | $r->param('key'), |
77 | $r->param('key'), |
| … | |
… | |
| 76 | $problemNumber, |
79 | $problemNumber, |
| 77 | { # translation options |
80 | { # translation options |
| 78 | displayMode => $displayMode, |
81 | displayMode => $displayMode, |
| 79 | showHints => $showHints, |
82 | showHints => $showHints, |
| 80 | showSolutions => $showSolutions, |
83 | showSolutions => $showSolutions, |
| 81 | processAnswers => $processAnswers, |
84 | processAnswers => $processAnswers ? 1 : 0, |
| 82 | }, |
85 | }, |
| 83 | $formFields |
86 | $formFields |
| 84 | ); |
87 | ); |
| 85 | |
88 | |
| 86 | # return ( |
89 | if ($pg->{flags}->{error_flag}) { |
| 87 | # h1("Problem.pm"), |
90 | # there was an error in translation |
| 88 | # table( |
91 | print h2("Software Error"); |
| 89 | # Tr(td("user"), td($r->param('userName'))), |
92 | print p(<<EOF); |
| 90 | # Tr(td("key"), td($r->param('key'))), |
93 | WeBWorK has encountered a software error while attempting to process this problem. |
| 91 | # Tr(td("set"), td($setName)), |
94 | It is likely that there is an error in the problem itself. |
| 92 | # Tr(td("problem"), td($problemNumber)), |
95 | If you are a student, contact your professor to have the error corrected. |
| 93 | # ), |
96 | If you are a professor, please consut the error output below for more informaiton. |
| 94 | # #pre(hash2string($pg, 0)), |
97 | EOF |
| 95 | # hash2string($pg, 1), |
98 | print h3("Error messages"), blockquote(pre($pg->{errors})); |
| 96 | # ); |
99 | print h3("Error context"), blockquote(pre($pg->{body_text})); |
|
|
100 | return ""; |
|
|
101 | } |
| 97 | |
102 | |
| 98 | # View options form |
103 | # Previous answer results |
|
|
104 | if ($processAnswers) { |
|
|
105 | print h3("Results of your latest attempt"); |
|
|
106 | print attemptResults($pg, $showCorrectAnswers, $pg->{flags}->{showPartialCorrectAnswers}); |
|
|
107 | print hr(); |
|
|
108 | } |
|
|
109 | |
|
|
110 | # main form |
| 99 | print startform("POST", $r->uri); |
111 | print startform("POST", $r->uri); |
| 100 | print $self->hidden_authen_fields; |
112 | print $self->hidden_authen_fields; |
|
|
113 | print $self->hidden_fields(qw(displayMode showOldAnswers showCorrectAnswers showHints showSolutions)); |
|
|
114 | print p($pg->{body_text}); |
|
|
115 | print p(submit(-name=>"submitAnswers", -label=>"Submit Answers")); |
|
|
116 | print endform(); |
|
|
117 | print hr(); |
|
|
118 | |
|
|
119 | # view options |
|
|
120 | # what i'd really like to do here is: |
|
|
121 | # - preserve the answers currently in the form fields |
|
|
122 | # - display the answer summary box |
|
|
123 | # - NOT record answers UNDER ANY CIRCUMSTANCES! |
|
|
124 | print startform("POST", $r->uri); |
|
|
125 | #print $self->hidden_fields(); |
| 101 | print p("View equations as: ", |
126 | print p("View equations as: ", |
| 102 | radio_group( |
127 | radio_group( |
| 103 | -name => "displayMode", |
128 | -name => "displayMode", |
| 104 | -values => ['plainText', 'formattedText', 'images'], |
129 | -values => ['plainText', 'formattedText', 'images'], |
| 105 | -default => $displayMode, |
130 | -default => $displayMode, |
| … | |
… | |
| 112 | checkbox( |
137 | checkbox( |
| 113 | -name => "showOldAnswers", |
138 | -name => "showOldAnswers", |
| 114 | -checked => $showOldAnswers, |
139 | -checked => $showOldAnswers, |
| 115 | -label => "Show old answers", |
140 | -label => "Show old answers", |
| 116 | ), br(), |
141 | ), br(), |
| 117 | submit(-name=>'redisplay') |
142 | checkbox( |
|
|
143 | -name => "showCorrectAnswers", |
|
|
144 | -checked => $showCorrectAnswers, |
|
|
145 | -label => "Show correct answers", |
|
|
146 | ), br(), |
|
|
147 | checkbox( |
|
|
148 | -name => "showHints", |
|
|
149 | -checked => $showHints, |
|
|
150 | -label => "Show hints", |
|
|
151 | ), br(), |
|
|
152 | checkbox( |
|
|
153 | -name => "showSolutions", |
|
|
154 | -checked => $showSolutions, |
|
|
155 | -label => "Show solutions", |
|
|
156 | ), br(), |
| 118 | ); |
157 | ); |
| 119 | print endform(); |
158 | print p(submit(-name=>"redisplay", -label=>"Redisplay Problem")); |
| 120 | print hr(); |
|
|
| 121 | |
|
|
| 122 | # Previous answer results |
|
|
| 123 | |
|
|
| 124 | |
|
|
| 125 | # Problem form |
|
|
| 126 | print startform("POST", $r->uri); |
|
|
| 127 | print $self->hidden_authen_fields; |
|
|
| 128 | print p($pg->{body_text}); |
|
|
| 129 | print p(submit(-name=>"submitAnswers", -label=>"Submit Answers")); |
|
|
| 130 | print endform(); |
159 | print endform(); |
| 131 | print hr(); |
160 | print hr(); |
| 132 | |
161 | |
| 133 | # debugging stuff |
162 | # debugging stuff |
| 134 | print h2("debugging information"); |
163 | print h2("debugging information"); |
| … | |
… | |
| 138 | print ref2string($pg, {'WeBWorK::PG::Translator' => 1}); |
167 | print ref2string($pg, {'WeBWorK::PG::Translator' => 1}); |
| 139 | |
168 | |
| 140 | return ""; |
169 | return ""; |
| 141 | } |
170 | } |
| 142 | |
171 | |
|
|
172 | sub attemptResults { |
|
|
173 | my $pg = shift; |
|
|
174 | my $showCorrectAnswers = shift; |
|
|
175 | my $showAttemptResults = shift; |
|
|
176 | my $problemResult = $pg->{result}; # the overall result of the problem |
|
|
177 | my @answerNames = @{ $pg->{flags}->{ANSWER_ENTRY_ORDER} }; |
|
|
178 | |
|
|
179 | my $header = th("answer") . th("attempt"); |
|
|
180 | $header .= $showCorrectAnswers ? th("correct") : ""; |
|
|
181 | $header .= $showAttemptResults ? th("result") : ""; |
|
|
182 | $header .= th("messages"); |
|
|
183 | my @tableRows = ( $header ); |
|
|
184 | my $numCorrect; |
|
|
185 | foreach my $name (@answerNames) { |
|
|
186 | my $answerResult = $pg->{answers}->{$name}; |
|
|
187 | my $studentAnswer = $answerResult->{student_ans}; |
|
|
188 | my $correctAnswer = $answerResult->{correct_ans}; |
|
|
189 | my $answerScore = $answerResult->{score}; |
|
|
190 | my $answerMessage = $answerResult->{ans_message}; |
|
|
191 | |
|
|
192 | $numCorrect += $answerScore > 0; |
|
|
193 | my $resultString = $answerScore ? "correct :^)" : "incorrect >:("; |
|
|
194 | |
|
|
195 | my $row = td($name) . td($studentAnswer); |
|
|
196 | $row .= $showCorrectAnswers ? td($correctAnswer) : ""; |
|
|
197 | $row .= $showAttemptResults ? td($resultString) : ""; |
|
|
198 | $row .= $answerMessage ? td($answerMessage) : ""; |
|
|
199 | push @tableRows, $row; |
|
|
200 | } |
|
|
201 | |
|
|
202 | my $scorePercent = int ($problemResult->{score} * 100) . "\%"; |
|
|
203 | my $message = i($problemResult->{msg}); |
|
|
204 | my $summary = "You answered $numCorrect questions out of " |
|
|
205 | . scalar @answerNames . " correct, for a score of $scorePercent."; |
|
|
206 | return table({-border=>1}, Tr(\@tableRows)) . p($message, br(), $summary); |
|
|
207 | } |
|
|
208 | |
| 143 | 1; |
209 | 1; |