File:  [LON-CAPA] / loncom / homework / inputtags.pm
Revision 1.194: download - view: text, annotated - select for diffs
Mon Jun 5 18:53:03 2006 UTC (18 years ago) by banghart
Branches: MAIN
CVS tags: HEAD
	Show handback files to student at problem grading.

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.