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