Annotation of loncom/homework/inputtags.pm, revision 1.109
1.43 albertel 1: # The LearningOnline Network with CAPA
2: # input definitons
1.47 albertel 3: #
1.109 ! www 4: # $Id: inputtags.pm,v 1.108 2003/07/15 21:12:01 www Exp $
1.47 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.43 albertel 28: # 2/19 Guy
1.1 albertel 29:
30: package Apache::inputtags;
1.55 albertel 31: use HTML::Entities();
1.1 albertel 32: use strict;
1.82 www 33: use Apache::loncommon;
1.1 albertel 34:
1.50 harris41 35: BEGIN {
1.98 albertel 36: &Apache::lonxml::register('Apache::inputtags',('hiddenline','textfield','textline'));
1.1 albertel 37: }
38:
1.43 albertel 39:
1.1 albertel 40: sub initialize_inputtags {
1.43 albertel 41: # list of current input ids
42: @Apache::inputtags::input=();
43: # list of all input ids seen in this problem
44: @Apache::inputtags::inputlist=();
45: # list of all current response ids
46: @Apache::inputtags::response=();
47: # list of all response ids seen in this problem
48: @Apache::inputtags::responselist=();
49: # list of whether or not a specific response was previously used
50: @Apache::inputtags::previous=();
1.75 albertel 51: # submission it was used in
52: @Apache::inputtags::previous_version=();
1.43 albertel 53: # id of current part, 0 means that no part is current (inside <problem> only
54: $Apache::inputtags::part='';
1.103 albertel 55: # list of all part ids seen
56: @Apache::inputtags::partlist=();
1.46 albertel 57: # list of problem date statuses, the first element is for <problem>
58: # if there is a second element it is for the current <part>
1.43 albertel 59: @Apache::inputtags::status=();
1.46 albertel 60: # hash of defined params for the current response
1.43 albertel 61: %Apache::inputtags::params=();
1.46 albertel 62: # list of all ids, for <import>, these get join()ed and prepended
63: @Apache::inputtags::import=();
1.103 albertel 64: # list of all import ids seen
65: @Apache::inputtags::importlist=();
66: }
67:
68: sub check_for_duplicate_ids {
69: my %check;
70: foreach my $id (@Apache::inputtags::partlist,
71: @Apache::inputtags::responselist,
72: @Apache::inputtags::importlist) {
73: $check{$id}++;
74: }
75: my @duplicates;
76: foreach my $id (sort(keys(%check))) {
77: if ($check{$id} > 1) {
78: push(@duplicates,$id);
79: }
80: }
81: if (@duplicates) {
82: &Apache::lonxml::error("Duplicated ids found, problem will operate incorrectly. Duplicated ids seen: ",join(', ',@duplicates));
83: }
1.1 albertel 84: }
85:
1.14 albertel 86: sub start_input {
1.43 albertel 87: my ($parstack,$safeeval)=@_;
88: my $id = &Apache::lonxml::get_param('id',$parstack,$safeeval);
89: if ($id eq '') { $id = $Apache::lonxml::curdepth; }
90: push (@Apache::inputtags::input,$id);
91: push (@Apache::inputtags::inputlist,$id);
92: return $id;
1.14 albertel 93: }
94:
95: sub end_input {
1.43 albertel 96: pop @Apache::inputtags::input;
97: return '';
1.14 albertel 98: }
99:
1.48 albertel 100: sub start_textfield {
1.43 albertel 101: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
102: my $result = "";
103: my $id = &start_input($parstack,$safeeval);
1.55 albertel 104: my $resid=$Apache::inputtags::response[-1];
1.43 albertel 105: if ($target eq 'web') {
1.57 albertel 106: $Apache::lonxml::evaluate--;
1.100 albertel 107: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
1.61 albertel 108: my $partid=$Apache::inputtags::part;
109: my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$resid.submission"});
110: my $cols = &Apache::lonxml::get_param('cols',$parstack,$safeeval);
111: if ( $cols eq '') { $cols = 80; }
112: my $rows = &Apache::lonxml::get_param('rows',$parstack,$safeeval);
113: if ( $rows eq '') { $rows = 10; }
1.89 albertel 114: $result= '<textarea name="HWVAL_'.$resid.'" '.
1.61 albertel 115: "rows=\"$rows\" cols=\"$cols\">".$oldresponse;
116: if ($oldresponse ne '') {
117: #get rid of any startup text if the user has already responded
1.84 albertel 118: &Apache::lonxml::get_all_text("/textfield",$parser);
1.61 albertel 119: }
1.45 albertel 120: } else {
1.61 albertel 121: #right or wrong don't show it
122: #$result='<table border="1"><tr><td><i>'.$oldresponse.'</i></td></tr></table>';
123: $result='';
124: #get rid of any startup text
1.84 albertel 125: &Apache::lonxml::get_all_text("/textfield",$parser);
1.51 albertel 126: }
1.60 albertel 127: } elsif ($target eq 'grade') {
1.84 albertel 128: my $seedtext=&Apache::lonxml::get_all_text("/textfield",$parser);
1.89 albertel 129: if ($seedtext eq $ENV{'form.HWVAL_'.$resid}) {
1.51 albertel 130: # if the seed text is still there it wasn't a real submission
1.89 albertel 131: $ENV{'form.HWVAL_'.$resid}='';
1.30 albertel 132: }
1.60 albertel 133: } elsif ($target eq 'edit') {
134: $result.=&Apache::edit::tag_start($target,$token);
135: $result.=&Apache::edit::text_arg('Rows:','rows',$token,4);
136: $result.=&Apache::edit::text_arg('Columns:','cols',$token,4);
1.84 albertel 137: my $bodytext=&Apache::lonxml::get_all_text("/textfield",$parser);
1.62 albertel 138: $result.=&Apache::edit::editfield($token->[1],$bodytext,'Text you want to appear by default:',80,2);
1.60 albertel 139: } elsif ($target eq 'modified') {
140: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
141: $safeeval,'rows','cols');
142: if ($constructtag) {
143: $result = &Apache::edit::rebuild_tag($token);
144: } else {
145: $result=$token->[4];
146: }
1.106 albertel 147: my $bodytext=&Apache::lonxml::get_all_text("/textfield",$parser);
1.60 albertel 148: $result.=&Apache::edit::modifiedfield();
1.78 sakharuk 149: } elsif ($target eq 'tex') {
1.94 sakharuk 150: my $number_of_lines = &Apache::lonxml::get_param('rows',$parstack,$safeeval);
151: my $width_of_box = &Apache::lonxml::get_param('cols',$parstack,$safeeval);
1.78 sakharuk 152: if ($$tagstack[-2] eq 'essayresponse' and $Apache::lonhomework::type eq 'exam') {
153: $result = '\fbox{\fbox{\parbox{\textwidth-5mm}{';
1.94 sakharuk 154: for (my $i=0;$i<int $number_of_lines*2;$i++) {$result.='\strut \\\\ ';}
155: $result.='\strut \\\\\strut \\\\\strut \\\\\strut \\\\}}}';
156: } else {
157: my $TeXwidth=$width_of_box/80;
158: $result = '\vskip 1 mm \fbox{\fbox{\parbox{'.$TeXwidth.'\textwidth-5mm}{';
159: for (my $i=0;$i<int $number_of_lines*2;$i++) {$result.='\strut \\\\ ';}
160: $result.='}}}\vskip 2 mm ';
1.78 sakharuk 161: }
1.43 albertel 162: }
163: return $result;
1.6 albertel 164: }
165:
1.48 albertel 166: sub end_textfield {
1.43 albertel 167: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.60 albertel 168: my $result;
1.43 albertel 169: if ($target eq 'web') {
1.57 albertel 170: $Apache::lonxml::evaluate++;
1.45 albertel 171: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
172: return "</textarea>";
173: }
1.60 albertel 174: } elsif ($target eq 'edit') {
175: $result=&Apache::edit::end_table();
1.45 albertel 176: }
1.43 albertel 177: &end_input;
1.60 albertel 178: return $result;
1.6 albertel 179: }
180:
1.1 albertel 181: sub start_textline {
1.43 albertel 182: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
183: my $result = "";
184: if ($target eq 'web') {
1.57 albertel 185: $Apache::lonxml::evaluate--;
1.99 albertel 186: my $partid=$Apache::inputtags::part;
187: my $id=$Apache::inputtags::response[-1];
1.100 albertel 188: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
1.61 albertel 189: my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
1.72 albertel 190: my $maxlength;
191: if ($size eq '') { $size=20; } else {
192: if ($size < 20) { $maxlength=$size; }
193: }
1.61 albertel 194: my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"});
1.73 sakharuk 195: if ($Apache::lonhomework::type ne 'exam') {
1.89 albertel 196: $result= '<input type="text" name="HWVAL_'.$id.'" value="'.
1.73 sakharuk 197: $oldresponse.'" size="'.$size.'" maxlength="'.$maxlength.'" />';
198: }
1.45 albertel 199: } else {
1.61 albertel 200: #right or wrong don't show what was last typed in.
201: #$result='<i>'.$oldresponse.'</i>';
202: $result='';
1.45 albertel 203: }
1.44 albertel 204: } elsif ($target eq 'edit') {
1.49 matthew 205: $result=&Apache::edit::tag_start($target,$token);
1.43 albertel 206: $result.=&Apache::edit::text_arg('Size:','size',$token,'5')."</td></tr>";
207: $result.=&Apache::edit::end_table;
1.44 albertel 208: } elsif ($target eq 'modified') {
1.43 albertel 209: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'size');
210: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.78 sakharuk 211: } elsif ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
1.76 sakharuk 212: my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
213: if ($size != 0) {$size=$size*2; $size.=' mm';} else {$size='40 mm';}
1.96 sakharuk 214: $result='\framebox['.$size.'][s]{\tiny\strut}';
1.43 albertel 215: }
216: return $result;
1.1 albertel 217: }
218:
219: sub end_textline {
1.43 albertel 220: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.57 albertel 221: if ($target eq 'web') { $Apache::lonxml::evaluate++; }
222: elsif ($target eq 'edit') { return ('','no'); }
1.43 albertel 223: return "";
1.9 albertel 224: }
225:
1.98 albertel 226: sub start_hiddenline {
227: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
228: my $result = "";
229: if ($target eq 'web') {
230: $Apache::lonxml::evaluate--;
231: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
232: my $partid=$Apache::inputtags::part;
233: my $id=$Apache::inputtags::response[-1];
234: my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"});
235: if ($Apache::lonhomework::type ne 'exam') {
236: $result= '<input type="hidden" name="HWVAL_'.$id.'" value="'.
237: $oldresponse.'" />';
238: }
239: }
240: } elsif ($target eq 'edit') {
241: $result=&Apache::edit::tag_start($target,$token);
242: $result.=&Apache::edit::end_table;
243: }
244: return $result;
245: }
246:
247: sub end_hiddenline {
248: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
249: if ($target eq 'web') { $Apache::lonxml::evaluate++; }
250: elsif ($target eq 'edit') { return ('','no'); }
251: return "";
252: }
253:
1.9 albertel 254: sub finalizeawards {
1.43 albertel 255: my $result='';
256: my $award;
257: if ($#_ == '-1') { $result = "NO_RESPONSE"; }
258: if ($result eq '' ) {
1.54 albertel 259: my $blankcount;
260: foreach $award (@_) {
261: if ($award eq '') {
262: $result='MISSING_ANSWER';
263: $blankcount++;
264: }
265: }
266: if ($blankcount == ($#_ + 1)) { $result = 'NO_RESPONSE'; }
1.56 albertel 267: }
268: if ($result eq '' ) {
269: foreach $award (@_) { if ($award eq 'MISSING_ANSWER') {$result='MISSING_ANSWER'; last;}}
1.43 albertel 270: }
271: if ($result eq '' ) {
272: foreach $award (@_) { if ($award eq 'ERROR') {$result='ERROR'; last;}}
273: }
274: if ($result eq '' ) {
275: foreach $award (@_) { if ($award eq 'NO_RESPONSE') {$result='NO_RESPONSE'; last;} }
276: }
1.102 albertel 277: if ($result eq '' ) {
278: foreach $award (@_) { if ($award eq 'TOO_LONG') {$result='TOO_LONG'; last;}}
279: }
1.43 albertel 280: if ($result eq '' ) {
281: foreach $award (@_) {
282: if ($award eq 'UNIT_FAIL' ||
283: $award eq 'NO_UNIT' ||
284: $award eq 'UNIT_NOTNEEDED') {
285: $result=$award; last;
286: }
287: }
288: }
289: if ($result eq '' ) {
290: foreach $award (@_) {
291: if ($award eq 'WANTED_NUMERIC' ||
292: $award eq 'BAD_FORMULA') {$result=$award; last;}
293: }
294: }
295: if ($result eq '' ) {
296: foreach $award (@_) { if ($award eq 'SIG_FAIL') {$result=$award; last;} }
297: }
298: if ($result eq '' ) {
299: foreach $award (@_) { if ($award eq 'INCORRECT') {$result=$award; last;} }
300: }
301: if ($result eq '' ) {
1.79 albertel 302: foreach $award (@_) { if ($award eq 'MISORDERED_RANK') {$result=$award; last;} }
303: }
304: if ($result eq '' ) {
1.80 www 305: foreach $award (@_) { if ($award eq 'INVALID_FILETYPE') {$result=$award; last;} }
306: }
307: if ($result eq '' ) {
1.59 ng 308: foreach $award (@_) { if ($award eq 'DRAFT') {$result=$award; last;} }
309: }
310: if ($result eq '' ) {
1.43 albertel 311: foreach $award (@_) { if ($award eq 'SUBMITTED') {$result=$award; last;} }
312: }
313: if ($result eq '' ) {
1.92 albertel 314: foreach $award (@_) { if ($award eq 'ASSIGNED_SCORE') {$result=$award; last;} }
315: }
316: if ($result eq '' ) {
1.43 albertel 317: foreach $award (@_) { if ($award eq 'APPROX_ANS') {$result=$award; last;} }
318: }
319: if ($result eq '' ) { $result='EXACT_ANS'; }
320: return $result
1.9 albertel 321: }
322:
1.10 albertel 323: sub decideoutput {
1.68 sakharuk 324: my ($award,$solved,$previous,$target)=@_;
1.43 albertel 325: my $message='';
326: my $button=0;
327: my $previousmsg;
1.105 albertel 328: my $bgcolor='orange';
329: my %possiblecolors =
330: ( 'correct' => '#aaffaa',
331: 'charged_try' => '#ffaaaa',
332: 'not_charged_try' => '#ffffaa',
333: 'no_message' => '#fffff',
334: );
1.43 albertel 335: if ($previous) { $previousmsg='You have entered that answer before'; }
336:
337: if ($solved =~ /^correct/) {
1.92 albertel 338: if ($award eq 'ASSIGNED_SCORE') {
339: $message = "A score has been assigned.";
1.91 sakharuk 340: } else {
1.92 albertel 341: if ($target eq 'tex') {
342: $message = '\textbf{You are correct}.';
343: } else {
344: $message = "<b>You are correct.</b>";
345: }
1.108 www 346: unless ($ENV{'course.'.
347: $ENV{'request.course.id'}.
348: '.disable_receipt_display'} eq 'yes') {
1.109 ! www 349: $message.='<br />Your receipt is '.&Apache::lonnet::receipt().
! 350: &Apache::loncommon::help_open_topic('Receipt');
1.108 www 351: }
1.91 sakharuk 352: }
1.105 albertel 353: $bgcolor=$possiblecolors{'correct'};
1.91 sakharuk 354: $button=0;
355: $previousmsg='';
1.43 albertel 356: } elsif ($solved =~ /^excused/) {
1.91 sakharuk 357: $message = "<b>You are excused from the problem.</b>";
1.105 albertel 358: $bgcolor=$possiblecolors{'charged_try'};
1.43 albertel 359: $button=0;
360: $previousmsg='';
1.91 sakharuk 361: } elsif ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
362: if ($solved =~ /^incorrect/ || $solved eq '') {
363: $message = "Incorrect";
1.105 albertel 364: $bgcolor=$possiblecolors{'charged_try'};
1.91 sakharuk 365: $button=1;
366: } else {
1.108 www 367: $message = "<b>You are correct.</b>";
368: unless ($ENV{'course.'.
369: $ENV{'request.course.id'}.
370: '.disable_receipt_display'} eq 'yes') {
1.109 ! www 371: $message.='<br />Your receipt is '.&Apache::lonnet::receipt().
! 372: &Apache::loncommon::help_open_topic('Receipt');
1.108 www 373: }
1.105 albertel 374: $bgcolor=$possiblecolors{'correct'};
1.91 sakharuk 375: $button=0;
376: $previousmsg='';
377: }
1.43 albertel 378: } elsif ($award eq 'NO_RESPONSE') {
1.91 sakharuk 379: $message = '';
1.105 albertel 380: $bgcolor=$possiblecolors{'no_feedback'};
1.91 sakharuk 381: $button=1;
1.43 albertel 382: } elsif ($award eq 'MISSING_ANSWER') {
1.91 sakharuk 383: $message = 'Some parts were not submitted';
1.105 albertel 384: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 385: $button = 1;
1.102 albertel 386: } elsif ($award eq 'ERROR') {
1.107 albertel 387: $message = 'An error occured while grading your answer.';
1.105 albertel 388: $bgcolor=$possiblecolors{'not_charged_try'};
1.102 albertel 389: $button = 1;
390: } elsif ($award eq 'TOO_LONG') {
391: $message = "The submitted answer was too long.";
1.105 albertel 392: $bgcolor=$possiblecolors{'not_charged_try'};
1.102 albertel 393: $button=1;
1.43 albertel 394: } elsif ($award eq 'WANTED_NUMERIC') {
1.91 sakharuk 395: $message = "This question expects a numeric answer";
1.105 albertel 396: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 397: $button=1;
1.79 albertel 398: } elsif ($award eq 'MISORDERED_RANK') {
1.91 sakharuk 399: $message = 'You have provided an invalid ranking, please refer to '.
1.105 albertel 400: &Apache::loncommon::help_open_topic('Ranking_Problems','help on ranking problems').'.';
401: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 402: $button=1;
1.80 www 403: } elsif ($award eq 'INVALID_FILETYPE') {
1.91 sakharuk 404: $message = 'The filetype extension of the file you uploaded is not allowed.';
1.105 albertel 405: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 406: $button=1;
1.43 albertel 407: } elsif ($award eq 'SIG_FAIL') {
1.91 sakharuk 408: $message = "Please adjust significant figures.";# you provided %s significant figures";
1.105 albertel 409: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 410: $button=1;
1.43 albertel 411: } elsif ($award eq 'UNIT_FAIL') {
1.91 sakharuk 412: $message = "Units incorrect. ".
1.82 www 413: &Apache::loncommon::help_open_topic('Physical_Units'); #Computer reads units as %s";
1.105 albertel 414: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 415: $button=1;
1.43 albertel 416: } elsif ($award eq 'UNIT_NOTNEEDED') {
1.91 sakharuk 417: $message = "Only a number required.";# Computer reads units of %s";
1.105 albertel 418: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 419: $button=1;
1.43 albertel 420: } elsif ($award eq 'NO_UNIT') {
1.91 sakharuk 421: $message = "Units required".
1.105 albertel 422: &Apache::loncommon::help_open_topic('Physical_Units');
423: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 424: $button=1;
1.43 albertel 425: } elsif ($award eq 'BAD_FORMULA') {
1.91 sakharuk 426: $message = "Unable to understand formula";
1.105 albertel 427: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 428: $button=1;
1.43 albertel 429: } elsif ($award eq 'INCORRECT') {
1.91 sakharuk 430: $message = "Incorrect";
1.105 albertel 431: $bgcolor=$possiblecolors{'charged_try'};
1.91 sakharuk 432: $button=1;
1.43 albertel 433: } elsif ($award eq 'SUBMITTED') {
1.91 sakharuk 434: $message = "Your submission has been recorded.";
1.105 albertel 435: $bgcolor=$possiblecolors{'correct'};
1.91 sakharuk 436: $button=1;
1.59 ng 437: } elsif ($award eq 'DRAFT') {
1.91 sakharuk 438: $message = "A draft copy has been saved.";
1.105 albertel 439: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 440: $button=1;
1.92 albertel 441: } elsif ($award eq 'ASSIGNED_SCORE') {
442: $message = "A score has been assigned.";
1.105 albertel 443: $bgcolor=$possiblecolors{'correct'};
1.92 albertel 444: $button=0;
1.43 albertel 445: } else {
1.91 sakharuk 446: $message = "Unknown message: $award";
447: $button=1;
1.98 albertel 448: }
449: if (lc($Apache::lonhomework::problemstatus) eq 'no') {
1.91 sakharuk 450: $message = "Answer Submitted";
1.105 albertel 451: $bgcolor=$possiblecolors{'correct'};
1.91 sakharuk 452: $button=1;
1.43 albertel 453: }
1.105 albertel 454: return ($button,$bgcolor,$message,$previousmsg);
1.12 albertel 455: }
456:
1.88 albertel 457: sub removealldata {
1.87 albertel 458: my ($id)=@_;
459: foreach my $key (keys(%Apache::lonhomework::results)) {
460: if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
461: &Apache::lonxml::debug("Removing $key");
462: delete($Apache::lonhomework::results{$key});
463: }
464: }
465: }
466:
1.12 albertel 467: sub setgradedata {
1.43 albertel 468: my ($award,$id,$previously_used) = @_;
469: # if the student already has it correct, don't modify the status
1.71 albertel 470: if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
471: $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
1.53 albertel 472: $Apache::lonhomework::results{"resource.$id.afterduedate"}=$award;
473: return '';
474: } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~
1.101 albertel 475: /^correct/ || $Apache::lonhomework::scantronmode ||
476: lc($Apache::lonhomework::problemstatus) eq 'no') {
1.43 albertel 477: #handle assignment of tries and solved status
1.93 albertel 478: my $solvemsg;
479: if ($Apache::lonhomework::scantronmode) {
480: $solvemsg='correct_by_scantron';
481: } else {
482: $solvemsg='correct_by_student';
483: }
1.53 albertel 484: if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
485: $Apache::lonhomework::results{"resource.$id.afterduedate"}='';
486: }
1.92 albertel 487: if ( $award eq 'ASSIGNED_SCORE') {
488: $Apache::lonhomework::results{"resource.$id.tries"} =
489: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
490: $Apache::lonhomework::results{"resource.$id.solved"} =
1.93 albertel 491: $solvemsg;
1.103 albertel 492: my $numawards=scalar(@Apache::inputtags::response);
1.92 albertel 493: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
1.103 albertel 494: foreach my $res (@Apache::inputtags::response) {
1.92 albertel 495: $Apache::lonhomework::results{"resource.$id.awarded"}+=
496: $Apache::lonhomework::results{"resource.$id.$res.awarded"};
497: }
1.93 albertel 498: if ($numawards > 0) {
499: $Apache::lonhomework::results{"resource.$id.awarded"}/=
500: $numawards;
501: }
1.92 albertel 502: } elsif ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
1.43 albertel 503: $Apache::lonhomework::results{"resource.$id.tries"} =
504: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
505: $Apache::lonhomework::results{"resource.$id.solved"} =
1.93 albertel 506: $solvemsg;
1.43 albertel 507: $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
508: } elsif ( $award eq 'INCORRECT' ) {
509: $Apache::lonhomework::results{"resource.$id.tries"} =
510: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
511: $Apache::lonhomework::results{"resource.$id.solved"} =
1.59 ng 512: 'incorrect_attempted'
1.43 albertel 513: } elsif ( $award eq 'SUBMITTED' ) {
514: $Apache::lonhomework::results{"resource.$id.tries"} =
515: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
516: $Apache::lonhomework::results{"resource.$id.solved"} =
517: 'ungraded_attempted';
1.59 ng 518: } elsif ( $award eq 'DRAFT' ) {
519: $Apache::lonhomework::results{"resource.$id.solved"} = '';
1.43 albertel 520: } elsif ( $award eq 'NO_RESPONSE' ) {
1.87 albertel 521: #no real response so delete any data that got stored
522: &removealldata($id);
523: return '';
1.43 albertel 524: } else {
525: $Apache::lonhomework::results{"resource.$id.solved"} =
526: 'incorrect_attempted';
1.101 albertel 527: if (lc($Apache::lonhomework::problemstatus) eq 'no') {
528: $Apache::lonhomework::results{"resource.$id.tries"} =
529: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
530: }
1.43 albertel 531: }
532:
533: # check if this was a previous submission if it was delete the
534: # unneeded data and update the previously_used attribute
535: if ( $previously_used eq 'PREVIOUSLY_USED') {
1.101 albertel 536: if (lc($Apache::lonhomework::problemstatus) ne 'no') {
537: delete($Apache::lonhomework::results{"resource.$id.tries"});
538: $Apache::lonhomework::results{"resource.$id.previous"} = '1';
539: }
1.43 albertel 540: } elsif ( $previously_used eq 'PREVIOUSLY_LAST') {
1.58 ng 541: #delete all data as they student didn't do anything, but save
542: #the list of collaborators.
1.87 albertel 543: &removealldata($id);
1.43 albertel 544: #and since they didn't do anything we were never here
545: return '';
546: } else {
547: $Apache::lonhomework::results{"resource.$id.previous"} = '0';
1.40 albertel 548: }
1.85 albertel 549: } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} =~
550: /^correct/ ) {
551: #delete all data as they student already has it correct
1.87 albertel 552: &removealldata($id);
1.85 albertel 553: #and since they didn't do anything we were never here
554: return '';
1.43 albertel 555: }
556: $Apache::lonhomework::results{"resource.$id.award"} = $award;
1.10 albertel 557: }
558:
1.9 albertel 559: sub grade {
1.43 albertel 560: my ($target) = @_;
561: my $id = $Apache::inputtags::part;
562: my $response='';
563: if ( defined $ENV{'form.submitted'}) {
564: my @awards = ();
1.103 albertel 565: foreach $response (@Apache::inputtags::response) {
1.43 albertel 566: &Apache::lonxml::debug("looking for response.$id.$response.awarddetail");
567: my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"};
1.54 albertel 568: &Apache::lonxml::debug("keeping $value from $response for $id");
569: push (@awards,$value);
1.43 albertel 570: }
571: my $finalaward = &finalizeawards(@awards);
572: my $previously_used;
573: if ( $#Apache::inputtags::previous eq $#awards ) {
1.75 albertel 574: my $match=0;
575: my @matches;
576: foreach my $versionar (@Apache::inputtags::previous_version) {
577: foreach my $version (@$versionar) {
578: $matches[$version]++;
579: }
580: }
581: foreach my $elem (@matches) {if ($elem eq ($#awards+1)) {$match=1;}}
582: if ($match) {
583: $previously_used = 'PREVIOUSLY_LAST';
584: foreach my $value (@Apache::inputtags::previous) {
585: if ($value eq 'PREVIOUSLY_USED' ) {
586: $previously_used = $value;
587: last;
588: }
589: }
1.43 albertel 590: }
591: }
592: &Apache::lonxml::debug("final award $finalaward, $previously_used");
593: &setgradedata($finalaward,$id,$previously_used);
594: }
595: return '';
1.1 albertel 596: }
597:
1.11 albertel 598: sub gradestatus {
1.63 sakharuk 599: my ($id,$target) = @_;
1.43 albertel 600: my $showbutton = 1;
1.105 albertel 601: my $bgcolor = '';
1.43 albertel 602: my $message = '';
1.53 albertel 603: my $latemessage = '';
1.43 albertel 604: my $trystr='';
605: my $button='';
606: my $previousmsg='';
607:
608: my $status = $Apache::inputtags::status['-1'];
609: &Apache::lonxml::debug("gradestatus has :$status:");
1.77 albertel 610: if ( $status ne 'CLOSED' && $status ne 'UNAVAILABLE') {
1.43 albertel 611: my $award = $Apache::lonhomework::history{"resource.$id.award"};
612: my $solved = $Apache::lonhomework::history{"resource.$id.solved"};
613: my $previous = $Apache::lonhomework::history{"resource.$id.previous"};
614: &Apache::lonxml::debug("Found Award |$award|$solved|");
615: if ( $award ne '' ) {
616: &Apache::lonxml::debug('Getting message');
1.105 albertel 617: ($showbutton,$bgcolor,$message,$previousmsg) =
1.68 sakharuk 618: &decideoutput($award,$solved,$previous,$target);
1.63 sakharuk 619: if ($target eq 'tex') {
620: $message=' '.$message.' ';
621: } else {
1.105 albertel 622: $message="<td bgcolor=\"$bgcolor\">$message</td>";
1.63 sakharuk 623: if ($previousmsg) {
1.105 albertel 624: $previousmsg="<td bgcolor=\"#aaaaff\">$previousmsg</td>";
1.63 sakharuk 625: }
1.43 albertel 626: }
627: }
628: my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
629: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
630: &Apache::lonxml::debug("got maxtries of :$maxtries:");
631: if ( $tries eq '' ) { $tries = '0'; }
632: if ( $maxtries eq '' ) { $maxtries = '2'; }
633: if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; }
634: if ( $showbutton ) {
1.63 sakharuk 635: if ($target eq 'tex') {
1.97 sakharuk 636: if ($ENV{'request.state'} ne "construct" && $Apache::lonhomework::type ne 'exam') {
637: $trystr = ' {\vskip 1 mm \small \textit{Tries} '.$tries.'/'.$maxtries.'} \vskip 2 mm ';
1.83 sakharuk 638: } else {
639: $trystr = '\vskip 0 mm ';
1.67 sakharuk 640: }
1.63 sakharuk 641: } else {
642: $trystr = "<td>Tries $tries/$maxtries</td>";
643: }
1.43 albertel 644: }
645: if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
646: if ( $showbutton ) {
1.63 sakharuk 647: if ($target ne 'tex') {
648: $button = '<br /><input type="submit" name="submit" value="Submit Answer" />';
649: }
1.43 albertel 650: }
1.53 albertel 651: if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
652: #last submissions was after due date
1.63 sakharuk 653: if ($target eq 'tex') {
654: $latemessage=' The last submission was after the Due Date ';
655: } else {
656: $latemessage="<td bgcolor=\"#ffaaaa\">The last submission was after the Due Date</td>";
657: }
1.53 albertel 658: }
1.43 albertel 659: }
1.53 albertel 660: my $output= $previousmsg.$latemessage.$message.$trystr;
1.43 albertel 661: if ($output =~ /^\s*$/) {
662: return $button;
663: } else {
1.63 sakharuk 664: if ($target eq 'tex') {
665: return $button.' \vskip 0 mm '.$output.' ';
666: } else {
667: return $button.'<table><tr>'.$output.'</tr></table>';
668: }
1.43 albertel 669: }
1.11 albertel 670: }
1.1 albertel 671: 1;
672: __END__
1.43 albertel 673:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>