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

1.43      albertel    1: # The LearningOnline Network with CAPA
                      2: # input  definitons
1.47      albertel    3: #
1.178   ! albertel    4: # $Id: inputtags.pm,v 1.177 2005/11/03 11:11:25 foxr 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.9       albertel  389: sub finalizeawards {
1.136     albertel  390:     my ($awardref,$msgref)=@_;
                    391:     my $result=undef;
1.135     albertel  392:     my $award;
1.136     albertel  393:     my $msg;
                    394:     if ($#$awardref == -1) { $result = "NO_RESPONSE"; }
1.135     albertel  395:     if ($result eq '' ) {
                    396: 	my $blankcount;
1.136     albertel  397: 	foreach $award (@$awardref) {
1.135     albertel  398: 	    if ($award eq '') {
                    399: 		$result='MISSING_ANSWER';
                    400: 		$blankcount++;
                    401: 	    }
                    402: 	}
1.136     albertel  403: 	if ($blankcount == ($#$awardref + 1)) { $result = 'NO_RESPONSE'; }
1.135     albertel  404:     }
1.136     albertel  405:     if (defined($result)) { return ($result,$msg); }
                    406:     foreach my $possibleaward ('MISSING_ANSWER', 'ERROR', 'NO_RESPONSE',
1.137     albertel  407: 			       'TOO_LONG', 'UNIT_INVALID_INSTRUCTOR',
                    408: 			       'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE',
                    409: 			       'UNIT_FAIL', 'NO_UNIT',
1.136     albertel  410: 			       'UNIT_NOTNEEDED', 'WANTED_NUMERIC',
                    411: 			       'BAD_FORMULA', 'SIG_FAIL', 'INCORRECT', 
                    412: 			       'MISORDERED_RANK', 'INVALID_FILETYPE',
                    413: 			       'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
1.153     albertel  414: 			       'APPROX_ANS', 'EXACT_ANS','COMMA_FAIL') {
1.136     albertel  415: 	($result,$msg)=&checkstatus($possibleaward,$awardref,$msgref);
                    416: 	if (defined($result)) { return ($result,$msg); }
1.135     albertel  417:     }
1.136     albertel  418:     return ('ERROR',undef);
1.9       albertel  419: }
                    420: 
1.10      albertel  421: sub decideoutput {
1.169     albertel  422:     my ($award,$awarded,$awardmsg,$solved,$previous,$target)=@_;
1.135     albertel  423:     my $message='';
                    424:     my $button=0;
                    425:     my $previousmsg;
                    426:     my $bgcolor='orange';
1.148     albertel  427:     my $added_computer_text=0;
1.135     albertel  428:     my %possiblecolors =
                    429: 	( 'correct' => '#aaffaa',
                    430: 	  'charged_try' => '#ffaaaa',
                    431: 	  'not_charged_try' => '#ffffaa',
                    432: 	  'no_message' => '#fffff',
                    433: 	  );
1.169     albertel  434: 
1.135     albertel  435:     if ($previous) { $previousmsg=&mt('You have entered that answer before'); }
                    436:     
                    437:     if      ($solved =~ /^correct/) {
1.169     albertel  438: 	$bgcolor=$possiblecolors{'correct'};
1.170     albertel  439: 	$message=&mt('You are correct.');
                    440: 	if ($awarded < 1 && $awarded > 0) {
                    441: 	    $message=&mt('You are partially correct.');
                    442: 	    $bgcolor=$possiblecolors{'not_charged_try'};
                    443: 	} elsif ($awarded < 1) {
                    444: 	    $message=&mt('Incorrect.');
                    445: 	    $bgcolor=$possiblecolors{'charged_try'};
                    446: 	}
1.172     albertel  447: 	if ($env{'request.filename'} =~ 
                    448: 	    m|/res/lib/templates/examupload.problem$|) {
                    449: 	    $message = &mt("A score has been assigned.");
                    450: 	    $added_computer_text=1;
1.135     albertel  451: 	} else {
1.172     albertel  452: 	    if ($target eq 'tex') {
                    453: 		$message = '\textbf{'.$message.'}';
                    454: 	    } else {
                    455: 		$message = "<b>".$message."</b>";
1.150     albertel  456: 		$message.=" ".&mt("Computer's answer now shown above.");
1.135     albertel  457: 	    }
1.172     albertel  458: 	    $added_computer_text=1;
1.165     albertel  459: 	    unless ($env{'course.'.
                    460: 			     $env{'request.course.id'}.
1.135     albertel  461: 			     '.disable_receipt_display'} eq 'yes') { 
                    462: 		$message.=(($target eq 'web')?'<br />':' ').
                    463: 		    &mt('Your receipt is').' '.&Apache::lonnet::receipt($Apache::inputtags::part).
                    464: 		    (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):'');
                    465: 	    }
                    466: 	}
                    467: 	$button=0;
                    468: 	$previousmsg='';
                    469:     } elsif ($solved =~ /^excused/) {
                    470: 	if ($target eq 'tex') {
                    471: 	    $message = ' \textbf{'.&mt('You are excused from the problem.').'} ';
                    472: 	} else {
                    473: 	    $message = "<b>".&mt('You are excused from the problem.')."</b>";
                    474: 	}
                    475: 	$bgcolor=$possiblecolors{'charged_try'};
                    476: 	$button=0;
                    477: 	$previousmsg='';
                    478:     } elsif ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
                    479: 	if ($solved =~ /^incorrect/ || $solved eq '') {
1.144     albertel  480: 	    $message = &mt("Incorrect").".";
1.135     albertel  481: 	    $bgcolor=$possiblecolors{'charged_try'};
                    482: 	    $button=1;
                    483: 	} else {
1.144     albertel  484: 	    if ($target eq 'tex') {
                    485: 		$message = '\textbf{'.&mt('You are correct.').'}';
                    486: 	    } else {
                    487: 		$message = "<b>".&mt('You are correct.')."</b>";
1.150     albertel  488: 		$message.=" ".&mt("Computer's answer now shown above.");
1.144     albertel  489: 	    }
1.148     albertel  490: 	    $added_computer_text=1;
1.165     albertel  491: 	    unless ($env{'course.'.
                    492: 			     $env{'request.course.id'}.
1.135     albertel  493: 			     '.disable_receipt_display'} eq 'yes') { 
                    494: 		$message.=(($target eq 'web')?'<br />':' ').
                    495: 		    'Your receipt is '.&Apache::lonnet::receipt($Apache::inputtags::part).
                    496: 		    (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):'');
                    497: 	    }
                    498: 	    $bgcolor=$possiblecolors{'correct'};
                    499: 	    $button=0;
                    500: 	    $previousmsg='';
                    501: 	}
                    502:     } elsif ($award eq 'NO_RESPONSE') {
                    503: 	$message = '';
                    504: 	$bgcolor=$possiblecolors{'no_feedback'};
                    505: 	$button=1;
                    506:     } elsif ($award eq 'MISSING_ANSWER') {
                    507: 	$message = &mt('Some items were not submitted.');
                    508: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    509: 	$button = 1;
                    510:     } elsif ($award eq 'ERROR') {
                    511: 	$message = &mt('An error occured while grading your answer.');
                    512: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    513: 	$button = 1;
                    514:     } elsif ($award eq 'TOO_LONG') {
                    515: 	$message = &mt("The submitted answer was too long.");
                    516: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    517: 	$button=1;
                    518:     } elsif ($award eq 'WANTED_NUMERIC') {
                    519: 	$message = &mt("This question expects a numeric answer.");
                    520: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    521: 	$button=1;
                    522:     } elsif ($award eq 'MISORDERED_RANK') {
                    523: 	$message = &mt('You have provided an invalid ranking');
                    524: 	if ($target ne 'tex') {
1.159     albertel  525: 	    $message.=', '.&mt('please refer to').' '.&Apache::loncommon::help_open_topic('Ranking_Problems','help on ranking problems');
1.135     albertel  526: 	}
                    527: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    528: 	$button=1;
                    529:     } elsif ($award eq 'INVALID_FILETYPE') {
1.166     albertel  530: 	$message = &mt('Submission won\'t be graded. The type of file submitted is not allowed.');
1.135     albertel  531: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    532: 	$button=1;
                    533:     } elsif ($award eq 'SIG_FAIL') {
1.145     albertel  534: 	my ($used,$min,$max)=split(':',$awardmsg);
                    535: 	my $word;
                    536: 	if ($used < $min) { $word=&mt('more'); }
                    537: 	if ($used > $max) { $word=&mt('fewer'); }
                    538: 	$message = &mt("Submission not graded.  Use [_2] digits.",$used,$word);
1.135     albertel  539: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    540: 	$button=1;
1.137     albertel  541:     } elsif ($award eq 'UNIT_INVALID_INSTRUCTOR') {
                    542: 	$message = &mt('Error in instructor specifed unit. This error has been reported to the instructor.', $awardmsg);
                    543: 	if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');} 
                    544: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    545: 	$button=1;
                    546:     } elsif ($award eq 'UNIT_INVALID_STUDENT') {
1.155     albertel  547: 	$message = &mt('Unable to interpret units. Computer reads units as "[_1]".',&markup_unit($awardmsg,$target));
1.137     albertel  548: 	if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');} 
                    549: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    550: 	$button=1;
1.140     matthew   551:     } elsif ($award eq 'UNIT_FAIL' || $award eq 'UNIT_IRRECONCIBLE') {
1.155     albertel  552: 	$message = &mt('Incompatible units. No conversion found between "[_1]" and the required units.',&markup_unit($awardmsg,$target));
1.136     albertel  553: 	if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');} 
1.135     albertel  554: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    555: 	$button=1;
                    556:     } elsif ($award eq 'UNIT_NOTNEEDED') {
1.155     albertel  557: 	$message = &mt('Only a number required. Computer reads units of "[_1]".',&markup_unit($awardmsg,$target));
1.135     albertel  558: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    559: 	$button=1;
                    560:     } elsif ($award eq 'NO_UNIT') {
1.144     albertel  561: 	$message = &mt("Units required").'.';
1.135     albertel  562: 	if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units')};
                    563: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    564: 	$button=1;
1.153     albertel  565:     } elsif ($award eq 'COMMA_FAIL') {
                    566: 	$message = &mt("Proper comma separation is required").'.';
                    567: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    568: 	$button=1;
1.135     albertel  569:     } elsif ($award eq 'BAD_FORMULA') {
                    570: 	$message = &mt("Unable to understand formula");
                    571: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    572: 	$button=1;
                    573:     } elsif ($award eq 'INCORRECT') {
1.144     albertel  574: 	$message = &mt("Incorrect").'.';
1.135     albertel  575: 	$bgcolor=$possiblecolors{'charged_try'};
                    576: 	$button=1;
                    577:     } elsif ($award eq 'SUBMITTED') {
                    578: 	$message = &mt("Your submission has been recorded.");
                    579: 	$bgcolor=$possiblecolors{'correct'};
                    580: 	$button=1;
                    581:     } elsif ($award eq 'DRAFT') {
1.144     albertel  582: 	$message = &mt("A draft copy has been saved.");
1.135     albertel  583: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    584: 	$button=1;
                    585:     } elsif ($award eq 'ASSIGNED_SCORE') {
1.144     albertel  586: 	$message = &mt("A score has been assigned.");
1.135     albertel  587: 	$bgcolor=$possiblecolors{'correct'};
                    588: 	$button=0;
1.144     albertel  589:     } elsif ($award eq '') {
                    590: 	$bgcolor=$possiblecolors{'not_charged_try'};
                    591: 	$button=1;
1.135     albertel  592:     } else {
                    593: 	$message = &mt("Unknown message").": $award";
                    594: 	$button=1;
                    595:     }
                    596:     if (lc($Apache::lonhomework::problemstatus) eq 'no'  && 
                    597: 	$Apache::inputtags::status[-1] ne 'SHOW_ANSWER') {
                    598: 	$message = &mt("Answer Submitted: Your final submission will be graded after the due date.");
                    599: 	$bgcolor=$possiblecolors{'correct'};
                    600: 	$button=1;
                    601:     }
1.148     albertel  602:     if ($Apache::inputtags::status[-1] eq 'SHOW_ANSWER' && 
1.150     albertel  603: 	!$added_computer_text && $target ne 'tex') {
1.149     albertel  604: 	$message.=" ".&mt("Computer's answer now shown above.");
1.148     albertel  605: 	$added_computer_text=1;
1.144     albertel  606:     }
1.135     albertel  607:     return ($button,$bgcolor,$message,$previousmsg);
1.12      albertel  608: }
                    609: 
1.155     albertel  610: sub markup_unit {
                    611:     my ($unit,$target)=@_;
                    612:     if ($target eq 'tex') {
                    613: 	return '\texttt{'.&Apache::lonxml::latex_special_symbols($unit).'}'; 
                    614:     } else {
                    615: 	return "<tt>".$unit."</tt>";
                    616:     }
                    617: }
                    618: 
1.88      albertel  619: sub removealldata {
1.87      albertel  620:     my ($id)=@_;
                    621:     foreach my $key (keys(%Apache::lonhomework::results)) {
                    622: 	if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
                    623: 	    &Apache::lonxml::debug("Removing $key");
                    624: 	    delete($Apache::lonhomework::results{$key});
                    625: 	}
                    626:     }
                    627: }
                    628: 
1.142     albertel  629: sub hidealldata {
                    630:     my ($id)=@_;
                    631:     foreach my $key (keys(%Apache::lonhomework::results)) {
                    632: 	if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
                    633: 	    &Apache::lonxml::debug("Hidding $key");
                    634: 	    my $newkey=$key;
                    635: 	    $newkey=~s/^(resource\.\Q$id\E\.[^\.]+\.)(.*)$/${1}hidden${2}/;
                    636: 	    $Apache::lonhomework::results{$newkey}=
                    637: 		$Apache::lonhomework::results{$key};
                    638: 	    delete($Apache::lonhomework::results{$key});
                    639: 	}
                    640:     }
                    641: }
                    642: 
1.12      albertel  643: sub setgradedata {
1.136     albertel  644:     my ($award,$msg,$id,$previously_used) = @_;
1.154     albertel  645:     if ($Apache::lonhomework::scantronmode && 
1.165     albertel  646: 	&Apache::lonnet::validCODE($env{'form.CODE'})) {
                    647: 	$Apache::lonhomework::results{"resource.CODE"}=$env{'form.CODE'};
1.154     albertel  648:     } elsif ($Apache::lonhomework::scantronmode && 
1.165     albertel  649: 	     $env{'form.CODE'} eq '' &&
1.154     albertel  650: 	     $Apache::lonhomework::history{"resource.CODE"} ne '') {
                    651: 	$Apache::lonhomework::results{"resource.CODE"}='';
1.141     albertel  652:     }
1.154     albertel  653: 
1.135     albertel  654:     if (!$Apache::lonhomework::scantronmode &&
                    655: 	$Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
                    656: 	$Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
                    657: 	$Apache::lonhomework::results{"resource.$id.afterduedate"}=$award;
1.87      albertel  658: 	return '';
1.135     albertel  659:     } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~
                    660: 	      /^correct/ || $Apache::lonhomework::scantronmode ||
                    661: 	      lc($Apache::lonhomework::problemstatus) eq 'no') {
1.154     albertel  662:         # the student doesn't already have it correct,
                    663: 	# or we are in a mode (scantron orno problem status) where a correct 
                    664:         # can become incorrect
                    665: 	# handle assignment of tries and solved status
1.135     albertel  666: 	my $solvemsg;
                    667: 	if ($Apache::lonhomework::scantronmode) {
                    668: 	    $solvemsg='correct_by_scantron';
                    669: 	} else {
                    670: 	    $solvemsg='correct_by_student';
                    671: 	}
                    672: 	if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
                    673: 	    $Apache::lonhomework::results{"resource.$id.afterduedate"}='';
                    674: 	}
                    675: 	if ( $award eq 'ASSIGNED_SCORE') {
                    676: 	    $Apache::lonhomework::results{"resource.$id.tries"} =
                    677: 		$Apache::lonhomework::history{"resource.$id.tries"} + 1;
                    678: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
                    679: 		$solvemsg;
                    680: 	    my $numawards=scalar(@Apache::inputtags::response);
                    681: 	    $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
                    682: 	    foreach my $res (@Apache::inputtags::response) {
                    683: 		$Apache::lonhomework::results{"resource.$id.awarded"}+=
                    684: 		    $Apache::lonhomework::results{"resource.$id.$res.awarded"};
                    685: 	    }
                    686: 	    if ($numawards > 0) {
                    687: 		$Apache::lonhomework::results{"resource.$id.awarded"}/=
                    688: 		    $numawards;
                    689: 	    }
                    690: 	} elsif ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
                    691: 	    $Apache::lonhomework::results{"resource.$id.tries"} =
                    692: 		$Apache::lonhomework::history{"resource.$id.tries"} + 1;
                    693: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
                    694: 		$solvemsg;
                    695: 	    $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
                    696: 	} elsif ( $award eq 'INCORRECT' ) {
                    697: 	    $Apache::lonhomework::results{"resource.$id.tries"} =
                    698: 		$Apache::lonhomework::history{"resource.$id.tries"} + 1;
1.152     albertel  699: 	    if (lc($Apache::lonhomework::problemstatus) eq 'no' ||
                    700: 		$Apache::lonhomework::scantronmode) {
1.135     albertel  701: 		$Apache::lonhomework::results{"resource.$id.awarded"} = 0;
                    702: 	    }
                    703: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
                    704: 		'incorrect_attempted';
                    705: 	} elsif ( $award eq 'SUBMITTED' ) {
                    706: 	    $Apache::lonhomework::results{"resource.$id.tries"} =
                    707: 		$Apache::lonhomework::history{"resource.$id.tries"} + 1;
                    708: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
                    709: 		'ungraded_attempted';
                    710: 	} elsif ( $award eq 'DRAFT' ) {
                    711: 	    $Apache::lonhomework::results{"resource.$id.solved"} = '';
                    712: 	} elsif ( $award eq 'NO_RESPONSE' ) {
                    713: 	    #no real response so delete any data that got stored
1.129     albertel  714: 	    &removealldata($id);
                    715: 	    return '';
                    716: 	} else {
1.135     albertel  717: 	    $Apache::lonhomework::results{"resource.$id.solved"} =
                    718: 		'incorrect_attempted';
1.152     albertel  719: 	    if (lc($Apache::lonhomework::problemstatus) eq 'no' ||
                    720: 		$Apache::lonhomework::scantronmode) {
1.135     albertel  721: 		$Apache::lonhomework::results{"resource.$id.tries"} =
                    722: 		    $Apache::lonhomework::history{"resource.$id.tries"} + 1;
                    723: 		$Apache::lonhomework::results{"resource.$id.awarded"} = 0;
                    724: 	    }
                    725: 	}
1.136     albertel  726: 	if (defined($msg)) {
                    727: 	    $Apache::lonhomework::results{"resource.$id.awardmsg"} = $msg;
                    728: 	}
1.135     albertel  729: 	# did either of the overall awards chage? If so ignore the 
                    730: 	# previous check
                    731: 	if (($Apache::lonhomework::results{"resource.$id.awarded"} eq
                    732: 	     $Apache::lonhomework::history{"resource.$id.awarded"}) &&
                    733: 	    ($Apache::lonhomework::results{"resource.$id.solved"} eq
                    734: 	     $Apache::lonhomework::history{"resource.$id.solved"})) {
                    735: 	    # check if this was a previous submission if it was delete the
                    736: 	    # unneeded data and update the previously_used attribute
                    737: 	    if ( $previously_used eq 'PREVIOUSLY_USED') {
                    738: 		if (lc($Apache::lonhomework::problemstatus) ne 'no') {
                    739: 		    delete($Apache::lonhomework::results{"resource.$id.tries"});
                    740: 		    $Apache::lonhomework::results{"resource.$id.previous"} = '1';
                    741: 		}
                    742: 	    } elsif ( $previously_used eq 'PREVIOUSLY_LAST') {
                    743: 		#delete all data as they student didn't do anything, but save
                    744: 		#the list of collaborators.
                    745: 		&removealldata($id);
                    746: 		#and since they didn't do anything we were never here
                    747: 		return '';
                    748: 	    } else {
                    749: 		$Apache::lonhomework::results{"resource.$id.previous"} = '0';
                    750: 	    }
1.101     albertel  751: 	}
1.135     albertel  752:     } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} =~
                    753: 	      /^correct/ ) {
                    754: 	#delete all data as they student already has it correct
                    755: 	&removealldata($id);
                    756: 	#and since they didn't do anything we were never here
                    757: 	return '';
1.40      albertel  758:     }
1.135     albertel  759:     $Apache::lonhomework::results{"resource.$id.award"} = $award;
1.10      albertel  760: }
                    761: 
1.9       albertel  762: sub grade {
1.135     albertel  763:     my ($target) = @_;
                    764:     my $id = $Apache::inputtags::part;
                    765:     my $response='';
1.165     albertel  766:     if ( defined $env{'form.submitted'}) {
1.136     albertel  767: 	my (@awards,@msgs);
1.135     albertel  768: 	foreach $response (@Apache::inputtags::response) {
                    769: 	    &Apache::lonxml::debug("looking for response.$id.$response.awarddetail");
                    770: 	    my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"};
                    771: 	    &Apache::lonxml::debug("keeping $value from $response for $id");
                    772: 	    push (@awards,$value);
1.136     albertel  773: 	    $value=$Apache::lonhomework::results{"resource.$id.$response.awardmsg"};
                    774: 	    &Apache::lonxml::debug("got message $value from $response for $id");
                    775: 	    push (@msgs,$value);
1.135     albertel  776: 	}
1.136     albertel  777: 	my ($finalaward,$msg) = &finalizeawards(\@awards,\@msgs);
1.135     albertel  778: 	my $previously_used;
                    779: 	if ( $#Apache::inputtags::previous eq $#awards ) {
                    780: 	    my $match=0;
                    781: 	    my @matches;
                    782: 	    foreach my $versionar (@Apache::inputtags::previous_version) {
                    783: 		foreach my $version (@$versionar) {
                    784: 		    $matches[$version]++;
                    785: 		}
                    786: 	    }
                    787: 	    foreach my $elem (@matches) {if ($elem eq ($#awards+1)) {$match=1;}}
                    788: 	    if ($match) {
                    789: 		$previously_used = 'PREVIOUSLY_LAST';
                    790: 		foreach my $value (@Apache::inputtags::previous) {
                    791: 		    if ($value eq 'PREVIOUSLY_USED' ) {
                    792: 			$previously_used = $value;
                    793: 			last;
                    794: 		    }
1.75      albertel  795: 		}
                    796: 	    }
1.43      albertel  797: 	}
1.136     albertel  798: 	&Apache::lonxml::debug("final award $finalaward, $previously_used, message $msg");
                    799: 	&setgradedata($finalaward,$msg,$id,$previously_used);
1.43      albertel  800:     }
1.135     albertel  801:     return '';
1.1       albertel  802: }
                    803: 
1.11      albertel  804: sub gradestatus {
1.135     albertel  805:     my ($id,$target) = @_;
                    806:     my $showbutton = 1;
                    807:     my $bgcolor = '';
                    808:     my $message = '';
                    809:     my $latemessage = '';
                    810:     my $trystr='';
                    811:     my $button='';
                    812:     my $previousmsg='';
                    813: 
                    814:     my $status = $Apache::inputtags::status['-1'];
                    815:     &Apache::lonxml::debug("gradestatus has :$status:");
                    816:     if ( $status ne 'CLOSED' && $status ne 'UNAVAILABLE' &&
                    817: 	 $status ne 'INVALID_ACCESS') {  
                    818: 	my $award = $Apache::lonhomework::history{"resource.$id.award"};
1.169     albertel  819: 	my $awarded = $Apache::lonhomework::history{"resource.$id.awarded"};
1.135     albertel  820: 	my $solved = $Apache::lonhomework::history{"resource.$id.solved"};
                    821: 	my $previous = $Apache::lonhomework::history{"resource.$id.previous"};
1.136     albertel  822: 	my $awardmsg = $Apache::lonhomework::history{"resource.$id.awardmsg"};
                    823: 	&Apache::lonxml::debug("Found Award |$award|$solved|$awardmsg");
1.144     albertel  824: 	if ( $award ne '' || $solved ne '' || $status eq 'SHOW_ANSWER') {
1.135     albertel  825: 	    &Apache::lonxml::debug('Getting message');
                    826: 	    ($showbutton,$bgcolor,$message,$previousmsg) =
1.169     albertel  827: 		&decideoutput($award,$awarded,$awardmsg,$solved,$previous,
                    828: 			      $target);
1.135     albertel  829: 	    if ($target eq 'tex') {
                    830: 		$message='\vskip 2 mm '.$message.' ';
                    831: 	    } else {
                    832: 		$message="<td bgcolor=\"$bgcolor\">$message</td>";
                    833: 		if ($previousmsg) {
                    834: 		    $previousmsg="<td bgcolor=\"#aaaaff\">$previousmsg</td>";
                    835: 		}
                    836: 	    }
                    837: 	}
                    838: 	my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
                    839: 	my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
                    840: 	&Apache::lonxml::debug("got maxtries of :$maxtries:");
                    841: 	#if tries are set to negative turn off the Tries/Button and messages
                    842: 	if (defined($maxtries) && $maxtries < 0) { return ''; }
                    843: 	if ( $tries eq '' ) { $tries = '0'; }
                    844: 	if ( $maxtries eq '' ) { $maxtries = '2'; } 
                    845: 	if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; } 
                    846: 	my $tries_text=&mt('Tries');
1.164     albertel  847: 	if ( $Apache::lonhomework::type eq 'survey' ||
                    848: 	     $Apache::lonhomework::parsing_a_task) {
                    849: 	    $tries_text=&mt('Submissions');
                    850: 	}
1.135     albertel  851: 	if ( $showbutton ) {
                    852: 	    if ($target eq 'tex') {
1.165     albertel  853: 		if ($env{'request.state'} ne "construct" && $Apache::lonhomework::type ne 'exam' && $env{'form.suppress_tries'} ne 'yes') {
1.135     albertel  854: 		    $trystr = ' {\vskip 1 mm \small \textit{'.$tries_text.'} '.$tries.'/'.$maxtries.'} \vskip 2 mm ';
                    855: 		} else {
                    856: 		    $trystr = '\vskip 0 mm ';
                    857: 		}
                    858: 	    } else {
1.136     albertel  859: 		$trystr = "<td><nobr>".$tries_text." $tries";
1.164     albertel  860: 		if ($Apache::lonhomework::parsing_a_task) {
1.165     albertel  861: 		} elsif($env{'request.state'} ne 'construct') {
1.135     albertel  862: 		    $trystr.="/$maxtries";
                    863: 		} else {
                    864: 		    if (defined($Apache::inputtags::params{'maxtries'})) {
                    865: 			$trystr.="/".$Apache::inputtags::params{'maxtries'};
                    866: 		    }
                    867: 		}
1.136     albertel  868: 		$trystr.="</nobr></td>";
1.135     albertel  869: 	    }
                    870: 	}
                    871: 	if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
                    872: 	if ( $showbutton ) { 
                    873: 	    if ($target ne 'tex') {
1.156     albertel  874: 		$button = '<input type="submit" name="submit_'.$id.'" value="'.&mt('Submit Answer').'" />';
1.135     albertel  875: 	    }
                    876: 	}
                    877: 	if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
                    878: 	    #last submissions was after due date
1.163     albertel  879: 	    $latemessage=&mt(' The last submission was after the Due Date ');;
                    880: 	    if ($target eq 'web') {
                    881: 		$latemessage='<td bgcolor="#ffaaaa">'.$latemessage.'</td>';
1.135     albertel  882: 	    }
                    883: 	}
                    884:     }
                    885:     my $output= $previousmsg.$latemessage.$message.$trystr;
                    886:     if ($output =~ /^\s*$/) {
                    887: 	return $button;
1.63      sakharuk  888:     } else {
1.135     albertel  889: 	if ($target eq 'tex') {
                    890: 	    return $button.' \vskip 0 mm '.$output.' ';
                    891: 	} else {
                    892: 	    return '<table><tr><td>'.$button.'</td>'.$output.'</tr></table>';
                    893: 	}
1.63      sakharuk  894:     }
1.11      albertel  895: }
1.1       albertel  896: 1;
                    897: __END__
1.43      albertel  898:  

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