1: # The LearningOnline Network with CAPA
2: # input definitons
3: # 2/19 Guy
4:
5: package Apache::inputtags;
6: use strict;
7:
8: sub BEGIN {
9: &Apache::lonxml::register('Apache::inputtags',('textarea','textline','datasubmission'));
10: }
11:
12:
13: sub initialize_inputtags {
14: # list of current input ids
15: @Apache::inputtags::input=();
16: # list of all input ids seen in this problem
17: @Apache::inputtags::inputlist=();
18: # list of all current response ids
19: @Apache::inputtags::response=();
20: #list of all response ids seen in this problem
21: @Apache::inputtags::responselist=();
22: # id of current part, 0 means that no part is current (inside <problem> only
23: $Apache::inputtags::part='';
24: # list of problem date statuses, the first element is for <problem>
25: #if there is a second element it is for the current <part>
26: @Apache::inputtags::status=();
27: #hash of defined params for the current response
28: %Apache::inputtags::params=();
29: }
30:
31: sub start_input {
32: my ($parstack,$safeeval)=@_;
33: my $id = &Apache::lonxml::get_param('id',$parstack,$safeeval);
34: if ($id eq '') { $id = $Apache::lonxml::curdepth; }
35: push (@Apache::inputtags::input,$id);
36: push (@Apache::inputtags::inputlist,$id);
37: return $id;
38: }
39:
40: sub end_input {
41: pop @Apache::inputtags::input;
42: return '';
43: }
44:
45: sub start_textarea {
46: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
47: my $result = "";
48: my $id = &start_input($parstack,$safeeval);
49: if ($target eq 'web') {
50: my $oldresponse = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.$Apache::inputtags::response['-1'].submission"};
51: my $cols = &Apache::lonxml::get_param('cols',$parstack,$safeeval);
52: if ( $cols eq '') { $cols = 80; }
53: my $rows = &Apache::lonxml::get_param('rows',$parstack,$safeeval);
54: if ( $rows eq '') { $rows = 10; }
55: $result= '<textarea name="HWVAL'.$Apache::inputtags::response['-1'].'" '.
56: "rows=\"$rows\" cols=\"$cols\">".$oldresponse;
57: if ($oldresponse ne '') {
58: #get rid of any startup text if the user has already responded
59: &Apache::lonxml::get_all_text("/textarea",$$parser[$#$parser]);
60: }
61: }
62: return $result;
63: }
64:
65: sub end_textarea {
66: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
67: if ($target eq 'web') {
68: return "</textarea>";
69: }
70: &end_input;
71: return '';
72: }
73:
74: sub start_textline {
75: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
76: my $result = "";
77: if ($target eq 'web') {
78: my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
79: if ($size eq '') { $size=20; }
80: my $oldresponse = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.$Apache::inputtags::response['-1'].submission"};
81: $result= '<input type="text" name="HWVAL'.$Apache::inputtags::response['-1'].'" value="'.$oldresponse.'" size="'.$size.'" />';
82: }
83: if ($target eq 'edit') {
84: $result.=&Apache::edit::tag_start($target,$token,&Apache::lonxml::description($token));
85: $result.=&Apache::edit::text_arg('Size:','size',$token,'5')."</td></tr>";
86: $result.=&Apache::edit::end_table;
87: }
88: if ($target eq 'modified') {
89: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'size');
90: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
91: }
92: return $result;
93: }
94:
95: sub end_textline {
96: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
97: if ($target eq 'edit') { return ('','no'); }
98: return "";
99: }
100:
101: sub start_datasubmission {
102: return '';
103: }
104:
105: sub end_datasubmission {
106: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
107: if ( $target == 'web' ) {
108: return '<input type="submit" name="submit" value="Submit All Data" />';
109: }
110: return '';
111: }
112:
113: sub finalizeawards {
114: my $result='';
115: my $award;
116: if ($#_ == '-1') { $result = "NO_RESPONSE"; }
117: if ($result eq '' ) {
118: foreach $award (@_) { if ($award eq '') {$result='MISSING_ANSWER'; last;}}
119: }
120: if ($result eq '' ) {
121: foreach $award (@_) { if ($award eq 'ERROR') {$result='ERROR'; last;}}
122: }
123: if ($result eq '' ) {
124: foreach $award (@_) { if ($award eq 'NO_RESPONSE') {$result='NO_RESPONSE'; last;} }
125: }
126:
127: if ($result eq '' ) {
128: foreach $award (@_) {
129: if ($award eq 'UNIT_FAIL' ||
130: $award eq 'NO_UNIT' ||
131: $award eq 'UNIT_NOTNEEDED') {
132: $result=$award; last;
133: }
134: }
135: }
136: if ($result eq '' ) {
137: foreach $award (@_) {
138: if ($award eq 'WANTED_NUMERIC' ||
139: $award eq 'BAD_FORMULA') {$result=$award; last;}
140: }
141: }
142: if ($result eq '' ) {
143: foreach $award (@_) { if ($award eq 'SIG_FAIL') {$result=$award; last;} }
144: }
145: if ($result eq '' ) {
146: foreach $award (@_) { if ($award eq 'INCORRECT') {$result=$award; last;} }
147: }
148: if ($result eq '' ) {
149: foreach $award (@_) { if ($award eq 'SUBMITTED') {$result=$award; last;} }
150: }
151: if ($result eq '' ) {
152: foreach $award (@_) { if ($award eq 'APPROX_ANS') {$result=$award; last;} }
153: }
154: if ($result eq '' ) { $result='EXACT_ANS'; }
155: return $result
156: }
157:
158: sub decideoutput {
159: my ($award,$solved)=@_;
160: my $message='';
161: my $button=0;
162: if ($solved =~ /^correct/) {
163: $message = "<b>You are correct.</b> Your receipt is ".
164: &Apache::lonnet::receipt;
165: $button=0;
166: } elsif ($solved =~ /^excused/) {
167: $message = "<b>You are excused from the problem.</b>";
168: $button=0;
169: } elsif ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
170: if ($solved =~ /^incorrect/ || $solved eq '') {
171: $message = "Incorrect";
172: $button=1;
173: } else {
174: $message = "<b>You are correct.</b> Your receipt is ".
175: &Apache::lonnet::receipt;
176: $button=0;
177: }
178: } elsif ($award eq 'NO_RESPONSE') {
179: $message = '';
180: $button=1;
181: } elsif ($award eq 'MISSING_ANSWER') {
182: $message = 'Some parts were not submitted';
183: $button = 1;
184: } elsif ($award eq 'WANTED_NUMERIC') {
185: $message = "This question expects a numeric answer";
186: $button=1;
187: } elsif ($award eq 'SIG_FAIL') {
188: $message = "Please adjust significant figures.";# you provided %s significant figures";
189: $button=1;
190: } elsif ($award eq 'UNIT_FAIL') {
191: $message = "Units incorrect."; #Computer reads units as %s";
192: $button=1;
193: } elsif ($award eq 'UNIT_NOTNEEDED') {
194: $message = "Only a number required.";# Computer reads units of %s";
195: $button=1;
196: } elsif ($award eq 'NO_UNIT') {
197: $message = "Units required";
198: $button=1;
199: } elsif ($award eq 'BAD_FORMULA') {
200: $message = "Unable to understand formula";
201: $button=1;
202: } elsif ($award eq 'INCORRECT') {
203: $message = "Incorrect";
204: $button=1;
205: } elsif ($award eq 'SUBMITTED') {
206: $message = "Your submission has been recorded.";
207: $button=1;
208: } else {
209: $message = "Unknown message: $award";
210: $button=1;
211: }
212: return ($button,$message);
213: }
214:
215: sub setgradedata {
216: my ($award,$id) = @_;
217: if ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
218: $Apache::lonhomework::results{"resource.$id.tries"} =
219: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
220: $Apache::lonhomework::results{"resource.$id.solved"} =
221: 'correct_by_student';
222: $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
223: } elsif ( $award eq 'INCORRECT' ) {
224: $Apache::lonhomework::results{"resource.$id.tries"} =
225: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
226: $Apache::lonhomework::results{"resource.$id.solved"} =
227: 'incorrect_attempted';
228: } elsif ( $award eq 'SUBMITTED' ) {
229: $Apache::lonhomework::results{"resource.$id.tries"} =
230: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
231: $Apache::lonhomework::results{"resource.$id.solved"} =
232: 'ungraded_attempted';
233: } else {
234: $Apache::lonhomework::results{"resource.$id.solved"} =
235: 'incorrect_attempted';
236: }
237: $Apache::lonhomework::results{"resource.$id.award"} = $award;
238: }
239:
240: sub grade {
241: my ($target) = @_;
242: my $id = $Apache::inputtags::part;
243: # my $result='';
244: my $response='';
245: if ( $target == 'web' ) {
246: if ( defined $ENV{'form.submitted'}) {
247: my @awards = ();
248: &Apache::lonxml::debug("$#Apache::inputtags::responselist");
249: foreach $response (@Apache::inputtags::responselist) {
250: &Apache::lonxml::debug("looking for response.$id.$response.awarddetail");
251: my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"};
252: if ( $value ne '' ) {
253: &Apache::lonxml::debug("keeping $value from $response for $id");
254: push (@awards,$value);
255: } else {
256: &Apache::lonxml::debug("skipping $value from $response for $id");
257: }
258: }
259: my $finalaward = &finalizeawards(@awards);
260: &Apache::lonxml::debug("final award $finalaward");
261: &setgradedata($finalaward,$id);
262: }
263: }
264: return '';
265: }
266:
267: sub gradestatus {
268: my ($id) = @_;
269: my $showbutton = 1;
270: my $message = '';
271: my $trystr='';
272: my $button='';
273:
274: my $status = $Apache::inputtags::status['-1'];
275: &Apache::lonxml::debug("gradestatus has :$status:");
276: if ( $status ne 'CLOSED' ) {
277: my $award = $Apache::lonhomework::history{"resource.$id.award"};
278: my $solved = $Apache::lonhomework::history{"resource.$id.solved"};
279: &Apache::lonxml::debug("Found Award |$award|$solved|");
280: if ( $award ne '' ) {
281: &Apache::lonxml::debug('Getting message');
282: ($showbutton,$message) = &decideoutput($award,$solved);
283: $message="<br /><table bgcolor=\"#aaffaa\"><tr><td>$message</td></tr></table>";
284: }
285: my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
286: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
287: &Apache::lonxml::debug("got maxtries of :$maxtries:");
288: if ( $tries eq '' ) { $tries = '0'; }
289: if ( $maxtries eq '' ) { $maxtries = '2'; }
290: if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; }
291: if ( $showbutton ) {
292: $trystr = "<br />Tries $tries/$maxtries";
293: }
294: if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
295: if ( $showbutton ) {
296: $button = '<br /><input type="submit" name="submit" value="Submit All Answers" />';
297: }
298: }
299: return $button.$message.$trystr;
300: }
301: 1;
302: __END__
303:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>