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