File:  [LON-CAPA] / loncom / homework / inputtags.pm
Revision 1.99: download - view: text, annotated - select for diffs
Thu May 8 15:22:03 2003 UTC (21 years ago) by albertel
Branches: MAIN
CVS tags: HEAD
- BUG#1375 and BUG#723 are fixed by this, hide studen'ts response after correct
  and still before due date

    1: # The LearningOnline Network with CAPA
    2: # input  definitons
    3: #
    4: # $Id: inputtags.pm,v 1.99 2003/05/08 15:22:03 albertel Exp $
    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: #
   28: # 2/19 Guy 
   29: 
   30: package Apache::inputtags;
   31: use HTML::Entities();
   32: use strict;
   33: use Apache::loncommon;
   34: 
   35: BEGIN {
   36:   &Apache::lonxml::register('Apache::inputtags',('hiddenline','textfield','textline'));
   37: }
   38: 
   39: 
   40: sub initialize_inputtags {
   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=();
   51:   # submission it was used in
   52:   @Apache::inputtags::previous_version=();
   53:   # id of current part, 0 means that no part is current (inside <problem> only
   54:   $Apache::inputtags::part='';
   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>
   57:   @Apache::inputtags::status=();
   58:   # hash of defined params for the current response
   59:   %Apache::inputtags::params=();
   60:   # list of all ids, for <import>, these get join()ed and prepended
   61:   @Apache::inputtags::import=();
   62: }
   63: 
   64: sub start_input {
   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;
   71: }
   72: 
   73: sub end_input {
   74:   pop @Apache::inputtags::input;
   75:   return '';
   76: }
   77: 
   78: sub start_textfield {
   79:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   80:   my $result = "";
   81:   my $id = &start_input($parstack,$safeeval);
   82:   my $resid=$Apache::inputtags::response[-1];
   83:   if ($target eq 'web') {
   84:     $Apache::lonxml::evaluate--;
   85:     if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER'  &&
   86:         $Apache::lonhomework::history{"resource.$id.solved"} =~/^correct/
   87: 	) {
   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; }
   94: 	$result= '<textarea name="HWVAL_'.$resid.'" '.
   95: 	    "rows=\"$rows\" cols=\"$cols\">".$oldresponse;
   96: 	if ($oldresponse ne '') {
   97: 	    #get rid of any startup text if the user has already responded
   98: 	    &Apache::lonxml::get_all_text("/textfield",$parser);
   99: 	}
  100:     } else {
  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
  105: 	&Apache::lonxml::get_all_text("/textfield",$parser);
  106:     }
  107:   } elsif ($target eq 'grade') {
  108:     my $seedtext=&Apache::lonxml::get_all_text("/textfield",$parser);
  109:     if ($seedtext eq $ENV{'form.HWVAL_'.$resid}) {
  110:       # if the seed text is still there it wasn't a real submission
  111:       $ENV{'form.HWVAL_'.$resid}='';
  112:     }
  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);
  117:     my $bodytext=&Apache::lonxml::get_all_text("/textfield",$parser);
  118:     $result.=&Apache::edit::editfield($token->[1],$bodytext,'Text you want to appear by default:',80,2);
  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();
  128:   } elsif ($target eq 'tex') {
  129:       my $number_of_lines = &Apache::lonxml::get_param('rows',$parstack,$safeeval);
  130:       my $width_of_box = &Apache::lonxml::get_param('cols',$parstack,$safeeval);
  131:       if ($$tagstack[-2] eq 'essayresponse' and $Apache::lonhomework::type eq 'exam') {
  132: 	  $result = '\fbox{\fbox{\parbox{\textwidth-5mm}{';
  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 ';
  140:       }
  141:   }
  142:   return $result;
  143: }
  144: 
  145: sub end_textfield {
  146:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  147:   my $result;
  148:   if ($target eq 'web') {
  149:     $Apache::lonxml::evaluate++;
  150:     if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
  151:       return "</textarea>";
  152:     }
  153:   } elsif ($target eq 'edit') {
  154:     $result=&Apache::edit::end_table();
  155:   }
  156:   &end_input;
  157:   return $result;
  158: }
  159: 
  160: sub start_textline {
  161:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  162:   my $result = "";
  163:   if ($target eq 'web') {
  164:     $Apache::lonxml::evaluate--;
  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: 	) {
  170:       my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
  171:       my $maxlength;
  172:       if ($size eq '') { $size=20; } else {
  173: 	if ($size < 20) { $maxlength=$size; }
  174:       }
  175:       my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"});
  176:       if ($Apache::lonhomework::type ne 'exam') {
  177:         $result= '<input type="text" name="HWVAL_'.$id.'" value="'.
  178: 	    $oldresponse.'" size="'.$size.'" maxlength="'.$maxlength.'" />';
  179:       }
  180:     } else {
  181:       #right or wrong don't show what was last typed in.
  182:       #$result='<i>'.$oldresponse.'</i>';
  183:       $result='';
  184:     }
  185:   } elsif ($target eq 'edit') {
  186:     $result=&Apache::edit::tag_start($target,$token);
  187:     $result.=&Apache::edit::text_arg('Size:','size',$token,'5')."</td></tr>";
  188:     $result.=&Apache::edit::end_table;
  189:   } elsif ($target eq 'modified') {
  190:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'size');
  191:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  192:   } elsif ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
  193:       my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
  194:       if ($size != 0) {$size=$size*2; $size.=' mm';} else {$size='40 mm';}
  195:       $result='\framebox['.$size.'][s]{\tiny\strut}';
  196:   }
  197:   return $result;
  198: }
  199: 
  200: sub end_textline {
  201:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  202:   if    ($target eq 'web') { $Apache::lonxml::evaluate++; }
  203:   elsif ($target eq 'edit') { return ('','no'); }
  204:   return "";
  205: }
  206: 
  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: 
  235: sub finalizeawards {
  236:   my $result='';
  237:   my $award;
  238:   if ($#_ == '-1') { $result = "NO_RESPONSE"; }
  239:   if ($result eq '' ) {
  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'; }
  248:   }
  249:   if ($result eq '' ) {
  250:     foreach $award (@_) { if ($award eq 'MISSING_ANSWER') {$result='MISSING_ANSWER'; last;}}
  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 '' ) {
  281:       foreach $award (@_) { if ($award eq 'MISORDERED_RANK') {$result=$award; last;} }
  282:   }
  283:   if ($result eq '' ) {
  284:       foreach $award (@_) { if ($award eq 'INVALID_FILETYPE') {$result=$award; last;} }
  285:   }
  286:   if ($result eq '' ) {
  287:     foreach $award (@_) { if ($award eq 'DRAFT') {$result=$award; last;} }
  288:   }
  289:   if ($result eq '' ) {
  290:     foreach $award (@_) { if ($award eq 'SUBMITTED') {$result=$award; last;} }
  291:   }
  292:   if ($result eq '' ) {
  293:     foreach $award (@_) { if ($award eq 'ASSIGNED_SCORE') {$result=$award; last;} }
  294:   }
  295:   if ($result eq '' ) {
  296:     foreach $award (@_) { if ($award eq 'APPROX_ANS') {$result=$award; last;} }
  297:   }
  298:   if ($result eq '' ) { $result='EXACT_ANS'; }
  299:   return $result
  300: }
  301: 
  302: sub decideoutput {
  303:   my ($award,$solved,$previous,$target)=@_;
  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/) {
  311:       if ($award eq 'ASSIGNED_SCORE') {
  312: 	  $message = "A score has been assigned.";
  313:       } else {
  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;
  320:       }
  321:       $button=0;
  322:       $previousmsg='';
  323:   } elsif ($solved =~ /^excused/) {
  324:       $message = "<b>You are excused from the problem.</b>";
  325:       $button=0;
  326:       $previousmsg='';
  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:       }
  337:   } elsif ($award eq 'NO_RESPONSE') {
  338:       $message = '';
  339:       $button=1;
  340:   } elsif ($award eq 'MISSING_ANSWER') {
  341:       $message = 'Some parts were not submitted';
  342:       $button = 1;
  343:   } elsif ($award eq 'WANTED_NUMERIC') {
  344:       $message = "This question expects a numeric answer";
  345:       $button=1;
  346:   } elsif ($award eq 'MISORDERED_RANK') {
  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;
  350:   } elsif ($award eq 'INVALID_FILETYPE') {
  351:       $message = 'The filetype extension of the file you uploaded is not allowed.';
  352:       $button=1;
  353:   } elsif ($award eq 'SIG_FAIL') {
  354:       $message = "Please adjust significant figures.";# you provided %s significant figures";
  355:       $button=1;
  356:   } elsif ($award eq 'UNIT_FAIL') {
  357:       $message = "Units incorrect. ".
  358:        &Apache::loncommon::help_open_topic('Physical_Units'); #Computer reads units as %s";
  359:       $button=1;
  360:   } elsif ($award eq 'UNIT_NOTNEEDED') {
  361:       $message = "Only a number required.";# Computer reads units of %s";
  362:       $button=1;
  363:   } elsif ($award eq 'NO_UNIT') {
  364:       $message = "Units required".
  365:        &Apache::loncommon::help_open_topic('Physical_Units');
  366:       $button=1;
  367:   } elsif ($award eq 'BAD_FORMULA') {
  368:       $message = "Unable to understand formula";
  369:       $button=1;
  370:   } elsif ($award eq 'INCORRECT') {
  371:       $message = "Incorrect";
  372:       $button=1;
  373:   } elsif ($award eq 'SUBMITTED') {
  374:       $message = "Your submission has been recorded.";
  375:       $button=1;
  376:   } elsif ($award eq 'DRAFT') {
  377:       $message = "A draft copy has been saved.";
  378:       $button=1;
  379:   } elsif ($award eq 'ASSIGNED_SCORE') {
  380:       $message = "A score has been assigned.";
  381:       $button=0;
  382:   } else {
  383:       $message = "Unknown message: $award";
  384:       $button=1;
  385:   }
  386:   if (lc($Apache::lonhomework::problemstatus) eq 'no') {
  387:       $message = "Answer Submitted";
  388:       $button=1;
  389:   }
  390:   return ($button,$message,$previousmsg);
  391: }
  392: 
  393: sub removealldata {
  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: 
  403: sub setgradedata {
  404:   my ($award,$id,$previously_used) = @_;
  405:   # if the student already has it correct, don't modify the status
  406:   if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
  407:       $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
  408:     $Apache::lonhomework::results{"resource.$id.afterduedate"}=$award;
  409:     return '';
  410:   } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~
  411:        /^correct/ || $Apache::lonhomework::scantronmode) {
  412:     #handle assignment of tries and solved status
  413:     my $solvemsg;
  414:     if ($Apache::lonhomework::scantronmode) {
  415: 	$solvemsg='correct_by_scantron';
  416:     } else {
  417: 	$solvemsg='correct_by_student';
  418:     }
  419:     if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
  420:       $Apache::lonhomework::results{"resource.$id.afterduedate"}='';
  421:     }
  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"} =
  426: 	    $solvemsg;
  427: 	my $numawards=scalar(@Apache::inputtags::responselist);
  428: 	&Apache::lonxml::debug("Whaaa!");
  429: 	$Apache::lonhomework::results{"resource.$id.awarded"} = 0;
  430: 	foreach my $res (@Apache::inputtags::responselist) {
  431: 	    $Apache::lonhomework::results{"resource.$id.awarded"}+=
  432: 	       $Apache::lonhomework::results{"resource.$id.$res.awarded"};
  433: 	}
  434: 	if ($numawards > 0) {
  435: 	    $Apache::lonhomework::results{"resource.$id.awarded"}/=
  436: 		$numawards;
  437: 	}
  438:     } elsif ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
  439:       $Apache::lonhomework::results{"resource.$id.tries"} =
  440: 	$Apache::lonhomework::history{"resource.$id.tries"} + 1;
  441:       $Apache::lonhomework::results{"resource.$id.solved"} =
  442: 	$solvemsg;
  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"} =
  448: 	'incorrect_attempted'
  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';
  454:     } elsif ( $award eq 'DRAFT' ) {
  455:       $Apache::lonhomework::results{"resource.$id.solved"} = '';
  456:     } elsif ( $award eq 'NO_RESPONSE' ) {
  457: 	#no real response so delete any data that got stored
  458: 	&removealldata($id);
  459: 	return '';
  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') {
  471:       #delete all data as they student didn't do anything, but save
  472:       #the list of collaborators.
  473:       &removealldata($id);
  474:       #and since they didn't do anything we were never here
  475:       return '';
  476:     } else {
  477:       $Apache::lonhomework::results{"resource.$id.previous"} = '0';
  478:     }
  479:   } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} =~
  480: 	    /^correct/ ) {
  481:       #delete all data as they student already has it correct
  482:       &removealldata($id);
  483:       #and since they didn't do anything we were never here
  484:       return '';
  485:   }
  486:   $Apache::lonhomework::results{"resource.$id.award"} = $award;
  487: }
  488: 
  489: sub grade {
  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"};
  498:       &Apache::lonxml::debug("keeping $value from $response for $id");
  499:       push (@awards,$value);
  500:     }
  501:     my $finalaward = &finalizeawards(@awards);
  502:     my $previously_used;
  503:     if ( $#Apache::inputtags::previous eq $#awards ) {
  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: 	    }
  520: 	}
  521:     }
  522:     &Apache::lonxml::debug("final award $finalaward, $previously_used");
  523:     &setgradedata($finalaward,$id,$previously_used);
  524:   }
  525:   return '';
  526: }
  527: 
  528: sub gradestatus {
  529:   my ($id,$target) = @_;
  530:   my $showbutton = 1;
  531:   my $message = '';
  532:   my $latemessage = '';
  533:   my $trystr='';
  534:   my $button='';
  535:   my $previousmsg='';
  536: 
  537:   my $status = $Apache::inputtags::status['-1'];
  538:   &Apache::lonxml::debug("gradestatus has :$status:");
  539:   if ( $status ne 'CLOSED' && $status ne 'UNAVAILABLE') {  
  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) =
  547: 	&decideoutput($award,$solved,$previous,$target);
  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: 	}
  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 ) {
  564:       if ($target eq 'tex') {
  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 ';
  567: 	  } else {
  568: 	      $trystr = '\vskip 0 mm ';
  569: 	  }
  570:       } else {
  571:          $trystr = "<td>Tries $tries/$maxtries</td>";
  572:       }
  573:     }
  574:     if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
  575:     if ( $showbutton ) { 
  576:       if ($target ne 'tex') {
  577:         $button = '<br /><input type="submit" name="submit" value="Submit Answer" />';
  578:       }
  579:     }
  580:     if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
  581:       #last submissions was after due date
  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:       }
  587:     }
  588:   }
  589:   my $output= $previousmsg.$latemessage.$message.$trystr;
  590:   if ($output =~ /^\s*$/) {
  591:     return $button;
  592:   } else {
  593:     if ($target eq 'tex') {
  594:       return $button.' \vskip 0 mm '.$output.' ';
  595:     } else {
  596:       return $button.'<table><tr>'.$output.'</tr></table>';
  597:     }
  598:   }
  599: }
  600: 1;
  601: __END__
  602:  

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>