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