File:  [LON-CAPA] / loncom / homework / inputtags.pm
Revision 1.187: download - view: text, annotated - select for diffs
Tue Feb 21 22:41:29 2006 UTC (18 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- if students submitted portfolio items that don't exist let them know

    1: # The LearningOnline Network with CAPA
    2: # input  definitons
    3: #
    4: # $Id: inputtags.pm,v 1.187 2006/02/21 22:41:29 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: package Apache::inputtags;
   29: use HTML::Entities();
   30: use strict;
   31: use Apache::loncommon;
   32: use Apache::lonlocal;
   33: use Apache::lonnet;
   34: 
   35: BEGIN {
   36:     &Apache::lonxml::register('Apache::inputtags',('hiddenline','textfield','textline'));
   37: }
   38: 
   39: #   Initializes a set of global variables used during the parse of the problem.
   40: #
   41: #  @Apache::inputtags::input        - List of current input ids.
   42: #  @Apache::inputtags::inputlist    - List of all input ids seen this problem.
   43: #  @Apache::inputtags::response     - List of all current resopnse ids.
   44: #  @Apache::inputtags::responselist - List of all response ids seen this 
   45: #                                       problem.
   46: #  @Apache::inputtags::hint         - List of all hint ids.
   47: #  @Apache::inputtags::hintlist     - List of all hint ids seen this problem.
   48: #  @Apache::inputtags::previous     - List describing if specific responseds
   49: #                                       have been used
   50: #  @Apache::inputtags::previous_version - Submission responses were used in.
   51: #  $Apache::inputtags::part         - Current part id (valid only in 
   52: #                                       <problem>)
   53: #                                     0 if not in a part.
   54: #  @Apache::inputtags::partlist     - List of part ids seen in the current
   55: #                                       <problem>
   56: #  @Apache::inputtags::status       - List of problem  statuses. First 
   57: #                                     element is the status of the <problem>
   58: #                                     the remainder are for individual <part>s.
   59: #  %Apache::inputtags::params       - Hash of defined parameters for the
   60: #                                     current response.
   61: #  @Apache::inputtags::import       - List of all ids for <import> thes get
   62: #                                     join()ed and prepended.
   63: #  @Apache::inputtags::importlist   - List of all import ids seen.
   64: #  $Apache::inputtags::response_with_no_part
   65: #                                   - Flag set true if we have seen a response
   66: #                                     that is not inside a <part>
   67: #  %Apache::inputtags::answertxt    - <*response> tags store correct
   68: #                                     answer strings for display by <textline/>
   69: #                                     in this hash.
   70: 
   71: sub initialize_inputtags {
   72:     @Apache::inputtags::input=();
   73:     @Apache::inputtags::inputlist=();
   74:     @Apache::inputtags::response=();
   75:     @Apache::inputtags::responselist=();
   76:     @Apache::inputtags::hint=();
   77:     @Apache::inputtags::hintlist=();
   78:     @Apache::inputtags::previous=();
   79:     @Apache::inputtags::previous_version=();
   80:     $Apache::inputtags::part='';
   81:     @Apache::inputtags::partlist=();
   82:     @Apache::inputtags::status=();
   83:     %Apache::inputtags::params=();
   84:     @Apache::inputtags::import=();
   85:     @Apache::inputtags::importlist=();
   86:     $Apache::inputtags::response_with_no_part=0;
   87:     %Apache::inputtags::answertxt=();
   88: }
   89: 
   90: sub check_for_duplicate_ids {
   91:     my %check;
   92:     foreach my $id (@Apache::inputtags::partlist,
   93: 		    @Apache::inputtags::responselist,
   94: 		    @Apache::inputtags::hintlist,
   95: 		    @Apache::inputtags::importlist) {
   96: 	$check{$id}++;
   97:     }
   98:     my @duplicates;
   99:     foreach my $id (sort(keys(%check))) {
  100: 	if ($check{$id} > 1) {
  101: 	    push(@duplicates,$id);
  102: 	}
  103:     }
  104:     if (@duplicates) {
  105: 	&Apache::lonxml::error("Duplicated ids found, problem will operate incorrectly. Duplicated ids seen: ",join(', ',@duplicates));
  106:     }
  107: }
  108: 
  109: sub start_input {
  110:     my ($parstack,$safeeval)=@_;
  111:     my $id = &Apache::lonxml::get_param('id',$parstack,$safeeval);
  112:     if ($id eq '') { $id = $Apache::lonxml::curdepth; }
  113:     push (@Apache::inputtags::input,$id);
  114:     push (@Apache::inputtags::inputlist,$id);
  115:     return $id;
  116: }
  117: 
  118: sub end_input {
  119:     pop @Apache::inputtags::input;
  120:     return '';
  121: }
  122: 
  123: sub addchars {
  124:     my ($fieldid,$addchars)=@_;
  125:     my $output='';
  126:     foreach (split(/\,/,$addchars)) {
  127: 	$output.='<a href="javascript:void(document.forms.lonhomework.'.
  128: 	    $fieldid.'.value+=\''.$_.'\')">'.$_.'</a> ';
  129:     }
  130:     return $output;
  131: }
  132: 
  133: sub start_textfield {
  134:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  135:     my $result = "";
  136:     my $id = &start_input($parstack,$safeeval);
  137:     my $resid=$Apache::inputtags::response[-1];
  138:     if ($target eq 'web') {
  139: 	$Apache::lonxml::evaluate--;
  140: 	if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
  141: 	    my $partid=$Apache::inputtags::part;
  142: 	    my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$resid.submission"},'<>&"');
  143: 	    my $cols = &Apache::lonxml::get_param('cols',$parstack,$safeeval);
  144: 	    if ( $cols eq '') { $cols = 80; }
  145: 	    my $rows = &Apache::lonxml::get_param('rows',$parstack,$safeeval);
  146: 	    if ( $rows eq '') { $rows = 16; }
  147: 	    my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval);
  148: 	    $result='';
  149: 	    if ($addchars) {
  150: 		$result.=&addchars('HWVAL_'.$resid,$addchars);
  151: 	    }
  152: 	    push @Apache::lonxml::htmlareafields,'HWVAL_'.$resid;
  153: 	    $result.= '<textarea wrap="hard" name="HWVAL_'.$resid.'" id="HWVAL_'.$resid.'" '.
  154: 		"rows=\"$rows\" cols=\"$cols\">".$oldresponse;
  155: 	    if ($oldresponse ne '') {
  156: 
  157: 		#get rid of any startup text if the user has already responded
  158: 		&Apache::lonxml::get_all_text("/textfield",$parser,$style);
  159: 	    }
  160: 	} else {
  161: 	    #right or wrong don't show it
  162: 	    #$result='<table border="1"><tr><td><i>'.$oldresponse.'</i></td></tr></table>';
  163: 	    $result='';
  164: 	    #get rid of any startup text
  165: 	    &Apache::lonxml::get_all_text("/textfield",$parser,$style);
  166: 	}
  167:     } elsif ($target eq 'grade') {
  168: 	my $seedtext=&Apache::lonxml::get_all_text("/textfield",$parser,
  169: 						   $style);
  170: 	if ($seedtext eq $env{'form.HWVAL_'.$resid}) {
  171: 	    # if the seed text is still there it wasn't a real submission
  172: 	    $env{'form.HWVAL_'.$resid}='';
  173: 	}
  174:     } elsif ($target eq 'edit') {
  175: 	$result.=&Apache::edit::tag_start($target,$token);
  176: 	$result.=&Apache::edit::text_arg('Rows:','rows',$token,4);
  177: 	$result.=&Apache::edit::text_arg('Columns:','cols',$token,4);
  178: 	$result.=&Apache::edit::text_arg
  179: 	    ('Click-On Texts (comma sep):','addchars',$token,10);
  180: 	my $bodytext=&Apache::lonxml::get_all_text("/textfield",$parser,
  181: 						   $style);
  182: 	$result.=&Apache::edit::editfield($token->[1],$bodytext,'Text you want to appear by default:',80,2);
  183:     } elsif ($target eq 'modified') {
  184: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  185: 						     $safeeval,'rows','cols',
  186: 						     'addchars');
  187: 	if ($constructtag) {
  188: 	    $result = &Apache::edit::rebuild_tag($token);
  189: 	} else {
  190: 	    $result=$token->[4];
  191: 	}
  192: 	$result.=&Apache::edit::modifiedfield("/textfield",$parser);
  193:     } elsif ($target eq 'tex') {
  194: 	my $number_of_lines = &Apache::lonxml::get_param('rows',$parstack,$safeeval);
  195: 	my $width_of_box = &Apache::lonxml::get_param('cols',$parstack,$safeeval);
  196: 	if ($$tagstack[-2] eq 'essayresponse' and $Apache::lonhomework::type eq 'exam') {
  197: 	    $result = '\fbox{\fbox{\parbox{\textwidth-5mm}{';
  198: 	    for (my $i=0;$i<int $number_of_lines*2;$i++) {$result.='\strut \\\\ ';}
  199: 	    $result.='\strut \\\\\strut \\\\\strut \\\\\strut \\\\}}}';
  200: 	} else {
  201: 	    my $TeXwidth=$width_of_box/80;
  202: 	    $result = '\vskip 1 mm \fbox{\fbox{\parbox{'.$TeXwidth.'\textwidth-5mm}{';
  203: 	    for (my $i=0;$i<int $number_of_lines*2;$i++) {$result.='\strut \\\\ ';}
  204: 	    $result.='}}}\vskip 2 mm ';
  205: 	}
  206:     }
  207:     return $result;
  208: }
  209: 
  210: sub end_textfield {
  211:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  212:     my $result;
  213:     if ($target eq 'web') {
  214: 	$Apache::lonxml::evaluate++;
  215: 	if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
  216: 	    return "</textarea>";
  217: 	}
  218:     } elsif ($target eq 'edit') {
  219: 	$result=&Apache::edit::end_table();
  220:     }
  221:     &end_input;
  222:     return $result;
  223: }
  224: 
  225: sub start_textline {
  226:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  227:     my $result = "";
  228:     if ($target eq 'web') {
  229: 	$Apache::lonxml::evaluate--;
  230: 	my $partid=$Apache::inputtags::part;
  231: 	my $id=$Apache::inputtags::response[-1];
  232: 	if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
  233: 	    my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
  234: 	    my $maxlength;
  235: 	    if ($size eq '') { $size=20; } else {
  236: 		if ($size < 20) { $maxlength=$size; }
  237: 	    }
  238: 	    my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"},'<>&"');
  239: 	    if ($Apache::lonhomework::type ne 'exam') {
  240: 		my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval);
  241: 		$result='';
  242: 		if ($addchars) {
  243: 		    $result.=&addchars('HWVAL_'.$id,$addchars);
  244: 		}
  245: 		my $readonly=&Apache::lonxml::get_param('readonly',$parstack,
  246: 							$safeeval);
  247: 		if (lc($readonly) eq 'yes') {
  248: 		    $readonly=' readonly="readonly" ';
  249: 		} else {
  250: 		    $readonly='';
  251: 		}
  252: 		$result.= '<input type="text" '.$readonly.' name="HWVAL_'.$id.'" value="'.
  253: 		    $oldresponse.'" size="'.$size.'" maxlength="'.$maxlength.'" />';
  254: 	    }
  255: 	} else {
  256: 	    #right or wrong don't show what was last typed in.
  257: 	    $result='<b>'.$Apache::inputtags::answertxt{$id}.'</b>';
  258: 	    #$result='';
  259: 	}
  260:     } elsif ($target eq 'edit') {
  261: 	$result=&Apache::edit::tag_start($target,$token);
  262: 	$result.=&Apache::edit::text_arg('Size:','size',$token,'5').
  263: 	    &Apache::edit::text_arg('Click-On Texts (comma sep):',
  264: 				    'addchars',$token,10);
  265:         $result.=&Apache::edit::select_arg('Readonly:','readonly',
  266: 					   ['no','yes'],$token);
  267: 	$result.=&Apache::edit::end_row();
  268: 	$result.=&Apache::edit::end_table();
  269:     } elsif ($target eq 'modified') {
  270: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  271: 						     $safeeval,'size',
  272: 						     'addchars','readonly');
  273: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  274:     } elsif ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
  275: 	my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
  276: 	if ($size != 0) {$size=$size*2; $size.=' mm';} else {$size='40 mm';}
  277: 	$result='\framebox['.$size.'][s]{\tiny\strut}';
  278:     }
  279:     return $result;
  280: }
  281: 
  282: sub end_textline {
  283:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  284:     if    ($target eq 'web') { $Apache::lonxml::evaluate++; }
  285:     elsif ($target eq 'edit') { return ('','no'); }
  286:     return "";
  287: }
  288: 
  289: sub start_hiddenline {
  290:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  291:     my $result = "";
  292:     if ($target eq 'web') {
  293: 	$Apache::lonxml::evaluate--;
  294: 	if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
  295: 	    my $partid=$Apache::inputtags::part;
  296: 	    my $id=$Apache::inputtags::response[-1];
  297: 	    my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"},'<>&"');
  298: 	    if ($Apache::lonhomework::type ne 'exam') {
  299: 		$result= '<input type="hidden" name="HWVAL_'.$id.'" value="'.
  300: 		    $oldresponse.'" />';
  301: 	    }
  302: 	}
  303:     } elsif ($target eq 'edit') {
  304: 	$result=&Apache::edit::tag_start($target,$token);
  305: 	$result.=&Apache::edit::end_table;
  306:     }
  307:     return $result;
  308: }
  309: 
  310: sub end_hiddenline {
  311:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  312:     if    ($target eq 'web') { $Apache::lonxml::evaluate++; }
  313:     elsif ($target eq 'edit') { return ('','no'); }
  314:     return "";
  315: }
  316: 
  317: # $part -> partid
  318: # $id -> responseid
  319: # $uploadefiletypes -> comma seperated list of extensions allowed or * for any
  320: # $which -> 'uploadedonly'  -> only newly uploaded files
  321: #           'portfolioonly' -> only allow files from portfolio
  322: #           'both' -> allow files from either location
  323: # $extratext -> additional text to go between the link and the input box
  324: # returns a table row <tr> 
  325: sub file_selector {
  326:     my ($part,$id,$uploadedfiletypes,$which,$extratext)=@_;
  327:     if (!$uploadedfiletypes) { return ''; }
  328: 
  329:     my $jspart=$part;
  330:     $jspart=~s/\./_/g;
  331: 
  332:     my $result;
  333:     
  334:     $result.='<tr><td>';
  335:     if ($uploadedfiletypes ne '*') {
  336: 	$result.=
  337: 	    &mt('Allowed filetypes: <b>[_1]</b>',$uploadedfiletypes).'<br />';
  338:     }
  339:     if ($which eq 'uploadonly' || $which eq 'both') { 
  340: 	$result.=&mt('Submit a file: (only one file can be uploaded)').
  341: 	    ' <br /><input type="file" size="50" name="HWFILE'.
  342: 	    $jspart.'_'.$id.'" /><br />';
  343: 	my $uploadedfile= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.uploadedfile"},'<>&"');
  344: 
  345: 	if ($uploadedfile) {
  346: 	    my $url=$Apache::lonhomework::history{"resource.$part.$id.uploadedurl"};
  347: 	    &Apache::lonxml::extlink($url);
  348: 	    &Apache::lonnet::allowuploaded('/adm/essayresponse',$url);
  349: 	    my $icon=&Apache::loncommon::icon($url);
  350: 	    my $curfile='<a href="'.$url.'"><img src="'.$icon.
  351: 		'" border="0" />'.$uploadedfile.'</a>';
  352: 	    $result.=&mt('Currently submitted: <tt>[_1]</tt>',$curfile);
  353: 	} else {
  354: 	    #$result.=&mt('(Hand in a file you have prepared on your computer)');
  355: 	}
  356:     }
  357:     if ( $which eq 'both') { 
  358: 	$result.='<br />'.'<strong>'.&mt('OR:').'</strong><br />';
  359:     }
  360:     if ($which eq 'portfolioonly' || $which eq 'both') { 
  361: 	$result.=$extratext.'<a href='."'".'javascript:void(window.open("/adm/portfolio?mode=selectfile&amp;fieldname=HWPORT'.$jspart.'_'.$id.'","cat","height=600,width=800,scrollbars=1,resizable=1,menubar=2,location=1"))'."'".'>'.
  362: 	    &mt('Select Portfolio Files').'</a><br />'.
  363: 	    '<input type="text" size="50" name="HWPORT'.$jspart.'_'.$id.'" value="" />'.
  364: 	    '<br />';
  365: 	if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"}=~/[^\s]/){
  366: 	    my (@filelist,@bad_file_list);
  367: 	    foreach my $file (split(',',&Apache::lonnet::unescape($Apache::lonhomework::history{"resource.$part.$id.portfiles"}))) {
  368: 		my (undef,undef,$domain,$user)=&Apache::lonxml::whichuser();
  369: 		my $url="/uploaded/$domain/$user/portfolio$file";
  370: 		my $icon=&Apache::loncommon::icon($url);
  371: 		push(@filelist,'<a href="'.$url.'"><img src="'.$icon.
  372: 		     '" border="0" />'.$file.'</a>');
  373: 		if (! &Apache::lonnet::stat_file($url)) {
  374: 		    push(@bad_file_list,'<a href="'.$url.'"><img src="'.$icon.
  375: 			 '" border="0" />'.$file.'</a>');
  376: 		}
  377: 	    }
  378: 	    $result.=&mt("Portfolio files previously selected: <strong>[_1]</strong>",join(', ',@filelist));
  379: 	    if (@bad_file_list) {
  380: 		$result.='<br />'.&mt('<font color="red">These file(s) don\'t exist:</font> <strong>[_1]</strong>',join(', ',@bad_file_list));
  381: 	    }
  382: 	}
  383:     }
  384:     $result.='</td></tr>'; 
  385:     return $result;
  386: }
  387: 
  388: sub checkstatus {
  389:     my ($value,$awardref,$msgref)=@_;
  390:     for (my $i=0;$i<=$#$awardref;$i++) {
  391: 	if ($$awardref[$i] eq $value) {
  392: 	    return ($$awardref[$i],$$msgref[$i]);
  393: 	}
  394:     }
  395:     return(undef,undef);
  396: }
  397: 
  398: sub valid_award {
  399:     my ($award) =@_;
  400:     foreach my $possibleaward ('EXTRA_ANSWER','MISSING_ANSWER', 'ERROR',
  401: 			       'NO_RESPONSE',
  402: 			       'TOO_LONG', 'UNIT_INVALID_INSTRUCTOR',
  403: 			       'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE',
  404: 			       'UNIT_FAIL', 'NO_UNIT',
  405: 			       'UNIT_NOTNEEDED', 'WANTED_NUMERIC',
  406: 			       'BAD_FORMULA', 'SIG_FAIL', 'INCORRECT', 
  407: 			       'MISORDERED_RANK', 'INVALID_FILETYPE',
  408: 			       'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
  409: 			       'APPROX_ANS', 'EXACT_ANS','COMMA_FAIL') {
  410: 	if ($award eq $possibleaward) { return 1; }
  411:     }
  412:     return 0;
  413: }
  414: 
  415: sub finalizeawards {
  416:     my ($awardref,$msgref,$nameref,$reverse)=@_;
  417:     my $result=undef;
  418:     my $award;
  419:     my $msg;
  420:     if ($#$awardref == -1) { $result = "NO_RESPONSE"; }
  421:     if ($result eq '' ) {
  422: 	my $blankcount;
  423: 	foreach $award (@$awardref) {
  424: 	    if ($award eq '') {
  425: 		$result='MISSING_ANSWER';
  426: 		$blankcount++;
  427: 	    }
  428: 	}
  429: 	if ($blankcount == ($#$awardref + 1)) { $result = 'NO_RESPONSE'; }
  430:     }
  431:     if (defined($result)) { return ($result,$msg); }
  432: 
  433:     # these awards are ordered from most important error through best correct
  434:     
  435:     my @awards = ('EXTRA_ANSWER', 'MISSING_ANSWER', 'ERROR', 'NO_RESPONSE',
  436: 		  'TOO_LONG',
  437: 		  'UNIT_INVALID_INSTRUCTOR', 'UNIT_INVALID_STUDENT',
  438: 		  'UNIT_IRRECONCIBLE', 'UNIT_FAIL', 'NO_UNIT',
  439: 		  'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA',
  440: 		  'COMMA_FAIL', 'SIG_FAIL', 'INCORRECT', 'MISORDERED_RANK',
  441: 		  'INVALID_FILETYPE', 'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
  442: 		  'APPROX_ANS', 'EXACT_ANS');
  443:     if ($reverse) { @awards=reverse(@awards); }
  444:     foreach my $possibleaward (@awards) {
  445: 	($result,$msg)=&checkstatus($possibleaward,$awardref,$msgref);
  446: 	if (defined($result)) { return ($result,$msg); }
  447:     }
  448:     return ('ERROR',undef);
  449: }
  450: 
  451: sub decideoutput {
  452:     my ($award,$awarded,$awardmsg,$solved,$previous,$target)=@_;
  453:     my $message='';
  454:     my $button=0;
  455:     my $previousmsg;
  456:     my $bgcolor='orange';
  457:     my $added_computer_text=0;
  458:     my %possiblecolors =
  459: 	( 'correct' => '#aaffaa',
  460: 	  'charged_try' => '#ffaaaa',
  461: 	  'not_charged_try' => '#ffffaa',
  462: 	  'no_message' => '#fffff',
  463: 	  );
  464: 
  465:     my $part = $Apache::inputtags::part;
  466:     my $handgrade = 
  467: 	('yes' eq lc(&Apache::lonnet::EXT("resource.$part.handgrade")));
  468:     
  469:     my $computer = ($handgrade)? ''
  470: 	                       : " ".&mt("Computer's answer now shown above.");
  471:     &Apache::lonxml::debug("handgrade has :$handgrade:");
  472: 
  473:     if ($previous) { $previousmsg=&mt('You have entered that answer before'); }
  474:     
  475:     if      ($solved =~ /^correct/) {
  476: 	$bgcolor=$possiblecolors{'correct'};
  477: 	$message=&mt('You are correct.');
  478: 	if ($awarded < 1 && $awarded > 0) {
  479: 	    $message=&mt('You are partially correct.');
  480: 	    $bgcolor=$possiblecolors{'not_charged_try'};
  481: 	} elsif ($awarded < 1) {
  482: 	    $message=&mt('Incorrect.');
  483: 	    $bgcolor=$possiblecolors{'charged_try'};
  484: 	}
  485: 	if ($env{'request.filename'} =~ 
  486: 	    m|/res/lib/templates/examupload.problem$|) {
  487: 	    $message = &mt("A score has been assigned.");
  488: 	    $added_computer_text=1;
  489: 	} else {
  490: 	    if ($target eq 'tex') {
  491: 		$message = '\textbf{'.$message.'}';
  492: 	    } else {
  493: 		$message = "<b>".$message."</b>";
  494: 		$message.= $computer;
  495: 	    }
  496: 	    $added_computer_text=1;
  497: 	    unless ($env{'course.'.
  498: 			     $env{'request.course.id'}.
  499: 			     '.disable_receipt_display'} eq 'yes') { 
  500: 		$message.=(($target eq 'web')?'<br />':' ').
  501: 		    &mt('Your receipt is').' '.&Apache::lonnet::receipt($Apache::inputtags::part).
  502: 		    (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):'');
  503: 	    }
  504: 	}
  505: 	$button=0;
  506: 	$previousmsg='';
  507:     } elsif ($solved =~ /^excused/) {
  508: 	if ($target eq 'tex') {
  509: 	    $message = ' \textbf{'.&mt('You are excused from the problem.').'} ';
  510: 	} else {
  511: 	    $message = "<b>".&mt('You are excused from the problem.')."</b>";
  512: 	}
  513: 	$bgcolor=$possiblecolors{'charged_try'};
  514: 	$button=0;
  515: 	$previousmsg='';
  516:     } elsif ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
  517: 	if ($solved =~ /^incorrect/ || $solved eq '') {
  518: 	    $message = &mt("Incorrect").".";
  519: 	    $bgcolor=$possiblecolors{'charged_try'};
  520: 	    $button=1;
  521: 	} else {
  522: 	    if ($target eq 'tex') {
  523: 		$message = '\textbf{'.&mt('You are correct.').'}';
  524: 	    } else {
  525: 		$message = "<b>".&mt('You are correct.')."</b>";
  526: 		$message.= $computer;
  527: 	    }
  528: 	    $added_computer_text=1;
  529: 	    unless ($env{'course.'.
  530: 			     $env{'request.course.id'}.
  531: 			     '.disable_receipt_display'} eq 'yes') { 
  532: 		$message.=(($target eq 'web')?'<br />':' ').
  533: 		    'Your receipt is '.&Apache::lonnet::receipt($Apache::inputtags::part).
  534: 		    (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):'');
  535: 	    }
  536: 	    $bgcolor=$possiblecolors{'correct'};
  537: 	    $button=0;
  538: 	    $previousmsg='';
  539: 	}
  540:     } elsif ($award eq 'NO_RESPONSE') {
  541: 	$message = '';
  542: 	$bgcolor=$possiblecolors{'no_feedback'};
  543: 	$button=1;
  544:     } elsif ($award eq 'EXTRA_ANSWER') {
  545: 	$message = &mt('Some extra items were submitted.');
  546: 	$bgcolor=$possiblecolors{'not_charged_try'};
  547: 	$button = 1;
  548:     } elsif ($award eq 'MISSING_ANSWER') {
  549: 	$message = &mt('Some items were not submitted.');
  550: 	$bgcolor=$possiblecolors{'not_charged_try'};
  551: 	$button = 1;
  552:     } elsif ($award eq 'ERROR') {
  553: 	$message = &mt('An error occured while grading your answer.');
  554: 	$bgcolor=$possiblecolors{'not_charged_try'};
  555: 	$button = 1;
  556:     } elsif ($award eq 'TOO_LONG') {
  557: 	$message = &mt("The submitted answer was too long.");
  558: 	$bgcolor=$possiblecolors{'not_charged_try'};
  559: 	$button=1;
  560:     } elsif ($award eq 'WANTED_NUMERIC') {
  561: 	$message = &mt("This question expects a numeric answer.");
  562: 	$bgcolor=$possiblecolors{'not_charged_try'};
  563: 	$button=1;
  564:     } elsif ($award eq 'MISORDERED_RANK') {
  565: 	$message = &mt('You have provided an invalid ranking');
  566: 	if ($target ne 'tex') {
  567: 	    $message.=', '.&mt('please refer to').' '.&Apache::loncommon::help_open_topic('Ranking_Problems','help on ranking problems');
  568: 	}
  569: 	$bgcolor=$possiblecolors{'not_charged_try'};
  570: 	$button=1;
  571:     } elsif ($award eq 'INVALID_FILETYPE') {
  572: 	$message = &mt('Submission won\'t be graded. The type of file submitted is not allowed.');
  573: 	$bgcolor=$possiblecolors{'not_charged_try'};
  574: 	$button=1;
  575:     } elsif ($award eq 'SIG_FAIL') {
  576: 	my ($used,$min,$max)=split(':',$awardmsg);
  577: 	my $word;
  578: 	if ($used < $min) { $word=&mt('more'); }
  579: 	if ($used > $max) { $word=&mt('fewer'); }
  580: 	$message = &mt("Submission not graded.  Use [_2] digits.",$used,$word);
  581: 	$bgcolor=$possiblecolors{'not_charged_try'};
  582: 	$button=1;
  583:     } elsif ($award eq 'UNIT_INVALID_INSTRUCTOR') {
  584: 	$message = &mt('Error in instructor specifed unit. This error has been reported to the instructor.', $awardmsg);
  585: 	if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');} 
  586: 	$bgcolor=$possiblecolors{'not_charged_try'};
  587: 	$button=1;
  588:     } elsif ($award eq 'UNIT_INVALID_STUDENT') {
  589: 	$message = &mt('Unable to interpret units. Computer reads units as "[_1]".',&markup_unit($awardmsg,$target));
  590: 	if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');} 
  591: 	$bgcolor=$possiblecolors{'not_charged_try'};
  592: 	$button=1;
  593:     } elsif ($award eq 'UNIT_FAIL' || $award eq 'UNIT_IRRECONCIBLE') {
  594: 	$message = &mt('Incompatible units. No conversion found between "[_1]" and the required units.',&markup_unit($awardmsg,$target));
  595: 	if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');} 
  596: 	$bgcolor=$possiblecolors{'not_charged_try'};
  597: 	$button=1;
  598:     } elsif ($award eq 'UNIT_NOTNEEDED') {
  599: 	$message = &mt('Only a number required. Computer reads units of "[_1]".',&markup_unit($awardmsg,$target));
  600: 	$bgcolor=$possiblecolors{'not_charged_try'};
  601: 	$button=1;
  602:     } elsif ($award eq 'NO_UNIT') {
  603: 	$message = &mt("Units required").'.';
  604: 	if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units')};
  605: 	$bgcolor=$possiblecolors{'not_charged_try'};
  606: 	$button=1;
  607:     } elsif ($award eq 'COMMA_FAIL') {
  608: 	$message = &mt("Proper comma separation is required").'.';
  609: 	$bgcolor=$possiblecolors{'not_charged_try'};
  610: 	$button=1;
  611:     } elsif ($award eq 'BAD_FORMULA') {
  612: 	$message = &mt("Unable to understand formula");
  613: 	$bgcolor=$possiblecolors{'not_charged_try'};
  614: 	$button=1;
  615:     } elsif ($award eq 'INCORRECT') {
  616: 	$message = &mt("Incorrect").'.';
  617: 	$bgcolor=$possiblecolors{'charged_try'};
  618: 	$button=1;
  619:     } elsif ($award eq 'SUBMITTED') {
  620: 	$message = &mt("Your submission has been recorded.");
  621: 	$bgcolor=$possiblecolors{'correct'};
  622: 	$button=1;
  623:     } elsif ($award eq 'DRAFT') {
  624: 	$message = &mt("A draft copy has been saved.");
  625: 	$bgcolor=$possiblecolors{'not_charged_try'};
  626: 	$button=1;
  627:     } elsif ($award eq 'ASSIGNED_SCORE') {
  628: 	$message = &mt("A score has been assigned.");
  629: 	$bgcolor=$possiblecolors{'correct'};
  630: 	$button=0;
  631:     } elsif ($award eq '') {
  632: 	if ($handgrade && $Apache::inputtags::status[-1] eq 'SHOW_ANSWER') {
  633: 	    $message = &mt("Nothing submitted.");
  634: 	    $bgcolor=$possiblecolors{'charged_try'};
  635: 	} else {
  636: 	    $bgcolor=$possiblecolors{'not_charged_try'};
  637: 	}
  638: 	$button=1;
  639:     } else {
  640: 	$message = &mt("Unknown message").": $award";
  641: 	$button=1;
  642:     }
  643:     if (lc($Apache::lonhomework::problemstatus) eq 'no'  && 
  644: 	$Apache::inputtags::status[-1] ne 'SHOW_ANSWER') {
  645: 	$message = &mt("Answer Submitted: Your final submission will be graded after the due date.");
  646: 	$bgcolor=$possiblecolors{'correct'};
  647: 	$button=1;
  648:     }
  649:     if ($Apache::inputtags::status[-1] eq 'SHOW_ANSWER' && 
  650: 	!$added_computer_text && $target ne 'tex') {
  651: 	$message.= $computer;
  652: 	$added_computer_text=1;
  653:     }
  654:     return ($button,$bgcolor,$message,$previousmsg);
  655: }
  656: 
  657: sub markup_unit {
  658:     my ($unit,$target)=@_;
  659:     if ($target eq 'tex') {
  660: 	return '\texttt{'.&Apache::lonxml::latex_special_symbols($unit).'}'; 
  661:     } else {
  662: 	return "<tt>".$unit."</tt>";
  663:     }
  664: }
  665: 
  666: sub removealldata {
  667:     my ($id)=@_;
  668:     foreach my $key (keys(%Apache::lonhomework::results)) {
  669: 	if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
  670: 	    &Apache::lonxml::debug("Removing $key");
  671: 	    delete($Apache::lonhomework::results{$key});
  672: 	}
  673:     }
  674: }
  675: 
  676: sub hidealldata {
  677:     my ($id)=@_;
  678:     foreach my $key (keys(%Apache::lonhomework::results)) {
  679: 	if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
  680: 	    &Apache::lonxml::debug("Hidding $key");
  681: 	    my $newkey=$key;
  682: 	    $newkey=~s/^(resource\.\Q$id\E\.[^\.]+\.)(.*)$/${1}hidden${2}/;
  683: 	    $Apache::lonhomework::results{$newkey}=
  684: 		$Apache::lonhomework::results{$key};
  685: 	    delete($Apache::lonhomework::results{$key});
  686: 	}
  687:     }
  688: }
  689: 
  690: sub setgradedata {
  691:     my ($award,$msg,$id,$previously_used) = @_;
  692:     if ($Apache::lonhomework::scantronmode && 
  693: 	&Apache::lonnet::validCODE($env{'form.CODE'})) {
  694: 	$Apache::lonhomework::results{"resource.CODE"}=$env{'form.CODE'};
  695:     } elsif ($Apache::lonhomework::scantronmode && 
  696: 	     $env{'form.CODE'} eq '' &&
  697: 	     $Apache::lonhomework::history{"resource.CODE"} ne '') {
  698: 	$Apache::lonhomework::results{"resource.CODE"}='';
  699:     }
  700: 
  701:     if (!$Apache::lonhomework::scantronmode &&
  702: 	$Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
  703: 	$Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
  704: 	$Apache::lonhomework::results{"resource.$id.afterduedate"}=$award;
  705: 	return '';
  706:     } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~
  707: 	      /^correct/ || $Apache::lonhomework::scantronmode ||
  708: 	      lc($Apache::lonhomework::problemstatus) eq 'no') {
  709:         # the student doesn't already have it correct,
  710: 	# or we are in a mode (scantron orno problem status) where a correct 
  711:         # can become incorrect
  712: 	# handle assignment of tries and solved status
  713: 	my $solvemsg;
  714: 	if ($Apache::lonhomework::scantronmode) {
  715: 	    $solvemsg='correct_by_scantron';
  716: 	} else {
  717: 	    $solvemsg='correct_by_student';
  718: 	}
  719: 	if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
  720: 	    $Apache::lonhomework::results{"resource.$id.afterduedate"}='';
  721: 	}
  722: 	if ( $award eq 'ASSIGNED_SCORE') {
  723: 	    $Apache::lonhomework::results{"resource.$id.tries"} =
  724: 		$Apache::lonhomework::history{"resource.$id.tries"} + 1;
  725: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
  726: 		$solvemsg;
  727: 	    my $numawards=scalar(@Apache::inputtags::response);
  728: 	    $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
  729: 	    foreach my $res (@Apache::inputtags::response) {
  730: 		$Apache::lonhomework::results{"resource.$id.awarded"}+=
  731: 		    $Apache::lonhomework::results{"resource.$id.$res.awarded"};
  732: 	    }
  733: 	    if ($numawards > 0) {
  734: 		$Apache::lonhomework::results{"resource.$id.awarded"}/=
  735: 		    $numawards;
  736: 	    }
  737: 	} elsif ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
  738: 	    $Apache::lonhomework::results{"resource.$id.tries"} =
  739: 		$Apache::lonhomework::history{"resource.$id.tries"} + 1;
  740: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
  741: 		$solvemsg;
  742: 	    $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
  743: 	} elsif ( $award eq 'INCORRECT' ) {
  744: 	    $Apache::lonhomework::results{"resource.$id.tries"} =
  745: 		$Apache::lonhomework::history{"resource.$id.tries"} + 1;
  746: 	    if (lc($Apache::lonhomework::problemstatus) eq 'no' ||
  747: 		$Apache::lonhomework::scantronmode) {
  748: 		$Apache::lonhomework::results{"resource.$id.awarded"} = 0;
  749: 	    }
  750: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
  751: 		'incorrect_attempted';
  752: 	} elsif ( $award eq 'SUBMITTED' ) {
  753: 	    $Apache::lonhomework::results{"resource.$id.tries"} =
  754: 		$Apache::lonhomework::history{"resource.$id.tries"} + 1;
  755: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
  756: 		'ungraded_attempted';
  757: 	} elsif ( $award eq 'DRAFT' ) {
  758: 	    $Apache::lonhomework::results{"resource.$id.solved"} = '';
  759: 	} elsif ( $award eq 'NO_RESPONSE' ) {
  760: 	    #no real response so delete any data that got stored
  761: 	    &removealldata($id);
  762: 	    return '';
  763: 	} else {
  764: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
  765: 		'incorrect_attempted';
  766: 	    if (lc($Apache::lonhomework::problemstatus) eq 'no' ||
  767: 		$Apache::lonhomework::scantronmode) {
  768: 		$Apache::lonhomework::results{"resource.$id.tries"} =
  769: 		    $Apache::lonhomework::history{"resource.$id.tries"} + 1;
  770: 		$Apache::lonhomework::results{"resource.$id.awarded"} = 0;
  771: 	    }
  772: 	}
  773: 	if (defined($msg)) {
  774: 	    $Apache::lonhomework::results{"resource.$id.awardmsg"} = $msg;
  775: 	}
  776: 	# did either of the overall awards chage? If so ignore the 
  777: 	# previous check
  778: 	if (($Apache::lonhomework::results{"resource.$id.awarded"} eq
  779: 	     $Apache::lonhomework::history{"resource.$id.awarded"}) &&
  780: 	    ($Apache::lonhomework::results{"resource.$id.solved"} eq
  781: 	     $Apache::lonhomework::history{"resource.$id.solved"})) {
  782: 	    # check if this was a previous submission if it was delete the
  783: 	    # unneeded data and update the previously_used attribute
  784: 	    if ( $previously_used eq 'PREVIOUSLY_USED') {
  785: 		if (lc($Apache::lonhomework::problemstatus) ne 'no') {
  786: 		    delete($Apache::lonhomework::results{"resource.$id.tries"});
  787: 		    $Apache::lonhomework::results{"resource.$id.previous"} = '1';
  788: 		}
  789: 	    } elsif ( $previously_used eq 'PREVIOUSLY_LAST') {
  790: 		#delete all data as they student didn't do anything, but save
  791: 		#the list of collaborators.
  792: 		&removealldata($id);
  793: 		#and since they didn't do anything we were never here
  794: 		return '';
  795: 	    } else {
  796: 		$Apache::lonhomework::results{"resource.$id.previous"} = '0';
  797: 	    }
  798: 	}
  799:     } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} =~
  800: 	      /^correct/ ) {
  801: 	#delete all data as they student already has it correct
  802: 	&removealldata($id);
  803: 	#and since they didn't do anything we were never here
  804: 	return '';
  805:     }
  806:     $Apache::lonhomework::results{"resource.$id.award"} = $award;
  807:     if ($award eq 'SUBMITTED') {
  808: 	&Apache::response::add_to_gradingqueue();
  809:     }
  810: }
  811: 
  812: sub grade {
  813:     my ($target) = @_;
  814:     my $id = $Apache::inputtags::part;
  815:     my $response='';
  816:     if ( defined $env{'form.submitted'}) {
  817: 	my (@awards,@msgs);
  818: 	foreach $response (@Apache::inputtags::response) {
  819: 	    &Apache::lonxml::debug("looking for response.$id.$response.awarddetail");
  820: 	    my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"};
  821: 	    &Apache::lonxml::debug("keeping $value from $response for $id");
  822: 	    push (@awards,$value);
  823: 	    $value=$Apache::lonhomework::results{"resource.$id.$response.awardmsg"};
  824: 	    &Apache::lonxml::debug("got message $value from $response for $id");
  825: 	    push (@msgs,$value);
  826: 	}
  827: 	my ($finalaward,$msg) = &finalizeawards(\@awards,\@msgs);
  828: 	my $previously_used;
  829: 	if ( $#Apache::inputtags::previous eq $#awards ) {
  830: 	    my $match=0;
  831: 	    my @matches;
  832: 	    foreach my $versionar (@Apache::inputtags::previous_version) {
  833: 		foreach my $version (@$versionar) {
  834: 		    $matches[$version]++;
  835: 		}
  836: 	    }
  837: 	    foreach my $elem (@matches) {if ($elem eq ($#awards+1)) {$match=1;}}
  838: 	    if ($match) {
  839: 		$previously_used = 'PREVIOUSLY_LAST';
  840: 		foreach my $value (@Apache::inputtags::previous) {
  841: 		    if ($value eq 'PREVIOUSLY_USED' ) {
  842: 			$previously_used = $value;
  843: 			last;
  844: 		    }
  845: 		}
  846: 	    }
  847: 	}
  848: 	&Apache::lonxml::debug("final award $finalaward, $previously_used, message $msg");
  849: 	&setgradedata($finalaward,$msg,$id,$previously_used);
  850:     }
  851:     return '';
  852: }
  853: 
  854: sub gradestatus {
  855:     my ($id,$target) = @_;
  856:     my $showbutton = 1;
  857:     my $bgcolor = '';
  858:     my $message = '';
  859:     my $latemessage = '';
  860:     my $trystr='';
  861:     my $button='';
  862:     my $previousmsg='';
  863: 
  864:     my $status = $Apache::inputtags::status['-1'];
  865:     &Apache::lonxml::debug("gradestatus has :$status:");
  866:     if ( $status ne 'CLOSED' 
  867: 	 && $status ne 'UNAVAILABLE' 
  868: 	 && $status ne 'INVALID_ACCESS' 
  869: 	 && $status ne 'NEEDS_CHECKIN' 
  870: 	 && $status ne 'NOT_IN_A_SLOT') {  
  871: 	my $award = $Apache::lonhomework::history{"resource.$id.award"};
  872: 	my $awarded = $Apache::lonhomework::history{"resource.$id.awarded"};
  873: 	my $solved = $Apache::lonhomework::history{"resource.$id.solved"};
  874: 	my $previous = $Apache::lonhomework::history{"resource.$id.previous"};
  875: 	my $awardmsg = $Apache::lonhomework::history{"resource.$id.awardmsg"};
  876: 	&Apache::lonxml::debug("Found Award |$award|$solved|$awardmsg");
  877: 	if ( $award ne '' || $solved ne '' || $status eq 'SHOW_ANSWER') {
  878: 	    &Apache::lonxml::debug('Getting message');
  879: 	    ($showbutton,$bgcolor,$message,$previousmsg) =
  880: 		&decideoutput($award,$awarded,$awardmsg,$solved,$previous,
  881: 			      $target);
  882: 	    if ($target eq 'tex') {
  883: 		$message='\vskip 2 mm '.$message.' ';
  884: 	    } else {
  885: 		$message="<td bgcolor=\"$bgcolor\">$message</td>";
  886: 		if ($previousmsg) {
  887: 		    $previousmsg="<td bgcolor=\"#aaaaff\">$previousmsg</td>";
  888: 		}
  889: 	    }
  890: 	}
  891: 	my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
  892: 	my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
  893: 	&Apache::lonxml::debug("got maxtries of :$maxtries:");
  894: 	#if tries are set to negative turn off the Tries/Button and messages
  895: 	if (defined($maxtries) && $maxtries < 0) { return ''; }
  896: 	if ( $tries eq '' ) { $tries = '0'; }
  897: 	if ( $maxtries eq '' ) { $maxtries = '2'; } 
  898: 	if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; } 
  899: 	my $tries_text=&mt('Tries');
  900: 	if ( $Apache::lonhomework::type eq 'survey' ||
  901: 	     $Apache::lonhomework::parsing_a_task) {
  902: 	    $tries_text=&mt('Submissions');
  903: 	}
  904: 	if ( $showbutton ) {
  905: 	    if ($target eq 'tex') {
  906: 		if ($env{'request.state'} ne "construct" && $Apache::lonhomework::type ne 'exam' && $env{'form.suppress_tries'} ne 'yes') {
  907: 		    $trystr = ' {\vskip 1 mm \small \textit{'.$tries_text.'} '.$tries.'/'.$maxtries.'} \vskip 2 mm ';
  908: 		} else {
  909: 		    $trystr = '\vskip 0 mm ';
  910: 		}
  911: 	    } else {
  912: 		$trystr = "<td><nobr>".$tries_text." $tries";
  913: 		if ($Apache::lonhomework::parsing_a_task) {
  914: 		} elsif($env{'request.state'} ne 'construct') {
  915: 		    $trystr.="/$maxtries";
  916: 		} else {
  917: 		    if (defined($Apache::inputtags::params{'maxtries'})) {
  918: 			$trystr.="/".$Apache::inputtags::params{'maxtries'};
  919: 		    }
  920: 		}
  921: 		$trystr.="</nobr></td>";
  922: 	    }
  923: 	}
  924: 	if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
  925: 	if ( $showbutton ) { 
  926: 	    if ($target ne 'tex') {
  927: 		$button = '<input type="submit" name="submit_'.$id.'" value="'.&mt('Submit Answer').'" />';
  928: 	    }
  929: 	}
  930: 	if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
  931: 	    #last submissions was after due date
  932: 	    $latemessage=&mt(' The last submission was after the Due Date ');;
  933: 	    if ($target eq 'web') {
  934: 		$latemessage='<td bgcolor="#ffaaaa">'.$latemessage.'</td>';
  935: 	    }
  936: 	}
  937:     }
  938:     my $output= $previousmsg.$latemessage.$message.$trystr;
  939:     if ($output =~ /^\s*$/) {
  940: 	return $button;
  941:     } else {
  942: 	if ($target eq 'tex') {
  943: 	    return $button.' \vskip 0 mm '.$output.' ';
  944: 	} else {
  945: 	    return '<table><tr><td>'.$button.'</td>'.$output.'</tr></table>';
  946: 	}
  947:     }
  948: }
  949: 1;
  950: __END__
  951:  

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