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