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