Annotation of loncom/homework/optionresponse.pm, revision 1.96.2.2
1.46 sakharuk 1: # LearningOnline Network with CAPA
1.22 albertel 2: # option list style responses
1.27 albertel 3: #
1.96.2.2! albertel 4: # $Id: optionresponse.pm,v 1.96.2.1 2004/02/19 19:19:15 albertel Exp $
1.27 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/
27: #
1.1 albertel 28: package Apache::optionresponse;
29: use strict;
1.6 albertel 30: use Apache::response;
1.1 albertel 31:
1.31 harris41 32: BEGIN {
1.1 albertel 33: &Apache::lonxml::register('Apache::optionresponse',('optionresponse'));
34: }
35:
36: sub start_optionresponse {
1.22 albertel 37: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
38: my $result='';
1.29 albertel 39: #when in a option response use these
1.22 albertel 40: &Apache::lonxml::register('Apache::optionresponse',('foilgroup','foil','conceptgroup'));
41: push (@Apache::lonxml::namespace,'optionresponse');
42: my $id = &Apache::response::start_response($parstack,$safeeval);
1.57 albertel 43: %Apache::hint::option=();
1.22 albertel 44: if ($target eq 'edit') {
1.23 albertel 45: $result.=&Apache::edit::start_table($token).
1.30 matthew 46: "<tr><td>Multiple Option Response Question</td><td>Delete:".
1.23 albertel 47: &Apache::edit::deletelist($target,$token)
1.30 matthew 48: ."</td><td> ".
49: &Apache::edit::end_row().
50: &Apache::edit::start_spanning_row().
51: "\n";
1.48 albertel 52: $result.=&Apache::edit::text_arg('Max Number Of Shown Foils:','max',
53: $token,'4').
54: &Apache::edit::select_arg('Randomize Foil Order','randomize',
55: ['yes','no'],$token).
56: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.34 albertel 57: } elsif ($target eq 'modified') {
1.23 albertel 58: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.48 albertel 59: $safeeval,'max','randomize');
1.22 albertel 60: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.34 albertel 61: } elsif ($target eq 'meta') {
1.23 albertel 62: $result=&Apache::response::meta_package_write('optionresponse');
1.34 albertel 63: } elsif ($target eq 'analyze') {
1.93 albertel 64: my $part_id="$Apache::inputtags::part.$id";
1.34 albertel 65: push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
1.22 albertel 66: }
67: return $result;
1.1 albertel 68: }
69:
70: sub end_optionresponse {
1.22 albertel 71: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
72: &Apache::response::end_response;
73: pop @Apache::lonxml::namespace;
1.29 albertel 74: &Apache::lonxml::deregister('Apache::optionresponse',('foilgroup','foil','conceptgroup'));
1.22 albertel 75: my $result;
76: if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
77: return $result;
1.1 albertel 78: }
79:
1.44 albertel 80: %Apache::response::foilgroup=();
1.1 albertel 81: sub start_foilgroup {
1.22 albertel 82: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
83:
84: my $result='';
1.44 albertel 85: %Apache::response::foilgroup=();
1.22 albertel 86: $Apache::optionresponse::conceptgroup=0;
87: &Apache::response::setrandomnumber();
88: if ($target eq 'edit') {
89: my $optionlist="<option></option>\n";
90: my $option;
91: my @opt;
92: eval '@opt ='. &Apache::lonxml::get_param('options',$parstack,$safeeval);
93: my $count=1;
94: foreach $option (@opt) {
95: $optionlist.="<option value=\"$count\">$option</option>\n";
96: $count++;
97: }
98: my $insertlist=&Apache::edit::insertlist($target,$token);
99: $result.=&Apache::edit::start_table($token);
100: $result.= (<<ENDTABLE);
101: <tr><td>Select Options</td>
1.13 albertel 102: <td>
103: Add new Option: <input type="text" name="$Apache::lonxml::curdepth.options" />
104: </td>
105: <td>Delete an Option:
106: <select name="$Apache::lonxml::curdepth.deleteopt">$optionlist</select>
107: ENDTABLE
1.30 matthew 108: $result.= &Apache::edit::end_row();
109: $result.= &Apache::edit::start_spanning_row();
110: $result.= $insertlist.'<br />';
1.22 albertel 111: }
112: if ($target eq 'modified') {
113: my @options;
114: my $optchanged=0;
115: eval '@options ='.&Apache::lonxml::get_param('options',$parstack,$safeeval);
116: if ($ENV{"form.$Apache::lonxml::curdepth.deleteopt"}) {
117: my $delopt=$ENV{"form.$Apache::lonxml::curdepth.deleteopt"};
118: &Apache::lonxml::debug("Deleting :$delopt:");
119: splice(@options,$delopt-1,1);
120: $optchanged=1;
121: }
122: if ($ENV{"form.$Apache::lonxml::curdepth.options"}) {
123: my $newopt = $ENV{"form.$Apache::lonxml::curdepth.options"};
124: if ($options[0]) {
125: push(@options,$newopt);
126: } else {
127: $options[0]=$newopt;
128: }
129: $optchanged=1;
130: }
131: if ($optchanged) {
132: $result = "<foilgroup options=\"(";
133: foreach my $option (@options) {
1.41 albertel 134: $option=~s/\'/\\\'/g;
1.22 albertel 135: &Apache::lonxml::debug("adding option :$option:");
136: $result .="'".$option."',";
137: }
138: chop $result;
139: $result.=')">';
140: } # else nothing changed so just use the default mechanism
141: }
1.68 sakharuk 142: if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
1.42 sakharuk 143: $result .= ' \begin{enumerate} ';
144: }
1.22 albertel 145: return $result;
1.1 albertel 146: }
147:
148: sub end_foilgroup {
1.22 albertel 149: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
150:
151: my $result;
1.94 albertel 152: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
153: $target eq 'tex' || $target eq 'analyze') {
1.81 sakharuk 154: my $tex_option_switch=&Apache::lonxml::get_param('texoptions',$parstack,$safeeval);
1.22 albertel 155: my $name;
156: my @opt;
157: eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval);
1.81 sakharuk 158: if ($target eq 'tex' && $tex_option_switch eq 'nochoice') {@opt=();}
1.22 albertel 159: &Apache::lonxml::debug("Options are $#opt");
1.48 albertel 160: my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
161: my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
162: $safeeval,'-2');
1.32 sakharuk 163: if ($target eq 'web' || $target eq 'tex') {
1.48 albertel 164: $result.=&displayfoils($target,$max,$randomize,@opt);
1.25 albertel 165: } elsif ( $target eq 'answer') {
1.48 albertel 166: $result.=&displayanswers($max,$randomize,@opt);
1.34 albertel 167: } elsif ( $target eq 'analyze') {
1.93 albertel 168: my @shown = &whichfoils($max,$randomize);
1.94 albertel 169: &Apache::response::analyze_store_foilgroup(\@shown,
170: ['text','value','location']);
1.93 albertel 171: my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
172: push (@{ $Apache::lonhomework::analyze{"$part_id.options"} },@opt);
1.22 albertel 173: } elsif ( $target eq 'grade') {
174: if ( defined $ENV{'form.submitted'}) {
1.48 albertel 175: my @whichopt = &whichfoils($max,$randomize);
1.22 albertel 176: my $temp=1;my $name;
1.26 albertel 177: my %responsehash;
1.57 albertel 178: my %grade;
1.22 albertel 179: my $right=0;
180: my $wrong=0;
181: my $ignored=0;
182: foreach $name (@whichopt) {
1.74 albertel 183: my $response=&Apache::response::getresponse($temp);
184: if ($ENV{'form.submitted'} eq 'scantron') {
185: $response = $opt[$response];
186: }
1.22 albertel 187: if ( $response =~ /[^\s]/) {
1.96 albertel 188: $responsehash{$name}=$response;
1.22 albertel 189: my $value=$Apache::response::foilgroup{$name.'.value'};
1.34 albertel 190: &Apache::lonxml::debug("submitted a $response for $value<br />\n");
1.57 albertel 191: if ($value eq $response) {
192: $grade{$name}='1'; $right++;
193: } else {
194: $grade{$name}='0'; $wrong++;
195: }
1.22 albertel 196: } else {
197: $ignored++;
198: }
199: $temp++;
200: }
1.28 albertel 201: my $part=$Apache::inputtags::part;
1.22 albertel 202: my $id = $Apache::inputtags::response['-1'];
1.28 albertel 203: my $responsestr=&Apache::lonnet::hash2str(%responsehash);
1.57 albertel 204: my $gradestr =&Apache::lonnet::hash2str(%grade);
1.28 albertel 205: my %previous=&Apache::response::check_for_previous($responsestr,
206: $part,$id);
1.22 albertel 207: &Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored");
1.75 albertel 208: $Apache::lonhomework::results{"resource.$part.$id.submission"}=
209: $responsestr;
210: $Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=$gradestr;
211:
212: if (!$Apache::lonhomework::scantronmode) {
213: my $ad;
214: if ($wrong==0 && $ignored==0) {
215: $ad='EXACT_ANS';
216: } elsif ($wrong==0 && $right==0) {
217: #nothing submitted
218: } else {
219: if ($ignored==0) {
220: $ad='INCORRECT';
221: } else {
222: $ad='MISSING_ANSWER';
223: }
224: }
225: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
226: &Apache::response::handle_previous(\%previous,$ad);
1.22 albertel 227: } else {
1.75 albertel 228: my $ad;
229: if ($wrong==0 && $right==0) {
230: #nothing submitted
231: } else {
232: $ad='ASSIGNED_SCORE';
233: }
234: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
235: $Apache::lonhomework::results{"resource.$part.$id.awarded"}=
236: $right/(scalar(@whichopt));
1.76 albertel 237: $Apache::lonhomework::results{"resource.$part.$id.numfoils"}=
238: scalar(@whichopt);
1.1 albertel 239: }
1.22 albertel 240: }
1.1 albertel 241: }
1.92 sakharuk 242: &Apache::lonxml::increment_counter(&getfoilcounts($max));
1.25 albertel 243: } elsif ($target eq 'edit') {
1.22 albertel 244: $result.=&Apache::edit::end_table();
1.74 albertel 245: }
246: if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
247: $result .= '\end{enumerate}';
248: }
1.22 albertel 249: return $result;
1.1 albertel 250: }
251:
252: sub getfoilcounts {
1.48 albertel 253: my ($max)=@_;
1.22 albertel 254: # +1 since instructors will count from 1
255: my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
1.39 albertel 256: if (&Apache::response::showallfoils()) { $max=$count; }
1.48 albertel 257: if ($count>$max) { $count=$max }
258: &Apache::lonxml::debug("Count is $count from $max");
259: return $count;
1.1 albertel 260: }
261:
262: sub whichfoils {
1.77 albertel 263: my ($max,$randomize)=@_;
264: return &Apache::response::whichorder($max,$randomize,
265: &Apache::response::showallfoils(),
266: \%Apache::response::foilgroup);
1.1 albertel 267: }
268:
1.25 albertel 269: sub displayanswers {
1.48 albertel 270: my ($max,$randomize,@opt)=@_;
1.67 albertel 271: if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
1.25 albertel 272: my @names = @{ $Apache::response::foilgroup{'names'} };
1.48 albertel 273: my @whichopt = &whichfoils($max,$randomize);
1.25 albertel 274: my $result=&Apache::response::answer_header('optionresponse');
275: foreach my $name (@whichopt) {
276: $result.=&Apache::response::answer_part('optionresponse',
277: $Apache::response::foilgroup{$name.'.value'})
278: }
279: $result.=&Apache::response::answer_footer('optionresponse');
280: return $result;
281: }
282:
1.1 albertel 283: sub displayfoils {
1.48 albertel 284: my ($target,$max,$randomize,@opt)=@_;
1.67 albertel 285: if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
1.22 albertel 286: my @names = @{ $Apache::response::foilgroup{'names'} };
287: my @truelist;
288: my @falselist;
1.79 sakharuk 289: my $result;
1.22 albertel 290: my $name;
1.45 albertel 291: my $displayoptionintex=0;
1.72 sakharuk 292: my @alphabet = ('A'..'Z');
1.48 albertel 293: my @whichopt = &whichfoils($max,$randomize);
1.28 albertel 294: my $part=$Apache::inputtags::part;
295: my $id=$Apache::inputtags::response[-1];
1.62 albertel 296: my $break;
1.65 albertel 297: my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
1.86 albertel 298: if ( ($target ne 'tex') &&
299: &Apache::response::show_answer() ) {
1.90 albertel 300: my $temp=1;
1.22 albertel 301: foreach $name (@whichopt) {
1.62 albertel 302: my $text=$Apache::response::foilgroup{$name.'.text'};
1.90 albertel 303: my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
304: my $lastopt=$lastresponse{$name};
1.62 albertel 305: if ($text!~/^\s*$/) {
306: if ($target eq 'tex') {
307: $break='\vskip 0 mm ';
308: } elsif ($target eq 'web') {
309: $break='<br />';
310: }
311: }
312: $result.=$break;
313: if ($target eq 'web') {
314: my $value=$Apache::response::foilgroup{$name.'.value'};
315: if (!($text=~s|<drawoptionlist\s*/>|$value|)) {
316: if ($text=~/^\s*$/) {
317: $text=$value.$text;
318: } else {
319: $text=$value.': '.$text;
320: }
1.95 albertel 321: } else {
322: $text='•'.$text;
1.62 albertel 323: }
324: $result.=$text."\n";
1.46 sakharuk 325: } elsif ($target eq 'tex') {
1.54 sakharuk 326: $Apache::response::foilgroup{$name.'.text'}=~s/\\item//;
1.82 sakharuk 327: if ($max>1) {$result .='\item ';}
328: $result .=' \textit{'.$Apache::response::foilgroup{$name.'.value'}.'}'.
1.46 sakharuk 329: ":".$Apache::response::foilgroup{$name.'.text'}."\n";
1.32 sakharuk 330: }
1.58 sakharuk 331: if ($Apache::lonhomework::type eq 'exam') {
332: if ($target ne 'tex') {
1.90 albertel 333: $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
1.58 sakharuk 334: } else {
335: $result.=&bubbles(\@alphabet,\@opt);
336: }
337: }
1.90 albertel 338: $temp++;
1.22 albertel 339: }
340: } else {
341: my $temp=1;
1.28 albertel 342: my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
1.79 sakharuk 343: my $internal_counter=$Apache::lonxml::counter;
1.22 albertel 344: foreach $name (@whichopt) {
1.62 albertel 345: my $text=$Apache::response::foilgroup{$name.'.text'};
346: if ($text!~/^\s*$/) {
347: if ($target eq 'tex') {
348: $break='\vskip 0 mm ';
349: } elsif ($target eq 'web') {
350: $break='<br />';
351: }
352: }
1.28 albertel 353: my $lastopt=$lastresponse{$name};
354: my $optionlist="<option></option>\n";
355: my $option;
356: foreach $option (@opt) {
357: if ($option eq $lastopt) {
358: $optionlist.="<option selected=\"on\">$option</option>\n";
359: } else {
360: $optionlist.="<option>$option</option>\n";
361: }
362: }
1.32 sakharuk 363: if ($target ne 'tex') {
1.72 sakharuk 364: if ($Apache::lonhomework::type ne 'exam') {
365: $optionlist='<select name="HWVAL_'.
1.59 albertel 366: $Apache::inputtags::response['-1'].':'.$temp.'">'.
367: $optionlist."</select>\n";
1.72 sakharuk 368: }
1.59 albertel 369: my $text=$Apache::response::foilgroup{$name.'.text'};
1.72 sakharuk 370: if (!($text=~s|<drawoptionlist\s*/>|$optionlist|) && $Apache::lonhomework::type ne 'exam') {
1.59 albertel 371: $text=$optionlist.$text;
1.95 albertel 372: } else {
373: $text='•'.$text;
1.59 albertel 374: }
1.62 albertel 375: $result.=$break.$text."\n";
1.49 sakharuk 376: if ($Apache::lonhomework::type eq 'exam') {
1.90 albertel 377: $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
1.49 sakharuk 378: }
1.32 sakharuk 379: $temp++;
380: } else {
1.60 sakharuk 381: my $texoptionlist = &optionlist_correction($optionlist);
1.45 albertel 382: if ($displayoptionintex == 0) {
1.60 sakharuk 383: if ($Apache::lonhomework::type eq 'exam') {$texoptionlist='';} #if exam we do not need to show optionlist
1.46 sakharuk 384: if ($Apache::response::foilgroup{$name.'.text'}=~m/\\item /) {
1.60 sakharuk 385: if ($Apache::lonhomework::type eq 'exam') {
1.68 sakharuk 386: $Apache::response::foilgroup{$name.'.text'}=~s/\\item/\\vskip 2 mm/;
1.60 sakharuk 387: }
388: if ($Apache::response::foilgroup{$name.'.text'}=~/<drawoptionlist\s*\/>/) {
1.61 sakharuk 389: $Apache::response::foilgroup{$name.'.text'}=~s|<drawoptionlist\s*/>| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |;
1.63 sakharuk 390: }
1.64 albertel 391: $result.= $texoptionlist.$Apache::response::foilgroup{$name.'.text'};
1.46 sakharuk 392: } else {
1.51 sakharuk 393: if ($Apache::lonhomework::type eq 'exam') {
1.68 sakharuk 394: $result.= $texoptionlist.' '.$Apache::response::foilgroup{$name.'.text'};
1.51 sakharuk 395: } else {
1.56 sakharuk 396: $result.= $texoptionlist.'\vspace*{-2 mm}\item '.$Apache::response::foilgroup{$name.'.text'};
1.51 sakharuk 397: }
1.46 sakharuk 398: }
1.50 sakharuk 399: if ($Apache::lonhomework::type eq 'exam') {
1.96.2.1 albertel 400: $result.='\vskip -1 mm\noindent\begin{enumerate}\item[\textbf{'.$internal_counter.'}.]'.&bubbles(\@alphabet,\@opt).'\end{enumerate} \vskip -9 mm \strut ';
1.79 sakharuk 401: $internal_counter++;
1.50 sakharuk 402: }
1.45 albertel 403: $displayoptionintex=1;
1.32 sakharuk 404: } else {
1.46 sakharuk 405: if ($Apache::response::foilgroup{$name.'.text'}=~m/\\item /) {
1.51 sakharuk 406: if ($Apache::lonhomework::type eq 'exam') {
1.68 sakharuk 407: $Apache::response::foilgroup{$name.'.text'}=~s/\\item//;
1.51 sakharuk 408: }
1.60 sakharuk 409: if ($Apache::response::foilgroup{$name.'.text'}=~/<drawoptionlist\s*\/>/) {
1.61 sakharuk 410: $Apache::response::foilgroup{$name.'.text'}=~s|<drawoptionlist\s*/>| \\makebox\[0\.3in\]\[b\]\{\\hrulefill\} |;
1.60 sakharuk 411: }
412: $result.= $Apache::response::foilgroup{$name.'.text'};
1.46 sakharuk 413: } else {
1.51 sakharuk 414: if ($Apache::lonhomework::type eq 'exam') {
1.68 sakharuk 415: $result.= ' '.$Apache::response::foilgroup{$name.'.text'};
1.51 sakharuk 416: } else {
417: $result.= '\item '.$Apache::response::foilgroup{$name.'.text'};
418: }
1.46 sakharuk 419: }
1.50 sakharuk 420: if ($Apache::lonhomework::type eq 'exam') {
1.96.2.1 albertel 421: $result.='\vskip -1 mm \noindent\begin{enumerate}\item[\textbf{'.$internal_counter.'}.]'.&bubbles(\@alphabet,\@opt).'\end{enumerate} \vskip -9 mm \strut ';
1.79 sakharuk 422: $internal_counter++;
1.50 sakharuk 423: }
1.32 sakharuk 424: }
1.62 albertel 425: }
1.1 albertel 426: }
1.62 albertel 427: }
1.32 sakharuk 428: if ($target ne 'tex') {
1.62 albertel 429: return $result.$break;
430: } else {
1.32 sakharuk 431: return $result;
1.22 albertel 432: }
1.50 sakharuk 433: }
434:
435:
436: sub optionlist_correction {
437:
438: my $texoptionlist = shift;
1.83 sakharuk 439: if ($texoptionlist=~/<option selected/ or $texoptionlist=~/<option>[^<]+<\/option>/) {
1.85 sakharuk 440: $texoptionlist =~ s/<option><\/option>/\\item \[\] Choices: /;
1.80 sakharuk 441: $texoptionlist =~ s/<option>/\{\\bf /g;
442: $texoptionlist =~ s/<option selected="on">/\{\\bf /g;
443: $texoptionlist =~ s/<\/option>/\},/g;
444: $texoptionlist =~ s/,$/\./g;
445: $texoptionlist =~ s/>/\$>\$/g;
446: $texoptionlist =~ s/</\$<\$/g;
447: $texoptionlist =~ s/=/\$=\$/g;
448: $texoptionlist =~ s/\^(\d+)/<m>\$$1\$<\/m>/g;
449: } else {
450: $texoptionlist =~ s/<option><\/option>/\\item \[\] \\vskip -5 mm/;
451: }
1.50 sakharuk 452: return $texoptionlist;
1.58 sakharuk 453: }
454:
455:
456: sub webbubbles {
457:
1.90 albertel 458: my ($ropt,$ralphabet,$temp,$lastopt)=@_;
1.58 sakharuk 459: my @opt=@$ropt;
460: my @alphabet=@$ralphabet;
461: my $result='';
1.90 albertel 462: my $number_of_bubbles = $#opt + 1;
463: $result.= '<table border="1"><tr>';
464: for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
465: my $checked='';
466: if ($lastopt eq $opt[$ind]) {
467: $checked=' checked="on" ';
1.58 sakharuk 468: }
1.90 albertel 469: $result.='<td><input type="radio" name="HWVAL_'.
470: $Apache::inputtags::response['-1'].':'.$temp.
471: '" value="'.$opt[$ind].'" '.$checked.' />'.$alphabet[$ind].': '.
472: $opt[$ind].'</td>';
473: }
474: $result.='</tr></table>';
475: return $result;
1.50 sakharuk 476: }
477:
478:
479: sub bubbles {
480:
481: my ($ralphabit,$ropt) = @_;
482: my @alphabet = @$ralphabit;
483: my @opt = @$ropt;
1.51 sakharuk 484: my ($result,$head,$line) =('','','');
1.50 sakharuk 485: my $number_of_bubbles = $#opt + 1;
1.51 sakharuk 486: my $current_length = 0;
1.96.2.1 albertel 487: my $textwidth;
488: if ($ENV{'form.textwidth'} ne '') {
489: $ENV{'form.textwidth'}=~/(\d+)/;
490: $textwidth=$1;
491: } else {
492: $ENV{'textwidth'}=~/(\d+)/;
493: $textwidth=$1;
494: }
1.51 sakharuk 495: for (my $ind=0;$ind<=$number_of_bubbles;$ind++) {
1.96.2.1 albertel 496: my $leftmargin;
1.96.2.2! albertel 497: $opt[$ind]=&Apache::lonxml::latex_special_symbols($opt[$ind]);
1.96.2.1 albertel 498: if ($ind==0) {$leftmargin=6;} else {$leftmargin=10;}
499: $current_length += (length($opt[$ind])+length($alphabet[$ind])+3)*2;
500: if ($current_length<($textwidth-$leftmargin) and $ind!=$number_of_bubbles) {
1.51 sakharuk 501: $line.='\hskip -1 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';
502: $head.='lr';
503: } else {
504: $line=~s/\&\s*$//;
1.96.2.1 albertel 505: $result.='\vskip -2 mm\noindent\begin{tabular}{'.$head.'}'.$line.'\\\\\end{tabular}';
1.51 sakharuk 506: $line = '\hskip -1 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';;
507: $head ='lr';
508: $current_length = (length($opt[$ind])+length($alphabet[$ind]))*2;
509: }
510:
1.50 sakharuk 511: }
512: return $result;
1.1 albertel 513: }
514:
1.22 albertel 515:
1.2 albertel 516: sub start_conceptgroup {
1.22 albertel 517: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
518: $Apache::optionresponse::conceptgroup=1;
1.44 albertel 519: %Apache::response::conceptgroup=();
1.22 albertel 520: my $result;
521: if ($target eq 'edit') {
522: $result.=&Apache::edit::tag_start($target,$token,"Concept Grouped Foils");
1.30 matthew 523: $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
524: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.22 albertel 525: }
526: if ($target eq 'modified') {
527: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'concept');
528: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
529: }
530: return $result;
1.2 albertel 531: }
532:
533: sub end_conceptgroup {
1.22 albertel 534: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
535: $Apache::optionresponse::conceptgroup=0;
536: my $result='';
1.93 albertel 537: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
538: $target eq 'tex' || $target eq 'analyze') {
1.22 albertel 539: #if not there aren't any foils to display and thus no question
1.93 albertel 540: &Apache::response::pick_foil_for_concept($target,
541: ['value','text','location'],
542: \%Apache::hint::option,
543: $parstack,$safeeval);
1.34 albertel 544: } elsif ($target eq 'edit') {
1.22 albertel 545: $result=&Apache::edit::end_table();
546: }
547: return $result;
1.2 albertel 548: }
549:
1.16 albertel 550: sub insert_conceptgroup {
1.22 albertel 551: my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
552: return $result;
1.16 albertel 553: }
554:
1.1 albertel 555: sub start_foil {
1.22 albertel 556: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
557: my $result='';
1.34 albertel 558: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze' ) {
1.25 albertel 559: &Apache::lonxml::startredirection;
560: } elsif ($target eq 'edit') {
1.22 albertel 561: $result=&Apache::edit::tag_start($target,$token,"Foil");
562: my $level='-2';
563: if ($$tagstack['-2'] eq 'conceptgroup') { $level = '-3'; }
564: my @opt;
565: eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval,$level);
566: $result.=&Apache::edit::text_arg('Name:','name',$token);
1.48 albertel 567: $result.= &Apache::edit::select_or_text_arg('Correct Option:','value',
568: ['unused',(@opt)],$token,'15');
569: my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
570: $safeeval,'-3');
571: if ($randomize ne 'no') {
572: $result.=&Apache::edit::select_arg('Location:','location',
573: ['random','top','bottom'],$token);
574: }
1.30 matthew 575: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.25 albertel 576: } elsif ($target eq 'modified') {
1.48 albertel 577: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
578: 'value','name','location');
1.22 albertel 579: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.32 sakharuk 580: }
1.22 albertel 581: return $result;
1.1 albertel 582: }
583:
584: sub end_foil {
1.22 albertel 585: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
586: my $text ='';
587: my $result = '';
1.88 albertel 588: if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
1.48 albertel 589: $text=&Apache::lonxml::endredirection;
1.68 sakharuk 590: if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') { $text = '\vspace*{-2 mm}\item '.$text; }
1.32 sakharuk 591: }
592: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'
1.34 albertel 593: || $target eq 'tex' || $target eq 'analyze') {
1.22 albertel 594: my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
595: if ($value ne 'unused') {
596: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
1.48 albertel 597: my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);
1.22 albertel 598: &Apache::lonxml::debug("Got a name of :$name:");
599: if (!$name) { $name=$Apache::lonxml::curdepth; }
600: &Apache::lonxml::debug("Using a name of :$name:");
1.39 albertel 601: if ( $Apache::optionresponse::conceptgroup
602: && !&Apache::response::showallfoils() ) {
1.22 albertel 603: push @{ $Apache::response::conceptgroup{'names'} }, $name;
604: $Apache::response::conceptgroup{"$name.value"} = $value;
1.70 albertel 605: if ($target eq 'tex' and $Apache::lonhomework::type eq 'exam') {
1.69 sakharuk 606: $Apache::response::conceptgroup{"$name.text"} = '\vskip 4 mm $\triangleright$ '.$text;
607: } else {
1.87 sakharuk 608: $Apache::response::conceptgroup{"$name.text"} = $text;
1.69 sakharuk 609: }
1.48 albertel 610: $Apache::response::conceptgroup{"$name.location"} = $location;
1.22 albertel 611: } else {
612: push @{ $Apache::response::foilgroup{'names'} }, $name;
1.48 albertel 613: $Apache::response::foilgroup{"$name.value"} = $value;
1.78 sakharuk 614: if ($target eq 'tex' and $Apache::lonhomework::type eq 'exam') {
1.69 sakharuk 615: $Apache::response::foilgroup{"$name.text"} = '\vskip 5 mm $\triangleright$ '.$text;
616: } else {
1.87 sakharuk 617: $Apache::response::foilgroup{"$name.text"} = $text;
1.69 sakharuk 618: }
1.48 albertel 619: $Apache::response::foilgroup{"$name.location"} = $location;
1.22 albertel 620: }
621: }
622: }
623: if ($target eq 'edit') {
624: $result.= &Apache::edit::tag_end($target,$token,'');
625: }
626: return $result;
1.1 albertel 627: }
628:
1.7 albertel 629: sub insert_foil {
1.22 albertel 630: return '
1.15 albertel 631: <foil name="" value="unused">
1.14 albertel 632: <startouttext />
633: <endouttext />
1.7 albertel 634: </foil>';
635: }
1.1 albertel 636: 1;
637: __END__
638:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>