Annotation of loncom/homework/inputtags.pm, revision 1.15
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.15 ! albertel 64: my $oldresponse = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.$Apache::inputtags::response['-1'].submission"};
1.14 albertel 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"; }
1.15 ! albertel 125: if ($result eq '' ) {
! 126: foreach $award (@_) { if ($award eq '') {$result='MISSING_ANSWER'; last;}}
! 127: }
! 128: if ($result eq '' ) {
! 129: foreach $award (@_) { if ($award eq 'ERROR') {$result='ERROR'; last;}}
! 130: }
! 131:
1.9 albertel 132: if ($result eq '' ) {
133: foreach $award (@_) {
134: if ($award eq 'UNIT_FAIL' ||
135: $award eq 'NO_UNIT' ||
136: $award eq 'UNIT_NOTNEEDED') {
137: $result=$award; last;
138: }
139: }
140: }
141: if ($result eq '' ) {
142: foreach $award (@_) {
143: if ($award eq 'WANTED_NUMERIC' ||
144: $award eq 'BAD_FORMULA') {$result=$award; last;}
145: }
146: }
147: if ($result eq '' ) {
148: foreach $award (@_) { if ($award eq 'SIG_FAIL') {$result=$award; last;} }
149: }
150: if ($result eq '' ) {
151: foreach $award (@_) { if ($award eq 'INCORRECT') {$result=$award; last;} }
152: }
153: if ($result eq '' ) {
154: foreach $award (@_) { if ($award eq 'APPROX_ANS') {$result=$award; last;} }
155: }
156: if ($result eq '' ) { $result='EXACT_ANS'; }
157: return $result
158: }
159:
1.10 albertel 160: sub decideoutput {
161: my ($award)=@_;
162: my $message='';
163: my $button=0;
164: if ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
1.12 albertel 165: $message = "Correct computer gets %s";
166: $button=0;
1.13 albertel 167: } elsif ($award eq 'NO_RESPONSE') {
168: $message = '';
169: $button=1;
1.14 albertel 170: } elsif ($award eq 'MISSING_ANSWER') {
171: $message = 'Some parts were not submitted';
172: $button = 1;
1.10 albertel 173: } elsif ($award eq 'WANTED_NUMERIC') {
174: $message = "This question expects a numeric answer";
1.12 albertel 175: $button=1;
1.10 albertel 176: } elsif ($award eq 'SIG_FAIL') {
177: $message = "Please adjust significant figures, you provided %s significant figures";
1.12 albertel 178: $button=1;
1.10 albertel 179: } elsif ($award eq 'UNIT_FAIL') {
180: $message = "Units incorrect, Computer reads units as %s";
1.12 albertel 181: $button=1;
1.10 albertel 182: } elsif ($award eq 'UNIT_NOTNEEDED') {
183: $message = "Only a number required, Computer reads units of %s";
1.12 albertel 184: $button=1;
1.10 albertel 185: } elsif ($award eq 'NO_UNIT') {
186: $message = "Units required";
1.12 albertel 187: $button=1;
1.10 albertel 188: } elsif ($award eq 'BAD_FORMULA') {
189: $message = "Unable to understand formula";
1.12 albertel 190: $button=1;
1.10 albertel 191: } elsif ($award eq 'INCORRECT') {
192: $message = "Incorrect";
1.12 albertel 193: $button=1;
1.10 albertel 194: } else {
195: $message = "Unknown message: $award";
1.12 albertel 196: $button=1;
1.10 albertel 197: }
1.12 albertel 198: return ($button,$message);
199: }
200:
201: sub setgradedata {
202: my ($award,$id) = @_;
203: if ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
1.15 ! albertel 204: $Apache::lonhomework::results{"resource.$id.tries"} =
! 205: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
! 206: $Apache::lonhomework::results{"resource.$id.solved"} =
1.12 albertel 207: 'correct_by_student';
1.15 ! albertel 208: $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
1.12 albertel 209: } elsif ( $award eq 'INCORRECT' ) {
1.15 ! albertel 210: $Apache::lonhomework::results{"resource.$id.tries"} =
! 211: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
! 212: $Apache::lonhomework::results{"resource.$id.solved"} =
1.12 albertel 213: 'incorrect_attempted';
214: } else {
1.15 ! albertel 215: $Apache::lonhomework::results{"resource.$id.solved"} =
1.12 albertel 216: 'incorrect_attempted';
217: }
1.15 ! albertel 218: $Apache::lonhomework::results{"resource.$id.award"} = $award;
1.10 albertel 219: }
220:
1.9 albertel 221: sub grade {
222: my ($target) = @_;
223: my $id = $Apache::inputtags::part;
224: my $result='';
225: my $response='';
226: if ( $target == 'web' ) {
227: if ( defined $ENV{'form.submit'}) {
228: my @awards = ();
1.10 albertel 229: &Apache::lonxml::debug("$#Apache::inputtags::responselist");
1.9 albertel 230: foreach $response (@Apache::inputtags::responselist) {
1.15 ! albertel 231: &Apache::lonxml::debug("looking for response.$id.$response.awarddetail");
! 232: my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"};
1.9 albertel 233: if ( $value ne '' ) {
234: &Apache::lonxml::debug("keep ing $value from $response for $id");
235: push (@awards,$value);
236: } else {
237: &Apache::lonxml::debug("skipping $value from $response for $id");
238: }
239: }
240: my $finalaward = &finalizeawards(@awards);
241: &Apache::lonxml::debug("final award $finalaward");
1.12 albertel 242: &setgradedata($finalaward,$id);
1.9 albertel 243: }
244: }
245: return $result;
1.1 albertel 246: }
247:
1.11 albertel 248: sub gradestatus {
1.12 albertel 249: my ($id) = @_;
250: my $showbutton = 1;
251: my $message = '';
1.15 ! albertel 252: my $award = $Apache::lonhomework::history{"resource.$id.award"};
1.12 albertel 253: &Apache::lonxml::debug("Found Award |$award|");
254: if ( $award ne '' ) {
255: &Apache::lonxml::debug('Getting message');
256: ($showbutton,$message) = &decideoutput($award);
257: }
258: my $button='';
1.15 ! albertel 259: my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
! 260: my $maxtries = $Apache::lonhomework::history{"resource.$id.maxtries"};
1.12 albertel 261: if ( $tries eq '' ) { $tries = '0'; }
1.13 albertel 262: if ( $maxtries eq '' ) { $maxtries = '2'; }
263: my $trystr='';
264: if ( $showbutton ) {
265: $trystr = "<br></br>Tries $tries/$maxtries";
266: }
1.12 albertel 267: if ( $tries >= $maxtries ) { $showbutton = 0; }
268: if ( $showbutton ) {
269: $button = '<input type="submit" name="submit" value="Submit All Answers"><br></br>';
270: }
271: return $button.$message.$trystr;
1.11 albertel 272: }
1.1 albertel 273: 1;
274: __END__
275:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>