Annotation of loncom/homework/inputtags.pm, revision 1.212
1.43 albertel 1: # The LearningOnline Network with CAPA
2: # input definitons
1.47 albertel 3: #
1.212 ! albertel 4: # $Id: inputtags.pm,v 1.211 2006/12/14 04:31:32 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);
1.212 ! albertel 704: my $word = ($used < $min) ? 'more' : 'fewer';
! 705: $message = &mt("Submission not graded. Use $word digits.",$used);
1.135 albertel 706: $bgcolor=$possiblecolors{'not_charged_try'};
707: $button=1;
1.137 albertel 708: } elsif ($award eq 'UNIT_INVALID_INSTRUCTOR') {
709: $message = &mt('Error in instructor specifed unit. This error has been reported to the instructor.', $awardmsg);
710: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');}
711: $bgcolor=$possiblecolors{'not_charged_try'};
712: $button=1;
713: } elsif ($award eq 'UNIT_INVALID_STUDENT') {
1.155 albertel 714: $message = &mt('Unable to interpret units. Computer reads units as "[_1]".',&markup_unit($awardmsg,$target));
1.137 albertel 715: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');}
716: $bgcolor=$possiblecolors{'not_charged_try'};
717: $button=1;
1.140 matthew 718: } elsif ($award eq 'UNIT_FAIL' || $award eq 'UNIT_IRRECONCIBLE') {
1.155 albertel 719: $message = &mt('Incompatible units. No conversion found between "[_1]" and the required units.',&markup_unit($awardmsg,$target));
1.136 albertel 720: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');}
1.135 albertel 721: $bgcolor=$possiblecolors{'not_charged_try'};
722: $button=1;
723: } elsif ($award eq 'UNIT_NOTNEEDED') {
1.155 albertel 724: $message = &mt('Only a number required. Computer reads units of "[_1]".',&markup_unit($awardmsg,$target));
1.135 albertel 725: $bgcolor=$possiblecolors{'not_charged_try'};
726: $button=1;
727: } elsif ($award eq 'NO_UNIT') {
1.144 albertel 728: $message = &mt("Units required").'.';
1.135 albertel 729: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units')};
730: $bgcolor=$possiblecolors{'not_charged_try'};
731: $button=1;
1.153 albertel 732: } elsif ($award eq 'COMMA_FAIL') {
733: $message = &mt("Proper comma separation is required").'.';
734: $bgcolor=$possiblecolors{'not_charged_try'};
735: $button=1;
1.135 albertel 736: } elsif ($award eq 'BAD_FORMULA') {
737: $message = &mt("Unable to understand formula");
738: $bgcolor=$possiblecolors{'not_charged_try'};
739: $button=1;
740: } elsif ($award eq 'INCORRECT') {
1.144 albertel 741: $message = &mt("Incorrect").'.';
1.135 albertel 742: $bgcolor=$possiblecolors{'charged_try'};
743: $button=1;
744: } elsif ($award eq 'SUBMITTED') {
745: $message = &mt("Your submission has been recorded.");
1.201 albertel 746: $bgcolor=$possiblecolors{'no_grade'};
1.135 albertel 747: $button=1;
748: } elsif ($award eq 'DRAFT') {
1.144 albertel 749: $message = &mt("A draft copy has been saved.");
1.135 albertel 750: $bgcolor=$possiblecolors{'not_charged_try'};
751: $button=1;
752: } elsif ($award eq 'ASSIGNED_SCORE') {
1.144 albertel 753: $message = &mt("A score has been assigned.");
1.135 albertel 754: $bgcolor=$possiblecolors{'correct'};
755: $button=0;
1.144 albertel 756: } elsif ($award eq '') {
1.186 albertel 757: if ($handgrade && $Apache::inputtags::status[-1] eq 'SHOW_ANSWER') {
758: $message = &mt("Nothing submitted.");
759: $bgcolor=$possiblecolors{'charged_try'};
760: } else {
761: $bgcolor=$possiblecolors{'not_charged_try'};
762: }
1.144 albertel 763: $button=1;
1.135 albertel 764: } else {
765: $message = &mt("Unknown message").": $award";
766: $button=1;
767: }
1.209 albertel 768: my (undef,undef,$domain,$user)=&Apache::lonnet::whichuser();
1.194 banghart 769: foreach my $resid(@Apache::inputtags::response){
770: if ($Apache::lonhomework::history{"resource.$part.$resid.handback"}) {
1.198 albertel 771: $message.='<br />';
772: my @files = split(/\s*,\s*/,
773: $Apache::lonhomework::history{"resource.$part.$resid.handback"});
774: my $file_msg;
775: foreach my $file (@files) {
776: $file_msg.= '<br /><a href="/uploaded/'."$domain/$user".'/'.$file.'">'.$file.'</a>';
777: }
778: $message .= &mt('Returned file(s): [_1]',$file_msg);
779: }
1.194 banghart 780: }
781:
1.135 albertel 782: if (lc($Apache::lonhomework::problemstatus) eq 'no' &&
783: $Apache::inputtags::status[-1] ne 'SHOW_ANSWER') {
784: $message = &mt("Answer Submitted: Your final submission will be graded after the due date.");
1.201 albertel 785: $bgcolor=$possiblecolors{'no_grade'};
1.135 albertel 786: $button=1;
787: }
1.148 albertel 788: if ($Apache::inputtags::status[-1] eq 'SHOW_ANSWER' &&
1.150 albertel 789: !$added_computer_text && $target ne 'tex') {
1.180 albertel 790: $message.= $computer;
1.148 albertel 791: $added_computer_text=1;
1.144 albertel 792: }
1.135 albertel 793: return ($button,$bgcolor,$message,$previousmsg);
1.12 albertel 794: }
795:
1.155 albertel 796: sub markup_unit {
797: my ($unit,$target)=@_;
798: if ($target eq 'tex') {
799: return '\texttt{'.&Apache::lonxml::latex_special_symbols($unit).'}';
800: } else {
801: return "<tt>".$unit."</tt>";
802: }
803: }
804:
1.88 albertel 805: sub removealldata {
1.87 albertel 806: my ($id)=@_;
807: foreach my $key (keys(%Apache::lonhomework::results)) {
808: if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
809: &Apache::lonxml::debug("Removing $key");
810: delete($Apache::lonhomework::results{$key});
811: }
812: }
813: }
814:
1.142 albertel 815: sub hidealldata {
816: my ($id)=@_;
817: foreach my $key (keys(%Apache::lonhomework::results)) {
818: if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
819: &Apache::lonxml::debug("Hidding $key");
820: my $newkey=$key;
821: $newkey=~s/^(resource\.\Q$id\E\.[^\.]+\.)(.*)$/${1}hidden${2}/;
822: $Apache::lonhomework::results{$newkey}=
823: $Apache::lonhomework::results{$key};
824: delete($Apache::lonhomework::results{$key});
825: }
826: }
827: }
828:
1.12 albertel 829: sub setgradedata {
1.136 albertel 830: my ($award,$msg,$id,$previously_used) = @_;
1.154 albertel 831: if ($Apache::lonhomework::scantronmode &&
1.165 albertel 832: &Apache::lonnet::validCODE($env{'form.CODE'})) {
833: $Apache::lonhomework::results{"resource.CODE"}=$env{'form.CODE'};
1.154 albertel 834: } elsif ($Apache::lonhomework::scantronmode &&
1.165 albertel 835: $env{'form.CODE'} eq '' &&
1.154 albertel 836: $Apache::lonhomework::history{"resource.CODE"} ne '') {
837: $Apache::lonhomework::results{"resource.CODE"}='';
1.141 albertel 838: }
1.154 albertel 839:
1.135 albertel 840: if (!$Apache::lonhomework::scantronmode &&
841: $Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
842: $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
843: $Apache::lonhomework::results{"resource.$id.afterduedate"}=$award;
1.87 albertel 844: return '';
1.135 albertel 845: } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~
846: /^correct/ || $Apache::lonhomework::scantronmode ||
847: lc($Apache::lonhomework::problemstatus) eq 'no') {
1.154 albertel 848: # the student doesn't already have it correct,
849: # or we are in a mode (scantron orno problem status) where a correct
850: # can become incorrect
851: # handle assignment of tries and solved status
1.135 albertel 852: my $solvemsg;
853: if ($Apache::lonhomework::scantronmode) {
854: $solvemsg='correct_by_scantron';
855: } else {
856: $solvemsg='correct_by_student';
857: }
858: if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
859: $Apache::lonhomework::results{"resource.$id.afterduedate"}='';
860: }
861: if ( $award eq 'ASSIGNED_SCORE') {
862: $Apache::lonhomework::results{"resource.$id.tries"} =
863: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
864: $Apache::lonhomework::results{"resource.$id.solved"} =
865: $solvemsg;
866: my $numawards=scalar(@Apache::inputtags::response);
867: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
868: foreach my $res (@Apache::inputtags::response) {
869: $Apache::lonhomework::results{"resource.$id.awarded"}+=
870: $Apache::lonhomework::results{"resource.$id.$res.awarded"};
871: }
872: if ($numawards > 0) {
873: $Apache::lonhomework::results{"resource.$id.awarded"}/=
874: $numawards;
875: }
876: } elsif ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
877: $Apache::lonhomework::results{"resource.$id.tries"} =
878: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
879: $Apache::lonhomework::results{"resource.$id.solved"} =
880: $solvemsg;
881: $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
882: } elsif ( $award eq 'INCORRECT' ) {
883: $Apache::lonhomework::results{"resource.$id.tries"} =
884: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1.152 albertel 885: if (lc($Apache::lonhomework::problemstatus) eq 'no' ||
886: $Apache::lonhomework::scantronmode) {
1.135 albertel 887: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
888: }
889: $Apache::lonhomework::results{"resource.$id.solved"} =
890: 'incorrect_attempted';
891: } elsif ( $award eq 'SUBMITTED' ) {
892: $Apache::lonhomework::results{"resource.$id.tries"} =
893: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
894: $Apache::lonhomework::results{"resource.$id.solved"} =
895: 'ungraded_attempted';
896: } elsif ( $award eq 'DRAFT' ) {
897: $Apache::lonhomework::results{"resource.$id.solved"} = '';
898: } elsif ( $award eq 'NO_RESPONSE' ) {
899: #no real response so delete any data that got stored
1.129 albertel 900: &removealldata($id);
901: return '';
902: } else {
1.135 albertel 903: $Apache::lonhomework::results{"resource.$id.solved"} =
904: 'incorrect_attempted';
1.152 albertel 905: if (lc($Apache::lonhomework::problemstatus) eq 'no' ||
906: $Apache::lonhomework::scantronmode) {
1.135 albertel 907: $Apache::lonhomework::results{"resource.$id.tries"} =
908: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
909: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
910: }
911: }
1.136 albertel 912: if (defined($msg)) {
913: $Apache::lonhomework::results{"resource.$id.awardmsg"} = $msg;
914: }
1.135 albertel 915: # did either of the overall awards chage? If so ignore the
916: # previous check
917: if (($Apache::lonhomework::results{"resource.$id.awarded"} eq
918: $Apache::lonhomework::history{"resource.$id.awarded"}) &&
919: ($Apache::lonhomework::results{"resource.$id.solved"} eq
920: $Apache::lonhomework::history{"resource.$id.solved"})) {
921: # check if this was a previous submission if it was delete the
922: # unneeded data and update the previously_used attribute
923: if ( $previously_used eq 'PREVIOUSLY_USED') {
924: if (lc($Apache::lonhomework::problemstatus) ne 'no') {
925: delete($Apache::lonhomework::results{"resource.$id.tries"});
926: $Apache::lonhomework::results{"resource.$id.previous"} = '1';
927: }
928: } elsif ( $previously_used eq 'PREVIOUSLY_LAST') {
929: #delete all data as they student didn't do anything, but save
930: #the list of collaborators.
931: &removealldata($id);
932: #and since they didn't do anything we were never here
933: return '';
934: } else {
935: $Apache::lonhomework::results{"resource.$id.previous"} = '0';
936: }
1.101 albertel 937: }
1.135 albertel 938: } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} =~
939: /^correct/ ) {
940: #delete all data as they student already has it correct
941: &removealldata($id);
942: #and since they didn't do anything we were never here
943: return '';
1.40 albertel 944: }
1.135 albertel 945: $Apache::lonhomework::results{"resource.$id.award"} = $award;
1.184 albertel 946: if ($award eq 'SUBMITTED') {
947: &Apache::response::add_to_gradingqueue();
948: }
1.10 albertel 949: }
950:
1.9 albertel 951: sub grade {
1.135 albertel 952: my ($target) = @_;
953: my $id = $Apache::inputtags::part;
954: my $response='';
1.165 albertel 955: if ( defined $env{'form.submitted'}) {
1.136 albertel 956: my (@awards,@msgs);
1.135 albertel 957: foreach $response (@Apache::inputtags::response) {
958: &Apache::lonxml::debug("looking for response.$id.$response.awarddetail");
959: my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"};
960: &Apache::lonxml::debug("keeping $value from $response for $id");
961: push (@awards,$value);
1.136 albertel 962: $value=$Apache::lonhomework::results{"resource.$id.$response.awardmsg"};
963: &Apache::lonxml::debug("got message $value from $response for $id");
964: push (@msgs,$value);
1.135 albertel 965: }
1.136 albertel 966: my ($finalaward,$msg) = &finalizeawards(\@awards,\@msgs);
1.135 albertel 967: my $previously_used;
968: if ( $#Apache::inputtags::previous eq $#awards ) {
969: my $match=0;
970: my @matches;
971: foreach my $versionar (@Apache::inputtags::previous_version) {
972: foreach my $version (@$versionar) {
973: $matches[$version]++;
974: }
975: }
976: foreach my $elem (@matches) {if ($elem eq ($#awards+1)) {$match=1;}}
977: if ($match) {
978: $previously_used = 'PREVIOUSLY_LAST';
979: foreach my $value (@Apache::inputtags::previous) {
980: if ($value eq 'PREVIOUSLY_USED' ) {
981: $previously_used = $value;
982: last;
983: }
1.75 albertel 984: }
985: }
1.43 albertel 986: }
1.136 albertel 987: &Apache::lonxml::debug("final award $finalaward, $previously_used, message $msg");
988: &setgradedata($finalaward,$msg,$id,$previously_used);
1.43 albertel 989: }
1.135 albertel 990: return '';
1.1 albertel 991: }
992:
1.11 albertel 993: sub gradestatus {
1.135 albertel 994: my ($id,$target) = @_;
995: my $showbutton = 1;
996: my $bgcolor = '';
997: my $message = '';
998: my $latemessage = '';
999: my $trystr='';
1000: my $button='';
1001: my $previousmsg='';
1002:
1003: my $status = $Apache::inputtags::status['-1'];
1004: &Apache::lonxml::debug("gradestatus has :$status:");
1.183 albertel 1005: if ( $status ne 'CLOSED'
1006: && $status ne 'UNAVAILABLE'
1007: && $status ne 'INVALID_ACCESS'
1008: && $status ne 'NEEDS_CHECKIN'
1009: && $status ne 'NOT_IN_A_SLOT') {
1.135 albertel 1010: my $award = $Apache::lonhomework::history{"resource.$id.award"};
1.169 albertel 1011: my $awarded = $Apache::lonhomework::history{"resource.$id.awarded"};
1.135 albertel 1012: my $solved = $Apache::lonhomework::history{"resource.$id.solved"};
1013: my $previous = $Apache::lonhomework::history{"resource.$id.previous"};
1.136 albertel 1014: my $awardmsg = $Apache::lonhomework::history{"resource.$id.awardmsg"};
1015: &Apache::lonxml::debug("Found Award |$award|$solved|$awardmsg");
1.144 albertel 1016: if ( $award ne '' || $solved ne '' || $status eq 'SHOW_ANSWER') {
1.135 albertel 1017: &Apache::lonxml::debug('Getting message');
1018: ($showbutton,$bgcolor,$message,$previousmsg) =
1.169 albertel 1019: &decideoutput($award,$awarded,$awardmsg,$solved,$previous,
1020: $target);
1.135 albertel 1021: if ($target eq 'tex') {
1022: $message='\vskip 2 mm '.$message.' ';
1023: } else {
1024: $message="<td bgcolor=\"$bgcolor\">$message</td>";
1025: if ($previousmsg) {
1026: $previousmsg="<td bgcolor=\"#aaaaff\">$previousmsg</td>";
1027: }
1028: }
1029: }
1030: my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
1031: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
1032: &Apache::lonxml::debug("got maxtries of :$maxtries:");
1033: #if tries are set to negative turn off the Tries/Button and messages
1034: if (defined($maxtries) && $maxtries < 0) { return ''; }
1035: if ( $tries eq '' ) { $tries = '0'; }
1036: if ( $maxtries eq '' ) { $maxtries = '2'; }
1037: if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; }
1038: my $tries_text=&mt('Tries');
1.164 albertel 1039: if ( $Apache::lonhomework::type eq 'survey' ||
1040: $Apache::lonhomework::parsing_a_task) {
1041: $tries_text=&mt('Submissions');
1042: }
1.135 albertel 1043: if ( $showbutton ) {
1044: if ($target eq 'tex') {
1.165 albertel 1045: if ($env{'request.state'} ne "construct" && $Apache::lonhomework::type ne 'exam' && $env{'form.suppress_tries'} ne 'yes') {
1.135 albertel 1046: $trystr = ' {\vskip 1 mm \small \textit{'.$tries_text.'} '.$tries.'/'.$maxtries.'} \vskip 2 mm ';
1047: } else {
1048: $trystr = '\vskip 0 mm ';
1049: }
1050: } else {
1.136 albertel 1051: $trystr = "<td><nobr>".$tries_text." $tries";
1.164 albertel 1052: if ($Apache::lonhomework::parsing_a_task) {
1.165 albertel 1053: } elsif($env{'request.state'} ne 'construct') {
1.135 albertel 1054: $trystr.="/$maxtries";
1055: } else {
1056: if (defined($Apache::inputtags::params{'maxtries'})) {
1057: $trystr.="/".$Apache::inputtags::params{'maxtries'};
1058: }
1059: }
1.136 albertel 1060: $trystr.="</nobr></td>";
1.135 albertel 1061: }
1062: }
1063: if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
1064: if ( $showbutton ) {
1065: if ($target ne 'tex') {
1.156 albertel 1066: $button = '<input type="submit" name="submit_'.$id.'" value="'.&mt('Submit Answer').'" />';
1.135 albertel 1067: }
1068: }
1069: if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
1070: #last submissions was after due date
1.163 albertel 1071: $latemessage=&mt(' The last submission was after the Due Date ');;
1072: if ($target eq 'web') {
1073: $latemessage='<td bgcolor="#ffaaaa">'.$latemessage.'</td>';
1.135 albertel 1074: }
1075: }
1076: }
1077: my $output= $previousmsg.$latemessage.$message.$trystr;
1078: if ($output =~ /^\s*$/) {
1079: return $button;
1.63 sakharuk 1080: } else {
1.135 albertel 1081: if ($target eq 'tex') {
1082: return $button.' \vskip 0 mm '.$output.' ';
1083: } else {
1084: return '<table><tr><td>'.$button.'</td>'.$output.'</tr></table>';
1085: }
1.63 sakharuk 1086: }
1.11 albertel 1087: }
1.1 albertel 1088: 1;
1089: __END__
1.43 albertel 1090:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>