Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / autohandler
1 % $m->call_next;
2 <%init>
3
4   $FS::Maketext::lh = '';
5
6   dbh->{'private_profile'} = {} if UNIVERSAL::can(dbh, 'sprintProfile');
7
8 </%init>
9 <%filter>
10
11 if ( UNIVERSAL::can(dbh, 'sprintProfile') ) {
12
13   my $profile = '';
14
15   if ( lc($r->content_type) =~ /^text\/html/
16        && $FS::CurrentUser::CurrentUser->option('show_db_profile')
17      )
18   {
19
20     ## barely worth it, just in case someone tries to use profiling on a
21     ## non-RT install
22     #eval "use Text::Wrapper;";
23     #die $@ if $@;
24
25     my $text = dbh->sprintProfile();
26     #$text =~ s/^/                                                          /mg;
27
28     $profile = '<PRE>'.  encode_entities( $text ). "\n\n". '</PRE>';
29
30   }
31
32   #well, could do this without sprintProfile, but definiately don't want it on
33   #unless DBIx::Profile is loaded
34   if ( $FS::CurrentUser::CurrentUser->option('save_db_profile') ) {
35     #my $file = %%%FREESIDE_LOG%%%; #substitute here?  maybe get from FS.pm?
36     my $file = '/usr/local/etc/freeside/'; #bah
37     $file .= "dbix_profile.$$.". time;
38     dbh->setLogFile($file);
39     dbh->printProfile();
40   }
41
42   dbh->{'private_profile'} = {};
43
44   s/(<\/BODY>[\s\n]*<\/HTML>[\s\n]*)/$profile$1/i;
45 }
46
47 </%filter>
48 <%cleanup>
49    dbh->commit() if dbh;
50 </%cleanup>