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