File:
[LON-CAPA] /
loncom /
homework /
response.pm
Revision
1.107:
download - view:
text,
annotated -
select for diffs
Thu Oct 21 03:19:04 2004 UTC (19 years, 10 months ago) by
albertel
Branches:
MAIN
CVS tags:
HEAD
- previous submission handling now works for survey mode, in survey mode all previous submissions can be picked again, but we throw away a submission if the last submission is the same as the last previous submission
1: # The LearningOnline Network with CAPA
2: # various response type definitons response definition
3: #
4: # $Id: response.pm,v 1.107 2004/10/21 03:19:04 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:
29: package Apache::response;
30: use strict;
31: use Apache::lonlocal;
32:
33: BEGIN {
34: &Apache::lonxml::register('Apache::response',('responseparam','parameter','dataresponse'));
35: }
36:
37: sub start_response {
38: my ($parstack,$safeeval)=@_;
39: my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
40: if ($id eq '') { $id = $Apache::lonxml::curdepth; }
41: if ($#Apache::inputtags::import > -1) {
42: &Apache::lonxml::debug("Turning :$id: into");
43: $id = join('_',@Apache::inputtags::import).'_'.$id;
44: &Apache::lonxml::debug("New :$id:");
45: }
46: push (@Apache::inputtags::response,$id);
47: push (@Apache::inputtags::responselist,$id);
48: @Apache::inputtags::inputlist=();
49: if ($Apache::inputtags::part eq '' &&
50: !$Apache::lonhomework::ignore_response_errors) {
51: &Apache::lonxml::error(&HTML::Entities::encode(&mt("Found a <*response> outside of a <part> in a <part>ed problem"),'<>&"'));
52: }
53: if ($Apache::inputtags::response_with_no_part &&
54: $Apache::inputtags::part ne '0') {
55: &Apache::lonxml::error(&HTML::Entities::encode(&mt("<*response>s are both inside of <part> and outside of <part>, this is not a valid problem, errors in grading may occur."),'<>&"').'<br />');
56: }
57: if ($Apache::inputtags::part eq '0') {
58: $Apache::inputtags::response_with_no_part=1;
59: }
60: return $id;
61: }
62:
63: sub end_response {
64: #pop @Apache::inputtags::response;
65: @Apache::inputtags::inputlist=();
66: return '';
67: }
68:
69: sub start_hintresponse {
70: my ($parstack,$safeeval)=@_;
71: my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
72: if ($id eq '') { $id = $Apache::lonxml::curdepth; }
73: push (@Apache::inputtags::response,$id);
74: push (@Apache::inputtags::responselist,$id);
75: push (@Apache::inputtags::paramstack,[%Apache::inputtags::params]);
76: return $id;
77: }
78:
79: sub end_hintresponse {
80: pop @Apache::inputtags::response;
81: if (defined($Apache::inputtags::paramstack[-1])) {
82: %Apache::inputtags::params=
83: @{ pop(@Apache::inputtags::paramstack) };
84: }
85: return '';
86: }
87:
88: my @randomseeds;
89: sub pushrandomnumber {
90: my $rand_alg=&Apache::lonnet::get_rand_alg();
91: if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
92: $rand_alg eq '64bit2') {
93: # do nothing
94: } else {
95: my @seed=&Math::Random::random_get_seed();
96: push (@randomseeds,\@seed);
97: }
98: &Apache::response::setrandomnumber();
99: }
100: sub poprandomnumber {
101: my $rand_alg=&Apache::lonnet::get_rand_alg();
102: if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
103: $rand_alg eq '64bit2') {
104: return;
105: }
106: my $seed=pop(@randomseeds);
107: if ($seed) {
108: &Math::Random::random_set_seed(@$seed);
109: } else {
110: &Apache::lonxml::error("Unable to restore random algorithm.");
111: }
112: }
113: sub setrandomnumber {
114: my $rndseed;
115: $rndseed=&Apache::structuretags::setup_rndseed();
116: if (!defined($rndseed)) { $rndseed=&Apache::lonnet::rndseed(); }
117: &Apache::lonxml::debug("randseed $rndseed");
118: # $rndseed=unpack("%32i",$rndseed);
119: my $rand_alg=&Apache::lonnet::get_rand_alg();
120: my $rndmod;
121: if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
122: $rand_alg eq '64bit2') {
123: $rndmod=(&Apache::lonnet::numval($Apache::inputtags::part) << 10);
124: if (defined($Apache::inputtags::response[-1])) {
125: $rndmod+=&Apache::lonnet::numval($Apache::inputtags::response[-1]);
126: }
127: } else {
128: $rndmod=(&Apache::lonnet::numval2($Apache::inputtags::part) << 10);
129: if (defined($Apache::inputtags::response[-1])) {
130: $rndmod+=&Apache::lonnet::numval2($Apache::inputtags::response[-1]);
131: }
132: }
133: if ($rndseed =~/([,:])/) {
134: my $char=$1;
135: use integer;
136: my ($num1,$num2)=split(/\Q$char\E/,$rndseed);
137: $num1+=$rndmod;
138: $num2+=$rndmod;
139: $rndseed=$num1.$char.$num2;
140: } else {
141: $rndseed+=$rndmod;
142: }
143: &Apache::lonnet::setup_random_from_rndseed($rndseed);
144: &Apache::lonxml::debug("randseed $rndseed");
145: return '';
146: }
147:
148: sub meta_parameter_write {
149: my ($name,$type,$default,$display)=@_;
150: my $partref=$Apache::inputtags::part;
151: my $result='<parameter part="'.$Apache::inputtags::part.'"';
152: if (defined($Apache::inputtags::response[-1])) {
153: $result.= ' id="'.$Apache::inputtags::response[-1].'"';
154: $partref.='_'.$Apache::inputtags::response[-1];
155: }
156: $result.= ' name="'.$name.'"'.
157: ' type="'.$type.'"'.
158: (defined($default)?' default="'.$default.'"':'').
159: (defined($display)?' display="'.$display.' [Part: '.$partref.']"':'')
160: .'></parameter>'
161: ."\n";
162: return $result;
163: }
164:
165: sub meta_package_write {
166: my $name=shift;
167: my $result = '<parameter part="'.$Apache::inputtags::part.'"';
168: if(defined($Apache::inputtags::response[-1])) {
169: $result.= ' id="'.$Apache::inputtags::response[-1].'"';
170: }
171: $result.=' package="'.$name.'"></parameter>'."\n";
172: return $result;
173: }
174:
175: sub meta_stores_write {
176: my ($name,$type,$display)=@_;
177: my $partref=$Apache::inputtags::part;
178: my $result = '<stores part="'.$Apache::inputtags::part.'"';
179: if (defined($Apache::inputtags::response[-1])) {
180: $result.= ' id="'.$Apache::inputtags::response[-1].'"';
181: $partref.='_'.$Apache::inputtags::response[-1];
182: }
183: $result.= ' name="'.$name.'"'.
184: ' type="'.$type.'"'.
185: ' display="'.$display.' [Part: '.$partref.']"'.
186: "></stores>\n";
187: }
188:
189: sub mandatory_part_meta {
190: #
191: # Autogenerate metadata for mandatory
192: # input (from RAT or lonparmset) and
193: # output (to lonspreadsheet)
194: # of each part
195: #
196: return
197: # &meta_parameter_write('opendate','date_start','',
198: # 'Opening Date').
199: # &meta_parameter_write('duedate','date_end','',
200: # 'Due Date').
201: # &meta_parameter_write('answerdate','date_start','',
202: # 'Show Answer Date').
203: # &meta_parameter_write('weight','int_zeropos','',
204: # 'Available Points').
205: # &meta_parameter_write('maxtries','int_pos','',
206: # 'Maximum Number of Tries').
207: &meta_package_write('part').
208: &meta_stores_write('solved','string',
209: 'Problem Status').
210: &meta_stores_write('tries','int_zeropos',
211: 'Number of Attempts').
212: &meta_stores_write('awarded','float',
213: 'Partial Credit Factor');
214: #
215: # Note: responseid-specific data 'submission' and 'awarddetail'
216: # not available to spreadsheet -> skip here
217: #
218: }
219:
220: sub meta_part_order {
221: if (@Apache::inputtags::partlist) {
222: my @parts=@Apache::inputtags::partlist;
223: shift(@parts);
224: return '<partorder>'.join(',',@parts).'</partorder>'."\n";
225: } else {
226: return '<partorder>0</partorder>'."\n";
227: }
228: }
229:
230: sub meta_response_order {
231: if (@Apache::inputtags::responselist) {
232: return '<responseorder>'.join(',',@Apache::inputtags::responselist).
233: '</responseorder>'."\n";
234: }
235: }
236:
237: sub check_for_previous {
238: my ($curresponse,$partid,$id) = @_;
239: my %previous;
240: $previous{'used'} = 0;
241: foreach my $key (sort(keys(%Apache::lonhomework::history))) {
242: if ($key =~ /resource\.$partid\.$id\.submission$/) {
243: &Apache::lonxml::debug("Trying $key");
244: my $pastresponse=$Apache::lonhomework::history{$key};
245: if ($pastresponse eq $curresponse) {
246: $previous{'used'} = 1;
247: my $history;
248: if ( $key =~ /^(\d+):/ ) {
249: $history=$1;
250: $previous{'award'} = $Apache::lonhomework::history{"$history:resource.$partid.$id.awarddetail"};
251: $previous{'last'}='0';
252: push(@{ $previous{'version'} },$history);
253: } else {
254: $previous{'award'} = $Apache::lonhomework::history{"resource.$partid.$id.awarddetail"};
255: $previous{'last'}='1';
256: }
257: if (! $previous{'award'} ) { $previous{'award'} = 'UNKNOWN'; }
258: &Apache::lonxml::debug("got a match :$previous{'award'}:$previous{'used'}:");
259: }
260: }
261: }
262: &Apache::lonhomework::showhash(%previous);
263: return %previous;
264: }
265:
266: sub handle_previous {
267: my ($previous,$ad)=@_;
268: if ($$previous{'used'} && ($$previous{'award'} eq $ad) ) {
269: if ($$previous{'last'}) {
270: push(@Apache::inputtags::previous,'PREVIOUSLY_LAST');
271: push(@Apache::inputtags::previous_version,$$previous{'version'});
272: } elsif ($Apache::lonhomework::type ne 'survey') {
273: push(@Apache::inputtags::previous,'PREVIOUSLY_USED');
274: push(@Apache::inputtags::previous_version,$$previous{'version'});
275: }
276: }
277: }
278:
279: sub view_or_modify {
280: my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
281: my $myself=0;
282: if ( ($name eq $ENV{'user.name'}) && ($domain eq $ENV{'user.domain'}) ) {
283: $myself=1;
284: }
285: my $vgr=&Apache::lonnet::allowed('vgr',$courseid);
286: my $mgr=&Apache::lonnet::allowed('vgr',$courseid);
287: if ($mgr) { return "M"; }
288: if ($vgr) { return "V"; }
289: if ($myself) { return "V"; }
290: return '';
291: }
292:
293: sub start_dataresponse {
294: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
295: my $id = &Apache::response::start_response($parstack,$safeeval);
296: my $result;
297: if ($target eq 'web') {
298: $result = $token->[2]->{'display'}.':';
299: } elsif ($target eq 'meta') {
300: $result = &Apache::response::meta_stores_write($token->[2]->{'name'},
301: $token->[2]->{'type'},
302: $token->[2]->{'display'});
303: $result .= &Apache::response::meta_package_write('dataresponse');
304: }
305: return $result;
306: }
307:
308: sub end_dataresponse {
309: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
310: my $result;
311: if ( $target eq 'web' ) {
312: } elsif ($target eq 'grade' ) {
313: if ( defined $ENV{'form.submitted'}) {
314: my ($symb,$courseid,$domain,$name)=&Apache::lonxml::whichuser();
315: my $allowed=&Apache::lonnet::allowed('mgr',$courseid);
316: if ($allowed) {
317: &Apache::response::setup_params('dataresponse',$safeeval);
318: my $partid = $Apache::inputtags::part;
319: my $id = $Apache::inputtags::response['-1'];
320: my $response = $ENV{'form.HWVAL_'.$id};
321: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
322: if ( $response =~ /[^\s]/) {
323: $Apache::lonhomework::results{"resource.$partid.$id.$name"}=$response;
324: $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
325: $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}='SUBMITTED';
326: }
327: } else {
328: $result='Not Permitted to change values.'
329: }
330: }
331: }
332: &Apache::response::end_response;
333: return $result;
334: }
335:
336: sub decide_package {
337: my ($tagstack)=@_;
338: my $package;
339: if ($$tagstack[-1] eq 'parameter') {
340: $package='part';
341: } else {
342: my $i=-1;
343: while (defined($$tagstack[$i])) {
344: if ($$tagstack[$i] =~ /(response|hint)$/) {
345: $package=$$tagstack[$i];
346: last;
347: }
348: $i--;
349: }
350: }
351: return $package;
352: }
353:
354: sub start_responseparam {
355: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
356: my $result='';
357: if ($target eq 'meta') {
358: $result = &meta_parameter_write($token->[2]->{'name'},
359: $token->[2]->{'type'},
360: $token->[2]->{'default'},
361: $token->[2]->{'description'});
362: } elsif ($target eq 'edit') {
363: $result.=&Apache::edit::tag_start($target,$token);
364: my $optionlist;
365: my $package=&decide_package($tagstack);
366: foreach my $key (sort(keys(%Apache::lonnet::packagetab))) {
367: if ($key =~ /^\Q$package\E&(.*)&display$/) {
368: $optionlist.='<option value="'.$1.'">'.
369: $Apache::lonnet::packagetab{$key}.'</option>';
370: }
371: }
372: if (defined($optionlist)) {
373: $result.='Use template: <select name="'.
374: &Apache::edit::html_element_name('parameter_package').'">'.
375: '<option value=""></option>'.$optionlist.'</select><br />';
376: }
377: $result.=&Apache::edit::text_arg('Name:','name',$token).
378: &Apache::edit::text_arg('Type:','type',$token).
379: &Apache::edit::text_arg('Description:','description',$token).
380: &Apache::edit::text_arg('Default:','default',$token).
381: "</td></tr>";
382: $result.=&Apache::edit::end_table;
383: } elsif ($target eq 'modified') {
384: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
385: $safeeval,'name','type',
386: 'description','default');
387: my $element=&Apache::edit::html_element_name('parameter_package');
388: if (defined($ENV{"form.$element"}) && $ENV{"form.$element"} ne '') {
389: my $name=$ENV{"form.$element"};
390: my $tag=&decide_package($tagstack);
391: $token->[2]->{'name'}=$name;
392: $token->[2]->{'type'}=
393: $Apache::lonnet::packagetab{"$tag&$name&type"};
394: $token->[2]->{'description'}=
395: $Apache::lonnet::packagetab{"$tag&$name&display"};
396: $token->[2]->{'default'}=
397: $Apache::lonnet::packagetab{"$tag&$name&default"};
398: $constructtag=1;
399: }
400: if ($constructtag) {
401: $result = &Apache::edit::rebuild_tag($token);
402: $result.=&Apache::edit::handle_insert();
403: }
404: } elsif ($target eq 'grade' || $target eq 'answer' || $target eq 'web' ||
405: $target eq 'tex' || $target eq 'analyze' ) {
406: if ($ENV{'request.state'} eq 'construct') {
407: my $name =&Apache::lonxml::get_param('name',$parstack,$safeeval);
408: my $default=&Apache::lonxml::get_param('default',$parstack,
409: $safeeval);
410: if ($name) {$Apache::inputtags::params{$name}=$default;}
411: }
412: }
413: return $result;
414: }
415:
416: sub end_responseparam {
417: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
418: if ($target eq 'edit') { return ('','no'); }
419: return '';
420: }
421:
422: sub start_parameter {
423: my $result = &start_responseparam(@_);
424: return $result;
425: }
426:
427: sub end_parameter {
428: my $result = &end_responseparam(@_);
429: return $result;
430: }
431:
432: sub reset_params {
433: %Apache::inputtags::params=();
434: }
435:
436: sub setup_params {
437: my ($tag,$safeeval) = @_;
438:
439: if ($ENV{'request.state'} eq 'construct') { return; }
440: my %paramlist=();
441: foreach my $key (keys(%Apache::lonnet::packagetab)) {
442: if ($key =~ /^$tag/) {
443: my ($package,$name) = split(/&/,$key);
444: $paramlist{$name}=1;
445: }
446: }
447: foreach my $key (keys(%paramlist)) {
448: my $entry= 'resource.'.$Apache::inputtags::part;
449: if (defined($Apache::inputtags::response[-1])) {
450: $entry.='_'.$Apache::inputtags::response[-1];
451: }
452: $entry.='.'.$key;
453: &Apache::lonxml::debug("looking for $entry");
454: my $value = &Apache::lonnet::EXT("$entry");
455: &Apache::lonxml::debug("$key has value :$value:");
456: if ($value eq 'con_lost' || $value =~ /^error:/) {
457: &Apache::lonxml::debug("using nothing");
458: $Apache::inputtags::params{$key}='';
459: } else {
460: my $string="{return qq\0".$value."\0}";
461: my $newvalue=&Apache::run::run($string,$safeeval,1);
462: if (defined($newvalue)) { $value=$newvalue; }
463: $Apache::inputtags::params{$key}=$value;
464: }
465: }
466: }
467:
468: sub answer_header {
469: my ($type) = @_;
470: my $result;
471: if ($ENV{'form.answer_output_mode'} eq 'tex') {
472: $result = ' \vskip 0 mm \begin{tabular}{|c|}\hline Answer for Part: \verb|'.
473: $Apache::inputtags::part.'| \\\\ \hline ';
474: } else {
475: $result = '<table border="1"><tr><td>Answer for Part:'.
476: $Apache::inputtags::part. '</td>'."\n";
477: }
478: return $result;
479: }
480:
481: sub answer_part {
482: my ($type,$answer) = @_;
483: my $result;
484: if ($ENV{'form.answer_output_mode'} eq 'tex') {
485: $result = ' \verb|'.$answer.'|\\\\ \hline ';
486: } else {
487: $result = '<td>'.$answer.'</td>';
488: }
489: return $result;
490: }
491:
492: sub answer_footer {
493: my ($type) = @_;
494: my $result;
495: if ($ENV{'form.answer_output_mode'} eq 'tex') {
496: $result = ' \end{tabular} \vskip 0 mm ';
497: } else {
498: $result = '</tr></table>';
499: }
500: return $result;
501: }
502:
503: sub showallfoils {
504: if (defined($ENV{'form.showallfoils'})) {
505: my ($symb)=&Apache::lonxml::whichuser();
506: if ($ENV{'request.state'} eq 'construct' ||
507: ($ENV{'user.adv'} && $symb eq '')) {
508: return 1;
509: }
510: }
511: return 0;
512: }
513:
514: sub getresponse {
515: my ($temp,$resulttype)=@_;
516: my $formparm='form.HWVAL_'.$Apache::inputtags::response['-1'];
517: my $response;
518: if (!defined($temp)) {
519: $temp=1;
520: } else {
521: $formparm.=":$temp";
522: }
523: my %let_to_num=('A'=>0,'B'=>1,'C'=>2,'D'=>3,'E'=>4,'F'=>5,'G'=>6,'H'=>7,
524: 'I'=>8,'J'=>9,'K'=>10,'L'=>11,'M'=>12,'N'=>13,'O'=>14,
525: 'P'=>15,'Q'=>16,'R'=>17,'S'=>18,'T'=>19,'U'=>20,'V'=>21,
526: 'W'=>22,'X'=>23,'Y'=>24,'Z'=>25);
527: if ($ENV{'form.submitted'} eq 'scantron') {
528: my $part = $Apache::inputtags::part;
529: my $id = $Apache::inputtags::response[-1];
530: $response = $ENV{'scantron.'.($Apache::lonxml::counter+$temp-1).
531: '.answer'};
532: # save bubbled letter for later
533: $Apache::lonhomework::results{"resource.$part.$id.scantron"}.=
534: $response;
535: if ($resulttype ne 'letter') {
536: if ($resulttype eq 'A is 1') {
537: $response = $let_to_num{$response}+1;
538: } else {
539: $response = $let_to_num{$response};
540: }
541: }
542: } else {
543: $response = $ENV{$formparm};
544: }
545: return $response;
546: }
547:
548: sub repetition {
549: my $id = $Apache::inputtags::part;
550: my $weight = &Apache::lonnet::EXT("resource.$id.weight");
551: my $repetition = int $weight/9;
552: if ($weight % 9 != 0) {$repetition++;}
553: return $repetition;
554: }
555:
556: sub scored_response {
557: my ($part,$id)=@_;
558: my $repetition=&repetition();
559: my $score=0;
560: for (my $i=0;$i<$repetition;$i++) {
561: my $increase=&Apache::response::getresponse($i+1);
562: if ($increase ne '') { $score+=$increase+1; }
563: }
564: my $weight = &Apache::lonnet::EXT("resource.$part.weight");
565: if (!defined($weight) || $weight eq '' || $weight eq 0) { $weight = 1; }
566: my $pcr=$score/$weight;
567: $Apache::lonhomework::results{"resource.$part.$id.awarded"}=$pcr;
568: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=
569: 'ASSIGNED_SCORE';
570: return $repetition;
571: }
572:
573: sub whichorder {
574: my ($max,$randomize,$showall,$hash)=@_;
575: #&Apache::lonxml::debug("man $max randomize $randomize");
576: if (!defined(@{ $$hash{'names'} })) { return; }
577: my @names = @{ $$hash{'names'} };
578: my @whichopt =();
579: my (%top,@toplist,%bottom,@bottomlist);
580: if (!($showall || ($randomize eq 'no'))) {
581: my $current=0;
582: foreach my $name (@names) {
583: $current++;
584: if ($$hash{"$name.location"} eq 'top') {
585: $top{$name}=$current;
586: } elsif ($$hash{"$name.location"} eq 'bottom') {
587: $bottom{$name}=$current;
588: }
589: }
590: }
591: my $topcount=0;
592: my $bottomcount=0;
593: while (((scalar(@whichopt)+$topcount+$bottomcount) < $max || $showall)
594: && ($#names > -1)) {
595: #&Apache::lonxml::debug("Have $#whichopt max is $max");
596: my $aopt;
597: if ($showall || ($randomize eq 'no')) {
598: $aopt=0;
599: } else {
600: $aopt=int(&Math::Random::random_uniform() * ($#names+1));
601: }
602: #&Apache::lonxml::debug("From $#whichopt $max $#names elms, picking $aopt");
603: $aopt=splice(@names,$aopt,1);
604: #&Apache::lonxml::debug("Picked $aopt");
605: if ($top{$aopt}) {
606: $toplist[$top{$aopt}]=$aopt;
607: $topcount++;
608: } elsif ($bottom{$aopt}) {
609: $bottomlist[$bottom{$aopt}]=$aopt;
610: $bottomcount++;
611: } else {
612: push (@whichopt,$aopt);
613: }
614: }
615: for (my $i=0;$i<=$#toplist;$i++) {
616: if ($toplist[$i]) { unshift(@whichopt,$toplist[$i]) }
617: }
618: for (my $i=0;$i<=$#bottomlist;$i++) {
619: if ($bottomlist[$i]) { push(@whichopt,$bottomlist[$i]) }
620: }
621: return @whichopt;
622: }
623:
624: sub show_answer {
625: my $part = $Apache::inputtags::part;
626: my $award = $Apache::lonhomework::history{"resource.$part.solved"};
627: my $status = $Apache::inputtags::status[-1];
628: return ( ($award =~ /^correct/
629: && lc($Apache::lonhomework::problemstatus) ne 'no')
630: || $status eq "SHOW_ANSWER");
631: }
632:
633: sub analyze_store_foilgroup {
634: my ($shown,$attrs)=@_;
635: my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
636: foreach my $name (@{ $Apache::response::foilgroup{'names'} }) {
637: if (defined($Apache::lonhomework::analyze{"$part_id.foil.value.$name"})) { next; }
638: push (@{ $Apache::lonhomework::analyze{"$part_id.foils"} },$name);
639: foreach my $attr (@$attrs) {
640: $Apache::lonhomework::analyze{"$part_id.foil.".$attr.".$name"} =
641: $Apache::response::foilgroup{"$name.".$attr};
642: }
643: }
644: push (@{ $Apache::lonhomework::analyze{"$part_id.shown"} }, @{ $shown });
645: }
646:
647: sub check_if_computed {
648: my ($token,$parstack,$safeeval,$name)=@_;
649: my $value = &Apache::lonxml::get_param($name,$parstack,$safeeval);
650: if (ref($token->[2]) eq 'HASH' && $value ne $token->[2]{$name}) {
651: my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
652: $Apache::lonhomework::analyze{"$part_id.answercomputed"} = 1;
653: }
654: }
655:
656: sub pick_foil_for_concept {
657: my ($target,$attrs,$hinthash,$parstack,$safeeval)=@_;
658: if (not defined(@{ $Apache::response::conceptgroup{'names'} })) { return; }
659: my @names = @{ $Apache::response::conceptgroup{'names'} };
660: my $pick=int(&Math::Random::random_uniform() * ($#names+1));
661: my $name=$names[$pick];
662: push @{ $Apache::response::foilgroup{'names'} }, $name;
663: foreach my $attr (@$attrs) {
664: $Apache::response::foilgroup{"$name.".$attr} =
665: $Apache::response::conceptgroup{"$name.".$attr};
666: }
667: my $concept = &Apache::lonxml::get_param('concept',$parstack,$safeeval);
668: $Apache::response::foilgroup{"$name.concept"} = $concept;
669: &Apache::lonxml::debug("Selecting $name in $concept");
670: my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
671: if ($target eq 'analyze') {
672: push (@{ $Apache::lonhomework::analyze{"$part_id.concepts"} },
673: $concept);
674: $Apache::lonhomework::analyze{"$part_id.concept.$concept"}=
675: $Apache::response::conceptgroup{'names'};
676: foreach my $name (@{ $Apache::response::conceptgroup{'names'} }) {
677: push (@{ $Apache::lonhomework::analyze{"$part_id.foils"} },
678: $name);
679: foreach my $attr (@$attrs) {
680: $Apache::lonhomework::analyze{"$part_id.foil.$attr.$name"}=
681: $Apache::response::conceptgroup{"$name.$attr"};
682: }
683: }
684: }
685: push(@{ $hinthash->{"$part_id.concepts"} },$concept);
686: $hinthash->{"$part_id.concept.$concept"}=
687: $Apache::response::conceptgroup{'names'};
688:
689: }
690:
691: sub get_response_param {
692: my ($id,$name,$default)=@_;
693: my $parameter;
694: if ($ENV{'request.state'} eq 'construct' &&
695: defined($Apache::inputtags::params{$name})) {
696: $parameter=$Apache::inputtags::params{$name};
697: } else {
698: $parameter=&Apache::lonnet::EXT("resource.$id.$name");
699: }
700: if (!defined($parameter) || $parameter eq '') {
701: $parameter = $default;
702: }
703: return $parameter;
704: }
705:
706: 1;
707: __END__
708:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>