Annotation of loncom/homework/inputtags.pm, revision 1.14
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # input definitons
3:
4: package Apache::inputtags;
5: use strict;
6:
7: sub BEGIN {
1.10 albertel 8: &Apache::lonxml::register('Apache::inputtags',('textarea','textline','datasubmission'));
1.1 albertel 9: }
10:
1.7 albertel 11:
1.1 albertel 12: sub initialize_inputtags {
1.7 albertel 13: @Apache::inputtags::input=();
1.14 ! albertel 14: @Apache::inputtags::inputlist=();
1.7 albertel 15: @Apache::inputtags::response=();
1.9 albertel 16: @Apache::inputtags::responselist=();
1.7 albertel 17: @Apache::inputtags::answergroup=();
1.8 albertel 18: $Apache::inputtags::part='';
1.7 albertel 19: %Apache::inputtags::params=();
1.1 albertel 20: }
21:
1.14 ! albertel 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:
1.6 albertel 37: sub start_textarea {
38: my ($target,$token,$parstack,$parser,$safeeval)=@_;
39: my $result = "";
1.14 ! albertel 40: my $id = &start_input($parstack,$safeeval);
1.6 albertel 41: if ($target eq 'web') {
1.14 ! albertel 42: $result= '<textarea name="HWVAL'.$id.'" value="">';
1.6 albertel 43: }
44: return $result;
45: }
46:
47: sub end_textarea {
48: my ($target,$token,$parstack,$parser,$safeeval)=@_;
1.10 albertel 49: if ($target eq 'web') {
50: return "</textarea>";
51: }
1.14 ! albertel 52: &end_input;
1.10 albertel 53: return '';
1.6 albertel 54: }
55:
1.1 albertel 56: sub start_textline {
57: my ($target,$token,$parstack,$parser,$safeeval)=@_;
58: my $result = "";
59: if ($target eq 'web') {
1.10 albertel 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; }
1.14 ! albertel 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.'">';
1.1 albertel 66: }
67: return $result;
68: }
69:
70: sub end_textline {
71: my ($target,$token,$parstack,$parser,$safeeval)=@_;
1.6 albertel 72: return "";
1.1 albertel 73: }
74:
1.10 albertel 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: #}
1.6 albertel 108:
109:
110: sub start_datasubmission {
111: }
112:
113: sub end_datasubmission {
114: my ($target,$token,$parstack,$parser,$safeeval)=@_;
115: if ( $target == 'web' ) {
1.7 albertel 116: return '<input type="submit" name="submit" value="Submit All Data">';
1.2 albertel 117: }
1.10 albertel 118: return '';
1.9 albertel 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:
1.10 albertel 154: sub decideoutput {
155: my ($award)=@_;
156: my $message='';
157: my $button=0;
158: if ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
1.12 albertel 159: $message = "Correct computer gets %s";
160: $button=0;
1.13 albertel 161: } elsif ($award eq 'NO_RESPONSE') {
162: $message = '';
163: $button=1;
1.14 ! albertel 164: } elsif ($award eq 'MISSING_ANSWER') {
! 165: $message = 'Some parts were not submitted';
! 166: $button = 1;
1.10 albertel 167: } elsif ($award eq 'WANTED_NUMERIC') {
168: $message = "This question expects a numeric answer";
1.12 albertel 169: $button=1;
1.10 albertel 170: } elsif ($award eq 'SIG_FAIL') {
171: $message = "Please adjust significant figures, you provided %s significant figures";
1.12 albertel 172: $button=1;
1.10 albertel 173: } elsif ($award eq 'UNIT_FAIL') {
174: $message = "Units incorrect, Computer reads units as %s";
1.12 albertel 175: $button=1;
1.10 albertel 176: } elsif ($award eq 'UNIT_NOTNEEDED') {
177: $message = "Only a number required, Computer reads units of %s";
1.12 albertel 178: $button=1;
1.10 albertel 179: } elsif ($award eq 'NO_UNIT') {
180: $message = "Units required";
1.12 albertel 181: $button=1;
1.10 albertel 182: } elsif ($award eq 'BAD_FORMULA') {
183: $message = "Unable to understand formula";
1.12 albertel 184: $button=1;
1.10 albertel 185: } elsif ($award eq 'INCORRECT') {
186: $message = "Incorrect";
1.12 albertel 187: $button=1;
1.10 albertel 188: } else {
189: $message = "Unknown message: $award";
1.12 albertel 190: $button=1;
1.10 albertel 191: }
1.12 albertel 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;
1.10 albertel 213: }
214:
1.9 albertel 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 = ();
1.10 albertel 223: &Apache::lonxml::debug("$#Apache::inputtags::responselist");
1.9 albertel 224: foreach $response (@Apache::inputtags::responselist) {
1.10 albertel 225: &Apache::lonxml::debug("looking for response.awarddetail.$id.$response");
226: my $value=$Apache::lonhomework::results{"resource.awarddetail.$id.$response"};
1.9 albertel 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");
1.12 albertel 236: &setgradedata($finalaward,$id);
1.9 albertel 237: }
238: }
239: return $result;
1.1 albertel 240: }
241:
1.11 albertel 242: sub gradestatus {
1.12 albertel 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'; }
1.13 albertel 256: if ( $maxtries eq '' ) { $maxtries = '2'; }
257: my $trystr='';
258: if ( $showbutton ) {
259: $trystr = "<br></br>Tries $tries/$maxtries";
260: }
1.12 albertel 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;
1.11 albertel 266: }
1.1 albertel 267: 1;
268: __END__
269:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>