Annotation of loncom/homework/rankresponse.pm, revision 1.73

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # rank style response
                      3: #
1.73    ! damieng     4: # $Id: rankresponse.pm,v 1.72 2015/01/19 15:35:53 goltermann 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>&nbsp;'.&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>&nbsp;</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') {
1.73    ! damieng   365: 		$result.='<div class="LC_rankfoil"><b>'.$value.':</b> '.$text.'</div>';
1.46      albertel  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.73    ! damieng   447:                 $result .= '<div class="LC_rankfoil">';
1.12      sakharuk  448: 		if ($Apache::lonhomework::type ne 'exam') {
1.73    ! damieng   449: 		    $result.=$optionlist.$text."\n";
1.12      sakharuk  450: 		} else {
1.73    ! damieng   451: 		    $result.=$text."\n";
1.12      sakharuk  452: 		}
1.4       sakharuk  453: 		if ($Apache::lonhomework::type eq 'exam') {
1.22      albertel  454: 		    my @values=(1..scalar(@whichopt));
                    455: 		    $result.=&Apache::optionresponse::webbubbles(\@values,\@whichopt,$temp,$lastopt);
1.4       sakharuk  456: 		}
1.73    ! damieng   457:                 $result .= '</div>';
1.4       sakharuk  458: 	    } else {
                    459: 		if ($Apache::lonhomework::type eq 'exam') {
1.66      raeburn   460:                     my $itemlabel;
                    461:                     if ($numrows == 1) {
                    462:                         $itemlabel = '\item[\textbf{'.$internal_counter.'}]';
                    463:                     } else {
                    464:                         my $linetext;
                    465:                         for (my $i=0; $i<$numrows; $i++) {
                    466:                             $linetext .= $internal_counter+$i.', ';
                    467:                         }
                    468:                         $linetext =~ s/,\s$//;
                    469:                         $itemlabel = '\item[\small {\textbf{'.$linetext.'}}]'.
                    470:                                      ' {\footnotesize '.
                    471:                                      &mt('(Bubble once in [_1] lines)',$numrows).
                    472:                                      '} \hspace*{\fill} \\\\';
                    473:                     }
1.63      foxr      474: 		    $result .= '\vskip 0 mm '.$text.' \vskip 0 mm '."\n";
                    475: 		    $result .= '\vskip -1 mm';
1.66      raeburn   476:                     $result .= '\begin{enumerate}'.$itemlabel;
                    477: 		    $result .= &Apache::optionresponse::bubbles(\@alp,\@whichopt,'rankresponse',undef,$numrows,$bubbles_per_row,$internal_counter);
                    478:                     $result .= '\end{enumerate} \vskip -8 mm \strut ';
                    479: 		    $internal_counter += $numrows;
1.4       sakharuk  480: 		} else {
1.58      onken     481:                     if($env{'form.pdfFormFields'} ne 'yes') {
                    482: 		        $result.=' \vskip 0mm \framebox[5 mm][s]{\tiny\strut} '.$text."\n";
                    483:                     } else {
                    484:                         $result.= $optionlist.' '. &Apache::lonxml::print_pdf_end_combobox($text).'\strut \\\\';
                    485:                     }
1.4       sakharuk  486: 		}
                    487: 	    }
1.1       albertel  488: 	    $temp++;
                    489: 	}
                    490:     }
1.52      albertel  491:     if ($target eq 'web') {
1.64      raeburn   492:         my $questiontype;
                    493:         if ($Apache::lonhomework::type eq 'randomizetry') {
                    494:             $questiontype = $Apache::lonhomework::type;
                    495:         }
1.52      albertel  496: 	&Apache::response::setup_prior_tries_hash(\&format_prior_answer,
                    497: 						  [\@whichfoils,
1.64      raeburn   498: 						   'submissiongrading'],
                    499:                                                   $questiontype);
1.52      albertel  500:     }
1.5       sakharuk  501:     if ($target ne 'tex') {$result.="<br />";} else {$result.=' \vskip 0 mm ';}
1.1       albertel  502:     return $result;
                    503: }
                    504: 
                    505: sub getfoilcounts {
                    506:     my ($max)=@_;
                    507:     # +1 since instructors will count from 1
                    508:     my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
                    509:     if (&Apache::response::showallfoils()) { $max=$count; }
                    510:     if ($count>$max) { $count=$max } 
                    511:     &Apache::lonxml::debug("Count is $count from $max");
                    512:     return $count;
                    513: }
                    514: 
                    515: sub whichfoils {
                    516:     my ($max,$randomize)=@_;
1.13      albertel  517:     return &Apache::response::whichorder($max,$randomize,
                    518: 					 &Apache::response::showallfoils(),
                    519: 					 \%Apache::response::foilgroup);
1.1       albertel  520: }
                    521: 
                    522: sub start_conceptgroup {
                    523:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    524:     $Apache::rankresponse::conceptgroup=1;
                    525:     %Apache::response::conceptgroup=();
                    526:     my $result;
                    527:     if ($target eq 'edit') {
                    528: 	$result.=&Apache::edit::tag_start($target,$token,
                    529: 					  "Concept Grouped Foils");
                    530: 	$result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
                    531: 	    &Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    532:     }
                    533:     if ($target eq 'modified') {
                    534: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    535: 						     $safeeval,'concept');
                    536: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    537:     }
                    538:     return $result;
                    539: }
                    540: 
                    541: sub end_conceptgroup {
                    542:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    543:     $Apache::rankresponse::conceptgroup=0;
                    544:     my $result='';
1.25      albertel  545:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    546: 	$target eq 'tex' || $target eq 'analyze') {
1.1       albertel  547: 	#if not there aren't any foils to display and thus no question
1.25      albertel  548: 	&Apache::response::pick_foil_for_concept($target,
                    549: 						 ['value','text','location'],
                    550: 						 \%Apache::hint::rank,
                    551: 						 $parstack,$safeeval);
1.1       albertel  552:     } elsif ($target eq 'edit') {
                    553: 	$result=&Apache::edit::end_table();
                    554:     }
                    555:     return $result;
                    556: }
                    557: 
                    558: sub insert_conceptgroup {
                    559:     my $result="\n\t\t<conceptgroup concept=\"\">".&insert_foil()."\n\t\t</conceptgroup>\n";
                    560:     return $result;
                    561: }
                    562: 
                    563: sub start_foil {
                    564:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    565:     my $result='';
1.25      albertel  566:     if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
1.1       albertel  567: 	&Apache::lonxml::startredirection;
1.39      albertel  568: 	if ($target eq 'analyze') {
                    569: 	    &Apache::response::check_if_computed($token,$parstack,$safeeval,'value');
                    570: 	}
1.1       albertel  571:     } elsif ($target eq 'edit') {
                    572: 	$result=&Apache::edit::tag_start($target,$token,"Foil");
                    573: 	my $level='-2';
                    574: 	if ($$tagstack[-2] eq 'conceptgroup') { $level = '-3'; }
                    575: 	$result.=&Apache::edit::text_arg('Name:','name',$token);
                    576: 	$result.= &Apache::edit::text_arg('Rank Value:','value',$token,'15');
                    577: 	my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
                    578: 						 $safeeval,'-3');
                    579: 	if ($randomize ne 'no') {
                    580: 	    $result.=&Apache::edit::select_arg('Location:','location',
                    581: 					     ['random','top','bottom'],$token);
                    582: 	}
                    583: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    584:     } elsif ($target eq 'modified') {
                    585: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    586: 						     $safeeval,'value',
                    587: 						     'name','location');
                    588: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    589:     }
                    590:     return $result;
                    591: }
                    592: 
                    593: sub end_foil {
                    594:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    595:     my $text ='';
                    596:     my $result = '';
1.25      albertel  597:     if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
1.1       albertel  598: 	$text=&Apache::lonxml::endredirection;
                    599:     }
1.25      albertel  600:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    601: 	$target eq 'tex' || $target eq 'analyze') {
1.1       albertel  602: 	my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
1.42      albertel  603: 	if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
                    604: 	    $text='\vskip 5mm $\triangleright$ '.$text;
                    605: 	}
1.1       albertel  606: 	if ($value ne 'unused') {
                    607: 	    my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
                    608: 	    &Apache::lonxml::debug("Got a name of :$name:");
1.48      albertel  609: 	    if ($name eq "") {
1.57      bisitz    610: 		&Apache::lonxml::warning(&mt('Foils without names exist. This can cause problems to malfunction.'));
1.43      albertel  611: 		$name=$Apache::lonxml::curdepth;
                    612: 	    }
1.1       albertel  613: 	    &Apache::lonxml::debug("Using a name of :$name:");
1.30      albertel  614: 	    if (defined($Apache::response::foilnames{$name})) {
1.57      bisitz    615: 		&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  616: 	    }
1.31      albertel  617: 	    $Apache::response::foilnames{$name}++;
1.30      albertel  618: 	    my $location =&Apache::lonxml::get_param('location',$parstack,
                    619: 						     $safeeval);
1.1       albertel  620: 	    if ( $Apache::rankresponse::conceptgroup
                    621: 		 && !&Apache::response::showallfoils() ) {
                    622: 		push @{ $Apache::response::conceptgroup{'names'} }, $name;
                    623: 		$Apache::response::conceptgroup{"$name.value"} = $value;
1.42      albertel  624: 		$Apache::response::conceptgroup{"$name.text"} = $text;
1.1       albertel  625: 		$Apache::response::conceptgroup{"$name.location"} = $location;
                    626: 	    } else {
                    627: 		push @{ $Apache::response::foilgroup{'names'} }, $name;
                    628: 		$Apache::response::foilgroup{"$name.value"} = $value;
1.42      albertel  629: 		$Apache::response::foilgroup{"$name.text"} = $text;
1.1       albertel  630: 		$Apache::response::foilgroup{"$name.location"} = $location;
                    631: 	    }
                    632: 	}
                    633:     }
                    634:     if ($target eq 'edit') {
                    635: 	$result.= &Apache::edit::tag_end($target,$token,'');
                    636:     }
                    637:     return $result;
                    638: }
                    639: 
                    640: sub insert_foil {
                    641:     return '
                    642: <foil name="" value="unused">
                    643: <startouttext />
                    644: <endouttext />
                    645: </foil>';
                    646: }
                    647: 1;
                    648: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>