Annotation of loncom/homework/inputtags.pm, revision 1.86

1.43      albertel    1: # The LearningOnline Network with CAPA
                      2: # input  definitons
1.47      albertel    3: #
1.86    ! sakharuk    4: # $Id: inputtags.pm,v 1.85 2003/03/17 21:33:33 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.65      bowersj2   36:   &Apache::lonxml::register('Apache::inputtags',('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.45      albertel   85:     if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
1.61      albertel   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
1.84      albertel   96: 	    &Apache::lonxml::get_all_text("/textfield",$parser);
1.61      albertel   97: 	}
1.45      albertel   98:     } else {
1.61      albertel   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
1.84      albertel  103: 	&Apache::lonxml::get_all_text("/textfield",$parser);
1.51      albertel  104:     }
1.60      albertel  105:   } elsif ($target eq 'grade') {
1.84      albertel  106:     my $seedtext=&Apache::lonxml::get_all_text("/textfield",$parser);
1.55      albertel  107:     if ($seedtext eq $ENV{'form.HWVAL'.$resid}) {
1.51      albertel  108:       # if the seed text is still there it wasn't a real submission
1.55      albertel  109:       $ENV{'form.HWVAL'.$resid}='';
1.30      albertel  110:     }
1.60      albertel  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);
1.84      albertel  115:     my $bodytext=&Apache::lonxml::get_all_text("/textfield",$parser);
1.62      albertel  116:     $result.=&Apache::edit::editfield($token->[1],$bodytext,'Text you want to appear by default:',80,2);
1.60      albertel  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();
1.78      sakharuk  126:   } elsif ($target eq 'tex') {
                    127:       if ($$tagstack[-2] eq 'essayresponse' and $Apache::lonhomework::type eq 'exam') {
                    128: 	  my $number_of_lines= &Apache::lonxml::get_param('rows',$parstack,$safeeval);
                    129: 	  $result = '\fbox{\fbox{\parbox{\textwidth-5mm}{';
                    130: 	for (my $i=0;$i<int $number_of_lines*2;$i++) {$result.='\strut \\\\ ';}
                    131: 	$result.='\strut \\\\\strut \\\\\strut \\\\\strut \\\\}}}';
                    132:       }
1.43      albertel  133:   }
                    134:   return $result;
1.6       albertel  135: }
                    136: 
1.48      albertel  137: sub end_textfield {
1.43      albertel  138:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.60      albertel  139:   my $result;
1.43      albertel  140:   if ($target eq 'web') {
1.57      albertel  141:     $Apache::lonxml::evaluate++;
1.45      albertel  142:     if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
                    143:       return "</textarea>";
                    144:     }
1.60      albertel  145:   } elsif ($target eq 'edit') {
                    146:     $result=&Apache::edit::end_table();
1.45      albertel  147:   }
1.43      albertel  148:   &end_input;
1.60      albertel  149:   return $result;
1.6       albertel  150: }
                    151: 
1.1       albertel  152: sub start_textline {
1.43      albertel  153:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    154:   my $result = "";
                    155:   if ($target eq 'web') {
1.57      albertel  156:     $Apache::lonxml::evaluate--;
1.45      albertel  157:     if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
1.61      albertel  158:       my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
1.72      albertel  159:       my $maxlength;
                    160:       if ($size eq '') { $size=20; } else {
                    161: 	if ($size < 20) { $maxlength=$size; }
                    162:       }
1.61      albertel  163:       my $partid=$Apache::inputtags::part;
                    164:       my $id=$Apache::inputtags::response[-1];
                    165:       my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"});
1.73      sakharuk  166:       if ($Apache::lonhomework::type ne 'exam') {
                    167:         $result= '<input type="text" name="HWVAL'.$id.'" value="'.
                    168: 	    $oldresponse.'" size="'.$size.'" maxlength="'.$maxlength.'" />';
                    169:       }
1.45      albertel  170:     } else {
1.61      albertel  171:       #right or wrong don't show what was last typed in.
                    172:       #$result='<i>'.$oldresponse.'</i>';
                    173:       $result='';
1.45      albertel  174:     }
1.44      albertel  175:   } elsif ($target eq 'edit') {
1.49      matthew   176:     $result=&Apache::edit::tag_start($target,$token);
1.43      albertel  177:     $result.=&Apache::edit::text_arg('Size:','size',$token,'5')."</td></tr>";
                    178:     $result.=&Apache::edit::end_table;
1.44      albertel  179:   } elsif ($target eq 'modified') {
1.43      albertel  180:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'size');
                    181:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.78      sakharuk  182:   } elsif ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
1.76      sakharuk  183:       my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
                    184:       if ($size != 0) {$size=$size*2; $size.=' mm';} else {$size='40 mm';}
                    185:       $result='\framebox['.$size.'][s]{\tiny\strut}';
1.43      albertel  186:   }
                    187:   return $result;
1.1       albertel  188: }
                    189: 
                    190: sub end_textline {
1.43      albertel  191:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.57      albertel  192:   if    ($target eq 'web') { $Apache::lonxml::evaluate++; }
                    193:   elsif ($target eq 'edit') { return ('','no'); }
1.43      albertel  194:   return "";
1.9       albertel  195: }
                    196: 
                    197: sub finalizeawards {
1.43      albertel  198:   my $result='';
                    199:   my $award;
                    200:   if ($#_ == '-1') { $result = "NO_RESPONSE"; }
                    201:   if ($result eq '' ) {
1.54      albertel  202:     my $blankcount;
                    203:     foreach $award (@_) {
                    204:       if ($award eq '') {
                    205: 	$result='MISSING_ANSWER';
                    206: 	$blankcount++;
                    207:       }
                    208:     }
                    209:     if ($blankcount == ($#_ + 1)) { $result = 'NO_RESPONSE'; }
1.56      albertel  210:   }
                    211:   if ($result eq '' ) {
                    212:     foreach $award (@_) { if ($award eq 'MISSING_ANSWER') {$result='MISSING_ANSWER'; last;}}
1.43      albertel  213:   }
                    214:   if ($result eq '' ) {
                    215:     foreach $award (@_) { if ($award eq 'ERROR') {$result='ERROR'; last;}}
                    216:   }
                    217:   if ($result eq '' ) {
                    218:     foreach $award (@_) { if ($award eq 'NO_RESPONSE') {$result='NO_RESPONSE'; last;} }
                    219:   }
                    220: 
                    221:   if ($result eq '' ) {
                    222:     foreach $award (@_) { 
                    223:       if ($award eq 'UNIT_FAIL' ||
                    224: 	  $award eq 'NO_UNIT' ||
                    225: 	  $award eq 'UNIT_NOTNEEDED') {
                    226: 	$result=$award; last;
                    227:       }
                    228:     }
                    229:   }
                    230:   if ($result eq '' ) {
                    231:     foreach $award (@_) { 
                    232:       if ($award eq 'WANTED_NUMERIC' || 
                    233: 	  $award eq 'BAD_FORMULA') {$result=$award; last;}
                    234:     }
                    235:   }
                    236:   if ($result eq '' ) {
                    237:     foreach $award (@_) { if ($award eq 'SIG_FAIL') {$result=$award; last;} }
                    238:   }
                    239:   if ($result eq '' ) {
                    240:     foreach $award (@_) { if ($award eq 'INCORRECT') {$result=$award; last;} }
                    241:   }
                    242:   if ($result eq '' ) {
1.79      albertel  243:       foreach $award (@_) { if ($award eq 'MISORDERED_RANK') {$result=$award; last;} }
                    244:   }
                    245:   if ($result eq '' ) {
1.80      www       246:       foreach $award (@_) { if ($award eq 'INVALID_FILETYPE') {$result=$award; last;} }
                    247:   }
                    248:   if ($result eq '' ) {
1.59      ng        249:     foreach $award (@_) { if ($award eq 'DRAFT') {$result=$award; last;} }
                    250:   }
                    251:   if ($result eq '' ) {
1.43      albertel  252:     foreach $award (@_) { if ($award eq 'SUBMITTED') {$result=$award; last;} }
                    253:   }
                    254:   if ($result eq '' ) {
                    255:     foreach $award (@_) { if ($award eq 'APPROX_ANS') {$result=$award; last;} }
                    256:   }
                    257:   if ($result eq '' ) { $result='EXACT_ANS'; }
                    258:   return $result
1.9       albertel  259: }
                    260: 
1.10      albertel  261: sub decideoutput {
1.68      sakharuk  262:   my ($award,$solved,$previous,$target)=@_;
1.43      albertel  263:   my $message='';
                    264:   my $button=0;
                    265:   my $previousmsg;
                    266: 
                    267:   if ($previous) { $previousmsg='You have entered that answer before'; }
                    268: 
                    269:   if      ($solved =~ /^correct/) {
1.68      sakharuk  270:     if ($target eq 'tex') {
                    271:       $message = '\textbf{You are correct}. Your receipt is '.
1.43      albertel  272:       &Apache::lonnet::receipt;
1.68      sakharuk  273:     } else {
                    274:       $message = "<b>You are correct.</b> Your receipt is ".
                    275:       &Apache::lonnet::receipt;
                    276:     }
1.43      albertel  277:     $button=0;
                    278:     $previousmsg='';
                    279:   } elsif ($solved =~ /^excused/) {
                    280:     $message = "<b>You are excused from the problem.</b>";
                    281:     $button=0;
                    282:     $previousmsg='';
                    283:   } elsif ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
                    284:     if ($solved =~ /^incorrect/ || $solved eq '') {
                    285:       $message = "Incorrect";
                    286:       $button=1;
1.37      albertel  287:     } else {
1.43      albertel  288:       $message = "<b>You are correct.</b> Your receipt is ".
                    289: 	&Apache::lonnet::receipt;
                    290:       $button=0;
                    291:       $previousmsg='';
                    292:     }
                    293:   } elsif ($award eq 'NO_RESPONSE') {
                    294:     $message = '';
                    295:     $button=1;
                    296:   } elsif ($award eq 'MISSING_ANSWER') {
                    297:     $message = 'Some parts were not submitted';
                    298:     $button = 1;
                    299:   } elsif ($award eq 'WANTED_NUMERIC') {
                    300:     $message = "This question expects a numeric answer";
1.79      albertel  301:     $button=1;
                    302:   } elsif ($award eq 'MISORDERED_RANK') {
1.81      www       303:     $message = 'You have provided an invalid ranking, please refer to '.
                    304:      &Apache::loncommon::help_open_topic('Ranking_Problems','help on ranking problems').'.';
1.80      www       305:     $button=1;
                    306:   } elsif ($award eq 'INVALID_FILETYPE') {
                    307:     $message = 'The filetype extension of the file you uploaded is not allowed.';
1.43      albertel  308:     $button=1;
                    309:   } elsif ($award eq 'SIG_FAIL') {
                    310:     $message = "Please adjust significant figures.";# you provided %s significant figures";
                    311:     $button=1;
                    312:   } elsif ($award eq 'UNIT_FAIL') {
1.82      www       313:     $message = "Units incorrect. ".
                    314:        &Apache::loncommon::help_open_topic('Physical_Units'); #Computer reads units as %s";
1.43      albertel  315:     $button=1;
                    316:   } elsif ($award eq 'UNIT_NOTNEEDED') {
                    317:     $message = "Only a number required.";# Computer reads units of %s";
                    318:     $button=1;
                    319:   } elsif ($award eq 'NO_UNIT') {
1.82      www       320:     $message = "Units required".
                    321:        &Apache::loncommon::help_open_topic('Physical_Units');
1.43      albertel  322:     $button=1;
                    323:   } elsif ($award eq 'BAD_FORMULA') {
                    324:     $message = "Unable to understand formula";
                    325:     $button=1;
                    326:   } elsif ($award eq 'INCORRECT') {
                    327:     $message = "Incorrect";
                    328:     $button=1;
                    329:   } elsif ($award eq 'SUBMITTED') {
                    330:     $message = "Your submission has been recorded.";
                    331:     $button=1;
1.59      ng        332:   } elsif ($award eq 'DRAFT') {
                    333:     $message = "A draft copy has been saved.";
                    334:     $button=1;
1.43      albertel  335:   } else {
                    336:     $message = "Unknown message: $award";
                    337:     $button=1;
                    338:   }
1.86    ! sakharuk  339:   if ($Apache::lonhomework::type eq 'exam') {$message='';$previousmsg='';}
1.43      albertel  340:   return ($button,$message,$previousmsg);
1.12      albertel  341: }
                    342: 
                    343: sub setgradedata {
1.43      albertel  344:   my ($award,$id,$previously_used) = @_;
                    345:   # if the student already has it correct, don't modify the status
1.71      albertel  346:   if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
                    347:       $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
1.53      albertel  348:     $Apache::lonhomework::results{"resource.$id.afterduedate"}=$award;
                    349:     return '';
                    350:   } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~
1.43      albertel  351:        /^correct/ ) {
                    352:     #handle assignment of tries and solved status
1.53      albertel  353:     if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
                    354:       $Apache::lonhomework::results{"resource.$id.afterduedate"}='';
                    355:     }
1.43      albertel  356:     if ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
                    357:       $Apache::lonhomework::results{"resource.$id.tries"} =
                    358: 	$Apache::lonhomework::history{"resource.$id.tries"} + 1;
                    359:       $Apache::lonhomework::results{"resource.$id.solved"} =
                    360: 	'correct_by_student';
                    361:       $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
                    362:     } elsif ( $award eq 'INCORRECT' ) {
                    363:       $Apache::lonhomework::results{"resource.$id.tries"} =
                    364: 	$Apache::lonhomework::history{"resource.$id.tries"} + 1;
                    365:       $Apache::lonhomework::results{"resource.$id.solved"} =
1.59      ng        366: 	'incorrect_attempted'
1.43      albertel  367:     } elsif ( $award eq 'SUBMITTED' ) {
                    368:       $Apache::lonhomework::results{"resource.$id.tries"} =
                    369: 	$Apache::lonhomework::history{"resource.$id.tries"} + 1;
                    370:       $Apache::lonhomework::results{"resource.$id.solved"} =
                    371: 	'ungraded_attempted';
1.59      ng        372:     } elsif ( $award eq 'DRAFT' ) {
                    373:       $Apache::lonhomework::results{"resource.$id.solved"} = '';
1.43      albertel  374:     } elsif ( $award eq 'NO_RESPONSE' ) {
                    375:       return '';
                    376:     } else {
                    377:       $Apache::lonhomework::results{"resource.$id.solved"} =
                    378: 	'incorrect_attempted';
                    379:     }
                    380: 
                    381:     # check if this was a previous submission if it was delete the
                    382:     # unneeded data and update the previously_used attribute
                    383:     if ( $previously_used eq 'PREVIOUSLY_USED') {
                    384:       delete($Apache::lonhomework::results{"resource.$id.tries"});
                    385:       $Apache::lonhomework::results{"resource.$id.previous"} = '1';
                    386:     } elsif ( $previously_used eq 'PREVIOUSLY_LAST') {
1.58      ng        387:       #delete all data as they student didn't do anything, but save
                    388:       #the list of collaborators.
1.43      albertel  389:       foreach my $key (keys(%Apache::lonhomework::results)) {
1.58      ng        390: 	if (($key =~ /^resource\.$id\./) && ($key !~ /\.collaborators$/)) {
1.43      albertel  391: 	  &Apache::lonxml::debug("Removing $key");
1.85      albertel  392: 	  delete($Apache::lonhomework::results{$key});
1.43      albertel  393: 	}
                    394:       }
                    395:       #and since they didn't do anything we were never here
                    396:       return '';
                    397:     } else {
                    398:       $Apache::lonhomework::results{"resource.$id.previous"} = '0';
1.40      albertel  399:     }
1.85      albertel  400:   } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} =~
                    401: 	    /^correct/ ) {
                    402:       #delete all data as they student already has it correct
                    403:       foreach my $key (keys(%Apache::lonhomework::results)) {
                    404: 	  if (($key =~ /^resource\.$id\./) && ($key !~ /\.collaborators$/)) {
                    405: 	      &Apache::lonxml::debug("Removing $key");
                    406: 	      delete($Apache::lonhomework::results{$key});
                    407: 	  }
                    408:       }
                    409:       #and since they didn't do anything we were never here
                    410:       return '';
1.43      albertel  411:   }
                    412:   $Apache::lonhomework::results{"resource.$id.award"} = $award;
1.10      albertel  413: }
                    414: 
1.9       albertel  415: sub grade {
1.43      albertel  416:   my ($target) = @_;
                    417:   my $id = $Apache::inputtags::part;
                    418:   my $response='';
                    419:   if ( defined $ENV{'form.submitted'}) {
                    420:     my @awards = ();
                    421:     foreach $response (@Apache::inputtags::responselist) {
                    422:       &Apache::lonxml::debug("looking for response.$id.$response.awarddetail");
                    423:       my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"};
1.54      albertel  424:       &Apache::lonxml::debug("keeping $value from $response for $id");
                    425:       push (@awards,$value);
1.43      albertel  426:     }
                    427:     my $finalaward = &finalizeawards(@awards);
                    428:     my $previously_used;
                    429:     if ( $#Apache::inputtags::previous eq $#awards ) {
1.75      albertel  430: 	my $match=0;
                    431: 	my @matches;
                    432: 	foreach my $versionar (@Apache::inputtags::previous_version) {
                    433: 	    foreach my $version (@$versionar) {
                    434: 		$matches[$version]++;
                    435: 	    }
                    436: 	}
                    437: 	foreach my $elem (@matches) {if ($elem eq ($#awards+1)) {$match=1;}}
                    438: 	if ($match) {
                    439: 	    $previously_used = 'PREVIOUSLY_LAST';
                    440: 	    foreach my $value (@Apache::inputtags::previous) {
                    441: 		if ($value eq 'PREVIOUSLY_USED' ) {
                    442: 		    $previously_used = $value;
                    443: 		    last;
                    444: 		}
                    445: 	    }
1.43      albertel  446: 	}
                    447:     }
                    448:     &Apache::lonxml::debug("final award $finalaward, $previously_used");
                    449:     &setgradedata($finalaward,$id,$previously_used);
                    450:   }
                    451:   return '';
1.1       albertel  452: }
                    453: 
1.11      albertel  454: sub gradestatus {
1.63      sakharuk  455:   my ($id,$target) = @_;
1.43      albertel  456:   my $showbutton = 1;
                    457:   my $message = '';
1.53      albertel  458:   my $latemessage = '';
1.43      albertel  459:   my $trystr='';
                    460:   my $button='';
                    461:   my $previousmsg='';
                    462: 
                    463:   my $status = $Apache::inputtags::status['-1'];
                    464:   &Apache::lonxml::debug("gradestatus has :$status:");
1.77      albertel  465:   if ( $status ne 'CLOSED' && $status ne 'UNAVAILABLE') {  
1.43      albertel  466:     my $award = $Apache::lonhomework::history{"resource.$id.award"};
                    467:     my $solved = $Apache::lonhomework::history{"resource.$id.solved"};
                    468:     my $previous = $Apache::lonhomework::history{"resource.$id.previous"};
                    469:     &Apache::lonxml::debug("Found Award |$award|$solved|");
                    470:     if ( $award ne '' ) {
                    471:       &Apache::lonxml::debug('Getting message');
                    472:       ($showbutton,$message,$previousmsg) =
1.68      sakharuk  473: 	&decideoutput($award,$solved,$previous,$target);
1.63      sakharuk  474:       if ($target eq 'tex') {
                    475: 	$message=' '.$message.' ';
                    476:       } else {
                    477: 	$message="<td bgcolor=\"#aaffaa\">$message</td>";
                    478: 	if ($previousmsg) {
                    479: 	  $previousmsg="<td bgcolor=\"#ffaaaa\">$previousmsg</td>";
                    480: 	}
1.43      albertel  481:       }
                    482:     }
                    483:     my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
                    484:     my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
                    485:     &Apache::lonxml::debug("got maxtries of :$maxtries:");
                    486:     if ( $tries eq '' ) { $tries = '0'; }
                    487:     if ( $maxtries eq '' ) { $maxtries = '2'; } 
                    488:     if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; } 
                    489:     if ( $showbutton ) {
1.63      sakharuk  490:       if ($target eq 'tex') {
1.69      sakharuk  491: 	  if ($ENV{'request.state'} ne "construct") {
1.70      sakharuk  492: 	      $trystr = ' {\small \textit{Tries} '.$tries.'/'.$maxtries.'} \vskip 0 mm ';
1.83      sakharuk  493: 	  } else {
                    494: 	      $trystr = '\vskip 0 mm ';
1.67      sakharuk  495: 	  }
1.63      sakharuk  496:       } else {
                    497:          $trystr = "<td>Tries $tries/$maxtries</td>";
                    498:       }
1.43      albertel  499:     }
                    500:     if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
                    501:     if ( $showbutton ) { 
1.63      sakharuk  502:       if ($target ne 'tex') {
                    503:         $button = '<br /><input type="submit" name="submit" value="Submit Answer" />';
                    504:       }
1.43      albertel  505:     }
1.53      albertel  506:     if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
                    507:       #last submissions was after due date
1.63      sakharuk  508:       if ($target eq 'tex') {
                    509: 	  $latemessage=' The last submission was after the Due Date ';
                    510:       } else {
                    511:         $latemessage="<td bgcolor=\"#ffaaaa\">The last submission was after the Due Date</td>";
                    512:       }
1.53      albertel  513:     }
1.43      albertel  514:   }
1.53      albertel  515:   my $output= $previousmsg.$latemessage.$message.$trystr;
1.43      albertel  516:   if ($output =~ /^\s*$/) {
                    517:     return $button;
                    518:   } else {
1.63      sakharuk  519:     if ($target eq 'tex') {
                    520:       return $button.' \vskip 0 mm '.$output.' ';
                    521:     } else {
                    522:       return $button.'<table><tr>'.$output.'</tr></table>';
                    523:     }
1.43      albertel  524:   }
1.11      albertel  525: }
1.1       albertel  526: 1;
                    527: __END__
1.43      albertel  528:  

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