version 1.86, 2011/12/15 01:21:28
|
version 1.97, 2025/02/21 20:55:17
|
Line 34 use Apache::optionresponse();
|
Line 34 use Apache::optionresponse();
|
use Apache::lonlocal; |
use Apache::lonlocal; |
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::lonxml; |
use Apache::lonxml; |
|
use POSIX qw(ceil); |
|
|
BEGIN { |
BEGIN { |
&Apache::lonxml::register('Apache::matchresponse',('matchresponse')); |
&Apache::lonxml::register('Apache::matchresponse',('matchresponse')); |
Line 54 sub start_matchresponse {
|
Line 55 sub start_matchresponse {
|
$result=&Apache::response::meta_package_write('matchresponse'); |
$result=&Apache::response::meta_package_write('matchresponse'); |
} elsif ($target eq 'edit' ) { |
} elsif ($target eq 'edit' ) { |
$result.=&Apache::edit::start_table($token). |
$result.=&Apache::edit::start_table($token). |
'<tr><td>'.&Apache::lonxml::description($token).'</td>' |
'<tr><td>'.&Apache::loncommon::insert_folding_button().&Apache::lonxml::description($token).'</td>' |
.'<td><span class="LC_nobreak">'.&mt('Delete?').' ' |
.'<td><span class="LC_nobreak">'.&mt('Delete?').' ' |
.&Apache::edit::deletelist($target,$token) |
.&Apache::edit::deletelist($target,$token) |
.'</span></td>' |
.'</span></td>' |
Line 103 sub start_itemgroup {
|
Line 104 sub start_itemgroup {
|
if ($target eq 'edit') { |
if ($target eq 'edit') { |
$result=&Apache::edit::tag_start($target,$token); |
$result=&Apache::edit::tag_start($target,$token); |
$result.=&Apache::edit::select_arg('Randomize Order:','randomize', |
$result.=&Apache::edit::select_arg('Randomize Order:','randomize', |
['yes','no'],$token).' 'x 3; |
['yes','no'],$token); |
$result.=&Apache::edit::select_arg('Items Display Location:', |
$result.=&Apache::edit::select_arg('Items Display Location:', |
'location', |
'location', |
['top','bottom','left','right'], |
['top','bottom','left','right'], |
$token).' 'x 3; |
$token); |
$result.=&Apache::edit::select_arg('Items Display Direction:', |
$result.=&Apache::edit::select_arg('Items Display Direction:', |
'direction', |
'direction', |
['vertical','horizontal'], |
['vertical','horizontal'], |
$token); |
$token); |
|
$result.=&Apache::edit::select_arg('Items Columns:', |
|
'columns', |
|
[['','default'],'1','2','3','4'], |
|
$token); |
$result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); |
$result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
my $constructtag=&Apache::edit::get_new_args($token,$parstack, |
my $constructtag=&Apache::edit::get_new_args($token,$parstack, |
$safeeval,'randomize', |
$safeeval,'randomize', |
'location','direction'); |
'location','direction', |
|
'columns'); |
if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } |
if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } |
} elsif ($target eq 'web' or $target eq 'tex') { |
} elsif ($target eq 'web' or $target eq 'tex') { |
$Apache::matchresponse::itemtable{'location'}= |
$Apache::matchresponse::itemtable{'location'}= |
Line 158 sub end_itemgroup {
|
Line 164 sub end_itemgroup {
|
$Apache::response::itemgroup{'letter_name_map'}=\%letter_name_map; |
$Apache::response::itemgroup{'letter_name_map'}=\%letter_name_map; |
$Apache::response::itemgroup{'name_letter_map'}=\%name_letter_map; |
$Apache::response::itemgroup{'name_letter_map'}=\%name_letter_map; |
my $direction=&Apache::lonxml::get_param('direction',$parstack,$safeeval); |
my $direction=&Apache::lonxml::get_param('direction',$parstack,$safeeval); |
|
my $columns=&Apache::lonxml::get_param('columns',$parstack,$safeeval); |
|
|
|
unless ($columns =~ /^\d+$/) { |
|
undef($columns); |
|
} |
if ($target eq 'web') { |
if ($target eq 'web') { |
|
my $table='<table class="LC_itemgroup">'; # extra space to match what latex does. |
my $table='<br /><table>'; # extra space to match what latex does. |
if ((!$columns) || ($columns < 0)) { |
my $i=0; |
if ($direction eq 'horizontal') { |
if ($direction eq 'horizontal') { $table .='<tr>';} |
if (@names > 0) { |
foreach my $name (@names) { |
$columns = scalar(@names); |
if ($direction ne 'horizontal') { $table.='<tr>'; } |
} else { |
$table.='<td>'.$alphabet[$i].'</td><td>'. |
$columns = 1; |
$Apache::response::itemgroup{$name.'.text'}.'</td>'; |
} |
if ($direction ne 'horizontal') { $table.='</tr>'; } |
} else { |
$i++; |
$columns = 1; |
} |
} |
if ($direction eq 'horizontal') { $table .='</tr>';} |
} |
|
my $rows=ceil(scalar(@names)/$columns); |
|
my $endloop = $columns*$rows; |
|
for (my $i=0; $i<$endloop; $i++) { |
|
my $label = ' '; |
|
my $item = ' '; |
|
my $index; |
|
if ($direction eq 'horizontal') { |
|
$index = $i; |
|
} else { |
|
$index = ($i % $columns)*$rows+int($i/$columns); |
|
} |
|
if ($index < scalar(@names)) { |
|
$label = $alphabet[$index]; |
|
$item = $Apache::response::itemgroup{$names[$index].'.text'}; |
|
} |
|
if ($i % $columns == 0) { |
|
$table.='<tr>'; |
|
} |
|
$table.= '<th>'.$label.'</th><td>'.$item.'</td>'; |
|
if ($columns > 1) { |
|
$table .= '<td> </td>'; |
|
} |
|
if ( ! (($i+1) % $columns) ) { |
|
$table.='</tr>'; |
|
} |
|
} |
$table.='</table>'; |
$table.='</table>'; |
$Apache::matchresponse::itemtable{'display'}=$table; |
$Apache::matchresponse::itemtable{'display'}=$table; |
$Apache::lonxml::post_evaluate=0; |
$Apache::lonxml::post_evaluate=0; |
Line 224 sub start_item {
|
Line 261 sub start_item {
|
$result=&Apache::edit::tag_start($target,$token,"Item"); |
$result=&Apache::edit::tag_start($target,$token,"Item"); |
$result.=&Apache::edit::text_arg('Name:','name',$token); |
$result.=&Apache::edit::text_arg('Name:','name',$token); |
if ($randomize ne 'no') { |
if ($randomize ne 'no') { |
$result.=' 'x 3 . |
$result.= |
&Apache::edit::select_arg('Location:','location', |
&Apache::edit::select_arg('Location:','location', |
['random','top','bottom'], |
['random','top','bottom'], |
$token); |
$token); |
Line 281 sub start_foilgroup {
|
Line 318 sub start_foilgroup {
|
&Apache::response::pushrandomnumber(undef,$target); |
&Apache::response::pushrandomnumber(undef,$target); |
if ($target eq 'edit') { |
if ($target eq 'edit') { |
$result.=&Apache::edit::start_table($token) |
$result.=&Apache::edit::start_table($token) |
.'<tr><td>'.&mt('Collection Of Foils').'</td>' |
.'<tr><td>'.&Apache::loncommon::insert_folding_button() |
|
.&mt('Collection Of Foils').'</td>' |
.'<td><span class="LC_nobreak">'.&mt('Delete?') |
.'<td><span class="LC_nobreak">'.&mt('Delete?') |
.&Apache::edit::deletelist($target,$token) |
.&Apache::edit::deletelist($target,$token) |
.'</span></td>' |
.'</span></td>' |
Line 542 sub format_prior_answer {
|
Line 580 sub format_prior_answer {
|
my $output; |
my $output; |
|
|
foreach my $name (@{ $foil_order }) { |
foreach my $name (@{ $foil_order }) { |
my $item=shift(@items); |
my $item = &HTML::Entities::encode(shift(@items),'<>&"'); |
|
if ($item eq '') { |
|
$item = ' '; |
|
} |
$output .= '<tr><td>'.$item.'</td></tr>'; |
$output .= '<tr><td>'.$item.'</td></tr>'; |
} |
} |
return if (!defined($output)); |
return if (!defined($output)); |
Line 614 sub displayfoils {
|
Line 655 sub displayfoils {
|
$newvariation = 1; |
$newvariation = 1; |
} |
} |
} |
} |
unless ((($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') || ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred') && (defined($env{'form.grade_symb'}))) || $newvariation) { |
unless ($newvariation) { |
$lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"}; |
if ((($env{'form.grade_username'} eq '') && ($env{'form.grade_domain'} eq '')) || |
|
(($env{'form.grade_username'} eq $env{'user.name'}) && |
|
($env{'form.grade_domain'} eq $env{'user.domain'}))) { |
|
$lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"}; |
|
} else { |
|
unless (($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') || |
|
($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) { |
|
$lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"}; |
|
} |
|
} |
} |
} |
|
|
my %lastresponse=&Apache::lonnet::str2hash($lastresponse); |
my %lastresponse=&Apache::lonnet::str2hash($lastresponse); |
my @alphabet=('A'..'Z'); |
my @alphabet=('A'..'Z'); |
my @used_letters=sort(keys(%letter_name_map)); |
my @used_letters=sort(keys(%letter_name_map)); |
Line 633 sub displayfoils {
|
Line 684 sub displayfoils {
|
my $last_letter=$name_letter_map{$lastopt}; |
my $last_letter=$name_letter_map{$lastopt}; |
my $optionlist = ''; |
my $optionlist = ''; |
if ($target ne 'tex') { |
if ($target ne 'tex') { |
$optionlist="<option></option>\n"; |
$optionlist="<option value=\"\"></option>\n"; |
} else { |
} else { |
if ($Apache::lonhomework::type ne 'exam') { |
if ($Apache::lonhomework::type ne 'exam') { |
if($env{'form.pdfFormFields'} eq 'yes' |
if($env{'form.pdfFormFields'} eq 'yes' |
Line 650 sub displayfoils {
|
Line 701 sub displayfoils {
|
foreach $option (@used_letters) { |
foreach $option (@used_letters) { |
if ($option eq $last_letter) { |
if ($option eq $last_letter) { |
if ($target ne 'tex') { |
if ($target ne 'tex') { |
$optionlist.="<option selected=\"selected\">$option</option>\n"; |
$optionlist.="<option value=\"$option\" selected=\"selected\">$option</option>\n"; |
} elsif ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes' |
} elsif ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes' |
&& $Apache::inputtags::status['-1'] eq 'CAN_ANSWER' |
&& $Apache::inputtags::status['-1'] eq 'CAN_ANSWER' |
&& $Apache::lonhomework::type ne 'exam') { |
&& $Apache::lonhomework::type ne 'exam') { |
Line 658 sub displayfoils {
|
Line 709 sub displayfoils {
|
} |
} |
} else { |
} else { |
if ($target ne 'tex') { |
if ($target ne 'tex') { |
$optionlist.="<option>$option</option>\n"; |
$optionlist.="<option value=\"$option\">$option</option>\n"; |
} elsif ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes' |
} elsif ($target eq 'tex' && $env{'form.pdfFormFields'} eq 'yes' |
&& $Apache::inputtags::status['-1'] eq 'CAN_ANSWER' |
&& $Apache::inputtags::status['-1'] eq 'CAN_ANSWER' |
&& $Apache::lonhomework::type ne 'exam') { |
&& $Apache::lonhomework::type ne 'exam') { |
Line 667 sub displayfoils {
|
Line 718 sub displayfoils {
|
} |
} |
} |
} |
if ($target ne 'tex' && $Apache::lonhomework::type ne 'exam') { |
if ($target ne 'tex' && $Apache::lonhomework::type ne 'exam') { |
$optionlist='<select onchange="javascript:setSubmittedPart(\''. |
$optionlist='<label><select onchange="javascript:setSubmittedPart(\''. |
$part.'\');" name="HWVAL_'. |
$part.'\');" name="HWVAL_'. |
$Apache::inputtags::response[-1].':'.$temp.'">'. |
$Apache::inputtags::response[-1].':'.$temp.'">'. |
$optionlist."</select>\n"; |
$optionlist."</select>\n"; |
Line 694 sub displayfoils {
|
Line 745 sub displayfoils {
|
} |
} |
if ($target ne 'tex') { |
if ($target ne 'tex') { |
if ($Apache::lonhomework::type ne 'exam') { |
if ($Apache::lonhomework::type ne 'exam') { |
$question.="<br />\n".$optionlist.$text; |
$question.='<div class="LC_matchfoil">'."\n".$optionlist.$text.'</label></div>'; |
} else { |
} else { |
$question.="<br />\n".$text; |
$question.="<br />\n".$text; |
} |
} |
Line 702 sub displayfoils {
|
Line 753 sub displayfoils {
|
my @blank; |
my @blank; |
$question.=&Apache::optionresponse::webbubbles(\@used_letters,\@blank,$temp,$last_letter); |
$question.=&Apache::optionresponse::webbubbles(\@used_letters,\@blank,$temp,$last_letter); |
} |
} |
} else { |
} else { |
# Note that if left or right positioned, we must |
# Note that if left or right positioned, we must |
# confine the bubbles to righttabsize: |
# confine the bubbles to righttabsize: |
# |
# |