13 $start_time = [Time::HiRes::gettimeofday()];
16 our $ccbs_dbdebug = 0;
18 # Set this flag to disable any admin tasks -- it's quite crude, but hey :-)
19 our $ccbs_noadmin = 0;
22 print CGI::header(-type=>'text/html; charset=utf-8');
27 print CGI::header(-status=>'303 See other',
28 -location=>'http://ccbs.sesse.net/' . $location,
29 -type=>'text/html; charset=utf-8');
33 $ccbs_dbdebug = defined(shift) ? 1 : 0;
35 my $dbh = DBI->connect("dbi:Pg:dbname=ccbs;host=www.positivegaming.com", "ccbs", "GeT|>>B_")
36 or die "Couldn't connect to database";
37 $dbh->{RaiseError} = 1;
42 my ($dbh, $sql, @parms) = @_;
43 my $q = $dbh->prepare($sql)
44 or die "Could not prepare query: " . $dbh->errstr;
46 or die "Could not execute query: " . $dbh->errstr;
50 warn "params=" . join(', ', @parms);
54 while (my $ref = $q->fetchrow_hashref()) {
57 for my $k (sort keys %$ref) {
58 $dbstr .= " " . $k . "=" . $ref->{$k};
69 sub process_template {
70 my ($page, $title, $vars) = @_;
71 $vars->{'page'} = $page;
72 $vars->{'title'} = $title;
73 $vars->{'public'} = $ccbs_noadmin;
74 $vars->{'timetogenerate'} = sprintf "%.3f", Time::HiRes::tv_interval($start_time);
77 INCLUDE_PATH => 'templates/',
82 my $template = Template->new($config);
85 $template->process('main.tmpl', $vars, \$output)
86 or die $template->error();
95 ccbs::process_template('user-error.tmpl', 'Feil',
101 user_error("Beklager, databasen står i no-admin-mode.") if ($ccbs_noadmin);
104 $SIG{__DIE__} = sub {
105 # Gosh! Net::Resolver::DNS is brain-damaged.
107 return if $msg =~ m#Win32/Registry.pm#;
109 ccbs::print_header();
110 ccbs::process_template('error.tmpl', 'Internal Server Error',
111 { message => HTML::Entities::encode_entities($msg) });