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