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