Annotation of loncom/homework/inputtags.pm, revision 1.354
1.43 albertel 1: # The LearningOnline Network with CAPA
2: # input definitons
1.47 albertel 3: #
1.354 ! raeburn 4: # $Id: inputtags.pm,v 1.353 2021/09/05 05:55:50 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.286 www 63: &Apache::lonxml::register('Apache::inputtags',('hiddensubmission','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:
1.310 foxr 128: #
129: # provides the onblur binding for spellchecking. This could be an
130: # empty string if spellchecking was not enabled.
131: # Jquery selector binding is done rather than setting an onblur
132: # attribute because we'll need to set the element's spellcheck language
133: # option dynamically so we need $(this) to be defined.
134: #
135: # @param id - The element id to bind.
136: # @param lang - Language in which spellchecking is desired.
137: # if undef, nothing is generated.
138: # @return string - onblur specification to do the requested spellchecking.
139: #
140: sub spellcheck_onblur {
141: my ($id, $lang) = @_;
142: my $result = '';
143: if ($lang) {
144:
145: $result = <<JAVASCRIPT;
146: <script type="text/javascript">
147: \$('\#$id').blur(function() {
148: doSpellcheck('\#$id', '$lang');
149: });
150: </script>
151:
152: JAVASCRIPT
153:
154:
155: }
156: return $result;
157: }
158:
1.103 albertel 159: sub check_for_duplicate_ids {
160: my %check;
161: foreach my $id (@Apache::inputtags::partlist,
162: @Apache::inputtags::responselist,
1.173 albertel 163: @Apache::inputtags::hintlist,
1.103 albertel 164: @Apache::inputtags::importlist) {
165: $check{$id}++;
166: }
167: my @duplicates;
168: foreach my $id (sort(keys(%check))) {
169: if ($check{$id} > 1) {
170: push(@duplicates,$id);
171: }
172: }
173: if (@duplicates) {
174: &Apache::lonxml::error("Duplicated ids found, problem will operate incorrectly. Duplicated ids seen: ",join(', ',@duplicates));
175: }
1.1 albertel 176: }
177:
1.14 albertel 178: sub start_input {
1.135 albertel 179: my ($parstack,$safeeval)=@_;
1.228 albertel 180: my $id = &Apache::lonxml::get_id($parstack,$safeeval);
1.135 albertel 181: push (@Apache::inputtags::input,$id);
182: push (@Apache::inputtags::inputlist,$id);
183: return $id;
1.14 albertel 184: }
185:
186: sub end_input {
1.135 albertel 187: pop @Apache::inputtags::input;
188: return '';
1.14 albertel 189: }
190:
1.124 www 191: sub addchars {
192: my ($fieldid,$addchars)=@_;
193: my $output='';
194: foreach (split(/\,/,$addchars)) {
195: $output.='<a href="javascript:void(document.forms.lonhomework.'.
196: $fieldid.'.value+=\''.$_.'\')">'.$_.'</a> ';
197: }
198: return $output;
199: }
200:
1.48 albertel 201: sub start_textfield {
1.185 albertel 202: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.135 albertel 203: my $result = "";
204: my $id = &start_input($parstack,$safeeval);
205: my $resid=$Apache::inputtags::response[-1];
206: if ($target eq 'web') {
207: $Apache::lonxml::evaluate--;
1.205 albertel 208: my $partid=$Apache::inputtags::part;
1.274 raeburn 209: my ($oldresponse,$newvariation);
210: if ((($Apache::lonhomework::history{"resource.$partid.type"} eq 'randomizetry') ||
211: ($Apache::lonhomework::type eq 'randomizetry')) &&
212: ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
213: if ($env{'form.'.$partid.'.rndseed'} ne
214: $Apache::lonhomework::history{"resource.$partid.rndseed"}) {
215: $newvariation = 1;
216: }
217: }
218: unless ($newvariation) {
1.317 raeburn 219: if ((($env{'form.grade_username'} eq '') && ($env{'form.grade_domain'} eq '')) ||
220: (($env{'form.grade_username'} eq $env{'user.name'}) &&
221: ($env{'form.grade_domain'} eq $env{'user.domain'}))) {
222: $oldresponse = $Apache::lonhomework::history{"resource.$partid.$resid.submission"};
223: } elsif (($Apache::lonhomework::history{"resource.$partid.type"} eq 'anonsurvey') ||
224: ($Apache::lonhomework::history{"resource.$partid.type"} eq 'anonsurveycred')) {
1.322 raeburn 225: $oldresponse = '* '.&mt('(only shown to submitter)').' *';
1.317 raeburn 226: } else {
227: $oldresponse = $Apache::lonhomework::history{"resource.$partid.$resid.submission"};
228: }
1.274 raeburn 229: }
1.135 albertel 230: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
231: my $cols = &Apache::lonxml::get_param('cols',$parstack,$safeeval);
232: if ( $cols eq '') { $cols = 80; }
233: my $rows = &Apache::lonxml::get_param('rows',$parstack,$safeeval);
1.143 www 234: if ( $rows eq '') { $rows = 16; }
1.135 albertel 235: my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval);
236: $result='';
1.310 foxr 237: my $tagident = 'HWVAL_' . $resid;
1.326 raeburn 238: my $itemid = 'HWVAL_'.$partid.'_'.$resid;
1.135 albertel 239: if ($addchars) {
1.310 foxr 240: $result.=&addchars($tagident, $addchars);
1.135 albertel 241: }
1.324 raeburn 242: my $textareaclass;
243: unless (&Apache::londefdef::is_inside_of($tagstack,
244: 'externalresponse')) {
245: $textareaclass = 'class="LC_richDetectHtml spellchecked"';
246: }
1.326 raeburn 247: $result.= '<textarea wrap="hard" name="'.$tagident.'" id="'.$itemid.'" ' .
1.308 foxr 248: 'rows="'.$rows.'" cols="'.$cols.'" '.$textareaclass
249: .'>'.
1.302 raeburn 250: &HTML::Entities::encode($oldresponse,'<>&"');
1.135 albertel 251: if ($oldresponse ne '') {
1.143 www 252:
1.135 albertel 253: #get rid of any startup text if the user has already responded
1.185 albertel 254: &Apache::lonxml::get_all_text("/textfield",$parser,$style);
1.135 albertel 255: }
256: } else {
1.205 albertel 257: #show past answer in the essayresponse case
258: if ($oldresponse =~ /\S/
259: && &Apache::londefdef::is_inside_of($tagstack,
260: 'essayresponse') ) {
261: $result='<table class="LC_pastsubmission"><tr><td>'.
1.323 bisitz 262: &HTML::Entities::encode($oldresponse,'"<>&').
263: '</td></tr></table>';
1.205 albertel 264: }
1.135 albertel 265: #get rid of any startup text
1.185 albertel 266: &Apache::lonxml::get_all_text("/textfield",$parser,$style);
1.61 albertel 267: }
1.135 albertel 268: } elsif ($target eq 'grade') {
1.185 albertel 269: my $seedtext=&Apache::lonxml::get_all_text("/textfield",$parser,
270: $style);
1.165 albertel 271: if ($seedtext eq $env{'form.HWVAL_'.$resid}) {
1.135 albertel 272: # if the seed text is still there it wasn't a real submission
1.165 albertel 273: $env{'form.HWVAL_'.$resid}='';
1.135 albertel 274: }
275: } elsif ($target eq 'edit') {
276: $result.=&Apache::edit::tag_start($target,$token);
277: $result.=&Apache::edit::text_arg('Rows:','rows',$token,4);
278: $result.=&Apache::edit::text_arg('Columns:','cols',$token,4);
279: $result.=&Apache::edit::text_arg
280: ('Click-On Texts (comma sep):','addchars',$token,10);
1.185 albertel 281: my $bodytext=&Apache::lonxml::get_all_text("/textfield",$parser,
282: $style);
1.135 albertel 283: $result.=&Apache::edit::editfield($token->[1],$bodytext,'Text you want to appear by default:',80,2);
1.314 raeburn 284: my $spell_langs = &spelling_languages();
1.312 raeburn 285: $result .= &Apache::edit::select_arg('Spellcheck for:', 'spellcheck',
1.314 raeburn 286: $spell_langs, $token);
1.135 albertel 287: } elsif ($target eq 'modified') {
288: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
289: $safeeval,'rows','cols',
1.311 foxr 290: 'addchars', 'spellcheck');
1.135 albertel 291: if ($constructtag) {
292: $result = &Apache::edit::rebuild_tag($token);
293: } else {
294: $result=$token->[4];
295: }
296: $result.=&Apache::edit::modifiedfield("/textfield",$parser);
297: } elsif ($target eq 'tex') {
298: my $number_of_lines = &Apache::lonxml::get_param('rows',$parstack,$safeeval);
299: my $width_of_box = &Apache::lonxml::get_param('cols',$parstack,$safeeval);
300: if ($$tagstack[-2] eq 'essayresponse' and $Apache::lonhomework::type eq 'exam') {
301: $result = '\fbox{\fbox{\parbox{\textwidth-5mm}{';
302: for (my $i=0;$i<int $number_of_lines*2;$i++) {$result.='\strut \\\\ ';}
303: $result.='\strut \\\\\strut \\\\\strut \\\\\strut \\\\}}}';
304: } else {
1.313 raeburn 305: if ($env{'form.pdfFormFields'} eq 'yes') {
306: my $fieldname = $env{'request.symb'}.
307: '&part_'. $Apache::inputtags::part.
308: '&textresponse'.
309: '&HWVAL_' . $Apache::inputtags::response['-1'];
310: $result.='\TextField[name='.$fieldname.',multiline=true,height=6\baselineskip,width=270,borderwidth=0,backgroundcolor={.85 .85 .85}]\\';
311: } else {
312: my $TeXwidth=$width_of_box/80;
313: $result = '\vskip 1 mm \fbox{\fbox{\parbox{'.$TeXwidth.'\textwidth-5mm}{';
314: for (my $i=0;$i<int $number_of_lines*2;$i++) {$result.='\strut \\\\ ';}
315: $result.='}}}\vskip 2 mm ';
316: }
1.135 albertel 317: }
1.60 albertel 318: }
1.135 albertel 319: return $result;
1.6 albertel 320: }
321:
1.48 albertel 322: sub end_textfield {
1.135 albertel 323: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
324: my $result;
325: if ($target eq 'web') {
1.310 foxr 326: my $spellcheck = &Apache::lonxml::get_param('spellcheck', $parstack, $safeeval);
1.135 albertel 327: $Apache::lonxml::evaluate++;
328: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
1.326 raeburn 329: my $partid=$Apache::inputtags::part;
1.310 foxr 330: my $resid = $Apache::inputtags::response[-1];
1.326 raeburn 331: my $itemid = 'HWVAL_' . $partid . '_' . $resid;
1.310 foxr 332: my $result = "</textarea>";
1.326 raeburn 333: $result .= &spellcheck_onblur($itemid, $spellcheck);
1.310 foxr 334: return $result;
1.135 albertel 335: }
336: } elsif ($target eq 'edit') {
337: $result=&Apache::edit::end_table();
338: }
339: &end_input;
340: return $result;
1.6 albertel 341: }
342:
1.190 albertel 343: sub exam_score_line {
1.188 albertel 344: my ($target) = @_;
1.190 albertel 345:
1.188 albertel 346: my $result;
347: if ($target eq 'tex') {
348: my $repetition = &Apache::response::repetition();
349: $result.='\begin{enumerate}';
1.190 albertel 350: if ($env{'request.state'} eq "construct" ) {$result.='\item[\strut]';}
1.188 albertel 351: foreach my $i (0..$repetition-1) {
352: $result.='\item[\textbf{'.
353: ($Apache::lonxml::counter+$i).
354: '}.]\textit{Leave blank on scoring form}\vskip 0 mm';
355: }
356: $result.= '\end{enumerate}';
1.190 albertel 357: }
358:
359: return $result;
360: }
361:
362: sub exam_box {
363: my ($target) = @_;
364: my $result;
1.188 albertel 365:
1.190 albertel 366: if ($target eq 'tex') {
367: $result .= '\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}';
368: $result .= &exam_score_line($target);
1.188 albertel 369: } elsif ($target eq 'web') {
370: my $id=$Apache::inputtags::response[-1];
371: $result.= '<br /><br />
372: <textarea name="HWVAL_'.$id.'" rows="4" cols="50">
373: </textarea> <br /><br />';
374: }
375: return $result;
376: }
377:
378: sub needs_exam_box {
379: my ($tagstack) = @_;
380: my @tags = ('formularesponse',
381: 'stringresponse',
382: 'reactionresponse',
383: 'organicresponse',
384: );
385:
386: foreach my $tag (@tags) {
387: if (grep(/\Q$tag\E/,@$tagstack)) {
388: return 1;
389: }
390: }
391: return 0;
392: }
393:
1.1 albertel 394: sub start_textline {
1.135 albertel 395: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
396: my $result = "";
1.210 albertel 397: my $input_id = &start_input($parstack,$safeeval);
1.310 foxr 398:
399: # The spellcheck attribute
400: # 1. enables spellchecking.
401: # 2. Provides the language code in which the spellchecking will be performed.
402:
403: my $spellcheck = &Apache::lonxml::get_param('spellcheck', $parstack, $safeeval);
1.135 albertel 404: if ($target eq 'web') {
405: $Apache::lonxml::evaluate--;
406: my $partid=$Apache::inputtags::part;
407: my $id=$Apache::inputtags::response[-1];
1.204 albertel 408: if (!&Apache::response::show_answer()) {
1.135 albertel 409: my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
410: my $maxlength;
411: if ($size eq '') { $size=20; } else {
1.214 albertel 412: if ($size < 20) {
413: $maxlength = ' maxlength="'.$size.'"';
414: }
1.135 albertel 415: }
1.274 raeburn 416: my ($oldresponse,$newvariation);
417: if ((($Apache::lonhomework::history{"resource.$partid.type"} eq 'randomizetry') ||
418: ($Apache::lonhomework::type eq 'randomizetry')) &&
419: ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
420: if ($env{'form.'.$partid.'.rndseed'} ne
421: $Apache::lonhomework::history{"resource.$partid.rndseed"}) {
422: $newvariation = 1;
423: }
424: }
425: unless ($newvariation) {
1.317 raeburn 426: if ((($env{'form.grade_username'} eq '') && ($env{'form.grade_domain'} eq '')) ||
427: (($env{'form.grade_username'} eq $env{'user.name'}) &&
428: ($env{'form.grade_domain'} eq $env{'user.domain'}))) {
429: $oldresponse = $Apache::lonhomework::history{"resource.$partid.$id.submission"};
430: } elsif (($Apache::lonhomework::history{"resource.$partid.type"} eq 'anonsurvey') ||
431: ($Apache::lonhomework::history{"resource.$partid.type"} eq 'anonsurveycred') ||
432: ($Apache::lonhomework::type eq 'anonsurvey') ||
433: ($Apache::lonhomework::type eq 'anonsurveycred')) {
1.322 raeburn 434: $oldresponse = '* '.&mt('(only shown to submitter)').' *';
1.317 raeburn 435: } else {
436: $oldresponse = $Apache::lonhomework::history{"resource.$partid.$id.submission"};
437: }
1.274 raeburn 438: &Apache::lonxml::debug("oldresponse $oldresponse is ".ref($oldresponse));
439: if (ref($oldresponse) eq 'ARRAY') {
440: $oldresponse = $oldresponse->[$#Apache::inputtags::inputlist];
441: }
442: $oldresponse = &HTML::Entities::encode($oldresponse,'<>&"');
443: $oldresponse =~ s/^\s+//;
444: $oldresponse =~ s/\s+$//;
445: $oldresponse =~ s/\s+/ /g;
446: }
1.135 albertel 447: if ($Apache::lonhomework::type ne 'exam') {
448: my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval);
449: $result='';
450: if ($addchars) {
451: $result.=&addchars('HWVAL_'.$id,$addchars);
452: }
1.157 albertel 453: my $readonly=&Apache::lonxml::get_param('readonly',$parstack,
454: $safeeval);
1.193 albertel 455: if (lc($readonly) eq 'yes'
456: || $Apache::inputtags::status[-1] eq 'CANNOT_ANSWER') {
1.157 albertel 457: $readonly=' readonly="readonly" ';
1.158 albertel 458: } else {
459: $readonly='';
1.157 albertel 460: }
1.193 albertel 461: my $name = 'HWVAL_'.$id;
1.326 raeburn 462: my $itemid = 'HWVAL_'.$partid.'_'.$id;
1.344 damieng 463: # NOTE: the input id should match the one given by defaut_homework input_id().
1.339 raeburn 464: my $input_tag_id = $itemid.'_'.$input_id;
1.193 albertel 465: if ($Apache::inputtags::status[-1] eq 'CANNOT_ANSWER') {
466: $name = "none";
467: }
1.310 foxr 468: $result.= '<input onkeydown="javascript:setSubmittedPart(\''.$partid.'\');"'
1.338 raeburn 469: . ' onfocus="javascript:disableAutoComplete(\''.$input_tag_id.'\');"'
1.331 raeburn 470: . ' type="text" '.$readonly.' name="'. $name . '"'
1.338 raeburn 471: . ' id="' . $input_tag_id . '"'
1.310 foxr 472: . ' value="'. $oldresponse.'"'
1.331 raeburn 473: . ' class="LC_textline spellchecked" size="'.$size.'"'.$maxlength.' />';
1.310 foxr 474:
1.326 raeburn 475: $result .= &spellcheck_onblur($itemid, $spellcheck);
1.338 raeburn 476: if (($Apache::inputtags::status['-1'] eq 'CAN_ANSWER') &&
477: (($tagstack->[-2] eq 'formularesponse') || ($tagstack->[-2] eq 'mathresponse')) &&
478: (&Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.turnoffeditor') ne 'yes')) {
479: $result.=&edit_mathresponse_button($input_tag_id);
480: }
1.135 albertel 481: }
1.188 albertel 482: if ($Apache::lonhomework::type eq 'exam'
483: && &needs_exam_box($tagstack)) {
484: $result.=&exam_box($target);
485: }
1.135 albertel 486: } else {
487: #right or wrong don't show what was last typed in.
1.208 albertel 488: my $count = scalar(@Apache::inputtags::inputlist)-1;
489: $result='<b>'.$Apache::inputtags::answertxt{$id}[$count].'</b>';
1.144 albertel 490: #$result='';
1.135 albertel 491: }
492: } elsif ($target eq 'edit') {
493: $result=&Apache::edit::tag_start($target,$token);
494: $result.=&Apache::edit::text_arg('Size:','size',$token,'5').
1.157 albertel 495: &Apache::edit::text_arg('Click-On Texts (comma sep):',
496: 'addchars',$token,10);
497: $result.=&Apache::edit::select_arg('Readonly:','readonly',
498: ['no','yes'],$token);
1.314 raeburn 499: my $spell_langs = &spelling_languages();
1.316 bisitz 500: $result.=&Apache::edit::select_arg('Spellcheck for:', 'spellcheck',
1.314 raeburn 501: $spell_langs, $token);
1.157 albertel 502: $result.=&Apache::edit::end_row();
503: $result.=&Apache::edit::end_table();
1.135 albertel 504: } elsif ($target eq 'modified') {
1.157 albertel 505: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
506: $safeeval,'size',
1.311 foxr 507: 'addchars','readonly', 'spellcheck');
1.135 albertel 508: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.188 albertel 509: } elsif ($target eq 'tex'
510: && $Apache::lonhomework::type ne 'exam') {
1.135 albertel 511: my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
512: if ($size != 0) {$size=$size*2; $size.=' mm';} else {$size='40 mm';}
1.257 onken 513: if ($env{'form.pdfFormFields'} eq 'yes'
514: && $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
1.246 onken 515: my $fieldname = $env{'request.symb'}.
516: '&part_'. $Apache::inputtags::part.
517: '&textresponse'.
518: '&HWVAL_' . $Apache::inputtags::response['-1'];
1.259 onken 519: $result='\textField{'.$fieldname.'}{'.$size.'}{12 bp}';
1.246 onken 520: } else {
521: $result='\framebox['.$size.'][s]{\tiny\strut}';
522: }
1.188 albertel 523: } elsif ($target eq 'tex'
524: && $Apache::lonhomework::type eq 'exam'
525: && &needs_exam_box($tagstack)) {
526: $result.=&exam_box($target);
1.135 albertel 527: }
528: return $result;
1.1 albertel 529: }
530:
531: sub end_textline {
1.135 albertel 532: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
533: if ($target eq 'web') { $Apache::lonxml::evaluate++; }
534: elsif ($target eq 'edit') { return ('','no'); }
1.208 albertel 535: &end_input();
1.135 albertel 536: return "";
1.9 albertel 537: }
538:
1.98 albertel 539: sub start_hiddenline {
540: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
541: my $result = "";
1.211 albertel 542: my $input_id = &start_input($parstack,$safeeval);
1.98 albertel 543: if ($target eq 'web') {
544: $Apache::lonxml::evaluate--;
545: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
546: my $partid=$Apache::inputtags::part;
547: my $id=$Apache::inputtags::response[-1];
1.211 albertel 548: my $oldresponse = $Apache::lonhomework::history{"resource.$partid.$id.submission"};
549: if (ref($oldresponse) eq 'ARRAY') {
550: $oldresponse = $oldresponse->[$#Apache::inputtags::inputlist];
551: }
552: $oldresponse = &HTML::Entities::encode($oldresponse,'<>&"');
553:
1.98 albertel 554: if ($Apache::lonhomework::type ne 'exam') {
555: $result= '<input type="hidden" name="HWVAL_'.$id.'" value="'.
556: $oldresponse.'" />';
557: }
558: }
559: } elsif ($target eq 'edit') {
560: $result=&Apache::edit::tag_start($target,$token);
561: $result.=&Apache::edit::end_table;
562: }
1.189 albertel 563:
564: if ( ($target eq 'web' || $target eq 'tex')
565: && $Apache::lonhomework::type eq 'exam'
566: && &needs_exam_box($tagstack)) {
567: $result.=&exam_box($target);
568: }
1.98 albertel 569: return $result;
570: }
571:
572: sub end_hiddenline {
1.135 albertel 573: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
574: if ($target eq 'web') { $Apache::lonxml::evaluate++; }
575: elsif ($target eq 'edit') { return ('','no'); }
1.211 albertel 576: &end_input();
1.135 albertel 577: return "";
1.98 albertel 578: }
579:
1.286 www 580:
581: sub start_hiddensubmission {
582: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
583: my $result = "";
584: my $input_id = &start_input($parstack,$safeeval);
585: if ($target eq 'web') {
586: $Apache::lonxml::evaluate--;
587: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
588: my $partid=$Apache::inputtags::part;
589: my $id=$Apache::inputtags::response[-1];
590: if ($Apache::lonhomework::type ne 'exam') {
591: my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
592: $value = &HTML::Entities::encode($value,'<>&"');
593: $result= '<input type="hidden" name="HWVAL_'.$id.'" value="'.$value.'" />';
594: }
595: }
596: } elsif ($target eq 'edit') {
597: $result=&Apache::edit::tag_start($target,$token);
598: $result.=&Apache::edit::text_arg('Value:','value',$token,'15');
599: $result.=&Apache::edit::end_row();
600: $result.=&Apache::edit::end_table();
601: } elsif ($target eq 'modified') {
602: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
603: $safeeval,'value');
604: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
605: }
606:
607: if ( ($target eq 'web' || $target eq 'tex')
608: && $Apache::lonhomework::type eq 'exam'
609: && &needs_exam_box($tagstack)) {
610: $result.=&exam_box($target);
611: }
612: return $result;
613: }
614:
615: sub end_hiddensubmission {
616: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
617: if ($target eq 'web') { $Apache::lonxml::evaluate++; }
618: elsif ($target eq 'edit') { return ('','no'); }
619: &end_input();
620: return "";
621: }
622:
1.249 jms 623: =pod
624:
625: =item file_selector()
626:
627: $part -> partid
628: $id -> responseid
629: $uploadefiletypes -> comma seperated list of extensions allowed or * for any
1.252 raeburn 630: $which -> 'uploadonly' -> only newly uploaded files
1.249 jms 631: 'portfolioonly' -> only allow files from portfolio
632: 'both' -> allow files from either location
633: $extratext -> additional text to go between the link and the input box
1.252 raeburn 634: $maxfilesize -> maximum cumulative filesize for submitted files (in MB).
1.249 jms 635: returns a table row <tr>
636:
637: =cut
638:
1.160 albertel 639: sub file_selector {
1.252 raeburn 640: my ($part,$id,$uploadedfiletypes,$which,$extratext,$maxfilesize)=@_;
1.160 albertel 641: if (!$uploadedfiletypes) { return ''; }
1.167 albertel 642:
643: my $jspart=$part;
644: $jspart=~s/\./_/g;
645:
1.160 albertel 646: my $result;
1.265 raeburn 647: my $current_files_display = ¤t_file_submissions($part,$id);
648: my $addfiles;
649: if ($current_files_display) {
1.329 raeburn 650: $result .= &Apache::lonhtmlcommon::row_title(&mt('Files currently selected for submission')).
1.265 raeburn 651: $current_files_display.
652: &Apache::lonhtmlcommon::row_closure();
653: $addfiles = &mt('Submit other file(s)');
654: } else {
655: $addfiles = &mt('Choose file(s) to submit');
656: }
657: $result .= &Apache::lonhtmlcommon::row_title($addfiles);
658: my $constraints;
659: if ($uploadedfiletypes ne '*') {
660: $constraints =
661: &mt('Allowed filetypes: [_1]','<b>'.$uploadedfiletypes.'</b>').'<br />';
662: }
663: if ($maxfilesize) {
1.319 bisitz 664: $constraints .= &mt('Combined size of all files not to exceed: [_1] MB.',
1.265 raeburn 665: '<b>'.$maxfilesize.'</b>').'<br />';
666: }
667: if ($constraints) {
668: $result .= $constraints.'<br />';
1.162 albertel 669: }
1.349 raeburn 670: if ($which eq 'uploadonly' || $which eq 'both') {
1.336 musolffc 671: my $free_space = $maxfilesize * 1048576;
672: $result .= &mt('Submit a file: (only one file per submission)').
673: ' <br /><input type="file" size="50" name="HWFILE'.$jspart.'_'.$id.
1.348 raeburn 674: '" id="HWFILE'.$jspart.'_'.$id.'" class="LC_flUpload LC_hwkfile" />'.
675: '<input type="hidden" id="LC_free_space_'.$jspart.'_'.$id.'"'.
676: ' value="'.$free_space.'" /><br />';
1.349 raeburn 677: }
1.265 raeburn 678: if ( $which eq 'both') {
1.160 albertel 679: $result.='<br />'.'<strong>'.&mt('OR:').'</strong><br />';
680: }
1.303 raeburn 681: if ($which eq 'portfolioonly' || $which eq 'both') {
682: my $symb = $env{'request.symb'};
683: (undef,undef,my $res)=&Apache::lonnet::decode_symb($symb);
684: my $showsymb;
685: # If resource is a .task and URL is unencrypted, include symb in query string
686: # for url opened in portfolio file selection window. Can be used to override
687: # blocking of portfolio access resulting from an exam event in a different course.
688: if ($res =~ /\.task$/i) {
689: my $encsymb = &Apache::lonenc::check_encrypt($symb);
690: if ($symb eq $encsymb) {
691: $showsymb = $symb;
692: }
693: }
1.306 raeburn 694: $result.=$extratext.'<a href='."'".'javascript:void(window.open("/adm/portfolio?mode=selectfile&fieldname='.$env{'form.request.prefix'}.'HWPORT'.$jspart.'_'.$id.'&symb='.$showsymb.'","cat","height=600,width=800,scrollbars=1,resizable=1,menubar=2,location=1"))'."'".'>'.
1.265 raeburn 695: &mt('Select Portfolio Files: (one or more files per submission)').'</a><br />'.
1.167 albertel 696: '<input type="text" size="50" name="HWPORT'.$jspart.'_'.$id.'" value="" />'.
1.160 albertel 697: '<br />';
698: }
1.265 raeburn 699: $result.=&Apache::lonhtmlcommon::row_closure(1);
1.160 albertel 700: return $result;
701: }
702:
1.265 raeburn 703: sub current_file_submissions {
1.205 albertel 704: my ($part,$id) = @_;
1.265 raeburn 705: my $jspart=$part;
706: $jspart=~s/\./_/g;
1.270 raeburn 707: my $uploadedfile=$Apache::lonhomework::history{"resource.$part.$id.uploadedfile"};
1.265 raeburn 708: my $portfiles=$Apache::lonhomework::history{"resource.$part.$id.portfiles"};
709: return if (($uploadedfile eq '') && ($portfiles !~/[^\s]/));
1.329 raeburn 710: my @unversioned;
711: foreach my $file (split(/\s*,\s*/,&unescape($portfiles))) {
712: my ($path,$name) = ($file =~ m{^(.*/)([^/]+)$});
713: my ($origname,$version,$ext) = &Apache::lonnet::file_name_version_ext($name);
714: unless ($version) {
715: push(@unversioned,$file);
716: }
717: }
718: return if (!@unversioned);
1.320 raeburn 719: my $header = &portpath_popup_js().
720: &Apache::loncommon::start_data_table().
1.270 raeburn 721: &Apache::loncommon::start_data_table_header_row();
722: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
723: $header .= '<th>'.&mt('Delete?').'</th>';
724: }
1.271 raeburn 725: $header .= '<th>'.&mt('File').'</th>'.
1.265 raeburn 726: '<th>'.&mt('Size (MB)').'</th>'.
727: '<th>'.&mt('Last Modified').'</th>'.
728: &Apache::loncommon::end_data_table_header_row();
1.329 raeburn 729: my ($symb,$crsid,$udom,$uname)=&Apache::lonnet::whichuser();
1.265 raeburn 730: my ($cdom,$cnum) = ($crsid =~ /^($LONCAPA::match_domain)_($LONCAPA::match_courseid)$/);
1.271 raeburn 731: my ($result,$header_shown,%okfiles,%rows,%legacy,@bad_file_list);
1.265 raeburn 732: if ($uploadedfile) {
733: my $url=$Apache::lonhomework::history{"resource.$part.$id.uploadedurl"};
1.270 raeburn 734: my $link = &HTML::Entities::encode($url,'<>&"');
735: my ($path,$name) = ($url =~ m{^(/uploaded/\Q$udom\E/\Q$uname\E/essayresponse.*/)([^/]+)$});
1.265 raeburn 736: my ($status,$hashref,$error) =
1.270 raeburn 737: ¤t_file_info($url,$link,$name,$path);
1.265 raeburn 738: if ($status eq 'ok') {
739: push(@{$okfiles{$name}},$url);
740: $rows{$url} = $hashref;
1.271 raeburn 741: $legacy{$url} = 1;
1.265 raeburn 742: &Apache::lonxml::extlink($url);
743: &Apache::lonnet::allowuploaded('/adm/essayresponse',$url);
744: } else {
745: push(@bad_file_list,$error);
746: }
747: }
1.329 raeburn 748: if (@unversioned > 0) {
1.265 raeburn 749: my $prefix = "/uploaded/$udom/$uname/portfolio";
1.329 raeburn 750: foreach my $file (@unversioned) {
1.265 raeburn 751: my ($path,$name) = ($file =~ m{^(.*/)([^/]+)$});
752: my $url = $prefix.$path.$name;
753: my $uploadedfile = &HTML::Entities::encode($url,'<>&"');
754: my ($status,$hashref,$error) =
755: ¤t_file_info($url,$uploadedfile,$name,$path);
756: if ($status eq 'ok') {
757: push(@{$okfiles{$name}},$url);
758: $rows{$url} = $hashref;
759: } else {
760: push(@bad_file_list,$error);
761: }
762: }
763: }
1.276 raeburn 764: my $num = 0;
1.265 raeburn 765: foreach my $name (sort(keys(%okfiles))) {
766: if (ref($okfiles{$name}) eq 'ARRAY') {
767: foreach my $url (@{$okfiles{$name}}) {
768: if (ref($rows{$url}) eq 'HASH') {
769: my $link = $rows{$url}{link};
770: my $portfile = $rows{$url}{path}.$rows{$url}{name};
771: $portfile = &HTML::Entities::encode($portfile,'<>&"');
772: if ($link) {
773: my $icon=&Apache::loncommon::icon($url);
774: unless ($header_shown) {
775: $result .= $header;
776: $header_shown = 1;
777: }
778: $result.=
1.270 raeburn 779: &Apache::loncommon::start_data_table_row()."\n";
780: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
781: $result .=
782: '<td valign="bottom"><input type="checkbox" name="HWFILE'.$jspart.'_'.$id.'_delete"'.
1.273 raeburn 783: ' value="'.$portfile.'" id="HWFILE'.$jspart.'_'.$id.'_'.$num.'_delete" /></td>'."\n";
784: $num ++;
1.270 raeburn 785: }
1.320 raeburn 786: my $pathid = 'HWFILE'.$jspart.'_'.$id.'_'.$num.'_path';
787: my $pathidtext = $pathid.'text';
788: my ($showname,$showpath);
1.271 raeburn 789: if ($legacy{$url}) {
790: $showname = $name.' '.&mt('not in portfolio');
1.320 raeburn 791: } else {
792: $showname = $name;
793: $showpath = '<br />'.
794: '<span id="'.$pathidtext.'" class="LC_cusr_subheading">'.
795: '<a href="javascript:showPortPath('."'$pathid','$pathidtext'".');" '.
796: 'class="LC_menubuttons_link">'.
797: &mt('(Show path)').'</a></span>'.
798: '<div id="'.$pathid.'" class="LC_dccid">'.$rows{$url}{path}.$name.
799: '</div>';
1.271 raeburn 800: }
1.270 raeburn 801: $result .=
1.265 raeburn 802: '<td><a href="'.$link.'"><img src="'.$icon.
1.320 raeburn 803: '" border="0" alt="" />'.$showname.'</a>'.$showpath.'</td>'."\n".
1.265 raeburn 804: '<td align="right" valign="bottom">'.$rows{$url}{size}.'</td>'."\n".
805: '<td align="right" valign="bottom">'.$rows{$url}{lastmodified}.'</td>'."\n".
806: &Apache::loncommon::end_data_table_row();
807: }
808: }
809: }
810: }
811: }
812: if ($header_shown) {
1.307 raeburn 813: $result .= &Apache::loncommon::end_data_table();
814: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
815: $result .= '<br /><span class="LC_warning">'.
816: &mt('Exclude existing file(s) from grading by checking the "Delete?" checkbox(es) and clicking "Submit Answer"').'</span>';
817: }
1.205 albertel 818: }
819: if (@bad_file_list) {
1.265 raeburn 820: my $bad_files = '<span class="LC_filename">'.
821: join('</span>, <span class="LC_filename">',@bad_file_list).
822: '</span>';
823: $result.='<p class="LC_error">'.
824: &mt("These file(s) don't exist: [_1]",$bad_files).
825: '</p>';
1.205 albertel 826: }
827: return $result;
1.265 raeburn 828: }
1.205 albertel 829:
1.265 raeburn 830: sub current_file_info {
831: my ($url,$uploadedfile,$name,$path) = @_;
832: my ($status,$error,%info);
833: my @stat = &Apache::lonnet::stat_file($url);
834: if ((@stat) && ($stat[0] ne 'no_such_dir')) {
835: my ($lastmod,$size);
836: if ($stat[9] =~ /^\d+$/) {
837: $lastmod = &Apache::lonlocal::locallocaltime($stat[9]);
838: }
839: $size = $stat[7]/(1024*1024);
840: $size = sprintf("%.3f",$size);
841: %info = (
842: link => $uploadedfile,
843: name => $name,
844: path => $path,
845: size => $size,
846: lastmodified => $lastmod,
847: );
848: $status = 'ok';
849: } else {
850: &Apache::lonnet::logthis("bad file is $url");
851: my $icon=&Apache::loncommon::icon($url);
852: $error = '<a href="'.$url.'"><img src="'.$icon.
853: '" border="0" />'.$uploadedfile.'</a>';
854: }
855: return ($status,\%info,$error);
1.205 albertel 856: }
857:
1.320 raeburn 858: sub portpath_popup_js {
859: my %lt = &Apache::lonlocal::texthash(
860: show => '(Show path)',
861: hide => '(Hide)',
862: );
863: return <<"END";
864: <script type="text/javascript">
865: // <![CDATA[
866:
867: function showPortPath(id,idtext) {
868: document.getElementById(id).style.display='block';
869: document.getElementById(id).style.textAlign='left';
870: document.getElementById(id).style.textFace='normal';
871: if (document.getElementById(idtext)) {
872: document.getElementById(idtext).innerHTML ='<a href="javascript:hidePortPath(\\''+id+'\\',\\''+idtext+'\\'); '+
873: '"class="LC_menubuttons_link">$lt{'hide'}</a> ';
874: }
875: return;
876: }
877:
878: function hidePortPath(id,idtext) {
879: if (document.getElementById(id)) {
880: document.getElementById(id).style.display='none';
881: }
882: if (document.getElementById(idtext)) {
883: document.getElementById(idtext).innerHTML ='<a href="javascript:showPortPath(\\''+id+'\\',\\''+idtext+'\\');" '+
884: 'class="LC_menubuttons_link">$lt{'show'}</a>';
885: }
886: return;
887: }
888:
889: // ]]>
890: </script>
891:
892: END
893: }
894:
1.179 albertel 895: sub valid_award {
896: my ($award) =@_;
1.182 albertel 897: foreach my $possibleaward ('EXTRA_ANSWER','MISSING_ANSWER', 'ERROR',
1.328 raeburn 898: 'NO_RESPONSE','WRONG_NUMBOXESCHECKED',
1.179 albertel 899: 'TOO_LONG', 'UNIT_INVALID_INSTRUCTOR',
900: 'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE',
901: 'UNIT_FAIL', 'NO_UNIT',
902: 'UNIT_NOTNEEDED', 'WANTED_NUMERIC',
1.272 www 903: 'BAD_FORMULA', 'NOT_FUNCTION', 'WRONG_FORMAT',
904: 'INTERNAL_ERROR', 'SIG_FAIL', 'INCORRECT',
1.179 albertel 905: 'MISORDERED_RANK', 'INVALID_FILETYPE',
1.264 raeburn 906: 'EXCESS_FILESIZE', 'FILENAME_INUSE',
907: 'DRAFT', 'SUBMITTED', 'SUBMITTED_CREDIT',
1.261 raeburn 908: 'ANONYMOUS', 'ANONYMOUS_CREDIT',
909: 'ASSIGNED_SCORE', 'APPROX_ANS',
910: 'EXACT_ANS','COMMA_FAIL') {
1.179 albertel 911: if ($award eq $possibleaward) { return 1; }
912: }
913: return 0;
914: }
915:
1.207 albertel 916: {
917: my @awards = ('EXTRA_ANSWER', 'MISSING_ANSWER', 'ERROR', 'NO_RESPONSE',
1.335 raeburn 918: 'WRONG_NUMBOXESCHECKED','TOO_LONG',
1.207 albertel 919: 'UNIT_INVALID_INSTRUCTOR', 'UNIT_INVALID_STUDENT',
920: 'UNIT_IRRECONCIBLE', 'UNIT_FAIL', 'NO_UNIT',
1.272 www 921: 'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA', 'NOT_FUNCTION',
922: 'WRONG_FORMAT', 'INTERNAL_ERROR',
1.207 albertel 923: 'COMMA_FAIL', 'SIG_FAIL', 'INCORRECT', 'MISORDERED_RANK',
1.264 raeburn 924: 'INVALID_FILETYPE', 'EXCESS_FILESIZE', 'FILENAME_INUSE',
925: 'DRAFT', 'SUBMITTED',
1.261 raeburn 926: 'SUBMITTED_CREDIT', 'ANONYMOUS', 'ANONYMOUS_CREDIT',
1.248 raeburn 927: 'ASSIGNED_SCORE', 'APPROX_ANS', 'EXACT_ANS');
1.207 albertel 928: my $i=0;
929: my %fwd_awards = map { ($_,$i++) } @awards;
930: my $max=scalar(@awards);
931: @awards=reverse(@awards);
1.208 albertel 932: $i=0;
1.207 albertel 933: my %rev_awards = map { ($_,$i++) } @awards;
934:
1.232 albertel 935: sub awarddetail_to_awarded {
936: my ($awarddetail) = @_;
937: if ($awarddetail eq 'EXACT_ANS'
938: || $awarddetail eq 'APPROX_ANS') {
939: return 1;
940: }
941: return 0;
942: }
943:
1.233 albertel 944: sub hide_award {
945: my ($award) = @_;
946: if (&Apache::lonhomework::show_no_problem_status()) {
947: return 1;
948: }
949: if ($award =~
1.261 raeburn 950: /^(?:EXACT_ANS|APPROX_ANS|SUBMITTED|SUBMITTED_CREDIT|ANONYMOUS|ANONYMOUS_CREDIT|ASSIGNED_SCORE|INCORRECT)/) {
1.233 albertel 951: return 1;
952: }
953: return 0;
954: }
955:
1.9 albertel 956: sub finalizeawards {
1.232 albertel 957: my ($awardref,$msgref,$nameref,$reverse,$final_scantron)=@_;
1.207 albertel 958: my $result;
1.136 albertel 959: if ($#$awardref == -1) { $result = "NO_RESPONSE"; }
1.135 albertel 960: if ($result eq '' ) {
961: my $blankcount;
1.207 albertel 962: foreach my $award (@$awardref) {
1.135 albertel 963: if ($award eq '') {
964: $result='MISSING_ANSWER';
965: $blankcount++;
966: }
967: }
1.232 albertel 968: if ($blankcount == ($#$awardref + 1)) {
969: return ('NO_RESPONSE');
970: }
1.135 albertel 971: }
1.251 www 972:
973: if ($Apache::lonxml::internal_error) { $result='INTERNAL_ERROR'; }
974:
1.232 albertel 975: if (!$final_scantron && defined($result)) { return ($result); }
1.181 albertel 976:
1.232 albertel 977: # if in scantron mode, if the award for any response is
978: # assigned score, then the part gets an assigned score
979: if ($final_scantron
980: && grep {$_ eq 'ASSIGNED_SCORE'} (@$awardref)) {
981: return ('ASSIGNED_SCORE');
982: }
983:
984: # if in scantron mode, if the award for any response is
985: # correct and there are non-correct responses,
986: # then the part gets an assigned score
987: if ($final_scantron
988: && (grep { $_ eq 'EXACT_ANS' ||
989: $_ eq 'APPROX_ANS' } (@$awardref))
990: && (grep { $_ ne 'EXACT_ANS' &&
991: $_ ne 'APPROX_ANS' } (@$awardref))) {
992: return ('ASSIGNED_SCORE');
993: }
1.181 albertel 994: # these awards are ordered from most important error through best correct
1.207 albertel 995: my $awards = (!$reverse) ? \%fwd_awards : \%rev_awards ;
996:
997: my $best = $max;
998: my $j=0;
999: my $which;
1000: foreach my $award (@$awardref) {
1001: if ($awards->{$award} < $best) {
1002: $best = $awards->{$award};
1003: $which = $j;
1004: }
1005: $j++;
1006: }
1.232 albertel 1007:
1.334 raeburn 1008: # if at least one response item is set to include lenient grading
1009: # and that item is partially correct then overall award reflects
1010: # that, unless an award for one of the other response items does
1011: # not fall within the basic awards for correct or incorrect.
1012: if ($Apache::inputtags::leniency) {
1013: if (($$awardref[$which] eq 'INCORRECT')
1014: && (grep { $_ eq 'EXACT_ANS' ||
1015: $_ eq 'APPROX_ANS' ||
1016: $_ eq 'ASSIGNED_SCORE' } (@$awardref))
1017: && !((grep { $_ ne 'INCORRECT' &&
1018: $_ ne 'EXACT_ANS' &&
1019: $_ ne 'APPROX_ANS' &&
1020: $_ ne 'ASSIGNED_SCORE' } (@$awardref)))) {
1021: return ('ASSIGNED_SCORE');
1022: }
1023: }
1024:
1.207 albertel 1025: if (defined($which)) {
1026: if (ref($nameref)) {
1027: return ($$awardref[$which],$$msgref[$which],$$nameref[$which]);
1028: } else {
1029: return ($$awardref[$which],$$msgref[$which]);
1030: }
1.135 albertel 1031: }
1.136 albertel 1032: return ('ERROR',undef);
1.9 albertel 1033: }
1.207 albertel 1034: }
1.9 albertel 1035:
1.10 albertel 1036: sub decideoutput {
1.325 raeburn 1037: my ($award,$awarded,$awardmsg,$solved,$previous,$target,$nocorrect,$tdclass)=@_;
1.251 www 1038:
1.135 albertel 1039: my $message='';
1040: my $button=0;
1041: my $previousmsg;
1.221 albertel 1042: my $css_class='orange';
1.148 albertel 1043: my $added_computer_text=0;
1.221 albertel 1044: my %possible_class =
1045: ( 'correct' => 'LC_answer_correct',
1046: 'charged_try' => 'LC_answer_charged_try',
1047: 'not_charged_try' => 'LC_answer_not_charged_try',
1048: 'no_grade' => 'LC_answer_no_grade',
1049: 'no_message' => 'LC_no_message',
1.350 raeburn 1050: 'no_charge_warn' => 'LC_answer_warning',
1.135 albertel 1051: );
1.169 albertel 1052:
1.180 albertel 1053: my $part = $Apache::inputtags::part;
1.236 raeburn 1054: my $tohandgrade = &Apache::lonnet::EXT("resource.$part.handgrade");
1055: my $handgrade = ('yes' eq lc($tohandgrade));
1.282 www 1056: #
1057: # Should "Computer's Answer" be displayed?
1058: # Should not be displayed if still answerable,
1059: # if the problem is handgraded,
1060: # or if the problem does not give a correct answer
1061: #
1.180 albertel 1062:
1.282 www 1063: my $computer = ($handgrade || $nocorrect)? ''
1.342 raeburn 1064: : &mt("Computer's answer now shown above.");
1.180 albertel 1065: &Apache::lonxml::debug("handgrade has :$handgrade:");
1066:
1.135 albertel 1067: if ($previous) { $previousmsg=&mt('You have entered that answer before'); }
1068:
1.194 banghart 1069: if ($solved =~ /^correct/) {
1.221 albertel 1070: $css_class=$possible_class{'correct'};
1.170 albertel 1071: $message=&mt('You are correct.');
1072: if ($awarded < 1 && $awarded > 0) {
1073: $message=&mt('You are partially correct.');
1.221 albertel 1074: $css_class=$possible_class{'not_charged_try'};
1.170 albertel 1075: } elsif ($awarded < 1) {
1076: $message=&mt('Incorrect.');
1.221 albertel 1077: $css_class=$possible_class{'charged_try'};
1.170 albertel 1078: }
1.291 www 1079: if ($handgrade ||
1080: ($env{'request.filename'}=~/\/res\/lib\/templates\/(examupload|DropBox).problem$/)) {
1.172 albertel 1081: $message = &mt("A score has been assigned.");
1082: $added_computer_text=1;
1.135 albertel 1083: } else {
1.172 albertel 1084: if ($target eq 'tex') {
1085: $message = '\textbf{'.$message.'}';
1086: } else {
1087: $message = "<b>".$message."</b>";
1.342 raeburn 1088: if ($computer) {
1089: $message = "$computer $message";
1090: }
1.135 albertel 1091: }
1.172 albertel 1092: $added_computer_text=1;
1.235 albertel 1093: if ($awarded > 0) {
1094: my ($symb) = &Apache::lonnet::whichuser();
1095: if (($symb ne '')
1096: &&
1097: ($env{'course.'.$env{'request.course.id'}.
1.237 www 1098: '.disable_receipt_display'} ne 'yes') &&
1099: ($Apache::lonhomework::type ne 'practice')) {
1.235 albertel 1100: $message.=(($target eq 'web')?'<br />':' ').
1.256 biermanm 1101: &mt('Your receipt no. is [_1]',
1.235 albertel 1102: (&Apache::lonnet::receipt($Apache::inputtags::part).
1103: (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):'')));
1104: }
1.135 albertel 1105: }
1106: }
1.299 raeburn 1107: if ($awarded >= 1) {
1.296 raeburn 1108: $button=0;
1.299 raeburn 1109: } elsif (&Apache::lonnet::EXT("resource.$part.retrypartial") !~/^1|on|yes$/i) {
1.296 raeburn 1110: $button=0;
1.299 raeburn 1111: } else {
1.296 raeburn 1112: $button=1;
1113: }
1.135 albertel 1114: $previousmsg='';
1115: } elsif ($solved =~ /^excused/) {
1116: if ($target eq 'tex') {
1117: $message = ' \textbf{'.&mt('You are excused from the problem.').'} ';
1118: } else {
1119: $message = "<b>".&mt('You are excused from the problem.')."</b>";
1120: }
1.221 albertel 1121: $css_class=$possible_class{'charged_try'};
1.135 albertel 1122: $button=0;
1123: $previousmsg='';
1124: } elsif ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
1125: if ($solved =~ /^incorrect/ || $solved eq '') {
1.144 albertel 1126: $message = &mt("Incorrect").".";
1.221 albertel 1127: $css_class=$possible_class{'charged_try'};
1.135 albertel 1128: $button=1;
1129: } else {
1.144 albertel 1130: if ($target eq 'tex') {
1131: $message = '\textbf{'.&mt('You are correct.').'}';
1132: } else {
1133: $message = "<b>".&mt('You are correct.')."</b>";
1.342 raeburn 1134: if ($computer) {
1135: $message = "$computer $message";
1136: }
1.144 albertel 1137: }
1.148 albertel 1138: $added_computer_text=1;
1.235 albertel 1139: if ($awarded > 0
1140: && $env{'course.'.
1.165 albertel 1141: $env{'request.course.id'}.
1.235 albertel 1142: '.disable_receipt_display'} ne 'yes') {
1.135 albertel 1143: $message.=(($target eq 'web')?'<br />':' ').
1.235 albertel 1144: &mt('Your receipt is [_1]',
1145: (&Apache::lonnet::receipt($Apache::inputtags::part).
1146: (($target eq 'web')?&Apache::loncommon::help_open_topic('Receipt'):'')));
1.135 albertel 1147: }
1.221 albertel 1148: $css_class=$possible_class{'correct'};
1.135 albertel 1149: $button=0;
1150: $previousmsg='';
1151: }
1152: } elsif ($award eq 'NO_RESPONSE') {
1153: $message = '';
1.221 albertel 1154: $css_class=$possible_class{'no_feedback'};
1.135 albertel 1155: $button=1;
1.182 albertel 1156: } elsif ($award eq 'EXTRA_ANSWER') {
1157: $message = &mt('Some extra items were submitted.');
1.221 albertel 1158: $css_class=$possible_class{'not_charged_try'};
1.182 albertel 1159: $button = 1;
1.135 albertel 1160: } elsif ($award eq 'MISSING_ANSWER') {
1.245 bisitz 1161: $message = &mt('Some items were not submitted.');
1162: if ($target ne 'tex') {
1163: $message .= &Apache::loncommon::help_open_topic('Some_Items_Were_Not_Submitted');
1164: }
1.354 ! raeburn 1165: if (&Apache::lonhomework::show_some_problem_status()) {
! 1166: $css_class=$possible_class{'no_charge_warn'};
! 1167: } else {
! 1168: $css_class=$possible_class{'not_charged_try'};
! 1169: }
1.135 albertel 1170: $button = 1;
1.328 raeburn 1171: } elsif ($award eq 'WRONG_NUMBOXESCHECKED') {
1172: $message = &mt('Number of boxes checked outside permissible range (either too few or too many).');
1173: if ($target ne 'tex') {
1174: $message .= &Apache::loncommon::help_open_topic('Wrong_Num_Boxes_Checked');
1175: }
1176: $css_class=$possible_class{'not_charged_try'};
1177: $button = 1;
1.135 albertel 1178: } elsif ($award eq 'ERROR') {
1.247 bisitz 1179: $message = &mt('An error occurred while grading your answer.');
1.221 albertel 1180: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 1181: $button = 1;
1182: } elsif ($award eq 'TOO_LONG') {
1183: $message = &mt("The submitted answer was too long.");
1.221 albertel 1184: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 1185: $button=1;
1186: } elsif ($award eq 'WANTED_NUMERIC') {
1187: $message = &mt("This question expects a numeric answer.");
1.221 albertel 1188: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 1189: $button=1;
1190: } elsif ($award eq 'MISORDERED_RANK') {
1.242 bisitz 1191: $message = &mt('You have provided an invalid ranking.');
1192: if ($target ne 'tex') {
1193: $message.=' '.&mt('Please refer to [_1]',&Apache::loncommon::help_open_topic('Ranking_Problems',&mt('help on ranking problems')));
1194: }
1.221 albertel 1195: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 1196: $button=1;
1.248 raeburn 1197: } elsif ($award eq 'EXCESS_FILESIZE') {
1.321 raeburn 1198: $message = &mt("Submission won't be graded. The combined size of submitted files exceeded the amount allowed.");
1.248 raeburn 1199: $css_class=$possible_class{'not_charged_try'};
1200: $button=1;
1.264 raeburn 1201: } elsif ($award eq 'FILENAME_INUSE') {
1202: $message = &mt('You have already uploaded a file with that filename.');
1203: if ($target eq 'tex') {
1204: $message.= "\\\\\n";
1205: } else {
1206: $message .= '<br />';
1207: }
1.315 bisitz 1208: $message .= &mt('Please use a different filename.');
1.264 raeburn 1209: $css_class=$possible_class{'not_charged_try'};
1210: $button=1;
1.135 albertel 1211: } elsif ($award eq 'INVALID_FILETYPE') {
1.255 bisitz 1212: $message = &mt("Submission won't be graded. The type of file submitted is not allowed.");
1.221 albertel 1213: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 1214: $button=1;
1215: } elsif ($award eq 'SIG_FAIL') {
1.145 albertel 1216: my ($used,$min,$max)=split(':',$awardmsg);
1.212 albertel 1217: my $word = ($used < $min) ? 'more' : 'fewer';
1.352 raeburn 1218: $message = &mt("Submission not graded. Use $word significant figures.");
1.350 raeburn 1219: if (&Apache::lonhomework::show_some_problem_status()) {
1220: $css_class=$possible_class{'no_charge_warn'};
1.351 raeburn 1221: } else {
1222: $css_class=$possible_class{'not_charged_try'};
1.350 raeburn 1223: }
1.135 albertel 1224: $button=1;
1.137 albertel 1225: } elsif ($award eq 'UNIT_INVALID_INSTRUCTOR') {
1226: $message = &mt('Error in instructor specifed unit. This error has been reported to the instructor.', $awardmsg);
1227: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');}
1.221 albertel 1228: $css_class=$possible_class{'not_charged_try'};
1.137 albertel 1229: $button=1;
1230: } elsif ($award eq 'UNIT_INVALID_STUDENT') {
1.155 albertel 1231: $message = &mt('Unable to interpret units. Computer reads units as "[_1]".',&markup_unit($awardmsg,$target));
1.137 albertel 1232: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');}
1.354 ! raeburn 1233: if (&Apache::lonhomework::show_some_problem_status()) {
! 1234: $css_class=$possible_class{'no_charge_warn'};
! 1235: } else {
! 1236: $css_class=$possible_class{'not_charged_try'};
! 1237: }
1.137 albertel 1238: $button=1;
1.140 matthew 1239: } elsif ($award eq 'UNIT_FAIL' || $award eq 'UNIT_IRRECONCIBLE') {
1.155 albertel 1240: $message = &mt('Incompatible units. No conversion found between "[_1]" and the required units.',&markup_unit($awardmsg,$target));
1.136 albertel 1241: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units');}
1.354 ! raeburn 1242: if (&Apache::lonhomework::show_some_problem_status()) {
! 1243: $css_class=$possible_class{'no_charge_warn'};
! 1244: } else {
! 1245: $css_class=$possible_class{'not_charged_try'};
! 1246: }
1.135 albertel 1247: $button=1;
1248: } elsif ($award eq 'UNIT_NOTNEEDED') {
1.155 albertel 1249: $message = &mt('Only a number required. Computer reads units of "[_1]".',&markup_unit($awardmsg,$target));
1.354 ! raeburn 1250: if (&Apache::lonhomework::show_some_problem_status()) {
! 1251: $css_class=$possible_class{'no_charge_warn'};
! 1252: } else {
! 1253: $css_class=$possible_class{'not_charged_try'};
! 1254: }
1.135 albertel 1255: $button=1;
1256: } elsif ($award eq 'NO_UNIT') {
1.144 albertel 1257: $message = &mt("Units required").'.';
1.135 albertel 1258: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Physical_Units')};
1.354 ! raeburn 1259: if (&Apache::lonhomework::show_some_problem_status()) {
! 1260: $css_class=$possible_class{'no_charge_warn'};
! 1261: } else {
! 1262: $css_class=$possible_class{'not_charged_try'};
! 1263: }
1.135 albertel 1264: $button=1;
1.153 albertel 1265: } elsif ($award eq 'COMMA_FAIL') {
1266: $message = &mt("Proper comma separation is required").'.';
1.221 albertel 1267: $css_class=$possible_class{'not_charged_try'};
1.153 albertel 1268: $button=1;
1.135 albertel 1269: } elsif ($award eq 'BAD_FORMULA') {
1.240 www 1270: $message = &mt("Unable to understand formula").'.';
1271: if ($target ne 'tex') {$message.=&Apache::loncommon::help_open_topic('Formula_Answers')};
1.221 albertel 1272: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 1273: $button=1;
1.272 www 1274: } elsif ($award eq 'NOT_FUNCTION') {
1275: $message = &mt("Not a function").'.';
1276: $css_class=$possible_class{'not_charged_try'};
1277: $button=1;
1278: } elsif ($award eq 'WRONG_FORMAT') {
1279: $message = &mt("Wrong format").'.';
1280: $css_class=$possible_class{'not_charged_try'};
1281: $button=1;
1282: } elsif ($award eq 'INTERNAL_ERROR') {
1.251 www 1283: $message = &mt("An internal error occurred while processing your answer. Please try again later.");
1284: $css_class=$possible_class{'not_charged_try'};
1285: $button=1;
1.135 albertel 1286: } elsif ($award eq 'INCORRECT') {
1.144 albertel 1287: $message = &mt("Incorrect").'.';
1.221 albertel 1288: $css_class=$possible_class{'charged_try'};
1.135 albertel 1289: $button=1;
1290: } elsif ($award eq 'SUBMITTED') {
1291: $message = &mt("Your submission has been recorded.");
1.221 albertel 1292: $css_class=$possible_class{'no_grade'};
1.135 albertel 1293: $button=1;
1.261 raeburn 1294: } elsif ($award eq 'SUBMITTED_CREDIT') {
1295: $message = &mt("Your submission has been recorded, and credit awarded.");
1296: $css_class=$possible_class{'correct'};
1297: $button=1;
1298: } elsif ($award eq 'ANONYMOUS') {
1299: $message = &mt("Your anonymous submission has been recorded.");
1300: $css_class=$possible_class{'no_grade'};
1301: $button=1;
1302: } elsif ($award eq 'ANONYMOUS_CREDIT') {
1303: $message = &mt("Your anonymous submission has been recorded, and credit awarded.");
1304: $css_class=$possible_class{'correct'};
1.301 raeburn 1305: $button=1;
1.135 albertel 1306: } elsif ($award eq 'DRAFT') {
1.258 riegler 1307: $message = &mt("Copy saved but not submitted.");
1.221 albertel 1308: $css_class=$possible_class{'not_charged_try'};
1.135 albertel 1309: $button=1;
1310: } elsif ($award eq 'ASSIGNED_SCORE') {
1.144 albertel 1311: $message = &mt("A score has been assigned.");
1.221 albertel 1312: $css_class=$possible_class{'correct'};
1.135 albertel 1313: $button=0;
1.144 albertel 1314: } elsif ($award eq '') {
1.186 albertel 1315: if ($handgrade && $Apache::inputtags::status[-1] eq 'SHOW_ANSWER') {
1316: $message = &mt("Nothing submitted.");
1.221 albertel 1317: $css_class=$possible_class{'charged_try'};
1.186 albertel 1318: } else {
1.221 albertel 1319: $css_class=$possible_class{'not_charged_try'};
1.186 albertel 1320: }
1.144 albertel 1321: $button=1;
1.135 albertel 1322: } else {
1323: $message = &mt("Unknown message").": $award";
1324: $button=1;
1325: }
1.209 albertel 1326: my (undef,undef,$domain,$user)=&Apache::lonnet::whichuser();
1.194 banghart 1327: foreach my $resid(@Apache::inputtags::response){
1328: if ($Apache::lonhomework::history{"resource.$part.$resid.handback"}) {
1.254 raeburn 1329: if ($target eq 'tex') {
1330: $message.= "\\\\\n";
1331: } else {
1332: $message.='<br />';
1333: }
1.198 albertel 1334: my @files = split(/\s*,\s*/,
1335: $Apache::lonhomework::history{"resource.$part.$resid.handback"});
1336: my $file_msg;
1337: foreach my $file (@files) {
1.254 raeburn 1338: if ($target eq 'tex') {
1339: $file_msg.= "\\\\\n".$file;
1340: } else {
1341: $file_msg.= '<br /><a href="/uploaded/'."$domain/$user".'/'.$file.'">'.$file.'</a>';
1342: }
1.198 albertel 1343: }
1344: $message .= &mt('Returned file(s): [_1]',$file_msg);
1.254 raeburn 1345: if ($target eq 'tex') {
1346: $message.= "\\\\\n";
1347: } else {
1348: $message.='<br />';
1349: }
1.198 albertel 1350: }
1.194 banghart 1351: }
1352:
1.233 albertel 1353: if (&Apache::lonhomework::hide_problem_status()
1354: && $Apache::inputtags::status[-1] ne 'SHOW_ANSWER'
1355: && &hide_award($award)) {
1.304 raeburn 1356: $message = &mt("Answer Submitted: Your final submission will be graded after the due date.");
1357: my @interval= &Apache::lonnet::EXT("resource.$part.interval");
1358: if ($interval[0] =~ /\d+/) {
1359: my $first_access=&Apache::lonnet::get_first_access($interval[1]);
1360: if (defined($first_access)) {
1361: my $due_date= &Apache::lonnet::EXT("resource.$part.duedate");
1.343 raeburn 1362: my ($timelimit) = ($interval[0] =~ /^(\d+)/);
1363: unless (($due_date) && ($due_date < $first_access + $timelimit)) {
1.304 raeburn 1364: $message = &mt("Answer Submitted: Your final submission will be graded when the time limit is reached.");
1365: }
1366: }
1367: }
1.221 albertel 1368: $css_class=$possible_class{'no_grade'};
1.135 albertel 1369: $button=1;
1.340 raeburn 1370: if ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') {
1371: if ($Apache::inputtags::status[-1] eq 'CANNOT_ANSWER') {
1372: $message = 'Answer Submitted';
1373: } else {
1374: undef($message);
1375: }
1376: }
1.135 albertel 1377: }
1.148 albertel 1378: if ($Apache::inputtags::status[-1] eq 'SHOW_ANSWER' &&
1.150 albertel 1379: !$added_computer_text && $target ne 'tex') {
1.342 raeburn 1380: if ($computer) {
1381: $message = "$computer $message";
1382: }
1.148 albertel 1383: $added_computer_text=1;
1.144 albertel 1384: }
1.237 www 1385: if ($Apache::lonhomework::type eq 'practice') {
1.244 raeburn 1386: if ($target eq 'web') {
1387: $message .= '<br />';
1388: } else {
1389: $message .= ' ';
1390: }
1391: $message.=&mt('Submissions to practice problems are not permanently recorded.');
1.237 www 1392: }
1.221 albertel 1393: return ($button,$css_class,$message,$previousmsg);
1.12 albertel 1394: }
1395:
1.155 albertel 1396: sub markup_unit {
1397: my ($unit,$target)=@_;
1398: if ($target eq 'tex') {
1399: return '\texttt{'.&Apache::lonxml::latex_special_symbols($unit).'}';
1400: } else {
1401: return "<tt>".$unit."</tt>";
1402: }
1403: }
1404:
1.88 albertel 1405: sub removealldata {
1.87 albertel 1406: my ($id)=@_;
1407: foreach my $key (keys(%Apache::lonhomework::results)) {
1408: if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
1409: &Apache::lonxml::debug("Removing $key");
1410: delete($Apache::lonhomework::results{$key});
1411: }
1412: }
1413: }
1414:
1.142 albertel 1415: sub hidealldata {
1416: my ($id)=@_;
1417: foreach my $key (keys(%Apache::lonhomework::results)) {
1418: if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
1419: &Apache::lonxml::debug("Hidding $key");
1420: my $newkey=$key;
1421: $newkey=~s/^(resource\.\Q$id\E\.[^\.]+\.)(.*)$/${1}hidden${2}/;
1422: $Apache::lonhomework::results{$newkey}=
1423: $Apache::lonhomework::results{$key};
1424: delete($Apache::lonhomework::results{$key});
1425: }
1426: }
1427: }
1428:
1.12 albertel 1429: sub setgradedata {
1.136 albertel 1430: my ($award,$msg,$id,$previously_used) = @_;
1.154 albertel 1431: if ($Apache::lonhomework::scantronmode &&
1.165 albertel 1432: &Apache::lonnet::validCODE($env{'form.CODE'})) {
1433: $Apache::lonhomework::results{"resource.CODE"}=$env{'form.CODE'};
1.154 albertel 1434: } elsif ($Apache::lonhomework::scantronmode &&
1.165 albertel 1435: $env{'form.CODE'} eq '' &&
1.154 albertel 1436: $Apache::lonhomework::history{"resource.CODE"} ne '') {
1437: $Apache::lonhomework::results{"resource.CODE"}='';
1.141 albertel 1438: }
1.154 albertel 1439:
1.135 albertel 1440: if (!$Apache::lonhomework::scantronmode &&
1441: $Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
1442: $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
1443: $Apache::lonhomework::results{"resource.$id.afterduedate"}=$award;
1.87 albertel 1444: return '';
1.284 www 1445: } elsif ( $Apache::lonhomework::history{"resource.$id.awarded"} < 1
1.233 albertel 1446: || $Apache::lonhomework::scantronmode
1447: || &Apache::lonhomework::hide_problem_status() ) {
1.154 albertel 1448: # the student doesn't already have it correct,
1449: # or we are in a mode (scantron orno problem status) where a correct
1450: # can become incorrect
1451: # handle assignment of tries and solved status
1.135 albertel 1452: my $solvemsg;
1453: if ($Apache::lonhomework::scantronmode) {
1454: $solvemsg='correct_by_scantron';
1455: } else {
1456: $solvemsg='correct_by_student';
1457: }
1458: if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
1459: $Apache::lonhomework::results{"resource.$id.afterduedate"}='';
1460: }
1461: if ( $award eq 'ASSIGNED_SCORE') {
1462: $Apache::lonhomework::results{"resource.$id.tries"} =
1463: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1464: $Apache::lonhomework::results{"resource.$id.solved"} =
1465: $solvemsg;
1466: my $numawards=scalar(@Apache::inputtags::response);
1467: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
1468: foreach my $res (@Apache::inputtags::response) {
1.232 albertel 1469: if (defined($Apache::lonhomework::results{"resource.$id.$res.awarded"})) {
1470: $Apache::lonhomework::results{"resource.$id.awarded"}+=
1471: $Apache::lonhomework::results{"resource.$id.$res.awarded"};
1472: } else {
1473: $Apache::lonhomework::results{"resource.$id.awarded"}+=
1474: &awarddetail_to_awarded($Apache::lonhomework::results{"resource.$id.$res.awarddetail"});
1475: }
1.135 albertel 1476: }
1477: if ($numawards > 0) {
1478: $Apache::lonhomework::results{"resource.$id.awarded"}/=
1479: $numawards;
1480: }
1481: } elsif ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
1482: $Apache::lonhomework::results{"resource.$id.tries"} =
1483: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1484: $Apache::lonhomework::results{"resource.$id.solved"} =
1485: $solvemsg;
1486: $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
1.261 raeburn 1487: } elsif ( $award eq 'SUBMITTED_CREDIT' ) {
1488: $Apache::lonhomework::results{"resource.$id.tries"} =
1489: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1490: $Apache::lonhomework::results{"resource.$id.solved"} =
1491: 'credit_attempted';
1492: $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
1493: } elsif ( $award eq 'ANONYMOUS_CREDIT' ) {
1494: $Apache::lonhomework::results{"resource.$id.tries"} =
1495: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1496: $Apache::lonhomework::results{"resource.$id.solved"} =
1497: 'credit_attempted';
1498: $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
1.135 albertel 1499: } elsif ( $award eq 'INCORRECT' ) {
1500: $Apache::lonhomework::results{"resource.$id.tries"} =
1501: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1.233 albertel 1502: if (&Apache::lonhomework::hide_problem_status()
1503: || $Apache::lonhomework::scantronmode) {
1.135 albertel 1504: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
1505: }
1506: $Apache::lonhomework::results{"resource.$id.solved"} =
1507: 'incorrect_attempted';
1508: } elsif ( $award eq 'SUBMITTED' ) {
1509: $Apache::lonhomework::results{"resource.$id.tries"} =
1510: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1511: $Apache::lonhomework::results{"resource.$id.solved"} =
1512: 'ungraded_attempted';
1.261 raeburn 1513: } elsif ( $award eq 'ANONYMOUS' ) {
1514: $Apache::lonhomework::results{"resource.$id.tries"} =
1515: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1516: $Apache::lonhomework::results{"resource.$id.solved"} =
1517: 'ungraded_attempted';
1.135 albertel 1518: } elsif ( $award eq 'DRAFT' ) {
1519: $Apache::lonhomework::results{"resource.$id.solved"} = '';
1520: } elsif ( $award eq 'NO_RESPONSE' ) {
1521: #no real response so delete any data that got stored
1.129 albertel 1522: &removealldata($id);
1523: return '';
1524: } else {
1.135 albertel 1525: $Apache::lonhomework::results{"resource.$id.solved"} =
1526: 'incorrect_attempted';
1.233 albertel 1527: if (&Apache::lonhomework::show_no_problem_status()
1528: || $Apache::lonhomework::scantronmode) {
1.135 albertel 1529: $Apache::lonhomework::results{"resource.$id.tries"} =
1530: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
1531: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
1532: }
1.233 albertel 1533:
1534: if (&Apache::lonhomework::show_some_problem_status()) {
1535: # clear out the awarded if they had gotten it wrong/right
1536: # and are now in an error mode
1537: $Apache::lonhomework::results{"resource.$id.awarded"} = '';
1538: }
1.135 albertel 1539: }
1.136 albertel 1540: if (defined($msg)) {
1541: $Apache::lonhomework::results{"resource.$id.awardmsg"} = $msg;
1542: }
1.135 albertel 1543: # did either of the overall awards chage? If so ignore the
1544: # previous check
1545: if (($Apache::lonhomework::results{"resource.$id.awarded"} eq
1546: $Apache::lonhomework::history{"resource.$id.awarded"}) &&
1547: ($Apache::lonhomework::results{"resource.$id.solved"} eq
1548: $Apache::lonhomework::history{"resource.$id.solved"})) {
1549: # check if this was a previous submission if it was delete the
1550: # unneeded data and update the previously_used attribute
1551: if ( $previously_used eq 'PREVIOUSLY_USED') {
1.233 albertel 1552: if (&Apache::lonhomework::show_problem_status()) {
1.135 albertel 1553: delete($Apache::lonhomework::results{"resource.$id.tries"});
1554: $Apache::lonhomework::results{"resource.$id.previous"} = '1';
1555: }
1556: } elsif ( $previously_used eq 'PREVIOUSLY_LAST') {
1557: #delete all data as they student didn't do anything, but save
1558: #the list of collaborators.
1559: &removealldata($id);
1560: #and since they didn't do anything we were never here
1561: return '';
1562: } else {
1563: $Apache::lonhomework::results{"resource.$id.previous"} = '0';
1564: }
1.101 albertel 1565: }
1.283 www 1566: } elsif ( $Apache::lonhomework::history{"resource.$id.awarded"} == 1 ) {
1.135 albertel 1567: #delete all data as they student already has it correct
1568: &removealldata($id);
1569: #and since they didn't do anything we were never here
1570: return '';
1.40 albertel 1571: }
1.135 albertel 1572: $Apache::lonhomework::results{"resource.$id.award"} = $award;
1.184 albertel 1573: if ($award eq 'SUBMITTED') {
1574: &Apache::response::add_to_gradingqueue();
1575: }
1.288 www 1576: $Apache::lonhomework::results{"resource.$id.type"} = $Apache::lonhomework::type;
1.289 www 1577: $Apache::lonhomework::results{"resource.$id.duedate"} = &Apache::lonnet::EXT("resource.$id.duedate");
1578: $Apache::lonhomework::results{"resource.$id.hinttries"} = &Apache::lonnet::EXT("resource.$id.hinttries");
1.330 raeburn 1579: $Apache::lonhomework::results{"resource.$id.version"} = &Apache::lonnet::usedversion();
1580: $Apache::lonhomework::results{"resource.$id.maxtries"} = &Apache::lonnet::EXT("resource.$id.maxtries");
1.10 albertel 1581: }
1582:
1.219 albertel 1583: sub find_which_previous {
1584: my ($version) = @_;
1585: my $part = $Apache::inputtags::part;
1586: my (@previous_version);
1587: foreach my $resp (@Apache::inputtags::response) {
1588: my $key = "$version:resource.$part.$resp.submission";
1589: my $submission = $Apache::lonhomework::history{$key};
1590: my %previous = &Apache::response::check_for_previous($submission,
1591: $part,$resp,
1592: $version);
1593: push(@previous_version,$previous{'version'});
1594: }
1595: return &previous_match(\@previous_version,
1596: scalar(@Apache::inputtags::response));
1597: }
1598:
1599: sub previous_match {
1600: my ($previous_array,$count) = @_;
1601: my $match = 0;
1602: my @matches;
1603: foreach my $versionar (@$previous_array) {
1604: foreach my $version (@$versionar) {
1605: $matches[$version]++;
1606: }
1607: }
1608: my $which=0;
1609: foreach my $elem (@matches) {
1610: if ($elem eq $count) {
1611: $match=1;
1612: last;
1613: }
1614: $which++;
1615: }
1616: return ($match,$which);
1617: }
1618:
1.9 albertel 1619: sub grade {
1.135 albertel 1620: my ($target) = @_;
1621: my $id = $Apache::inputtags::part;
1622: my $response='';
1.165 albertel 1623: if ( defined $env{'form.submitted'}) {
1.136 albertel 1624: my (@awards,@msgs);
1.135 albertel 1625: foreach $response (@Apache::inputtags::response) {
1626: &Apache::lonxml::debug("looking for response.$id.$response.awarddetail");
1627: my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"};
1628: &Apache::lonxml::debug("keeping $value from $response for $id");
1629: push (@awards,$value);
1.136 albertel 1630: $value=$Apache::lonhomework::results{"resource.$id.$response.awardmsg"};
1631: &Apache::lonxml::debug("got message $value from $response for $id");
1632: push (@msgs,$value);
1.135 albertel 1633: }
1.232 albertel 1634: my ($finalaward,$msg) =
1635: &finalizeawards(\@awards,\@msgs,undef,undef,
1636: $Apache::lonhomework::scantronmode);
1.135 albertel 1637: my $previously_used;
1638: if ( $#Apache::inputtags::previous eq $#awards ) {
1.219 albertel 1639: my ($match) =
1640: &previous_match(\@Apache::inputtags::previous_version,
1641: scalar(@Apache::inputtags::response));
1.244 raeburn 1642:
1.135 albertel 1643: if ($match) {
1644: $previously_used = 'PREVIOUSLY_LAST';
1645: foreach my $value (@Apache::inputtags::previous) {
1646: if ($value eq 'PREVIOUSLY_USED' ) {
1647: $previously_used = $value;
1648: last;
1649: }
1.75 albertel 1650: }
1651: }
1.43 albertel 1652: }
1.136 albertel 1653: &Apache::lonxml::debug("final award $finalaward, $previously_used, message $msg");
1654: &setgradedata($finalaward,$msg,$id,$previously_used);
1.43 albertel 1655: }
1.135 albertel 1656: return '';
1.1 albertel 1657: }
1658:
1.217 albertel 1659: sub get_grade_messages {
1.325 raeburn 1660: my ($id,$prefix,$target,$status,$nocorrect,$tdclass) = @_;
1.282 www 1661: # nocorrect suppresses "Computer's answer now shown above"
1.217 albertel 1662: my ($message,$latemessage,$trystr,$previousmsg);
1663: my $showbutton = 1;
1664:
1665: my $award = $Apache::lonhomework::history{"$prefix.award"};
1666: my $awarded = $Apache::lonhomework::history{"$prefix.awarded"};
1667: my $solved = $Apache::lonhomework::history{"$prefix.solved"};
1668: my $previous = $Apache::lonhomework::history{"$prefix.previous"};
1669: my $awardmsg = $Apache::lonhomework::history{"$prefix.awardmsg"};
1670: &Apache::lonxml::debug("Found Award |$award|$solved|$awardmsg");
1671: if ( $award ne '' || $solved ne '' || $status eq 'SHOW_ANSWER') {
1672: &Apache::lonxml::debug('Getting message');
1.221 albertel 1673: ($showbutton,my $css_class,$message,$previousmsg) =
1.217 albertel 1674: &decideoutput($award,$awarded,$awardmsg,$solved,$previous,
1.325 raeburn 1675: $target,(($status eq 'CAN_ANSWER') || $nocorrect),$tdclass);
1.217 albertel 1676: if ($target eq 'tex') {
1677: $message='\vskip 2 mm '.$message.' ';
1678: } else {
1.340 raeburn 1679: if ($message) {
1680: $message="<td class=\"$tdclass $css_class\">$message</td>";
1681: } else {
1682: $message="<td class=\"$tdclass\"></td>";
1683: }
1.217 albertel 1684: if ($previousmsg) {
1.325 raeburn 1685: $previousmsg="<td class=\"$tdclass LC_answer_previous\">$previousmsg</td>";
1.217 albertel 1686: }
1687: }
1688: }
1689: my $tries = $Apache::lonhomework::history{"$prefix.tries"};
1690: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
1691: &Apache::lonxml::debug("got maxtries of :$maxtries:");
1692: #if tries are set to negative turn off the Tries/Button and messages
1693: if (defined($maxtries) && $maxtries < 0) { return ''; }
1694: if ( $tries eq '' ) { $tries = '0'; }
1695: if ( $maxtries eq '' ) { $maxtries = '2'; }
1696: if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; }
1.292 christia 1697: my $tries_text= &get_tries_text();
1.217 albertel 1698: if ($showbutton) {
1699: if ($target eq 'tex') {
1700: if ($env{'request.state'} ne "construct"
1701: && $Apache::lonhomework::type ne 'exam'
1702: && $env{'form.suppress_tries'} ne 'yes') {
1.292 christia 1703: $trystr ='{\vskip 1 mm \small '
1704: .&mt('[_1]'.$tries_text.'[_2] [_3]'
1705: ,'\textit{','}',$tries.'/'.$maxtries )
1706: .'} \vskip 2 mm';
1.217 albertel 1707: } else {
1708: $trystr = '\vskip 0 mm ';
1709: }
1710: } else {
1.292 christia 1711: my $trial =$tries;
1.217 albertel 1712: if ($Apache::lonhomework::parsing_a_task) {
1713: } elsif($env{'request.state'} ne 'construct') {
1.292 christia 1714: $trial.="/".&Apache::lonhtmlcommon::direct_parm_link($maxtries,$env{'request.symb'},'maxtries',$id,$target);
1.217 albertel 1715: } else {
1716: if (defined($Apache::inputtags::params{'maxtries'})) {
1.292 christia 1717: $trial.="/".$Apache::inputtags::params{'maxtries'};
1.217 albertel 1718: }
1719: }
1.341 raeburn 1720:
1721: unless (($env{'request.state'} ne "construct") &&
1722: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') &&
1723: (!$env{'request.role.adv'})) {
1724: $trystr = '<span class="LC_nobreak">'.&mt($tries_text.' [_1]',$trial).'</span>';
1725: }
1726: $trystr = '<td class="'.$tdclass.'">'.$trystr.'</td>';
1.217 albertel 1727: }
1728: }
1.221 albertel 1729:
1.217 albertel 1730: if ($Apache::lonhomework::history{"$prefix.afterduedate"}) {
1731: #last submissions was after due date
1732: $latemessage=&mt(' The last submission was after the Due Date ');;
1733: if ($target eq 'web') {
1.325 raeburn 1734: $latemessage='<td class="'.$tdclass.' LC_answer_late">'.$latemessage.'</td>';
1.217 albertel 1735: }
1736: }
1737: return ($previousmsg,$latemessage,$message,$trystr,$showbutton);
1738: }
1739:
1.11 albertel 1740: sub gradestatus {
1.223 albertel 1741: my ($id,$target,$no_previous) = @_;
1.135 albertel 1742: my $showbutton = 1;
1743: my $message = '';
1744: my $latemessage = '';
1745: my $trystr='';
1746: my $button='';
1747: my $previousmsg='';
1.325 raeburn 1748: my $tdclass='';
1.135 albertel 1749:
1750: my $status = $Apache::inputtags::status['-1'];
1751: &Apache::lonxml::debug("gradestatus has :$status:");
1.183 albertel 1752: if ( $status ne 'CLOSED'
1753: && $status ne 'UNAVAILABLE'
1754: && $status ne 'INVALID_ACCESS'
1755: && $status ne 'NEEDS_CHECKIN'
1.300 raeburn 1756: && $status ne 'NOT_IN_A_SLOT'
1757: && $status ne 'RESERVABLE'
1758: && $status ne 'RESERVABLE_LATER'
1.337 raeburn 1759: && $status ne 'NOTRESERVABLE'
1760: && $status ne 'NEED_DIFFERENT_IP') {
1.217 albertel 1761:
1.305 raeburn 1762: if ($status eq 'SHOW_ANSWER') {
1763: $showbutton = 0;
1764: }
1765:
1.325 raeburn 1766: unless (($status eq 'SHOW_ANSWER') || ($status eq 'CANNOT_ANSWER')) {
1767: if ($target ne 'tex') {
1768: $tdclass = 'LC_status_submit_'.$id;
1769: }
1770: }
1771:
1.217 albertel 1772: ($previousmsg,$latemessage,$message,$trystr) =
1773: &get_grade_messages($id,"resource.$id",$target,$status,
1.325 raeburn 1774: $showbutton,$tdclass);
1.305 raeburn 1775: if ($status eq 'CANNOT_ANSWER') {
1.217 albertel 1776: $showbutton = 0;
1.164 albertel 1777: }
1.218 albertel 1778: if ( $status eq 'SHOW_ANSWER') {
1779: undef($previousmsg);
1780: }
1.325 raeburn 1781: if ( $showbutton ) {
1.135 albertel 1782: if ($target ne 'tex') {
1.230 albertel 1783: $button =
1.262 www 1784: '<input onmouseup="javascript:setSubmittedPart(\''.$id.'\');this.form.action+=\'#'.&escape($id).'\';"
1.325 raeburn 1785: type="submit" name="submit_'.$id.'" id="submit_'.$id.'" class="LC_hwk_submit"
1786: value="'.&mt('Submit Answer').'" /> '.
1787: '<div id="msg_submit_'.$id.'" style="display:none">'.
1788: &mt('Processing your submission ...').'</div>';
1.135 albertel 1789: }
1790: }
1.217 albertel 1791:
1.135 albertel 1792: }
1.341 raeburn 1793: my $output= $previousmsg.$latemessage.$message.$trystr;
1.135 albertel 1794: if ($output =~ /^\s*$/) {
1795: return $button;
1.63 sakharuk 1796: } else {
1.135 albertel 1797: if ($target eq 'tex') {
1798: return $button.' \vskip 0 mm '.$output.' ';
1799: } else {
1.223 albertel 1800: $output =
1801: '<table><tr><td>'.$button.'</td>'.$output;
1.341 raeburn 1802: if ((!$no_previous) &&
1803: (($env{'course.'.$env{'request.course.id'}.'.type'} ne 'Placement') ||
1804: ($env{'request.role.adv'}))) {
1.325 raeburn 1805: $output.='<td class="'.$tdclass.'">'.&previous_tries($id,$target).'</td>';
1.223 albertel 1806: }
1807: $output.= '</tr></table>';
1808: return $output;
1.135 albertel 1809: }
1.63 sakharuk 1810: }
1.11 albertel 1811: }
1.217 albertel 1812:
1813: sub previous_tries {
1814: my ($id,$target) = @_;
1815: my $output;
1816: my $status = $Apache::inputtags::status['-1'];
1.219 albertel 1817:
1818: my $count;
1819: my %count_lookup;
1.333 raeburn 1820: my ($lastrndseed,$lasttype);
1.318 raeburn 1821: my $numstamps = 0;
1.219 albertel 1822:
1.217 albertel 1823: foreach my $i (1..$Apache::lonhomework::history{'version'}) {
1824: my $prefix = $i.":resource.$id";
1.333 raeburn 1825: my $is_anon;
1826: my $curr_type = $Apache::lonhomework::history{"$prefix.type"};
1.263 raeburn 1827: if (defined($env{'form.grade_symb'})) {
1.333 raeburn 1828: if (($curr_type eq 'anonsurvey') || ($curr_type eq 'anonsurveycred')) {
1.263 raeburn 1829: $is_anon = 1;
1830: }
1831: }
1.217 albertel 1832: next if (!exists($Apache::lonhomework::history{"$prefix.award"}));
1.219 albertel 1833: $count++;
1834: $count_lookup{$i} = $count;
1.274 raeburn 1835: my $curr_rndseed = $Apache::lonhomework::history{"$prefix.rndseed"};
1.217 albertel 1836: my ($previousmsg,$latemessage,$message,$trystr);
1837:
1838: ($previousmsg,$latemessage,$message,$trystr) =
1839: &get_grade_messages($id,"$prefix",$target,$status);
1840:
1.219 albertel 1841: if ($previousmsg ne '') {
1842: my ($match,$which) = &find_which_previous($i);
1843: $message=$previousmsg;
1844: my $previous = $count_lookup{$which};
1.226 albertel 1845: $message =~ s{(</td>)}{ as submission \# $previous $1};
1.221 albertel 1846: } elsif ($Apache::lonhomework::history{"$prefix.tries"}) {
1.233 albertel 1847: if (!(&Apache::lonhomework::hide_problem_status()
1.225 albertel 1848: && $Apache::inputtags::status[-1] ne 'SHOW_ANSWER')
1849: && $Apache::lonhomework::history{"$prefix.solved"} =~/^correct/
1850: ) {
1851:
1.238 bisitz 1852: my $txt_correct = &mt('Correct');
1.279 raeburn 1853: my $awarded = $Apache::lonhomework::history{"$prefix.awarded"};
1854: if ($awarded < 1 && $awarded > 0) {
1.280 raeburn 1855: $txt_correct=&mt('Partially Correct');
1.279 raeburn 1856: } elsif ($awarded < 1) {
1857: if ($awarded eq '') {
1858: $txt_correct='';
1859: } else {
1860: $txt_correct=&mt('Incorrect');
1861: }
1862: }
1.221 albertel 1863: $message =~ s{(<td.*?>)(.*?)(</td>)}
1.238 bisitz 1864: {$1 <strong>$txt_correct</strong>. $3}s;
1.221 albertel 1865: }
1.238 bisitz 1866: my $trystr = "(".&mt('Try [_1]',$Apache::lonhomework::history{"$prefix.tries"}).")";
1.332 raeburn 1867: if (($curr_rndseed ne '') && ($lastrndseed ne '')) {
1.333 raeburn 1868: if (($curr_rndseed ne $lastrndseed) &&
1869: (($curr_type eq 'randomizetry') || ($lasttype eq 'randomizetry'))) {
1.274 raeburn 1870: $trystr .= '<br /><span style="color: green; white-space: nowrap; font-style: italic; font-weight: bold; font-size: 80%;">'.&mt('New problem variation this try.').'</span>';
1871: }
1872: }
1.221 albertel 1873: $message =~ s{(</td>)}{ $trystr $1};
1.219 albertel 1874: }
1.221 albertel 1875: my ($class) = ($message =~ m{<td.*class="([^"]*)"}); #"
1876: $message =~ s{(<td.*?>)}{<td>};
1877:
1.219 albertel 1878:
1.318 raeburn 1879: $output .= '<tr class="'.$class.'">'.
1880: '<td align="center">'.$count.'</td>'.$message;
1881: if ((!$is_anon) && ($Apache::lonhomework::history{"$prefix.tries"}) &&
1882: ($Apache::lonhomework::history{"$prefix.award"} ne 'ASSIGNED_SCORE') &&
1883: ($Apache::lonhomework::history{$i.':timestamp'})) {
1884: $output .= '<td>'.&Apache::lonlocal::locallocaltime(
1885: $Apache::lonhomework::history{$i.':timestamp'}).'</td>';
1886: $numstamps ++;
1887: } else {
1888: $output .= '<td></td>';
1889: }
1.217 albertel 1890: foreach my $resid (@Apache::inputtags::response) {
1891: my $prefix = $prefix.".$resid";
1892: if (exists($Apache::lonhomework::history{"$prefix.submission"})) {
1893: my $submission =
1894: $Apache::inputtags::submission_display{"$prefix.submission"};
1895: if (!defined($submission)) {
1896: $submission =
1897: $Apache::lonhomework::history{"$prefix.submission"};
1898: }
1.263 raeburn 1899: if ($is_anon) {
1900: $output.='<td>'.&mt('(only shown to submitter)').'</td>';
1901: } else {
1902: $output.='<td>'.$submission.'</td>';
1903: }
1.217 albertel 1904: } else {
1905: $output.='<td></td>';
1906: }
1907: }
1.221 albertel 1908: $output.=&Apache::loncommon::end_data_table_row()."\n";
1.274 raeburn 1909: $lastrndseed = $curr_rndseed;
1.333 raeburn 1910: $lasttype = $curr_type;
1.217 albertel 1911: }
1912: return if ($output eq '');
1.318 raeburn 1913: my $headers = '<tr>'.
1914: '<th>'.&mt('Submission #').'</th>'.
1915: '<th>'.&mt('Try').'</th><th>';
1916: if ($numstamps) {
1917: $headers .= &mt('When');
1918: }
1919: $headers .= '</th>';
1920: my $colspan = scalar(@Apache::inputtags::response);
1921: if ($colspan > 1) {
1922: $headers .= '<th colspan="'.$colspan.'">';
1923: } else {
1924: $headers .= '<th>';
1925: }
1926: $headers .= &mt('Submitted Answer').'</th></tr>';
1.298 www 1927: $output ='<table class="LC_prior_tries">'.$headers.$output.'</table>';
1.226 albertel 1928:
1.263 raeburn 1929: my $tries_text = &get_tries_text('link');
1.231 albertel 1930: my $prefix = $env{'form.request.prefix'};
1931: $prefix =~ tr{.}{_};
1.345 raeburn 1932: my $function_name = 'LONCAPA_previous_tries_'.$prefix;
1933: if (($env{'request.state'} eq 'construct') || ($id =~ /[._]|[^\w\s\-]/)) {
1934: $function_name .= $Apache::lonxml::curdepth;
1935: } else {
1936: $function_name .= &js_escape($id);
1937: }
1938: $function_name .= '_'.$Apache::lonxml::counter;
1.353 raeburn 1939: my $possmathjax = 1;
1940: my $result = &Apache::loncommon::modal_adhoc_window($function_name,420,410,$output,
1941: &mt($tries_text),$possmathjax)."<br />";
1.217 albertel 1942: return $result;
1943: }
1944:
1.263 raeburn 1945: sub get_tries_text {
1946: my ($context) = @_;
1947: my $tries_text;
1948: if ($context eq 'link') {
1949: $tries_text = 'Previous Tries';
1950: } else {
1951: $tries_text = 'Tries';
1952: }
1953: if ( $Apache::lonhomework::type eq 'survey' ||
1954: $Apache::lonhomework::type eq 'surveycred' ||
1955: $Apache::lonhomework::type eq 'anonsurvey' ||
1956: $Apache::lonhomework::type eq 'anonsurveycred' ||
1957: $Apache::lonhomework::parsing_a_task) {
1958: if ($context eq 'link') {
1959: $tries_text = 'Previous Submissions';
1960: } else {
1961: $tries_text = 'Submissions';
1962: }
1963: }
1964: return $tries_text;
1965: }
1966:
1.314 raeburn 1967: sub spelling_languages {
1968: my %langchoices;
1969: foreach my $id (&Apache::loncommon::languageids()) {
1970: my $code = &Apache::loncommon::supportedlanguagecode($id);
1971: if ($code ne '') {
1972: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
1973: }
1974: }
1975: my @spelllangs = ('none');
1976: foreach my $code ('en','de','he','es','fr','pt','tr') {
1977: push(@spelllangs,[$code,$langchoices{$code}]);
1978: }
1979: return \@spelllangs;
1980: }
1981:
1.338 raeburn 1982: sub edit_mathresponse_button {
1983: my ($field) = @_;
1984: my $eqneditor = 'lcmath';
1985: if ($env{'browser.type'} eq 'safari') {
1986: if ($env{'browser.os'} eq 'mac') {
1987: my ($prefix,$version) = ($env{'browser.version'} =~ /^(\d*)(\d{3})\./);
1988: if ($env{'browser.mobile'}) {
1989: if (($version < 531) || (($prefix eq '') && ($version < 533))) {
1990: $eqneditor = '';
1991: }
1992: } elsif ($version < 533) {
1993: $eqneditor = 'dragmath';
1994: }
1995: } elsif ($env{'browser.os'} eq 'win') {
1996: if ($env{'browser.version'} < 533) {
1997: $eqneditor = 'dragmath';
1998: }
1999: }
2000: } elsif ($env{'browser.type'} eq 'explorer') {
2001: if ($env{'browser.version'} < 9) {
2002: $eqneditor = 'dragmath';
2003: }
2004: } elsif ($env{'browser.type'} eq 'mozilla') {
2005: if ($env{'browser.version'} < 5) {
2006: $eqneditor = 'dragmath';
2007: } else {
2008: if ($env{'browser.info'} =~ /^firefox\-([\d\.]+)/) {
2009: my $firefox = $1;
2010: if ($firefox < 4) {
2011: $eqneditor = 'dragmath';
2012: }
2013: }
2014: }
2015: } elsif ($env{'browser.type'} eq 'chrome') {
2016: if ($env{'browser.version'} < 5) {
2017: $eqneditor = 'dragmath';
2018: }
2019: } elsif ($env{'browser.type'} eq 'opera') {
2020: if ($env{'browser.version'} < 12) {
2021: $eqneditor = 'dragmath';
2022: }
2023: }
2024: if ($eqneditor eq 'lcmath') {
2025: if (($env{'request.course.id'}) && ($env{'request.state'} ne 'construct')) {
2026: if (exists($env{'course.'.$env{'request.course.id'}.'.uselcmath'})) {
2027: if ($env{'course.'.$env{'request.course.id'}.'.uselcmath'} eq '0') {
2028: $eqneditor = 'dragmath';
2029: }
2030: } else {
2031: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
2032: if ($domdefs{'uselcmath'} eq '0') {
2033: $eqneditor = 'dragmath';
2034: }
2035: }
2036: } else {
2037: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
2038: if ($domdefs{'uselcmath'} eq '0') {
2039: $eqneditor = 'dragmath';
2040: }
2041: }
2042: }
2043: if ($eqneditor eq 'dragmath') {
2044: # DragMath applet
2045: my $button=&mt('Edit Answer');
2046: # my $helplink=&Apache::loncommon::help_open_topic('Formula_Editor');
2047: my $iconpath=$Apache::lonnet::perlvar{'lonIconsURL'};
2048: return(<<ENDFORMULABUTTON);
2049: <script type="text/javascript" language="JavaScript">
2050: function LC_mathedit_${field} (LCtextline) {
2051: thenumber = LCtextline;
2052: var thedata = '';
2053: if (document.getElementById(LCtextline)) {
2054: thedata = document.getElementById(LCtextline).value;
2055: }
2056: newwin = window.open("/adm/dragmath/MaximaPopup.html","","width=565,height=400,resizable");
2057: }
2058: </script>
2059: <a href="javascript:LC_mathedit_${field}('${field}');void(0);"><img class="stift" src="$iconpath/stift.gif" alt="$button" title="$button" /></a>
2060: ENDFORMULABUTTON
2061: } elsif ($eqneditor eq 'lcmath') {
2062: # LON-CAPA math equation editor
2063: my $mathjaxjs;
2064: unless (lc(&Apache::lontexconvert::tex_engine()) eq 'mathjax') {
2065: $mathjaxjs = <<"MATHJAX_SCRIPT";
2066: var mathjaxscript = document.createElement("script");
2067: mathjaxscript.type = "text/javascript";
2068: mathjaxscript.src = "/adm/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
2069: document.body.appendChild(mathjaxscript);
2070: MATHJAX_SCRIPT
2071: }
2072: return(<<EQ_EDITOR_SCRIPT);
2073: <script type="text/javascript">
2074: var LCmathField = document.getElementById('${field}');
2075: LCmathField.className += ' math'; // note the space
2076: LCmathField.setAttribute('data-implicit_operators', 'true');
2077: var LCMATH_started;
2078: if (typeof LCMATH_started === 'undefined') {
2079: $mathjaxjs
2080: LCMATH_started = true;
2081: var script = document.createElement("script");
2082: script.type = "text/javascript";
2083: script.src = "/adm/LC_math_editor/LC_math_editor.min.js";
2084: document.body.appendChild(script);
2085: window.addEventListener('load', function(e) {
2086: LCMATH.initEditors();
2087: }, false);
2088: }
2089: </script>
2090: EQ_EDITOR_SCRIPT
2091: }
2092: }
2093:
1.1 albertel 2094: 1;
2095: __END__
1.249 jms 2096:
2097: =pod
2098:
2099: =back
2100:
2101: =cut
1.43 albertel 2102:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>