invoice_sections_with_taxes per-agent, RT#79636
[freeside.git] / httemplate / autohandler
index ee37934..3cc8e10 100644 (file)
@@ -1,13 +1,18 @@
 % $m->call_next;
 <%init>
+
+  $FS::Maketext::lh = '';
+
   dbh->{'private_profile'} = {} if UNIVERSAL::can(dbh, 'sprintProfile');
+
 </%init>
 <%filter>
 
-my $profile = '';
 if ( UNIVERSAL::can(dbh, 'sprintProfile') ) {
 
-  if ( lc($r->content_type) eq 'text/html'
+  my $profile = '';
+
+  if ( $r && lc($r->content_type) =~ /^text\/html/
        && $FS::CurrentUser::CurrentUser->option('show_db_profile')
      )
   {
@@ -17,22 +22,29 @@ if ( UNIVERSAL::can(dbh, 'sprintProfile') ) {
     #eval "use Text::Wrapper;";
     #die $@ if $@;
 
-    my $wrapper = new Text::Wrapper( columns => 80 );
     my $text = dbh->sprintProfile();
-    #my $text = $wrapper->wrap( dbh->sprintProfile() );
-    $text =~ s/^/                                                          /mg;
-    
-    $profile = '<PRE>'.
-               encode_entities( $text ).
-               #"\n\n". &sprintAutoProfile(). '</PRE>';
-               "\n\n".                        '</PRE>';
-  } 
+    #$text =~ s/^/                                                          /mg;
+
+    $profile = '<PRE>'.  encode_entities( $text ). "\n\n". '</PRE>';
+
+  }
+
+  #well, could do this without sprintProfile, but definiately don't want it on
+  #unless DBIx::Profile is loaded
+  if ( $FS::CurrentUser::CurrentUser->option('save_db_profile') ) {
+    #my $file = %%%FREESIDE_LOG%%%; #substitute here?  maybe get from FS.pm?
+    my $file = '/usr/local/etc/freeside/'; #bah
+    $file .= "dbix_profile.$$.". time;
+    dbh->setLogFile($file);
+    dbh->printProfile();
+  }
 
   dbh->{'private_profile'} = {};
+
+  s/(<\/BODY>[\s\n]*<\/HTML>[\s\n]*)/$profile$1/i;
 }
 
-s/(<\/BODY>[\s\n]*<\/HTML>[\s\n]*)$/$profile$1/i;
 </%filter>
 <%cleanup>
-   dbh->commit();
+   dbh->commit() if dbh;
 </%cleanup>