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