1: # The LearningOnline Network with CAPA
2: # input definitons
3: #
4: # $Id: inputtags.pm,v 1.105 2003/06/19 21:41:02 albertel Exp $
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/
27: #
28: # 2/19 Guy
29:
30: package Apache::inputtags;
31: use HTML::Entities();
32: use strict;
33: use Apache::loncommon;
34:
35: BEGIN {
36: &Apache::lonxml::register('Apache::inputtags',('hiddenline','textfield','textline'));
37: }
38:
39:
40: sub initialize_inputtags {
41: # list of current input ids
42: @Apache::inputtags::input=();
43: # list of all input ids seen in this problem
44: @Apache::inputtags::inputlist=();
45: # list of all current response ids
46: @Apache::inputtags::response=();
47: # list of all response ids seen in this problem
48: @Apache::inputtags::responselist=();
49: # list of whether or not a specific response was previously used
50: @Apache::inputtags::previous=();
51: # submission it was used in
52: @Apache::inputtags::previous_version=();
53: # id of current part, 0 means that no part is current (inside <problem> only
54: $Apache::inputtags::part='';
55: # list of all part ids seen
56: @Apache::inputtags::partlist=();
57: # list of problem date statuses, the first element is for <problem>
58: # if there is a second element it is for the current <part>
59: @Apache::inputtags::status=();
60: # hash of defined params for the current response
61: %Apache::inputtags::params=();
62: # list of all ids, for <import>, these get join()ed and prepended
63: @Apache::inputtags::import=();
64: # list of all import ids seen
65: @Apache::inputtags::importlist=();
66: }
67:
68: sub check_for_duplicate_ids {
69: my %check;
70: foreach my $id (@Apache::inputtags::partlist,
71: @Apache::inputtags::responselist,
72: @Apache::inputtags::importlist) {
73: $check{$id}++;
74: }
75: my @duplicates;
76: foreach my $id (sort(keys(%check))) {
77: if ($check{$id} > 1) {
78: push(@duplicates,$id);
79: }
80: }
81: if (@duplicates) {
82: &Apache::lonxml::error("Duplicated ids found, problem will operate incorrectly. Duplicated ids seen: ",join(', ',@duplicates));
83: }
84: }
85:
86: sub start_input {
87: my ($parstack,$safeeval)=@_;
88: my $id = &Apache::lonxml::get_param('id',$parstack,$safeeval);
89: if ($id eq '') { $id = $Apache::lonxml::curdepth; }
90: push (@Apache::inputtags::input,$id);
91: push (@Apache::inputtags::inputlist,$id);
92: return $id;
93: }
94:
95: sub end_input {
96: pop @Apache::inputtags::input;
97: return '';
98: }
99:
100: sub start_textfield {
101: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
102: my $result = "";
103: my $id = &start_input($parstack,$safeeval);
104: my $resid=$Apache::inputtags::response[-1];
105: if ($target eq 'web') {
106: $Apache::lonxml::evaluate--;
107: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
108: my $partid=$Apache::inputtags::part;
109: my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$resid.submission"});
110: my $cols = &Apache::lonxml::get_param('cols',$parstack,$safeeval);
111: if ( $cols eq '') { $cols = 80; }
112: my $rows = &Apache::lonxml::get_param('rows',$parstack,$safeeval);
113: if ( $rows eq '') { $rows = 10; }
114: $result= '<textarea name="HWVAL_'.$resid.'" '.
115: "rows=\"$rows\" cols=\"$cols\">".$oldresponse;
116: if ($oldresponse ne '') {
117: #get rid of any startup text if the user has already responded
118: &Apache::lonxml::get_all_text("/textfield",$parser);
119: }
120: } else {
121: #right or wrong don't show it
122: #$result='<table border="1"><tr><td><i>'.$oldresponse.'</i></td></tr></table>';
123: $result='';
124: #get rid of any startup text
125: &Apache::lonxml::get_all_text("/textfield",$parser);
126: }
127: } elsif ($target eq 'grade') {
128: my $seedtext=&Apache::lonxml::get_all_text("/textfield",$parser);
129: if ($seedtext eq $ENV{'form.HWVAL_'.$resid}) {
130: # if the seed text is still there it wasn't a real submission
131: $ENV{'form.HWVAL_'.$resid}='';
132: }
133: } elsif ($target eq 'edit') {
134: $result.=&Apache::edit::tag_start($target,$token);
135: $result.=&Apache::edit::text_arg('Rows:','rows',$token,4);
136: $result.=&Apache::edit::text_arg('Columns:','cols',$token,4);
137: my $bodytext=&Apache::lonxml::get_all_text("/textfield",$parser);
138: $result.=&Apache::edit::editfield($token->[1],$bodytext,'Text you want to appear by default:',80,2);
139: } elsif ($target eq 'modified') {
140: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
141: $safeeval,'rows','cols');
142: if ($constructtag) {
143: $result = &Apache::edit::rebuild_tag($token);
144: } else {
145: $result=$token->[4];
146: }
147: $result.=&Apache::edit::modifiedfield();
148: } elsif ($target eq 'tex') {
149: my $number_of_lines = &Apache::lonxml::get_param('rows',$parstack,$safeeval);
150: my $width_of_box = &Apache::lonxml::get_param('cols',$parstack,$safeeval);
151: if ($$tagstack[-2] eq 'essayresponse' and $Apache::lonhomework::type eq 'exam') {
152: $result = '\fbox{\fbox{\parbox{\textwidth-5mm}{';
153: for (my $i=0;$i<int $number_of_lines*2;$i++) {$result.='\strut \\\\ ';}
154: $result.='\strut \\\\\strut \\\\\strut \\\\\strut \\\\}}}';
155: } else {
156: my $TeXwidth=$width_of_box/80;
157: $result = '\vskip 1 mm \fbox{\fbox{\parbox{'.$TeXwidth.'\textwidth-5mm}{';
158: for (my $i=0;$i<int $number_of_lines*2;$i++) {$result.='\strut \\\\ ';}
159: $result.='}}}\vskip 2 mm ';
160: }
161: }
162: return $result;
163: }
164:
165: sub end_textfield {
166: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
167: my $result;
168: if ($target eq 'web') {
169: $Apache::lonxml::evaluate++;
170: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
171: return "</textarea>";
172: }
173: } elsif ($target eq 'edit') {
174: $result=&Apache::edit::end_table();
175: }
176: &end_input;
177: return $result;
178: }
179:
180: sub start_textline {
181: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
182: my $result = "";
183: if ($target eq 'web') {
184: $Apache::lonxml::evaluate--;
185: my $partid=$Apache::inputtags::part;
186: my $id=$Apache::inputtags::response[-1];
187: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
188: my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
189: my $maxlength;
190: if ($size eq '') { $size=20; } else {
191: if ($size < 20) { $maxlength=$size; }
192: }
193: my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"});
194: if ($Apache::lonhomework::type ne 'exam') {
195: $result= '<input type="text" name="HWVAL_'.$id.'" value="'.
196: $oldresponse.'" size="'.$size.'" maxlength="'.$maxlength.'" />';
197: }
198: } else {
199: #right or wrong don't show what was last typed in.
200: #$result='<i>'.$oldresponse.'</i>';
201: $result='';
202: }
203: } elsif ($target eq 'edit') {
204: $result=&Apache::edit::tag_start($target,$token);
205: $result.=&Apache::edit::text_arg('Size:','size',$token,'5')."</td></tr>";
206: $result.=&Apache::edit::end_table;
207: } elsif ($target eq 'modified') {
208: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'size');
209: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
210: } elsif ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
211: my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
212: if ($size != 0) {$size=$size*2; $size.=' mm';} else {$size='40 mm';}
213: $result='\framebox['.$size.'][s]{\tiny\strut}';
214: }
215: return $result;
216: }
217:
218: sub end_textline {
219: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
220: if ($target eq 'web') { $Apache::lonxml::evaluate++; }
221: elsif ($target eq 'edit') { return ('','no'); }
222: return "";
223: }
224:
225: sub start_hiddenline {
226: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
227: my $result = "";
228: if ($target eq 'web') {
229: $Apache::lonxml::evaluate--;
230: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
231: my $partid=$Apache::inputtags::part;
232: my $id=$Apache::inputtags::response[-1];
233: my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$id.submission"});
234: if ($Apache::lonhomework::type ne 'exam') {
235: $result= '<input type="hidden" name="HWVAL_'.$id.'" value="'.
236: $oldresponse.'" />';
237: }
238: }
239: } elsif ($target eq 'edit') {
240: $result=&Apache::edit::tag_start($target,$token);
241: $result.=&Apache::edit::end_table;
242: }
243: return $result;
244: }
245:
246: sub end_hiddenline {
247: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
248: if ($target eq 'web') { $Apache::lonxml::evaluate++; }
249: elsif ($target eq 'edit') { return ('','no'); }
250: return "";
251: }
252:
253: sub finalizeawards {
254: my $result='';
255: my $award;
256: if ($#_ == '-1') { $result = "NO_RESPONSE"; }
257: if ($result eq '' ) {
258: my $blankcount;
259: foreach $award (@_) {
260: if ($award eq '') {
261: $result='MISSING_ANSWER';
262: $blankcount++;
263: }
264: }
265: if ($blankcount == ($#_ + 1)) { $result = 'NO_RESPONSE'; }
266: }
267: if ($result eq '' ) {
268: foreach $award (@_) { if ($award eq 'MISSING_ANSWER') {$result='MISSING_ANSWER'; last;}}
269: }
270: if ($result eq '' ) {
271: foreach $award (@_) { if ($award eq 'ERROR') {$result='ERROR'; last;}}
272: }
273: if ($result eq '' ) {
274: foreach $award (@_) { if ($award eq 'NO_RESPONSE') {$result='NO_RESPONSE'; last;} }
275: }
276: if ($result eq '' ) {
277: foreach $award (@_) { if ($award eq 'TOO_LONG') {$result='TOO_LONG'; last;}}
278: }
279: if ($result eq '' ) {
280: foreach $award (@_) {
281: if ($award eq 'UNIT_FAIL' ||
282: $award eq 'NO_UNIT' ||
283: $award eq 'UNIT_NOTNEEDED') {
284: $result=$award; last;
285: }
286: }
287: }
288: if ($result eq '' ) {
289: foreach $award (@_) {
290: if ($award eq 'WANTED_NUMERIC' ||
291: $award eq 'BAD_FORMULA') {$result=$award; last;}
292: }
293: }
294: if ($result eq '' ) {
295: foreach $award (@_) { if ($award eq 'SIG_FAIL') {$result=$award; last;} }
296: }
297: if ($result eq '' ) {
298: foreach $award (@_) { if ($award eq 'INCORRECT') {$result=$award; last;} }
299: }
300: if ($result eq '' ) {
301: foreach $award (@_) { if ($award eq 'MISORDERED_RANK') {$result=$award; last;} }
302: }
303: if ($result eq '' ) {
304: foreach $award (@_) { if ($award eq 'INVALID_FILETYPE') {$result=$award; last;} }
305: }
306: if ($result eq '' ) {
307: foreach $award (@_) { if ($award eq 'DRAFT') {$result=$award; last;} }
308: }
309: if ($result eq '' ) {
310: foreach $award (@_) { if ($award eq 'SUBMITTED') {$result=$award; last;} }
311: }
312: if ($result eq '' ) {
313: foreach $award (@_) { if ($award eq 'ASSIGNED_SCORE') {$result=$award; last;} }
314: }
315: if ($result eq '' ) {
316: foreach $award (@_) { if ($award eq 'APPROX_ANS') {$result=$award; last;} }
317: }
318: if ($result eq '' ) { $result='EXACT_ANS'; }
319: return $result
320: }
321:
322: sub decideoutput {
323: my ($award,$solved,$previous,$target)=@_;
324: my $message='';
325: my $button=0;
326: my $previousmsg;
327: my $bgcolor='orange';
328: my %possiblecolors =
329: ( 'correct' => '#aaffaa',
330: 'charged_try' => '#ffaaaa',
331: 'not_charged_try' => '#ffffaa',
332: 'no_message' => '#fffff',
333: );
334: if ($previous) { $previousmsg='You have entered that answer before'; }
335:
336: if ($solved =~ /^correct/) {
337: if ($award eq 'ASSIGNED_SCORE') {
338: $message = "A score has been assigned.";
339: } else {
340: if ($target eq 'tex') {
341: $message = '\textbf{You are correct}.';
342: } else {
343: $message = "<b>You are correct.</b>";
344: }
345: $message.=' Your receipt is '.&Apache::lonnet::receipt;
346: }
347: $bgcolor=$possiblecolors{'correct'};
348: $button=0;
349: $previousmsg='';
350: } elsif ($solved =~ /^excused/) {
351: $message = "<b>You are excused from the problem.</b>";
352: $bgcolor=$possiblecolors{'charged_try'};
353: $button=0;
354: $previousmsg='';
355: } elsif ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
356: if ($solved =~ /^incorrect/ || $solved eq '') {
357: $message = "Incorrect";
358: $bgcolor=$possiblecolors{'charged_try'};
359: $button=1;
360: } else {
361: $message = "<b>You are correct.</b> Your receipt is ".
362: &Apache::lonnet::receipt;
363: $bgcolor=$possiblecolors{'correct'};
364: $button=0;
365: $previousmsg='';
366: }
367: } elsif ($award eq 'NO_RESPONSE') {
368: $message = '';
369: $bgcolor=$possiblecolors{'no_feedback'};
370: $button=1;
371: } elsif ($award eq 'MISSING_ANSWER') {
372: $message = 'Some parts were not submitted';
373: $bgcolor=$possiblecolors{'not_charged_try'};
374: $button = 1;
375: } elsif ($award eq 'ERROR') {
376: $message = 'An error occured while trying to grade answer.';
377: $bgcolor=$possiblecolors{'not_charged_try'};
378: $button = 1;
379: } elsif ($award eq 'TOO_LONG') {
380: $message = "The submitted answer was too long.";
381: $bgcolor=$possiblecolors{'not_charged_try'};
382: $button=1;
383: } elsif ($award eq 'WANTED_NUMERIC') {
384: $message = "This question expects a numeric answer";
385: $bgcolor=$possiblecolors{'not_charged_try'};
386: $button=1;
387: } elsif ($award eq 'MISORDERED_RANK') {
388: $message = 'You have provided an invalid ranking, please refer to '.
389: &Apache::loncommon::help_open_topic('Ranking_Problems','help on ranking problems').'.';
390: $bgcolor=$possiblecolors{'not_charged_try'};
391: $button=1;
392: } elsif ($award eq 'INVALID_FILETYPE') {
393: $message = 'The filetype extension of the file you uploaded is not allowed.';
394: $bgcolor=$possiblecolors{'not_charged_try'};
395: $button=1;
396: } elsif ($award eq 'SIG_FAIL') {
397: $message = "Please adjust significant figures.";# you provided %s significant figures";
398: $bgcolor=$possiblecolors{'not_charged_try'};
399: $button=1;
400: } elsif ($award eq 'UNIT_FAIL') {
401: $message = "Units incorrect. ".
402: &Apache::loncommon::help_open_topic('Physical_Units'); #Computer reads units as %s";
403: $bgcolor=$possiblecolors{'not_charged_try'};
404: $button=1;
405: } elsif ($award eq 'UNIT_NOTNEEDED') {
406: $message = "Only a number required.";# Computer reads units of %s";
407: $bgcolor=$possiblecolors{'not_charged_try'};
408: $button=1;
409: } elsif ($award eq 'NO_UNIT') {
410: $message = "Units required".
411: &Apache::loncommon::help_open_topic('Physical_Units');
412: $bgcolor=$possiblecolors{'not_charged_try'};
413: $button=1;
414: } elsif ($award eq 'BAD_FORMULA') {
415: $message = "Unable to understand formula";
416: $bgcolor=$possiblecolors{'not_charged_try'};
417: $button=1;
418: } elsif ($award eq 'INCORRECT') {
419: $message = "Incorrect";
420: $bgcolor=$possiblecolors{'charged_try'};
421: $button=1;
422: } elsif ($award eq 'SUBMITTED') {
423: $message = "Your submission has been recorded.";
424: $bgcolor=$possiblecolors{'correct'};
425: $button=1;
426: } elsif ($award eq 'DRAFT') {
427: $message = "A draft copy has been saved.";
428: $bgcolor=$possiblecolors{'not_charged_try'};
429: $button=1;
430: } elsif ($award eq 'ASSIGNED_SCORE') {
431: $message = "A score has been assigned.";
432: $bgcolor=$possiblecolors{'correct'};
433: $button=0;
434: } else {
435: $message = "Unknown message: $award";
436: $button=1;
437: }
438: if (lc($Apache::lonhomework::problemstatus) eq 'no') {
439: $message = "Answer Submitted";
440: $bgcolor=$possiblecolors{'correct'};
441: $button=1;
442: }
443: return ($button,$bgcolor,$message,$previousmsg);
444: }
445:
446: sub removealldata {
447: my ($id)=@_;
448: foreach my $key (keys(%Apache::lonhomework::results)) {
449: if (($key =~ /^resource\.\Q$id\E\./) && ($key !~ /\.collaborators$/)) {
450: &Apache::lonxml::debug("Removing $key");
451: delete($Apache::lonhomework::results{$key});
452: }
453: }
454: }
455:
456: sub setgradedata {
457: my ($award,$id,$previously_used) = @_;
458: # if the student already has it correct, don't modify the status
459: if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
460: $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
461: $Apache::lonhomework::results{"resource.$id.afterduedate"}=$award;
462: return '';
463: } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} !~
464: /^correct/ || $Apache::lonhomework::scantronmode ||
465: lc($Apache::lonhomework::problemstatus) eq 'no') {
466: #handle assignment of tries and solved status
467: my $solvemsg;
468: if ($Apache::lonhomework::scantronmode) {
469: $solvemsg='correct_by_scantron';
470: } else {
471: $solvemsg='correct_by_student';
472: }
473: if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
474: $Apache::lonhomework::results{"resource.$id.afterduedate"}='';
475: }
476: if ( $award eq 'ASSIGNED_SCORE') {
477: $Apache::lonhomework::results{"resource.$id.tries"} =
478: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
479: $Apache::lonhomework::results{"resource.$id.solved"} =
480: $solvemsg;
481: my $numawards=scalar(@Apache::inputtags::response);
482: $Apache::lonhomework::results{"resource.$id.awarded"} = 0;
483: foreach my $res (@Apache::inputtags::response) {
484: $Apache::lonhomework::results{"resource.$id.awarded"}+=
485: $Apache::lonhomework::results{"resource.$id.$res.awarded"};
486: }
487: if ($numawards > 0) {
488: $Apache::lonhomework::results{"resource.$id.awarded"}/=
489: $numawards;
490: }
491: } elsif ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
492: $Apache::lonhomework::results{"resource.$id.tries"} =
493: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
494: $Apache::lonhomework::results{"resource.$id.solved"} =
495: $solvemsg;
496: $Apache::lonhomework::results{"resource.$id.awarded"} = '1';
497: } elsif ( $award eq 'INCORRECT' ) {
498: $Apache::lonhomework::results{"resource.$id.tries"} =
499: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
500: $Apache::lonhomework::results{"resource.$id.solved"} =
501: 'incorrect_attempted'
502: } elsif ( $award eq 'SUBMITTED' ) {
503: $Apache::lonhomework::results{"resource.$id.tries"} =
504: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
505: $Apache::lonhomework::results{"resource.$id.solved"} =
506: 'ungraded_attempted';
507: } elsif ( $award eq 'DRAFT' ) {
508: $Apache::lonhomework::results{"resource.$id.solved"} = '';
509: } elsif ( $award eq 'NO_RESPONSE' ) {
510: #no real response so delete any data that got stored
511: &removealldata($id);
512: return '';
513: } else {
514: $Apache::lonhomework::results{"resource.$id.solved"} =
515: 'incorrect_attempted';
516: if (lc($Apache::lonhomework::problemstatus) eq 'no') {
517: $Apache::lonhomework::results{"resource.$id.tries"} =
518: $Apache::lonhomework::history{"resource.$id.tries"} + 1;
519: }
520: }
521:
522: # check if this was a previous submission if it was delete the
523: # unneeded data and update the previously_used attribute
524: if ( $previously_used eq 'PREVIOUSLY_USED') {
525: if (lc($Apache::lonhomework::problemstatus) ne 'no') {
526: delete($Apache::lonhomework::results{"resource.$id.tries"});
527: $Apache::lonhomework::results{"resource.$id.previous"} = '1';
528: }
529: } elsif ( $previously_used eq 'PREVIOUSLY_LAST') {
530: #delete all data as they student didn't do anything, but save
531: #the list of collaborators.
532: &removealldata($id);
533: #and since they didn't do anything we were never here
534: return '';
535: } else {
536: $Apache::lonhomework::results{"resource.$id.previous"} = '0';
537: }
538: } elsif ( $Apache::lonhomework::history{"resource.$id.solved"} =~
539: /^correct/ ) {
540: #delete all data as they student already has it correct
541: &removealldata($id);
542: #and since they didn't do anything we were never here
543: return '';
544: }
545: $Apache::lonhomework::results{"resource.$id.award"} = $award;
546: }
547:
548: sub grade {
549: my ($target) = @_;
550: my $id = $Apache::inputtags::part;
551: my $response='';
552: if ( defined $ENV{'form.submitted'}) {
553: my @awards = ();
554: foreach $response (@Apache::inputtags::response) {
555: &Apache::lonxml::debug("looking for response.$id.$response.awarddetail");
556: my $value=$Apache::lonhomework::results{"resource.$id.$response.awarddetail"};
557: &Apache::lonxml::debug("keeping $value from $response for $id");
558: push (@awards,$value);
559: }
560: my $finalaward = &finalizeawards(@awards);
561: my $previously_used;
562: if ( $#Apache::inputtags::previous eq $#awards ) {
563: my $match=0;
564: my @matches;
565: foreach my $versionar (@Apache::inputtags::previous_version) {
566: foreach my $version (@$versionar) {
567: $matches[$version]++;
568: }
569: }
570: foreach my $elem (@matches) {if ($elem eq ($#awards+1)) {$match=1;}}
571: if ($match) {
572: $previously_used = 'PREVIOUSLY_LAST';
573: foreach my $value (@Apache::inputtags::previous) {
574: if ($value eq 'PREVIOUSLY_USED' ) {
575: $previously_used = $value;
576: last;
577: }
578: }
579: }
580: }
581: &Apache::lonxml::debug("final award $finalaward, $previously_used");
582: &setgradedata($finalaward,$id,$previously_used);
583: }
584: return '';
585: }
586:
587: sub gradestatus {
588: my ($id,$target) = @_;
589: my $showbutton = 1;
590: my $bgcolor = '';
591: my $message = '';
592: my $latemessage = '';
593: my $trystr='';
594: my $button='';
595: my $previousmsg='';
596:
597: my $status = $Apache::inputtags::status['-1'];
598: &Apache::lonxml::debug("gradestatus has :$status:");
599: if ( $status ne 'CLOSED' && $status ne 'UNAVAILABLE') {
600: my $award = $Apache::lonhomework::history{"resource.$id.award"};
601: my $solved = $Apache::lonhomework::history{"resource.$id.solved"};
602: my $previous = $Apache::lonhomework::history{"resource.$id.previous"};
603: &Apache::lonxml::debug("Found Award |$award|$solved|");
604: if ( $award ne '' ) {
605: &Apache::lonxml::debug('Getting message');
606: ($showbutton,$bgcolor,$message,$previousmsg) =
607: &decideoutput($award,$solved,$previous,$target);
608: if ($target eq 'tex') {
609: $message=' '.$message.' ';
610: } else {
611: $message="<td bgcolor=\"$bgcolor\">$message</td>";
612: if ($previousmsg) {
613: $previousmsg="<td bgcolor=\"#aaaaff\">$previousmsg</td>";
614: }
615: }
616: }
617: my $tries = $Apache::lonhomework::history{"resource.$id.tries"};
618: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
619: &Apache::lonxml::debug("got maxtries of :$maxtries:");
620: if ( $tries eq '' ) { $tries = '0'; }
621: if ( $maxtries eq '' ) { $maxtries = '2'; }
622: if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; }
623: if ( $showbutton ) {
624: if ($target eq 'tex') {
625: if ($ENV{'request.state'} ne "construct" && $Apache::lonhomework::type ne 'exam') {
626: $trystr = ' {\vskip 1 mm \small \textit{Tries} '.$tries.'/'.$maxtries.'} \vskip 2 mm ';
627: } else {
628: $trystr = '\vskip 0 mm ';
629: }
630: } else {
631: $trystr = "<td>Tries $tries/$maxtries</td>";
632: }
633: }
634: if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}
635: if ( $showbutton ) {
636: if ($target ne 'tex') {
637: $button = '<br /><input type="submit" name="submit" value="Submit Answer" />';
638: }
639: }
640: if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {
641: #last submissions was after due date
642: if ($target eq 'tex') {
643: $latemessage=' The last submission was after the Due Date ';
644: } else {
645: $latemessage="<td bgcolor=\"#ffaaaa\">The last submission was after the Due Date</td>";
646: }
647: }
648: }
649: my $output= $previousmsg.$latemessage.$message.$trystr;
650: if ($output =~ /^\s*$/) {
651: return $button;
652: } else {
653: if ($target eq 'tex') {
654: return $button.' \vskip 0 mm '.$output.' ';
655: } else {
656: return $button.'<table><tr>'.$output.'</tr></table>';
657: }
658: }
659: }
660: 1;
661: __END__
662:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>