Annotation of loncom/homework/inputtags.pm, revision 1.205
1.43 albertel 1: # The LearningOnline Network with CAPA
2: # input definitons
1.47 albertel 3: #
1.205 ! albertel 4: # $Id: inputtags.pm,v 1.204 2006/07/20 21:48:07 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 {
488: my ($value,$awardref,$msgref)=@_;
489: for (my $i=0;$i<=$#$awardref;$i++) {
490: if ($$awardref[$i] eq $value) {
491: return ($$awardref[$i],$$msgref[$i]);
492: }
493: }
494: return(undef,undef);
495: }
496:
1.179 albertel 497: sub valid_award {
498: my ($award) =@_;
1.182 albertel 499: foreach my $possibleaward ('EXTRA_ANSWER','MISSING_ANSWER', 'ERROR',
500: 'NO_RESPONSE',
1.179 albertel 501: 'TOO_LONG', 'UNIT_INVALID_INSTRUCTOR',
502: 'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE',
503: 'UNIT_FAIL', 'NO_UNIT',
504: 'UNIT_NOTNEEDED', 'WANTED_NUMERIC',
505: 'BAD_FORMULA', 'SIG_FAIL', 'INCORRECT',
506: 'MISORDERED_RANK', 'INVALID_FILETYPE',
507: 'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
508: 'APPROX_ANS', 'EXACT_ANS','COMMA_FAIL') {
509: if ($award eq $possibleaward) { return 1; }
510: }
511: return 0;
512: }
513:
1.9 albertel 514: sub finalizeawards {
1.181 albertel 515: my ($awardref,$msgref,$nameref,$reverse)=@_;
1.136 albertel 516: my $result=undef;
1.135 albertel 517: my $award;
1.136 albertel 518: my $msg;
519: if ($#$awardref == -1) { $result = "NO_RESPONSE"; }
1.135 albertel 520: if ($result eq '' ) {
521: my $blankcount;
1.136 albertel 522: foreach $award (@$awardref) {
1.135 albertel 523: if ($award eq '') {
524: $result='MISSING_ANSWER';
525: $blankcount++;
526: }
527: }
1.136 albertel 528: if ($blankcount == ($#$awardref + 1)) { $result = 'NO_RESPONSE'; }
1.135 albertel 529: }
1.136 albertel 530: if (defined($result)) { return ($result,$msg); }
1.181 albertel 531:
532: # these awards are ordered from most important error through best correct
533:
1.182 albertel 534: my @awards = ('EXTRA_ANSWER', 'MISSING_ANSWER', 'ERROR', 'NO_RESPONSE',
535: 'TOO_LONG',
1.181 albertel 536: 'UNIT_INVALID_INSTRUCTOR', 'UNIT_INVALID_STUDENT',
537: 'UNIT_IRRECONCIBLE', 'UNIT_FAIL', 'NO_UNIT',
538: 'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA',
539: 'COMMA_FAIL', 'SIG_FAIL', 'INCORRECT', 'MISORDERED_RANK',
540: 'INVALID_FILETYPE', 'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
541: 'APPROX_ANS', 'EXACT_ANS');
542: if ($reverse) { @awards=reverse(@awards); }
543: foreach my $possibleaward (@awards) {
1.136 albertel 544: ($result,$msg)=&checkstatus($possibleaward,$awardref,$msgref);
545: if (defined($result)) { return ($result,$msg); }
1.135 albertel 546: }
1.136 albertel 547: return ('ERROR',undef);
1.9 albertel 548: }
549:
1.10 albertel 550: sub decideoutput {
1.169 albertel 551: my ($award,$awarded,$awardmsg,$solved,$previous,$target)=@_;
1.135 albertel 552: my $message='';
553: my $button=0;
554: my $previousmsg;
555: my $bgcolor='orange';
1.148 albertel 556: my $added_computer_text=0;
1.135 albertel 557: my %possiblecolors =
1.201 albertel 558: ( 'correct' => '#aaffaa',
559: 'charged_try' => '#ffaaaa',
1.135 albertel 560: 'not_charged_try' => '#ffffaa',
1.201 albertel 561: 'no_grade' => '#ffffaa',
562: 'no_message' => '#ffffff',
1.135 albertel 563: );
1.169 albertel 564:
1.180 albertel 565: my $part = $Apache::inputtags::part;
566: my $handgrade =
567: ('yes' eq lc(&Apache::lonnet::EXT("resource.$part.handgrade")));
568:
569: my $computer = ($handgrade)? ''
1.203 www 570: : " ".&mt("Computer's answer now shown above.");
1.180 albertel 571: &Apache::lonxml::debug("handgrade has :$handgrade:");
572:
1.135 albertel 573: if ($previous) { $previousmsg=&mt('You have entered that answer before'); }
574:
1.194 banghart 575: if ($solved =~ /^correct/) {
576: $bgcolor=$possiblecolors{'correct'};
1.170 albertel 577: $message=&mt('You are correct.');
578: if ($awarded < 1 && $awarded > 0) {
579: $message=&mt('You are partially correct.');
580: $bgcolor=$possiblecolors{'not_charged_try'};
581: } elsif ($awarded < 1) {
582: $message=&mt('Incorrect.');
583: $bgcolor=$possiblecolors{'charged_try'};
584: }
1.172 albertel 585: if ($env{'request.filename'} =~
586: m|/res/lib/templates/examupload.problem$|) {
587: $message = &mt("A score has been assigned.");
588: $added_computer_text=1;
1.135 albertel 589: } else {
1.172 albertel 590: if ($target eq 'tex') {
591: $message = '\textbf{'.$message.'}';
592: } else {
593: $message = "<b>".$message."</b>";
1.180 albertel 594: $message.= $computer;
1.135 albertel 595: }
1.172 albertel 596: $added_computer_text=1;
1.165 albertel 597: unless ($env{'course.'.
598: $env{'request.course.id'}.
1.135 albertel 599: '.disable_receipt_display'} eq 'yes') {
600: $message.=(($target eq 'web')?'<br />':' ').
601: &mt('Your receipt is').' '.&Apache::lonnet::receipt($Apache::inputtags::part).
602: (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):'');
603: }
604: }
605: $button=0;
606: $previousmsg='';
607: } elsif ($solved =~ /^excused/) {
608: if ($target eq 'tex') {
609: $message = ' \textbf{'.&mt('You are excused from the problem.').'} ';
610: } else {
611: $message = "<b>".&mt('You are excused from the problem.')."</b>";
612: }
613: $bgcolor=$possiblecolors{'charged_try'};
614: $button=0;
615: $previousmsg='';
616: } elsif ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
617: if ($solved =~ /^incorrect/ || $solved eq '') {
1.144 albertel 618: $message = &mt("Incorrect").".";
1.135 albertel 619: $bgcolor=$possiblecolors{'charged_try'};
620: $button=1;
621: } else {
1.144 albertel 622: if ($target eq 'tex') {
623: $message = '\textbf{'.&mt('You are correct.').'}';
624: } else {
625: $message = "<b>".&mt('You are correct.')."</b>";
1.180 albertel 626: $message.= $computer;
1.144 albertel 627: }
1.148 albertel 628: $added_computer_text=1;
1.165 albertel 629: unless ($env{'course.'.
630: $env{'request.course.id'}.
1.135 albertel 631: '.disable_receipt_display'} eq 'yes') {
632: $message.=(($target eq 'web')?'<br />':' ').
633: 'Your receipt is '.&Apache::lonnet::receipt($Apache::inputtags::part).
634: (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):'');
635: }
636: $bgcolor=$possiblecolors{'correct'};
637: $button=0;
638: $previousmsg='';
639: }
640: } elsif ($award eq 'NO_RESPONSE') {
641: $message = '';
642: $bgcolor=$possiblecolors{'no_feedback'};
643: $button=1;
1.182 albertel 644: } elsif ($award eq 'EXTRA_ANSWER') {
645: $message = &mt('Some extra items were submitted.');
646: $bgcolor=$possiblecolors{'not_charged_try'};
647: $button = 1;
1.135 albertel 648: } elsif ($award eq 'MISSING_ANSWER') {
649: $message = &mt('Some items were not submitted.');
650: $bgcolor=$possiblecolors{'not_charged_try'};
651: $button = 1;
652: } elsif ($award eq 'ERROR') {
653: $message = &mt('An error occured while grading your answer.');
654: $bgcolor=$possiblecolors{'not_charged_try'};
655: $button = 1;
656: } elsif ($award eq 'TOO_LONG') {
657: $message = &mt("The submitted answer was too long.");
658: $bgcolor=$possiblecolors{'not_charged_try'};
659: $button=1;
660: } elsif ($award eq 'WANTED_NUMERIC') {
661: $message = &mt("This question expects a numeric answer.");
662: $bgcolor=$possiblecolors{'not_charged_try'};
663: $button=1;
664: } elsif ($award eq 'MISORDERED_RANK') {
665: $message = &mt('You have provided an invalid ranking');
666: if ($target ne 'tex') {
1.159 albertel 667: $message.=', '.&mt('please refer to').' '.&Apache::loncommon::help_open_topic('Ranking_Problems','help on ranking problems');
1.135 albertel 668: }
669: $bgcolor=$possiblecolors{'not_charged_try'};
670: $button=1;
671: } elsif ($award eq 'INVALID_FILETYPE') {
1.166 albertel 672: $message = &mt('Submission won\'t be graded. The type of file submitted is not allowed.');
1.135 albertel 673: $bgcolor=$possiblecolors{'not_charged_try'};
674: $button=1;
675: } elsif ($award eq 'SIG_FAIL') {
1.145 albertel 676: my ($used,$min,$max)=split(':',$awardmsg);
677: my $word;
678: if ($used < $min) { $word=&mt('more'); }
679: if ($used > $max) { $word=&mt('fewer'); }
680: $message = &mt("Submission not graded. Use [_2] digits.",$used,$word);
1.135 albertel 681: $bgcolor=$possiblecolors{'not_charged_try'};
682: $button=1;
1.137 albertel 683: } elsif ($award eq 'UNIT_INVALID_INSTRUCTOR') {
684: $message = &mt('Error in instructor specifed unit. This error has been reported to the instructor.', $awardmsg);
685: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');}
686: $bgcolor=$possiblecolors{'not_charged_try'};
687: $button=1;
688: } elsif ($award eq 'UNIT_INVALID_STUDENT') {
1.155 albertel 689: $message = &mt('Unable to interpret units. Computer reads units as "[_1]".',&markup_unit($awardmsg,$target));
1.137 albertel 690: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');}
691: $bgcolor=$possiblecolors{'not_charged_try'};
692: $button=1;
1.140 matthew 693: } elsif ($award eq 'UNIT_FAIL' || $award eq 'UNIT_IRRECONCIBLE') {
1.155 albertel 694: $message = &mt('Incompatible units. No conversion found between "[_1]" and the required units.',&markup_unit($awardmsg,$target));
1.136 albertel 695: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');}
1.135 albertel 696: $bgcolor=$possiblecolors{'not_charged_try'};
697: $button=1;
698: } elsif ($award eq 'UNIT_NOTNEEDED') {
1.155 albertel 699: $message = &mt('Only a number required. Computer reads units of "[_1]".',&markup_unit($awardmsg,$target));
1.135 albertel 700: $bgcolor=$possiblecolors{'not_charged_try'};
701: $button=1;
702: } elsif ($award eq 'NO_UNIT') {
1.144 albertel 703: $message = &mt("Units required").'.';
1.135 albertel 704: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units')};
705: $bgcolor=$possiblecolors{'not_charged_try'};
706: $button=1;
1.153 albertel 707: } elsif ($award eq 'COMMA_FAIL') {
708: $message = &mt("Proper comma separation is required").'.';
709: $bgcolor=$possiblecolors{'not_charged_try'};
710: $button=1;
1.135 albertel 711: } elsif ($award eq 'BAD_FORMULA') {
712: $message = &mt("Unable to understand formula");
713: $bgcolor=$possiblecolors{'not_charged_try'};
714: $button=1;
715: } elsif ($award eq 'INCORRECT') {
1.144 albertel 716: $message = &mt("Incorrect").'.';
1.135 albertel 717: $bgcolor=$possiblecolors{'charged_try'};
718: $button=1;
719: } elsif ($award eq 'SUBMITTED') {
720: $message = &mt("Your submission has been recorded.");
1.201 albertel 721: $bgcolor=$possiblecolors{'no_grade'};
1.135 albertel 722: $button=1;
723: } elsif ($award eq 'DRAFT') {
1.144 albertel 724: $message = &mt("A draft copy has been saved.");
1.135 albertel 725: $bgcolor=$possiblecolors{'not_charged_try'};
726: $button=1;
727: } elsif ($award eq 'ASSIGNED_SCORE') {
1.144 albertel 728: $message = &mt("A score has been assigned.");
1.135 albertel 729: $bgcolor=$possiblecolors{'correct'};
730: $button=0;
1.144 albertel 731: } elsif ($award eq '') {
1.186 albertel 732: if ($handgrade && $Apache::inputtags::status[-1] eq 'SHOW_ANSWER') {
733: $message = &mt("Nothing submitted.");
734: $bgcolor=$possiblecolors{'charged_try'};
735: } else {
736: $bgcolor=$possiblecolors{'not_charged_try'};
737: }
1.144 albertel 738: $button=1;
1.135 albertel 739: } else {
740: $message = &mt("Unknown message").": $award";
741: $button=1;
742: }
1.194 banghart 743: my (undef,undef,$domain,$user)=&Apache::lonxml::whichuser();
744: foreach my $resid(@Apache::inputtags::response){
745: if ($Apache::lonhomework::history{"resource.$part.$resid.handback"}) {
1.198 albertel 746: $message.='<br />';
747: my @files = split(/\s*,\s*/,
748: $Apache::lonhomework::history{"resource.$part.$resid.handback"});
749: my $file_msg;
750: foreach my $file (@files) {
751: $file_msg.= '<br /><a href="/uploaded/'."$domain/$user".'/'.$file.'">'.$file.'</a>';
752: }
753: $message .= &mt('Returned file(s): [_1]',$file_msg);
754: }
1.194 banghart 755: }
756:
1.135 albertel 757: if (lc($Apache::lonhomework::problemstatus) eq 'no' &&
758: $Apache::inputtags::status[-1] ne 'SHOW_ANSWER') {
759: $message = &mt("Answer Submitted: Your final submission will be graded after the due date.");
1.201 albertel 760: $bgcolor=$possiblecolors{'no_grade'};
1.135 albertel 761: $button=1;
762: }
1.148 albertel 763: if ($Apache::inputtags::status[-1] eq 'SHOW_ANSWER' &&
1.150 albertel 764: !$added_computer_text && $target ne 'tex') {
1.180 albertel 765: $message.= $computer;
1.148 albertel 766: $added_computer_text=1;
1.144 albertel 767: }
1.135 albertel 768: return ($button,$bgcolor,$message,$previousmsg);
1.12 albertel 769: }
770:
1.155 albertel 771: sub markup_unit {
772: my ($unit,$target)=@_;
773: if ($target eq 'tex') {
774: return '\texttt{'.&Apache::lonxml::latex_special_symbols($unit).'}';
775: } else {
776: return "<tt>".$unit."</tt>";
777: }
778: }
779:
1.88 albertel 780: sub removealldata {
1.87 albertel 781: my ($id)=@_;
782: foreach my $key (keys(%Apache::lonhomework::results)) {
783: if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
784: &Apache::lonxml::debug("Removing $key");
785: delete($Apache::lonhomework::results{$key});
786: }
787: }
788: }
789:
1.142 albertel 790: sub hidealldata {
791: my ($id)=@_;
792: foreach my $key (keys(%Apache::lonhomework::results)) {
793: if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
794: &Apache::lonxml::debug("Hidding $key");
795: my $newkey=$key;
796: $newkey=~s/^(resource\.\Q$id\E\.[^\.]+\.)(.*)$/${1}hidden${2}/;
797: $Apache::lonhomework::results{$newkey}=
798: $Apache::lonhomework::results{$key};
799: delete($Apache::lonhomework::results{$key});
800: }
801: }
802: }
803:
1.12 albertel 804: sub setgradedata {
1.136 albertel 805: my ($award,$msg,$id,$previously_used) = @_;
1.154 albertel 806: if ($Apache::lonhomework::scantronmode &&
1.165 albertel 807: &Apache::lonnet::validCODE($env{'form.CODE'})) {
808: $Apache::lonhomework::results{"resource.CODE"}=$env{'form.CODE'};
1.154 albertel 809: } elsif ($Apache::lonhomework::scantronmode &&
1.165 albertel 810: $env{'form.CODE'} eq '' &&
1.154 albertel 811: $Apache::lonhomework::history{"resource.CODE"} ne '') {
812: $Apache::lonhomework::results{"resource.CODE"}='';
1.141 albertel 813: }
1.154 albertel 814:
1.135 albertel 815: if (!$Apache::lonhomework::scantronmode &&
816: $Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
817: $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
818: $Apache::lonhomework::results{"resource.$id.afterduedate"}=$award;
1.87 albertel 819: return '';
1.135 albertel 820: } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~
821: /^correct/ || $Apache::lonhomework::scantronmode ||
822: lc($Apache::lonhomework::problemstatus) eq 'no') {
1.154 albertel 823: # the student doesn't already have it correct,
824: # or we are in a mode (scantron orno problem status) where a correct
825: # can become incorrect
826: # handle assignment of tries and solved status
1.135 albertel 827: my $solvemsg;
828: if ($Apache::lonhomework::scantronmode) {
829: $solvemsg='correct_by_scantron';
830: } else {
831: $solvemsg='correct_by_student';
832: }
833: if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
834: $Apache::lonhomework::results{"resource.$id.afterduedate"}='';
835: }
836: if ( $award eq 'ASSIGNED_SCORE') {
837: $Apache::lonhomework::results{"resource.$id.tries"} =
838: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
839: $Apache::lonhomework::results{"resource.$id.solved"} =
840: $solvemsg;
841: my $numawards=scalar(@Apache::inputtags::response);
842: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
843: foreach my $res (@Apache::inputtags::response) {
844: $Apache::lonhomework::results{"resource.$id.awarded"}+=
845: $Apache::lonhomework::results{"resource.$id.$res.awarded"};
846: }
847: if ($numawards > 0) {
848: $Apache::lonhomework::results{"resource.$id.awarded"}/=
849: $numawards;
850: }
851: } elsif ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
852: $Apache::lonhomework::results{"resource.$id.tries"} =
853: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
854: $Apache::lonhomework::results{"resource.$id.solved"} =
855: $solvemsg;
856: $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
857: } elsif ( $award eq 'INCORRECT' ) {
858: $Apache::lonhomework::results{"resource.$id.tries"} =
859: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1.152 albertel 860: if (lc($Apache::lonhomework::problemstatus) eq 'no' ||
861: $Apache::lonhomework::scantronmode) {
1.135 albertel 862: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
863: }
864: $Apache::lonhomework::results{"resource.$id.solved"} =
865: 'incorrect_attempted';
866: } elsif ( $award eq 'SUBMITTED' ) {
867: $Apache::lonhomework::results{"resource.$id.tries"} =
868: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
869: $Apache::lonhomework::results{"resource.$id.solved"} =
870: 'ungraded_attempted';
871: } elsif ( $award eq 'DRAFT' ) {
872: $Apache::lonhomework::results{"resource.$id.solved"} = '';
873: } elsif ( $award eq 'NO_RESPONSE' ) {
874: #no real response so delete any data that got stored
1.129 albertel 875: &removealldata($id);
876: return '';
877: } else {
1.135 albertel 878: $Apache::lonhomework::results{"resource.$id.solved"} =
879: 'incorrect_attempted';
1.152 albertel 880: if (lc($Apache::lonhomework::problemstatus) eq 'no' ||
881: $Apache::lonhomework::scantronmode) {
1.135 albertel 882: $Apache::lonhomework::results{"resource.$id.tries"} =
883: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
884: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
885: }
886: }
1.136 albertel 887: if (defined($msg)) {
888: $Apache::lonhomework::results{"resource.$id.awardmsg"} = $msg;
889: }
1.135 albertel 890: # did either of the overall awards chage? If so ignore the
891: # previous check
892: if (($Apache::lonhomework::results{"resource.$id.awarded"} eq
893: $Apache::lonhomework::history{"resource.$id.awarded"}) &&
894: ($Apache::lonhomework::results{"resource.$id.solved"} eq
895: $Apache::lonhomework::history{"resource.$id.solved"})) {
896: # check if this was a previous submission if it was delete the
897: # unneeded data and update the previously_used attribute
898: if ( $previously_used eq 'PREVIOUSLY_USED') {
899: if (lc($Apache::lonhomework::problemstatus) ne 'no') {
900: delete($Apache::lonhomework::results{"resource.$id.tries"});
901: $Apache::lonhomework::results{"resource.$id.previous"} = '1';
902: }
903: } elsif ( $previously_used eq 'PREVIOUSLY_LAST') {
904: #delete all data as they student didn't do anything, but save
905: #the list of collaborators.
906: &removealldata($id);
907: #and since they didn't do anything we were never here
908: return '';
909: } else {
910: $Apache::lonhomework::results{"resource.$id.previous"} = '0';
911: }
1.101 albertel 912: }
1.135 albertel 913: } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} =~
914: /^correct/ ) {
915: #delete all data as they student already has it correct
916: &removealldata($id);
917: #and since they didn't do anything we were never here
918: return '';
1.40 albertel 919: }
1.135 albertel 920: $Apache::lonhomework::results{"resource.$id.award"} = $award;
1.184 albertel 921: if ($award eq 'SUBMITTED') {
922: &Apache::response::add_to_gradingqueue();
923: }
1.10 albertel 924: }
925:
1.9 albertel 926: sub grade {
1.135 albertel 927: my ($target) = @_;
928: my $id = $Apache::inputtags::part;
929: my $response='';
1.165 albertel 930: if ( defined $env{'form.submitted'}) {
1.136 albertel 931: my (@awards,@msgs);
1.135 albertel 932: foreach $response (@Apache::inputtags::response) {
933: &Apache::lonxml::debug("looking for response.$id.$response.awarddetail");
934: my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"};
935: &Apache::lonxml::debug("keeping $value from $response for $id");
936: push (@awards,$value);
1.136 albertel 937: $value=$Apache::lonhomework::results{"resource.$id.$response.awardmsg"};
938: &Apache::lonxml::debug("got message $value from $response for $id");
939: push (@msgs,$value);
1.135 albertel 940: }
1.136 albertel 941: my ($finalaward,$msg) = &finalizeawards(\@awards,\@msgs);
1.135 albertel 942: my $previously_used;
943: if ( $#Apache::inputtags::previous eq $#awards ) {
944: my $match=0;
945: my @matches;
946: foreach my $versionar (@Apache::inputtags::previous_version) {
947: foreach my $version (@$versionar) {
948: $matches[$version]++;
949: }
950: }
951: foreach my $elem (@matches) {if ($elem eq ($#awards+1)) {$match=1;}}
952: if ($match) {
953: $previously_used = 'PREVIOUSLY_LAST';
954: foreach my $value (@Apache::inputtags::previous) {
955: if ($value eq 'PREVIOUSLY_USED' ) {
956: $previously_used = $value;
957: last;
958: }
1.75 albertel 959: }
960: }
1.43 albertel 961: }
1.136 albertel 962: &Apache::lonxml::debug("final award $finalaward, $previously_used, message $msg");
963: &setgradedata($finalaward,$msg,$id,$previously_used);
1.43 albertel 964: }
1.135 albertel 965: return '';
1.1 albertel 966: }
967:
1.11 albertel 968: sub gradestatus {
1.135 albertel 969: my ($id,$target) = @_;
970: my $showbutton = 1;
971: my $bgcolor = '';
972: my $message = '';
973: my $latemessage = '';
974: my $trystr='';
975: my $button='';
976: my $previousmsg='';
977:
978: my $status = $Apache::inputtags::status['-1'];
979: &Apache::lonxml::debug("gradestatus has :$status:");
1.183 albertel 980: if ( $status ne 'CLOSED'
981: && $status ne 'UNAVAILABLE'
982: && $status ne 'INVALID_ACCESS'
983: && $status ne 'NEEDS_CHECKIN'
984: && $status ne 'NOT_IN_A_SLOT') {
1.135 albertel 985: my $award = $Apache::lonhomework::history{"resource.$id.award"};
1.169 albertel 986: my $awarded = $Apache::lonhomework::history{"resource.$id.awarded"};
1.135 albertel 987: my $solved = $Apache::lonhomework::history{"resource.$id.solved"};
988: my $previous = $Apache::lonhomework::history{"resource.$id.previous"};
1.136 albertel 989: my $awardmsg = $Apache::lonhomework::history{"resource.$id.awardmsg"};
990: &Apache::lonxml::debug("Found Award |$award|$solved|$awardmsg");
1.144 albertel 991: if ( $award ne '' || $solved ne '' || $status eq 'SHOW_ANSWER') {
1.135 albertel 992: &Apache::lonxml::debug('Getting message');
993: ($showbutton,$bgcolor,$message,$previousmsg) =
1.169 albertel 994: &decideoutput($award,$awarded,$awardmsg,$solved,$previous,
995: $target);
1.135 albertel 996: if ($target eq 'tex') {
997: $message='\vskip 2 mm '.$message.' ';
998: } else {
999: $message="<td bgcolor=\"$bgcolor\">$message</td>";
1000: if ($previousmsg) {
1001: $previousmsg="<td bgcolor=\"#aaaaff\">$previousmsg</td>";
1002: }
1003: }
1004: }
1005: my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
1006: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
1007: &Apache::lonxml::debug("got maxtries of :$maxtries:");
1008: #if tries are set to negative turn off the Tries/Button and messages
1009: if (defined($maxtries) && $maxtries < 0) { return ''; }
1010: if ( $tries eq '' ) { $tries = '0'; }
1011: if ( $maxtries eq '' ) { $maxtries = '2'; }
1012: if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; }
1013: my $tries_text=&mt('Tries');
1.164 albertel 1014: if ( $Apache::lonhomework::type eq 'survey' ||
1015: $Apache::lonhomework::parsing_a_task) {
1016: $tries_text=&mt('Submissions');
1017: }
1.135 albertel 1018: if ( $showbutton ) {
1019: if ($target eq 'tex') {
1.165 albertel 1020: if ($env{'request.state'} ne "construct" && $Apache::lonhomework::type ne 'exam' && $env{'form.suppress_tries'} ne 'yes') {
1.135 albertel 1021: $trystr = ' {\vskip 1 mm \small \textit{'.$tries_text.'} '.$tries.'/'.$maxtries.'} \vskip 2 mm ';
1022: } else {
1023: $trystr = '\vskip 0 mm ';
1024: }
1025: } else {
1.136 albertel 1026: $trystr = "<td><nobr>".$tries_text." $tries";
1.164 albertel 1027: if ($Apache::lonhomework::parsing_a_task) {
1.165 albertel 1028: } elsif($env{'request.state'} ne 'construct') {
1.135 albertel 1029: $trystr.="/$maxtries";
1030: } else {
1031: if (defined($Apache::inputtags::params{'maxtries'})) {
1032: $trystr.="/".$Apache::inputtags::params{'maxtries'};
1033: }
1034: }
1.136 albertel 1035: $trystr.="</nobr></td>";
1.135 albertel 1036: }
1037: }
1038: if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
1039: if ( $showbutton ) {
1040: if ($target ne 'tex') {
1.156 albertel 1041: $button = '<input type="submit" name="submit_'.$id.'" value="'.&mt('Submit Answer').'" />';
1.135 albertel 1042: }
1043: }
1044: if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
1045: #last submissions was after due date
1.163 albertel 1046: $latemessage=&mt(' The last submission was after the Due Date ');;
1047: if ($target eq 'web') {
1048: $latemessage='<td bgcolor="#ffaaaa">'.$latemessage.'</td>';
1.135 albertel 1049: }
1050: }
1051: }
1052: my $output= $previousmsg.$latemessage.$message.$trystr;
1053: if ($output =~ /^\s*$/) {
1054: return $button;
1.63 sakharuk 1055: } else {
1.135 albertel 1056: if ($target eq 'tex') {
1057: return $button.' \vskip 0 mm '.$output.' ';
1058: } else {
1059: return '<table><tr><td>'.$button.'</td>'.$output.'</tr></table>';
1060: }
1.63 sakharuk 1061: }
1.11 albertel 1062: }
1.1 albertel 1063: 1;
1064: __END__
1.43 albertel 1065:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>