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