Diff for /loncom/homework/matchresponse.pm between versions 1.86 and 1.87

version 1.86, 2011/12/15 01:21:28 version 1.87, 2012/12/29 01:21:10
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 111  sub start_itemgroup { Line 112  sub start_itemgroup {
  $result.=&Apache::edit::select_arg('Items Display Direction:',   $result.=&Apache::edit::select_arg('Items Display Direction:',
    'direction',     'direction',
    ['vertical','horizontal'],     ['vertical','horizontal'],
    $token);     $token).' 'x 3;
           $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='<br /><table>'; # extra space to match what latex does.   my $table='<br /><table>'; # extra space to match what latex does.
  my $i=0;          if ((!$columns) || ($columns < 0)) {
  if ($direction eq 'horizontal') { $table .='<tr>';}              if ($direction eq 'horizontal') {
  foreach my $name (@names) {                  if (@names > 0) { 
     if ($direction ne 'horizontal') { $table.='<tr>'; }                      $columns = scalar(@names);
     $table.='<td>'.$alphabet[$i].'</td><td>'.                  } else {
  $Apache::response::itemgroup{$name.'.text'}.'</td>';                      $columns = 1;
     if ($direction ne 'horizontal') { $table.='</tr>'; }                  }
     $i++;              } else {
  }                  $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 = '&nbsp;';
               my $item = '&nbsp;';
               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.= '<td>'.$label.'</td><td>'.$item.'</td>';
               if ($columns > 1) {
                   $table .= '<td>&nbsp;</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;

Removed from v.1.86  
changed lines
  Added in v.1.87


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