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

1.43      albertel    1: # The LearningOnline Network with CAPA
                      2: # input  definitons
1.47      albertel    3: #
1.179   ! albertel    4: # $Id: inputtags.pm,v 1.178 2005/11/03 17:44:15 albertel Exp $
1.47      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
1.1       albertel   27: 
                     28: package Apache::inputtags;
1.55      albertel   29: use HTML::Entities();
1.1       albertel   30: use strict;
1.82      www        31: use Apache::loncommon;
1.115     www        32: use Apache::lonlocal;
1.165     albertel   33: use Apache::lonnet;
1.1       albertel   34: 
1.50      harris41   35: BEGIN {
1.135     albertel   36:     &Apache::lonxml::register('Apache::inputtags',('hiddenline','textfield','textline'));
1.1       albertel   37: }
                     38: 
1.177     foxr       39: #   Initializes a set of global variables used during the parse of the problem.
                     40: #
1.178     albertel   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: 
1.1       albertel   71: sub initialize_inputtags {
1.135     albertel   72:     @Apache::inputtags::input=();
                     73:     @Apache::inputtags::inputlist=();
1.174     albertel   74:     @Apache::inputtags::response=();
1.135     albertel   75:     @Apache::inputtags::responselist=();
1.174     albertel   76:     @Apache::inputtags::hint=();
1.173     albertel   77:     @Apache::inputtags::hintlist=();
1.135     albertel   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;
1.144     albertel   87:     %Apache::inputtags::answertxt=();
1.103     albertel   88: }
                     89: 
                     90: sub check_for_duplicate_ids {
                     91:     my %check;
                     92:     foreach my $id (@Apache::inputtags::partlist,
                     93: 		    @Apache::inputtags::responselist,
1.173     albertel   94: 		    @Apache::inputtags::hintlist,
1.103     albertel   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:     }
1.1       albertel  107: }
                    108: 
1.14      albertel  109: sub start_input {
1.135     albertel  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;
1.14      albertel  116: }
                    117: 
                    118: sub end_input {
1.135     albertel  119:     pop @Apache::inputtags::input;
                    120:     return '';
1.14      albertel  121: }
                    122: 
1.124     www       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: 
1.48      albertel  133: sub start_textfield {
1.135     albertel  134:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    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;
1.138     albertel  142: 	    my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$resid.submission"},'<>&"');
1.135     albertel  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);
1.143     www       146: 	    if ( $rows eq '') { $rows = 16; }
1.135     albertel  147: 	    my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval);
                    148: 	    $result='';
                    149: 	    if ($addchars) {
                    150: 		$result.=&addchars('HWVAL_'.$resid,$addchars);
                    151: 	    }
1.143     www       152: 	    push @Apache::lonxml::htmlareafields,'HWVAL_'.$resid;
                    153: 	    $result.= '<textarea wrap="hard" name="HWVAL_'.$resid.'" id="HWVAL_'.$resid.'" '.
1.135     albertel  154: 		"rows=\"$rows\" cols=\"$cols\">".$oldresponse;
                    155: 	    if ($oldresponse ne '') {
1.143     www       156: 
1.135     albertel  157: 		#get rid of any startup text if the user has already responded
                    158: 		&Apache::lonxml::get_all_text("/textfield",$parser);
                    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
1.84      albertel  165: 	    &Apache::lonxml::get_all_text("/textfield",$parser);
1.61      albertel  166: 	}
1.135     albertel  167:     } elsif ($target eq 'grade') {
                    168: 	my $seedtext=&Apache::lonxml::get_all_text("/textfield",$parser);
1.165     albertel  169: 	if ($seedtext eq $env{'form.HWVAL_'.$resid}) {
1.135     albertel  170: 	    # if the seed text is still there it wasn't a real submission
1.165     albertel  171: 	    $env{'form.HWVAL_'.$resid}='';
1.135     albertel  172: 	}
                    173:     } elsif ($target eq 'edit') {
                    174: 	$result.=&Apache::edit::tag_start($target,$token);
                    175: 	$result.=&Apache::edit::text_arg('Rows:','rows',$token,4);
                    176: 	$result.=&Apache::edit::text_arg('Columns:','cols',$token,4);
                    177: 	$result.=&Apache::edit::text_arg
                    178: 	    ('Click-On Texts (comma sep):','addchars',$token,10);
                    179: 	my $bodytext=&Apache::lonxml::get_all_text("/textfield",$parser);
                    180: 	$result.=&Apache::edit::editfield($token->[1],$bodytext,'Text you want to appear by default:',80,2);
                    181:     } elsif ($target eq 'modified') {
                    182: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    183: 						     $safeeval,'rows','cols',
                    184: 						     'addchars');
                    185: 	if ($constructtag) {
                    186: 	    $result = &Apache::edit::rebuild_tag($token);
                    187: 	} else {
                    188: 	    $result=$token->[4];
                    189: 	}
                    190: 	$result.=&Apache::edit::modifiedfield("/textfield",$parser);
                    191:     } elsif ($target eq 'tex') {
                    192: 	my $number_of_lines = &Apache::lonxml::get_param('rows',$parstack,$safeeval);
                    193: 	my $width_of_box = &Apache::lonxml::get_param('cols',$parstack,$safeeval);
                    194: 	if ($$tagstack[-2] eq 'essayresponse' and $Apache::lonhomework::type eq 'exam') {
                    195: 	    $result = '\fbox{\fbox{\parbox{\textwidth-5mm}{';
                    196: 	    for (my $i=0;$i<int $number_of_lines*2;$i++) {$result.='\strut \\\\ ';}
                    197: 	    $result.='\strut \\\\\strut \\\\\strut \\\\\strut \\\\}}}';
                    198: 	} else {
                    199: 	    my $TeXwidth=$width_of_box/80;
                    200: 	    $result = '\vskip 1 mm \fbox{\fbox{\parbox{'.$TeXwidth.'\textwidth-5mm}{';
                    201: 	    for (my $i=0;$i<int $number_of_lines*2;$i++) {$result.='\strut \\\\ ';}
                    202: 	    $result.='}}}\vskip 2 mm ';
                    203: 	}
1.60      albertel  204:     }
1.135     albertel  205:     return $result;
1.6       albertel  206: }
                    207: 
1.48      albertel  208: sub end_textfield {
1.135     albertel  209:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    210:     my $result;
                    211:     if ($target eq 'web') {
                    212: 	$Apache::lonxml::evaluate++;
                    213: 	if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
                    214: 	    return "</textarea>";
                    215: 	}
                    216:     } elsif ($target eq 'edit') {
                    217: 	$result=&Apache::edit::end_table();
                    218:     }
                    219:     &end_input;
                    220:     return $result;
1.6       albertel  221: }
                    222: 
1.1       albertel  223: sub start_textline {
1.135     albertel  224:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    225:     my $result = "";
                    226:     if ($target eq 'web') {
                    227: 	$Apache::lonxml::evaluate--;
                    228: 	my $partid=$Apache::inputtags::part;
                    229: 	my $id=$Apache::inputtags::response[-1];
                    230: 	if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
                    231: 	    my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
                    232: 	    my $maxlength;
                    233: 	    if ($size eq '') { $size=20; } else {
                    234: 		if ($size < 20) { $maxlength=$size; }
                    235: 	    }
1.138     albertel  236: 	    my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"},'<>&"');
1.135     albertel  237: 	    if ($Apache::lonhomework::type ne 'exam') {
                    238: 		my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval);
                    239: 		$result='';
                    240: 		if ($addchars) {
                    241: 		    $result.=&addchars('HWVAL_'.$id,$addchars);
                    242: 		}
1.157     albertel  243: 		my $readonly=&Apache::lonxml::get_param('readonly',$parstack,
                    244: 							$safeeval);
                    245: 		if (lc($readonly) eq 'yes') {
                    246: 		    $readonly=' readonly="readonly" ';
1.158     albertel  247: 		} else {
                    248: 		    $readonly='';
1.157     albertel  249: 		}
                    250: 		$result.= '<input type="text" '.$readonly.' name="HWVAL_'.$id.'" value="'.
1.135     albertel  251: 		    $oldresponse.'" size="'.$size.'" maxlength="'.$maxlength.'" />';
                    252: 	    }
                    253: 	} else {
                    254: 	    #right or wrong don't show what was last typed in.
1.168     albertel  255: 	    $result='<b>'.$Apache::inputtags::answertxt{$id}.'</b>';
1.144     albertel  256: 	    #$result='';
1.135     albertel  257: 	}
                    258:     } elsif ($target eq 'edit') {
                    259: 	$result=&Apache::edit::tag_start($target,$token);
                    260: 	$result.=&Apache::edit::text_arg('Size:','size',$token,'5').
1.157     albertel  261: 	    &Apache::edit::text_arg('Click-On Texts (comma sep):',
                    262: 				    'addchars',$token,10);
                    263:         $result.=&Apache::edit::select_arg('Readonly:','readonly',
                    264: 					   ['no','yes'],$token);
                    265: 	$result.=&Apache::edit::end_row();
                    266: 	$result.=&Apache::edit::end_table();
1.135     albertel  267:     } elsif ($target eq 'modified') {
1.157     albertel  268: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    269: 						     $safeeval,'size',
                    270: 						     'addchars','readonly');
1.135     albertel  271: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    272:     } elsif ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
                    273: 	my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
                    274: 	if ($size != 0) {$size=$size*2; $size.=' mm';} else {$size='40 mm';}
                    275: 	$result='\framebox['.$size.'][s]{\tiny\strut}';
                    276:     }
                    277:     return $result;
1.1       albertel  278: }
                    279: 
                    280: sub end_textline {
1.135     albertel  281:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    282:     if    ($target eq 'web') { $Apache::lonxml::evaluate++; }
                    283:     elsif ($target eq 'edit') { return ('','no'); }
                    284:     return "";
1.9       albertel  285: }
                    286: 
1.98      albertel  287: sub start_hiddenline {
                    288:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    289:     my $result = "";
                    290:     if ($target eq 'web') {
                    291: 	$Apache::lonxml::evaluate--;
                    292: 	if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
                    293: 	    my $partid=$Apache::inputtags::part;
                    294: 	    my $id=$Apache::inputtags::response[-1];
1.138     albertel  295: 	    my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"},'<>&"');
1.98      albertel  296: 	    if ($Apache::lonhomework::type ne 'exam') {
                    297: 		$result= '<input type="hidden" name="HWVAL_'.$id.'" value="'.
                    298: 		    $oldresponse.'" />';
                    299: 	    }
                    300: 	}
                    301:     } elsif ($target eq 'edit') {
                    302: 	$result=&Apache::edit::tag_start($target,$token);
                    303: 	$result.=&Apache::edit::end_table;
                    304:     }
                    305:     return $result;
                    306: }
                    307: 
                    308: sub end_hiddenline {
1.135     albertel  309:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    310:     if    ($target eq 'web') { $Apache::lonxml::evaluate++; }
                    311:     elsif ($target eq 'edit') { return ('','no'); }
                    312:     return "";
1.98      albertel  313: }
                    314: 
1.160     albertel  315: # $part -> partid
                    316: # $id -> responseid
                    317: # $uploadefiletypes -> comma seperated list of extensions allowed or * for any
                    318: # $which -> 'uploadedonly'  -> only newly uploaded files
                    319: #           'portfolioonly' -> only allow files from portfolio
                    320: #           'both' -> allow files from either location
1.175     albertel  321: # $extratext -> additional text to go between the link and the input box
1.160     albertel  322: # returns a table row <tr> 
                    323: sub file_selector {
1.175     albertel  324:     my ($part,$id,$uploadedfiletypes,$which,$extratext)=@_;
1.160     albertel  325:     if (!$uploadedfiletypes) { return ''; }
1.167     albertel  326: 
                    327:     my $jspart=$part;
                    328:     $jspart=~s/\./_/g;
                    329: 
1.160     albertel  330:     my $result;
                    331:     
1.162     albertel  332:     $result.='<tr><td>';
                    333:     if ($uploadedfiletypes ne '*') {
                    334: 	$result.=
                    335: 	    &mt('Allowed filetypes: <b>[_1]</b>',$uploadedfiletypes).'<br />';
                    336:     }
1.160     albertel  337:     if ($which eq 'uploadonly' || $which eq 'both') { 
                    338: 	$result.=&mt('Submit a file: (only one file can be uploaded)').
                    339: 	    ' <br /><input type="file" size="50" name="HWFILE'.
1.167     albertel  340: 	    $jspart.'_'.$id.'" /><br />';
1.160     albertel  341: 	my $uploadedfile= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.uploadedfile"},'<>&"');
                    342: 
                    343: 	if ($uploadedfile) {
                    344: 	    my $url=$Apache::lonhomework::history{"resource.$part.$id.uploadedurl"};
1.176     albertel  345: 	    &Apache::lonxml::extlink($url);
1.160     albertel  346: 	    &Apache::lonnet::allowuploaded('/adm/essayresponse',$url);
                    347: 	    my $icon=&Apache::loncommon::icon($url);
                    348: 	    my $curfile='<a href="'.$url.'"><img src="'.$icon.
                    349: 		'" border="0" />'.$uploadedfile.'</a>';
                    350: 	    $result.=&mt('Currently submitted: <tt>[_1]</tt>',$curfile);
                    351: 	} else {
                    352: 	    #$result.=&mt('(Hand in a file you have prepared on your computer)');
                    353: 	}
                    354:     }
                    355:     if ( $which eq 'both') { 
                    356: 	$result.='<br />'.'<strong>'.&mt('OR:').'</strong><br />';
                    357:     }
                    358:     if ($which eq 'portfolioonly' || $which eq 'both') { 
1.175     albertel  359: 	$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"))'."'".'>'.
1.160     albertel  360: 	    &mt('Select Portfolio Files').'</a><br />'.
1.167     albertel  361: 	    '<input type="text" size="50" name="HWPORT'.$jspart.'_'.$id.'" value="" />'.
1.160     albertel  362: 	    '<br />';
                    363: 	if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"}=~/[^\s]/){
1.161     albertel  364: 	    my @filelist;
1.160     albertel  365: 	    foreach my $file (split(',',&Apache::lonnet::unescape($Apache::lonhomework::history{"resource.$part.$id.portfiles"}))) {
                    366: 		my (undef,undef,$domain,$user)=&Apache::lonxml::whichuser();
                    367: 		my $url="/uploaded/$domain/$user/portfolio$file";
                    368: 		my $icon=&Apache::loncommon::icon($url);
1.161     albertel  369: 		push(@filelist,'<a href="'.$url.'"><img src="'.$icon.
                    370: 		     '" border="0" />'.$file.'</a>');
1.160     albertel  371: 	    }
1.161     albertel  372: 	    $result.=&mt("Portfolio files previously selected: <strong>[_1]</strong>",join(', ',@filelist));
1.160     albertel  373: 	}
                    374:     }
                    375:     $result.='</td></tr>'; 
                    376:     return $result;
                    377: }
                    378: 
1.136     albertel  379: sub checkstatus {
                    380:     my ($value,$awardref,$msgref)=@_;
                    381:     for (my $i=0;$i<=$#$awardref;$i++) {
                    382: 	if ($$awardref[$i] eq $value) {
                    383: 	    return ($$awardref[$i],$$msgref[$i]);
                    384: 	}
                    385:     }
                    386:     return(undef,undef);
                    387: }
                    388: 
1.179   ! albertel  389: sub valid_award {
        !           390:     my ($award) =@_;
        !           391:     foreach my $possibleaward ('MISSING_ANSWER', 'ERROR', 'NO_RESPONSE',
        !           392: 			       'TOO_LONG', 'UNIT_INVALID_INSTRUCTOR',
        !           393: 			       'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE',
        !           394: 			       'UNIT_FAIL', 'NO_UNIT',
        !           395: 			       'UNIT_NOTNEEDED', 'WANTED_NUMERIC',
        !           396: 			       'BAD_FORMULA', 'SIG_FAIL', 'INCORRECT', 
        !           397: 			       'MISORDERED_RANK', 'INVALID_FILETYPE',
        !           398: 			       'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
        !           399: 			       'APPROX_ANS', 'EXACT_ANS','COMMA_FAIL') {
        !           400: 	if ($award eq $possibleaward) { return 1; }
        !           401:     }
        !           402:     return 0;
        !           403: }
        !           404: 
1.9       albertel  405: sub finalizeawards {
1.136     albertel  406:     my ($awardref,$msgref)=@_;
                    407:     my $result=undef;
1.135     albertel  408:     my $award;
1.136     albertel  409:     my $msg;
                    410:     if ($#$awardref == -1) { $result = "NO_RESPONSE"; }
1.135     albertel  411:     if ($result eq '' ) {
                    412: 	my $blankcount;
1.136     albertel  413: 	foreach $award (@$awardref) {
1.135     albertel  414: 	    if ($award eq '') {
                    415: 		$result='MISSING_ANSWER';
                    416: 		$blankcount++;
                    417: 	    }
                    418: 	}
1.136     albertel  419: 	if ($blankcount == ($#$awardref + 1)) { $result = 'NO_RESPONSE'; }
1.135     albertel  420:     }
1.136     albertel  421:     if (defined($result)) { return ($result,$msg); }
                    422:     foreach my $possibleaward ('MISSING_ANSWER', 'ERROR', 'NO_RESPONSE',
1.137     albertel  423: 			       'TOO_LONG', 'UNIT_INVALID_INSTRUCTOR',
                    424: 			       'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE',
                    425: 			       'UNIT_FAIL', 'NO_UNIT',
1.136     albertel  426: 			       'UNIT_NOTNEEDED', 'WANTED_NUMERIC',
                    427: 			       'BAD_FORMULA', 'SIG_FAIL', 'INCORRECT', 
                    428: 			       'MISORDERED_RANK', 'INVALID_FILETYPE',
                    429: 			       'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
1.153     albertel  430: 			       'APPROX_ANS', 'EXACT_ANS','COMMA_FAIL') {
1.136     albertel  431: 	($result,$msg)=&checkstatus($possibleaward,$awardref,$msgref);
                    432: 	if (defined($result)) { return ($result,$msg); }
1.135     albertel  433:     }
1.136     albertel  434:     return ('ERROR',undef);
1.9       albertel  435: }
                    436: 
1.10      albertel  437: sub decideoutput {
1.169     albertel  438:     my ($award,$awarded,$awardmsg,$solved,$previous,$target)=@_;
1.135     albertel  439:     my $message='';
                    440:     my $button=0;
                    441:     my $previousmsg;
                    442:     my $bgcolor='orange';
1.148     albertel  443:     my $added_computer_text=0;
1.135     albertel  444:     my %possiblecolors =
                    445: 	( 'correct' => '#aaffaa',
                    446: 	  'charged_try' => '#ffaaaa',
                    447: 	  'not_charged_try' => '#ffffaa',
                    448: 	  'no_message' => '#fffff',
                    449: 	  );
1.169     albertel  450: 
1.135     albertel  451:     if ($previous) { $previousmsg=&mt('You have entered that answer before'); }
                    452:     
                    453:     if      ($solved =~ /^correct/) {
1.169     albertel  454: 	$bgcolor=$possiblecolors{'correct'};
1.170     albertel  455: 	$message=&mt('You are correct.');
                    456: 	if ($awarded < 1 && $awarded > 0) {
                    457: 	    $message=&mt('You are partially correct.');
                    458: 	    $bgcolor=$possiblecolors{'not_charged_try'};
                    459: 	} elsif ($awarded < 1) {
                    460: 	    $message=&mt('Incorrect.');
                    461: 	    $bgcolor=$possiblecolors{'charged_try'};
                    462: 	}
1.172     albertel  463: 	if ($env{'request.filename'} =~ 
                    464: 	    m|/res/lib/templates/examupload.problem$|) {
                    465: 	    $message = &mt("A score has been assigned.");
                    466: 	    $added_computer_text=1;
1.135     albertel  467: 	} else {
1.172     albertel  468: 	    if ($target eq 'tex') {
                    469: 		$message = '\textbf{'.$message.'}';
                    470: 	    } else {
                    471: 		$message = "<b>".$message."</b>";
1.150     albertel  472: 		$message.=" ".&mt("Computer's answer now shown above.");
1.135     albertel  473: 	    }
1.172     albertel  474: 	    $added_computer_text=1;
1.165     albertel  475: 	    unless ($env{'course.'.
                    476: 			     $env{'request.course.id'}.
1.135     albertel  477: 			     '.disable_receipt_display'} eq 'yes') { 
                    478: 		$message.=(($target eq 'web')?'<br />':' ').
                    479: 		    &mt('Your receipt is').' '.&Apache::lonnet::receipt($Apache::inputtags::part).
                    480: 		    (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):'');
                    481: 	    }
                    482: 	}
                    483: 	$button=0;
                    484: 	$previousmsg='';
                    485:     } elsif ($solved =~ /^excused/) {
                    486: 	if ($target eq 'tex') {
                    487: 	    $message = ' \textbf{'.&mt('You are excused from the problem.').'} ';
                    488: 	} else {
                    489: 	    $message = "<b>".&mt('You are excused from the problem.')."</b>";
                    490: 	}
                    491: 	$bgcolor=$possiblecolors{'charged_try'};
                    492: 	$button=0;
                    493: 	$previousmsg='';
                    494:     } elsif ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
                    495: 	if ($solved =~ /^incorrect/ || $solved eq '') {
1.144     albertel  496: 	    $message = &mt("Incorrect").".";
1.135     albertel  497: 	    $bgcolor=$possiblecolors{'charged_try'};
                    498: 	    $button=1;
                    499: 	} else {
1.144     albertel  500: 	    if ($target eq 'tex') {
                    501: 		$message = '\textbf{'.&mt('You are correct.').'}';
                    502: 	    } else {
                    503: 		$message = "<b>".&mt('You are correct.')."</b>";
1.150     albertel  504: 		$message.=" ".&mt("Computer's answer now shown above.");
1.144     albertel  505: 	    }
1.148     albertel  506: 	    $added_computer_text=1;
1.165     albertel  507: 	    unless ($env{'course.'.
                    508: 			     $env{'request.course.id'}.
1.135     albertel  509: 			     '.disable_receipt_display'} eq 'yes') { 
                    510: 		$message.=(($target eq 'web')?'<br />':' ').
                    511: 		    'Your receipt is '.&Apache::lonnet::receipt($Apache::inputtags::part).
                    512: 		    (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):'');
                    513: 	    }
                    514: 	    $bgcolor=$possiblecolors{'correct'};
                    515: 	    $button=0;
                    516: 	    $previousmsg='';
                    517: 	}
                    518:     } elsif ($award eq 'NO_RESPONSE') {
                    519: 	$message = '';
                    520: 	$bgcolor=$possiblecolors{'no_feedback'};
                    521: 	$button=1;
                    522:     } elsif ($award eq 'MISSING_ANSWER') {
                    523: 	$message = &mt('Some items were not submitted.');
                    524: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    525: 	$button = 1;
                    526:     } elsif ($award eq 'ERROR') {
                    527: 	$message = &mt('An error occured while grading your answer.');
                    528: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    529: 	$button = 1;
                    530:     } elsif ($award eq 'TOO_LONG') {
                    531: 	$message = &mt("The submitted answer was too long.");
                    532: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    533: 	$button=1;
                    534:     } elsif ($award eq 'WANTED_NUMERIC') {
                    535: 	$message = &mt("This question expects a numeric answer.");
                    536: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    537: 	$button=1;
                    538:     } elsif ($award eq 'MISORDERED_RANK') {
                    539: 	$message = &mt('You have provided an invalid ranking');
                    540: 	if ($target ne 'tex') {
1.159     albertel  541: 	    $message.=', '.&mt('please refer to').' '.&Apache::loncommon::help_open_topic('Ranking_Problems','help on ranking problems');
1.135     albertel  542: 	}
                    543: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    544: 	$button=1;
                    545:     } elsif ($award eq 'INVALID_FILETYPE') {
1.166     albertel  546: 	$message = &mt('Submission won\'t be graded. The type of file submitted is not allowed.');
1.135     albertel  547: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    548: 	$button=1;
                    549:     } elsif ($award eq 'SIG_FAIL') {
1.145     albertel  550: 	my ($used,$min,$max)=split(':',$awardmsg);
                    551: 	my $word;
                    552: 	if ($used < $min) { $word=&mt('more'); }
                    553: 	if ($used > $max) { $word=&mt('fewer'); }
                    554: 	$message = &mt("Submission not graded.  Use [_2] digits.",$used,$word);
1.135     albertel  555: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    556: 	$button=1;
1.137     albertel  557:     } elsif ($award eq 'UNIT_INVALID_INSTRUCTOR') {
                    558: 	$message = &mt('Error in instructor specifed unit. This error has been reported to the instructor.', $awardmsg);
                    559: 	if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');} 
                    560: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    561: 	$button=1;
                    562:     } elsif ($award eq 'UNIT_INVALID_STUDENT') {
1.155     albertel  563: 	$message = &mt('Unable to interpret units. Computer reads units as "[_1]".',&markup_unit($awardmsg,$target));
1.137     albertel  564: 	if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');} 
                    565: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    566: 	$button=1;
1.140     matthew   567:     } elsif ($award eq 'UNIT_FAIL' || $award eq 'UNIT_IRRECONCIBLE') {
1.155     albertel  568: 	$message = &mt('Incompatible units. No conversion found between "[_1]" and the required units.',&markup_unit($awardmsg,$target));
1.136     albertel  569: 	if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');} 
1.135     albertel  570: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    571: 	$button=1;
                    572:     } elsif ($award eq 'UNIT_NOTNEEDED') {
1.155     albertel  573: 	$message = &mt('Only a number required. Computer reads units of "[_1]".',&markup_unit($awardmsg,$target));
1.135     albertel  574: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    575: 	$button=1;
                    576:     } elsif ($award eq 'NO_UNIT') {
1.144     albertel  577: 	$message = &mt("Units required").'.';
1.135     albertel  578: 	if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units')};
                    579: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    580: 	$button=1;
1.153     albertel  581:     } elsif ($award eq 'COMMA_FAIL') {
                    582: 	$message = &mt("Proper comma separation is required").'.';
                    583: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    584: 	$button=1;
1.135     albertel  585:     } elsif ($award eq 'BAD_FORMULA') {
                    586: 	$message = &mt("Unable to understand formula");
                    587: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    588: 	$button=1;
                    589:     } elsif ($award eq 'INCORRECT') {
1.144     albertel  590: 	$message = &mt("Incorrect").'.';
1.135     albertel  591: 	$bgcolor=$possiblecolors{'charged_try'};
                    592: 	$button=1;
                    593:     } elsif ($award eq 'SUBMITTED') {
                    594: 	$message = &mt("Your submission has been recorded.");
                    595: 	$bgcolor=$possiblecolors{'correct'};
                    596: 	$button=1;
                    597:     } elsif ($award eq 'DRAFT') {
1.144     albertel  598: 	$message = &mt("A draft copy has been saved.");
1.135     albertel  599: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    600: 	$button=1;
                    601:     } elsif ($award eq 'ASSIGNED_SCORE') {
1.144     albertel  602: 	$message = &mt("A score has been assigned.");
1.135     albertel  603: 	$bgcolor=$possiblecolors{'correct'};
                    604: 	$button=0;
1.144     albertel  605:     } elsif ($award eq '') {
                    606: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    607: 	$button=1;
1.135     albertel  608:     } else {
                    609: 	$message = &mt("Unknown message").": $award";
                    610: 	$button=1;
                    611:     }
                    612:     if (lc($Apache::lonhomework::problemstatus) eq 'no'  && 
                    613: 	$Apache::inputtags::status[-1] ne 'SHOW_ANSWER') {
                    614: 	$message = &mt("Answer Submitted: Your final submission will be graded after the due date.");
                    615: 	$bgcolor=$possiblecolors{'correct'};
                    616: 	$button=1;
                    617:     }
1.148     albertel  618:     if ($Apache::inputtags::status[-1] eq 'SHOW_ANSWER' && 
1.150     albertel  619: 	!$added_computer_text && $target ne 'tex') {
1.149     albertel  620: 	$message.=" ".&mt("Computer's answer now shown above.");
1.148     albertel  621: 	$added_computer_text=1;
1.144     albertel  622:     }
1.135     albertel  623:     return ($button,$bgcolor,$message,$previousmsg);
1.12      albertel  624: }
                    625: 
1.155     albertel  626: sub markup_unit {
                    627:     my ($unit,$target)=@_;
                    628:     if ($target eq 'tex') {
                    629: 	return '\texttt{'.&Apache::lonxml::latex_special_symbols($unit).'}'; 
                    630:     } else {
                    631: 	return "<tt>".$unit."</tt>";
                    632:     }
                    633: }
                    634: 
1.88      albertel  635: sub removealldata {
1.87      albertel  636:     my ($id)=@_;
                    637:     foreach my $key (keys(%Apache::lonhomework::results)) {
                    638: 	if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
                    639: 	    &Apache::lonxml::debug("Removing $key");
                    640: 	    delete($Apache::lonhomework::results{$key});
                    641: 	}
                    642:     }
                    643: }
                    644: 
1.142     albertel  645: sub hidealldata {
                    646:     my ($id)=@_;
                    647:     foreach my $key (keys(%Apache::lonhomework::results)) {
                    648: 	if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
                    649: 	    &Apache::lonxml::debug("Hidding $key");
                    650: 	    my $newkey=$key;
                    651: 	    $newkey=~s/^(resource\.\Q$id\E\.[^\.]+\.)(.*)$/${1}hidden${2}/;
                    652: 	    $Apache::lonhomework::results{$newkey}=
                    653: 		$Apache::lonhomework::results{$key};
                    654: 	    delete($Apache::lonhomework::results{$key});
                    655: 	}
                    656:     }
                    657: }
                    658: 
1.12      albertel  659: sub setgradedata {
1.136     albertel  660:     my ($award,$msg,$id,$previously_used) = @_;
1.154     albertel  661:     if ($Apache::lonhomework::scantronmode && 
1.165     albertel  662: 	&Apache::lonnet::validCODE($env{'form.CODE'})) {
                    663: 	$Apache::lonhomework::results{"resource.CODE"}=$env{'form.CODE'};
1.154     albertel  664:     } elsif ($Apache::lonhomework::scantronmode && 
1.165     albertel  665: 	     $env{'form.CODE'} eq '' &&
1.154     albertel  666: 	     $Apache::lonhomework::history{"resource.CODE"} ne '') {
                    667: 	$Apache::lonhomework::results{"resource.CODE"}='';
1.141     albertel  668:     }
1.154     albertel  669: 
1.135     albertel  670:     if (!$Apache::lonhomework::scantronmode &&
                    671: 	$Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
                    672: 	$Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
                    673: 	$Apache::lonhomework::results{"resource.$id.afterduedate"}=$award;
1.87      albertel  674: 	return '';
1.135     albertel  675:     } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~
                    676: 	      /^correct/ || $Apache::lonhomework::scantronmode ||
                    677: 	      lc($Apache::lonhomework::problemstatus) eq 'no') {
1.154     albertel  678:         # the student doesn't already have it correct,
                    679: 	# or we are in a mode (scantron orno problem status) where a correct 
                    680:         # can become incorrect
                    681: 	# handle assignment of tries and solved status
1.135     albertel  682: 	my $solvemsg;
                    683: 	if ($Apache::lonhomework::scantronmode) {
                    684: 	    $solvemsg='correct_by_scantron';
                    685: 	} else {
                    686: 	    $solvemsg='correct_by_student';
                    687: 	}
                    688: 	if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
                    689: 	    $Apache::lonhomework::results{"resource.$id.afterduedate"}='';
                    690: 	}
                    691: 	if ( $award eq 'ASSIGNED_SCORE') {
                    692: 	    $Apache::lonhomework::results{"resource.$id.tries"} =
                    693: 		$Apache::lonhomework::history{"resource.$id.tries"} + 1;
                    694: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
                    695: 		$solvemsg;
                    696: 	    my $numawards=scalar(@Apache::inputtags::response);
                    697: 	    $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
                    698: 	    foreach my $res (@Apache::inputtags::response) {
                    699: 		$Apache::lonhomework::results{"resource.$id.awarded"}+=
                    700: 		    $Apache::lonhomework::results{"resource.$id.$res.awarded"};
                    701: 	    }
                    702: 	    if ($numawards > 0) {
                    703: 		$Apache::lonhomework::results{"resource.$id.awarded"}/=
                    704: 		    $numawards;
                    705: 	    }
                    706: 	} elsif ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
                    707: 	    $Apache::lonhomework::results{"resource.$id.tries"} =
                    708: 		$Apache::lonhomework::history{"resource.$id.tries"} + 1;
                    709: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
                    710: 		$solvemsg;
                    711: 	    $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
                    712: 	} elsif ( $award eq 'INCORRECT' ) {
                    713: 	    $Apache::lonhomework::results{"resource.$id.tries"} =
                    714: 		$Apache::lonhomework::history{"resource.$id.tries"} + 1;
1.152     albertel  715: 	    if (lc($Apache::lonhomework::problemstatus) eq 'no' ||
                    716: 		$Apache::lonhomework::scantronmode) {
1.135     albertel  717: 		$Apache::lonhomework::results{"resource.$id.awarded"} = 0;
                    718: 	    }
                    719: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
                    720: 		'incorrect_attempted';
                    721: 	} elsif ( $award eq 'SUBMITTED' ) {
                    722: 	    $Apache::lonhomework::results{"resource.$id.tries"} =
                    723: 		$Apache::lonhomework::history{"resource.$id.tries"} + 1;
                    724: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
                    725: 		'ungraded_attempted';
                    726: 	} elsif ( $award eq 'DRAFT' ) {
                    727: 	    $Apache::lonhomework::results{"resource.$id.solved"} = '';
                    728: 	} elsif ( $award eq 'NO_RESPONSE' ) {
                    729: 	    #no real response so delete any data that got stored
1.129     albertel  730: 	    &removealldata($id);
                    731: 	    return '';
                    732: 	} else {
1.135     albertel  733: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
                    734: 		'incorrect_attempted';
1.152     albertel  735: 	    if (lc($Apache::lonhomework::problemstatus) eq 'no' ||
                    736: 		$Apache::lonhomework::scantronmode) {
1.135     albertel  737: 		$Apache::lonhomework::results{"resource.$id.tries"} =
                    738: 		    $Apache::lonhomework::history{"resource.$id.tries"} + 1;
                    739: 		$Apache::lonhomework::results{"resource.$id.awarded"} = 0;
                    740: 	    }
                    741: 	}
1.136     albertel  742: 	if (defined($msg)) {
                    743: 	    $Apache::lonhomework::results{"resource.$id.awardmsg"} = $msg;
                    744: 	}
1.135     albertel  745: 	# did either of the overall awards chage? If so ignore the 
                    746: 	# previous check
                    747: 	if (($Apache::lonhomework::results{"resource.$id.awarded"} eq
                    748: 	     $Apache::lonhomework::history{"resource.$id.awarded"}) &&
                    749: 	    ($Apache::lonhomework::results{"resource.$id.solved"} eq
                    750: 	     $Apache::lonhomework::history{"resource.$id.solved"})) {
                    751: 	    # check if this was a previous submission if it was delete the
                    752: 	    # unneeded data and update the previously_used attribute
                    753: 	    if ( $previously_used eq 'PREVIOUSLY_USED') {
                    754: 		if (lc($Apache::lonhomework::problemstatus) ne 'no') {
                    755: 		    delete($Apache::lonhomework::results{"resource.$id.tries"});
                    756: 		    $Apache::lonhomework::results{"resource.$id.previous"} = '1';
                    757: 		}
                    758: 	    } elsif ( $previously_used eq 'PREVIOUSLY_LAST') {
                    759: 		#delete all data as they student didn't do anything, but save
                    760: 		#the list of collaborators.
                    761: 		&removealldata($id);
                    762: 		#and since they didn't do anything we were never here
                    763: 		return '';
                    764: 	    } else {
                    765: 		$Apache::lonhomework::results{"resource.$id.previous"} = '0';
                    766: 	    }
1.101     albertel  767: 	}
1.135     albertel  768:     } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} =~
                    769: 	      /^correct/ ) {
                    770: 	#delete all data as they student already has it correct
                    771: 	&removealldata($id);
                    772: 	#and since they didn't do anything we were never here
                    773: 	return '';
1.40      albertel  774:     }
1.135     albertel  775:     $Apache::lonhomework::results{"resource.$id.award"} = $award;
1.10      albertel  776: }
                    777: 
1.9       albertel  778: sub grade {
1.135     albertel  779:     my ($target) = @_;
                    780:     my $id = $Apache::inputtags::part;
                    781:     my $response='';
1.165     albertel  782:     if ( defined $env{'form.submitted'}) {
1.136     albertel  783: 	my (@awards,@msgs);
1.135     albertel  784: 	foreach $response (@Apache::inputtags::response) {
                    785: 	    &Apache::lonxml::debug("looking for response.$id.$response.awarddetail");
                    786: 	    my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"};
                    787: 	    &Apache::lonxml::debug("keeping $value from $response for $id");
                    788: 	    push (@awards,$value);
1.136     albertel  789: 	    $value=$Apache::lonhomework::results{"resource.$id.$response.awardmsg"};
                    790: 	    &Apache::lonxml::debug("got message $value from $response for $id");
                    791: 	    push (@msgs,$value);
1.135     albertel  792: 	}
1.136     albertel  793: 	my ($finalaward,$msg) = &finalizeawards(\@awards,\@msgs);
1.135     albertel  794: 	my $previously_used;
                    795: 	if ( $#Apache::inputtags::previous eq $#awards ) {
                    796: 	    my $match=0;
                    797: 	    my @matches;
                    798: 	    foreach my $versionar (@Apache::inputtags::previous_version) {
                    799: 		foreach my $version (@$versionar) {
                    800: 		    $matches[$version]++;
                    801: 		}
                    802: 	    }
                    803: 	    foreach my $elem (@matches) {if ($elem eq ($#awards+1)) {$match=1;}}
                    804: 	    if ($match) {
                    805: 		$previously_used = 'PREVIOUSLY_LAST';
                    806: 		foreach my $value (@Apache::inputtags::previous) {
                    807: 		    if ($value eq 'PREVIOUSLY_USED' ) {
                    808: 			$previously_used = $value;
                    809: 			last;
                    810: 		    }
1.75      albertel  811: 		}
                    812: 	    }
1.43      albertel  813: 	}
1.136     albertel  814: 	&Apache::lonxml::debug("final award $finalaward, $previously_used, message $msg");
                    815: 	&setgradedata($finalaward,$msg,$id,$previously_used);
1.43      albertel  816:     }
1.135     albertel  817:     return '';
1.1       albertel  818: }
                    819: 
1.11      albertel  820: sub gradestatus {
1.135     albertel  821:     my ($id,$target) = @_;
                    822:     my $showbutton = 1;
                    823:     my $bgcolor = '';
                    824:     my $message = '';
                    825:     my $latemessage = '';
                    826:     my $trystr='';
                    827:     my $button='';
                    828:     my $previousmsg='';
                    829: 
                    830:     my $status = $Apache::inputtags::status['-1'];
                    831:     &Apache::lonxml::debug("gradestatus has :$status:");
                    832:     if ( $status ne 'CLOSED' && $status ne 'UNAVAILABLE' &&
                    833: 	 $status ne 'INVALID_ACCESS') {  
                    834: 	my $award = $Apache::lonhomework::history{"resource.$id.award"};
1.169     albertel  835: 	my $awarded = $Apache::lonhomework::history{"resource.$id.awarded"};
1.135     albertel  836: 	my $solved = $Apache::lonhomework::history{"resource.$id.solved"};
                    837: 	my $previous = $Apache::lonhomework::history{"resource.$id.previous"};
1.136     albertel  838: 	my $awardmsg = $Apache::lonhomework::history{"resource.$id.awardmsg"};
                    839: 	&Apache::lonxml::debug("Found Award |$award|$solved|$awardmsg");
1.144     albertel  840: 	if ( $award ne '' || $solved ne '' || $status eq 'SHOW_ANSWER') {
1.135     albertel  841: 	    &Apache::lonxml::debug('Getting message');
                    842: 	    ($showbutton,$bgcolor,$message,$previousmsg) =
1.169     albertel  843: 		&decideoutput($award,$awarded,$awardmsg,$solved,$previous,
                    844: 			      $target);
1.135     albertel  845: 	    if ($target eq 'tex') {
                    846: 		$message='\vskip 2 mm '.$message.' ';
                    847: 	    } else {
                    848: 		$message="<td bgcolor=\"$bgcolor\">$message</td>";
                    849: 		if ($previousmsg) {
                    850: 		    $previousmsg="<td bgcolor=\"#aaaaff\">$previousmsg</td>";
                    851: 		}
                    852: 	    }
                    853: 	}
                    854: 	my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
                    855: 	my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
                    856: 	&Apache::lonxml::debug("got maxtries of :$maxtries:");
                    857: 	#if tries are set to negative turn off the Tries/Button and messages
                    858: 	if (defined($maxtries) && $maxtries < 0) { return ''; }
                    859: 	if ( $tries eq '' ) { $tries = '0'; }
                    860: 	if ( $maxtries eq '' ) { $maxtries = '2'; } 
                    861: 	if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; } 
                    862: 	my $tries_text=&mt('Tries');
1.164     albertel  863: 	if ( $Apache::lonhomework::type eq 'survey' ||
                    864: 	     $Apache::lonhomework::parsing_a_task) {
                    865: 	    $tries_text=&mt('Submissions');
                    866: 	}
1.135     albertel  867: 	if ( $showbutton ) {
                    868: 	    if ($target eq 'tex') {
1.165     albertel  869: 		if ($env{'request.state'} ne "construct" && $Apache::lonhomework::type ne 'exam' && $env{'form.suppress_tries'} ne 'yes') {
1.135     albertel  870: 		    $trystr = ' {\vskip 1 mm \small \textit{'.$tries_text.'} '.$tries.'/'.$maxtries.'} \vskip 2 mm ';
                    871: 		} else {
                    872: 		    $trystr = '\vskip 0 mm ';
                    873: 		}
                    874: 	    } else {
1.136     albertel  875: 		$trystr = "<td><nobr>".$tries_text." $tries";
1.164     albertel  876: 		if ($Apache::lonhomework::parsing_a_task) {
1.165     albertel  877: 		} elsif($env{'request.state'} ne 'construct') {
1.135     albertel  878: 		    $trystr.="/$maxtries";
                    879: 		} else {
                    880: 		    if (defined($Apache::inputtags::params{'maxtries'})) {
                    881: 			$trystr.="/".$Apache::inputtags::params{'maxtries'};
                    882: 		    }
                    883: 		}
1.136     albertel  884: 		$trystr.="</nobr></td>";
1.135     albertel  885: 	    }
                    886: 	}
                    887: 	if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
                    888: 	if ( $showbutton ) { 
                    889: 	    if ($target ne 'tex') {
1.156     albertel  890: 		$button = '<input type="submit" name="submit_'.$id.'" value="'.&mt('Submit Answer').'" />';
1.135     albertel  891: 	    }
                    892: 	}
                    893: 	if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
                    894: 	    #last submissions was after due date
1.163     albertel  895: 	    $latemessage=&mt(' The last submission was after the Due Date ');;
                    896: 	    if ($target eq 'web') {
                    897: 		$latemessage='<td bgcolor="#ffaaaa">'.$latemessage.'</td>';
1.135     albertel  898: 	    }
                    899: 	}
                    900:     }
                    901:     my $output= $previousmsg.$latemessage.$message.$trystr;
                    902:     if ($output =~ /^\s*$/) {
                    903: 	return $button;
1.63      sakharuk  904:     } else {
1.135     albertel  905: 	if ($target eq 'tex') {
                    906: 	    return $button.' \vskip 0 mm '.$output.' ';
                    907: 	} else {
                    908: 	    return '<table><tr><td>'.$button.'</td>'.$output.'</tr></table>';
                    909: 	}
1.63      sakharuk  910:     }
1.11      albertel  911: }
1.1       albertel  912: 1;
                    913: __END__
1.43      albertel  914:  

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