[freeside-commits] freeside/FS/FS Conf.pm, 1.181, 1.182 UID.pm, 1.32, 1.33 conf.pm, NONE, 1.1 cust_bill.pm, 1.164, 1.165 cust_main.pm, 1.272, 1.273 svc_acct.pm, 1.218, 1.219

Jeff Finucane,420,, jeff at wavetail.420.am
Mon Feb 26 17:48:09 PST 2007


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail:/tmp/cvs-serv2258/FS/FS

Modified Files:
	Conf.pm UID.pm cust_bill.pm cust_main.pm svc_acct.pm 
Added Files:
	conf.pm 
Log Message:
config goes in database

--- NEW FILE: conf.pm ---
package FS::conf;

use strict;
use vars qw( @ISA );
use FS::Record qw( qsearch qsearchs );

@ISA = qw(FS::Record);

=head1 NAME

FS::conf - Object methods for conf records

=head1 SYNOPSIS

  use FS::conf;

  $record = new FS::conf \%hash;
  $record = new FS::conf { 'column' => 'value' };

  $error = $record->insert;

  $error = $new_record->replace($old_record);

  $error = $record->delete;

  $error = $record->check;

=head1 DESCRIPTION

An FS::conf object represents a configuration value.  FS::conf inherits from
FS::Record.  The following fields are currently supported:

=over 4

=item confnum - primary key

=item agentnum - the agent to which this configuration value applies

=item name - the name of the configuration value

=item value - the configuration value


=back

=head1 METHODS

=over 4

=item new HASHREF

Creates a new configuration value.  To add the example to the database, see L<"insert">.

Note that this stores the hash reference, not a distinct copy of the hash it
points to.  You can ask the object for a copy with the I<hash> method.

=cut

sub table { 'conf'; }

=item insert

Adds this record to the database.  If there is an error, returns the error,
otherwise returns false.

=cut

=item delete

Delete this record from the database.

=cut

=item replace OLD_RECORD

Replaces the OLD_RECORD with this one in the database.  If there is an error,
returns the error, otherwise returns false.

=cut

=item check

Checks all fields to make sure this is a valid configuration value.  If there is
an error, returns the error, otherwise returns false.  Called by the insert
and replace methods.

=cut

sub check {
  my $self = shift;

  my $error = 
    $self->ut_numbern('confnum')
    || $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum')
    || $self->ut_text('name')
    || $self->ut_anything('value')
  ;
  return $error if $error;

  $self->SUPER::check;
}

=back

=head1 BUGS

=head1 SEE ALSO

L<FS::Record>, schema.html from the base documentation.

=cut

1;


Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.272
retrieving revision 1.273
diff -u -d -r1.272 -r1.273
--- cust_main.pm	15 Feb 2007 20:18:29 -0000	1.272
+++ cust_main.pm	27 Feb 2007 01:48:06 -0000	1.273
@@ -417,7 +417,7 @@
   #'mg_watchlist_header.watchlist_header_id' => { 'mg_watchlist_details.watchlist_details_id' },
   #'mg_user_grid_header.grid_header_id' => { 'mg_user_grid_details.user_grid_details_id' },
   #'mg_portfolio_header.portfolio_header_id' => { 'mg_portfolio_trades.portfolio_trades_id' => { 'mg_portfolio_trades_positions.portfolio_trades_positions_id' } },
-  my @tables = eval($conf->config_binary('cust_main-skeleton_tables'));
+  my @tables = eval(join('\n',$conf->config('cust_main-skeleton_tables')));
   die $@ if $@;
 
   _copy_skel( 'cust_main',                                 #tablename

Index: UID.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/UID.pm,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- UID.pm	14 Dec 2006 09:27:26 -0000	1.32
+++ UID.pm	27 Feb 2007 01:48:06 -0000	1.33
@@ -4,7 +4,7 @@
 use vars qw(
   @ISA @EXPORT_OK $cgi $dbh $freeside_uid $user 
   $conf_dir $secrets $datasrc $db_user $db_pass %callback @callback
-  $driver_name $AutoCommit
+  $driver_name $AutoCommit $callback_hack
 );
 use subs qw(
   getsecrets cgisetotaker
@@ -12,7 +12,7 @@
 use Exporter;
 use Carp qw(carp croak cluck confess);
 use DBI;
-use FS::Conf;
+use IO::File;
 use FS::CurrentUser;
 
 @ISA = qw(Exporter);
@@ -24,6 +24,7 @@
 $conf_dir = "%%%FREESIDE_CONF%%%/";
 
 $AutoCommit = 1; #ours, not DBI
+$callback_hack = 0;
 
 =head1 NAME
 
@@ -104,12 +105,14 @@
 
   FS::CurrentUser->load_user($user);
 
-  foreach ( keys %callback ) {
-    &{$callback{$_}};
-    # breaks multi-database installs # delete $callback{$_}; #run once
-  }
+  unless($callback_hack) {
+    foreach ( keys %callback ) {
+      &{$callback{$_}};
+      # breaks multi-database installs # delete $callback{$_}; #run once
+    }
 
-  &{$_} foreach @callback;
+    &{$_} foreach @callback;
+  }
 
   $dbh;
 }
@@ -275,11 +278,11 @@
 sub getsecrets {
   my($setuser) = shift;
   $user = $setuser if $setuser;
-  my($conf) = new FS::Conf $conf_dir;
 
-  if ( $conf->exists('mapsecrets') ) {
+  if ( -e "$conf_dir/mapsecrets" ) {
     die "No user!" unless $user;
-    my($line) = grep /^\s*($user|\*)\s/, $conf->config('mapsecrets');
+    my($line) = grep /^\s*($user|\*)\s/,
+      map { /^(.*)$/; $1 } readline(new IO::File "$conf_dir/mapsecrets");
     confess "User $user not found in mapsecrets!" unless $line;
     $line =~ /^\s*($user|\*)\s+(.*)$/;
     $secrets = $2;
@@ -289,9 +292,9 @@
     $secrets = 'secrets';
   }
 
-  ($datasrc, $db_user, $db_pass) = $conf->config($secrets)
-    or die "Can't get secrets: $secrets: $!\n";
-  $FS::Conf::default_dir = $conf_dir. "/conf.$datasrc";
+  ($datasrc, $db_user, $db_pass) = 
+    map { /^(.*)$/; $1 } readline(new IO::File "$conf_dir/$secrets")
+      or die "Can't get secrets: $secrets: $!\n";
   undef $driver_name;
   ($datasrc, $db_user, $db_pass);
 }

Index: svc_acct.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_acct.pm,v
retrieving revision 1.218
retrieving revision 1.219
diff -u -d -r1.218 -r1.219
--- svc_acct.pm	21 Feb 2007 11:26:02 -0000	1.218
+++ svc_acct.pm	27 Feb 2007 01:48:06 -0000	1.219
@@ -8,8 +8,6 @@
              $username_noperiod $username_nounderscore $username_nodash
              $username_uppercase $username_percent
              $password_noampersand $password_noexclamation
-             $welcome_template $welcome_from
-             $welcome_subject $welcome_subject_template $welcome_mimetype
              $warning_template $warning_from $warning_subject $warning_mimetype
              $warning_cc
              $smtpmachine
@@ -66,24 +64,6 @@
   $password_noampersand = $conf->exists('password-noexclamation');
   $password_noexclamation = $conf->exists('password-noexclamation');
   $dirhash = $conf->config('dirhash') || 0;
-  if ( $conf->exists('welcome_email') ) {
-    $welcome_template = new Text::Template (
-      TYPE   => 'ARRAY',
-      SOURCE => [ map "$_\n", $conf->config('welcome_email') ]
-    ) or warn "can't create welcome email template: $Text::Template::ERROR";
-    $welcome_from = $conf->config('welcome_email-from'); # || 'your-isp-is-dum'
-    $welcome_subject = $conf->config('welcome_email-subject') || 'Welcome';
-    $welcome_subject_template = new Text::Template (
-      TYPE   => 'STRING',
-      SOURCE => $welcome_subject,
-    ) or warn "can't create welcome email subject template: $Text::Template::ERROR";
-    $welcome_mimetype = $conf->config('welcome_email-mimetype') || 'text/plain';
-  } else {
-    $welcome_template = '';
-    $welcome_from = '';
-    $welcome_subject = '';
-    $welcome_mimetype = '';
-  }
   if ( $conf->exists('warning_email') ) {
     $warning_template = new Text::Template (
       TYPE   => 'ARRAY',
@@ -467,6 +447,7 @@
 
   if ( $cust_pkg ) {
     my $cust_main = $cust_pkg->cust_main;
+    my $agentnum = $cust_main->agentnum;
 
     if (   $conf->exists('emailinvoiceautoalways')
         || $conf->exists('emailinvoiceauto')
@@ -478,7 +459,25 @@
     }
 
     #welcome email
-    my $to = '';
+    my ($to,$welcome_template,$welcome_from,$welcome_subject,$welcome_subject_template,$welcome_mimetype)
+      = ('','','','','','');
+
+    if ( $conf->exists('welcome_email', $agentnum) ) {
+      $welcome_template = new Text::Template (
+        TYPE   => 'ARRAY',
+        SOURCE => [ map "$_\n", $conf->config('welcome_email', $agentnum) ]
+      ) or warn "can't create welcome email template: $Text::Template::ERROR";
+      $welcome_from = $conf->config('welcome_email-from', $agentnum);
+        # || 'your-isp-is-dum'
+      $welcome_subject = $conf->config('welcome_email-subject', $agentnum)
+        || 'Welcome';
+      $welcome_subject_template = new Text::Template (
+        TYPE   => 'STRING',
+        SOURCE => $welcome_subject,
+      ) or warn "can't create welcome email subject template: $Text::Template::ERROR";
+      $welcome_mimetype = $conf->config('welcome_email-mimetype', $agentnum)
+        || 'text/plain';
+    }
     if ( $welcome_template && $cust_pkg ) {
       my $to = join(', ', grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list );
       if ( $to ) {
@@ -949,7 +948,7 @@
         $recref->{shell} = (grep $_ eq $recref->{shell}, @shells)[0];
       } else {
         return "Illegal shell \`". $self->shell. "\'; ".
-               $conf->dir. "/shells contains: @shells";
+               "shells configuration value contains: @shells";
       }
     } else {
       $recref->{shell} = '/bin/sync';

Index: Conf.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Conf.pm,v
retrieving revision 1.181
retrieving revision 1.182
diff -u -d -r1.181 -r1.182
--- Conf.pm	25 Feb 2007 03:08:10 -0000	1.181
+++ Conf.pm	27 Feb 2007 01:48:06 -0000	1.182
@@ -1,13 +1,14 @@
 package FS::Conf;
 
-use vars qw($default_dir $base_dir @config_items @card_types $DEBUG );
-use IO::File;
-use File::Basename;
+use vars qw($base_dir @config_items @card_types $DEBUG );
+use MIME::Base64;
 use FS::ConfItem;
 use FS::ConfDefaults;
+use FS::conf;
+use FS::Record qw(qsearch qsearchs);
+use FS::UID qw(dbh);
 
 $base_dir = '%%%FREESIDE_CONF%%%';
-$default_dir = '%%%FREESIDE_CONF%%%';
 
 
 $DEBUG = 0;
@@ -20,13 +21,8 @@
 
   use FS::Conf;
 
-  $conf = new FS::Conf "/config/directory";
-
-  $FS::Conf::default_dir = "/config/directory";
   $conf = new FS::Conf;
 
-  $dir = $conf->dir;
-
   $value = $conf->config('key');
   @list  = $conf->config('key');
   $bool  = $conf->exists('key');
@@ -46,39 +42,19 @@
 
 =over 4
 
-=item new [ DIRECTORY ]
+=item new
 
-Create a new configuration object.  A directory arguement is required if
-$FS::Conf::default_dir has not been set.
+Create a new configuration object.
 
 =cut
 
 sub new {
-  my($proto,$dir) = @_;
+  my($proto) = @_;
   my($class) = ref($proto) || $proto;
-  my($self) = { 'dir'      => $dir || $default_dir,
-                'base_dir' => $base_dir,
-              };
+  my($self) = { 'base_dir' => $base_dir };
   bless ($self, $class);
 }
 
-=item dir
-
-Returns the conf directory.
-
-=cut
-
-sub dir {
-  my($self) = @_;
-  my $dir = $self->{dir};
-  -e $dir or die "FATAL: $dir doesn't exist!";
-  -d $dir or die "FATAL: $dir isn't a directory!";
-  -r $dir or die "FATAL: Can't read $dir!";
-  -x $dir or die "FATAL: $dir not searchable (executable)!";
-  $dir =~ /^(.*)$/;
-  $1;
-}
-
 =item base_dir
 
 Returns the base directory.  By default this is /usr/local/etc/freeside.
@@ -102,20 +78,29 @@
 
 =cut
 
+sub _config {
+  my($self,$name,$agent)=@_;
+  my $hashref = { 'name' => $name };
+  if (defined($agent) && $agent) {
+    $hashref->{agent} = $agent;
+  }
+  local $FS::Record::conf = undef;  # XXX evil hack prevents recursion
+  my $cv = FS::Record::qsearchs('conf', $hashref);
+  if (!$cv && exists($hashref->{agent})) {
+    delete($hashref->{agent});
+    $cv = FS::Record::qsearchs('conf', $hashref);
+  }
+  return $cv;
+}
+
 sub config {
-  my($self,$file)=@_;
-  my($dir)=$self->dir;
-  my $fh = new IO::File "<$dir/$file" or return;
+  my($self,$name,$agent)=@_;
+  my $cv = $self->_config($name, $agent) or return;
+
   if ( wantarray ) {
-    map {
-      /^(.*)$/
-        or die "Illegal line (array context) in $dir/$file:\n$_\n";
-      $1;
-    } <$fh>;
+    split "\n", $cv->value;
   } else {
-    <$fh> =~ /^(.*)$/
-      or die "Illegal line (scalar context) in $dir/$file:\n$_\n";
-    $1;
+    (split("\n", $cv->value))[0];
   }
 }
 
@@ -126,12 +111,9 @@
 =cut
 
 sub config_binary {
-  my($self,$file)=@_;
-  my($dir)=$self->dir;
-  my $fh = new IO::File "<$dir/$file" or return;
-  local $/;
-  my $content = <$fh>;
-  $content;
+  my($self,$name,$agent)=@_;
+  my $cv = $self->_config($name, $agent) or return;
+  decode_base64($cv->value);
 }
 
 =item exists KEY
@@ -142,9 +124,8 @@
 =cut
 
 sub exists {
-  my($self,$file)=@_;
-  my($dir) = $self->dir;
-  -e "$dir/$file";
+  my($self,$name,$agent)=@_;
+  defined($self->_config($name, $agent));
 }
 
 =item config_orbase KEY SUFFIX
@@ -155,11 +136,11 @@
 =cut
 
 sub config_orbase {
-  my( $self, $file, $suffix ) = @_;
-  if ( $self->exists("${file}_$suffix") ) {
-    $self->config("${file}_$suffix");
+  my( $self, $name, $suffix ) = @_;
+  if ( $self->exists("${name}_$suffix") ) {
+    $self->config("${name}_$suffix");
   } else {
-    $self->config($file);
+    $self->config($name);
   }
 }
 
@@ -170,12 +151,8 @@
 =cut
 
 sub touch {
-  my($self, $file) = @_;
-  my $dir = $self->dir;
-  unless ( $self->exists($file) ) {
-    warn "[FS::Conf] TOUCH $file\n" if $DEBUG;
-    system('touch', "$dir/$file");
-  }
+  my($self, $name, $agent) = @_;
+  $self->set($name, '', $agent);
 }
 
 =item set KEY VALUE
@@ -185,23 +162,49 @@
 =cut
 
 sub set {
-  my($self, $file, $value) = @_;
-  my $dir = $self->dir;
+  my($self, $name, $value, $agent) = @_;
   $value =~ /^(.*)$/s;
   $value = $1;
-  unless ( join("\n", @{[ $self->config($file) ]}) eq $value ) {
-    warn "[FS::Conf] SET $file\n" if $DEBUG;
-#    warn "$dir" if is_tainted($dir);
-#    warn "$dir" if is_tainted($file);
-    chmod 0644, "$dir/$file";
-    my $fh = new IO::File ">$dir/$file" or return;
-    chmod 0644, "$dir/$file";
-    print $fh "$value\n";
+
+  warn "[FS::Conf] SET $file\n" if $DEBUG;
+
+  my $old = FS::Record::qsearchs('conf', {name => $name, agent => $agent});
+  my $new = new FS::conf { $old ? $old->hash 
+                                : ('name' => $name, 'agent' => $agent)
+                         };
+  $new->value($value);
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  my $error;
+  if ($old) {
+    $error = $new->replace($old);
+  }else{
+    $error = $new->insert;
+  }
+
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    die "error setting configuration value: $error \n"
   }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+}
+
+=item set_binary KEY VALUE
+
+Sets the specified configuration key to an exact scalar value which
+can be retrieved with config_binary.
+
+=cut
+
+sub set_binary {
+  my($self,$name, $value, $agent)=@_;
+  $self->set($name, encode_base64($value), $agent);
 }
-#sub is_tainted {
-#             return ! eval { join('', at _), kill 0; 1; };
-#         }
 
 =item delete KEY
 
@@ -210,11 +213,23 @@
 =cut
 
 sub delete {
-  my($self, $file) = @_;
-  my $dir = $self->dir;
-  if ( $self->exists($file) ) {
+  my($self, $name, $agent) = @_;
+  if ( my $cv = FS::Record::qsearchs('conf', {name => $name, agent => $agent}) ) {
     warn "[FS::Conf] DELETE $file\n";
-    unlink "$dir/$file";
+
+    my $oldAutoCommit = $FS::UID::AutoCommit;
+    local $FS::UID::AutoCommit = 0;
+    my $dbh = dbh;
+
+    my $error = $cv->delete;
+
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      die "error setting configuration value: $error \n"
+    }
+
+    $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
   }
 }
 
@@ -230,65 +245,68 @@
   #quelle kludge
   @config_items,
   ( map { 
-        my $basename = basename($_);
-        $basename =~ /^(.*)$/;
-        $basename = $1;
         new FS::ConfItem {
-                           'key'         => $basename,
+                           'key'         => $_->name,
                            'section'     => 'billing',
                            'description' => 'Alternate template file for invoices.  See the <a href="../docs/billing.html">billing documentation</a> for details.',
                            'type'        => 'textarea',
                          }
-      } glob($self->dir. '/invoice_template_*')
+      } FS::Record::qsearch('conf', {}, '', "WHERE name LIKE 'invoice!_template!_%' ESCAPE '!'")
   ),
   ( map { 
-        my $basename = basename($_);
-        $basename =~ /^(.*)$/;
-        $basename = $1;
         new FS::ConfItem {
-                           'key'         => $basename,
+                           'key'         => '$_->name',
+                           'section'     => 'billing',  #? 
+                           'description' => 'An image to include in some types of invoices',
+                           'type'        => 'binary',
+                         }
+      } FS::Record::qsearch('conf', {}, '', "WHERE name LIKE 'logo!_%.png' ESCAPE '!'")
+  ),
+  ( map { 
+        new FS::ConfItem {
+                           'key'         => $_->name,
                            'section'     => 'billing',
                            'description' => 'Alternate HTML template for invoices.  See the <a href="../docs/billing.html">billing documentation</a> for details.',
                            'type'        => 'textarea',
                          }
-      } glob($self->dir. '/invoice_html_*')
+      } FS::Record::qsearch('conf', {}, '', "WHERE name LIKE 'invoice!_html!_%' ESCAPE '!'")
   ),
   ( map { 
-        my $basename = basename($_);
-        $basename =~ /^(.*)$/;
-        $basename = $1;
-        ($latexname = $basename ) =~ s/latex/html/;
+        ($latexname = $_->name ) =~ s/latex/html/;
         new FS::ConfItem {
-                           'key'         => $basename,
+                           'key'         => $_->name,
                            'section'     => 'billing',
                            'description' => "Alternate Notes section for HTML invoices.  Defaults to the same data in $latexname if not specified.",
                            'type'        => 'textarea',
                          }
-      } glob($self->dir. '/invoice_htmlnotes_*')
+      } FS::Record::qsearch('conf', {}, '', "WHERE name LIKE 'invoice!_htmlnotes!_%' ESCAPE '!'")
   ),
   ( map { 
-        my $basename = basename($_);
-        $basename =~ /^(.*)$/;
-        $basename = $1;
         new FS::ConfItem {
-                           'key'         => $basename,
+                           'key'         => $_->name,
                            'section'     => 'billing',
                            'description' => 'Alternate LaTeX template for invoices.  See the <a href="../docs/billing.html">billing documentation</a> for details.',
                            'type'        => 'textarea',
                          }
-      } glob($self->dir. '/invoice_latex_*')
+      } FS::Record::qsearch('conf', {}, '', "WHERE name LIKE 'invoice!_latex!_%' ESCAPE '!'")
   ),
   ( map { 
-        my $basename = basename($_);
-        $basename =~ /^(.*)$/;
-        $basename = $1;
         new FS::ConfItem {
-                           'key'         => $basename,
+                           'key'         => '$_->name',
+                           'section'     => 'billing',  #? 
+                           'description' => 'An image to include in some types of invoices',
+                           'type'        => 'binary',
+                         }
+      } FS::Record::qsearch('conf', {}, '', "WHERE name LIKE 'logo!_%.eps' ESCAPE '!'")
+  ),
+  ( map { 
+        new FS::ConfItem {
+                           'key'         => $_->name,
                            'section'     => 'billing',
                            'description' => 'Alternate Notes section for LaTeX typeset PostScript invoices.  See the <a href="../docs/billing.html">billing documentation</a> for details.',
                            'type'        => 'textarea',
                          }
-      } glob($self->dir. '/invoice_latexnotes_*')
+      } FS::Record::qsearch('conf', {}, '', "WHERE name LIKE 'invoice!_latexnotes!_%' ESCAPE '!'")
   );
 }
 
@@ -2046,6 +2064,20 @@
   },
 
   {
+    'key'         => 'logo.png',
+    'section'     => 'billing',  #? 
+    'description' => 'An image to include in some types of invoices',
+    'type'        => 'binary',
+  },
+
+  {
+    'key'         => 'logo.eps',
+    'section'     => 'billing',  #? 
+    'description' => 'An image to include in some types of invoices',
+    'type'        => 'binary',
+  },
+
+  {
     'key'         => 'selfservice-ignore_quantity',
     'section'     => '',
     'description' => 'Ignores service quantity restrictions in self-service context.  Strongly not recommended - just set your quantities correctly in the first place.',

Index: cust_bill.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill.pm,v
retrieving revision 1.164
retrieving revision 1.165
diff -u -d -r1.164 -r1.165
--- cust_bill.pm	19 Feb 2007 15:40:30 -0000	1.164
+++ cust_bill.pm	27 Feb 2007 01:48:06 -0000	1.165
@@ -1827,7 +1827,8 @@
 =item print_latex [ TIME [ , TEMPLATE ] ]
 
 Internal method - returns a filename of a filled-in LaTeX template for this
-invoice (Note: add ".tex" to get the actual filename).
+invoice (Note: add ".tex" to get the actual filename), and a filename of
+an associated logo (with the .eps extension included).
 
 See print_ps and print_pdf for methods that return PostScript and PDF output.
 
@@ -1909,6 +1910,7 @@
     'quantity'     => 1,
     'terms'        => $conf->config('invoice_default_terms') || 'Payable upon receipt',
     #'notes'        => join("\n", $conf->config('invoice_latexnotes') ),
+    # better hang on to conf_dir for a while
     'conf_dir'     => "$FS::UID::conf_dir/conf.$FS::UID::datasrc",
   );
 
@@ -2134,6 +2136,22 @@
   }
 
   my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
+  my $lh = new File::Temp( TEMPLATE => 'invoice.'. $self->invnum. '.XXXXXXXX',
+                           DIR      => $dir,
+                           SUFFIX   => '.eps',
+                           UNLINK   => 0,
+                         ) or die "can't open temp file: $!\n";
+
+  if ($template && $conf->exists("logo_${template}.eps")) {
+    print $lh $conf->config_binary("logo_${template}.eps")
+      or die "can't write temp file: $!\n";
+  }else{
+    print $lh $conf->config_binary('logo.eps')
+      or die "can't write temp file: $!\n";
+  }
+  close $lh;
+  $invoice_data{'logo_file'} = $lh->filename;
+
   my $fh = new File::Temp( TEMPLATE => 'invoice.'. $self->invnum. '.XXXXXXXX',
                            DIR      => $dir,
                            SUFFIX   => '.tex',
@@ -2149,7 +2167,7 @@
   close $fh;
 
   $fh->filename =~ /^(.*).tex$/ or die "unparsable filename: ". $fh->filename;
-  return $1;
+  return ($1, $invoice_data{'logo_file'});
 
 }
 
@@ -2167,7 +2185,7 @@
 sub print_ps {
   my $self = shift;
 
-  my $file = $self->print_latex(@_);
+  my ($file, $lfile) = $self->print_latex(@_);
 
   my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
   chdir($dir);
@@ -2186,6 +2204,7 @@
     or die "can't open $file.ps: $! (error in LaTeX template?)\n";
 
   unlink("$file.dvi", "$file.log", "$file.aux", "$file.ps", "$file.tex");
+  unlink("$lfile");
 
   my $ps = '';
   while (<POSTSCRIPT>) {
@@ -2212,7 +2231,7 @@
 sub print_pdf {
   my $self = shift;
 
-  my $file = $self->print_latex(@_);
+  my ($file, $lfile) = $self->print_latex(@_);
 
   my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
   chdir($dir);
@@ -2240,6 +2259,7 @@
     or die "can't open $file.pdf: $! (error in LaTeX template?)\n";
 
   unlink("$file.dvi", "$file.log", "$file.aux", "$file.pdf", "$file.tex");
+  unlink("$lfile");
 
   my $pdf = '';
   while (<PDF>) {



More information about the freeside-commits mailing list