Annotation of loncom/homework/inputtags.pm, revision 1.105
1.43 albertel 1: # The LearningOnline Network with CAPA
2: # input definitons
1.47 albertel 3: #
1.105 ! albertel 4: # $Id: inputtags.pm,v 1.104 2003/06/07 03:57:28 albertel 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: }
147: $result.=&Apache::edit::modifiedfield();
1.78 sakharuk 148: } elsif ($target eq 'tex') {
1.94 sakharuk 149: my $number_of_lines = &Apache::lonxml::get_param('rows',$parstack,$safeeval);
150: my $width_of_box = &Apache::lonxml::get_param('cols',$parstack,$safeeval);
1.78 sakharuk 151: if ($$tagstack[-2] eq 'essayresponse' and $Apache::lonhomework::type eq 'exam') {
152: $result = '\fbox{\fbox{\parbox{\textwidth-5mm}{';
1.94 sakharuk 153: for (my $i=0;$i<int $number_of_lines*2;$i++) {$result.='\strut \\\\ ';}
154: $result.='\strut \\\\\strut \\\\\strut \\\\\strut \\\\}}}';
155: } else {
156: my $TeXwidth=$width_of_box/80;
157: $result = '\vskip 1 mm \fbox{\fbox{\parbox{'.$TeXwidth.'\textwidth-5mm}{';
158: for (my $i=0;$i<int $number_of_lines*2;$i++) {$result.='\strut \\\\ ';}
159: $result.='}}}\vskip 2 mm ';
1.78 sakharuk 160: }
1.43 albertel 161: }
162: return $result;
1.6 albertel 163: }
164:
1.48 albertel 165: sub end_textfield {
1.43 albertel 166: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.60 albertel 167: my $result;
1.43 albertel 168: if ($target eq 'web') {
1.57 albertel 169: $Apache::lonxml::evaluate++;
1.45 albertel 170: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
171: return "</textarea>";
172: }
1.60 albertel 173: } elsif ($target eq 'edit') {
174: $result=&Apache::edit::end_table();
1.45 albertel 175: }
1.43 albertel 176: &end_input;
1.60 albertel 177: return $result;
1.6 albertel 178: }
179:
1.1 albertel 180: sub start_textline {
1.43 albertel 181: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
182: my $result = "";
183: if ($target eq 'web') {
1.57 albertel 184: $Apache::lonxml::evaluate--;
1.99 albertel 185: my $partid=$Apache::inputtags::part;
186: my $id=$Apache::inputtags::response[-1];
1.100 albertel 187: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
1.61 albertel 188: my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
1.72 albertel 189: my $maxlength;
190: if ($size eq '') { $size=20; } else {
191: if ($size < 20) { $maxlength=$size; }
192: }
1.61 albertel 193: my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"});
1.73 sakharuk 194: if ($Apache::lonhomework::type ne 'exam') {
1.89 albertel 195: $result= '<input type="text" name="HWVAL_'.$id.'" value="'.
1.73 sakharuk 196: $oldresponse.'" size="'.$size.'" maxlength="'.$maxlength.'" />';
197: }
1.45 albertel 198: } else {
1.61 albertel 199: #right or wrong don't show what was last typed in.
200: #$result='<i>'.$oldresponse.'</i>';
201: $result='';
1.45 albertel 202: }
1.44 albertel 203: } elsif ($target eq 'edit') {
1.49 matthew 204: $result=&Apache::edit::tag_start($target,$token);
1.43 albertel 205: $result.=&Apache::edit::text_arg('Size:','size',$token,'5')."</td></tr>";
206: $result.=&Apache::edit::end_table;
1.44 albertel 207: } elsif ($target eq 'modified') {
1.43 albertel 208: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'size');
209: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.78 sakharuk 210: } elsif ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
1.76 sakharuk 211: my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
212: if ($size != 0) {$size=$size*2; $size.=' mm';} else {$size='40 mm';}
1.96 sakharuk 213: $result='\framebox['.$size.'][s]{\tiny\strut}';
1.43 albertel 214: }
215: return $result;
1.1 albertel 216: }
217:
218: sub end_textline {
1.43 albertel 219: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.57 albertel 220: if ($target eq 'web') { $Apache::lonxml::evaluate++; }
221: elsif ($target eq 'edit') { return ('','no'); }
1.43 albertel 222: return "";
1.9 albertel 223: }
224:
1.98 albertel 225: sub start_hiddenline {
226: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
227: my $result = "";
228: if ($target eq 'web') {
229: $Apache::lonxml::evaluate--;
230: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
231: my $partid=$Apache::inputtags::part;
232: my $id=$Apache::inputtags::response[-1];
233: my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"});
234: if ($Apache::lonhomework::type ne 'exam') {
235: $result= '<input type="hidden" name="HWVAL_'.$id.'" value="'.
236: $oldresponse.'" />';
237: }
238: }
239: } elsif ($target eq 'edit') {
240: $result=&Apache::edit::tag_start($target,$token);
241: $result.=&Apache::edit::end_table;
242: }
243: return $result;
244: }
245:
246: sub end_hiddenline {
247: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
248: if ($target eq 'web') { $Apache::lonxml::evaluate++; }
249: elsif ($target eq 'edit') { return ('','no'); }
250: return "";
251: }
252:
1.9 albertel 253: sub finalizeawards {
1.43 albertel 254: my $result='';
255: my $award;
256: if ($#_ == '-1') { $result = "NO_RESPONSE"; }
257: if ($result eq '' ) {
1.54 albertel 258: my $blankcount;
259: foreach $award (@_) {
260: if ($award eq '') {
261: $result='MISSING_ANSWER';
262: $blankcount++;
263: }
264: }
265: if ($blankcount == ($#_ + 1)) { $result = 'NO_RESPONSE'; }
1.56 albertel 266: }
267: if ($result eq '' ) {
268: foreach $award (@_) { if ($award eq 'MISSING_ANSWER') {$result='MISSING_ANSWER'; last;}}
1.43 albertel 269: }
270: if ($result eq '' ) {
271: foreach $award (@_) { if ($award eq 'ERROR') {$result='ERROR'; last;}}
272: }
273: if ($result eq '' ) {
274: foreach $award (@_) { if ($award eq 'NO_RESPONSE') {$result='NO_RESPONSE'; last;} }
275: }
1.102 albertel 276: if ($result eq '' ) {
277: foreach $award (@_) { if ($award eq 'TOO_LONG') {$result='TOO_LONG'; last;}}
278: }
1.43 albertel 279: if ($result eq '' ) {
280: foreach $award (@_) {
281: if ($award eq 'UNIT_FAIL' ||
282: $award eq 'NO_UNIT' ||
283: $award eq 'UNIT_NOTNEEDED') {
284: $result=$award; last;
285: }
286: }
287: }
288: if ($result eq '' ) {
289: foreach $award (@_) {
290: if ($award eq 'WANTED_NUMERIC' ||
291: $award eq 'BAD_FORMULA') {$result=$award; last;}
292: }
293: }
294: if ($result eq '' ) {
295: foreach $award (@_) { if ($award eq 'SIG_FAIL') {$result=$award; last;} }
296: }
297: if ($result eq '' ) {
298: foreach $award (@_) { if ($award eq 'INCORRECT') {$result=$award; last;} }
299: }
300: if ($result eq '' ) {
1.79 albertel 301: foreach $award (@_) { if ($award eq 'MISORDERED_RANK') {$result=$award; last;} }
302: }
303: if ($result eq '' ) {
1.80 www 304: foreach $award (@_) { if ($award eq 'INVALID_FILETYPE') {$result=$award; last;} }
305: }
306: if ($result eq '' ) {
1.59 ng 307: foreach $award (@_) { if ($award eq 'DRAFT') {$result=$award; last;} }
308: }
309: if ($result eq '' ) {
1.43 albertel 310: foreach $award (@_) { if ($award eq 'SUBMITTED') {$result=$award; last;} }
311: }
312: if ($result eq '' ) {
1.92 albertel 313: foreach $award (@_) { if ($award eq 'ASSIGNED_SCORE') {$result=$award; last;} }
314: }
315: if ($result eq '' ) {
1.43 albertel 316: foreach $award (@_) { if ($award eq 'APPROX_ANS') {$result=$award; last;} }
317: }
318: if ($result eq '' ) { $result='EXACT_ANS'; }
319: return $result
1.9 albertel 320: }
321:
1.10 albertel 322: sub decideoutput {
1.68 sakharuk 323: my ($award,$solved,$previous,$target)=@_;
1.43 albertel 324: my $message='';
325: my $button=0;
326: my $previousmsg;
1.105 ! albertel 327: my $bgcolor='orange';
! 328: my %possiblecolors =
! 329: ( 'correct' => '#aaffaa',
! 330: 'charged_try' => '#ffaaaa',
! 331: 'not_charged_try' => '#ffffaa',
! 332: 'no_message' => '#fffff',
! 333: );
1.43 albertel 334: if ($previous) { $previousmsg='You have entered that answer before'; }
335:
336: if ($solved =~ /^correct/) {
1.92 albertel 337: if ($award eq 'ASSIGNED_SCORE') {
338: $message = "A score has been assigned.";
1.91 sakharuk 339: } else {
1.92 albertel 340: if ($target eq 'tex') {
341: $message = '\textbf{You are correct}.';
342: } else {
343: $message = "<b>You are correct.</b>";
344: }
1.104 albertel 345: $message.=' Your receipt is '.&Apache::lonnet::receipt;
1.91 sakharuk 346: }
1.105 ! albertel 347: $bgcolor=$possiblecolors{'correct'};
1.91 sakharuk 348: $button=0;
349: $previousmsg='';
1.43 albertel 350: } elsif ($solved =~ /^excused/) {
1.91 sakharuk 351: $message = "<b>You are excused from the problem.</b>";
1.105 ! albertel 352: $bgcolor=$possiblecolors{'charged_try'};
1.43 albertel 353: $button=0;
354: $previousmsg='';
1.91 sakharuk 355: } elsif ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
356: if ($solved =~ /^incorrect/ || $solved eq '') {
357: $message = "Incorrect";
1.105 ! albertel 358: $bgcolor=$possiblecolors{'charged_try'};
1.91 sakharuk 359: $button=1;
360: } else {
361: $message = "<b>You are correct.</b> Your receipt is ".
362: &Apache::lonnet::receipt;
1.105 ! albertel 363: $bgcolor=$possiblecolors{'correct'};
1.91 sakharuk 364: $button=0;
365: $previousmsg='';
366: }
1.43 albertel 367: } elsif ($award eq 'NO_RESPONSE') {
1.91 sakharuk 368: $message = '';
1.105 ! albertel 369: $bgcolor=$possiblecolors{'no_feedback'};
1.91 sakharuk 370: $button=1;
1.43 albertel 371: } elsif ($award eq 'MISSING_ANSWER') {
1.91 sakharuk 372: $message = 'Some parts were not submitted';
1.105 ! albertel 373: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 374: $button = 1;
1.102 albertel 375: } elsif ($award eq 'ERROR') {
376: $message = 'An error occured while trying to grade answer.';
1.105 ! albertel 377: $bgcolor=$possiblecolors{'not_charged_try'};
1.102 albertel 378: $button = 1;
379: } elsif ($award eq 'TOO_LONG') {
380: $message = "The submitted answer was too long.";
1.105 ! albertel 381: $bgcolor=$possiblecolors{'not_charged_try'};
1.102 albertel 382: $button=1;
1.43 albertel 383: } elsif ($award eq 'WANTED_NUMERIC') {
1.91 sakharuk 384: $message = "This question expects a numeric answer";
1.105 ! albertel 385: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 386: $button=1;
1.79 albertel 387: } elsif ($award eq 'MISORDERED_RANK') {
1.91 sakharuk 388: $message = 'You have provided an invalid ranking, please refer to '.
1.105 ! albertel 389: &Apache::loncommon::help_open_topic('Ranking_Problems','help on ranking problems').'.';
! 390: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 391: $button=1;
1.80 www 392: } elsif ($award eq 'INVALID_FILETYPE') {
1.91 sakharuk 393: $message = 'The filetype extension of the file you uploaded is not allowed.';
1.105 ! albertel 394: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 395: $button=1;
1.43 albertel 396: } elsif ($award eq 'SIG_FAIL') {
1.91 sakharuk 397: $message = "Please adjust significant figures.";# you provided %s significant figures";
1.105 ! albertel 398: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 399: $button=1;
1.43 albertel 400: } elsif ($award eq 'UNIT_FAIL') {
1.91 sakharuk 401: $message = "Units incorrect. ".
1.82 www 402: &Apache::loncommon::help_open_topic('Physical_Units'); #Computer reads units as %s";
1.105 ! albertel 403: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 404: $button=1;
1.43 albertel 405: } elsif ($award eq 'UNIT_NOTNEEDED') {
1.91 sakharuk 406: $message = "Only a number required.";# Computer reads units of %s";
1.105 ! albertel 407: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 408: $button=1;
1.43 albertel 409: } elsif ($award eq 'NO_UNIT') {
1.91 sakharuk 410: $message = "Units required".
1.105 ! albertel 411: &Apache::loncommon::help_open_topic('Physical_Units');
! 412: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 413: $button=1;
1.43 albertel 414: } elsif ($award eq 'BAD_FORMULA') {
1.91 sakharuk 415: $message = "Unable to understand formula";
1.105 ! albertel 416: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 417: $button=1;
1.43 albertel 418: } elsif ($award eq 'INCORRECT') {
1.91 sakharuk 419: $message = "Incorrect";
1.105 ! albertel 420: $bgcolor=$possiblecolors{'charged_try'};
1.91 sakharuk 421: $button=1;
1.43 albertel 422: } elsif ($award eq 'SUBMITTED') {
1.91 sakharuk 423: $message = "Your submission has been recorded.";
1.105 ! albertel 424: $bgcolor=$possiblecolors{'correct'};
1.91 sakharuk 425: $button=1;
1.59 ng 426: } elsif ($award eq 'DRAFT') {
1.91 sakharuk 427: $message = "A draft copy has been saved.";
1.105 ! albertel 428: $bgcolor=$possiblecolors{'not_charged_try'};
1.91 sakharuk 429: $button=1;
1.92 albertel 430: } elsif ($award eq 'ASSIGNED_SCORE') {
431: $message = "A score has been assigned.";
1.105 ! albertel 432: $bgcolor=$possiblecolors{'correct'};
1.92 albertel 433: $button=0;
1.43 albertel 434: } else {
1.91 sakharuk 435: $message = "Unknown message: $award";
436: $button=1;
1.98 albertel 437: }
438: if (lc($Apache::lonhomework::problemstatus) eq 'no') {
1.91 sakharuk 439: $message = "Answer Submitted";
1.105 ! albertel 440: $bgcolor=$possiblecolors{'correct'};
1.91 sakharuk 441: $button=1;
1.43 albertel 442: }
1.105 ! albertel 443: return ($button,$bgcolor,$message,$previousmsg);
1.12 albertel 444: }
445:
1.88 albertel 446: sub removealldata {
1.87 albertel 447: my ($id)=@_;
448: foreach my $key (keys(%Apache::lonhomework::results)) {
449: if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
450: &Apache::lonxml::debug("Removing $key");
451: delete($Apache::lonhomework::results{$key});
452: }
453: }
454: }
455:
1.12 albertel 456: sub setgradedata {
1.43 albertel 457: my ($award,$id,$previously_used) = @_;
458: # if the student already has it correct, don't modify the status
1.71 albertel 459: if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
460: $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
1.53 albertel 461: $Apache::lonhomework::results{"resource.$id.afterduedate"}=$award;
462: return '';
463: } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~
1.101 albertel 464: /^correct/ || $Apache::lonhomework::scantronmode ||
465: lc($Apache::lonhomework::problemstatus) eq 'no') {
1.43 albertel 466: #handle assignment of tries and solved status
1.93 albertel 467: my $solvemsg;
468: if ($Apache::lonhomework::scantronmode) {
469: $solvemsg='correct_by_scantron';
470: } else {
471: $solvemsg='correct_by_student';
472: }
1.53 albertel 473: if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
474: $Apache::lonhomework::results{"resource.$id.afterduedate"}='';
475: }
1.92 albertel 476: if ( $award eq 'ASSIGNED_SCORE') {
477: $Apache::lonhomework::results{"resource.$id.tries"} =
478: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
479: $Apache::lonhomework::results{"resource.$id.solved"} =
1.93 albertel 480: $solvemsg;
1.103 albertel 481: my $numawards=scalar(@Apache::inputtags::response);
1.92 albertel 482: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
1.103 albertel 483: foreach my $res (@Apache::inputtags::response) {
1.92 albertel 484: $Apache::lonhomework::results{"resource.$id.awarded"}+=
485: $Apache::lonhomework::results{"resource.$id.$res.awarded"};
486: }
1.93 albertel 487: if ($numawards > 0) {
488: $Apache::lonhomework::results{"resource.$id.awarded"}/=
489: $numawards;
490: }
1.92 albertel 491: } elsif ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
1.43 albertel 492: $Apache::lonhomework::results{"resource.$id.tries"} =
493: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
494: $Apache::lonhomework::results{"resource.$id.solved"} =
1.93 albertel 495: $solvemsg;
1.43 albertel 496: $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
497: } elsif ( $award eq 'INCORRECT' ) {
498: $Apache::lonhomework::results{"resource.$id.tries"} =
499: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
500: $Apache::lonhomework::results{"resource.$id.solved"} =
1.59 ng 501: 'incorrect_attempted'
1.43 albertel 502: } elsif ( $award eq 'SUBMITTED' ) {
503: $Apache::lonhomework::results{"resource.$id.tries"} =
504: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
505: $Apache::lonhomework::results{"resource.$id.solved"} =
506: 'ungraded_attempted';
1.59 ng 507: } elsif ( $award eq 'DRAFT' ) {
508: $Apache::lonhomework::results{"resource.$id.solved"} = '';
1.43 albertel 509: } elsif ( $award eq 'NO_RESPONSE' ) {
1.87 albertel 510: #no real response so delete any data that got stored
511: &removealldata($id);
512: return '';
1.43 albertel 513: } else {
514: $Apache::lonhomework::results{"resource.$id.solved"} =
515: 'incorrect_attempted';
1.101 albertel 516: if (lc($Apache::lonhomework::problemstatus) eq 'no') {
517: $Apache::lonhomework::results{"resource.$id.tries"} =
518: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
519: }
1.43 albertel 520: }
521:
522: # check if this was a previous submission if it was delete the
523: # unneeded data and update the previously_used attribute
524: if ( $previously_used eq 'PREVIOUSLY_USED') {
1.101 albertel 525: if (lc($Apache::lonhomework::problemstatus) ne 'no') {
526: delete($Apache::lonhomework::results{"resource.$id.tries"});
527: $Apache::lonhomework::results{"resource.$id.previous"} = '1';
528: }
1.43 albertel 529: } elsif ( $previously_used eq 'PREVIOUSLY_LAST') {
1.58 ng 530: #delete all data as they student didn't do anything, but save
531: #the list of collaborators.
1.87 albertel 532: &removealldata($id);
1.43 albertel 533: #and since they didn't do anything we were never here
534: return '';
535: } else {
536: $Apache::lonhomework::results{"resource.$id.previous"} = '0';
1.40 albertel 537: }
1.85 albertel 538: } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} =~
539: /^correct/ ) {
540: #delete all data as they student already has it correct
1.87 albertel 541: &removealldata($id);
1.85 albertel 542: #and since they didn't do anything we were never here
543: return '';
1.43 albertel 544: }
545: $Apache::lonhomework::results{"resource.$id.award"} = $award;
1.10 albertel 546: }
547:
1.9 albertel 548: sub grade {
1.43 albertel 549: my ($target) = @_;
550: my $id = $Apache::inputtags::part;
551: my $response='';
552: if ( defined $ENV{'form.submitted'}) {
553: my @awards = ();
1.103 albertel 554: foreach $response (@Apache::inputtags::response) {
1.43 albertel 555: &Apache::lonxml::debug("looking for response.$id.$response.awarddetail");
556: my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"};
1.54 albertel 557: &Apache::lonxml::debug("keeping $value from $response for $id");
558: push (@awards,$value);
1.43 albertel 559: }
560: my $finalaward = &finalizeawards(@awards);
561: my $previously_used;
562: if ( $#Apache::inputtags::previous eq $#awards ) {
1.75 albertel 563: my $match=0;
564: my @matches;
565: foreach my $versionar (@Apache::inputtags::previous_version) {
566: foreach my $version (@$versionar) {
567: $matches[$version]++;
568: }
569: }
570: foreach my $elem (@matches) {if ($elem eq ($#awards+1)) {$match=1;}}
571: if ($match) {
572: $previously_used = 'PREVIOUSLY_LAST';
573: foreach my $value (@Apache::inputtags::previous) {
574: if ($value eq 'PREVIOUSLY_USED' ) {
575: $previously_used = $value;
576: last;
577: }
578: }
1.43 albertel 579: }
580: }
581: &Apache::lonxml::debug("final award $finalaward, $previously_used");
582: &setgradedata($finalaward,$id,$previously_used);
583: }
584: return '';
1.1 albertel 585: }
586:
1.11 albertel 587: sub gradestatus {
1.63 sakharuk 588: my ($id,$target) = @_;
1.43 albertel 589: my $showbutton = 1;
1.105 ! albertel 590: my $bgcolor = '';
1.43 albertel 591: my $message = '';
1.53 albertel 592: my $latemessage = '';
1.43 albertel 593: my $trystr='';
594: my $button='';
595: my $previousmsg='';
596:
597: my $status = $Apache::inputtags::status['-1'];
598: &Apache::lonxml::debug("gradestatus has :$status:");
1.77 albertel 599: if ( $status ne 'CLOSED' && $status ne 'UNAVAILABLE') {
1.43 albertel 600: my $award = $Apache::lonhomework::history{"resource.$id.award"};
601: my $solved = $Apache::lonhomework::history{"resource.$id.solved"};
602: my $previous = $Apache::lonhomework::history{"resource.$id.previous"};
603: &Apache::lonxml::debug("Found Award |$award|$solved|");
604: if ( $award ne '' ) {
605: &Apache::lonxml::debug('Getting message');
1.105 ! albertel 606: ($showbutton,$bgcolor,$message,$previousmsg) =
1.68 sakharuk 607: &decideoutput($award,$solved,$previous,$target);
1.63 sakharuk 608: if ($target eq 'tex') {
609: $message=' '.$message.' ';
610: } else {
1.105 ! albertel 611: $message="<td bgcolor=\"$bgcolor\">$message</td>";
1.63 sakharuk 612: if ($previousmsg) {
1.105 ! albertel 613: $previousmsg="<td bgcolor=\"#aaaaff\">$previousmsg</td>";
1.63 sakharuk 614: }
1.43 albertel 615: }
616: }
617: my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
618: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
619: &Apache::lonxml::debug("got maxtries of :$maxtries:");
620: if ( $tries eq '' ) { $tries = '0'; }
621: if ( $maxtries eq '' ) { $maxtries = '2'; }
622: if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; }
623: if ( $showbutton ) {
1.63 sakharuk 624: if ($target eq 'tex') {
1.97 sakharuk 625: if ($ENV{'request.state'} ne "construct" && $Apache::lonhomework::type ne 'exam') {
626: $trystr = ' {\vskip 1 mm \small \textit{Tries} '.$tries.'/'.$maxtries.'} \vskip 2 mm ';
1.83 sakharuk 627: } else {
628: $trystr = '\vskip 0 mm ';
1.67 sakharuk 629: }
1.63 sakharuk 630: } else {
631: $trystr = "<td>Tries $tries/$maxtries</td>";
632: }
1.43 albertel 633: }
634: if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
635: if ( $showbutton ) {
1.63 sakharuk 636: if ($target ne 'tex') {
637: $button = '<br /><input type="submit" name="submit" value="Submit Answer" />';
638: }
1.43 albertel 639: }
1.53 albertel 640: if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
641: #last submissions was after due date
1.63 sakharuk 642: if ($target eq 'tex') {
643: $latemessage=' The last submission was after the Due Date ';
644: } else {
645: $latemessage="<td bgcolor=\"#ffaaaa\">The last submission was after the Due Date</td>";
646: }
1.53 albertel 647: }
1.43 albertel 648: }
1.53 albertel 649: my $output= $previousmsg.$latemessage.$message.$trystr;
1.43 albertel 650: if ($output =~ /^\s*$/) {
651: return $button;
652: } else {
1.63 sakharuk 653: if ($target eq 'tex') {
654: return $button.' \vskip 0 mm '.$output.' ';
655: } else {
656: return $button.'<table><tr>'.$output.'</tr></table>';
657: }
1.43 albertel 658: }
1.11 albertel 659: }
1.1 albertel 660: 1;
661: __END__
1.43 albertel 662:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>