Annotation of loncom/homework/inputtags.pm, revision 1.207
1.43 albertel 1: # The LearningOnline Network with CAPA
2: # input definitons
1.47 albertel 3: #
1.207 ! albertel 4: # $Id: inputtags.pm,v 1.206 2006/09/29 20:55:33 albertel Exp $
1.47 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
1.1 albertel 27:
28: package Apache::inputtags;
1.55 albertel 29: use HTML::Entities();
1.1 albertel 30: use strict;
1.82 www 31: use Apache::loncommon;
1.115 www 32: use Apache::lonlocal;
1.165 albertel 33: use Apache::lonnet;
1.192 www 34: use lib '/home/httpd/lib/perl/';
35: use LONCAPA;
36:
1.1 albertel 37:
1.50 harris41 38: BEGIN {
1.135 albertel 39: &Apache::lonxml::register('Apache::inputtags',('hiddenline','textfield','textline'));
1.1 albertel 40: }
41:
1.177 foxr 42: # Initializes a set of global variables used during the parse of the problem.
43: #
1.178 albertel 44: # @Apache::inputtags::input - List of current input ids.
45: # @Apache::inputtags::inputlist - List of all input ids seen this problem.
46: # @Apache::inputtags::response - List of all current resopnse ids.
47: # @Apache::inputtags::responselist - List of all response ids seen this
48: # problem.
49: # @Apache::inputtags::hint - List of all hint ids.
50: # @Apache::inputtags::hintlist - List of all hint ids seen this problem.
51: # @Apache::inputtags::previous - List describing if specific responseds
52: # have been used
53: # @Apache::inputtags::previous_version - Submission responses were used in.
54: # $Apache::inputtags::part - Current part id (valid only in
55: # <problem>)
56: # 0 if not in a part.
57: # @Apache::inputtags::partlist - List of part ids seen in the current
58: # <problem>
59: # @Apache::inputtags::status - List of problem statuses. First
60: # element is the status of the <problem>
61: # the remainder are for individual <part>s.
62: # %Apache::inputtags::params - Hash of defined parameters for the
63: # current response.
64: # @Apache::inputtags::import - List of all ids for <import> thes get
65: # join()ed and prepended.
66: # @Apache::inputtags::importlist - List of all import ids seen.
67: # $Apache::inputtags::response_with_no_part
68: # - Flag set true if we have seen a response
69: # that is not inside a <part>
70: # %Apache::inputtags::answertxt - <*response> tags store correct
71: # answer strings for display by <textline/>
72: # in this hash.
73:
1.1 albertel 74: sub initialize_inputtags {
1.135 albertel 75: @Apache::inputtags::input=();
76: @Apache::inputtags::inputlist=();
1.174 albertel 77: @Apache::inputtags::response=();
1.135 albertel 78: @Apache::inputtags::responselist=();
1.174 albertel 79: @Apache::inputtags::hint=();
1.173 albertel 80: @Apache::inputtags::hintlist=();
1.135 albertel 81: @Apache::inputtags::previous=();
82: @Apache::inputtags::previous_version=();
83: $Apache::inputtags::part='';
84: @Apache::inputtags::partlist=();
85: @Apache::inputtags::status=();
86: %Apache::inputtags::params=();
87: @Apache::inputtags::import=();
88: @Apache::inputtags::importlist=();
89: $Apache::inputtags::response_with_no_part=0;
1.144 albertel 90: %Apache::inputtags::answertxt=();
1.103 albertel 91: }
92:
93: sub check_for_duplicate_ids {
94: my %check;
95: foreach my $id (@Apache::inputtags::partlist,
96: @Apache::inputtags::responselist,
1.173 albertel 97: @Apache::inputtags::hintlist,
1.103 albertel 98: @Apache::inputtags::importlist) {
99: $check{$id}++;
100: }
101: my @duplicates;
102: foreach my $id (sort(keys(%check))) {
103: if ($check{$id} > 1) {
104: push(@duplicates,$id);
105: }
106: }
107: if (@duplicates) {
108: &Apache::lonxml::error("Duplicated ids found, problem will operate incorrectly. Duplicated ids seen: ",join(', ',@duplicates));
109: }
1.1 albertel 110: }
111:
1.14 albertel 112: sub start_input {
1.135 albertel 113: my ($parstack,$safeeval)=@_;
114: my $id = &Apache::lonxml::get_param('id',$parstack,$safeeval);
115: if ($id eq '') { $id = $Apache::lonxml::curdepth; }
116: push (@Apache::inputtags::input,$id);
117: push (@Apache::inputtags::inputlist,$id);
118: return $id;
1.14 albertel 119: }
120:
121: sub end_input {
1.135 albertel 122: pop @Apache::inputtags::input;
123: return '';
1.14 albertel 124: }
125:
1.124 www 126: sub addchars {
127: my ($fieldid,$addchars)=@_;
128: my $output='';
129: foreach (split(/\,/,$addchars)) {
130: $output.='<a href="javascript:void(document.forms.lonhomework.'.
131: $fieldid.'.value+=\''.$_.'\')">'.$_.'</a> ';
132: }
133: return $output;
134: }
135:
1.48 albertel 136: sub start_textfield {
1.185 albertel 137: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.135 albertel 138: my $result = "";
139: my $id = &start_input($parstack,$safeeval);
140: my $resid=$Apache::inputtags::response[-1];
141: if ($target eq 'web') {
142: $Apache::lonxml::evaluate--;
1.205 albertel 143: my $partid=$Apache::inputtags::part;
144: my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$resid.submission"},'<>&"');
1.135 albertel 145: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
146: my $cols = &Apache::lonxml::get_param('cols',$parstack,$safeeval);
147: if ( $cols eq '') { $cols = 80; }
148: my $rows = &Apache::lonxml::get_param('rows',$parstack,$safeeval);
1.143 www 149: if ( $rows eq '') { $rows = 16; }
1.135 albertel 150: my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval);
151: $result='';
152: if ($addchars) {
153: $result.=&addchars('HWVAL_'.$resid,$addchars);
154: }
1.191 albertel 155: &Apache::lonhtmlcommon::add_htmlareafields('HWVAL_'.$resid);
1.143 www 156: $result.= '<textarea wrap="hard" name="HWVAL_'.$resid.'" id="HWVAL_'.$resid.'" '.
1.135 albertel 157: "rows=\"$rows\" cols=\"$cols\">".$oldresponse;
158: if ($oldresponse ne '') {
1.143 www 159:
1.135 albertel 160: #get rid of any startup text if the user has already responded
1.185 albertel 161: &Apache::lonxml::get_all_text("/textfield",$parser,$style);
1.135 albertel 162: }
163: } else {
1.205 albertel 164: #show past answer in the essayresponse case
165: if ($oldresponse =~ /\S/
166: && &Apache::londefdef::is_inside_of($tagstack,
167: 'essayresponse') ) {
168: $result='<table class="LC_pastsubmission"><tr><td>'.
169: $oldresponse.'</td></tr></table>';
170: }
1.135 albertel 171: #get rid of any startup text
1.185 albertel 172: &Apache::lonxml::get_all_text("/textfield",$parser,$style);
1.61 albertel 173: }
1.135 albertel 174: } elsif ($target eq 'grade') {
1.185 albertel 175: my $seedtext=&Apache::lonxml::get_all_text("/textfield",$parser,
176: $style);
1.165 albertel 177: if ($seedtext eq $env{'form.HWVAL_'.$resid}) {
1.135 albertel 178: # if the seed text is still there it wasn't a real submission
1.165 albertel 179: $env{'form.HWVAL_'.$resid}='';
1.135 albertel 180: }
181: } elsif ($target eq 'edit') {
182: $result.=&Apache::edit::tag_start($target,$token);
183: $result.=&Apache::edit::text_arg('Rows:','rows',$token,4);
184: $result.=&Apache::edit::text_arg('Columns:','cols',$token,4);
185: $result.=&Apache::edit::text_arg
186: ('Click-On Texts (comma sep):','addchars',$token,10);
1.185 albertel 187: my $bodytext=&Apache::lonxml::get_all_text("/textfield",$parser,
188: $style);
1.135 albertel 189: $result.=&Apache::edit::editfield($token->[1],$bodytext,'Text you want to appear by default:',80,2);
190: } elsif ($target eq 'modified') {
191: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
192: $safeeval,'rows','cols',
193: 'addchars');
194: if ($constructtag) {
195: $result = &Apache::edit::rebuild_tag($token);
196: } else {
197: $result=$token->[4];
198: }
199: $result.=&Apache::edit::modifiedfield("/textfield",$parser);
200: } elsif ($target eq 'tex') {
201: my $number_of_lines = &Apache::lonxml::get_param('rows',$parstack,$safeeval);
202: my $width_of_box = &Apache::lonxml::get_param('cols',$parstack,$safeeval);
203: if ($$tagstack[-2] eq 'essayresponse' and $Apache::lonhomework::type eq 'exam') {
204: $result = '\fbox{\fbox{\parbox{\textwidth-5mm}{';
205: for (my $i=0;$i<int $number_of_lines*2;$i++) {$result.='\strut \\\\ ';}
206: $result.='\strut \\\\\strut \\\\\strut \\\\\strut \\\\}}}';
207: } else {
208: my $TeXwidth=$width_of_box/80;
209: $result = '\vskip 1 mm \fbox{\fbox{\parbox{'.$TeXwidth.'\textwidth-5mm}{';
210: for (my $i=0;$i<int $number_of_lines*2;$i++) {$result.='\strut \\\\ ';}
211: $result.='}}}\vskip 2 mm ';
212: }
1.60 albertel 213: }
1.135 albertel 214: return $result;
1.6 albertel 215: }
216:
1.48 albertel 217: sub end_textfield {
1.135 albertel 218: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
219: my $result;
220: if ($target eq 'web') {
221: $Apache::lonxml::evaluate++;
222: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
223: return "</textarea>";
224: }
225: } elsif ($target eq 'edit') {
226: $result=&Apache::edit::end_table();
227: }
228: &end_input;
229: return $result;
1.6 albertel 230: }
231:
1.190 albertel 232: sub exam_score_line {
1.188 albertel 233: my ($target) = @_;
1.190 albertel 234:
1.188 albertel 235: my $result;
236: if ($target eq 'tex') {
237: my $repetition = &Apache::response::repetition();
238: $result.='\begin{enumerate}';
1.190 albertel 239: if ($env{'request.state'} eq "construct" ) {$result.='\item[\strut]';}
1.188 albertel 240: foreach my $i (0..$repetition-1) {
241: $result.='\item[\textbf{'.
242: ($Apache::lonxml::counter+$i).
243: '}.]\textit{Leave blank on scoring form}\vskip 0 mm';
244: }
245: $result.= '\end{enumerate}';
1.190 albertel 246: }
247:
248: return $result;
249: }
250:
251: sub exam_box {
252: my ($target) = @_;
253: my $result;
1.188 albertel 254:
1.190 albertel 255: if ($target eq 'tex') {
256: $result .= '\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}';
257: $result .= &exam_score_line($target);
1.188 albertel 258: } elsif ($target eq 'web') {
259: my $id=$Apache::inputtags::response[-1];
260: $result.= '<br /><br />
261: <textarea name="HWVAL_'.$id.'" rows="4" cols="50">
262: </textarea> <br /><br />';
263: }
264: return $result;
265: }
266:
267: sub needs_exam_box {
268: my ($tagstack) = @_;
269: my @tags = ('formularesponse',
270: 'stringresponse',
271: 'reactionresponse',
272: 'organicresponse',
273: );
274:
275: foreach my $tag (@tags) {
276: if (grep(/\Q$tag\E/,@$tagstack)) {
277: return 1;
278: }
279: }
280: return 0;
281: }
282:
1.1 albertel 283: sub start_textline {
1.135 albertel 284: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
285: my $result = "";
286: if ($target eq 'web') {
287: $Apache::lonxml::evaluate--;
288: my $partid=$Apache::inputtags::part;
289: my $id=$Apache::inputtags::response[-1];
1.204 albertel 290: if (!&Apache::response::show_answer()) {
1.135 albertel 291: my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
292: my $maxlength;
293: if ($size eq '') { $size=20; } else {
294: if ($size < 20) { $maxlength=$size; }
295: }
1.138 albertel 296: my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"},'<>&"');
1.135 albertel 297: if ($Apache::lonhomework::type ne 'exam') {
298: my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval);
299: $result='';
300: if ($addchars) {
301: $result.=&addchars('HWVAL_'.$id,$addchars);
302: }
1.157 albertel 303: my $readonly=&Apache::lonxml::get_param('readonly',$parstack,
304: $safeeval);
1.193 albertel 305: if (lc($readonly) eq 'yes'
306: || $Apache::inputtags::status[-1] eq 'CANNOT_ANSWER') {
1.157 albertel 307: $readonly=' readonly="readonly" ';
1.158 albertel 308: } else {
309: $readonly='';
1.157 albertel 310: }
1.193 albertel 311: my $name = 'HWVAL_'.$id;
312: if ($Apache::inputtags::status[-1] eq 'CANNOT_ANSWER') {
313: $name = "none";
314: }
315: $result.= '<input type="text" '.$readonly.' name="'.$name.'" value="'.
1.135 albertel 316: $oldresponse.'" size="'.$size.'" maxlength="'.$maxlength.'" />';
317: }
1.188 albertel 318: if ($Apache::lonhomework::type eq 'exam'
319: && &needs_exam_box($tagstack)) {
320: $result.=&exam_box($target);
321: }
1.135 albertel 322: } else {
323: #right or wrong don't show what was last typed in.
1.168 albertel 324: $result='<b>'.$Apache::inputtags::answertxt{$id}.'</b>';
1.144 albertel 325: #$result='';
1.135 albertel 326: }
327: } elsif ($target eq 'edit') {
328: $result=&Apache::edit::tag_start($target,$token);
329: $result.=&Apache::edit::text_arg('Size:','size',$token,'5').
1.157 albertel 330: &Apache::edit::text_arg('Click-On Texts (comma sep):',
331: 'addchars',$token,10);
332: $result.=&Apache::edit::select_arg('Readonly:','readonly',
333: ['no','yes'],$token);
334: $result.=&Apache::edit::end_row();
335: $result.=&Apache::edit::end_table();
1.135 albertel 336: } elsif ($target eq 'modified') {
1.157 albertel 337: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
338: $safeeval,'size',
339: 'addchars','readonly');
1.135 albertel 340: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.188 albertel 341: } elsif ($target eq 'tex'
342: && $Apache::lonhomework::type ne 'exam') {
1.135 albertel 343: my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
344: if ($size != 0) {$size=$size*2; $size.=' mm';} else {$size='40 mm';}
345: $result='\framebox['.$size.'][s]{\tiny\strut}';
1.188 albertel 346:
347: } elsif ($target eq 'tex'
348: && $Apache::lonhomework::type eq 'exam'
349: && &needs_exam_box($tagstack)) {
350: $result.=&exam_box($target);
1.135 albertel 351: }
352: return $result;
1.1 albertel 353: }
354:
355: sub end_textline {
1.135 albertel 356: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
357: if ($target eq 'web') { $Apache::lonxml::evaluate++; }
358: elsif ($target eq 'edit') { return ('','no'); }
359: return "";
1.9 albertel 360: }
361:
1.98 albertel 362: sub start_hiddenline {
363: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
364: my $result = "";
365: if ($target eq 'web') {
366: $Apache::lonxml::evaluate--;
367: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
368: my $partid=$Apache::inputtags::part;
369: my $id=$Apache::inputtags::response[-1];
1.138 albertel 370: my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"},'<>&"');
1.98 albertel 371: if ($Apache::lonhomework::type ne 'exam') {
372: $result= '<input type="hidden" name="HWVAL_'.$id.'" value="'.
373: $oldresponse.'" />';
374: }
375: }
376: } elsif ($target eq 'edit') {
377: $result=&Apache::edit::tag_start($target,$token);
378: $result.=&Apache::edit::end_table;
379: }
1.189 albertel 380:
381: if ( ($target eq 'web' || $target eq 'tex')
382: && $Apache::lonhomework::type eq 'exam'
383: && &needs_exam_box($tagstack)) {
384: $result.=&exam_box($target);
385: }
1.98 albertel 386: return $result;
387: }
388:
389: sub end_hiddenline {
1.135 albertel 390: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
391: if ($target eq 'web') { $Apache::lonxml::evaluate++; }
392: elsif ($target eq 'edit') { return ('','no'); }
393: return "";
1.98 albertel 394: }
395:
1.160 albertel 396: # $part -> partid
397: # $id -> responseid
398: # $uploadefiletypes -> comma seperated list of extensions allowed or * for any
399: # $which -> 'uploadedonly' -> only newly uploaded files
400: # 'portfolioonly' -> only allow files from portfolio
401: # 'both' -> allow files from either location
1.175 albertel 402: # $extratext -> additional text to go between the link and the input box
1.160 albertel 403: # returns a table row <tr>
404: sub file_selector {
1.175 albertel 405: my ($part,$id,$uploadedfiletypes,$which,$extratext)=@_;
1.160 albertel 406: if (!$uploadedfiletypes) { return ''; }
1.167 albertel 407:
408: my $jspart=$part;
409: $jspart=~s/\./_/g;
410:
1.160 albertel 411: my $result;
412:
1.162 albertel 413: $result.='<tr><td>';
414: if ($uploadedfiletypes ne '*') {
415: $result.=
416: &mt('Allowed filetypes: <b>[_1]</b>',$uploadedfiletypes).'<br />';
417: }
1.160 albertel 418: if ($which eq 'uploadonly' || $which eq 'both') {
419: $result.=&mt('Submit a file: (only one file can be uploaded)').
420: ' <br /><input type="file" size="50" name="HWFILE'.
1.167 albertel 421: $jspart.'_'.$id.'" /><br />';
1.205 albertel 422: $result .= &show_past_file_submission($part,$id);
1.160 albertel 423: }
424: if ( $which eq 'both') {
425: $result.='<br />'.'<strong>'.&mt('OR:').'</strong><br />';
426: }
427: if ($which eq 'portfolioonly' || $which eq 'both') {
1.175 albertel 428: $result.=$extratext.'<a href='."'".'javascript:void(window.open("/adm/portfolio?mode=selectfile&fieldname=HWPORT'.$jspart.'_'.$id.'","cat","height=600,width=800,scrollbars=1,resizable=1,menubar=2,location=1"))'."'".'>'.
1.160 albertel 429: &mt('Select Portfolio Files').'</a><br />'.
1.167 albertel 430: '<input type="text" size="50" name="HWPORT'.$jspart.'_'.$id.'" value="" />'.
1.160 albertel 431: '<br />';
1.205 albertel 432: $result .= &show_past_portfile_submission($part,$id);
433:
1.160 albertel 434: }
435: $result.='</td></tr>';
436: return $result;
437: }
438:
1.205 albertel 439: sub show_past_file_submission {
440: my ($part,$id) = @_;
441: my $uploadedfile= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.uploadedfile"},'<>&"');
442:
443: return if (!$uploadedfile);
444:
445: my $url=$Apache::lonhomework::history{"resource.$part.$id.uploadedurl"};
446: &Apache::lonxml::extlink($url);
447: &Apache::lonnet::allowuploaded('/adm/essayresponse',$url);
448: my $icon=&Apache::loncommon::icon($url);
449: my $curfile='<a href="'.$url.'"><img src="'.$icon.
450: '" border="0" />'.$uploadedfile.'</a>';
451: return &mt('Currently submitted: <tt>[_1]</tt>',$curfile);
452:
453: }
454:
455: sub show_past_portfile_submission {
456: my ($part,$id) = @_;
457: if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"}!~/[^\s]/){
458: return;
459: }
460: my (@file_list,@bad_file_list);
461: foreach my $file (split(/\s*,\s*/,&unescape($Apache::lonhomework::history{"resource.$part.$id.portfiles"}))) {
462: my (undef,undef,$domain,$user)=&Apache::lonxml::whichuser();
463: my $url="/uploaded/$domain/$user/portfolio$file";
464: my $icon=&Apache::loncommon::icon($url);
465: push(@file_list,'<a href="'.$url.'"><img src="'.$icon.
466: '" border="0" />'.$file.'</a>');
467: if (! &Apache::lonnet::stat_file($url)) {
468: &Apache::lonnet::logthis("bad file is $url");
469: push(@bad_file_list,'<a href="'.$url.'"><img src="'.$icon.
470: '" border="0" />'.$file.'</a>');
471: }
472: }
473: my $files = '<span class="LC_filename">'.
474: join('</span>, <span class="LC_filename">',@file_list).
475: '</span>';
476: my $result = &mt("Portfolio files previously selected: [_1]",$files);
477: if (@bad_file_list) {
478: my $bad_files = '<span class="LC_filename">'.
479: join('</span>, <span class="LC_filename">',@bad_file_list).
480: '</span>';
481: $result.='<br />'.&mt('<span class="LC_error">These file(s) don\'t exist:</span> [_1]',$bad_files);
482: }
483: return $result;
484:
485: }
486:
1.179 albertel 487: sub valid_award {
488: my ($award) =@_;
1.182 albertel 489: foreach my $possibleaward ('EXTRA_ANSWER','MISSING_ANSWER', 'ERROR',
490: 'NO_RESPONSE',
1.179 albertel 491: 'TOO_LONG', 'UNIT_INVALID_INSTRUCTOR',
492: 'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE',
493: 'UNIT_FAIL', 'NO_UNIT',
494: 'UNIT_NOTNEEDED', 'WANTED_NUMERIC',
495: 'BAD_FORMULA', 'SIG_FAIL', 'INCORRECT',
496: 'MISORDERED_RANK', 'INVALID_FILETYPE',
497: 'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
498: 'APPROX_ANS', 'EXACT_ANS','COMMA_FAIL') {
499: if ($award eq $possibleaward) { return 1; }
500: }
501: return 0;
502: }
503:
1.207 ! albertel 504: {
! 505: my @awards = ('EXTRA_ANSWER', 'MISSING_ANSWER', 'ERROR', 'NO_RESPONSE',
! 506: 'TOO_LONG',
! 507: 'UNIT_INVALID_INSTRUCTOR', 'UNIT_INVALID_STUDENT',
! 508: 'UNIT_IRRECONCIBLE', 'UNIT_FAIL', 'NO_UNIT',
! 509: 'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA',
! 510: 'COMMA_FAIL', 'SIG_FAIL', 'INCORRECT', 'MISORDERED_RANK',
! 511: 'INVALID_FILETYPE', 'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
! 512: 'APPROX_ANS', 'EXACT_ANS');
! 513: my $i=0;
! 514: my %fwd_awards = map { ($_,$i++) } @awards;
! 515: my $max=scalar(@awards);
! 516: @awards=reverse(@awards);
! 517: my $i=0;
! 518: my %rev_awards = map { ($_,$i++) } @awards;
! 519:
1.9 albertel 520: sub finalizeawards {
1.181 albertel 521: my ($awardref,$msgref,$nameref,$reverse)=@_;
1.207 ! albertel 522: my $result;
1.136 albertel 523: if ($#$awardref == -1) { $result = "NO_RESPONSE"; }
1.135 albertel 524: if ($result eq '' ) {
525: my $blankcount;
1.207 ! albertel 526: foreach my $award (@$awardref) {
1.135 albertel 527: if ($award eq '') {
528: $result='MISSING_ANSWER';
529: $blankcount++;
530: }
531: }
1.136 albertel 532: if ($blankcount == ($#$awardref + 1)) { $result = 'NO_RESPONSE'; }
1.135 albertel 533: }
1.207 ! albertel 534: if (defined($result)) { return ($result); }
1.181 albertel 535:
536: # these awards are ordered from most important error through best correct
1.207 ! albertel 537: my $awards = (!$reverse) ? \%fwd_awards : \%rev_awards ;
! 538:
! 539: my $best = $max;
! 540: my $j=0;
! 541: my $which;
! 542: foreach my $award (@$awardref) {
! 543: if ($awards->{$award} < $best) {
! 544: $best = $awards->{$award};
! 545: $which = $j;
! 546: }
! 547: $j++;
! 548: }
! 549: if (defined($which)) {
! 550: if (ref($nameref)) {
! 551: return ($$awardref[$which],$$msgref[$which],$$nameref[$which]);
! 552: } else {
! 553: return ($$awardref[$which],$$msgref[$which]);
! 554: }
1.135 albertel 555: }
1.136 albertel 556: return ('ERROR',undef);
1.9 albertel 557: }
1.207 ! albertel 558: }
1.9 albertel 559:
1.10 albertel 560: sub decideoutput {
1.169 albertel 561: my ($award,$awarded,$awardmsg,$solved,$previous,$target)=@_;
1.135 albertel 562: my $message='';
563: my $button=0;
564: my $previousmsg;
565: my $bgcolor='orange';
1.148 albertel 566: my $added_computer_text=0;
1.135 albertel 567: my %possiblecolors =
1.201 albertel 568: ( 'correct' => '#aaffaa',
569: 'charged_try' => '#ffaaaa',
1.135 albertel 570: 'not_charged_try' => '#ffffaa',
1.201 albertel 571: 'no_grade' => '#ffffaa',
572: 'no_message' => '#ffffff',
1.135 albertel 573: );
1.169 albertel 574:
1.180 albertel 575: my $part = $Apache::inputtags::part;
576: my $handgrade =
577: ('yes' eq lc(&Apache::lonnet::EXT("resource.$part.handgrade")));
578:
579: my $computer = ($handgrade)? ''
1.203 www 580: : " ".&mt("Computer's answer now shown above.");
1.180 albertel 581: &Apache::lonxml::debug("handgrade has :$handgrade:");
582:
1.135 albertel 583: if ($previous) { $previousmsg=&mt('You have entered that answer before'); }
584:
1.194 banghart 585: if ($solved =~ /^correct/) {
586: $bgcolor=$possiblecolors{'correct'};
1.170 albertel 587: $message=&mt('You are correct.');
588: if ($awarded < 1 && $awarded > 0) {
589: $message=&mt('You are partially correct.');
590: $bgcolor=$possiblecolors{'not_charged_try'};
591: } elsif ($awarded < 1) {
592: $message=&mt('Incorrect.');
593: $bgcolor=$possiblecolors{'charged_try'};
594: }
1.172 albertel 595: if ($env{'request.filename'} =~
596: m|/res/lib/templates/examupload.problem$|) {
597: $message = &mt("A score has been assigned.");
598: $added_computer_text=1;
1.135 albertel 599: } else {
1.172 albertel 600: if ($target eq 'tex') {
601: $message = '\textbf{'.$message.'}';
602: } else {
603: $message = "<b>".$message."</b>";
1.180 albertel 604: $message.= $computer;
1.135 albertel 605: }
1.172 albertel 606: $added_computer_text=1;
1.165 albertel 607: unless ($env{'course.'.
608: $env{'request.course.id'}.
1.135 albertel 609: '.disable_receipt_display'} eq 'yes') {
610: $message.=(($target eq 'web')?'<br />':' ').
611: &mt('Your receipt is').' '.&Apache::lonnet::receipt($Apache::inputtags::part).
612: (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):'');
613: }
614: }
615: $button=0;
616: $previousmsg='';
617: } elsif ($solved =~ /^excused/) {
618: if ($target eq 'tex') {
619: $message = ' \textbf{'.&mt('You are excused from the problem.').'} ';
620: } else {
621: $message = "<b>".&mt('You are excused from the problem.')."</b>";
622: }
623: $bgcolor=$possiblecolors{'charged_try'};
624: $button=0;
625: $previousmsg='';
626: } elsif ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
627: if ($solved =~ /^incorrect/ || $solved eq '') {
1.144 albertel 628: $message = &mt("Incorrect").".";
1.135 albertel 629: $bgcolor=$possiblecolors{'charged_try'};
630: $button=1;
631: } else {
1.144 albertel 632: if ($target eq 'tex') {
633: $message = '\textbf{'.&mt('You are correct.').'}';
634: } else {
635: $message = "<b>".&mt('You are correct.')."</b>";
1.180 albertel 636: $message.= $computer;
1.144 albertel 637: }
1.148 albertel 638: $added_computer_text=1;
1.165 albertel 639: unless ($env{'course.'.
640: $env{'request.course.id'}.
1.135 albertel 641: '.disable_receipt_display'} eq 'yes') {
642: $message.=(($target eq 'web')?'<br />':' ').
643: 'Your receipt is '.&Apache::lonnet::receipt($Apache::inputtags::part).
644: (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):'');
645: }
646: $bgcolor=$possiblecolors{'correct'};
647: $button=0;
648: $previousmsg='';
649: }
650: } elsif ($award eq 'NO_RESPONSE') {
651: $message = '';
652: $bgcolor=$possiblecolors{'no_feedback'};
653: $button=1;
1.182 albertel 654: } elsif ($award eq 'EXTRA_ANSWER') {
655: $message = &mt('Some extra items were submitted.');
656: $bgcolor=$possiblecolors{'not_charged_try'};
657: $button = 1;
1.135 albertel 658: } elsif ($award eq 'MISSING_ANSWER') {
659: $message = &mt('Some items were not submitted.');
660: $bgcolor=$possiblecolors{'not_charged_try'};
661: $button = 1;
662: } elsif ($award eq 'ERROR') {
663: $message = &mt('An error occured while grading your answer.');
664: $bgcolor=$possiblecolors{'not_charged_try'};
665: $button = 1;
666: } elsif ($award eq 'TOO_LONG') {
667: $message = &mt("The submitted answer was too long.");
668: $bgcolor=$possiblecolors{'not_charged_try'};
669: $button=1;
670: } elsif ($award eq 'WANTED_NUMERIC') {
671: $message = &mt("This question expects a numeric answer.");
672: $bgcolor=$possiblecolors{'not_charged_try'};
673: $button=1;
674: } elsif ($award eq 'MISORDERED_RANK') {
675: $message = &mt('You have provided an invalid ranking');
676: if ($target ne 'tex') {
1.159 albertel 677: $message.=', '.&mt('please refer to').' '.&Apache::loncommon::help_open_topic('Ranking_Problems','help on ranking problems');
1.135 albertel 678: }
679: $bgcolor=$possiblecolors{'not_charged_try'};
680: $button=1;
681: } elsif ($award eq 'INVALID_FILETYPE') {
1.166 albertel 682: $message = &mt('Submission won\'t be graded. The type of file submitted is not allowed.');
1.135 albertel 683: $bgcolor=$possiblecolors{'not_charged_try'};
684: $button=1;
685: } elsif ($award eq 'SIG_FAIL') {
1.145 albertel 686: my ($used,$min,$max)=split(':',$awardmsg);
687: my $word;
688: if ($used < $min) { $word=&mt('more'); }
689: if ($used > $max) { $word=&mt('fewer'); }
690: $message = &mt("Submission not graded. Use [_2] digits.",$used,$word);
1.135 albertel 691: $bgcolor=$possiblecolors{'not_charged_try'};
692: $button=1;
1.137 albertel 693: } elsif ($award eq 'UNIT_INVALID_INSTRUCTOR') {
694: $message = &mt('Error in instructor specifed unit. This error has been reported to the instructor.', $awardmsg);
695: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');}
696: $bgcolor=$possiblecolors{'not_charged_try'};
697: $button=1;
698: } elsif ($award eq 'UNIT_INVALID_STUDENT') {
1.155 albertel 699: $message = &mt('Unable to interpret units. Computer reads units as "[_1]".',&markup_unit($awardmsg,$target));
1.137 albertel 700: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');}
701: $bgcolor=$possiblecolors{'not_charged_try'};
702: $button=1;
1.140 matthew 703: } elsif ($award eq 'UNIT_FAIL' || $award eq 'UNIT_IRRECONCIBLE') {
1.155 albertel 704: $message = &mt('Incompatible units. No conversion found between "[_1]" and the required units.',&markup_unit($awardmsg,$target));
1.136 albertel 705: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');}
1.135 albertel 706: $bgcolor=$possiblecolors{'not_charged_try'};
707: $button=1;
708: } elsif ($award eq 'UNIT_NOTNEEDED') {
1.155 albertel 709: $message = &mt('Only a number required. Computer reads units of "[_1]".',&markup_unit($awardmsg,$target));
1.135 albertel 710: $bgcolor=$possiblecolors{'not_charged_try'};
711: $button=1;
712: } elsif ($award eq 'NO_UNIT') {
1.144 albertel 713: $message = &mt("Units required").'.';
1.135 albertel 714: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units')};
715: $bgcolor=$possiblecolors{'not_charged_try'};
716: $button=1;
1.153 albertel 717: } elsif ($award eq 'COMMA_FAIL') {
718: $message = &mt("Proper comma separation is required").'.';
719: $bgcolor=$possiblecolors{'not_charged_try'};
720: $button=1;
1.135 albertel 721: } elsif ($award eq 'BAD_FORMULA') {
722: $message = &mt("Unable to understand formula");
723: $bgcolor=$possiblecolors{'not_charged_try'};
724: $button=1;
725: } elsif ($award eq 'INCORRECT') {
1.144 albertel 726: $message = &mt("Incorrect").'.';
1.135 albertel 727: $bgcolor=$possiblecolors{'charged_try'};
728: $button=1;
729: } elsif ($award eq 'SUBMITTED') {
730: $message = &mt("Your submission has been recorded.");
1.201 albertel 731: $bgcolor=$possiblecolors{'no_grade'};
1.135 albertel 732: $button=1;
733: } elsif ($award eq 'DRAFT') {
1.144 albertel 734: $message = &mt("A draft copy has been saved.");
1.135 albertel 735: $bgcolor=$possiblecolors{'not_charged_try'};
736: $button=1;
737: } elsif ($award eq 'ASSIGNED_SCORE') {
1.144 albertel 738: $message = &mt("A score has been assigned.");
1.135 albertel 739: $bgcolor=$possiblecolors{'correct'};
740: $button=0;
1.144 albertel 741: } elsif ($award eq '') {
1.186 albertel 742: if ($handgrade && $Apache::inputtags::status[-1] eq 'SHOW_ANSWER') {
743: $message = &mt("Nothing submitted.");
744: $bgcolor=$possiblecolors{'charged_try'};
745: } else {
746: $bgcolor=$possiblecolors{'not_charged_try'};
747: }
1.144 albertel 748: $button=1;
1.135 albertel 749: } else {
750: $message = &mt("Unknown message").": $award";
751: $button=1;
752: }
1.194 banghart 753: my (undef,undef,$domain,$user)=&Apache::lonxml::whichuser();
754: foreach my $resid(@Apache::inputtags::response){
755: if ($Apache::lonhomework::history{"resource.$part.$resid.handback"}) {
1.198 albertel 756: $message.='<br />';
757: my @files = split(/\s*,\s*/,
758: $Apache::lonhomework::history{"resource.$part.$resid.handback"});
759: my $file_msg;
760: foreach my $file (@files) {
761: $file_msg.= '<br /><a href="/uploaded/'."$domain/$user".'/'.$file.'">'.$file.'</a>';
762: }
763: $message .= &mt('Returned file(s): [_1]',$file_msg);
764: }
1.194 banghart 765: }
766:
1.135 albertel 767: if (lc($Apache::lonhomework::problemstatus) eq 'no' &&
768: $Apache::inputtags::status[-1] ne 'SHOW_ANSWER') {
769: $message = &mt("Answer Submitted: Your final submission will be graded after the due date.");
1.201 albertel 770: $bgcolor=$possiblecolors{'no_grade'};
1.135 albertel 771: $button=1;
772: }
1.148 albertel 773: if ($Apache::inputtags::status[-1] eq 'SHOW_ANSWER' &&
1.150 albertel 774: !$added_computer_text && $target ne 'tex') {
1.180 albertel 775: $message.= $computer;
1.148 albertel 776: $added_computer_text=1;
1.144 albertel 777: }
1.135 albertel 778: return ($button,$bgcolor,$message,$previousmsg);
1.12 albertel 779: }
780:
1.155 albertel 781: sub markup_unit {
782: my ($unit,$target)=@_;
783: if ($target eq 'tex') {
784: return '\texttt{'.&Apache::lonxml::latex_special_symbols($unit).'}';
785: } else {
786: return "<tt>".$unit."</tt>";
787: }
788: }
789:
1.88 albertel 790: sub removealldata {
1.87 albertel 791: my ($id)=@_;
792: foreach my $key (keys(%Apache::lonhomework::results)) {
793: if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
794: &Apache::lonxml::debug("Removing $key");
795: delete($Apache::lonhomework::results{$key});
796: }
797: }
798: }
799:
1.142 albertel 800: sub hidealldata {
801: my ($id)=@_;
802: foreach my $key (keys(%Apache::lonhomework::results)) {
803: if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
804: &Apache::lonxml::debug("Hidding $key");
805: my $newkey=$key;
806: $newkey=~s/^(resource\.\Q$id\E\.[^\.]+\.)(.*)$/${1}hidden${2}/;
807: $Apache::lonhomework::results{$newkey}=
808: $Apache::lonhomework::results{$key};
809: delete($Apache::lonhomework::results{$key});
810: }
811: }
812: }
813:
1.12 albertel 814: sub setgradedata {
1.136 albertel 815: my ($award,$msg,$id,$previously_used) = @_;
1.154 albertel 816: if ($Apache::lonhomework::scantronmode &&
1.165 albertel 817: &Apache::lonnet::validCODE($env{'form.CODE'})) {
818: $Apache::lonhomework::results{"resource.CODE"}=$env{'form.CODE'};
1.154 albertel 819: } elsif ($Apache::lonhomework::scantronmode &&
1.165 albertel 820: $env{'form.CODE'} eq '' &&
1.154 albertel 821: $Apache::lonhomework::history{"resource.CODE"} ne '') {
822: $Apache::lonhomework::results{"resource.CODE"}='';
1.141 albertel 823: }
1.154 albertel 824:
1.135 albertel 825: if (!$Apache::lonhomework::scantronmode &&
826: $Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
827: $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
828: $Apache::lonhomework::results{"resource.$id.afterduedate"}=$award;
1.87 albertel 829: return '';
1.135 albertel 830: } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~
831: /^correct/ || $Apache::lonhomework::scantronmode ||
832: lc($Apache::lonhomework::problemstatus) eq 'no') {
1.154 albertel 833: # the student doesn't already have it correct,
834: # or we are in a mode (scantron orno problem status) where a correct
835: # can become incorrect
836: # handle assignment of tries and solved status
1.135 albertel 837: my $solvemsg;
838: if ($Apache::lonhomework::scantronmode) {
839: $solvemsg='correct_by_scantron';
840: } else {
841: $solvemsg='correct_by_student';
842: }
843: if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
844: $Apache::lonhomework::results{"resource.$id.afterduedate"}='';
845: }
846: if ( $award eq 'ASSIGNED_SCORE') {
847: $Apache::lonhomework::results{"resource.$id.tries"} =
848: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
849: $Apache::lonhomework::results{"resource.$id.solved"} =
850: $solvemsg;
851: my $numawards=scalar(@Apache::inputtags::response);
852: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
853: foreach my $res (@Apache::inputtags::response) {
854: $Apache::lonhomework::results{"resource.$id.awarded"}+=
855: $Apache::lonhomework::results{"resource.$id.$res.awarded"};
856: }
857: if ($numawards > 0) {
858: $Apache::lonhomework::results{"resource.$id.awarded"}/=
859: $numawards;
860: }
861: } elsif ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
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: $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
867: } elsif ( $award eq 'INCORRECT' ) {
868: $Apache::lonhomework::results{"resource.$id.tries"} =
869: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1.152 albertel 870: if (lc($Apache::lonhomework::problemstatus) eq 'no' ||
871: $Apache::lonhomework::scantronmode) {
1.135 albertel 872: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
873: }
874: $Apache::lonhomework::results{"resource.$id.solved"} =
875: 'incorrect_attempted';
876: } elsif ( $award eq 'SUBMITTED' ) {
877: $Apache::lonhomework::results{"resource.$id.tries"} =
878: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
879: $Apache::lonhomework::results{"resource.$id.solved"} =
880: 'ungraded_attempted';
881: } elsif ( $award eq 'DRAFT' ) {
882: $Apache::lonhomework::results{"resource.$id.solved"} = '';
883: } elsif ( $award eq 'NO_RESPONSE' ) {
884: #no real response so delete any data that got stored
1.129 albertel 885: &removealldata($id);
886: return '';
887: } else {
1.135 albertel 888: $Apache::lonhomework::results{"resource.$id.solved"} =
889: 'incorrect_attempted';
1.152 albertel 890: if (lc($Apache::lonhomework::problemstatus) eq 'no' ||
891: $Apache::lonhomework::scantronmode) {
1.135 albertel 892: $Apache::lonhomework::results{"resource.$id.tries"} =
893: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
894: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
895: }
896: }
1.136 albertel 897: if (defined($msg)) {
898: $Apache::lonhomework::results{"resource.$id.awardmsg"} = $msg;
899: }
1.135 albertel 900: # did either of the overall awards chage? If so ignore the
901: # previous check
902: if (($Apache::lonhomework::results{"resource.$id.awarded"} eq
903: $Apache::lonhomework::history{"resource.$id.awarded"}) &&
904: ($Apache::lonhomework::results{"resource.$id.solved"} eq
905: $Apache::lonhomework::history{"resource.$id.solved"})) {
906: # check if this was a previous submission if it was delete the
907: # unneeded data and update the previously_used attribute
908: if ( $previously_used eq 'PREVIOUSLY_USED') {
909: if (lc($Apache::lonhomework::problemstatus) ne 'no') {
910: delete($Apache::lonhomework::results{"resource.$id.tries"});
911: $Apache::lonhomework::results{"resource.$id.previous"} = '1';
912: }
913: } elsif ( $previously_used eq 'PREVIOUSLY_LAST') {
914: #delete all data as they student didn't do anything, but save
915: #the list of collaborators.
916: &removealldata($id);
917: #and since they didn't do anything we were never here
918: return '';
919: } else {
920: $Apache::lonhomework::results{"resource.$id.previous"} = '0';
921: }
1.101 albertel 922: }
1.135 albertel 923: } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} =~
924: /^correct/ ) {
925: #delete all data as they student already has it correct
926: &removealldata($id);
927: #and since they didn't do anything we were never here
928: return '';
1.40 albertel 929: }
1.135 albertel 930: $Apache::lonhomework::results{"resource.$id.award"} = $award;
1.184 albertel 931: if ($award eq 'SUBMITTED') {
932: &Apache::response::add_to_gradingqueue();
933: }
1.10 albertel 934: }
935:
1.9 albertel 936: sub grade {
1.135 albertel 937: my ($target) = @_;
938: my $id = $Apache::inputtags::part;
939: my $response='';
1.165 albertel 940: if ( defined $env{'form.submitted'}) {
1.136 albertel 941: my (@awards,@msgs);
1.135 albertel 942: foreach $response (@Apache::inputtags::response) {
943: &Apache::lonxml::debug("looking for response.$id.$response.awarddetail");
944: my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"};
945: &Apache::lonxml::debug("keeping $value from $response for $id");
946: push (@awards,$value);
1.136 albertel 947: $value=$Apache::lonhomework::results{"resource.$id.$response.awardmsg"};
948: &Apache::lonxml::debug("got message $value from $response for $id");
949: push (@msgs,$value);
1.135 albertel 950: }
1.136 albertel 951: my ($finalaward,$msg) = &finalizeawards(\@awards,\@msgs);
1.135 albertel 952: my $previously_used;
953: if ( $#Apache::inputtags::previous eq $#awards ) {
954: my $match=0;
955: my @matches;
956: foreach my $versionar (@Apache::inputtags::previous_version) {
957: foreach my $version (@$versionar) {
958: $matches[$version]++;
959: }
960: }
961: foreach my $elem (@matches) {if ($elem eq ($#awards+1)) {$match=1;}}
962: if ($match) {
963: $previously_used = 'PREVIOUSLY_LAST';
964: foreach my $value (@Apache::inputtags::previous) {
965: if ($value eq 'PREVIOUSLY_USED' ) {
966: $previously_used = $value;
967: last;
968: }
1.75 albertel 969: }
970: }
1.43 albertel 971: }
1.136 albertel 972: &Apache::lonxml::debug("final award $finalaward, $previously_used, message $msg");
973: &setgradedata($finalaward,$msg,$id,$previously_used);
1.43 albertel 974: }
1.135 albertel 975: return '';
1.1 albertel 976: }
977:
1.11 albertel 978: sub gradestatus {
1.135 albertel 979: my ($id,$target) = @_;
980: my $showbutton = 1;
981: my $bgcolor = '';
982: my $message = '';
983: my $latemessage = '';
984: my $trystr='';
985: my $button='';
986: my $previousmsg='';
987:
988: my $status = $Apache::inputtags::status['-1'];
989: &Apache::lonxml::debug("gradestatus has :$status:");
1.183 albertel 990: if ( $status ne 'CLOSED'
991: && $status ne 'UNAVAILABLE'
992: && $status ne 'INVALID_ACCESS'
993: && $status ne 'NEEDS_CHECKIN'
994: && $status ne 'NOT_IN_A_SLOT') {
1.135 albertel 995: my $award = $Apache::lonhomework::history{"resource.$id.award"};
1.169 albertel 996: my $awarded = $Apache::lonhomework::history{"resource.$id.awarded"};
1.135 albertel 997: my $solved = $Apache::lonhomework::history{"resource.$id.solved"};
998: my $previous = $Apache::lonhomework::history{"resource.$id.previous"};
1.136 albertel 999: my $awardmsg = $Apache::lonhomework::history{"resource.$id.awardmsg"};
1000: &Apache::lonxml::debug("Found Award |$award|$solved|$awardmsg");
1.144 albertel 1001: if ( $award ne '' || $solved ne '' || $status eq 'SHOW_ANSWER') {
1.135 albertel 1002: &Apache::lonxml::debug('Getting message');
1003: ($showbutton,$bgcolor,$message,$previousmsg) =
1.169 albertel 1004: &decideoutput($award,$awarded,$awardmsg,$solved,$previous,
1005: $target);
1.135 albertel 1006: if ($target eq 'tex') {
1007: $message='\vskip 2 mm '.$message.' ';
1008: } else {
1009: $message="<td bgcolor=\"$bgcolor\">$message</td>";
1010: if ($previousmsg) {
1011: $previousmsg="<td bgcolor=\"#aaaaff\">$previousmsg</td>";
1012: }
1013: }
1014: }
1015: my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
1016: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
1017: &Apache::lonxml::debug("got maxtries of :$maxtries:");
1018: #if tries are set to negative turn off the Tries/Button and messages
1019: if (defined($maxtries) && $maxtries < 0) { return ''; }
1020: if ( $tries eq '' ) { $tries = '0'; }
1021: if ( $maxtries eq '' ) { $maxtries = '2'; }
1022: if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; }
1023: my $tries_text=&mt('Tries');
1.164 albertel 1024: if ( $Apache::lonhomework::type eq 'survey' ||
1025: $Apache::lonhomework::parsing_a_task) {
1026: $tries_text=&mt('Submissions');
1027: }
1.135 albertel 1028: if ( $showbutton ) {
1029: if ($target eq 'tex') {
1.165 albertel 1030: if ($env{'request.state'} ne "construct" && $Apache::lonhomework::type ne 'exam' && $env{'form.suppress_tries'} ne 'yes') {
1.135 albertel 1031: $trystr = ' {\vskip 1 mm \small \textit{'.$tries_text.'} '.$tries.'/'.$maxtries.'} \vskip 2 mm ';
1032: } else {
1033: $trystr = '\vskip 0 mm ';
1034: }
1035: } else {
1.136 albertel 1036: $trystr = "<td><nobr>".$tries_text." $tries";
1.164 albertel 1037: if ($Apache::lonhomework::parsing_a_task) {
1.165 albertel 1038: } elsif($env{'request.state'} ne 'construct') {
1.135 albertel 1039: $trystr.="/$maxtries";
1040: } else {
1041: if (defined($Apache::inputtags::params{'maxtries'})) {
1042: $trystr.="/".$Apache::inputtags::params{'maxtries'};
1043: }
1044: }
1.136 albertel 1045: $trystr.="</nobr></td>";
1.135 albertel 1046: }
1047: }
1048: if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
1049: if ( $showbutton ) {
1050: if ($target ne 'tex') {
1.156 albertel 1051: $button = '<input type="submit" name="submit_'.$id.'" value="'.&mt('Submit Answer').'" />';
1.135 albertel 1052: }
1053: }
1054: if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
1055: #last submissions was after due date
1.163 albertel 1056: $latemessage=&mt(' The last submission was after the Due Date ');;
1057: if ($target eq 'web') {
1058: $latemessage='<td bgcolor="#ffaaaa">'.$latemessage.'</td>';
1.135 albertel 1059: }
1060: }
1061: }
1062: my $output= $previousmsg.$latemessage.$message.$trystr;
1063: if ($output =~ /^\s*$/) {
1064: return $button;
1.63 sakharuk 1065: } else {
1.135 albertel 1066: if ($target eq 'tex') {
1067: return $button.' \vskip 0 mm '.$output.' ';
1068: } else {
1069: return '<table><tr><td>'.$button.'</td>'.$output.'</tr></table>';
1070: }
1.63 sakharuk 1071: }
1.11 albertel 1072: }
1.1 albertel 1073: 1;
1074: __END__
1.43 albertel 1075:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>