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