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

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

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