Annotation of loncom/homework/inputtags.pm, revision 1.272
1.43 albertel 1: # The LearningOnline Network with CAPA
2: # input definitons
1.47 albertel 3: #
1.272 ! www 4: # $Id: inputtags.pm,v 1.271 2010/09/05 20:57:42 raeburn 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:
1.249 jms 28: =pod
29:
30: =head1 NAME
31:
32: Apache::inputtags
33:
34: =head1 SYNOPSIS
35:
36:
37:
38: This is part of the LearningOnline Network with CAPA project
39: described at http://www.lon-capa.org.
40:
41:
42: =head1 NOTABLE SUBROUTINES
43:
44: =over
45:
46: =item
47:
48: =back
49:
50: =cut
51:
1.1 albertel 52: package Apache::inputtags;
1.55 albertel 53: use HTML::Entities();
1.1 albertel 54: use strict;
1.82 www 55: use Apache::loncommon;
1.265 raeburn 56: use Apache::lonhtmlcommon;
1.115 www 57: use Apache::lonlocal;
1.165 albertel 58: use Apache::lonnet;
1.192 www 59: use LONCAPA;
60:
1.1 albertel 61:
1.50 harris41 62: BEGIN {
1.135 albertel 63: &Apache::lonxml::register('Apache::inputtags',('hiddenline','textfield','textline'));
1.1 albertel 64: }
65:
1.249 jms 66: =pod
67:
68: =item initialize_inputtags()
69:
70: Initializes a set of global variables used during the parse of the problem.
71:
72: @Apache::inputtags::input - List of current input ids.
73: @Apache::inputtags::inputlist - List of all input ids seen this problem.
74: @Apache::inputtags::response - List of all current resopnse ids.
75: @Apache::inputtags::responselist - List of all response ids seen this
76: problem.
77: @Apache::inputtags::hint - List of all hint ids.
78: @Apache::inputtags::hintlist - List of all hint ids seen this problem.
79: @Apache::inputtags::previous - List describing if specific responseds
80: have been used
81: @Apache::inputtags::previous_version - Submission responses were used in.
82: $Apache::inputtags::part - Current part id (valid only in
83: <problem>)
84: 0 if not in a part.
85: @Apache::inputtags::partlist - List of part ids seen in the current
86: <problem>
87: @Apache::inputtags::status - List of problem statuses. First
88: element is the status of the <problem>
89: the remainder are for individual <part>s.
90: %Apache::inputtags::params - Hash of defined parameters for the
91: current response.
92: @Apache::inputtags::import - List of all ids for <import> thes get
93: join()ed and prepended.
94: @Apache::inputtags::importlist - List of all import ids seen.
95: $Apache::inputtags::response_with_no_part
96: - Flag set true if we have seen a response
97: that is not inside a <part>
98: %Apache::inputtags::answertxt - <*response> tags store correct
99: answer strings for display by <textline/>
100: in this hash.
101: %Apache::inputtags::submission_display
102: - <*response> tags store improved display
103: of submission strings for display by part
104: end.
105:
106: =cut
1.178 albertel 107:
1.1 albertel 108: sub initialize_inputtags {
1.135 albertel 109: @Apache::inputtags::input=();
110: @Apache::inputtags::inputlist=();
1.174 albertel 111: @Apache::inputtags::response=();
1.135 albertel 112: @Apache::inputtags::responselist=();
1.174 albertel 113: @Apache::inputtags::hint=();
1.173 albertel 114: @Apache::inputtags::hintlist=();
1.135 albertel 115: @Apache::inputtags::previous=();
116: @Apache::inputtags::previous_version=();
117: $Apache::inputtags::part='';
118: @Apache::inputtags::partlist=();
119: @Apache::inputtags::status=();
120: %Apache::inputtags::params=();
121: @Apache::inputtags::import=();
122: @Apache::inputtags::importlist=();
123: $Apache::inputtags::response_with_no_part=0;
1.144 albertel 124: %Apache::inputtags::answertxt=();
1.217 albertel 125: %Apache::inputtags::submission_display=();
1.103 albertel 126: }
127:
128: sub check_for_duplicate_ids {
129: my %check;
130: foreach my $id (@Apache::inputtags::partlist,
131: @Apache::inputtags::responselist,
1.173 albertel 132: @Apache::inputtags::hintlist,
1.103 albertel 133: @Apache::inputtags::importlist) {
134: $check{$id}++;
135: }
136: my @duplicates;
137: foreach my $id (sort(keys(%check))) {
138: if ($check{$id} > 1) {
139: push(@duplicates,$id);
140: }
141: }
142: if (@duplicates) {
143: &Apache::lonxml::error("Duplicated ids found, problem will operate incorrectly. Duplicated ids seen: ",join(', ',@duplicates));
144: }
1.1 albertel 145: }
146:
1.14 albertel 147: sub start_input {
1.135 albertel 148: my ($parstack,$safeeval)=@_;
1.228 albertel 149: my $id = &Apache::lonxml::get_id($parstack,$safeeval);
1.135 albertel 150: push (@Apache::inputtags::input,$id);
151: push (@Apache::inputtags::inputlist,$id);
152: return $id;
1.14 albertel 153: }
154:
155: sub end_input {
1.135 albertel 156: pop @Apache::inputtags::input;
157: return '';
1.14 albertel 158: }
159:
1.124 www 160: sub addchars {
161: my ($fieldid,$addchars)=@_;
162: my $output='';
163: foreach (split(/\,/,$addchars)) {
164: $output.='<a href="javascript:void(document.forms.lonhomework.'.
165: $fieldid.'.value+=\''.$_.'\')">'.$_.'</a> ';
166: }
167: return $output;
168: }
169:
1.48 albertel 170: sub start_textfield {
1.185 albertel 171: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.135 albertel 172: my $result = "";
173: my $id = &start_input($parstack,$safeeval);
174: my $resid=$Apache::inputtags::response[-1];
175: if ($target eq 'web') {
176: $Apache::lonxml::evaluate--;
1.205 albertel 177: my $partid=$Apache::inputtags::part;
178: my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$resid.submission"},'<>&"');
1.135 albertel 179: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
180: my $cols = &Apache::lonxml::get_param('cols',$parstack,$safeeval);
181: if ( $cols eq '') { $cols = 80; }
182: my $rows = &Apache::lonxml::get_param('rows',$parstack,$safeeval);
1.143 www 183: if ( $rows eq '') { $rows = 16; }
1.135 albertel 184: my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval);
185: $result='';
186: if ($addchars) {
187: $result.=&addchars('HWVAL_'.$resid,$addchars);
188: }
1.266 raeburn 189: my $textareaclass = 'class="LC_richDetectHtml"';
1.143 www 190: $result.= '<textarea wrap="hard" name="HWVAL_'.$resid.'" id="HWVAL_'.$resid.'" '.
1.266 raeburn 191: 'rows="'.$rows.'" cols="'.$cols.'" '.$textareaclass.'>'.
192: $oldresponse;
1.135 albertel 193: if ($oldresponse ne '') {
1.143 www 194:
1.135 albertel 195: #get rid of any startup text if the user has already responded
1.185 albertel 196: &Apache::lonxml::get_all_text("/textfield",$parser,$style);
1.135 albertel 197: }
198: } else {
1.205 albertel 199: #show past answer in the essayresponse case
200: if ($oldresponse =~ /\S/
201: && &Apache::londefdef::is_inside_of($tagstack,
202: 'essayresponse') ) {
203: $result='<table class="LC_pastsubmission"><tr><td>'.
204: $oldresponse.'</td></tr></table>';
205: }
1.135 albertel 206: #get rid of any startup text
1.185 albertel 207: &Apache::lonxml::get_all_text("/textfield",$parser,$style);
1.61 albertel 208: }
1.135 albertel 209: } elsif ($target eq 'grade') {
1.185 albertel 210: my $seedtext=&Apache::lonxml::get_all_text("/textfield",$parser,
211: $style);
1.165 albertel 212: if ($seedtext eq $env{'form.HWVAL_'.$resid}) {
1.135 albertel 213: # if the seed text is still there it wasn't a real submission
1.165 albertel 214: $env{'form.HWVAL_'.$resid}='';
1.135 albertel 215: }
216: } elsif ($target eq 'edit') {
217: $result.=&Apache::edit::tag_start($target,$token);
218: $result.=&Apache::edit::text_arg('Rows:','rows',$token,4);
219: $result.=&Apache::edit::text_arg('Columns:','cols',$token,4);
220: $result.=&Apache::edit::text_arg
221: ('Click-On Texts (comma sep):','addchars',$token,10);
1.185 albertel 222: my $bodytext=&Apache::lonxml::get_all_text("/textfield",$parser,
223: $style);
1.135 albertel 224: $result.=&Apache::edit::editfield($token->[1],$bodytext,'Text you want to appear by default:',80,2);
225: } elsif ($target eq 'modified') {
226: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
227: $safeeval,'rows','cols',
228: 'addchars');
229: if ($constructtag) {
230: $result = &Apache::edit::rebuild_tag($token);
231: } else {
232: $result=$token->[4];
233: }
234: $result.=&Apache::edit::modifiedfield("/textfield",$parser);
235: } elsif ($target eq 'tex') {
236: my $number_of_lines = &Apache::lonxml::get_param('rows',$parstack,$safeeval);
237: my $width_of_box = &Apache::lonxml::get_param('cols',$parstack,$safeeval);
238: if ($$tagstack[-2] eq 'essayresponse' and $Apache::lonhomework::type eq 'exam') {
239: $result = '\fbox{\fbox{\parbox{\textwidth-5mm}{';
240: for (my $i=0;$i<int $number_of_lines*2;$i++) {$result.='\strut \\\\ ';}
241: $result.='\strut \\\\\strut \\\\\strut \\\\\strut \\\\}}}';
242: } else {
243: my $TeXwidth=$width_of_box/80;
244: $result = '\vskip 1 mm \fbox{\fbox{\parbox{'.$TeXwidth.'\textwidth-5mm}{';
245: for (my $i=0;$i<int $number_of_lines*2;$i++) {$result.='\strut \\\\ ';}
246: $result.='}}}\vskip 2 mm ';
247: }
1.60 albertel 248: }
1.135 albertel 249: return $result;
1.6 albertel 250: }
251:
1.48 albertel 252: sub end_textfield {
1.135 albertel 253: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
254: my $result;
255: if ($target eq 'web') {
256: $Apache::lonxml::evaluate++;
257: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
258: return "</textarea>";
259: }
260: } elsif ($target eq 'edit') {
261: $result=&Apache::edit::end_table();
262: }
263: &end_input;
264: return $result;
1.6 albertel 265: }
266:
1.190 albertel 267: sub exam_score_line {
1.188 albertel 268: my ($target) = @_;
1.190 albertel 269:
1.188 albertel 270: my $result;
271: if ($target eq 'tex') {
272: my $repetition = &Apache::response::repetition();
273: $result.='\begin{enumerate}';
1.190 albertel 274: if ($env{'request.state'} eq "construct" ) {$result.='\item[\strut]';}
1.188 albertel 275: foreach my $i (0..$repetition-1) {
276: $result.='\item[\textbf{'.
277: ($Apache::lonxml::counter+$i).
278: '}.]\textit{Leave blank on scoring form}\vskip 0 mm';
279: }
280: $result.= '\end{enumerate}';
1.190 albertel 281: }
282:
283: return $result;
284: }
285:
286: sub exam_box {
287: my ($target) = @_;
288: my $result;
1.188 albertel 289:
1.190 albertel 290: if ($target eq 'tex') {
291: $result .= '\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}';
292: $result .= &exam_score_line($target);
1.188 albertel 293: } elsif ($target eq 'web') {
294: my $id=$Apache::inputtags::response[-1];
295: $result.= '<br /><br />
296: <textarea name="HWVAL_'.$id.'" rows="4" cols="50">
297: </textarea> <br /><br />';
298: }
299: return $result;
300: }
301:
302: sub needs_exam_box {
303: my ($tagstack) = @_;
304: my @tags = ('formularesponse',
305: 'stringresponse',
306: 'reactionresponse',
307: 'organicresponse',
308: );
309:
310: foreach my $tag (@tags) {
311: if (grep(/\Q$tag\E/,@$tagstack)) {
312: return 1;
313: }
314: }
315: return 0;
316: }
317:
1.1 albertel 318: sub start_textline {
1.135 albertel 319: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
320: my $result = "";
1.210 albertel 321: my $input_id = &start_input($parstack,$safeeval);
1.135 albertel 322: if ($target eq 'web') {
323: $Apache::lonxml::evaluate--;
324: my $partid=$Apache::inputtags::part;
325: my $id=$Apache::inputtags::response[-1];
1.204 albertel 326: if (!&Apache::response::show_answer()) {
1.135 albertel 327: my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
328: my $maxlength;
329: if ($size eq '') { $size=20; } else {
1.214 albertel 330: if ($size < 20) {
331: $maxlength = ' maxlength="'.$size.'"';
332: }
1.135 albertel 333: }
1.210 albertel 334: my $oldresponse = $Apache::lonhomework::history{"resource.$partid.$id.submission"};
335: &Apache::lonxml::debug("oldresponse $oldresponse is ".ref($oldresponse));
336:
337: if (ref($oldresponse) eq 'ARRAY') {
338: $oldresponse = $oldresponse->[$#Apache::inputtags::inputlist];
339: }
340: $oldresponse = &HTML::Entities::encode($oldresponse,'<>&"');
1.241 www 341: $oldresponse =~ s/^\s+//;
342: $oldresponse =~ s/\s+$//;
343: $oldresponse =~ s/\s+/ /g;
1.135 albertel 344: if ($Apache::lonhomework::type ne 'exam') {
345: my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval);
346: $result='';
347: if ($addchars) {
348: $result.=&addchars('HWVAL_'.$id,$addchars);
349: }
1.157 albertel 350: my $readonly=&Apache::lonxml::get_param('readonly',$parstack,
351: $safeeval);
1.193 albertel 352: if (lc($readonly) eq 'yes'
353: || $Apache::inputtags::status[-1] eq 'CANNOT_ANSWER') {
1.157 albertel 354: $readonly=' readonly="readonly" ';
1.158 albertel 355: } else {
356: $readonly='';
1.157 albertel 357: }
1.193 albertel 358: my $name = 'HWVAL_'.$id;
359: if ($Apache::inputtags::status[-1] eq 'CANNOT_ANSWER') {
360: $name = "none";
361: }
1.214 albertel 362: $result.= '<input onkeydown="javascript:setSubmittedPart(\''.$partid.'\');" type="text" '.$readonly.' name="'.$name.'" value="'.
363: $oldresponse.'" size="'.$size.'"'.$maxlength.' />';
1.135 albertel 364: }
1.188 albertel 365: if ($Apache::lonhomework::type eq 'exam'
366: && &needs_exam_box($tagstack)) {
367: $result.=&exam_box($target);
368: }
1.135 albertel 369: } else {
370: #right or wrong don't show what was last typed in.
1.208 albertel 371: my $count = scalar(@Apache::inputtags::inputlist)-1;
372: $result='<b>'.$Apache::inputtags::answertxt{$id}[$count].'</b>';
1.144 albertel 373: #$result='';
1.135 albertel 374: }
375: } elsif ($target eq 'edit') {
376: $result=&Apache::edit::tag_start($target,$token);
377: $result.=&Apache::edit::text_arg('Size:','size',$token,'5').
1.157 albertel 378: &Apache::edit::text_arg('Click-On Texts (comma sep):',
379: 'addchars',$token,10);
380: $result.=&Apache::edit::select_arg('Readonly:','readonly',
381: ['no','yes'],$token);
382: $result.=&Apache::edit::end_row();
383: $result.=&Apache::edit::end_table();
1.135 albertel 384: } elsif ($target eq 'modified') {
1.157 albertel 385: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
386: $safeeval,'size',
387: 'addchars','readonly');
1.135 albertel 388: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.188 albertel 389: } elsif ($target eq 'tex'
390: && $Apache::lonhomework::type ne 'exam') {
1.135 albertel 391: my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
392: if ($size != 0) {$size=$size*2; $size.=' mm';} else {$size='40 mm';}
1.257 onken 393: if ($env{'form.pdfFormFields'} eq 'yes'
394: && $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
1.246 onken 395: my $fieldname = $env{'request.symb'}.
396: '&part_'. $Apache::inputtags::part.
397: '&textresponse'.
398: '&HWVAL_' . $Apache::inputtags::response['-1'];
1.259 onken 399: $result='\textField{'.$fieldname.'}{'.$size.'}{12 bp}';
1.246 onken 400: } else {
401: $result='\framebox['.$size.'][s]{\tiny\strut}';
402: }
1.188 albertel 403: } elsif ($target eq 'tex'
404: && $Apache::lonhomework::type eq 'exam'
405: && &needs_exam_box($tagstack)) {
406: $result.=&exam_box($target);
1.135 albertel 407: }
408: return $result;
1.1 albertel 409: }
410:
411: sub end_textline {
1.135 albertel 412: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
413: if ($target eq 'web') { $Apache::lonxml::evaluate++; }
414: elsif ($target eq 'edit') { return ('','no'); }
1.208 albertel 415: &end_input();
1.135 albertel 416: return "";
1.9 albertel 417: }
418:
1.98 albertel 419: sub start_hiddenline {
420: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
421: my $result = "";
1.211 albertel 422: my $input_id = &start_input($parstack,$safeeval);
1.98 albertel 423: if ($target eq 'web') {
424: $Apache::lonxml::evaluate--;
425: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
426: my $partid=$Apache::inputtags::part;
427: my $id=$Apache::inputtags::response[-1];
1.211 albertel 428: my $oldresponse = $Apache::lonhomework::history{"resource.$partid.$id.submission"};
429: if (ref($oldresponse) eq 'ARRAY') {
430: $oldresponse = $oldresponse->[$#Apache::inputtags::inputlist];
431: }
432: $oldresponse = &HTML::Entities::encode($oldresponse,'<>&"');
433:
1.98 albertel 434: if ($Apache::lonhomework::type ne 'exam') {
435: $result= '<input type="hidden" name="HWVAL_'.$id.'" value="'.
436: $oldresponse.'" />';
437: }
438: }
439: } elsif ($target eq 'edit') {
440: $result=&Apache::edit::tag_start($target,$token);
441: $result.=&Apache::edit::end_table;
442: }
1.189 albertel 443:
444: if ( ($target eq 'web' || $target eq 'tex')
445: && $Apache::lonhomework::type eq 'exam'
446: && &needs_exam_box($tagstack)) {
447: $result.=&exam_box($target);
448: }
1.98 albertel 449: return $result;
450: }
451:
452: sub end_hiddenline {
1.135 albertel 453: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
454: if ($target eq 'web') { $Apache::lonxml::evaluate++; }
455: elsif ($target eq 'edit') { return ('','no'); }
1.211 albertel 456: &end_input();
1.135 albertel 457: return "";
1.98 albertel 458: }
459:
1.249 jms 460: =pod
461:
462: =item file_selector()
463:
464: $part -> partid
465: $id -> responseid
466: $uploadefiletypes -> comma seperated list of extensions allowed or * for any
1.252 raeburn 467: $which -> 'uploadonly' -> only newly uploaded files
1.249 jms 468: 'portfolioonly' -> only allow files from portfolio
469: 'both' -> allow files from either location
470: $extratext -> additional text to go between the link and the input box
1.252 raeburn 471: $maxfilesize -> maximum cumulative filesize for submitted files (in MB).
1.249 jms 472: returns a table row <tr>
473:
474: =cut
475:
1.160 albertel 476: sub file_selector {
1.252 raeburn 477: my ($part,$id,$uploadedfiletypes,$which,$extratext,$maxfilesize)=@_;
1.160 albertel 478: if (!$uploadedfiletypes) { return ''; }
1.167 albertel 479:
480: my $jspart=$part;
481: $jspart=~s/\./_/g;
482:
1.160 albertel 483: my $result;
1.265 raeburn 484: my $current_files_display = ¤t_file_submissions($part,$id);
485: my $addfiles;
486: if ($current_files_display) {
1.268 raeburn 487: $result .= &Apache::lonhtmlcommon::row_title(&mt('Currently submitted files')).
1.265 raeburn 488: $current_files_display.
489: &Apache::lonhtmlcommon::row_closure();
490: $addfiles = &mt('Submit other file(s)');
491: } else {
492: $addfiles = &mt('Choose file(s) to submit');
493: }
494: $result .= &Apache::lonhtmlcommon::row_title($addfiles);
495: my $constraints;
496: if ($uploadedfiletypes ne '*') {
497: $constraints =
498: &mt('Allowed filetypes: [_1]','<b>'.$uploadedfiletypes.'</b>').'<br />';
499: }
500: if ($maxfilesize) {
501: $constraints .= &mt('Combined size of all files not to exceed: [_1] MB[_2].',
502: '<b>'.$maxfilesize.'</b>').'<br />';
503: }
504: if ($constraints) {
505: $result .= $constraints.'<br />';
1.162 albertel 506: }
1.160 albertel 507: if ($which eq 'uploadonly' || $which eq 'both') {
1.265 raeburn 508: $result.=&mt('Submit a file: (only one file per submission)').
1.160 albertel 509: ' <br /><input type="file" size="50" name="HWFILE'.
1.167 albertel 510: $jspart.'_'.$id.'" /><br />';
1.160 albertel 511: }
1.265 raeburn 512: if ( $which eq 'both') {
1.160 albertel 513: $result.='<br />'.'<strong>'.&mt('OR:').'</strong><br />';
514: }
515: if ($which eq 'portfolioonly' || $which eq 'both') {
1.227 albertel 516: $result.=$extratext.'<a href='."'".'javascript:void(window.open("/adm/portfolio?mode=selectfile&fieldname='.$env{'form.request.prefix'}.'HWPORT'.$jspart.'_'.$id.'","cat","height=600,width=800,scrollbars=1,resizable=1,menubar=2,location=1"))'."'".'>'.
1.265 raeburn 517: &mt('Select Portfolio Files: (one or more files per submission)').'</a><br />'.
1.167 albertel 518: '<input type="text" size="50" name="HWPORT'.$jspart.'_'.$id.'" value="" />'.
1.160 albertel 519: '<br />';
1.265 raeburn 520:
1.160 albertel 521: }
1.265 raeburn 522: $result.=&Apache::lonhtmlcommon::row_closure(1);
1.160 albertel 523: return $result;
524: }
525:
1.265 raeburn 526: sub current_file_submissions {
1.205 albertel 527: my ($part,$id) = @_;
1.265 raeburn 528: my $jspart=$part;
529: $jspart=~s/\./_/g;
1.270 raeburn 530: my $uploadedfile=$Apache::lonhomework::history{"resource.$part.$id.uploadedfile"};
1.265 raeburn 531: my $portfiles=$Apache::lonhomework::history{"resource.$part.$id.portfiles"};
532: return if (($uploadedfile eq '') && ($portfiles !~/[^\s]/));
533: my $header = &Apache::loncommon::start_data_table().
1.270 raeburn 534: &Apache::loncommon::start_data_table_header_row();
535: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
536: $header .= '<th>'.&mt('Delete?').'</th>';
537: }
1.271 raeburn 538: $header .= '<th>'.&mt('File').'</th>'.
1.265 raeburn 539: '<th>'.&mt('Size (MB)').'</th>'.
540: '<th>'.&mt('Last Modified').'</th>'.
541: &Apache::loncommon::end_data_table_header_row();
542: my (undef,$crsid,$udom,$uname)=&Apache::lonnet::whichuser();
543: my ($cdom,$cnum) = ($crsid =~ /^($LONCAPA::match_domain)_($LONCAPA::match_courseid)$/);
1.271 raeburn 544: my ($result,$header_shown,%okfiles,%rows,%legacy,@bad_file_list);
1.265 raeburn 545: if ($uploadedfile) {
546: my $url=$Apache::lonhomework::history{"resource.$part.$id.uploadedurl"};
1.270 raeburn 547: my $link = &HTML::Entities::encode($url,'<>&"');
548: my ($path,$name) = ($url =~ m{^(/uploaded/\Q$udom\E/\Q$uname\E/essayresponse.*/)([^/]+)$});
1.265 raeburn 549: my ($status,$hashref,$error) =
1.270 raeburn 550: ¤t_file_info($url,$link,$name,$path);
1.265 raeburn 551: if ($status eq 'ok') {
552: push(@{$okfiles{$name}},$url);
553: $rows{$url} = $hashref;
1.271 raeburn 554: $legacy{$url} = 1;
1.265 raeburn 555: &Apache::lonxml::extlink($url);
556: &Apache::lonnet::allowuploaded('/adm/essayresponse',$url);
557: } else {
558: push(@bad_file_list,$error);
559: }
560: }
561: if ($portfiles =~ /[^\s]/) {
562: my $prefix = "/uploaded/$udom/$uname/portfolio";
563: foreach my $file (split(/\s*,\s*/,&unescape($portfiles))) {
564: my ($path,$name) = ($file =~ m{^(.*/)([^/]+)$});
565: my $url = $prefix.$path.$name;
566: my $uploadedfile = &HTML::Entities::encode($url,'<>&"');
567: my ($status,$hashref,$error) =
568: ¤t_file_info($url,$uploadedfile,$name,$path);
569: if ($status eq 'ok') {
570: push(@{$okfiles{$name}},$url);
571: $rows{$url} = $hashref;
572: } else {
573: push(@bad_file_list,$error);
574: }
575: }
576: }
577: foreach my $name (sort(keys(%okfiles))) {
578: if (ref($okfiles{$name}) eq 'ARRAY') {
579: foreach my $url (@{$okfiles{$name}}) {
580: if (ref($rows{$url}) eq 'HASH') {
581: my $link = $rows{$url}{link};
582: my $portfile = $rows{$url}{path}.$rows{$url}{name};
583: $portfile = &HTML::Entities::encode($portfile,'<>&"');
584: if ($link) {
585: my $icon=&Apache::loncommon::icon($url);
586: unless ($header_shown) {
587: $result .= $header;
588: $header_shown = 1;
589: }
590: $result.=
1.270 raeburn 591: &Apache::loncommon::start_data_table_row()."\n";
592: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
593: $result .=
594: '<td valign="bottom"><input type="checkbox" name="HWFILE'.$jspart.'_'.$id.'_delete"'.
595: ' value="'.$portfile.'" /></td>'."\n";
596: }
1.271 raeburn 597: my $showname = $rows{$url}{path}.$name;
598: if ($legacy{$url}) {
599: $showname = $name.' '.&mt('not in portfolio');
600: }
1.270 raeburn 601: $result .=
1.265 raeburn 602: '<td><a href="'.$link.'"><img src="'.$icon.
1.271 raeburn 603: '" border="0" />'.$showname.'</a></td>'."\n".
1.265 raeburn 604: '<td align="right" valign="bottom">'.$rows{$url}{size}.'</td>'."\n".
605: '<td align="right" valign="bottom">'.$rows{$url}{lastmodified}.'</td>'."\n".
606: &Apache::loncommon::end_data_table_row();
607: }
608: }
609: }
610: }
611: }
612: if ($header_shown) {
613: $result .= &Apache::loncommon::end_data_table();
1.205 albertel 614: }
615: if (@bad_file_list) {
1.265 raeburn 616: my $bad_files = '<span class="LC_filename">'.
617: join('</span>, <span class="LC_filename">',@bad_file_list).
618: '</span>';
619: $result.='<p class="LC_error">'.
620: &mt("These file(s) don't exist: [_1]",$bad_files).
621: '</p>';
1.205 albertel 622: }
623: return $result;
1.265 raeburn 624: }
1.205 albertel 625:
1.265 raeburn 626: sub current_file_info {
627: my ($url,$uploadedfile,$name,$path) = @_;
628: my ($status,$error,%info);
629: my @stat = &Apache::lonnet::stat_file($url);
630: if ((@stat) && ($stat[0] ne 'no_such_dir')) {
631: my ($lastmod,$size);
632: if ($stat[9] =~ /^\d+$/) {
633: $lastmod = &Apache::lonlocal::locallocaltime($stat[9]);
634: }
635: $size = $stat[7]/(1024*1024);
636: $size = sprintf("%.3f",$size);
637: %info = (
638: link => $uploadedfile,
639: name => $name,
640: path => $path,
641: size => $size,
642: lastmodified => $lastmod,
643: );
644: $status = 'ok';
645: } else {
646: &Apache::lonnet::logthis("bad file is $url");
647: my $icon=&Apache::loncommon::icon($url);
648: $error = '<a href="'.$url.'"><img src="'.$icon.
649: '" border="0" />'.$uploadedfile.'</a>';
650: }
651: return ($status,\%info,$error);
1.205 albertel 652: }
653:
1.179 albertel 654: sub valid_award {
655: my ($award) =@_;
1.182 albertel 656: foreach my $possibleaward ('EXTRA_ANSWER','MISSING_ANSWER', 'ERROR',
657: 'NO_RESPONSE',
1.179 albertel 658: 'TOO_LONG', 'UNIT_INVALID_INSTRUCTOR',
659: 'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE',
660: 'UNIT_FAIL', 'NO_UNIT',
661: 'UNIT_NOTNEEDED', 'WANTED_NUMERIC',
1.272 ! www 662: 'BAD_FORMULA', 'NOT_FUNCTION', 'WRONG_FORMAT',
! 663: 'INTERNAL_ERROR', 'SIG_FAIL', 'INCORRECT',
1.179 albertel 664: 'MISORDERED_RANK', 'INVALID_FILETYPE',
1.264 raeburn 665: 'EXCESS_FILESIZE', 'FILENAME_INUSE',
666: 'DRAFT', 'SUBMITTED', 'SUBMITTED_CREDIT',
1.261 raeburn 667: 'ANONYMOUS', 'ANONYMOUS_CREDIT',
668: 'ASSIGNED_SCORE', 'APPROX_ANS',
669: 'EXACT_ANS','COMMA_FAIL') {
1.179 albertel 670: if ($award eq $possibleaward) { return 1; }
671: }
672: return 0;
673: }
674:
1.207 albertel 675: {
676: my @awards = ('EXTRA_ANSWER', 'MISSING_ANSWER', 'ERROR', 'NO_RESPONSE',
677: 'TOO_LONG',
678: 'UNIT_INVALID_INSTRUCTOR', 'UNIT_INVALID_STUDENT',
679: 'UNIT_IRRECONCIBLE', 'UNIT_FAIL', 'NO_UNIT',
1.272 ! www 680: 'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA', 'NOT_FUNCTION',
! 681: 'WRONG_FORMAT', 'INTERNAL_ERROR',
1.207 albertel 682: 'COMMA_FAIL', 'SIG_FAIL', 'INCORRECT', 'MISORDERED_RANK',
1.264 raeburn 683: 'INVALID_FILETYPE', 'EXCESS_FILESIZE', 'FILENAME_INUSE',
684: 'DRAFT', 'SUBMITTED',
1.261 raeburn 685: 'SUBMITTED_CREDIT', 'ANONYMOUS', 'ANONYMOUS_CREDIT',
1.248 raeburn 686: 'ASSIGNED_SCORE', 'APPROX_ANS', 'EXACT_ANS');
1.207 albertel 687: my $i=0;
688: my %fwd_awards = map { ($_,$i++) } @awards;
689: my $max=scalar(@awards);
690: @awards=reverse(@awards);
1.208 albertel 691: $i=0;
1.207 albertel 692: my %rev_awards = map { ($_,$i++) } @awards;
693:
1.232 albertel 694: sub awarddetail_to_awarded {
695: my ($awarddetail) = @_;
696: if ($awarddetail eq 'EXACT_ANS'
697: || $awarddetail eq 'APPROX_ANS') {
698: return 1;
699: }
700: return 0;
701: }
702:
1.233 albertel 703: sub hide_award {
704: my ($award) = @_;
705: if (&Apache::lonhomework::show_no_problem_status()) {
706: return 1;
707: }
708: if ($award =~
1.261 raeburn 709: /^(?:EXACT_ANS|APPROX_ANS|SUBMITTED|SUBMITTED_CREDIT|ANONYMOUS|ANONYMOUS_CREDIT|ASSIGNED_SCORE|INCORRECT)/) {
1.233 albertel 710: return 1;
711: }
712: return 0;
713: }
714:
1.9 albertel 715: sub finalizeawards {
1.232 albertel 716: my ($awardref,$msgref,$nameref,$reverse,$final_scantron)=@_;
1.207 albertel 717: my $result;
1.136 albertel 718: if ($#$awardref == -1) { $result = "NO_RESPONSE"; }
1.135 albertel 719: if ($result eq '' ) {
720: my $blankcount;
1.207 albertel 721: foreach my $award (@$awardref) {
1.135 albertel 722: if ($award eq '') {
723: $result='MISSING_ANSWER';
724: $blankcount++;
725: }
726: }
1.232 albertel 727: if ($blankcount == ($#$awardref + 1)) {
728: return ('NO_RESPONSE');
729: }
1.135 albertel 730: }
1.251 www 731:
732: if ($Apache::lonxml::internal_error) { $result='INTERNAL_ERROR'; }
733:
1.232 albertel 734: if (!$final_scantron && defined($result)) { return ($result); }
1.181 albertel 735:
1.232 albertel 736: # if in scantron mode, if the award for any response is
737: # assigned score, then the part gets an assigned score
738: if ($final_scantron
739: && grep {$_ eq 'ASSIGNED_SCORE'} (@$awardref)) {
740: return ('ASSIGNED_SCORE');
741: }
742:
743: # if in scantron mode, if the award for any response is
744: # correct and there are non-correct responses,
745: # then the part gets an assigned score
746: if ($final_scantron
747: && (grep { $_ eq 'EXACT_ANS' ||
748: $_ eq 'APPROX_ANS' } (@$awardref))
749: && (grep { $_ ne 'EXACT_ANS' &&
750: $_ ne 'APPROX_ANS' } (@$awardref))) {
751: return ('ASSIGNED_SCORE');
752: }
1.181 albertel 753: # these awards are ordered from most important error through best correct
1.207 albertel 754: my $awards = (!$reverse) ? \%fwd_awards : \%rev_awards ;
755:
756: my $best = $max;
757: my $j=0;
758: my $which;
759: foreach my $award (@$awardref) {
760: if ($awards->{$award} < $best) {
761: $best = $awards->{$award};
762: $which = $j;
763: }
764: $j++;
765: }
1.232 albertel 766:
1.207 albertel 767: if (defined($which)) {
768: if (ref($nameref)) {
769: return ($$awardref[$which],$$msgref[$which],$$nameref[$which]);
770: } else {
771: return ($$awardref[$which],$$msgref[$which]);
772: }
1.135 albertel 773: }
1.136 albertel 774: return ('ERROR',undef);
1.9 albertel 775: }
1.207 albertel 776: }
1.9 albertel 777:
1.10 albertel 778: sub decideoutput {
1.169 albertel 779: my ($award,$awarded,$awardmsg,$solved,$previous,$target)=@_;
1.251 www 780:
1.135 albertel 781: my $message='';
782: my $button=0;
783: my $previousmsg;
1.221 albertel 784: my $css_class='orange';
1.148 albertel 785: my $added_computer_text=0;
1.221 albertel 786: my %possible_class =
787: ( 'correct' => 'LC_answer_correct',
788: 'charged_try' => 'LC_answer_charged_try',
789: 'not_charged_try' => 'LC_answer_not_charged_try',
790: 'no_grade' => 'LC_answer_no_grade',
791: 'no_message' => 'LC_no_message',
1.135 albertel 792: );
1.169 albertel 793:
1.180 albertel 794: my $part = $Apache::inputtags::part;
1.236 raeburn 795: my $tohandgrade = &Apache::lonnet::EXT("resource.$part.handgrade");
796: my $handgrade = ('yes' eq lc($tohandgrade));
1.180 albertel 797:
798: my $computer = ($handgrade)? ''
1.203 www 799: : " ".&mt("Computer's answer now shown above.");
1.180 albertel 800: &Apache::lonxml::debug("handgrade has :$handgrade:");
801:
1.135 albertel 802: if ($previous) { $previousmsg=&mt('You have entered that answer before'); }
803:
1.194 banghart 804: if ($solved =~ /^correct/) {
1.221 albertel 805: $css_class=$possible_class{'correct'};
1.170 albertel 806: $message=&mt('You are correct.');
807: if ($awarded < 1 && $awarded > 0) {
808: $message=&mt('You are partially correct.');
1.221 albertel 809: $css_class=$possible_class{'not_charged_try'};
1.170 albertel 810: } elsif ($awarded < 1) {
811: $message=&mt('Incorrect.');
1.221 albertel 812: $css_class=$possible_class{'charged_try'};
1.170 albertel 813: }
1.172 albertel 814: if ($env{'request.filename'} =~
815: m|/res/lib/templates/examupload.problem$|) {
816: $message = &mt("A score has been assigned.");
817: $added_computer_text=1;
1.135 albertel 818: } else {
1.172 albertel 819: if ($target eq 'tex') {
820: $message = '\textbf{'.$message.'}';
821: } else {
822: $message = "<b>".$message."</b>";
1.180 albertel 823: $message.= $computer;
1.135 albertel 824: }
1.172 albertel 825: $added_computer_text=1;
1.235 albertel 826: if ($awarded > 0) {
827: my ($symb) = &Apache::lonnet::whichuser();
828: if (($symb ne '')
829: &&
830: ($env{'course.'.$env{'request.course.id'}.
1.237 www 831: '.disable_receipt_display'} ne 'yes') &&
832: ($Apache::lonhomework::type ne 'practice')) {
1.235 albertel 833: $message.=(($target eq 'web')?'<br />':' ').
1.256 biermanm 834: &mt('Your receipt no. is [_1]',
1.235 albertel 835: (&Apache::lonnet::receipt($Apache::inputtags::part).
836: (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):'')));
837: }
1.135 albertel 838: }
839: }
840: $button=0;
841: $previousmsg='';
842: } elsif ($solved =~ /^excused/) {
843: if ($target eq 'tex') {
844: $message = ' \textbf{'.&mt('You are excused from the problem.').'} ';
845: } else {
846: $message = "<b>".&mt('You are excused from the problem.')."</b>";
847: }
1.221 albertel 848: $css_class=$possible_class{'charged_try'};
1.135 albertel 849: $button=0;
850: $previousmsg='';
851: } elsif ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
852: if ($solved =~ /^incorrect/ || $solved eq '') {
1.144 albertel 853: $message = &mt("Incorrect").".";
1.221 albertel 854: $css_class=$possible_class{'charged_try'};
1.135 albertel 855: $button=1;
856: } else {
1.144 albertel 857: if ($target eq 'tex') {
858: $message = '\textbf{'.&mt('You are correct.').'}';
859: } else {
860: $message = "<b>".&mt('You are correct.')."</b>";
1.180 albertel 861: $message.= $computer;
1.144 albertel 862: }
1.148 albertel 863: $added_computer_text=1;
1.235 albertel 864: if ($awarded > 0
865: && $env{'course.'.
1.165 albertel 866: $env{'request.course.id'}.
1.235 albertel 867: '.disable_receipt_display'} ne 'yes') {
1.135 albertel 868: $message.=(($target eq 'web')?'<br />':' ').
1.235 albertel 869: &mt('Your receipt is [_1]',
870: (&Apache::lonnet::receipt($Apache::inputtags::part).
871: (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):'')));
1.135 albertel 872: }
1.221 albertel 873: $css_class=$possible_class{'correct'};
1.135 albertel 874: $button=0;
875: $previousmsg='';
876: }
877: } elsif ($award eq 'NO_RESPONSE') {
878: $message = '';
1.221 albertel 879: $css_class=$possible_class{'no_feedback'};
1.135 albertel 880: $button=1;
1.182 albertel 881: } elsif ($award eq 'EXTRA_ANSWER') {
882: $message = &mt('Some extra items were submitted.');
1.221 albertel 883: $css_class=$possible_class{'not_charged_try'};
1.182 albertel 884: $button = 1;
1.135 albertel 885: } elsif ($award eq 'MISSING_ANSWER') {
1.245 bisitz 886: $message = &mt('Some items were not submitted.');
887: if ($target ne 'tex') {
888: $message .= &Apache::loncommon::help_open_topic('Some_Items_Were_Not_Submitted');
889: }
1.221 albertel 890: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 891: $button = 1;
892: } elsif ($award eq 'ERROR') {
1.247 bisitz 893: $message = &mt('An error occurred while grading your answer.');
1.221 albertel 894: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 895: $button = 1;
896: } elsif ($award eq 'TOO_LONG') {
897: $message = &mt("The submitted answer was too long.");
1.221 albertel 898: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 899: $button=1;
900: } elsif ($award eq 'WANTED_NUMERIC') {
901: $message = &mt("This question expects a numeric answer.");
1.221 albertel 902: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 903: $button=1;
904: } elsif ($award eq 'MISORDERED_RANK') {
1.242 bisitz 905: $message = &mt('You have provided an invalid ranking.');
906: if ($target ne 'tex') {
907: $message.=' '.&mt('Please refer to [_1]',&Apache::loncommon::help_open_topic('Ranking_Problems',&mt('help on ranking problems')));
908: }
1.221 albertel 909: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 910: $button=1;
1.248 raeburn 911: } elsif ($award eq 'EXCESS_FILESIZE') {
912: $message = &mt('Submission won\'t be graded. The combined size of submitted files exceeded the amount allowed.');
913: $css_class=$possible_class{'not_charged_try'};
914: $button=1;
1.264 raeburn 915: } elsif ($award eq 'FILENAME_INUSE') {
916: $message = &mt('You have already uploaded a file with that filename.');
917: if ($target eq 'tex') {
918: $message.= "\\\\\n";
919: } else {
920: $message .= '<br />';
921: }
922: $message .= &mt('Please use a different file name.');
923: $css_class=$possible_class{'not_charged_try'};
924: $button=1;
1.135 albertel 925: } elsif ($award eq 'INVALID_FILETYPE') {
1.255 bisitz 926: $message = &mt("Submission won't be graded. The type of file submitted is not allowed.");
1.221 albertel 927: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 928: $button=1;
929: } elsif ($award eq 'SIG_FAIL') {
1.145 albertel 930: my ($used,$min,$max)=split(':',$awardmsg);
1.212 albertel 931: my $word = ($used < $min) ? 'more' : 'fewer';
1.250 bisitz 932: $message = &mt("Submission not graded. Use $word digits.",$used);
1.221 albertel 933: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 934: $button=1;
1.137 albertel 935: } elsif ($award eq 'UNIT_INVALID_INSTRUCTOR') {
936: $message = &mt('Error in instructor specifed unit. This error has been reported to the instructor.', $awardmsg);
937: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');}
1.221 albertel 938: $css_class=$possible_class{'not_charged_try'};
1.137 albertel 939: $button=1;
940: } elsif ($award eq 'UNIT_INVALID_STUDENT') {
1.155 albertel 941: $message = &mt('Unable to interpret units. Computer reads units as "[_1]".',&markup_unit($awardmsg,$target));
1.137 albertel 942: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');}
1.221 albertel 943: $css_class=$possible_class{'not_charged_try'};
1.137 albertel 944: $button=1;
1.140 matthew 945: } elsif ($award eq 'UNIT_FAIL' || $award eq 'UNIT_IRRECONCIBLE') {
1.155 albertel 946: $message = &mt('Incompatible units. No conversion found between "[_1]" and the required units.',&markup_unit($awardmsg,$target));
1.136 albertel 947: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');}
1.221 albertel 948: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 949: $button=1;
950: } elsif ($award eq 'UNIT_NOTNEEDED') {
1.155 albertel 951: $message = &mt('Only a number required. Computer reads units of "[_1]".',&markup_unit($awardmsg,$target));
1.221 albertel 952: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 953: $button=1;
954: } elsif ($award eq 'NO_UNIT') {
1.144 albertel 955: $message = &mt("Units required").'.';
1.135 albertel 956: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units')};
1.221 albertel 957: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 958: $button=1;
1.153 albertel 959: } elsif ($award eq 'COMMA_FAIL') {
960: $message = &mt("Proper comma separation is required").'.';
1.221 albertel 961: $css_class=$possible_class{'not_charged_try'};
1.153 albertel 962: $button=1;
1.135 albertel 963: } elsif ($award eq 'BAD_FORMULA') {
1.240 www 964: $message = &mt("Unable to understand formula").'.';
965: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Formula_Answers')};
1.221 albertel 966: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 967: $button=1;
1.272 ! www 968: } elsif ($award eq 'NOT_FUNCTION') {
! 969: $message = &mt("Not a function").'.';
! 970: $css_class=$possible_class{'not_charged_try'};
! 971: $button=1;
! 972: } elsif ($award eq 'WRONG_FORMAT') {
! 973: $message = &mt("Wrong format").'.';
! 974: $css_class=$possible_class{'not_charged_try'};
! 975: $button=1;
! 976: } elsif ($award eq 'INTERNAL_ERROR') {
1.251 www 977: $message = &mt("An internal error occurred while processing your answer. Please try again later.");
978: $css_class=$possible_class{'not_charged_try'};
979: $button=1;
1.135 albertel 980: } elsif ($award eq 'INCORRECT') {
1.144 albertel 981: $message = &mt("Incorrect").'.';
1.221 albertel 982: $css_class=$possible_class{'charged_try'};
1.135 albertel 983: $button=1;
984: } elsif ($award eq 'SUBMITTED') {
985: $message = &mt("Your submission has been recorded.");
1.221 albertel 986: $css_class=$possible_class{'no_grade'};
1.135 albertel 987: $button=1;
1.261 raeburn 988: } elsif ($award eq 'SUBMITTED_CREDIT') {
989: $message = &mt("Your submission has been recorded, and credit awarded.");
990: $css_class=$possible_class{'correct'};
991: $button=1;
992: } elsif ($award eq 'ANONYMOUS') {
993: $message = &mt("Your anonymous submission has been recorded.");
994: $css_class=$possible_class{'no_grade'};
995: $button=1;
996: } elsif ($award eq 'ANONYMOUS_CREDIT') {
997: $message = &mt("Your anonymous submission has been recorded, and credit awarded.");
998: $css_class=$possible_class{'correct'};
1.135 albertel 999: } elsif ($award eq 'DRAFT') {
1.258 riegler 1000: $message = &mt("Copy saved but not submitted.");
1.221 albertel 1001: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 1002: $button=1;
1003: } elsif ($award eq 'ASSIGNED_SCORE') {
1.144 albertel 1004: $message = &mt("A score has been assigned.");
1.221 albertel 1005: $css_class=$possible_class{'correct'};
1.135 albertel 1006: $button=0;
1.144 albertel 1007: } elsif ($award eq '') {
1.186 albertel 1008: if ($handgrade && $Apache::inputtags::status[-1] eq 'SHOW_ANSWER') {
1009: $message = &mt("Nothing submitted.");
1.221 albertel 1010: $css_class=$possible_class{'charged_try'};
1.186 albertel 1011: } else {
1.221 albertel 1012: $css_class=$possible_class{'not_charged_try'};
1.186 albertel 1013: }
1.144 albertel 1014: $button=1;
1.135 albertel 1015: } else {
1016: $message = &mt("Unknown message").": $award";
1017: $button=1;
1018: }
1.209 albertel 1019: my (undef,undef,$domain,$user)=&Apache::lonnet::whichuser();
1.194 banghart 1020: foreach my $resid(@Apache::inputtags::response){
1021: if ($Apache::lonhomework::history{"resource.$part.$resid.handback"}) {
1.254 raeburn 1022: if ($target eq 'tex') {
1023: $message.= "\\\\\n";
1024: } else {
1025: $message.='<br />';
1026: }
1.198 albertel 1027: my @files = split(/\s*,\s*/,
1028: $Apache::lonhomework::history{"resource.$part.$resid.handback"});
1029: my $file_msg;
1030: foreach my $file (@files) {
1.254 raeburn 1031: if ($target eq 'tex') {
1032: $file_msg.= "\\\\\n".$file;
1033: } else {
1034: $file_msg.= '<br /><a href="/uploaded/'."$domain/$user".'/'.$file.'">'.$file.'</a>';
1035: }
1.198 albertel 1036: }
1037: $message .= &mt('Returned file(s): [_1]',$file_msg);
1.254 raeburn 1038: if ($target eq 'tex') {
1039: $message.= "\\\\\n";
1040: } else {
1041: $message.='<br />';
1042: }
1.198 albertel 1043: }
1.194 banghart 1044: }
1045:
1.233 albertel 1046: if (&Apache::lonhomework::hide_problem_status()
1047: && $Apache::inputtags::status[-1] ne 'SHOW_ANSWER'
1048: && &hide_award($award)) {
1.135 albertel 1049: $message = &mt("Answer Submitted: Your final submission will be graded after the due date.");
1.221 albertel 1050: $css_class=$possible_class{'no_grade'};
1.135 albertel 1051: $button=1;
1052: }
1.148 albertel 1053: if ($Apache::inputtags::status[-1] eq 'SHOW_ANSWER' &&
1.150 albertel 1054: !$added_computer_text && $target ne 'tex') {
1.180 albertel 1055: $message.= $computer;
1.148 albertel 1056: $added_computer_text=1;
1.144 albertel 1057: }
1.237 www 1058: if ($Apache::lonhomework::type eq 'practice') {
1.244 raeburn 1059: if ($target eq 'web') {
1060: $message .= '<br />';
1061: } else {
1062: $message .= ' ';
1063: }
1064: $message.=&mt('Submissions to practice problems are not permanently recorded.');
1.237 www 1065: }
1066:
1.221 albertel 1067: return ($button,$css_class,$message,$previousmsg);
1.12 albertel 1068: }
1069:
1.155 albertel 1070: sub markup_unit {
1071: my ($unit,$target)=@_;
1072: if ($target eq 'tex') {
1073: return '\texttt{'.&Apache::lonxml::latex_special_symbols($unit).'}';
1074: } else {
1075: return "<tt>".$unit."</tt>";
1076: }
1077: }
1078:
1.88 albertel 1079: sub removealldata {
1.87 albertel 1080: my ($id)=@_;
1081: foreach my $key (keys(%Apache::lonhomework::results)) {
1082: if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
1083: &Apache::lonxml::debug("Removing $key");
1084: delete($Apache::lonhomework::results{$key});
1085: }
1086: }
1087: }
1088:
1.142 albertel 1089: sub hidealldata {
1090: my ($id)=@_;
1091: foreach my $key (keys(%Apache::lonhomework::results)) {
1092: if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
1093: &Apache::lonxml::debug("Hidding $key");
1094: my $newkey=$key;
1095: $newkey=~s/^(resource\.\Q$id\E\.[^\.]+\.)(.*)$/${1}hidden${2}/;
1096: $Apache::lonhomework::results{$newkey}=
1097: $Apache::lonhomework::results{$key};
1098: delete($Apache::lonhomework::results{$key});
1099: }
1100: }
1101: }
1102:
1.12 albertel 1103: sub setgradedata {
1.136 albertel 1104: my ($award,$msg,$id,$previously_used) = @_;
1.154 albertel 1105: if ($Apache::lonhomework::scantronmode &&
1.165 albertel 1106: &Apache::lonnet::validCODE($env{'form.CODE'})) {
1107: $Apache::lonhomework::results{"resource.CODE"}=$env{'form.CODE'};
1.154 albertel 1108: } elsif ($Apache::lonhomework::scantronmode &&
1.165 albertel 1109: $env{'form.CODE'} eq '' &&
1.154 albertel 1110: $Apache::lonhomework::history{"resource.CODE"} ne '') {
1111: $Apache::lonhomework::results{"resource.CODE"}='';
1.141 albertel 1112: }
1.154 albertel 1113:
1.135 albertel 1114: if (!$Apache::lonhomework::scantronmode &&
1115: $Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
1116: $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
1117: $Apache::lonhomework::results{"resource.$id.afterduedate"}=$award;
1.87 albertel 1118: return '';
1.135 albertel 1119: } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~
1.233 albertel 1120: /^correct/
1121: || $Apache::lonhomework::scantronmode
1122: || &Apache::lonhomework::hide_problem_status() ) {
1.154 albertel 1123: # the student doesn't already have it correct,
1124: # or we are in a mode (scantron orno problem status) where a correct
1125: # can become incorrect
1126: # handle assignment of tries and solved status
1.135 albertel 1127: my $solvemsg;
1128: if ($Apache::lonhomework::scantronmode) {
1129: $solvemsg='correct_by_scantron';
1130: } else {
1131: $solvemsg='correct_by_student';
1132: }
1133: if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
1134: $Apache::lonhomework::results{"resource.$id.afterduedate"}='';
1135: }
1136: if ( $award eq 'ASSIGNED_SCORE') {
1137: $Apache::lonhomework::results{"resource.$id.tries"} =
1138: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1139: $Apache::lonhomework::results{"resource.$id.solved"} =
1140: $solvemsg;
1141: my $numawards=scalar(@Apache::inputtags::response);
1142: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
1143: foreach my $res (@Apache::inputtags::response) {
1.232 albertel 1144: if (defined($Apache::lonhomework::results{"resource.$id.$res.awarded"})) {
1145: $Apache::lonhomework::results{"resource.$id.awarded"}+=
1146: $Apache::lonhomework::results{"resource.$id.$res.awarded"};
1147: } else {
1148: $Apache::lonhomework::results{"resource.$id.awarded"}+=
1149: &awarddetail_to_awarded($Apache::lonhomework::results{"resource.$id.$res.awarddetail"});
1150: }
1.135 albertel 1151: }
1152: if ($numawards > 0) {
1153: $Apache::lonhomework::results{"resource.$id.awarded"}/=
1154: $numawards;
1155: }
1156: } elsif ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
1157: $Apache::lonhomework::results{"resource.$id.tries"} =
1158: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1159: $Apache::lonhomework::results{"resource.$id.solved"} =
1160: $solvemsg;
1161: $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
1.261 raeburn 1162: } elsif ( $award eq 'SUBMITTED_CREDIT' ) {
1163: $Apache::lonhomework::results{"resource.$id.tries"} =
1164: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1165: $Apache::lonhomework::results{"resource.$id.solved"} =
1166: 'credit_attempted';
1167: $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
1168: } elsif ( $award eq 'ANONYMOUS_CREDIT' ) {
1169: $Apache::lonhomework::results{"resource.$id.tries"} =
1170: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1171: $Apache::lonhomework::results{"resource.$id.solved"} =
1172: 'credit_attempted';
1173: $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
1.135 albertel 1174: } elsif ( $award eq 'INCORRECT' ) {
1175: $Apache::lonhomework::results{"resource.$id.tries"} =
1176: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1.233 albertel 1177: if (&Apache::lonhomework::hide_problem_status()
1178: || $Apache::lonhomework::scantronmode) {
1.135 albertel 1179: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
1180: }
1181: $Apache::lonhomework::results{"resource.$id.solved"} =
1182: 'incorrect_attempted';
1183: } elsif ( $award eq 'SUBMITTED' ) {
1184: $Apache::lonhomework::results{"resource.$id.tries"} =
1185: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1186: $Apache::lonhomework::results{"resource.$id.solved"} =
1187: 'ungraded_attempted';
1.261 raeburn 1188: } elsif ( $award eq 'ANONYMOUS' ) {
1189: $Apache::lonhomework::results{"resource.$id.tries"} =
1190: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1191: $Apache::lonhomework::results{"resource.$id.solved"} =
1192: 'ungraded_attempted';
1.135 albertel 1193: } elsif ( $award eq 'DRAFT' ) {
1194: $Apache::lonhomework::results{"resource.$id.solved"} = '';
1195: } elsif ( $award eq 'NO_RESPONSE' ) {
1196: #no real response so delete any data that got stored
1.129 albertel 1197: &removealldata($id);
1198: return '';
1199: } else {
1.135 albertel 1200: $Apache::lonhomework::results{"resource.$id.solved"} =
1201: 'incorrect_attempted';
1.233 albertel 1202: if (&Apache::lonhomework::show_no_problem_status()
1203: || $Apache::lonhomework::scantronmode) {
1.135 albertel 1204: $Apache::lonhomework::results{"resource.$id.tries"} =
1205: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1206: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
1207: }
1.233 albertel 1208:
1209: if (&Apache::lonhomework::show_some_problem_status()) {
1210: # clear out the awarded if they had gotten it wrong/right
1211: # and are now in an error mode
1212: $Apache::lonhomework::results{"resource.$id.awarded"} = '';
1213: }
1.135 albertel 1214: }
1.136 albertel 1215: if (defined($msg)) {
1216: $Apache::lonhomework::results{"resource.$id.awardmsg"} = $msg;
1217: }
1.135 albertel 1218: # did either of the overall awards chage? If so ignore the
1219: # previous check
1220: if (($Apache::lonhomework::results{"resource.$id.awarded"} eq
1221: $Apache::lonhomework::history{"resource.$id.awarded"}) &&
1222: ($Apache::lonhomework::results{"resource.$id.solved"} eq
1223: $Apache::lonhomework::history{"resource.$id.solved"})) {
1224: # check if this was a previous submission if it was delete the
1225: # unneeded data and update the previously_used attribute
1226: if ( $previously_used eq 'PREVIOUSLY_USED') {
1.233 albertel 1227: if (&Apache::lonhomework::show_problem_status()) {
1.135 albertel 1228: delete($Apache::lonhomework::results{"resource.$id.tries"});
1229: $Apache::lonhomework::results{"resource.$id.previous"} = '1';
1230: }
1231: } elsif ( $previously_used eq 'PREVIOUSLY_LAST') {
1232: #delete all data as they student didn't do anything, but save
1233: #the list of collaborators.
1234: &removealldata($id);
1235: #and since they didn't do anything we were never here
1236: return '';
1237: } else {
1238: $Apache::lonhomework::results{"resource.$id.previous"} = '0';
1239: }
1.101 albertel 1240: }
1.135 albertel 1241: } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} =~
1242: /^correct/ ) {
1243: #delete all data as they student already has it correct
1244: &removealldata($id);
1245: #and since they didn't do anything we were never here
1246: return '';
1.40 albertel 1247: }
1.135 albertel 1248: $Apache::lonhomework::results{"resource.$id.award"} = $award;
1.184 albertel 1249: if ($award eq 'SUBMITTED') {
1250: &Apache::response::add_to_gradingqueue();
1251: }
1.261 raeburn 1252: if (($Apache::lonhomework::type eq 'anonsurvey') ||
1253: ($Apache::lonhomework::type eq 'anonsurveycred')) {
1254: $Apache::lonhomework::results{"resource.$id.type"} = $Apache::lonhomework::type;
1255: }
1.10 albertel 1256: }
1257:
1.219 albertel 1258: sub find_which_previous {
1259: my ($version) = @_;
1260: my $part = $Apache::inputtags::part;
1261: my (@previous_version);
1262: foreach my $resp (@Apache::inputtags::response) {
1263: my $key = "$version:resource.$part.$resp.submission";
1264: my $submission = $Apache::lonhomework::history{$key};
1265: my %previous = &Apache::response::check_for_previous($submission,
1266: $part,$resp,
1267: $version);
1268: push(@previous_version,$previous{'version'});
1269: }
1270: return &previous_match(\@previous_version,
1271: scalar(@Apache::inputtags::response));
1272: }
1273:
1274: sub previous_match {
1275: my ($previous_array,$count) = @_;
1276: my $match = 0;
1277: my @matches;
1278: foreach my $versionar (@$previous_array) {
1279: foreach my $version (@$versionar) {
1280: $matches[$version]++;
1281: }
1282: }
1283: my $which=0;
1284: foreach my $elem (@matches) {
1285: if ($elem eq $count) {
1286: $match=1;
1287: last;
1288: }
1289: $which++;
1290: }
1291: return ($match,$which);
1292: }
1293:
1.9 albertel 1294: sub grade {
1.135 albertel 1295: my ($target) = @_;
1296: my $id = $Apache::inputtags::part;
1297: my $response='';
1.165 albertel 1298: if ( defined $env{'form.submitted'}) {
1.136 albertel 1299: my (@awards,@msgs);
1.135 albertel 1300: foreach $response (@Apache::inputtags::response) {
1301: &Apache::lonxml::debug("looking for response.$id.$response.awarddetail");
1302: my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"};
1303: &Apache::lonxml::debug("keeping $value from $response for $id");
1304: push (@awards,$value);
1.136 albertel 1305: $value=$Apache::lonhomework::results{"resource.$id.$response.awardmsg"};
1306: &Apache::lonxml::debug("got message $value from $response for $id");
1307: push (@msgs,$value);
1.135 albertel 1308: }
1.232 albertel 1309: my ($finalaward,$msg) =
1310: &finalizeawards(\@awards,\@msgs,undef,undef,
1311: $Apache::lonhomework::scantronmode);
1.135 albertel 1312: my $previously_used;
1313: if ( $#Apache::inputtags::previous eq $#awards ) {
1.219 albertel 1314: my ($match) =
1315: &previous_match(\@Apache::inputtags::previous_version,
1316: scalar(@Apache::inputtags::response));
1.244 raeburn 1317:
1.135 albertel 1318: if ($match) {
1319: $previously_used = 'PREVIOUSLY_LAST';
1320: foreach my $value (@Apache::inputtags::previous) {
1321: if ($value eq 'PREVIOUSLY_USED' ) {
1322: $previously_used = $value;
1323: last;
1324: }
1.75 albertel 1325: }
1326: }
1.43 albertel 1327: }
1.136 albertel 1328: &Apache::lonxml::debug("final award $finalaward, $previously_used, message $msg");
1329: &setgradedata($finalaward,$msg,$id,$previously_used);
1.43 albertel 1330: }
1.135 albertel 1331: return '';
1.1 albertel 1332: }
1333:
1.217 albertel 1334: sub get_grade_messages {
1335: my ($id,$prefix,$target,$status) = @_;
1336:
1337: my ($message,$latemessage,$trystr,$previousmsg);
1338: my $showbutton = 1;
1339:
1340: my $award = $Apache::lonhomework::history{"$prefix.award"};
1341: my $awarded = $Apache::lonhomework::history{"$prefix.awarded"};
1342: my $solved = $Apache::lonhomework::history{"$prefix.solved"};
1343: my $previous = $Apache::lonhomework::history{"$prefix.previous"};
1344: my $awardmsg = $Apache::lonhomework::history{"$prefix.awardmsg"};
1345: &Apache::lonxml::debug("Found Award |$award|$solved|$awardmsg");
1346: if ( $award ne '' || $solved ne '' || $status eq 'SHOW_ANSWER') {
1347: &Apache::lonxml::debug('Getting message');
1.221 albertel 1348: ($showbutton,my $css_class,$message,$previousmsg) =
1.217 albertel 1349: &decideoutput($award,$awarded,$awardmsg,$solved,$previous,
1350: $target);
1351: if ($target eq 'tex') {
1352: $message='\vskip 2 mm '.$message.' ';
1353: } else {
1.221 albertel 1354: $message="<td class=\"$css_class\">$message</td>";
1.217 albertel 1355: if ($previousmsg) {
1.221 albertel 1356: $previousmsg="<td class=\"LC_answer_previous\">$previousmsg</td>";
1.217 albertel 1357: }
1358: }
1359: }
1360: my $tries = $Apache::lonhomework::history{"$prefix.tries"};
1361: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
1362: &Apache::lonxml::debug("got maxtries of :$maxtries:");
1363: #if tries are set to negative turn off the Tries/Button and messages
1364: if (defined($maxtries) && $maxtries < 0) { return ''; }
1365: if ( $tries eq '' ) { $tries = '0'; }
1366: if ( $maxtries eq '' ) { $maxtries = '2'; }
1367: if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; }
1.263 raeburn 1368: my $tries_text= &get_tries_text();;
1.217 albertel 1369: if ($showbutton) {
1370: if ($target eq 'tex') {
1371: if ($env{'request.state'} ne "construct"
1372: && $Apache::lonhomework::type ne 'exam'
1373: && $env{'form.suppress_tries'} ne 'yes') {
1374: $trystr = ' {\vskip 1 mm \small \textit{'.$tries_text.'} '.
1375: $tries.'/'.$maxtries.'} \vskip 2 mm ';
1376: } else {
1377: $trystr = '\vskip 0 mm ';
1378: }
1379: } else {
1.263 raeburn 1380: $trystr = '<td><span class="LC_nobreak">'.&mt($tries_text)." $tries";
1.217 albertel 1381: if ($Apache::lonhomework::parsing_a_task) {
1382: } elsif($env{'request.state'} ne 'construct') {
1383: $trystr.="/$maxtries";
1384: } else {
1385: if (defined($Apache::inputtags::params{'maxtries'})) {
1386: $trystr.="/".$Apache::inputtags::params{'maxtries'};
1387: }
1388: }
1.253 bisitz 1389: $trystr.="</span></td>";
1.217 albertel 1390: }
1391: }
1.221 albertel 1392:
1.217 albertel 1393: if ($Apache::lonhomework::history{"$prefix.afterduedate"}) {
1394: #last submissions was after due date
1395: $latemessage=&mt(' The last submission was after the Due Date ');;
1396: if ($target eq 'web') {
1.221 albertel 1397: $latemessage='<td class="LC_answer_late">'.$latemessage.'</td>';
1.217 albertel 1398: }
1399: }
1400: return ($previousmsg,$latemessage,$message,$trystr,$showbutton);
1401: }
1402:
1.11 albertel 1403: sub gradestatus {
1.223 albertel 1404: my ($id,$target,$no_previous) = @_;
1.135 albertel 1405: my $showbutton = 1;
1406: my $message = '';
1407: my $latemessage = '';
1408: my $trystr='';
1409: my $button='';
1410: my $previousmsg='';
1411:
1412: my $status = $Apache::inputtags::status['-1'];
1413: &Apache::lonxml::debug("gradestatus has :$status:");
1.183 albertel 1414: if ( $status ne 'CLOSED'
1415: && $status ne 'UNAVAILABLE'
1416: && $status ne 'INVALID_ACCESS'
1417: && $status ne 'NEEDS_CHECKIN'
1418: && $status ne 'NOT_IN_A_SLOT') {
1.217 albertel 1419:
1420: ($previousmsg,$latemessage,$message,$trystr) =
1421: &get_grade_messages($id,"resource.$id",$target,$status,
1422: $showbutton);
1423: if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {
1424: $showbutton = 0;
1.164 albertel 1425: }
1.218 albertel 1426: if ( $status eq 'SHOW_ANSWER') {
1427: undef($previousmsg);
1428: }
1.135 albertel 1429: if ( $showbutton ) {
1430: if ($target ne 'tex') {
1.230 albertel 1431: $button =
1.262 www 1432: '<input onmouseup="javascript:setSubmittedPart(\''.$id.'\');this.form.action+=\'#'.&escape($id).'\';"
1.260 droeschl 1433: type="submit" name="submit_'.$id.'"
1434: value="'.&mt('Submit Answer').'" />';
1.135 albertel 1435: }
1436: }
1.217 albertel 1437:
1.135 albertel 1438: }
1439: my $output= $previousmsg.$latemessage.$message.$trystr;
1440: if ($output =~ /^\s*$/) {
1441: return $button;
1.63 sakharuk 1442: } else {
1.135 albertel 1443: if ($target eq 'tex') {
1444: return $button.' \vskip 0 mm '.$output.' ';
1445: } else {
1.223 albertel 1446: $output =
1447: '<table><tr><td>'.$button.'</td>'.$output;
1448: if (!$no_previous) {
1449: $output.='<td>'.&previous_tries($id,$target).'</td>';
1450: }
1451: $output.= '</tr></table>';
1452: return $output;
1.135 albertel 1453: }
1.63 sakharuk 1454: }
1.11 albertel 1455: }
1.217 albertel 1456:
1457: sub previous_tries {
1458: my ($id,$target) = @_;
1459: my $output;
1460: my $status = $Apache::inputtags::status['-1'];
1.219 albertel 1461:
1462: my $count;
1463: my %count_lookup;
1464:
1.217 albertel 1465: foreach my $i (1..$Apache::lonhomework::history{'version'}) {
1466: my $prefix = $i.":resource.$id";
1.263 raeburn 1467: my $is_anon;
1468: if (defined($env{'form.grade_symb'})) {
1469: if (($Apache::lonhomework::history{"$prefix.type"} eq 'anonsurvey') ||
1470: ($Apache::lonhomework::history{"$prefix.type"} eq 'anonsurveycred')) {
1471: $is_anon = 1;
1472: }
1473: }
1.217 albertel 1474: next if (!exists($Apache::lonhomework::history{"$prefix.award"}));
1.219 albertel 1475: $count++;
1476: $count_lookup{$i} = $count;
1477:
1.217 albertel 1478: my ($previousmsg,$latemessage,$message,$trystr);
1479:
1480: ($previousmsg,$latemessage,$message,$trystr) =
1481: &get_grade_messages($id,"$prefix",$target,$status);
1482:
1.219 albertel 1483: if ($previousmsg ne '') {
1484: my ($match,$which) = &find_which_previous($i);
1485: $message=$previousmsg;
1486: my $previous = $count_lookup{$which};
1.226 albertel 1487: $message =~ s{(</td>)}{ as submission \# $previous $1};
1.221 albertel 1488: } elsif ($Apache::lonhomework::history{"$prefix.tries"}) {
1.233 albertel 1489: if (!(&Apache::lonhomework::hide_problem_status()
1.225 albertel 1490: && $Apache::inputtags::status[-1] ne 'SHOW_ANSWER')
1491: && $Apache::lonhomework::history{"$prefix.solved"} =~/^correct/
1492: ) {
1493:
1.238 bisitz 1494: my $txt_correct = &mt('Correct');
1.221 albertel 1495: $message =~ s{(<td.*?>)(.*?)(</td>)}
1.238 bisitz 1496: {$1 <strong>$txt_correct</strong>. $3}s;
1.221 albertel 1497: }
1.238 bisitz 1498: my $trystr = "(".&mt('Try [_1]',$Apache::lonhomework::history{"$prefix.tries"}).")";
1.221 albertel 1499: $message =~ s{(</td>)}{ $trystr $1};
1.219 albertel 1500: }
1.221 albertel 1501: my ($class) = ($message =~ m{<td.*class="([^"]*)"}); #"
1502: $message =~ s{(<td.*?>)}{<td>};
1503:
1.219 albertel 1504:
1.221 albertel 1505: $output.='<tr class="'.$class.'">';
1.223 albertel 1506: $output.='<td align="center">'.$count.'</td>';
1.219 albertel 1507: $output.=$message;
1.217 albertel 1508:
1509: foreach my $resid (@Apache::inputtags::response) {
1510: my $prefix = $prefix.".$resid";
1511: if (exists($Apache::lonhomework::history{"$prefix.submission"})) {
1512: my $submission =
1513: $Apache::inputtags::submission_display{"$prefix.submission"};
1514: if (!defined($submission)) {
1515: $submission =
1516: $Apache::lonhomework::history{"$prefix.submission"};
1517: }
1.263 raeburn 1518: if ($is_anon) {
1519: $output.='<td>'.&mt('(only shown to submitter)').'</td>';
1520: } else {
1521: $output.='<td>'.$submission.'</td>';
1522: }
1.217 albertel 1523: } else {
1524: $output.='<td></td>';
1525: }
1526: }
1.221 albertel 1527: $output.=&Apache::loncommon::end_data_table_row()."\n";
1.217 albertel 1528: }
1529: return if ($output eq '');
1.219 albertel 1530: my $headers =
1.222 albertel 1531: '<tr>'.'<th>'.&mt('Submission #').'</th><th>'.&mt('Try').
1.219 albertel 1532: '</th><th colspan="'.scalar(@Apache::inputtags::response).'">'.
1533: &mt('Submitted Answer').'</th>';
1534: $output ='<table class="LC_prior_tries">'.$headers.$output.'</table>';
1.217 albertel 1535: #return $output;
1.229 albertel 1536: $output = &Apache::loncommon::js_ready($output);
1.226 albertel 1537: $output.='<br /><form action=""><center><input type="button" name="close" value="'.&mt('Close Window').'" onClick="window.close()" /></center></form>';
1538:
1.217 albertel 1539: my $windowopen=&Apache::lonhtmlcommon::javascript_docopen();
1.263 raeburn 1540: my $tries_text = &get_tries_text('link');
1.217 albertel 1541: my $start_page =
1.263 raeburn 1542: &Apache::loncommon::start_page($tries_text, undef,
1.229 albertel 1543: {'only_body' => 1,
1544: 'bgcolor' => '#FFFFFF',
1545: 'js_ready' => 1,
1546: 'inherit_jsmath' => 1, });
1.217 albertel 1547: my $end_page =
1548: &Apache::loncommon::end_page({'js_ready' => 1,});
1.231 albertel 1549: my $prefix = $env{'form.request.prefix'};
1550: $prefix =~ tr{.}{_};
1551: my $function_name = "LONCAPA_previous_tries_".$prefix.
1.234 albertel 1552: $Apache::lonxml::curdepth.'_'.$env{'form.counter'};
1.217 albertel 1553: my $result ="<script type=\"text/javascript\">
1554: // <![CDATA[
1.231 albertel 1555: function $function_name() {newWindow=open('','new_W','width=500,height=500,scrollbars=1,resizable=yes');newWindow.$windowopen;newWindow.document.writeln('$start_page $output $end_page');newWindow.document.close();newWindow.focus()}
1.217 albertel 1556: // ]]>
1.263 raeburn 1557: </script><a href=\"javascript:$function_name();void(0);\">".&mt($tries_text)."</a><br />";
1.217 albertel 1558: #use Data::Dumper;
1559: #&Apache::lonnet::logthis(&Dumper(\%Apache::inputtags::submission_display));
1560: return $result;
1561: }
1562:
1.263 raeburn 1563: sub get_tries_text {
1564: my ($context) = @_;
1565: my $tries_text;
1566: if ($context eq 'link') {
1567: $tries_text = 'Previous Tries';
1568: } else {
1569: $tries_text = 'Tries';
1570: }
1571: if ( $Apache::lonhomework::type eq 'survey' ||
1572: $Apache::lonhomework::type eq 'surveycred' ||
1573: $Apache::lonhomework::type eq 'anonsurvey' ||
1574: $Apache::lonhomework::type eq 'anonsurveycred' ||
1575: $Apache::lonhomework::parsing_a_task) {
1576: if ($context eq 'link') {
1577: $tries_text = 'Previous Submissions';
1578: } else {
1579: $tries_text = 'Submissions';
1580: }
1581: }
1582: return $tries_text;
1583: }
1584:
1.1 albertel 1585: 1;
1586: __END__
1.249 jms 1587:
1588: =pod
1589:
1590: =back
1591:
1592: =cut
1.43 albertel 1593:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>