File:  [LON-CAPA] / loncom / homework / inputtags.pm
Revision 1.189: download - view: text, annotated - select for diffs
Thu Mar 9 00:43:05 2006 UTC (18 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- add exam_box support to <hiddenline />

    1: # The LearningOnline Network with CAPA
    2: # input  definitons
    3: #
    4: # $Id: inputtags.pm,v 1.189 2006/03/09 00:43:05 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: 
   28: 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 exam_box {
  226:     my ($target) = @_;
  227:     my $result;
  228: 
  229:     if ($target eq 'tex') {
  230: 	$result.='\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}';
  231: 	my $repetition = &Apache::response::repetition();
  232: 	$result.='\begin{enumerate}';
  233: 	foreach my $i (0..$repetition-1) {
  234: 	    $result.='\item[\textbf{'.
  235: 		($Apache::lonxml::counter+$i).
  236: 		'}.]\textit{Leave blank on scoring form}\vskip 0 mm';
  237: 	}
  238: 	$result.= '\end{enumerate}';
  239: 
  240:     } elsif ($target eq 'web') {
  241: 	my $id=$Apache::inputtags::response[-1];
  242: 	$result.= '<br /><br />
  243:                    <textarea name="HWVAL_'.$id.'" rows="4" cols="50">
  244:                    </textarea> <br /><br />';
  245:     }
  246:     return $result;
  247: }
  248: 
  249: sub needs_exam_box {
  250:     my ($tagstack) = @_;
  251:     my @tags = ('formularesponse',
  252: 		'stringresponse',
  253: 		'reactionresponse',
  254: 		'organicresponse',
  255: 		'imageresponse',
  256: 		);
  257: 
  258:     foreach my $tag (@tags) {
  259: 	if (grep(/\Q$tag\E/,@$tagstack)) {
  260: 	    return 1;
  261: 	}
  262:     }
  263:     return 0;
  264: }
  265: 
  266: sub start_textline {
  267:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  268:     my $result = "";
  269:     if ($target eq 'web') {
  270: 	$Apache::lonxml::evaluate--;
  271: 	my $partid=$Apache::inputtags::part;
  272: 	my $id=$Apache::inputtags::response[-1];
  273: 	if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
  274: 	    my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
  275: 	    my $maxlength;
  276: 	    if ($size eq '') { $size=20; } else {
  277: 		if ($size < 20) { $maxlength=$size; }
  278: 	    }
  279: 	    my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"},'<>&"');
  280: 	    if ($Apache::lonhomework::type ne 'exam') {
  281: 		my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval);
  282: 		$result='';
  283: 		if ($addchars) {
  284: 		    $result.=&addchars('HWVAL_'.$id,$addchars);
  285: 		}
  286: 		my $readonly=&Apache::lonxml::get_param('readonly',$parstack,
  287: 							$safeeval);
  288: 		if (lc($readonly) eq 'yes') {
  289: 		    $readonly=' readonly="readonly" ';
  290: 		} else {
  291: 		    $readonly='';
  292: 		}
  293: 		$result.= '<input type="text" '.$readonly.' name="HWVAL_'.$id.'" value="'.
  294: 		    $oldresponse.'" size="'.$size.'" maxlength="'.$maxlength.'" />';
  295: 	    }
  296: 	    if ($Apache::lonhomework::type eq 'exam'
  297: 		&& &needs_exam_box($tagstack)) {
  298: 		$result.=&exam_box($target);
  299: 	    }
  300: 	} else {
  301: 	    #right or wrong don't show what was last typed in.
  302: 	    $result='<b>'.$Apache::inputtags::answertxt{$id}.'</b>';
  303: 	    #$result='';
  304: 	}
  305:     } elsif ($target eq 'edit') {
  306: 	$result=&Apache::edit::tag_start($target,$token);
  307: 	$result.=&Apache::edit::text_arg('Size:','size',$token,'5').
  308: 	    &Apache::edit::text_arg('Click-On Texts (comma sep):',
  309: 				    'addchars',$token,10);
  310:         $result.=&Apache::edit::select_arg('Readonly:','readonly',
  311: 					   ['no','yes'],$token);
  312: 	$result.=&Apache::edit::end_row();
  313: 	$result.=&Apache::edit::end_table();
  314:     } elsif ($target eq 'modified') {
  315: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  316: 						     $safeeval,'size',
  317: 						     'addchars','readonly');
  318: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  319:     } elsif ($target eq 'tex' 
  320: 	     && $Apache::lonhomework::type ne 'exam') {
  321: 	my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
  322: 	if ($size != 0) {$size=$size*2; $size.=' mm';} else {$size='40 mm';}
  323: 	$result='\framebox['.$size.'][s]{\tiny\strut}';
  324: 
  325:     } elsif ($target eq 'tex' 
  326: 	     && $Apache::lonhomework::type eq 'exam'
  327: 	     && &needs_exam_box($tagstack)) {
  328: 	$result.=&exam_box($target);
  329:     }
  330:     return $result;
  331: }
  332: 
  333: sub end_textline {
  334:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  335:     if    ($target eq 'web') { $Apache::lonxml::evaluate++; }
  336:     elsif ($target eq 'edit') { return ('','no'); }
  337:     return "";
  338: }
  339: 
  340: sub start_hiddenline {
  341:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  342:     my $result = "";
  343:     if ($target eq 'web') {
  344: 	$Apache::lonxml::evaluate--;
  345: 	if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
  346: 	    my $partid=$Apache::inputtags::part;
  347: 	    my $id=$Apache::inputtags::response[-1];
  348: 	    my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"},'<>&"');
  349: 	    if ($Apache::lonhomework::type ne 'exam') {
  350: 		$result= '<input type="hidden" name="HWVAL_'.$id.'" value="'.
  351: 		    $oldresponse.'" />';
  352: 	    }
  353: 	}
  354:     } elsif ($target eq 'edit') {
  355: 	$result=&Apache::edit::tag_start($target,$token);
  356: 	$result.=&Apache::edit::end_table;
  357:     }
  358: 
  359:     if ( ($target eq 'web' || $target eq 'tex')
  360: 	 && $Apache::lonhomework::type eq 'exam'
  361: 	 && &needs_exam_box($tagstack)) {
  362: 	$result.=&exam_box($target);
  363:     }
  364:     return $result;
  365: }
  366: 
  367: sub end_hiddenline {
  368:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  369:     if    ($target eq 'web') { $Apache::lonxml::evaluate++; }
  370:     elsif ($target eq 'edit') { return ('','no'); }
  371:     return "";
  372: }
  373: 
  374: # $part -> partid
  375: # $id -> responseid
  376: # $uploadefiletypes -> comma seperated list of extensions allowed or * for any
  377: # $which -> 'uploadedonly'  -> only newly uploaded files
  378: #           'portfolioonly' -> only allow files from portfolio
  379: #           'both' -> allow files from either location
  380: # $extratext -> additional text to go between the link and the input box
  381: # returns a table row <tr> 
  382: sub file_selector {
  383:     my ($part,$id,$uploadedfiletypes,$which,$extratext)=@_;
  384:     if (!$uploadedfiletypes) { return ''; }
  385: 
  386:     my $jspart=$part;
  387:     $jspart=~s/\./_/g;
  388: 
  389:     my $result;
  390:     
  391:     $result.='<tr><td>';
  392:     if ($uploadedfiletypes ne '*') {
  393: 	$result.=
  394: 	    &mt('Allowed filetypes: <b>[_1]</b>',$uploadedfiletypes).'<br />';
  395:     }
  396:     if ($which eq 'uploadonly' || $which eq 'both') { 
  397: 	$result.=&mt('Submit a file: (only one file can be uploaded)').
  398: 	    ' <br /><input type="file" size="50" name="HWFILE'.
  399: 	    $jspart.'_'.$id.'" /><br />';
  400: 	my $uploadedfile= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.uploadedfile"},'<>&"');
  401: 
  402: 	if ($uploadedfile) {
  403: 	    my $url=$Apache::lonhomework::history{"resource.$part.$id.uploadedurl"};
  404: 	    &Apache::lonxml::extlink($url);
  405: 	    &Apache::lonnet::allowuploaded('/adm/essayresponse',$url);
  406: 	    my $icon=&Apache::loncommon::icon($url);
  407: 	    my $curfile='<a href="'.$url.'"><img src="'.$icon.
  408: 		'" border="0" />'.$uploadedfile.'</a>';
  409: 	    $result.=&mt('Currently submitted: <tt>[_1]</tt>',$curfile);
  410: 	} else {
  411: 	    #$result.=&mt('(Hand in a file you have prepared on your computer)');
  412: 	}
  413:     }
  414:     if ( $which eq 'both') { 
  415: 	$result.='<br />'.'<strong>'.&mt('OR:').'</strong><br />';
  416:     }
  417:     if ($which eq 'portfolioonly' || $which eq 'both') { 
  418: 	$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"))'."'".'>'.
  419: 	    &mt('Select Portfolio Files').'</a><br />'.
  420: 	    '<input type="text" size="50" name="HWPORT'.$jspart.'_'.$id.'" value="" />'.
  421: 	    '<br />';
  422: 	if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"}=~/[^\s]/){
  423: 	    my (@filelist,@bad_file_list);
  424: 	    foreach my $file (split(',',&Apache::lonnet::unescape($Apache::lonhomework::history{"resource.$part.$id.portfiles"}))) {
  425: 		my (undef,undef,$domain,$user)=&Apache::lonxml::whichuser();
  426: 		my $url="/uploaded/$domain/$user/portfolio$file";
  427: 		my $icon=&Apache::loncommon::icon($url);
  428: 		push(@filelist,'<a href="'.$url.'"><img src="'.$icon.
  429: 		     '" border="0" />'.$file.'</a>');
  430: 		if (! &Apache::lonnet::stat_file($url)) {
  431: 		    push(@bad_file_list,'<a href="'.$url.'"><img src="'.$icon.
  432: 			 '" border="0" />'.$file.'</a>');
  433: 		}
  434: 	    }
  435: 	    $result.=&mt("Portfolio files previously selected: <strong>[_1]</strong>",join(', ',@filelist));
  436: 	    if (@bad_file_list) {
  437: 		$result.='<br />'.&mt('<font color="red">These file(s) don\'t exist:</font> <strong>[_1]</strong>',join(', ',@bad_file_list));
  438: 	    }
  439: 	}
  440:     }
  441:     $result.='</td></tr>'; 
  442:     return $result;
  443: }
  444: 
  445: sub checkstatus {
  446:     my ($value,$awardref,$msgref)=@_;
  447:     for (my $i=0;$i<=$#$awardref;$i++) {
  448: 	if ($$awardref[$i] eq $value) {
  449: 	    return ($$awardref[$i],$$msgref[$i]);
  450: 	}
  451:     }
  452:     return(undef,undef);
  453: }
  454: 
  455: sub valid_award {
  456:     my ($award) =@_;
  457:     foreach my $possibleaward ('EXTRA_ANSWER','MISSING_ANSWER', 'ERROR',
  458: 			       'NO_RESPONSE',
  459: 			       'TOO_LONG', 'UNIT_INVALID_INSTRUCTOR',
  460: 			       'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE',
  461: 			       'UNIT_FAIL', 'NO_UNIT',
  462: 			       'UNIT_NOTNEEDED', 'WANTED_NUMERIC',
  463: 			       'BAD_FORMULA', 'SIG_FAIL', 'INCORRECT', 
  464: 			       'MISORDERED_RANK', 'INVALID_FILETYPE',
  465: 			       'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
  466: 			       'APPROX_ANS', 'EXACT_ANS','COMMA_FAIL') {
  467: 	if ($award eq $possibleaward) { return 1; }
  468:     }
  469:     return 0;
  470: }
  471: 
  472: sub finalizeawards {
  473:     my ($awardref,$msgref,$nameref,$reverse)=@_;
  474:     my $result=undef;
  475:     my $award;
  476:     my $msg;
  477:     if ($#$awardref == -1) { $result = "NO_RESPONSE"; }
  478:     if ($result eq '' ) {
  479: 	my $blankcount;
  480: 	foreach $award (@$awardref) {
  481: 	    if ($award eq '') {
  482: 		$result='MISSING_ANSWER';
  483: 		$blankcount++;
  484: 	    }
  485: 	}
  486: 	if ($blankcount == ($#$awardref + 1)) { $result = 'NO_RESPONSE'; }
  487:     }
  488:     if (defined($result)) { return ($result,$msg); }
  489: 
  490:     # these awards are ordered from most important error through best correct
  491:     
  492:     my @awards = ('EXTRA_ANSWER', 'MISSING_ANSWER', 'ERROR', 'NO_RESPONSE',
  493: 		  'TOO_LONG',
  494: 		  'UNIT_INVALID_INSTRUCTOR', 'UNIT_INVALID_STUDENT',
  495: 		  'UNIT_IRRECONCIBLE', 'UNIT_FAIL', 'NO_UNIT',
  496: 		  'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA',
  497: 		  'COMMA_FAIL', 'SIG_FAIL', 'INCORRECT', 'MISORDERED_RANK',
  498: 		  'INVALID_FILETYPE', 'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
  499: 		  'APPROX_ANS', 'EXACT_ANS');
  500:     if ($reverse) { @awards=reverse(@awards); }
  501:     foreach my $possibleaward (@awards) {
  502: 	($result,$msg)=&checkstatus($possibleaward,$awardref,$msgref);
  503: 	if (defined($result)) { return ($result,$msg); }
  504:     }
  505:     return ('ERROR',undef);
  506: }
  507: 
  508: sub decideoutput {
  509:     my ($award,$awarded,$awardmsg,$solved,$previous,$target)=@_;
  510:     my $message='';
  511:     my $button=0;
  512:     my $previousmsg;
  513:     my $bgcolor='orange';
  514:     my $added_computer_text=0;
  515:     my %possiblecolors =
  516: 	( 'correct' => '#aaffaa',
  517: 	  'charged_try' => '#ffaaaa',
  518: 	  'not_charged_try' => '#ffffaa',
  519: 	  'no_message' => '#fffff',
  520: 	  );
  521: 
  522:     my $part = $Apache::inputtags::part;
  523:     my $handgrade = 
  524: 	('yes' eq lc(&Apache::lonnet::EXT("resource.$part.handgrade")));
  525:     
  526:     my $computer = ($handgrade)? ''
  527: 	                       : " ".&mt("Computer's answer now shown above.");
  528:     &Apache::lonxml::debug("handgrade has :$handgrade:");
  529: 
  530:     if ($previous) { $previousmsg=&mt('You have entered that answer before'); }
  531:     
  532:     if      ($solved =~ /^correct/) {
  533: 	$bgcolor=$possiblecolors{'correct'};
  534: 	$message=&mt('You are correct.');
  535: 	if ($awarded < 1 && $awarded > 0) {
  536: 	    $message=&mt('You are partially correct.');
  537: 	    $bgcolor=$possiblecolors{'not_charged_try'};
  538: 	} elsif ($awarded < 1) {
  539: 	    $message=&mt('Incorrect.');
  540: 	    $bgcolor=$possiblecolors{'charged_try'};
  541: 	}
  542: 	if ($env{'request.filename'} =~ 
  543: 	    m|/res/lib/templates/examupload.problem$|) {
  544: 	    $message = &mt("A score has been assigned.");
  545: 	    $added_computer_text=1;
  546: 	} else {
  547: 	    if ($target eq 'tex') {
  548: 		$message = '\textbf{'.$message.'}';
  549: 	    } else {
  550: 		$message = "<b>".$message."</b>";
  551: 		$message.= $computer;
  552: 	    }
  553: 	    $added_computer_text=1;
  554: 	    unless ($env{'course.'.
  555: 			     $env{'request.course.id'}.
  556: 			     '.disable_receipt_display'} eq 'yes') { 
  557: 		$message.=(($target eq 'web')?'<br />':' ').
  558: 		    &mt('Your receipt is').' '.&Apache::lonnet::receipt($Apache::inputtags::part).
  559: 		    (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):'');
  560: 	    }
  561: 	}
  562: 	$button=0;
  563: 	$previousmsg='';
  564:     } elsif ($solved =~ /^excused/) {
  565: 	if ($target eq 'tex') {
  566: 	    $message = ' \textbf{'.&mt('You are excused from the problem.').'} ';
  567: 	} else {
  568: 	    $message = "<b>".&mt('You are excused from the problem.')."</b>";
  569: 	}
  570: 	$bgcolor=$possiblecolors{'charged_try'};
  571: 	$button=0;
  572: 	$previousmsg='';
  573:     } elsif ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
  574: 	if ($solved =~ /^incorrect/ || $solved eq '') {
  575: 	    $message = &mt("Incorrect").".";
  576: 	    $bgcolor=$possiblecolors{'charged_try'};
  577: 	    $button=1;
  578: 	} else {
  579: 	    if ($target eq 'tex') {
  580: 		$message = '\textbf{'.&mt('You are correct.').'}';
  581: 	    } else {
  582: 		$message = "<b>".&mt('You are correct.')."</b>";
  583: 		$message.= $computer;
  584: 	    }
  585: 	    $added_computer_text=1;
  586: 	    unless ($env{'course.'.
  587: 			     $env{'request.course.id'}.
  588: 			     '.disable_receipt_display'} eq 'yes') { 
  589: 		$message.=(($target eq 'web')?'<br />':' ').
  590: 		    'Your receipt is '.&Apache::lonnet::receipt($Apache::inputtags::part).
  591: 		    (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):'');
  592: 	    }
  593: 	    $bgcolor=$possiblecolors{'correct'};
  594: 	    $button=0;
  595: 	    $previousmsg='';
  596: 	}
  597:     } elsif ($award eq 'NO_RESPONSE') {
  598: 	$message = '';
  599: 	$bgcolor=$possiblecolors{'no_feedback'};
  600: 	$button=1;
  601:     } elsif ($award eq 'EXTRA_ANSWER') {
  602: 	$message = &mt('Some extra items were submitted.');
  603: 	$bgcolor=$possiblecolors{'not_charged_try'};
  604: 	$button = 1;
  605:     } elsif ($award eq 'MISSING_ANSWER') {
  606: 	$message = &mt('Some items were not submitted.');
  607: 	$bgcolor=$possiblecolors{'not_charged_try'};
  608: 	$button = 1;
  609:     } elsif ($award eq 'ERROR') {
  610: 	$message = &mt('An error occured while grading your answer.');
  611: 	$bgcolor=$possiblecolors{'not_charged_try'};
  612: 	$button = 1;
  613:     } elsif ($award eq 'TOO_LONG') {
  614: 	$message = &mt("The submitted answer was too long.");
  615: 	$bgcolor=$possiblecolors{'not_charged_try'};
  616: 	$button=1;
  617:     } elsif ($award eq 'WANTED_NUMERIC') {
  618: 	$message = &mt("This question expects a numeric answer.");
  619: 	$bgcolor=$possiblecolors{'not_charged_try'};
  620: 	$button=1;
  621:     } elsif ($award eq 'MISORDERED_RANK') {
  622: 	$message = &mt('You have provided an invalid ranking');
  623: 	if ($target ne 'tex') {
  624: 	    $message.=', '.&mt('please refer to').' '.&Apache::loncommon::help_open_topic('Ranking_Problems','help on ranking problems');
  625: 	}
  626: 	$bgcolor=$possiblecolors{'not_charged_try'};
  627: 	$button=1;
  628:     } elsif ($award eq 'INVALID_FILETYPE') {
  629: 	$message = &mt('Submission won\'t be graded. The type of file submitted is not allowed.');
  630: 	$bgcolor=$possiblecolors{'not_charged_try'};
  631: 	$button=1;
  632:     } elsif ($award eq 'SIG_FAIL') {
  633: 	my ($used,$min,$max)=split(':',$awardmsg);
  634: 	my $word;
  635: 	if ($used < $min) { $word=&mt('more'); }
  636: 	if ($used > $max) { $word=&mt('fewer'); }
  637: 	$message = &mt("Submission not graded.  Use [_2] digits.",$used,$word);
  638: 	$bgcolor=$possiblecolors{'not_charged_try'};
  639: 	$button=1;
  640:     } elsif ($award eq 'UNIT_INVALID_INSTRUCTOR') {
  641: 	$message = &mt('Error in instructor specifed unit. This error has been reported to the instructor.', $awardmsg);
  642: 	if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');} 
  643: 	$bgcolor=$possiblecolors{'not_charged_try'};
  644: 	$button=1;
  645:     } elsif ($award eq 'UNIT_INVALID_STUDENT') {
  646: 	$message = &mt('Unable to interpret units. Computer reads units as "[_1]".',&markup_unit($awardmsg,$target));
  647: 	if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');} 
  648: 	$bgcolor=$possiblecolors{'not_charged_try'};
  649: 	$button=1;
  650:     } elsif ($award eq 'UNIT_FAIL' || $award eq 'UNIT_IRRECONCIBLE') {
  651: 	$message = &mt('Incompatible units. No conversion found between "[_1]" and the required units.',&markup_unit($awardmsg,$target));
  652: 	if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');} 
  653: 	$bgcolor=$possiblecolors{'not_charged_try'};
  654: 	$button=1;
  655:     } elsif ($award eq 'UNIT_NOTNEEDED') {
  656: 	$message = &mt('Only a number required. Computer reads units of "[_1]".',&markup_unit($awardmsg,$target));
  657: 	$bgcolor=$possiblecolors{'not_charged_try'};
  658: 	$button=1;
  659:     } elsif ($award eq 'NO_UNIT') {
  660: 	$message = &mt("Units required").'.';
  661: 	if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units')};
  662: 	$bgcolor=$possiblecolors{'not_charged_try'};
  663: 	$button=1;
  664:     } elsif ($award eq 'COMMA_FAIL') {
  665: 	$message = &mt("Proper comma separation is required").'.';
  666: 	$bgcolor=$possiblecolors{'not_charged_try'};
  667: 	$button=1;
  668:     } elsif ($award eq 'BAD_FORMULA') {
  669: 	$message = &mt("Unable to understand formula");
  670: 	$bgcolor=$possiblecolors{'not_charged_try'};
  671: 	$button=1;
  672:     } elsif ($award eq 'INCORRECT') {
  673: 	$message = &mt("Incorrect").'.';
  674: 	$bgcolor=$possiblecolors{'charged_try'};
  675: 	$button=1;
  676:     } elsif ($award eq 'SUBMITTED') {
  677: 	$message = &mt("Your submission has been recorded.");
  678: 	$bgcolor=$possiblecolors{'correct'};
  679: 	$button=1;
  680:     } elsif ($award eq 'DRAFT') {
  681: 	$message = &mt("A draft copy has been saved.");
  682: 	$bgcolor=$possiblecolors{'not_charged_try'};
  683: 	$button=1;
  684:     } elsif ($award eq 'ASSIGNED_SCORE') {
  685: 	$message = &mt("A score has been assigned.");
  686: 	$bgcolor=$possiblecolors{'correct'};
  687: 	$button=0;
  688:     } elsif ($award eq '') {
  689: 	if ($handgrade && $Apache::inputtags::status[-1] eq 'SHOW_ANSWER') {
  690: 	    $message = &mt("Nothing submitted.");
  691: 	    $bgcolor=$possiblecolors{'charged_try'};
  692: 	} else {
  693: 	    $bgcolor=$possiblecolors{'not_charged_try'};
  694: 	}
  695: 	$button=1;
  696:     } else {
  697: 	$message = &mt("Unknown message").": $award";
  698: 	$button=1;
  699:     }
  700:     if (lc($Apache::lonhomework::problemstatus) eq 'no'  && 
  701: 	$Apache::inputtags::status[-1] ne 'SHOW_ANSWER') {
  702: 	$message = &mt("Answer Submitted: Your final submission will be graded after the due date.");
  703: 	$bgcolor=$possiblecolors{'correct'};
  704: 	$button=1;
  705:     }
  706:     if ($Apache::inputtags::status[-1] eq 'SHOW_ANSWER' && 
  707: 	!$added_computer_text && $target ne 'tex') {
  708: 	$message.= $computer;
  709: 	$added_computer_text=1;
  710:     }
  711:     return ($button,$bgcolor,$message,$previousmsg);
  712: }
  713: 
  714: sub markup_unit {
  715:     my ($unit,$target)=@_;
  716:     if ($target eq 'tex') {
  717: 	return '\texttt{'.&Apache::lonxml::latex_special_symbols($unit).'}'; 
  718:     } else {
  719: 	return "<tt>".$unit."</tt>";
  720:     }
  721: }
  722: 
  723: sub removealldata {
  724:     my ($id)=@_;
  725:     foreach my $key (keys(%Apache::lonhomework::results)) {
  726: 	if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
  727: 	    &Apache::lonxml::debug("Removing $key");
  728: 	    delete($Apache::lonhomework::results{$key});
  729: 	}
  730:     }
  731: }
  732: 
  733: sub hidealldata {
  734:     my ($id)=@_;
  735:     foreach my $key (keys(%Apache::lonhomework::results)) {
  736: 	if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
  737: 	    &Apache::lonxml::debug("Hidding $key");
  738: 	    my $newkey=$key;
  739: 	    $newkey=~s/^(resource\.\Q$id\E\.[^\.]+\.)(.*)$/${1}hidden${2}/;
  740: 	    $Apache::lonhomework::results{$newkey}=
  741: 		$Apache::lonhomework::results{$key};
  742: 	    delete($Apache::lonhomework::results{$key});
  743: 	}
  744:     }
  745: }
  746: 
  747: sub setgradedata {
  748:     my ($award,$msg,$id,$previously_used) = @_;
  749:     if ($Apache::lonhomework::scantronmode && 
  750: 	&Apache::lonnet::validCODE($env{'form.CODE'})) {
  751: 	$Apache::lonhomework::results{"resource.CODE"}=$env{'form.CODE'};
  752:     } elsif ($Apache::lonhomework::scantronmode && 
  753: 	     $env{'form.CODE'} eq '' &&
  754: 	     $Apache::lonhomework::history{"resource.CODE"} ne '') {
  755: 	$Apache::lonhomework::results{"resource.CODE"}='';
  756:     }
  757: 
  758:     if (!$Apache::lonhomework::scantronmode &&
  759: 	$Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
  760: 	$Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
  761: 	$Apache::lonhomework::results{"resource.$id.afterduedate"}=$award;
  762: 	return '';
  763:     } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~
  764: 	      /^correct/ || $Apache::lonhomework::scantronmode ||
  765: 	      lc($Apache::lonhomework::problemstatus) eq 'no') {
  766:         # the student doesn't already have it correct,
  767: 	# or we are in a mode (scantron orno problem status) where a correct 
  768:         # can become incorrect
  769: 	# handle assignment of tries and solved status
  770: 	my $solvemsg;
  771: 	if ($Apache::lonhomework::scantronmode) {
  772: 	    $solvemsg='correct_by_scantron';
  773: 	} else {
  774: 	    $solvemsg='correct_by_student';
  775: 	}
  776: 	if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
  777: 	    $Apache::lonhomework::results{"resource.$id.afterduedate"}='';
  778: 	}
  779: 	if ( $award eq 'ASSIGNED_SCORE') {
  780: 	    $Apache::lonhomework::results{"resource.$id.tries"} =
  781: 		$Apache::lonhomework::history{"resource.$id.tries"} + 1;
  782: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
  783: 		$solvemsg;
  784: 	    my $numawards=scalar(@Apache::inputtags::response);
  785: 	    $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
  786: 	    foreach my $res (@Apache::inputtags::response) {
  787: 		$Apache::lonhomework::results{"resource.$id.awarded"}+=
  788: 		    $Apache::lonhomework::results{"resource.$id.$res.awarded"};
  789: 	    }
  790: 	    if ($numawards > 0) {
  791: 		$Apache::lonhomework::results{"resource.$id.awarded"}/=
  792: 		    $numawards;
  793: 	    }
  794: 	} elsif ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
  795: 	    $Apache::lonhomework::results{"resource.$id.tries"} =
  796: 		$Apache::lonhomework::history{"resource.$id.tries"} + 1;
  797: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
  798: 		$solvemsg;
  799: 	    $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
  800: 	} elsif ( $award eq 'INCORRECT' ) {
  801: 	    $Apache::lonhomework::results{"resource.$id.tries"} =
  802: 		$Apache::lonhomework::history{"resource.$id.tries"} + 1;
  803: 	    if (lc($Apache::lonhomework::problemstatus) eq 'no' ||
  804: 		$Apache::lonhomework::scantronmode) {
  805: 		$Apache::lonhomework::results{"resource.$id.awarded"} = 0;
  806: 	    }
  807: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
  808: 		'incorrect_attempted';
  809: 	} elsif ( $award eq 'SUBMITTED' ) {
  810: 	    $Apache::lonhomework::results{"resource.$id.tries"} =
  811: 		$Apache::lonhomework::history{"resource.$id.tries"} + 1;
  812: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
  813: 		'ungraded_attempted';
  814: 	} elsif ( $award eq 'DRAFT' ) {
  815: 	    $Apache::lonhomework::results{"resource.$id.solved"} = '';
  816: 	} elsif ( $award eq 'NO_RESPONSE' ) {
  817: 	    #no real response so delete any data that got stored
  818: 	    &removealldata($id);
  819: 	    return '';
  820: 	} else {
  821: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
  822: 		'incorrect_attempted';
  823: 	    if (lc($Apache::lonhomework::problemstatus) eq 'no' ||
  824: 		$Apache::lonhomework::scantronmode) {
  825: 		$Apache::lonhomework::results{"resource.$id.tries"} =
  826: 		    $Apache::lonhomework::history{"resource.$id.tries"} + 1;
  827: 		$Apache::lonhomework::results{"resource.$id.awarded"} = 0;
  828: 	    }
  829: 	}
  830: 	if (defined($msg)) {
  831: 	    $Apache::lonhomework::results{"resource.$id.awardmsg"} = $msg;
  832: 	}
  833: 	# did either of the overall awards chage? If so ignore the 
  834: 	# previous check
  835: 	if (($Apache::lonhomework::results{"resource.$id.awarded"} eq
  836: 	     $Apache::lonhomework::history{"resource.$id.awarded"}) &&
  837: 	    ($Apache::lonhomework::results{"resource.$id.solved"} eq
  838: 	     $Apache::lonhomework::history{"resource.$id.solved"})) {
  839: 	    # check if this was a previous submission if it was delete the
  840: 	    # unneeded data and update the previously_used attribute
  841: 	    if ( $previously_used eq 'PREVIOUSLY_USED') {
  842: 		if (lc($Apache::lonhomework::problemstatus) ne 'no') {
  843: 		    delete($Apache::lonhomework::results{"resource.$id.tries"});
  844: 		    $Apache::lonhomework::results{"resource.$id.previous"} = '1';
  845: 		}
  846: 	    } elsif ( $previously_used eq 'PREVIOUSLY_LAST') {
  847: 		#delete all data as they student didn't do anything, but save
  848: 		#the list of collaborators.
  849: 		&removealldata($id);
  850: 		#and since they didn't do anything we were never here
  851: 		return '';
  852: 	    } else {
  853: 		$Apache::lonhomework::results{"resource.$id.previous"} = '0';
  854: 	    }
  855: 	}
  856:     } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} =~
  857: 	      /^correct/ ) {
  858: 	#delete all data as they student already has it correct
  859: 	&removealldata($id);
  860: 	#and since they didn't do anything we were never here
  861: 	return '';
  862:     }
  863:     $Apache::lonhomework::results{"resource.$id.award"} = $award;
  864:     if ($award eq 'SUBMITTED') {
  865: 	&Apache::response::add_to_gradingqueue();
  866:     }
  867: }
  868: 
  869: sub grade {
  870:     my ($target) = @_;
  871:     my $id = $Apache::inputtags::part;
  872:     my $response='';
  873:     if ( defined $env{'form.submitted'}) {
  874: 	my (@awards,@msgs);
  875: 	foreach $response (@Apache::inputtags::response) {
  876: 	    &Apache::lonxml::debug("looking for response.$id.$response.awarddetail");
  877: 	    my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"};
  878: 	    &Apache::lonxml::debug("keeping $value from $response for $id");
  879: 	    push (@awards,$value);
  880: 	    $value=$Apache::lonhomework::results{"resource.$id.$response.awardmsg"};
  881: 	    &Apache::lonxml::debug("got message $value from $response for $id");
  882: 	    push (@msgs,$value);
  883: 	}
  884: 	my ($finalaward,$msg) = &finalizeawards(\@awards,\@msgs);
  885: 	my $previously_used;
  886: 	if ( $#Apache::inputtags::previous eq $#awards ) {
  887: 	    my $match=0;
  888: 	    my @matches;
  889: 	    foreach my $versionar (@Apache::inputtags::previous_version) {
  890: 		foreach my $version (@$versionar) {
  891: 		    $matches[$version]++;
  892: 		}
  893: 	    }
  894: 	    foreach my $elem (@matches) {if ($elem eq ($#awards+1)) {$match=1;}}
  895: 	    if ($match) {
  896: 		$previously_used = 'PREVIOUSLY_LAST';
  897: 		foreach my $value (@Apache::inputtags::previous) {
  898: 		    if ($value eq 'PREVIOUSLY_USED' ) {
  899: 			$previously_used = $value;
  900: 			last;
  901: 		    }
  902: 		}
  903: 	    }
  904: 	}
  905: 	&Apache::lonxml::debug("final award $finalaward, $previously_used, message $msg");
  906: 	&setgradedata($finalaward,$msg,$id,$previously_used);
  907:     }
  908:     return '';
  909: }
  910: 
  911: sub gradestatus {
  912:     my ($id,$target) = @_;
  913:     my $showbutton = 1;
  914:     my $bgcolor = '';
  915:     my $message = '';
  916:     my $latemessage = '';
  917:     my $trystr='';
  918:     my $button='';
  919:     my $previousmsg='';
  920: 
  921:     my $status = $Apache::inputtags::status['-1'];
  922:     &Apache::lonxml::debug("gradestatus has :$status:");
  923:     if ( $status ne 'CLOSED' 
  924: 	 && $status ne 'UNAVAILABLE' 
  925: 	 && $status ne 'INVALID_ACCESS' 
  926: 	 && $status ne 'NEEDS_CHECKIN' 
  927: 	 && $status ne 'NOT_IN_A_SLOT') {  
  928: 	my $award = $Apache::lonhomework::history{"resource.$id.award"};
  929: 	my $awarded = $Apache::lonhomework::history{"resource.$id.awarded"};
  930: 	my $solved = $Apache::lonhomework::history{"resource.$id.solved"};
  931: 	my $previous = $Apache::lonhomework::history{"resource.$id.previous"};
  932: 	my $awardmsg = $Apache::lonhomework::history{"resource.$id.awardmsg"};
  933: 	&Apache::lonxml::debug("Found Award |$award|$solved|$awardmsg");
  934: 	if ( $award ne '' || $solved ne '' || $status eq 'SHOW_ANSWER') {
  935: 	    &Apache::lonxml::debug('Getting message');
  936: 	    ($showbutton,$bgcolor,$message,$previousmsg) =
  937: 		&decideoutput($award,$awarded,$awardmsg,$solved,$previous,
  938: 			      $target);
  939: 	    if ($target eq 'tex') {
  940: 		$message='\vskip 2 mm '.$message.' ';
  941: 	    } else {
  942: 		$message="<td bgcolor=\"$bgcolor\">$message</td>";
  943: 		if ($previousmsg) {
  944: 		    $previousmsg="<td bgcolor=\"#aaaaff\">$previousmsg</td>";
  945: 		}
  946: 	    }
  947: 	}
  948: 	my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
  949: 	my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
  950: 	&Apache::lonxml::debug("got maxtries of :$maxtries:");
  951: 	#if tries are set to negative turn off the Tries/Button and messages
  952: 	if (defined($maxtries) && $maxtries < 0) { return ''; }
  953: 	if ( $tries eq '' ) { $tries = '0'; }
  954: 	if ( $maxtries eq '' ) { $maxtries = '2'; } 
  955: 	if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; } 
  956: 	my $tries_text=&mt('Tries');
  957: 	if ( $Apache::lonhomework::type eq 'survey' ||
  958: 	     $Apache::lonhomework::parsing_a_task) {
  959: 	    $tries_text=&mt('Submissions');
  960: 	}
  961: 	if ( $showbutton ) {
  962: 	    if ($target eq 'tex') {
  963: 		if ($env{'request.state'} ne "construct" && $Apache::lonhomework::type ne 'exam' && $env{'form.suppress_tries'} ne 'yes') {
  964: 		    $trystr = ' {\vskip 1 mm \small \textit{'.$tries_text.'} '.$tries.'/'.$maxtries.'} \vskip 2 mm ';
  965: 		} else {
  966: 		    $trystr = '\vskip 0 mm ';
  967: 		}
  968: 	    } else {
  969: 		$trystr = "<td><nobr>".$tries_text." $tries";
  970: 		if ($Apache::lonhomework::parsing_a_task) {
  971: 		} elsif($env{'request.state'} ne 'construct') {
  972: 		    $trystr.="/$maxtries";
  973: 		} else {
  974: 		    if (defined($Apache::inputtags::params{'maxtries'})) {
  975: 			$trystr.="/".$Apache::inputtags::params{'maxtries'};
  976: 		    }
  977: 		}
  978: 		$trystr.="</nobr></td>";
  979: 	    }
  980: 	}
  981: 	if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
  982: 	if ( $showbutton ) { 
  983: 	    if ($target ne 'tex') {
  984: 		$button = '<input type="submit" name="submit_'.$id.'" value="'.&mt('Submit Answer').'" />';
  985: 	    }
  986: 	}
  987: 	if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
  988: 	    #last submissions was after due date
  989: 	    $latemessage=&mt(' The last submission was after the Due Date ');;
  990: 	    if ($target eq 'web') {
  991: 		$latemessage='<td bgcolor="#ffaaaa">'.$latemessage.'</td>';
  992: 	    }
  993: 	}
  994:     }
  995:     my $output= $previousmsg.$latemessage.$message.$trystr;
  996:     if ($output =~ /^\s*$/) {
  997: 	return $button;
  998:     } else {
  999: 	if ($target eq 'tex') {
 1000: 	    return $button.' \vskip 0 mm '.$output.' ';
 1001: 	} else {
 1002: 	    return '<table><tr><td>'.$button.'</td>'.$output.'</tr></table>';
 1003: 	}
 1004:     }
 1005: }
 1006: 1;
 1007: __END__
 1008:  

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