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