Annotation of loncom/homework/inputtags.pm, revision 1.201
1.43 albertel 1: # The LearningOnline Network with CAPA
2: # input definitons
1.47 albertel 3: #
1.201 ! albertel 4: # $Id: inputtags.pm,v 1.200 2006/07/14 18:12:16 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];
1.193 albertel 286: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER'
1.200 albertel 287: || lc($Apache::lonhomework::problemstatus) eq 'no'
288: || ($Apache::inputtags::status[-1] eq 'CANNOT_ANSWER'
289: && $Apache::lonhomework::history{"resource.$partid.solved"} !~ /^correct/ )) {
1.135 albertel 290: my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
291: my $maxlength;
292: if ($size eq '') { $size=20; } else {
293: if ($size < 20) { $maxlength=$size; }
294: }
1.138 albertel 295: my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"},'<>&"');
1.135 albertel 296: if ($Apache::lonhomework::type ne 'exam') {
297: my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval);
298: $result='';
299: if ($addchars) {
300: $result.=&addchars('HWVAL_'.$id,$addchars);
301: }
1.157 albertel 302: my $readonly=&Apache::lonxml::get_param('readonly',$parstack,
303: $safeeval);
1.193 albertel 304: if (lc($readonly) eq 'yes'
305: || $Apache::inputtags::status[-1] eq 'CANNOT_ANSWER') {
1.157 albertel 306: $readonly=' readonly="readonly" ';
1.158 albertel 307: } else {
308: $readonly='';
1.157 albertel 309: }
1.193 albertel 310: my $name = 'HWVAL_'.$id;
311: if ($Apache::inputtags::status[-1] eq 'CANNOT_ANSWER') {
312: $name = "none";
313: }
314: $result.= '<input type="text" '.$readonly.' name="'.$name.'" value="'.
1.135 albertel 315: $oldresponse.'" size="'.$size.'" maxlength="'.$maxlength.'" />';
316: }
1.188 albertel 317: if ($Apache::lonhomework::type eq 'exam'
318: && &needs_exam_box($tagstack)) {
319: $result.=&exam_box($target);
320: }
1.135 albertel 321: } else {
322: #right or wrong don't show what was last typed in.
1.168 albertel 323: $result='<b>'.$Apache::inputtags::answertxt{$id}.'</b>';
1.144 albertel 324: #$result='';
1.135 albertel 325: }
326: } elsif ($target eq 'edit') {
327: $result=&Apache::edit::tag_start($target,$token);
328: $result.=&Apache::edit::text_arg('Size:','size',$token,'5').
1.157 albertel 329: &Apache::edit::text_arg('Click-On Texts (comma sep):',
330: 'addchars',$token,10);
331: $result.=&Apache::edit::select_arg('Readonly:','readonly',
332: ['no','yes'],$token);
333: $result.=&Apache::edit::end_row();
334: $result.=&Apache::edit::end_table();
1.135 albertel 335: } elsif ($target eq 'modified') {
1.157 albertel 336: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
337: $safeeval,'size',
338: 'addchars','readonly');
1.135 albertel 339: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.188 albertel 340: } elsif ($target eq 'tex'
341: && $Apache::lonhomework::type ne 'exam') {
1.135 albertel 342: my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
343: if ($size != 0) {$size=$size*2; $size.=' mm';} else {$size='40 mm';}
344: $result='\framebox['.$size.'][s]{\tiny\strut}';
1.188 albertel 345:
346: } elsif ($target eq 'tex'
347: && $Apache::lonhomework::type eq 'exam'
348: && &needs_exam_box($tagstack)) {
349: $result.=&exam_box($target);
1.135 albertel 350: }
351: return $result;
1.1 albertel 352: }
353:
354: sub end_textline {
1.135 albertel 355: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
356: if ($target eq 'web') { $Apache::lonxml::evaluate++; }
357: elsif ($target eq 'edit') { return ('','no'); }
358: return "";
1.9 albertel 359: }
360:
1.98 albertel 361: sub start_hiddenline {
362: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
363: my $result = "";
364: if ($target eq 'web') {
365: $Apache::lonxml::evaluate--;
366: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
367: my $partid=$Apache::inputtags::part;
368: my $id=$Apache::inputtags::response[-1];
1.138 albertel 369: my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"},'<>&"');
1.98 albertel 370: if ($Apache::lonhomework::type ne 'exam') {
371: $result= '<input type="hidden" name="HWVAL_'.$id.'" value="'.
372: $oldresponse.'" />';
373: }
374: }
375: } elsif ($target eq 'edit') {
376: $result=&Apache::edit::tag_start($target,$token);
377: $result.=&Apache::edit::end_table;
378: }
1.189 albertel 379:
380: if ( ($target eq 'web' || $target eq 'tex')
381: && $Apache::lonhomework::type eq 'exam'
382: && &needs_exam_box($tagstack)) {
383: $result.=&exam_box($target);
384: }
1.98 albertel 385: return $result;
386: }
387:
388: sub end_hiddenline {
1.135 albertel 389: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
390: if ($target eq 'web') { $Apache::lonxml::evaluate++; }
391: elsif ($target eq 'edit') { return ('','no'); }
392: return "";
1.98 albertel 393: }
394:
1.160 albertel 395: # $part -> partid
396: # $id -> responseid
397: # $uploadefiletypes -> comma seperated list of extensions allowed or * for any
398: # $which -> 'uploadedonly' -> only newly uploaded files
399: # 'portfolioonly' -> only allow files from portfolio
400: # 'both' -> allow files from either location
1.175 albertel 401: # $extratext -> additional text to go between the link and the input box
1.160 albertel 402: # returns a table row <tr>
403: sub file_selector {
1.175 albertel 404: my ($part,$id,$uploadedfiletypes,$which,$extratext)=@_;
1.160 albertel 405: if (!$uploadedfiletypes) { return ''; }
1.167 albertel 406:
407: my $jspart=$part;
408: $jspart=~s/\./_/g;
409:
1.160 albertel 410: my $result;
411:
1.162 albertel 412: $result.='<tr><td>';
413: if ($uploadedfiletypes ne '*') {
414: $result.=
415: &mt('Allowed filetypes: <b>[_1]</b>',$uploadedfiletypes).'<br />';
416: }
1.160 albertel 417: if ($which eq 'uploadonly' || $which eq 'both') {
418: $result.=&mt('Submit a file: (only one file can be uploaded)').
419: ' <br /><input type="file" size="50" name="HWFILE'.
1.167 albertel 420: $jspart.'_'.$id.'" /><br />';
1.160 albertel 421: my $uploadedfile= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.uploadedfile"},'<>&"');
422:
423: if ($uploadedfile) {
424: my $url=$Apache::lonhomework::history{"resource.$part.$id.uploadedurl"};
1.176 albertel 425: &Apache::lonxml::extlink($url);
1.160 albertel 426: &Apache::lonnet::allowuploaded('/adm/essayresponse',$url);
427: my $icon=&Apache::loncommon::icon($url);
428: my $curfile='<a href="'.$url.'"><img src="'.$icon.
429: '" border="0" />'.$uploadedfile.'</a>';
430: $result.=&mt('Currently submitted: <tt>[_1]</tt>',$curfile);
431: } else {
432: #$result.=&mt('(Hand in a file you have prepared on your computer)');
433: }
434: }
435: if ( $which eq 'both') {
436: $result.='<br />'.'<strong>'.&mt('OR:').'</strong><br />';
437: }
438: if ($which eq 'portfolioonly' || $which eq 'both') {
1.175 albertel 439: $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 440: &mt('Select Portfolio Files').'</a><br />'.
1.167 albertel 441: '<input type="text" size="50" name="HWPORT'.$jspart.'_'.$id.'" value="" />'.
1.160 albertel 442: '<br />';
443: if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"}=~/[^\s]/){
1.199 albertel 444: my (@file_list,@bad_file_list);
445: foreach my $file (split(/\s*,\s*/,&unescape($Apache::lonhomework::history{"resource.$part.$id.portfiles"}))) {
1.160 albertel 446: my (undef,undef,$domain,$user)=&Apache::lonxml::whichuser();
447: my $url="/uploaded/$domain/$user/portfolio$file";
448: my $icon=&Apache::loncommon::icon($url);
1.199 albertel 449: push(@file_list,'<a href="'.$url.'"><img src="'.$icon.
1.161 albertel 450: '" border="0" />'.$file.'</a>');
1.187 albertel 451: if (! &Apache::lonnet::stat_file($url)) {
1.194 banghart 452: &Apache::lonnet::logthis("bad file is $url");
1.187 albertel 453: push(@bad_file_list,'<a href="'.$url.'"><img src="'.$icon.
454: '" border="0" />'.$file.'</a>');
455: }
1.160 albertel 456: }
1.199 albertel 457: my $files = '<span class="LC_filename">'.
458: join('</span>, <span class="LC_filename">',@file_list).
459: '</span>';
460: $result.=&mt("Portfolio files previously selected: [_1]",$files);
1.187 albertel 461: if (@bad_file_list) {
1.199 albertel 462: my $bad_files = '<span class="LC_filename">'.
463: join('</span>, <span class="LC_filename">',@bad_file_list).
464: '</span>';
465: $result.='<br />'.&mt('<span class="LC_error">These file(s) don\'t exist:</span> [_1]',$bad_files);
1.187 albertel 466: }
1.160 albertel 467: }
468: }
469: $result.='</td></tr>';
470: return $result;
471: }
472:
1.136 albertel 473: sub checkstatus {
474: my ($value,$awardref,$msgref)=@_;
475: for (my $i=0;$i<=$#$awardref;$i++) {
476: if ($$awardref[$i] eq $value) {
477: return ($$awardref[$i],$$msgref[$i]);
478: }
479: }
480: return(undef,undef);
481: }
482:
1.179 albertel 483: sub valid_award {
484: my ($award) =@_;
1.182 albertel 485: foreach my $possibleaward ('EXTRA_ANSWER','MISSING_ANSWER', 'ERROR',
486: 'NO_RESPONSE',
1.179 albertel 487: 'TOO_LONG', 'UNIT_INVALID_INSTRUCTOR',
488: 'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE',
489: 'UNIT_FAIL', 'NO_UNIT',
490: 'UNIT_NOTNEEDED', 'WANTED_NUMERIC',
491: 'BAD_FORMULA', 'SIG_FAIL', 'INCORRECT',
492: 'MISORDERED_RANK', 'INVALID_FILETYPE',
493: 'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
494: 'APPROX_ANS', 'EXACT_ANS','COMMA_FAIL') {
495: if ($award eq $possibleaward) { return 1; }
496: }
497: return 0;
498: }
499:
1.9 albertel 500: sub finalizeawards {
1.181 albertel 501: my ($awardref,$msgref,$nameref,$reverse)=@_;
1.136 albertel 502: my $result=undef;
1.135 albertel 503: my $award;
1.136 albertel 504: my $msg;
505: if ($#$awardref == -1) { $result = "NO_RESPONSE"; }
1.135 albertel 506: if ($result eq '' ) {
507: my $blankcount;
1.136 albertel 508: foreach $award (@$awardref) {
1.135 albertel 509: if ($award eq '') {
510: $result='MISSING_ANSWER';
511: $blankcount++;
512: }
513: }
1.136 albertel 514: if ($blankcount == ($#$awardref + 1)) { $result = 'NO_RESPONSE'; }
1.135 albertel 515: }
1.136 albertel 516: if (defined($result)) { return ($result,$msg); }
1.181 albertel 517:
518: # these awards are ordered from most important error through best correct
519:
1.182 albertel 520: my @awards = ('EXTRA_ANSWER', 'MISSING_ANSWER', 'ERROR', 'NO_RESPONSE',
521: 'TOO_LONG',
1.181 albertel 522: 'UNIT_INVALID_INSTRUCTOR', 'UNIT_INVALID_STUDENT',
523: 'UNIT_IRRECONCIBLE', 'UNIT_FAIL', 'NO_UNIT',
524: 'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA',
525: 'COMMA_FAIL', 'SIG_FAIL', 'INCORRECT', 'MISORDERED_RANK',
526: 'INVALID_FILETYPE', 'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
527: 'APPROX_ANS', 'EXACT_ANS');
528: if ($reverse) { @awards=reverse(@awards); }
529: foreach my $possibleaward (@awards) {
1.136 albertel 530: ($result,$msg)=&checkstatus($possibleaward,$awardref,$msgref);
531: if (defined($result)) { return ($result,$msg); }
1.135 albertel 532: }
1.136 albertel 533: return ('ERROR',undef);
1.9 albertel 534: }
535:
1.10 albertel 536: sub decideoutput {
1.169 albertel 537: my ($award,$awarded,$awardmsg,$solved,$previous,$target)=@_;
1.135 albertel 538: my $message='';
539: my $button=0;
540: my $previousmsg;
541: my $bgcolor='orange';
1.148 albertel 542: my $added_computer_text=0;
1.135 albertel 543: my %possiblecolors =
1.201 ! albertel 544: ( 'correct' => '#aaffaa',
! 545: 'charged_try' => '#ffaaaa',
1.135 albertel 546: 'not_charged_try' => '#ffffaa',
1.201 ! albertel 547: 'no_grade' => '#ffffaa',
! 548: 'no_message' => '#ffffff',
1.135 albertel 549: );
1.169 albertel 550:
1.180 albertel 551: my $part = $Apache::inputtags::part;
552: my $handgrade =
553: ('yes' eq lc(&Apache::lonnet::EXT("resource.$part.handgrade")));
554:
555: my $computer = ($handgrade)? ''
556: : " ".&mt("Computer's answer now shown above.");
557: &Apache::lonxml::debug("handgrade has :$handgrade:");
558:
1.135 albertel 559: if ($previous) { $previousmsg=&mt('You have entered that answer before'); }
560:
1.194 banghart 561: if ($solved =~ /^correct/) {
562: $bgcolor=$possiblecolors{'correct'};
1.170 albertel 563: $message=&mt('You are correct.');
564: if ($awarded < 1 && $awarded > 0) {
565: $message=&mt('You are partially correct.');
566: $bgcolor=$possiblecolors{'not_charged_try'};
567: } elsif ($awarded < 1) {
568: $message=&mt('Incorrect.');
569: $bgcolor=$possiblecolors{'charged_try'};
570: }
1.172 albertel 571: if ($env{'request.filename'} =~
572: m|/res/lib/templates/examupload.problem$|) {
573: $message = &mt("A score has been assigned.");
574: $added_computer_text=1;
1.135 albertel 575: } else {
1.172 albertel 576: if ($target eq 'tex') {
577: $message = '\textbf{'.$message.'}';
578: } else {
579: $message = "<b>".$message."</b>";
1.180 albertel 580: $message.= $computer;
1.135 albertel 581: }
1.172 albertel 582: $added_computer_text=1;
1.165 albertel 583: unless ($env{'course.'.
584: $env{'request.course.id'}.
1.135 albertel 585: '.disable_receipt_display'} eq 'yes') {
586: $message.=(($target eq 'web')?'<br />':' ').
587: &mt('Your receipt is').' '.&Apache::lonnet::receipt($Apache::inputtags::part).
588: (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):'');
589: }
590: }
591: $button=0;
592: $previousmsg='';
593: } elsif ($solved =~ /^excused/) {
594: if ($target eq 'tex') {
595: $message = ' \textbf{'.&mt('You are excused from the problem.').'} ';
596: } else {
597: $message = "<b>".&mt('You are excused from the problem.')."</b>";
598: }
599: $bgcolor=$possiblecolors{'charged_try'};
600: $button=0;
601: $previousmsg='';
602: } elsif ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
603: if ($solved =~ /^incorrect/ || $solved eq '') {
1.144 albertel 604: $message = &mt("Incorrect").".";
1.135 albertel 605: $bgcolor=$possiblecolors{'charged_try'};
606: $button=1;
607: } else {
1.144 albertel 608: if ($target eq 'tex') {
609: $message = '\textbf{'.&mt('You are correct.').'}';
610: } else {
611: $message = "<b>".&mt('You are correct.')."</b>";
1.180 albertel 612: $message.= $computer;
1.144 albertel 613: }
1.148 albertel 614: $added_computer_text=1;
1.165 albertel 615: unless ($env{'course.'.
616: $env{'request.course.id'}.
1.135 albertel 617: '.disable_receipt_display'} eq 'yes') {
618: $message.=(($target eq 'web')?'<br />':' ').
619: 'Your receipt is '.&Apache::lonnet::receipt($Apache::inputtags::part).
620: (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):'');
621: }
622: $bgcolor=$possiblecolors{'correct'};
623: $button=0;
624: $previousmsg='';
625: }
626: } elsif ($award eq 'NO_RESPONSE') {
627: $message = '';
628: $bgcolor=$possiblecolors{'no_feedback'};
629: $button=1;
1.182 albertel 630: } elsif ($award eq 'EXTRA_ANSWER') {
631: $message = &mt('Some extra items were submitted.');
632: $bgcolor=$possiblecolors{'not_charged_try'};
633: $button = 1;
1.135 albertel 634: } elsif ($award eq 'MISSING_ANSWER') {
635: $message = &mt('Some items were not submitted.');
636: $bgcolor=$possiblecolors{'not_charged_try'};
637: $button = 1;
638: } elsif ($award eq 'ERROR') {
639: $message = &mt('An error occured while grading your answer.');
640: $bgcolor=$possiblecolors{'not_charged_try'};
641: $button = 1;
642: } elsif ($award eq 'TOO_LONG') {
643: $message = &mt("The submitted answer was too long.");
644: $bgcolor=$possiblecolors{'not_charged_try'};
645: $button=1;
646: } elsif ($award eq 'WANTED_NUMERIC') {
647: $message = &mt("This question expects a numeric answer.");
648: $bgcolor=$possiblecolors{'not_charged_try'};
649: $button=1;
650: } elsif ($award eq 'MISORDERED_RANK') {
651: $message = &mt('You have provided an invalid ranking');
652: if ($target ne 'tex') {
1.159 albertel 653: $message.=', '.&mt('please refer to').' '.&Apache::loncommon::help_open_topic('Ranking_Problems','help on ranking problems');
1.135 albertel 654: }
655: $bgcolor=$possiblecolors{'not_charged_try'};
656: $button=1;
657: } elsif ($award eq 'INVALID_FILETYPE') {
1.166 albertel 658: $message = &mt('Submission won\'t be graded. The type of file submitted is not allowed.');
1.135 albertel 659: $bgcolor=$possiblecolors{'not_charged_try'};
660: $button=1;
661: } elsif ($award eq 'SIG_FAIL') {
1.145 albertel 662: my ($used,$min,$max)=split(':',$awardmsg);
663: my $word;
664: if ($used < $min) { $word=&mt('more'); }
665: if ($used > $max) { $word=&mt('fewer'); }
666: $message = &mt("Submission not graded. Use [_2] digits.",$used,$word);
1.135 albertel 667: $bgcolor=$possiblecolors{'not_charged_try'};
668: $button=1;
1.137 albertel 669: } elsif ($award eq 'UNIT_INVALID_INSTRUCTOR') {
670: $message = &mt('Error in instructor specifed unit. This error has been reported to the instructor.', $awardmsg);
671: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');}
672: $bgcolor=$possiblecolors{'not_charged_try'};
673: $button=1;
674: } elsif ($award eq 'UNIT_INVALID_STUDENT') {
1.155 albertel 675: $message = &mt('Unable to interpret units. Computer reads units as "[_1]".',&markup_unit($awardmsg,$target));
1.137 albertel 676: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');}
677: $bgcolor=$possiblecolors{'not_charged_try'};
678: $button=1;
1.140 matthew 679: } elsif ($award eq 'UNIT_FAIL' || $award eq 'UNIT_IRRECONCIBLE') {
1.155 albertel 680: $message = &mt('Incompatible units. No conversion found between "[_1]" and the required units.',&markup_unit($awardmsg,$target));
1.136 albertel 681: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');}
1.135 albertel 682: $bgcolor=$possiblecolors{'not_charged_try'};
683: $button=1;
684: } elsif ($award eq 'UNIT_NOTNEEDED') {
1.155 albertel 685: $message = &mt('Only a number required. Computer reads units of "[_1]".',&markup_unit($awardmsg,$target));
1.135 albertel 686: $bgcolor=$possiblecolors{'not_charged_try'};
687: $button=1;
688: } elsif ($award eq 'NO_UNIT') {
1.144 albertel 689: $message = &mt("Units required").'.';
1.135 albertel 690: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units')};
691: $bgcolor=$possiblecolors{'not_charged_try'};
692: $button=1;
1.153 albertel 693: } elsif ($award eq 'COMMA_FAIL') {
694: $message = &mt("Proper comma separation is required").'.';
695: $bgcolor=$possiblecolors{'not_charged_try'};
696: $button=1;
1.135 albertel 697: } elsif ($award eq 'BAD_FORMULA') {
698: $message = &mt("Unable to understand formula");
699: $bgcolor=$possiblecolors{'not_charged_try'};
700: $button=1;
701: } elsif ($award eq 'INCORRECT') {
1.144 albertel 702: $message = &mt("Incorrect").'.';
1.135 albertel 703: $bgcolor=$possiblecolors{'charged_try'};
704: $button=1;
705: } elsif ($award eq 'SUBMITTED') {
706: $message = &mt("Your submission has been recorded.");
1.201 ! albertel 707: $bgcolor=$possiblecolors{'no_grade'};
1.135 albertel 708: $button=1;
709: } elsif ($award eq 'DRAFT') {
1.144 albertel 710: $message = &mt("A draft copy has been saved.");
1.135 albertel 711: $bgcolor=$possiblecolors{'not_charged_try'};
712: $button=1;
713: } elsif ($award eq 'ASSIGNED_SCORE') {
1.144 albertel 714: $message = &mt("A score has been assigned.");
1.135 albertel 715: $bgcolor=$possiblecolors{'correct'};
716: $button=0;
1.144 albertel 717: } elsif ($award eq '') {
1.186 albertel 718: if ($handgrade && $Apache::inputtags::status[-1] eq 'SHOW_ANSWER') {
719: $message = &mt("Nothing submitted.");
720: $bgcolor=$possiblecolors{'charged_try'};
721: } else {
722: $bgcolor=$possiblecolors{'not_charged_try'};
723: }
1.144 albertel 724: $button=1;
1.135 albertel 725: } else {
726: $message = &mt("Unknown message").": $award";
727: $button=1;
728: }
1.194 banghart 729: my (undef,undef,$domain,$user)=&Apache::lonxml::whichuser();
730: foreach my $resid(@Apache::inputtags::response){
731: if ($Apache::lonhomework::history{"resource.$part.$resid.handback"}) {
1.198 albertel 732: $message.='<br />';
733: my @files = split(/\s*,\s*/,
734: $Apache::lonhomework::history{"resource.$part.$resid.handback"});
735: my $file_msg;
736: foreach my $file (@files) {
737: $file_msg.= '<br /><a href="/uploaded/'."$domain/$user".'/'.$file.'">'.$file.'</a>';
738: }
739: $message .= &mt('Returned file(s): [_1]',$file_msg);
740: }
1.194 banghart 741: }
742:
1.135 albertel 743: if (lc($Apache::lonhomework::problemstatus) eq 'no' &&
744: $Apache::inputtags::status[-1] ne 'SHOW_ANSWER') {
745: $message = &mt("Answer Submitted: Your final submission will be graded after the due date.");
1.201 ! albertel 746: $bgcolor=$possiblecolors{'no_grade'};
1.135 albertel 747: $button=1;
748: }
1.148 albertel 749: if ($Apache::inputtags::status[-1] eq 'SHOW_ANSWER' &&
1.150 albertel 750: !$added_computer_text && $target ne 'tex') {
1.180 albertel 751: $message.= $computer;
1.148 albertel 752: $added_computer_text=1;
1.144 albertel 753: }
1.135 albertel 754: return ($button,$bgcolor,$message,$previousmsg);
1.12 albertel 755: }
756:
1.155 albertel 757: sub markup_unit {
758: my ($unit,$target)=@_;
759: if ($target eq 'tex') {
760: return '\texttt{'.&Apache::lonxml::latex_special_symbols($unit).'}';
761: } else {
762: return "<tt>".$unit."</tt>";
763: }
764: }
765:
1.88 albertel 766: sub removealldata {
1.87 albertel 767: my ($id)=@_;
768: foreach my $key (keys(%Apache::lonhomework::results)) {
769: if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
770: &Apache::lonxml::debug("Removing $key");
771: delete($Apache::lonhomework::results{$key});
772: }
773: }
774: }
775:
1.142 albertel 776: sub hidealldata {
777: my ($id)=@_;
778: foreach my $key (keys(%Apache::lonhomework::results)) {
779: if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
780: &Apache::lonxml::debug("Hidding $key");
781: my $newkey=$key;
782: $newkey=~s/^(resource\.\Q$id\E\.[^\.]+\.)(.*)$/${1}hidden${2}/;
783: $Apache::lonhomework::results{$newkey}=
784: $Apache::lonhomework::results{$key};
785: delete($Apache::lonhomework::results{$key});
786: }
787: }
788: }
789:
1.12 albertel 790: sub setgradedata {
1.136 albertel 791: my ($award,$msg,$id,$previously_used) = @_;
1.154 albertel 792: if ($Apache::lonhomework::scantronmode &&
1.165 albertel 793: &Apache::lonnet::validCODE($env{'form.CODE'})) {
794: $Apache::lonhomework::results{"resource.CODE"}=$env{'form.CODE'};
1.154 albertel 795: } elsif ($Apache::lonhomework::scantronmode &&
1.165 albertel 796: $env{'form.CODE'} eq '' &&
1.154 albertel 797: $Apache::lonhomework::history{"resource.CODE"} ne '') {
798: $Apache::lonhomework::results{"resource.CODE"}='';
1.141 albertel 799: }
1.154 albertel 800:
1.135 albertel 801: if (!$Apache::lonhomework::scantronmode &&
802: $Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
803: $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
804: $Apache::lonhomework::results{"resource.$id.afterduedate"}=$award;
1.87 albertel 805: return '';
1.135 albertel 806: } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~
807: /^correct/ || $Apache::lonhomework::scantronmode ||
808: lc($Apache::lonhomework::problemstatus) eq 'no') {
1.154 albertel 809: # the student doesn't already have it correct,
810: # or we are in a mode (scantron orno problem status) where a correct
811: # can become incorrect
812: # handle assignment of tries and solved status
1.135 albertel 813: my $solvemsg;
814: if ($Apache::lonhomework::scantronmode) {
815: $solvemsg='correct_by_scantron';
816: } else {
817: $solvemsg='correct_by_student';
818: }
819: if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
820: $Apache::lonhomework::results{"resource.$id.afterduedate"}='';
821: }
822: if ( $award eq 'ASSIGNED_SCORE') {
823: $Apache::lonhomework::results{"resource.$id.tries"} =
824: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
825: $Apache::lonhomework::results{"resource.$id.solved"} =
826: $solvemsg;
827: my $numawards=scalar(@Apache::inputtags::response);
828: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
829: foreach my $res (@Apache::inputtags::response) {
830: $Apache::lonhomework::results{"resource.$id.awarded"}+=
831: $Apache::lonhomework::results{"resource.$id.$res.awarded"};
832: }
833: if ($numawards > 0) {
834: $Apache::lonhomework::results{"resource.$id.awarded"}/=
835: $numawards;
836: }
837: } elsif ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
838: $Apache::lonhomework::results{"resource.$id.tries"} =
839: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
840: $Apache::lonhomework::results{"resource.$id.solved"} =
841: $solvemsg;
842: $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
843: } elsif ( $award eq 'INCORRECT' ) {
844: $Apache::lonhomework::results{"resource.$id.tries"} =
845: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1.152 albertel 846: if (lc($Apache::lonhomework::problemstatus) eq 'no' ||
847: $Apache::lonhomework::scantronmode) {
1.135 albertel 848: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
849: }
850: $Apache::lonhomework::results{"resource.$id.solved"} =
851: 'incorrect_attempted';
852: } elsif ( $award eq 'SUBMITTED' ) {
853: $Apache::lonhomework::results{"resource.$id.tries"} =
854: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
855: $Apache::lonhomework::results{"resource.$id.solved"} =
856: 'ungraded_attempted';
857: } elsif ( $award eq 'DRAFT' ) {
858: $Apache::lonhomework::results{"resource.$id.solved"} = '';
859: } elsif ( $award eq 'NO_RESPONSE' ) {
860: #no real response so delete any data that got stored
1.129 albertel 861: &removealldata($id);
862: return '';
863: } else {
1.135 albertel 864: $Apache::lonhomework::results{"resource.$id.solved"} =
865: 'incorrect_attempted';
1.152 albertel 866: if (lc($Apache::lonhomework::problemstatus) eq 'no' ||
867: $Apache::lonhomework::scantronmode) {
1.135 albertel 868: $Apache::lonhomework::results{"resource.$id.tries"} =
869: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
870: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
871: }
872: }
1.136 albertel 873: if (defined($msg)) {
874: $Apache::lonhomework::results{"resource.$id.awardmsg"} = $msg;
875: }
1.135 albertel 876: # did either of the overall awards chage? If so ignore the
877: # previous check
878: if (($Apache::lonhomework::results{"resource.$id.awarded"} eq
879: $Apache::lonhomework::history{"resource.$id.awarded"}) &&
880: ($Apache::lonhomework::results{"resource.$id.solved"} eq
881: $Apache::lonhomework::history{"resource.$id.solved"})) {
882: # check if this was a previous submission if it was delete the
883: # unneeded data and update the previously_used attribute
884: if ( $previously_used eq 'PREVIOUSLY_USED') {
885: if (lc($Apache::lonhomework::problemstatus) ne 'no') {
886: delete($Apache::lonhomework::results{"resource.$id.tries"});
887: $Apache::lonhomework::results{"resource.$id.previous"} = '1';
888: }
889: } elsif ( $previously_used eq 'PREVIOUSLY_LAST') {
890: #delete all data as they student didn't do anything, but save
891: #the list of collaborators.
892: &removealldata($id);
893: #and since they didn't do anything we were never here
894: return '';
895: } else {
896: $Apache::lonhomework::results{"resource.$id.previous"} = '0';
897: }
1.101 albertel 898: }
1.135 albertel 899: } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} =~
900: /^correct/ ) {
901: #delete all data as they student already has it correct
902: &removealldata($id);
903: #and since they didn't do anything we were never here
904: return '';
1.40 albertel 905: }
1.135 albertel 906: $Apache::lonhomework::results{"resource.$id.award"} = $award;
1.184 albertel 907: if ($award eq 'SUBMITTED') {
908: &Apache::response::add_to_gradingqueue();
909: }
1.10 albertel 910: }
911:
1.9 albertel 912: sub grade {
1.135 albertel 913: my ($target) = @_;
914: my $id = $Apache::inputtags::part;
915: my $response='';
1.165 albertel 916: if ( defined $env{'form.submitted'}) {
1.136 albertel 917: my (@awards,@msgs);
1.135 albertel 918: foreach $response (@Apache::inputtags::response) {
919: &Apache::lonxml::debug("looking for response.$id.$response.awarddetail");
920: my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"};
921: &Apache::lonxml::debug("keeping $value from $response for $id");
922: push (@awards,$value);
1.136 albertel 923: $value=$Apache::lonhomework::results{"resource.$id.$response.awardmsg"};
924: &Apache::lonxml::debug("got message $value from $response for $id");
925: push (@msgs,$value);
1.135 albertel 926: }
1.136 albertel 927: my ($finalaward,$msg) = &finalizeawards(\@awards,\@msgs);
1.135 albertel 928: my $previously_used;
929: if ( $#Apache::inputtags::previous eq $#awards ) {
930: my $match=0;
931: my @matches;
932: foreach my $versionar (@Apache::inputtags::previous_version) {
933: foreach my $version (@$versionar) {
934: $matches[$version]++;
935: }
936: }
937: foreach my $elem (@matches) {if ($elem eq ($#awards+1)) {$match=1;}}
938: if ($match) {
939: $previously_used = 'PREVIOUSLY_LAST';
940: foreach my $value (@Apache::inputtags::previous) {
941: if ($value eq 'PREVIOUSLY_USED' ) {
942: $previously_used = $value;
943: last;
944: }
1.75 albertel 945: }
946: }
1.43 albertel 947: }
1.136 albertel 948: &Apache::lonxml::debug("final award $finalaward, $previously_used, message $msg");
949: &setgradedata($finalaward,$msg,$id,$previously_used);
1.43 albertel 950: }
1.135 albertel 951: return '';
1.1 albertel 952: }
953:
1.11 albertel 954: sub gradestatus {
1.135 albertel 955: my ($id,$target) = @_;
956: my $showbutton = 1;
957: my $bgcolor = '';
958: my $message = '';
959: my $latemessage = '';
960: my $trystr='';
961: my $button='';
962: my $previousmsg='';
963:
964: my $status = $Apache::inputtags::status['-1'];
965: &Apache::lonxml::debug("gradestatus has :$status:");
1.183 albertel 966: if ( $status ne 'CLOSED'
967: && $status ne 'UNAVAILABLE'
968: && $status ne 'INVALID_ACCESS'
969: && $status ne 'NEEDS_CHECKIN'
970: && $status ne 'NOT_IN_A_SLOT') {
1.135 albertel 971: my $award = $Apache::lonhomework::history{"resource.$id.award"};
1.169 albertel 972: my $awarded = $Apache::lonhomework::history{"resource.$id.awarded"};
1.135 albertel 973: my $solved = $Apache::lonhomework::history{"resource.$id.solved"};
974: my $previous = $Apache::lonhomework::history{"resource.$id.previous"};
1.136 albertel 975: my $awardmsg = $Apache::lonhomework::history{"resource.$id.awardmsg"};
976: &Apache::lonxml::debug("Found Award |$award|$solved|$awardmsg");
1.144 albertel 977: if ( $award ne '' || $solved ne '' || $status eq 'SHOW_ANSWER') {
1.135 albertel 978: &Apache::lonxml::debug('Getting message');
979: ($showbutton,$bgcolor,$message,$previousmsg) =
1.169 albertel 980: &decideoutput($award,$awarded,$awardmsg,$solved,$previous,
981: $target);
1.135 albertel 982: if ($target eq 'tex') {
983: $message='\vskip 2 mm '.$message.' ';
984: } else {
985: $message="<td bgcolor=\"$bgcolor\">$message</td>";
986: if ($previousmsg) {
987: $previousmsg="<td bgcolor=\"#aaaaff\">$previousmsg</td>";
988: }
989: }
990: }
991: my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
992: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
993: &Apache::lonxml::debug("got maxtries of :$maxtries:");
994: #if tries are set to negative turn off the Tries/Button and messages
995: if (defined($maxtries) && $maxtries < 0) { return ''; }
996: if ( $tries eq '' ) { $tries = '0'; }
997: if ( $maxtries eq '' ) { $maxtries = '2'; }
998: if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; }
999: my $tries_text=&mt('Tries');
1.164 albertel 1000: if ( $Apache::lonhomework::type eq 'survey' ||
1001: $Apache::lonhomework::parsing_a_task) {
1002: $tries_text=&mt('Submissions');
1003: }
1.135 albertel 1004: if ( $showbutton ) {
1005: if ($target eq 'tex') {
1.165 albertel 1006: if ($env{'request.state'} ne "construct" && $Apache::lonhomework::type ne 'exam' && $env{'form.suppress_tries'} ne 'yes') {
1.135 albertel 1007: $trystr = ' {\vskip 1 mm \small \textit{'.$tries_text.'} '.$tries.'/'.$maxtries.'} \vskip 2 mm ';
1008: } else {
1009: $trystr = '\vskip 0 mm ';
1010: }
1011: } else {
1.136 albertel 1012: $trystr = "<td><nobr>".$tries_text." $tries";
1.164 albertel 1013: if ($Apache::lonhomework::parsing_a_task) {
1.165 albertel 1014: } elsif($env{'request.state'} ne 'construct') {
1.135 albertel 1015: $trystr.="/$maxtries";
1016: } else {
1017: if (defined($Apache::inputtags::params{'maxtries'})) {
1018: $trystr.="/".$Apache::inputtags::params{'maxtries'};
1019: }
1020: }
1.136 albertel 1021: $trystr.="</nobr></td>";
1.135 albertel 1022: }
1023: }
1024: if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
1025: if ( $showbutton ) {
1026: if ($target ne 'tex') {
1.156 albertel 1027: $button = '<input type="submit" name="submit_'.$id.'" value="'.&mt('Submit Answer').'" />';
1.135 albertel 1028: }
1029: }
1030: if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
1031: #last submissions was after due date
1.163 albertel 1032: $latemessage=&mt(' The last submission was after the Due Date ');;
1033: if ($target eq 'web') {
1034: $latemessage='<td bgcolor="#ffaaaa">'.$latemessage.'</td>';
1.135 albertel 1035: }
1036: }
1037: }
1038: my $output= $previousmsg.$latemessage.$message.$trystr;
1039: if ($output =~ /^\s*$/) {
1040: return $button;
1.63 sakharuk 1041: } else {
1.135 albertel 1042: if ($target eq 'tex') {
1043: return $button.' \vskip 0 mm '.$output.' ';
1044: } else {
1045: return '<table><tr><td>'.$button.'</td>'.$output.'</tr></table>';
1046: }
1.63 sakharuk 1047: }
1.11 albertel 1048: }
1.1 albertel 1049: 1;
1050: __END__
1.43 albertel 1051:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>