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