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