12 require '../intl/Sesse::GettextizeTemplates.pm';
14 require '../config.pm';
15 -r '../config.local.pm' and require '../config.local.pm';
17 # Check for language settings
18 my %cookies = fetch CGI::Cookie;
19 my $lang = defined($cookies{'language'}) ? $cookies{'language'}->value : undef;
20 if (defined($lang) && ($lang eq 'nb_NO' || $lang eq 'nn_NO' || $lang eq 'en_US')) {
21 POSIX::setlocale( &POSIX::LC_CTYPE , $lang . ".UTF-8" );
22 POSIX::setlocale( &POSIX::LC_MESSAGES , $lang . ".UTF-8" );
24 POSIX::setlocale( &POSIX::LC_CTYPE , $ccbs::config::lang );
25 POSIX::setlocale( &POSIX::LC_MESSAGES , $ccbs::config::lang );
27 Locale::gettext::bindtextdomain("ccbs", "po");
28 Locale::gettext::textdomain("ccbs");
33 $start_time = [Time::HiRes::gettimeofday()];
36 # Hack to get the non-templatized gettext stuff working
38 return Locale::gettext::gettext(@_);
42 print CGI::header(-type=>'text/html; charset=utf-8');
47 print CGI::header(-status=>'303 See other',
48 -location=>$ccbs::config::webroot . $location,
49 -type=>'text/html; charset=utf-8');
53 my $dbh = DBI->connect("dbi:Pg:dbname=$ccbs::config::dbname;host=$ccbs::config::dbhost", $ccbs::config::dbuser, $ccbs::config::dbpass)
54 or die "Couldn't connect to database";
55 $dbh->{RaiseError} = 1;
60 my ($dbh, $sql, @parms) = @_;
61 my $q = $dbh->prepare($sql)
62 or die "Could not prepare query: " . $dbh->errstr;
64 or die "Could not execute query: " . $dbh->errstr;
66 if ($config::ccbs::dbdebug) {
68 warn "params=" . join(', ', @parms);
72 while (my $ref = $q->fetchrow_hashref()) {
73 if ($config::ccbs::dbdebug) {
75 for my $k (sort keys %$ref) {
76 $dbstr .= " " . $k . "=" . $ref->{$k};
87 sub process_template {
88 my ($page, $title, $vars) = @_;
89 $vars->{'page'} = $page;
90 $vars->{'title'} = $title;
91 $vars->{'public'} = $ccbs::config::noadmin;
92 $vars->{'timetogenerate'} = sprintf "%.3f", Time::HiRes::tv_interval($start_time);
95 INCLUDE_PATH => 'templates/',
99 FACTORY => 'Sesse::GettextizeTemplates'
101 my $template = Template->new($config);
104 $template->process($ccbs::config::main_template, $vars, \$output)
105 or die $template->error();
113 ccbs::print_header();
114 ccbs::process_template('user-error.tmpl', _('Error'),
115 { message => $msg });
120 user_error(_("Sorry, the database is in no-admin-mode.")) if ($config::ccbs::noadmin);
123 $SIG{__DIE__} = sub {
124 # Gosh! Net::Resolver::DNS is brain-damaged.
126 return if $msg =~ m#Win32/Registry.pm#;
128 ccbs::print_header();
129 ccbs::process_template('error.tmpl', _('Internal Server Error'),
130 { message => HTML::Entities::encode_entities($msg) });