/[SQL2XLS]/sql2xlsx.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sql2xlsx.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 12 by dpavlin, Mon Nov 3 20:15:09 2008 UTC revision 13 by dpavlin, Mon Nov 3 20:32:44 2008 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl  #!/usr/bin/perl -T
2  use warnings;  use warnings;
3  use strict;  use strict;
4    
# Line 22  C<< \c database >> syntax is supported. Line 22  C<< \c database >> syntax is supported.
22  You can also run script from command line, and it will produce  You can also run script from command line, and it will produce
23  C<< sql_reports.xls >> file.  C<< sql_reports.xls >> file.
24    
25    If run within directory, it will use files in it to produce file.
26    
27    When called as CGI, directory name can be appended to name of script
28    to produce report for any sub-directory within directory where
29    C<sql2xls.cgi> is installed.
30    
31  =head1 INSTALLATION  =head1 INSTALLATION
32    
33  Only required file is this script C<< sql2xls.cgi >>  Only required file is this script C<< sql2xls.cgi >>
# Line 42  Dobrica Pavlinusic, dpavlin@rot13.org Line 48  Dobrica Pavlinusic, dpavlin@rot13.org
48  use Spreadsheet::WriteExcel;  use Spreadsheet::WriteExcel;
49  use DBI;  use DBI;
50  use CGI::Carp qw(fatalsToBrowser);  use CGI::Carp qw(fatalsToBrowser);
 use CGI qw(path_translated);  
51  use Encode qw/decode/;  use Encode qw/decode/;
52  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
53    
# Line 58  our $xls_date_format = 'dd.mm.yyyy'; Line 63  our $xls_date_format = 'dd.mm.yyyy';
63    
64  our $debug = 1;  our $debug = 1;
65    
66  my $sql_dir = path_translated || '.';  my $sql_dir = $ENV{SCRIPT_FILENAME} || '.';
67  $sql_dir =~ s,/[^/]+$,,;  $sql_dir =~ s,/[^/]+$,,;
68    
 opendir(DIR, $sql_dir) || die "can't opendir $sql_dir: $!";  
 my @sql_files = sort grep { /\.sql$/i && -f "$sql_dir/$_" } readdir(DIR);  
 closedir DIR;  
   
69  my $config_path = "$sql_dir/config.pl";  my $config_path = "$sql_dir/config.pl";
70  warn "# using $config_path\n";  warn "# using $config_path\n";
71  require $config_path if -e $config_path;  require $config_path if -e $config_path;
72    
73    my $reports_path = $ENV{PATH_INFO};
74    $reports_path =~ s/\.\.//g; # some protection against path exploits
75    $reports_path ||= shift @ARGV; # for CLI invocation
76    $sql_dir .= "/$reports_path" if -e "$sql_dir/$reports_path";
77    
78    warn "# reading SQL queries from $sql_dir\n" if $debug;
79    
80    opendir(DIR, $sql_dir) || die "can't opendir $sql_dir: $!";
81    my @sql_files = sort grep { /\.sql$/i && -f "$sql_dir/$_" } readdir(DIR);
82    closedir DIR;
83    
84  my $workbook;  my $workbook;
85  if ($ENV{GATEWAY_INTERFACE} && $ENV{GATEWAY_INTERFACE} =~ m/CGI/i) {  if ($ENV{GATEWAY_INTERFACE} && $ENV{GATEWAY_INTERFACE} =~ m/CGI/i) {
86          # use as cgi script          # use as cgi script
# Line 101  foreach my $sql_file (@sql_files) { Line 113  foreach my $sql_file (@sql_files) {
113    
114          print STDERR "working on $sql_file\n" if ($debug);          print STDERR "working on $sql_file\n" if ($debug);
115    
116          open(SQL,$sql_file) || die "can't open sql file '$sql_file': $!";          open(SQL,"$sql_dir/$sql_file") || die "can't open sql file '$sql_dir/$sql_file': $!";
117          my $comment = '';          my $comment = '';
118          my $sql = "";          my $sql = "";
119          while(<SQL>) {          while(<SQL>) {

Legend:
Removed from v.12  
changed lines
  Added in v.13

  ViewVC Help
Powered by ViewVC 1.1.26