optimize CDR rating after timed rate perf regression, RT#15739
[freeside.git] / httemplate / view / cust_bill-logo.cgi
index 235485f..d55ec04 100755 (executable)
@@ -1,10 +1,28 @@
-<%
+<% $conf->config_binary("logo$templatename.png", $agentnum) %>
+<%init>
 
-my $conf = new FS::Conf;
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('View invoices')
+      or $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
+my $conf;
+
+my $templatename;
+my $agentnum = '';
+if ( $cgi->param('invnum') ) {
+  $templatename = $cgi->param('template') || $cgi->param('templatename');
+  my $cust_bill = qsearchs('cust_bill', { 'invnum' => $cgi->param('invnum') } )
+    or die 'unknown invnum';
+  $conf = $cust_bill->conf;
+  $agentnum = $cust_bill->cust_main->agentnum;
+} else {
+  # assume the default config
+  $conf = FS::Conf->new;
+  my($query) = $cgi->keywords;
+  $query =~ /^([^\.\/]*)$/ or die 'illegal query';
+  $templatename = $1;
+}
 
-my($query) = $cgi->keywords;
-$query =~ /^([^\.\/]*)$/;
-my $templatename = $1;
 if ( $templatename && $conf->exists("logo_$templatename.png") ) {
   $templatename = "_$templatename";
 } else {
@@ -12,4 +30,5 @@ if ( $templatename && $conf->exists("logo_$templatename.png") ) {
 }
 
 http_header('Content-Type' => 'image/png' );
-%><%= $conf->config_binary("logo$templatename.png") %>
+
+</%init>