--- loncom/homework/optionresponse.pm 2001/08/06 19:00:13 1.21 +++ loncom/homework/optionresponse.pm 2018/02/28 13:20:50 1.201 @@ -1,361 +1,1140 @@ -# The LON-CAPA option response handler +# LearningOnline Network with CAPA +# option list style responses # -# Option list style responses +# $Id: optionresponse.pm,v 1.201 2018/02/28 13:20:50 raeburn Exp $ # -# YEAR=2001 -# 1/19,2/7,2/19,2/21,2/22,3/1,5/4,5/21,5/31,6/1,6/2,6/5,6/11 Guy Albertelli -# 6/12,6/16,6/26,6/27,7/18 Guy Albertelli -# 8/6 Scott Harrison +# 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::response(); +use Apache::lonlocal; +use Apache::lonnet; -# ======================================================================= BEGIN -sub BEGIN { +BEGIN { &Apache::lonxml::register('Apache::optionresponse',('optionresponse')); } -# ================================ Start option response (return scalar string) sub start_optionresponse { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; - my $result = ''; - #when in a radiobutton response use these - &Apache::lonxml::register('Apache::optionresponse',('foilgroup','foil', - 'conceptgroup')); - push (@Apache::lonxml::namespace,'optionresponse'); - my $id = &Apache::response::start_response($parstack,$safeeval); - if ($target eq 'edit') { - $result .= &Apache::edit::start_table($token). - "Multiple Option Response QuestionDelete:". - &Apache::edit::deletelist($target,$token). - " \n"; - $result .= &Apache::edit::text_arg('Max Number Of Foils:','max', - $token,'4').""; - $result .= "\n"; - } - if ($target eq 'modified') { - my $constructtag = &Apache::edit::get_new_args($token,$parstack, - $safeeval,'max'); - if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } - } - return $result; + 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); + %Apache::hint::option=(); + undef(%Apache::response::foilnames); + if ($target eq 'edit') { + $result.=&Apache::edit::start_table($token) + .''.&Apache::loncommon::insert_folding_button().' ' + .&mt('Multiple Option Response Question').' ' + .&Apache::loncommon::help_open_topic('Option_Response_Problems')."" + .''.&mt('Delete?').' ' + .&Apache::edit::deletelist($target,$token) + .'' + ." " + .&Apache::edit::end_row() + .&Apache::edit::start_spanning_row() + ."\n"; + $result.=&Apache::edit::text_arg('Max Number Of Shown Foils:','max', + $token,'4'). + &Apache::edit::select_arg('Randomize Foil Order:','randomize', + ['yes','no'],$token). + &Apache::edit::select_arg('Display of options when printed','TeXlayout', + [['horizontal','Normal list'], + ['vertical','Listed in a vertical column']],$token). + &Apache::edit::end_row().&Apache::edit::start_spanning_row(); + } elsif ($target eq 'modified') { + my $constructtag=&Apache::edit::get_new_args($token,$parstack, + $safeeval,'max','randomize', + 'TeXlayout'); + if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } + } elsif ($target eq 'meta') { + $result=&Apache::response::meta_package_write('optionresponse'); + } elsif ($target eq 'analyze') { + my $part_id="$Apache::inputtags::part.$id"; + $Apache::lonhomework::analyze{"$part_id.type"} = 'optionresponse'; + push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id); + push (@{ $Apache::lonhomework::analyze{"$part_id.bubble_lines"} }, 1); + + } + return $result; } -# ================================== End option response (return scalar string) sub end_optionresponse { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; - &Apache::response::end_response; - pop @Apache::lonxml::namespace; - my $result; - if ($target eq 'edit') { $result = &Apache::edit::end_table(); } - return $result; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + &Apache::response::end_response; + pop @Apache::lonxml::namespace; + &Apache::lonxml::deregister('Apache::optionresponse',('foilgroup','foil','conceptgroup','drawoptionlist')); + my $result; + if ($target eq 'edit') { $result=&Apache::edit::end_table(); } + undef(%Apache::response::foilnames); + return $result; } -# ===================================== Start foil group (return scalar string) -%Apache::response::foilgroup = {}; +%Apache::response::foilgroup=(); sub start_foilgroup { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; - my $result = ''; - %Apache::response::foilgroup = {}; - $Apache::optionresponse::conceptgroup = 0; - &Apache::response::setrandomnumber(); - if ($target eq 'edit') { - my $optionlist = "\n"; - my $option; - my @opt; - eval '@opt ='. - &Apache::lonxml::get_param('options',$parstack,$safeeval); - my $count = 1; - foreach $option (@opt) { - $optionlist .= "\n"; - $count++; - } - my $insertlist = &Apache::edit::insertlist($target,$token); - $result .= &Apache::edit::start_table($token); - $result .= (<Select Options + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + + my $result=''; + %Apache::response::foilgroup=(); + $Apache::optionresponse::conceptgroup=0; + &Apache::response::pushrandomnumber(undef,$target); + if ($target eq 'edit') { + my $optionlist="\n"; + my $option; + my @opt; + my @raw_options = &Apache::lonxml::get_param('options', $parstack, $safeeval, 0, 0, 1); + + + eval '@opt ='. &Apache::lonxml::get_param('options',$parstack,$safeeval, 0, 0, 1); + + my $count=1; + foreach $option (@opt) { + $optionlist.="\n"; + $count++; + } + my $insertlist=&Apache::edit::insertlist($target,$token); + $result.=&Apache::edit::start_table($token); + my %lt = &Apache::lonlocal::texthash( + sel => 'Select Options', + add => 'Add new Option:', + del => 'Delete an Option:', + maxcheck => 'Enter maximum number students may check (e.g., 3)', + mincheck => 'Enter minimum number students need to check (e.g., 1)', + ); + $result.= sprintf(<%s $lt{'sel'} - Add new Option: + $lt{'add'} - Delete an Option: + $lt{'del'} - - $insertlist
ENDTABLE + $result.= ''.&Apache::edit::checked_arg('Print options:','texoptions', + [ ['nochoice',"Don't show option list"] ] + ,$token).''; + $result.= '