File:  [LON-CAPA] / loncom / homework / inputtags.pm
Revision 1.101: download - view: text, annotated - select for diffs
Fri May 9 22:24:05 2003 UTC (21 years ago) by albertel
Branches: MAIN
CVS tags: HEAD
- some of BUG#628, also needed for online exams, disable feedback to students about whether they are correct or not.

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

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