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