--- loncom/interface/spreadsheet/Spreadsheet.pm 2006/01/10 16:38:47 1.61 +++ loncom/interface/spreadsheet/Spreadsheet.pm 2007/01/23 01:48:16 1.75 @@ -1,5 +1,5 @@ # -# $Id: Spreadsheet.pm,v 1.61 2006/01/10 16:38:47 albertel Exp $ +# $Id: Spreadsheet.pm,v 1.75 2007/01/23 01:48:16 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -60,6 +60,9 @@ use HTML::TokeParser; use Spreadsheet::WriteExcel; use Time::HiRes; use Apache::lonlocal; +use lib '/home/httpd/lib/perl/'; +use LONCAPA; + ## ## Package Variables @@ -85,7 +88,7 @@ sub new { my $class = ref($this) || $this; my ($stype) = ($class =~ /Apache::(.*)$/); # - my ($name,$domain,$filename,$usymb)=@_; + my ($name,$domain,$filename,$usymb,$section,$groups)=@_; if (defined($usymb) && ref($usymb)) { $usymb = $usymb->symb; } @@ -95,10 +98,22 @@ sub new { if (! defined($domain) || $domain eq '') { $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 = { name => $name, domain => $domain, + section => $section, + groups => $groups, type => $stype, symb => $usymb, errorlog => '', @@ -157,16 +172,20 @@ sub filename { $newfilename = 'default_'.$self->{'type'}; } } - if ($newfilename !~ /\w/ || $newfilename =~ /^\W*$/) { - $newfilename = 'default_'.$self->{'type'}; - } - if ($newfilename !~ /^default\.$self->{'type'}$/ && - $newfilename !~ /^\/res\/(.*)spreadsheet$/) { - if ($newfilename !~ /_$self->{'type'}$/) { - $newfilename =~ s/[\s_]*$//; - $newfilename .= '_'.$self->{'type'}; - } - } + if ($newfilename eq &mt('LON-CAPA Standard')) { + undef($newfilename); + } else { + if ($newfilename !~ /\w/ || $newfilename =~ /^\W*$/) { + $newfilename = 'default_'.$self->{'type'}; + } + if ($newfilename !~ /^default\.$self->{'type'}$/ && + $newfilename !~ /^\/res\/(.*)spreadsheet$/) { + if ($newfilename !~ /_$self->{'type'}$/) { + $newfilename =~ s/[\s_]*$//; + $newfilename .= '_'.$self->{'type'}; + } + } + } $self->{'filename'} = $newfilename; return; } @@ -656,6 +675,21 @@ sub MAXPARM { return $max; } + +=pod + +=item PARM(parametername) + +Returns the value of the parameter matching the input parameter name. +parametername should be a string such as 'parameter_1_opendate'. + +=cut + +#------------------------------------------------------- +sub PARM { + return $c{$_[0]}; +} + #------------------------------------------------------- =pod @@ -786,8 +820,10 @@ sub expandnamed { my $self = shift; my $expression=shift; if ($expression=~/^\&/) { - my ($func,$var,$formula)=($expression=~/^\&(\w+)\(([^\;]+)\;(.*)\)/); + my ($func,$var,$formula)=($expression=~/^\&(\w+)\(([^\;]+)\;(.*)\)/s); my @vars=split(/\W+/,$formula); + # make the list uniq + @vars = keys(%{{ map { $_ => 1 } @vars }}); my %values=(); foreach my $varname ( @vars ) { if ($varname=~/^(parameter|stores|timestamp)/) { @@ -808,7 +844,7 @@ sub expandnamed { $result.=$thissum.'+'; } $result=~s/\+$//; - return $result; + return '('.$result.')'; } else { return 0; } @@ -871,7 +907,7 @@ sub sett { # Replace 'A0' with the value from 'A0' $t{$cell}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$sheet_values\{\'$2\'\}/g; # Replace parameters - $t{$cell}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.$self->expandnamed($2)/ge; + $t{$cell}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.$self->expandnamed($2)/sge; } } # @@ -883,7 +919,7 @@ sub sett { $t{$cell}=$formula; $t{$cell}=~s/\.\.+/\,/g; $t{$cell}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$sheet_values\{\'$2\'\}/g; - $t{$cell}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.$self->expandnamed($2)/ge; + $t{$cell}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.$self->expandnamed($2)/sge; } elsif ( $col =~ /^[A-Z]$/ ) { if ($formula !~ /^\!/ && exists($self->{'constants'}->{$cell}) && $self->{'constants'}->{$cell} ne '') { @@ -894,7 +930,7 @@ sub sett { $t{$cell}=$formula; $t{$cell}=~s/\.\.+/\,/g; $t{$cell}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$sheet_values\{\'$2\'\}/g; - $t{$cell}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.$self->expandnamed($2)/ge; + $t{$cell}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.$self->expandnamed($2)/sge; } } %{$self->{'safe'}->varglob('t')}=%t; @@ -1195,12 +1231,19 @@ sub display { last; } } + $self->{outputmode} = $outputmode; if ($outputmode eq 'html') { $self->compute($r); $self->outsheet_html($r); } elsif ($outputmode eq 'htmlclasslist') { # No computation neccessary... This is kludgy $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') { $self->compute($r); $self->outsheet_excel($r); @@ -1240,10 +1283,12 @@ sub html_export_row { foreach my $cell (@rowdata) { if ($cell->{'name'} =~ /^[A-Z]/) { $row_html .= '