Diff for /loncom/interface/spreadsheet/Spreadsheet.pm between versions 1.61 and 1.72

version 1.61, 2006/01/10 16:38:47 version 1.72, 2006/09/03 00:54:05
Line 60  use HTML::TokeParser; Line 60  use HTML::TokeParser;
 use Spreadsheet::WriteExcel;  use Spreadsheet::WriteExcel;
 use Time::HiRes;  use Time::HiRes;
 use Apache::lonlocal;  use Apache::lonlocal;
   use lib '/home/httpd/lib/perl/';
   use LONCAPA;
    
   
 ##  ##
 ## Package Variables  ## Package Variables
Line 85  sub new { Line 88  sub new {
     my $class = ref($this) || $this;      my $class = ref($this) || $this;
     my ($stype) = ($class =~ /Apache::(.*)$/);      my ($stype) = ($class =~ /Apache::(.*)$/);
     #      #
     my ($name,$domain,$filename,$usymb)=@_;      my ($name,$domain,$filename,$usymb,$section,$groups)=@_;
     if (defined($usymb) && ref($usymb)) {      if (defined($usymb) && ref($usymb)) {
         $usymb = $usymb->symb;          $usymb = $usymb->symb;
     }      }
Line 95  sub new { Line 98  sub new {
     if (! defined($domain) || $domain eq '') {      if (! defined($domain) || $domain eq '') {
         $domain = $env{'user.domain'};          $domain = $env{'user.domain'};
     }      }
       if (! defined($section) || $section eq '') {
           $section = &Apache::lonnet::getsection($domain,$name,
          $env{'request.course.id'});
       }
       if (! defined($groups)) {
   
           my @usersgroups = &Apache::lonnet::get_users_groups($domain,$name,
                                                       $env{'request.course.id'});
           $groups = \@usersgroups;
       }
     #      #
     my $self = {      my $self = {
         name     => $name,          name     => $name,
         domain   => $domain,          domain   => $domain,
           section  => $section,
           groups   => $groups, 
         type     => $stype,          type     => $stype,
         symb     => $usymb,          symb     => $usymb,
         errorlog => '',          errorlog => '',
Line 157  sub filename { Line 172  sub filename {
                 $newfilename = 'default_'.$self->{'type'};                  $newfilename = 'default_'.$self->{'type'};
             }              }
         }          }
         if ($newfilename !~ /\w/ || $newfilename =~ /^\W*$/) {   if ($newfilename eq &mt('LON-CAPA Standard')) {
             $newfilename = 'default_'.$self->{'type'};      undef($newfilename);
         }   } else {
         if ($newfilename !~ /^default\.$self->{'type'}$/ &&      if ($newfilename !~ /\w/ || $newfilename =~ /^\W*$/) {
             $newfilename !~ /^\/res\/(.*)spreadsheet$/) {   $newfilename = 'default_'.$self->{'type'};
             if ($newfilename !~ /_$self->{'type'}$/) {      }
                 $newfilename =~ s/[\s_]*$//;      if ($newfilename !~ /^default\.$self->{'type'}$/ &&
                 $newfilename .= '_'.$self->{'type'};   $newfilename !~ /^\/res\/(.*)spreadsheet$/) {
             }   if ($newfilename !~ /_$self->{'type'}$/) {
         }      $newfilename =~ s/[\s_]*$//;
       $newfilename .= '_'.$self->{'type'};
    }
       }
    }
         $self->{'filename'} = $newfilename;          $self->{'filename'} = $newfilename;
         return;          return;
     }      }
Line 808  sub expandnamed { Line 827  sub expandnamed {
                 $result.=$thissum.'+';                  $result.=$thissum.'+';
             }               } 
             $result=~s/\+$//;              $result=~s/\+$//;
             return $result;              return '('.$result.')';
         } else {          } else {
     return 0;      return 0;
         }          }
Line 1195  sub display { Line 1214  sub display {
             last;              last;
         }          }
     }      }
       $self->{outputmode} = $outputmode;
     if ($outputmode eq 'html') {      if ($outputmode eq 'html') {
         $self->compute($r);          $self->compute($r);
         $self->outsheet_html($r);          $self->outsheet_html($r);
     } elsif ($outputmode eq 'htmlclasslist') {      } elsif ($outputmode eq 'htmlclasslist') {
         # No computation neccessary...  This is kludgy          # No computation neccessary...  This is kludgy
         $self->outsheet_htmlclasslist($r);          $self->outsheet_htmlclasslist($r);
       } elsif ($outputmode eq 'source') {
           # No computation necessary. Rumor has it that this is some
           # sort of kludge w.r.t. not "computing". It's also
           # a bit of of a kludge that we call "outsheet_html" and 
           # let the 'outputmode' cause the outputting of source.
           $self->outsheet_html($r);
     } elsif ($outputmode eq 'excel') {      } elsif ($outputmode eq 'excel') {
         $self->compute($r);          $self->compute($r);
         $self->outsheet_excel($r);          $self->outsheet_excel($r);
Line 1240  sub html_export_row { Line 1266  sub html_export_row {
     foreach my $cell (@rowdata) {      foreach my $cell (@rowdata) {
         if ($cell->{'name'} =~ /^[A-Z]/) {          if ($cell->{'name'} =~ /^[A-Z]/) {
     $row_html .= '<td bgcolor="'.$color.'">'.      $row_html .= '<td bgcolor="'.$color.'">'.
                 &html_editable_cell($cell,$color,$allowed).'</td>';                  &html_editable_cell($cell,$color,$allowed,
                                       $self->{outputmode} eq 'source').'</td>';
         } else {          } else {
     $row_html .= '<td bgcolor="#DDCCFF">'.      $row_html .= '<td bgcolor="#DDCCFF">'.
                 &html_editable_cell($cell,'#DDCCFF',$allowed).'</td>';                  &html_editable_cell($cell,'#DDCCFF',$allowed,
                                       $self->{outputmode} eq 'source').'</td>';
         }          }
     }      }
     return $row_html;      return $row_html;
Line 1262  sub html_template_row { Line 1290  sub html_template_row {
     $row_html .= '<td bgcolor="'.$importcolor.'">'.      $row_html .= '<td bgcolor="'.$importcolor.'">'.
                 &html_uneditable_cell($cell,'#FFDDDD',$allowed).'</td>';                  &html_uneditable_cell($cell,'#FFDDDD',$allowed).'</td>';
         } else {          } else {
     $row_html .= '<td bgcolor="#EOFFDD">'.      $row_html .= '<td bgcolor="#E0FFDD">'.
                 &html_editable_cell($cell,'#EOFFDD',$allowed).'</td>';                  &html_editable_cell($cell,'#E0FFDD',$allowed,
                                       $self->{outputmode} eq 'source').'</td>';
         }          }
     }      }
     return $row_html;      return $row_html;
 }  }
   
 sub html_editable_cell {  sub html_editable_cell {
     my ($cell,$bgcolor,$allowed) = @_;      my ($cell,$bgcolor,$allowed,$showsource) = @_;
     my $result;      my $result;
     my ($name,$formula,$value);      my ($name,$formula,$value);
     if (defined($cell)) {      if (defined($cell)) {
Line 1280  sub html_editable_cell { Line 1309  sub html_editable_cell {
     }      }
     $name    = '' if (! defined($name));      $name    = '' if (! defined($name));
     $formula = '' if (! defined($formula));      $formula = '' if (! defined($formula));
     if (! defined($value)) {      if ($showsource) {
           if (!defined($formula) || $formula =~ /^\s*$/) {
               $value = '<font color="'.$bgcolor.'">#</font>';
           } else {
               $value = &HTML::Entities::encode($formula, '<>&"');
           }
       } elsif (! defined($value)) {
         $value = '<font color="'.$bgcolor.'">#</font>';          $value = '<font color="'.$bgcolor.'">#</font>';
         if ($formula ne '') {          if ($formula ne '') {
             $value = '<i>undefined value</i>';              $value = '<i>undefined value</i>';
Line 1332  sub html_row { Line 1367  sub html_row {
     $row_html .= '<td bgcolor="'.$color.'">';      $row_html .= '<td bgcolor="'.$color.'">';
     $row_html .= &html_uneditable_cell($cell,'#FFDDDD');      $row_html .= &html_uneditable_cell($cell,'#FFDDDD');
  } else {   } else {
     $row_html .= '<td bgcolor="#EOFFDD">';      $row_html .= '<td bgcolor="#E0FFDD">';
     $row_html .= &html_editable_cell($cell,'#E0FFDD',$allowed);      $row_html .= &html_editable_cell($cell,'#E0FFDD',$allowed,
                                                $self->{outputmode} eq 'source');
  }   }
  $row_html .= '</td>';   $row_html .= '</td>';
     }      }
Line 1357  sub output_options { Line 1393  sub output_options {
               description => 'HTML'},                description => 'HTML'},
              {value       => 'excel',               {value       => 'excel',
               description => 'Excel'},                description => 'Excel'},
                {value       => 'source',
                 description => 'Show Source'},
 #             {value       => 'xml',  #             {value       => 'xml',
 #              description => 'XML'},  #              description => 'XML'},
              {value       => 'csv',               {value       => 'csv',
Line 1650  sub load { Line 1688  sub load {
             # Load the spreadsheet definition file from the save file              # Load the spreadsheet definition file from the save file
             my %tmphash = &Apache::lonnet::dump($filename,$cdom,$cnum);              my %tmphash = &Apache::lonnet::dump($filename,$cdom,$cnum);
             my ($tmp) = keys(%tmphash);              my ($tmp) = keys(%tmphash);
             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {              if (%tmphash
    && $tmp !~ /^(con_lost|error|no_such_host)/i) {
                 while (my ($cell,$formula) = each(%tmphash)) {                  while (my ($cell,$formula) = each(%tmphash)) {
                     $formulas->{$cell}=$formula;                      $formulas->{$cell}=$formula;
                 }                  }
Line 1784  sub save_tmp { Line 1823  sub save_tmp {
         my %f = $self->formulas();          my %f = $self->formulas();
         while( my ($cell,$formula) = each(%f)) {          while( my ($cell,$formula) = each(%f)) {
             next if ($formula eq 'import');              next if ($formula eq 'import');
             print $fh &Apache::lonnet::escape($cell)."=".              print $fh &escape($cell)."=".
                 &Apache::lonnet::escape($formula)."\n";                  &escape($formula)."\n";
         }          }
         $fh->close();          $fh->close();
     }      }
Line 1803  sub load_tmp { Line 1842  sub load_tmp {
         while (<$spreadsheet_file>) {          while (<$spreadsheet_file>) {
     chomp;      chomp;
             my ($cell,$formula) = split(/=/);              my ($cell,$formula) = split(/=/);
             $cell    = &Apache::lonnet::unescape($cell);              $cell    = &unescape($cell);
             $formula = &Apache::lonnet::unescape($formula);              $formula = &unescape($formula);
             $formulas{$cell} = $formula;              $formulas{$cell} = $formula;
         }          }
         $spreadsheet_file->close();          $spreadsheet_file->close();
Line 1847  sub othersheets { Line 1886  sub othersheets {
     my ($stype) = @_;      my ($stype) = @_;
     $stype = $self->{'type'} if (! defined($stype) || $stype !~ /calc$/);      $stype = $self->{'type'} if (! defined($stype) || $stype !~ /calc$/);
     #      #
     my @alternatives=();      my @alternatives=(&mt('Default'), &mt('LON-CAPA Standard'));
     my %results=&Apache::lonnet::dump($stype.'_spreadsheets',      my %results=&Apache::lonnet::dump($stype.'_spreadsheets',
                                       $self->{'cdom'}, $self->{'cnum'});                                        $self->{'cdom'}, $self->{'cnum'});
     my ($tmp) = keys(%results);      my ($tmp) = keys(%results);
     if ($tmp =~ /^(con_lost|error|no_such_host)/i ) {      if (%results
         @alternatives = (&mt('Default'));   && $tmp !~ /^(con_lost|error|no_such_host)/i ) {
     } else {          push(@alternatives, sort(keys(%results)));
         @alternatives = (&mt('Default'), sort (keys(%results)));  
     }      }
     return @alternatives;       return @alternatives; 
 }  }

Removed from v.1.61  
changed lines
  Added in v.1.72


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