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