Annotation of loncom/homework/rankresponse.pm, revision 1.72
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # rank style response
3: #
1.72 ! golterma 4: # $Id: rankresponse.pm,v 1.71 2014/05/05 17:40:54 bisitz Exp $
1.1 albertel 5: # Copyright Michigan State University Board of Trustees
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27:
28: package Apache::rankresponse;
29: use strict;
30: use HTML::Entities();
1.30 albertel 31: use Apache::optionresponse();
32: use Apache::lonlocal;
1.58 onken 33: use Apache::lonxml;
34: use Apache::lonnet;
1.1 albertel 35:
36: BEGIN {
37: &Apache::lonxml::register('Apache::rankresponse',('rankresponse'));
38: }
39:
40: sub start_rankresponse {
41: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
42: my $result;
43: #when in a rank response use these
44: &Apache::lonxml::register('Apache::rankresponse',
45: ('foilgroup','foil','conceptgroup'));
46: push (@Apache::lonxml::namespace,'rankresponse');
47: my $id = &Apache::response::start_response($parstack,$safeeval);
48: %Apache::hint::rank=();
1.30 albertel 49: undef(%Apache::response::foilnames);
1.1 albertel 50: if ($target eq 'meta') {
51: $result=&Apache::response::meta_package_write('rankresponse');
52: } elsif ($target eq 'edit' ) {
1.59 bisitz 53: $result.=&Apache::edit::start_table($token)
1.72 ! golterma 54: .'<tr><td>'.&Apache::loncommon::insert_folding_button()
! 55: .&Apache::lonxml::description($token).'</td>'
1.61 bisitz 56: .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
1.59 bisitz 57: .&Apache::edit::deletelist($target,$token)
58: .'</span></td>'
1.60 raeburn 59: .'<td> '.&Apache::edit::end_row()
1.59 bisitz 60: .&Apache::edit::start_spanning_row();
1.1 albertel 61:
62: $result.=
63: &Apache::edit::text_arg('Max Number Of Shown Foils:','max',$token,'4').
1.59 bisitz 64: &Apache::edit::select_arg('Randomize Foil Order:','randomize',
1.1 albertel 65: ['yes','no'],$token).
66: &Apache::edit::end_row().&Apache::edit::start_spanning_row()."\n";
67: } elsif ($target eq 'modified') {
68: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
69: $safeeval,'max',
70: 'randomize');
71: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.25 albertel 72: } elsif ($target eq 'analyze') {
73: my $part_id="$Apache::inputtags::part.$id";
1.56 raeburn 74: $Apache::lonhomework::analyze{"$part_id.type"} = 'rankresponse';
1.25 albertel 75: push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
1.53 foxr 76: push (@{ $Apache::lonhomework::analyze{"$part_id.bubble_lines"} }, 1);
77:
1.1 albertel 78: }
79: return $result;
80: }
81:
82: sub end_rankresponse {
83: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
84: my $result;
85: if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
86: &Apache::response::end_response;
87: pop @Apache::lonxml::namespace;
88: &Apache::lonxml::deregister('Apache::rankresponse',
89: ('foilgroup','foil','conceptgroup'));
1.30 albertel 90: undef(%Apache::response::foilnames);
1.1 albertel 91: return $result;
92: }
93:
94: %Apache::response::foilgroup=();
95: sub start_foilgroup {
96: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
97: my $result;
98: %Apache::response::foilgroup=();
99: $Apache::rankresponse::conceptgroup=0;
1.64 raeburn 100: &Apache::response::pushrandomnumber(undef,$target);
1.1 albertel 101: return $result;
102: }
103:
104: sub end_foilgroup {
105: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
106: my $result;
1.26 albertel 107: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
108: $target eq 'tex' || $target eq 'analyze') {
1.1 albertel 109: my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
110: my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
111: $safeeval,'-2');
112: my $tol = &Apache::lonxml::get_param('tol',$parstack,$safeeval,'-2');
113: if (!defined($tol)) { $tol=0; }
1.3 sakharuk 114: if ($target eq 'web' || $target eq 'tex') {
1.1 albertel 115: $result=&displayfoils($target,$max,$randomize,$tol);
1.50 albertel 116: $Apache::lonxml::post_evaluate=0;
1.1 albertel 117: } elsif ($target eq 'answer' ) {
118: $result=&displayanswers($max,$randomize,$tol);
119: } elsif ( $target eq 'grade') {
120: &grade_response($max,$randomize,$tol);
1.25 albertel 121: } elsif ( $target eq 'analyze') {
122: my @shown = &whichfoils($max,$randomize);
123: &Apache::response::analyze_store_foilgroup(\@shown,
1.26 albertel 124: ['text','value','location']);
1.41 albertel 125: my $part_id=
126: "$Apache::inputtags::part.$Apache::inputtags::response[-1]";
127: $Apache::lonhomework::analyze{"$part_id.tol"}=$tol;
1.1 albertel 128: }
1.55 foxr 129: my $part = $Apache::inputtags::part;
130: my $id = $Apache::inputtags::response[-1];
1.66 raeburn 131: my ($numrows,$bubbles_per_row);
132: if (($target eq 'tex') && ($Apache::lonhomework::type eq 'exam')) {
133: my (@whichfoils)=&whichfoils($max,$randomize);
134: ($numrows,$bubbles_per_row) =
135: &Apache::optionresponse::getnumrows(scalar(@whichfoils));
136: }
137: if ($numrows < 1) {
138: $numrows = 1;
139: }
140: my $increment = &getfoilcounts($max) * $numrows;
141: &Apache::lonxml::increment_counter($increment,"$part.$id");
1.54 foxr 142: if ($target eq 'analyze') {
143: &Apache::lonhomework::set_bubble_lines();
144: }
1.14 albertel 145: } elsif ($target eq 'edit') {
146: $result=&Apache::edit::end_table();
1.1 albertel 147: }
1.34 albertel 148: &Apache::response::poprandomnumber();
1.1 albertel 149: return $result;
150: }
151:
152: sub get_correct_order {
153: my ($tol,@foils) =@_;
154: my @correctorder;
155: my @value_names;
156: foreach my $name (@foils) {
157: my @pair=($Apache::response::foilgroup{$name.'.value'},$name);
158: push(@value_names,\@pair);
159: }
160: @value_names =
161: sort {
1.17 albertel 162: if (abs($a->[0] - $b->[0]) > $tol) {return ($a->[0] <=> $b->[0]);}
1.1 albertel 163: return 0;
164: } @value_names;
165: my @value_names_tmp=@value_names;
166: my $firstpair=shift(@value_names_tmp);
167: my $order=1;
168: my %order;
169: my $count=1;
170: my $lastvalue=$firstpair->[0];
171: $order{$firstpair->[1]}=$order;
172: foreach my $pair (@value_names_tmp) {
173: $count++;
174: if (abs($pair->[0]-$lastvalue) > $tol ) {
175: $order=$count;
176: }
177: $order{$pair->[1]}=$order;
178: $lastvalue=$pair->[0];
179: }
180: foreach my $name (@foils) {
181: push(@correctorder,$order{$name});
182: }
183: &Apache::lonhomework::showhash('b' => \@value_names);
184: &Apache::lonhomework::showhash('b' => \@correctorder);
185: return @correctorder;
186: }
187:
188: sub displayanswers {
189: my ($max,$randomize,$tol,@opt)=@_;
1.68 raeburn 190: my @names;
191: if (ref($Apache::response::foilgroup{'names'}) eq 'ARRAY') {
192: @names = @{ $Apache::response::foilgroup{'names'} };
193: }
194: return if (!@names);
1.1 albertel 195: my @whichfoils = &whichfoils($max,$randomize);
196: my @correctorder=&get_correct_order($tol,@whichfoils);
1.49 albertel 197: my $result;
198: if ($Apache::lonhomework::type eq 'exam') {
199: my @alphabet = ('A'..'Z');
200: my $i=0;
201: foreach my $order (@correctorder) {
202: $result.=&Apache::response::answer_header('rankresponse',$i++);
203: $result.=&Apache::response::answer_part('rankresponse',
204: $alphabet[$order-1]);
205: $result.=&Apache::response::answer_part('rankresponse',$order);
206: $result.=&Apache::response::answer_footer('rankresponse');
207: }
208: } else {
209: $result=&Apache::response::answer_header('rankresponse');
210: foreach my $order (@correctorder) {
211: $result.=&Apache::response::answer_part('rankresponse',$order);
212: }
213: $result.=&Apache::response::answer_footer('rankresponse');
1.1 albertel 214: }
215: return $result;
216: }
217:
218: sub check_response_order {
219: my (%responsehash)=@_;
1.45 albertel 220: my @order=sort( {$a <=> $b} values(%responsehash));
1.1 albertel 221: my $lastvalue=0;
222: my $expected=1;
223: my $malformed=0;
224: foreach my $current (@order) {
225: &Apache::lonxml::debug("$lastvalue $expected $malformed");
226: if (!($current == $lastvalue || $current == $expected)) {
227: $malformed=1;
228: }
229: $expected++;
230: $lastvalue=$current;
231: }
232: return $malformed;
233: }
234:
235: sub grade_response {
236: my ($max,$randomize,$tol)=@_;
237: my (@whichfoils)=&whichfoils($max,$randomize);
1.44 albertel 238: if (!&Apache::response::submitted()) { return; }
1.1 albertel 239: my %responsehash;
240: my %grade;
1.28 albertel 241: my ($temp,$right,$wrong,$ignored)=(1,0,0,0);
1.1 albertel 242: my @correctorder=&get_correct_order($tol,@whichfoils);
1.66 raeburn 243: my ($numrows,$bubbles_per_row);
244: if ($Apache::lonhomework::scantronmode) {
245: my $numitems = scalar(@whichfoils);
246: ($numrows,$bubbles_per_row) =
247: &Apache::optionresponse::getnumrows($numitems);
248: }
249: if ($numrows < 1) {
250: $numrows = 1;
251: }
252:
1.1 albertel 253: foreach my $name (@whichfoils) {
1.66 raeburn 254: my $response;
255: if ($numrows > 1) {
256: my $num = $temp;
257: my $totalnum;
258: for (my $i=0; $i<$numrows; $i++) {
259: my $item = &Apache::response::getresponse($num,'A is 1');
260: if ($item =~ /^\d+$/) {
261: $totalnum = $i*$bubbles_per_row + $item;
262: }
263: $num ++;
264: }
265: $response = $totalnum;
266: $temp += $numrows;
267: } else {
268: $response = &Apache::response::getresponse($temp,'A is 1');
269: $temp ++;
270: }
1.1 albertel 271: my $value=shift(@correctorder);
272: if ( $response =~ /[^\s]/) {
1.27 albertel 273: $responsehash{$name}=$response;
1.1 albertel 274: &Apache::lonxml::debug("submitted a $response for $value<br />\n");
275: if ($value eq $response) {
276: $grade{$name}='1'; $right++;
277: } else {
278: $grade{$name}='0'; $wrong++;
279: }
280: } else {
281: $ignored++;
282: }
283: }
284: my $malformed=&check_response_order(%responsehash);
285: my $part=$Apache::inputtags::part;
286: my $id = $Apache::inputtags::response['-1'];
287: my $responsestr=&Apache::lonnet::hash2str(%responsehash);
288: my $gradestr =&Apache::lonnet::hash2str(%grade);
289: my %previous=&Apache::response::check_for_previous($responsestr,
290: $part,$id);
291: &Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored and was $malformed malformed");
292: my $ad;
293: if ($malformed) {
294: $ad='MISORDERED_RANK';
295: } elsif ($wrong==0 && $ignored==0) {
296: $ad='EXACT_ANS';
297: } elsif ($wrong==0 && $right==0) {
298: #nothing submitted
299: } else {
300: if ($ignored==0) {
301: $ad='INCORRECT';
302: } else {
303: $ad='MISSING_ANSWER';
304: }
305: }
1.62 raeburn 306: if (($ad eq 'INCORRECT' || $ad eq 'EXACT_ANS')) {
307: if ($Apache::lonhomework::type eq 'survey') {
308: $ad='SUBMITTED';
309: } elsif ($Apache::lonhomework::type eq 'surveycred') {
310: $ad='SUBMITTED_CREDIT';
311: } elsif ($Apache::lonhomework::type eq 'anonsurvey') {
312: $ad='ANONYMOUS';
313: } elsif ($Apache::lonhomework::type eq 'anonsurveycred') {
314: $ad='ANONYMOUS_CREDIT';
315: } else {
316: $Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=$gradestr;
317: }
1.40 albertel 318: } else {
319: $Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=$gradestr;
320: }
1.64 raeburn 321: if ($Apache::lonhomework::type eq 'randomizetry') {
322: if ($Apache::lonhomework::type eq 'randomizetry') {
323: $Apache::lonhomework::results{"resource.$part.$id.foilorder"} = &Apache::lonnet::array2str(@whichfoils);
324: }
325: }
1.1 albertel 326: $Apache::lonhomework::results{"resource.$part.$id.submission"}=
327: $responsestr;
328: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
329: &Apache::response::handle_previous(\%previous,$ad);
330: }
331:
1.52 albertel 332: sub format_prior_answer {
333: my ($mode,$answer,$other_data) = @_;
334: my %lastresponse=&Apache::lonnet::str2hash($answer);
335: my $foil_order =$other_data->[0];
336: my %grading =&Apache::lonnet::str2hash($other_data->[1]);
337: my $output;
338: foreach my $name (@{ $foil_order }) {
1.71 bisitz 339: if (defined($lastresponse{$name})) {
340: $output .= '<tr><td>'.&HTML::Entities::encode($lastresponse{$name},'<>&"').'</td></tr>';
341: } else {
342: $output .= '<tr><td> </td></tr>';
343: }
1.52 albertel 344: }
345: return if (!defined($output));
346: $output =
347: '<table class="LC_prior_rank">'.$output.'</table>';
348: return $output;
349: }
350:
1.1 albertel 351: sub displayfoils {
352: my ($target,$max,$randomize,$tol)=@_;
353: my $result;
1.4 sakharuk 354: my @alphabet=('A'..'Z');
1.1 albertel 355: my (@whichfoils)=&whichfoils($max,$randomize);
356: my $part=$Apache::inputtags::part;
357: my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
358: my @whichopt=(1..($#whichfoils+1));
359: my @correctorder=&get_correct_order($tol,@whichfoils);
1.20 sakharuk 360: if ( &Apache::response::show_answer() && ($target ne 'tex')) {
1.1 albertel 361: foreach my $name (@whichfoils) {
362: my $text=$Apache::response::foilgroup{$name.'.text'};
363: my $value=shift(@correctorder);
1.46 albertel 364: if ($target eq 'web') {
365: $result.='<br /><b>'.$value.':</b> '.$text;
366: } else {
367: $result.=' \strut\\\\\strut '.$value.':'.$text;
368: }
1.1 albertel 369: }
370: } else {
371: my $i = 0;
1.29 albertel 372: my $temp=1;
1.1 albertel 373: my $id=$Apache::inputtags::response[-1];
374: my $part=$Apache::inputtags::part;
1.64 raeburn 375: my ($lastresponse,$newvariation);
376: if ((($Apache::lonhomework::history{"resource.$part.type"} eq 'randomizetry') ||
377: ($Apache::lonhomework::type eq 'randomizetry')) &&
378: ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
379: if ($env{'form.'.$part.'.rndseed'} ne
380: $Apache::lonhomework::history{"resource.$part.rndseed"}) {
381: $newvariation = 1;
382: }
383: }
1.69 raeburn 384: unless ($newvariation) {
385: if ((($env{'form.grade_username'} eq '') && ($env{'form.grade_domain'} eq '')) ||
386: (($env{'form.grade_username'} eq $env{'user.name'}) &&
387: ($env{'form.grade_domain'} eq $env{'user.domain'}))) {
388: $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
389: } else {
390: unless (($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') ||
391: ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) {
392: $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
393: }
394: }
1.62 raeburn 395: }
1.5 sakharuk 396: my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
397: my @alp = splice @alphabet, 0, $#whichopt + 1;
1.15 sakharuk 398: my $internal_counter=$Apache::lonxml::counter;
1.66 raeburn 399: my ($numrows,$bubbles_per_row);
400: if (($target eq 'tex') && ($Apache::lonhomework::type eq 'exam')) {
401: ($numrows,$bubbles_per_row) =
402: &Apache::optionresponse::getnumrows(scalar(@alp));
403: } else {
404: $numrows = 1;
405: }
1.58 onken 406: if($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes') {
407: $result .= '\strut \\\\ \strut \\\\' ;
408: }
409: foreach my $name (@whichfoils) {
1.1 albertel 410: my $lastopt=$lastresponse{$name};
1.3 sakharuk 411: my $optionlist='';
1.58 onken 412: if ($target ne 'tex') {
413: $optionlist = "<option></option>\n";
414: }
415: if ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes') {
416: my $fieldname = $env{'request.symb'}.'&part_'.$Apache::inputtags::part.'&rankresponse'.'&HWVAL_'.$Apache::inputtags::response['-1'].':'.$temp;
417: $optionlist = &Apache::lonxml::print_pdf_start_combobox($fieldname);
418: }
1.1 albertel 419: my $option;
420: foreach $option (@whichopt) {
421: if ($option eq $lastopt) {
1.58 onken 422: if ($target ne 'tex' ) {
1.64 raeburn 423: $optionlist.="<option selected=\"selected\">$option</option>\n";
1.58 onken 424: } elsif ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes') {
425: $optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option);
426: }
1.1 albertel 427: } else {
1.58 onken 428: if ($target ne 'tex') {
429: $optionlist.="<option>$option</option>\n";
430: } elsif ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes') {
431: $optionlist .= &Apache::lonxml::print_pdf_add_combobox_option($option);
432: }
433: }
1.1 albertel 434: }
1.12 sakharuk 435: if ($target ne 'tex' && $Apache::lonhomework::type ne 'exam') {
1.51 albertel 436: $optionlist='<select onchange="javascript:setSubmittedPart(\''.
437: $part.'\');" name="HWVAL_'.
1.3 sakharuk 438: $Apache::inputtags::response[-1].':'.$temp.'">'.
439: $optionlist."</select>\n";
1.58 onken 440: } elsif ($env{'form.pdfFormFields'} eq 'yes') {
441: #do nothing
442: } else {
1.3 sakharuk 443: $optionlist=' '.$temp.' '.$optionlist.' ';
444: }
1.1 albertel 445: my $text=$Apache::response::foilgroup{$name.'.text'};
1.3 sakharuk 446: if ($target ne 'tex') {
1.12 sakharuk 447: if ($Apache::lonhomework::type ne 'exam') {
448: $result.='<br />'.$optionlist.$text."\n";
449: } else {
450: $result.='<br />'.$text."\n";
451: }
1.4 sakharuk 452: if ($Apache::lonhomework::type eq 'exam') {
1.22 albertel 453: my @values=(1..scalar(@whichopt));
454: $result.=&Apache::optionresponse::webbubbles(\@values,\@whichopt,$temp,$lastopt);
1.4 sakharuk 455: }
456: } else {
457: if ($Apache::lonhomework::type eq 'exam') {
1.66 raeburn 458: my $itemlabel;
459: if ($numrows == 1) {
460: $itemlabel = '\item[\textbf{'.$internal_counter.'}]';
461: } else {
462: my $linetext;
463: for (my $i=0; $i<$numrows; $i++) {
464: $linetext .= $internal_counter+$i.', ';
465: }
466: $linetext =~ s/,\s$//;
467: $itemlabel = '\item[\small {\textbf{'.$linetext.'}}]'.
468: ' {\footnotesize '.
469: &mt('(Bubble once in [_1] lines)',$numrows).
470: '} \hspace*{\fill} \\\\';
471: }
1.63 foxr 472: $result .= '\vskip 0 mm '.$text.' \vskip 0 mm '."\n";
473: $result .= '\vskip -1 mm';
1.66 raeburn 474: $result .= '\begin{enumerate}'.$itemlabel;
475: $result .= &Apache::optionresponse::bubbles(\@alp,\@whichopt,'rankresponse',undef,$numrows,$bubbles_per_row,$internal_counter);
476: $result .= '\end{enumerate} \vskip -8 mm \strut ';
477: $internal_counter += $numrows;
1.4 sakharuk 478: } else {
1.58 onken 479: if($env{'form.pdfFormFields'} ne 'yes') {
480: $result.=' \vskip 0mm \framebox[5 mm][s]{\tiny\strut} '.$text."\n";
481: } else {
482: $result.= $optionlist.' '. &Apache::lonxml::print_pdf_end_combobox($text).'\strut \\\\';
483: }
1.4 sakharuk 484: }
485: }
1.1 albertel 486: $temp++;
487: }
488: }
1.52 albertel 489: if ($target eq 'web') {
1.64 raeburn 490: my $questiontype;
491: if ($Apache::lonhomework::type eq 'randomizetry') {
492: $questiontype = $Apache::lonhomework::type;
493: }
1.52 albertel 494: &Apache::response::setup_prior_tries_hash(\&format_prior_answer,
495: [\@whichfoils,
1.64 raeburn 496: 'submissiongrading'],
497: $questiontype);
1.52 albertel 498: }
1.5 sakharuk 499: if ($target ne 'tex') {$result.="<br />";} else {$result.=' \vskip 0 mm ';}
1.1 albertel 500: return $result;
501: }
502:
503: sub getfoilcounts {
504: my ($max)=@_;
505: # +1 since instructors will count from 1
506: my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
507: if (&Apache::response::showallfoils()) { $max=$count; }
508: if ($count>$max) { $count=$max }
509: &Apache::lonxml::debug("Count is $count from $max");
510: return $count;
511: }
512:
513: sub whichfoils {
514: my ($max,$randomize)=@_;
1.13 albertel 515: return &Apache::response::whichorder($max,$randomize,
516: &Apache::response::showallfoils(),
517: \%Apache::response::foilgroup);
1.1 albertel 518: }
519:
520: sub start_conceptgroup {
521: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
522: $Apache::rankresponse::conceptgroup=1;
523: %Apache::response::conceptgroup=();
524: my $result;
525: if ($target eq 'edit') {
526: $result.=&Apache::edit::tag_start($target,$token,
527: "Concept Grouped Foils");
528: $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
529: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
530: }
531: if ($target eq 'modified') {
532: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
533: $safeeval,'concept');
534: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
535: }
536: return $result;
537: }
538:
539: sub end_conceptgroup {
540: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
541: $Apache::rankresponse::conceptgroup=0;
542: my $result='';
1.25 albertel 543: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
544: $target eq 'tex' || $target eq 'analyze') {
1.1 albertel 545: #if not there aren't any foils to display and thus no question
1.25 albertel 546: &Apache::response::pick_foil_for_concept($target,
547: ['value','text','location'],
548: \%Apache::hint::rank,
549: $parstack,$safeeval);
1.1 albertel 550: } elsif ($target eq 'edit') {
551: $result=&Apache::edit::end_table();
552: }
553: return $result;
554: }
555:
556: sub insert_conceptgroup {
557: my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
558: return $result;
559: }
560:
561: sub start_foil {
562: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
563: my $result='';
1.25 albertel 564: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
1.1 albertel 565: &Apache::lonxml::startredirection;
1.39 albertel 566: if ($target eq 'analyze') {
567: &Apache::response::check_if_computed($token,$parstack,$safeeval,'value');
568: }
1.1 albertel 569: } elsif ($target eq 'edit') {
570: $result=&Apache::edit::tag_start($target,$token,"Foil");
571: my $level='-2';
572: if ($$tagstack[-2] eq 'conceptgroup') { $level = '-3'; }
573: $result.=&Apache::edit::text_arg('Name:','name',$token);
574: $result.= &Apache::edit::text_arg('Rank Value:','value',$token,'15');
575: my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
576: $safeeval,'-3');
577: if ($randomize ne 'no') {
578: $result.=&Apache::edit::select_arg('Location:','location',
579: ['random','top','bottom'],$token);
580: }
581: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
582: } elsif ($target eq 'modified') {
583: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
584: $safeeval,'value',
585: 'name','location');
586: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
587: }
588: return $result;
589: }
590:
591: sub end_foil {
592: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
593: my $text ='';
594: my $result = '';
1.25 albertel 595: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
1.1 albertel 596: $text=&Apache::lonxml::endredirection;
597: }
1.25 albertel 598: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
599: $target eq 'tex' || $target eq 'analyze') {
1.1 albertel 600: my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
1.42 albertel 601: if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
602: $text='\vskip 5mm $\triangleright$ '.$text;
603: }
1.1 albertel 604: if ($value ne 'unused') {
605: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
606: &Apache::lonxml::debug("Got a name of :$name:");
1.48 albertel 607: if ($name eq "") {
1.57 bisitz 608: &Apache::lonxml::warning(&mt('Foils without names exist. This can cause problems to malfunction.'));
1.43 albertel 609: $name=$Apache::lonxml::curdepth;
610: }
1.1 albertel 611: &Apache::lonxml::debug("Using a name of :$name:");
1.30 albertel 612: if (defined($Apache::response::foilnames{$name})) {
1.57 bisitz 613: &Apache::lonxml::error(&mt('Foil name [_1] appears more than once. Foil names need to be unique.','<b><tt>'.$name.'</tt></b>'));
1.30 albertel 614: }
1.31 albertel 615: $Apache::response::foilnames{$name}++;
1.30 albertel 616: my $location =&Apache::lonxml::get_param('location',$parstack,
617: $safeeval);
1.1 albertel 618: if ( $Apache::rankresponse::conceptgroup
619: && !&Apache::response::showallfoils() ) {
620: push @{ $Apache::response::conceptgroup{'names'} }, $name;
621: $Apache::response::conceptgroup{"$name.value"} = $value;
1.42 albertel 622: $Apache::response::conceptgroup{"$name.text"} = $text;
1.1 albertel 623: $Apache::response::conceptgroup{"$name.location"} = $location;
624: } else {
625: push @{ $Apache::response::foilgroup{'names'} }, $name;
626: $Apache::response::foilgroup{"$name.value"} = $value;
1.42 albertel 627: $Apache::response::foilgroup{"$name.text"} = $text;
1.1 albertel 628: $Apache::response::foilgroup{"$name.location"} = $location;
629: }
630: }
631: }
632: if ($target eq 'edit') {
633: $result.= &Apache::edit::tag_end($target,$token,'');
634: }
635: return $result;
636: }
637:
638: sub insert_foil {
639: return '
640: <foil name="" value="unused">
641: <startouttext />
642: <endouttext />
643: </foil>';
644: }
645: 1;
646: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>