1: # The LearningOnline Network with CAPA
2: # input definitons
3:
4: package Apache::inputtags;
5: use strict;
6:
7: sub BEGIN {
8: &Apache::lonxml::register('Apache::inputtags',('textarea','textline','datasubmission'));
9: }
10:
11:
12: sub initialize_inputtags {
13: @Apache::inputtags::input=();
14: @Apache::inputtags::inputlist=();
15: @Apache::inputtags::response=();
16: @Apache::inputtags::responselist=();
17: @Apache::inputtags::answergroup=();
18: $Apache::inputtags::part='';
19: %Apache::inputtags::params=();
20: }
21:
22: sub start_input {
23: my ($parstack,$safeeval)=@_;
24: my $args ='';
25: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
26: my $id = &Apache::run::run("{$args;".'return $id}',$safeeval);
27: push (@Apache::inputtags::input,$id);
28: push (@Apache::inputtags::inputlist,$id);
29: return $id;
30: }
31:
32: sub end_input {
33: pop @Apache::inputtags::input;
34: return '';
35: }
36:
37: sub start_textarea {
38: my ($target,$token,$parstack,$parser,$safeeval)=@_;
39: my $result = "";
40: my $id = &start_input($parstack,$safeeval);
41: if ($target eq 'web') {
42: $result= '<textarea name="HWVAL'.$id.'" value="">';
43: }
44: return $result;
45: }
46:
47: sub end_textarea {
48: my ($target,$token,$parstack,$parser,$safeeval)=@_;
49: if ($target eq 'web') {
50: return "</textarea>";
51: }
52: &end_input;
53: return '';
54: }
55:
56: sub start_textline {
57: my ($target,$token,$parstack,$parser,$safeeval)=@_;
58: my $result = "";
59: if ($target eq 'web') {
60: my $args ='';
61: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
62: my $size = &Apache::run::run("{$args;".'return $size}',$safeeval);
63: if ($size eq '') { $size=20; }
64: my $oldresponse = $Apache::lonhomework::history{"resource.submission.$Apache::inputtags::part.$Apache::inputtags::response['-1']"};
65: $result= '<input type="text" name="HWVAL'.$Apache::inputtags::response['-1'].'" value="'.$oldresponse.'" size="'.$size.'">';
66: }
67: return $result;
68: }
69:
70: sub end_textline {
71: my ($target,$token,$parstack,$parser,$safeeval)=@_;
72: return "";
73: }
74:
75: #answergroup is deprecated
76: #sub start_answergroup {
77: # my ($target,$token,$parstack,$parser,$safeeval)=@_;
78: # my $args ='';
79: # if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
80: # my $id = &Apache::run::run("{$args;".'return $id}',$safeeval);
81: # push (@Apache::inputtags::answergroup,$id);
82: # if ($target == 'web') {
83: #
84: # }
85: # return '';
86: #}
87: #
88: #sub end_answergroup {
89: # my ($target,$token,$parstack,$parser,$safeeval)=@_;
90: # return ''; # <answergroup> has ben deprecated
91: # my $args ='';
92: # if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
93: # my $id = &Apache::run::run("{$args;".'return $id}',$safeeval);
94: # push (@Apache::inputtags::answergroup,$id);
95: # my $result='';
96: # my $button='<input type="submit" name="submit" value="Submit All Answers">';
97: # my $showbutton='1';
98: # my $usedtry='1';
99: # my $response='';
100: # if ( $target == 'web' ) {
101: # if ( defined $ENV{'form.submit'}) {
102: # }
103: # if ($showbutton > 0) { $result.=$button }
104: # }
105: # pop @Apache::inputtags::answergroup;
106: # return $result;
107: #}
108:
109:
110: sub start_datasubmission {
111: }
112:
113: sub end_datasubmission {
114: my ($target,$token,$parstack,$parser,$safeeval)=@_;
115: if ( $target == 'web' ) {
116: return '<input type="submit" name="submit" value="Submit All Data">';
117: }
118: return '';
119: }
120:
121: sub finalizeawards {
122: my $result='';
123: my $award;
124: if ($#_ == '-1') { $result = "NO_RESPONSE"; }
125: foreach $award (@_) { if ($award eq '') {$result='MISSING_ANSWER'; last;}}
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 'APPROX_ANS') {$result=$award; last;} }
149: }
150: if ($result eq '' ) { $result='EXACT_ANS'; }
151: return $result
152: }
153:
154: sub decideoutput {
155: my ($award)=@_;
156: my $message='';
157: my $button=0;
158: if ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
159: $message = "Correct computer gets %s";
160: $button=0;
161: } elsif ($award eq 'NO_RESPONSE') {
162: $message = '';
163: $button=1;
164: } elsif ($award eq 'MISSING_ANSWER') {
165: $message = 'Some parts were not submitted';
166: $button = 1;
167: } elsif ($award eq 'WANTED_NUMERIC') {
168: $message = "This question expects a numeric answer";
169: $button=1;
170: } elsif ($award eq 'SIG_FAIL') {
171: $message = "Please adjust significant figures, you provided %s significant figures";
172: $button=1;
173: } elsif ($award eq 'UNIT_FAIL') {
174: $message = "Units incorrect, Computer reads units as %s";
175: $button=1;
176: } elsif ($award eq 'UNIT_NOTNEEDED') {
177: $message = "Only a number required, Computer reads units of %s";
178: $button=1;
179: } elsif ($award eq 'NO_UNIT') {
180: $message = "Units required";
181: $button=1;
182: } elsif ($award eq 'BAD_FORMULA') {
183: $message = "Unable to understand formula";
184: $button=1;
185: } elsif ($award eq 'INCORRECT') {
186: $message = "Incorrect";
187: $button=1;
188: } else {
189: $message = "Unknown message: $award";
190: $button=1;
191: }
192: return ($button,$message);
193: }
194:
195: sub setgradedata {
196: my ($award,$id) = @_;
197: if ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
198: $Apache::lonhomework::results{"resource.tries.$id"} =
199: $Apache::lonhomework::history{"resource.tries.$id"} + 1;
200: $Apache::lonhomework::results{"resource.solved.$id"} =
201: 'correct_by_student';
202: $Apache::lonhomework::results{"resource.awarded.$id"} = '1';
203: } elsif ( $award eq 'INCORRECT' ) {
204: $Apache::lonhomework::results{"resource.tries.$id"} =
205: $Apache::lonhomework::history{"resource.tries.$id"} + 1;
206: $Apache::lonhomework::results{"resource.solved.$id"} =
207: 'incorrect_attempted';
208: } else {
209: $Apache::lonhomework::results{"resource.solved.$id"} =
210: 'incorrect_attempted';
211: }
212: $Apache::lonhomework::results{"resource.award.$id"} = $award;
213: }
214:
215: sub grade {
216: my ($target) = @_;
217: my $id = $Apache::inputtags::part;
218: my $result='';
219: my $response='';
220: if ( $target == 'web' ) {
221: if ( defined $ENV{'form.submit'}) {
222: my @awards = ();
223: &Apache::lonxml::debug("$#Apache::inputtags::responselist");
224: foreach $response (@Apache::inputtags::responselist) {
225: &Apache::lonxml::debug("looking for response.awarddetail.$id.$response");
226: my $value=$Apache::lonhomework::results{"resource.awarddetail.$id.$response"};
227: if ( $value ne '' ) {
228: &Apache::lonxml::debug("keep ing $value from $response for $id");
229: push (@awards,$value);
230: } else {
231: &Apache::lonxml::debug("skipping $value from $response for $id");
232: }
233: }
234: my $finalaward = &finalizeawards(@awards);
235: &Apache::lonxml::debug("final award $finalaward");
236: &setgradedata($finalaward,$id);
237: }
238: }
239: return $result;
240: }
241:
242: sub gradestatus {
243: my ($id) = @_;
244: my $showbutton = 1;
245: my $message = '';
246: my $award = $Apache::lonhomework::history{"resource.award.$id"};
247: &Apache::lonxml::debug("Found Award |$award|");
248: if ( $award ne '' ) {
249: &Apache::lonxml::debug('Getting message');
250: ($showbutton,$message) = &decideoutput($award);
251: }
252: my $button='';
253: my $tries = $Apache::lonhomework::history{"resource.tries.$id"};
254: my $maxtries = $Apache::lonhomework::history{"resource.maxtries.$id"};
255: if ( $tries eq '' ) { $tries = '0'; }
256: if ( $maxtries eq '' ) { $maxtries = '2'; }
257: my $trystr='';
258: if ( $showbutton ) {
259: $trystr = "<br></br>Tries $tries/$maxtries";
260: }
261: if ( $tries >= $maxtries ) { $showbutton = 0; }
262: if ( $showbutton ) {
263: $button = '<input type="submit" name="submit" value="Submit All Answers"><br></br>';
264: }
265: return $button.$message.$trystr;
266: }
267: 1;
268: __END__
269:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>