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

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

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