--- loncom/homework/optionresponse.pm 2001/02/07 00:28:33 1.2
+++ loncom/homework/optionresponse.pm 2015/04/21 12:28:05 1.199
@@ -1,178 +1,1195 @@
-# The LearningOnline Network with CAPA
+# LearningOnline Network with CAPA
# option list style responses
+#
+# $Id: optionresponse.pm,v 1.199 2015/04/21 12:28:05 raeburn Exp $
+#
+# Copyright Michigan State University Board of Trustees
+#
+# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
+#
+# LON-CAPA is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# LON-CAPA is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with LON-CAPA; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# /home/httpd/html/adm/gpl.txt
+#
+# http://www.lon-capa.org/
+#
+
+
+
+
package Apache::optionresponse;
use strict;
+use Apache::response();
+use Apache::lonlocal;
+use Apache::lonnet;
-sub BEGIN {
+BEGIN {
&Apache::lonxml::register('Apache::optionresponse',('optionresponse'));
}
sub start_optionresponse {
- my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
- #when in a radiobutton response use these
- &Apache::lonxml::register('Apache::optionresponse',('foilgroup','foil','conceptgroup'));
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+ my $result='';
+ #when in a option response use these
+ &Apache::lonxml::register('Apache::optionresponse',('foilgroup','foil','conceptgroup','drawoptionlist'));
+ push (@Apache::lonxml::namespace,'optionresponse');
my $id = &Apache::response::start_response($parstack,$safeeval);
- return '';
+ %Apache::hint::option=();
+ undef(%Apache::response::foilnames);
+ if ($target eq 'edit') {
+ $result.=&Apache::edit::start_table($token)
+ .'
';
+ return $result;
+}
+
+
+sub bubbles {
+ my ($ralphabet,$ropt,$response,$max_width,$numrows,$bubbles_per_row,
+ $internal_counter) = @_;
+ my @alphabet = @$ralphabet;
+ my @opt = @$ropt;
+ my ($result,$head,$line) =('','','');
+ my $number_of_bubbles = $#opt + 1;
+ my $current_length = 0;
+ my $textwidth;
+ if (defined($max_width)) {
+ $textwidth=$max_width;
+ &Apache::lonxml::debug("Max width passed in: $max_width");
+ } elsif ($env{'form.textwidth'} ne '') {
+ $env{'form.textwidth'}=~/(\d+)/;
+ $textwidth=$1;
+ &Apache::lonxml::debug("Max width from form: $textwidth");
+ } else {
+ $env{'form.textwidth'}=~/(\d*)\.?(\d*)/;
+ $textwidth=$1.'.'.$2;
+ &Apache::lonxml::debug("Max width defaults? $textwidth");
+ }
+ &Apache::lonxml::debug("Final maxwidth: $textwidth");
+ for (my $ind=0;$ind<=$number_of_bubbles;$ind++) {
+ my $item;
+ if ($numrows > 1) {
+ my $num = $internal_counter+int($ind/$bubbles_per_row);
+ my $idx = int($ind % $bubbles_per_row);
+ $item = $num.$alphabet[$idx];
+ } else {
+ $item = $alphabet[$ind];
+ }
+ my $leftmargin;
+ $opt[$ind]=&Apache::lonxml::latex_special_symbols($opt[$ind]);
+ if ($response eq 'rankresponse') {$opt[$ind]='Rank '.$opt[$ind];}
+ if ($ind==0) {$leftmargin=6;} else {$leftmargin=10;}
+
+ $current_length += (length($opt[$ind])+length($item)+5)*2;
+
+ if ($current_length<($textwidth-$leftmargin) and $ind!=$number_of_bubbles) {
+
+ $line.='\hskip 4 mm {\small \textbf{'.$item.'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';
+ $head.='lr';
+ } else {
+ $line=~s/\&\s*$//;
+ $result.='\vskip -1 mm\noindent\setlength{\tabcolsep}{2 mm}\renewcommand{\arraystretch}{1.25}\begin{tabular}{'.$head.'}'.$line.'\\\\\end{tabular}\vskip 0 mm';
+ $line = '\hskip 4 mm {\small \textbf{'.$item.'}}$\bigcirc$\hskip -1 mm & \hskip -3 mm {\small '.$opt[$ind].'} & ';
+ $head ='lr';
+ $current_length = (length($opt[$ind])+length($item))*2;
+ }
+
+ }
+ return $result;
}
sub start_conceptgroup {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+ $Apache::optionresponse::conceptgroup=1;
+ %Apache::response::conceptgroup=();
+ my $result;
+ if ($target eq 'edit') {
+ $result.=&Apache::edit::tag_start($target,$token,"Concept Grouped Foils");
+ $result.=&Apache::edit::text_arg('Concept:','concept',$token,'50').
+ &Apache::edit::end_row().&Apache::edit::start_spanning_row();
+ }
+ if ($target eq 'modified') {
+ my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'concept');
+ if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
+ }
+ return $result;
}
sub end_conceptgroup {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+ $Apache::optionresponse::conceptgroup=0;
+ my $result='';
+ if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
+ $target eq 'tex' || $target eq 'analyze') {
+ #if not there aren't any foils to display and thus no question
+ &Apache::response::pick_foil_for_concept($target,
+ ['value','text','location'],
+ \%Apache::hint::option,
+ $parstack,$safeeval);
+ } elsif ($target eq 'edit') {
+ $result=&Apache::edit::end_table();
+ }
+ return $result;
+}
+
+sub insert_conceptgroup {
+ my $result="\n\t\t".&insert_foil()."\n\t\t\n";
+ return $result;
}
sub start_foil {
- my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
- if ($target eq 'web') {
- $Apache::lonxml::redirection--;
- }
- return '';
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+ my $result='';
+ if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze' ) {
+ &Apache::lonxml::startredirection;
+ if ($target eq 'analyze') {
+ &Apache::response::check_if_computed($token,$parstack,$safeeval,'value');
+ }
+ } elsif ($target eq 'edit') {
+ $result=&Apache::edit::tag_start($target,$token,"Foil");
+ my $level='-2';
+ if ($$tagstack['-2'] eq 'conceptgroup') { $level = '-3'; }
+ my @opt;
+ eval '@opt ='.&Apache::lonxml::get_param('options',$parstack,$safeeval,$level);
+ $result.=&Apache::edit::text_arg('Name:','name',$token);
+ $result.= &Apache::edit::select_or_text_arg('Correct Option:','value',
+ ['unused',(@opt)],$token,'15');
+ my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
+ $safeeval,'-3');
+ if ($randomize ne 'no') {
+ $result.=&Apache::edit::select_arg('Location:','location',
+ ['random','top','bottom'],$token);
+ }
+ $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
+ } elsif ($target eq 'modified') {
+ my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
+ 'value','name','location');
+ if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
+ }
+ return $result;
}
sub end_foil {
- my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
- if ($target eq 'web' || $target eq 'grade') {
- my $args ='';
- if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
- my $value = &Apache::run::run("{$args;".'return $value}',$safeeval);
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+ my $text ='';
+ my $result = '';
+ if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
+ $text=&Apache::lonxml::endredirection;
+ if ($target eq 'tex') {$text=~s/\\strut\s*\\\\\s*\\strut/\\vskip 0 mm/;}
+ if (($target eq 'tex') and ($Apache::lonhomework::type ne 'exam') and ($text=~/\S/)) {$text = '\vspace*{-2 mm}\item '.$text;}
+ }
+ if ($target eq 'web' || $target eq 'grade' || $target eq 'answer'
+ || $target eq 'tex' || $target eq 'analyze') {
+ my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval);
+ if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
+ $text='\vskip 5mm $\triangleright$ '.$text;
+ }
if ($value ne 'unused') {
- my $name = &Apache::run::run("{$args;".'return $name}',$safeeval);
- push @{ $Apache::response::foilgroup{'names'} }, $name;
- $Apache::response::foilgroup{"$name.value"} = $value;
- $Apache::response::foilgroup{"$name.text"} = $Apache::lonxml::outputstack;
+ my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
+ &Apache::lonxml::debug("Got a name of :$name:");
+ if ($name eq "") {
+ &Apache::lonxml::warning(&mt('Foils without names exist. This can cause problems to malfunction.'));
+ $name=$Apache::lonxml::curdepth;
+ }
+ &Apache::lonxml::debug("Using a name of :$name:");
+ if (defined($Apache::response::foilnames{$name})) {
+ &Apache::lonxml::error(&mt("Foil name [_1] appears more than once. Foil names need to be unique.",''.$name.''));
+ }
+ $Apache::response::foilnames{$name}++;
+ my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval);
+ if ( $Apache::optionresponse::conceptgroup
+ && !&Apache::response::showallfoils() ) {
+ push @{ $Apache::response::conceptgroup{'names'} }, $name;
+ $Apache::response::conceptgroup{"$name.value"} = $value;
+ $Apache::response::conceptgroup{"$name.text"} = $text;
+ $Apache::response::conceptgroup{"$name.location"} = $location;
+ } else {
+ push @{ $Apache::response::foilgroup{'names'} }, $name;
+ $Apache::response::foilgroup{"$name.value"} = $value;
+ $Apache::response::foilgroup{"$name.text"} = $text;
+ $Apache::response::foilgroup{"$name.location"} = $location;
+ }
}
}
- if ($target eq 'web' ) {
- $Apache::lonxml::redirection++;
- if ($Apache::lonxml::redirection == 1) {
- $Apache::lonxml::outputstack='';
- }
+ if ($target eq 'edit') {
+ $result.= &Apache::edit::tag_end($target,$token,'');
}
- return '';
+ return $result;
+}
+
+sub start_drawoptionlist {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+ if ($target !~ /^(?:meta|answer|modified|edit)$/) {
+ return $token->[4];
+ }
+}
+
+sub end_drawoptionlist {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+ if ($target !~ /^(?:meta|answer|modified|edit)$/) {
+ return $token->[2];
+ }
+}
+
+sub insert_foil {
+ return '
+
+
+
+';
+}
+
+sub insert_drawoptionlist {
+ return '';
+}
+
+sub getnumrows {
+ my ($numitems) = @_;
+ my $bubbles_per_row;
+ my $default_numbubbles = 10;
+ if (($env{'form.bubbles_per_row'} =~ /^\d+$/) &&
+ ($env{'form.bubbles_per_row'} > 0)) {
+ $bubbles_per_row = $env{'form.bubbles_per_row'};
+ } else {
+ $bubbles_per_row = $default_numbubbles;
+ }
+ my $numrows = int ($numitems/$bubbles_per_row);
+ if (($numitems % $bubbles_per_row) != 0) {
+ $numrows ++;
+ }
+ return ($numrows,$bubbles_per_row);
}
1;
__END__
+=head1 NAME
+
+Apache::optionresponse.pm;
+
+=head1 SYNOPSIS
+
+Handles tags associated with showing a list of
+options.
+
+This is part of the LearningOnline Network with CAPA project
+described at http://www.lon-capa.org.
+
+=head1 HANDLER SUBROUTINE
+
+start_optionresponse()
+
+=head1 OTHER SUBROUTINES
+
+=over
+
+=item end_optionresponse()
+
+=item start_foilgroup()
+
+=item end_foilgroup()
+
+=item getfoilcounts()
+
+=item displayanswers()
+
+=item check_for_invalid()
+
+=item displayfoils()
+
+=item optionlist_correction()
+
+=item webbubbles()
+
+=item bubbles()
+
+=item start_conceptgroup()
+
+=item end_conceptgroup()
+
+=item insert_conceptgroup()
+
+=item start_foil()
+
+=item end_foil()
+
+=item start_drawoptionlist()
+
+=item end_drawoptionlist()
+
+=item insert_foil()
+
+=item insert_drawoptionlist()
+
+=back
+
+=cut
500 Internal Server Error
Internal Server Error
The server encountered an internal error or
misconfiguration and was unable to complete
your request.
Please contact the server administrator at
root@localhost to inform them of the time this error occurred,
and the actions you performed just before this error.
More information about this error may be available
in the server error log.