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