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