]> git.sesse.net Git - ccbs/commitdiff
Add first beginnings of web control system.
authorSteinar H. Gunderson <sesse@samfundet.no>
Sun, 13 Feb 2005 23:45:00 +0000 (23:45 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Sun, 13 Feb 2005 23:45:00 +0000 (23:45 +0000)
html/.htaccess [new file with mode: 0644]
html/ccbs.css [new file with mode: 0644]
html/ccbs.pm [new file with mode: 0755]
html/index.pl [new file with mode: 0755]
html/templates/index.tmpl [new file with mode: 0644]
html/templates/main.tmpl [new file with mode: 0644]

diff --git a/html/.htaccess b/html/.htaccess
new file mode 100644 (file)
index 0000000..21623ec
--- /dev/null
@@ -0,0 +1 @@
+DirectoryIndex index.pl
diff --git a/html/ccbs.css b/html/ccbs.css
new file mode 100644 (file)
index 0000000..f3f8f6f
--- /dev/null
@@ -0,0 +1,80 @@
+body {
+       font-family: georgia, arial, sans-serif;
+       background-color: white;
+}
+* {
+/*     border: 1px solid black; */
+}
+.header {
+       margin-bottom: 1em;
+}
+.menu {
+       border-top: 1px solid gray;
+       border-bottom: 1px solid gray;
+       padding-top: 0.5em;
+       padding-bottom: 0.5em;
+       margin-bottom: 1em;
+       text-align: center;
+       background-color: rgb(161,206,222);
+}
+h1 img {
+       vertical-align: middle;
+       margin-left: 1em;
+       margin-right: 1em;
+}
+
+.main {
+       margin-left: 3em;
+}
+/* .main > div, but IE can't handle that :-/ */
+.main div {
+       border-left: 2px solid rgb(78,179,78);
+}
+.main div.msg, .main div.qotd {
+       border: 2px solid red;
+       background-color: rgb(161,206,222);
+       padding: 0.5em;
+       margin-bottom: 0.5em;
+}
+.msgfooter {
+       font-size: smaller;
+       text-align: right;
+}
+.msgfooter input { 
+       margin-left: 0.5em;
+}
+
+.main p, .main pre {
+       margin-left: 1em;
+}
+table {
+       border-collapse: collapse; 
+       background-color: white;
+       margin-left: 2em;
+       font-size: smaller;
+}
+th, td {
+       border: 1px solid black;
+       padding: 2px;
+}
+th { background-color: rgb(128,229,128); }
+tr.even td { background-color: #ffa; }
+tr.total { border-top: 2px solid black; }
+tr.own { border: 2px solid red; }
+
+a:link, a:hover, th a:link, th a:visited, th a:hover {
+       color: blue;
+}
+a:visited {
+       color: navy;
+}
+
+/* IE sucks! */
+tr.own td, tr.own th { border-top: 2px solid red; border-bottom: 2px solid red; }
+
+.footer {
+       padding-top: 0.5em;
+       margin-top: 1em;
+       font-size: x-small;
+       border-top: 1px solid gray;
+}
diff --git a/html/ccbs.pm b/html/ccbs.pm
new file mode 100755 (executable)
index 0000000..6080078
--- /dev/null
@@ -0,0 +1,81 @@
+package ccbs;
+use Template;
+use CGI;
+use DBI;
+use strict;
+use warnings;
+
+our $ccbs_dbdebug = 0;
+       
+sub print_header {
+       print CGI::header(-type=>'text/html; charset=utf-8');
+}
+
+sub db_connect {
+       $ccbs_dbdebug = defined(shift) ? 1 : 0;
+
+       my $dbh = DBI->connect("dbi:Pg:dbname=ccbs;host=sql.samfundet.no", "ccbsmmeligaen", "Noohos8h")
+               or die "Couldn't connect to database";
+       $dbh->{RaiseError} = 1;
+       return $dbh;
+}
+
+sub db_fetch_all {
+       my ($dbh, $sql, @parms) = @_;
+       my $q = $dbh->prepare($sql)
+               or die "Could not prepare query: " . $dbh->errstr;
+       $q->execute(@parms)
+               or die "Could not execute query: " . $dbh->errstr;
+
+       if ($ccbs_dbdebug) {
+               warn $sql;
+               warn "params=" . join(', ', @parms);
+       }
+       
+       my @ret = ();
+       while (my $ref = $q->fetchrow_hashref()) {
+               if ($ccbs_dbdebug) {
+                       my $dbstr = "";
+                       for my $k (sort keys %$ref) {
+                               $dbstr .= " " . $k . "=" . $ref->{$k};
+                       }
+                       warn $dbstr;
+               }
+               push @ret, $ref;
+       }
+
+       $q->finish;
+       return \@ret;
+}
+       
+sub process_template {
+       my ($page, $title, $vars) = @_;
+       $vars->{'page'} = $page;
+       $vars->{'title'} = $title;
+       
+       my $config = {
+               INCLUDE_PATH => 'templates/',
+               INTERPOLATE  => 1,
+               POST_CHOMP   => 1,
+               EVAL_PERL    => 1,
+       };
+       my $template = Template->new($config);
+
+       my $output = '';
+       $template->process('main.tmpl', $vars, \$output)
+               or die $template->error();
+
+       print $output;
+}
+
+$SIG{__DIE__} = sub {
+       # Gosh! Net::Resolver::DNS is brain-damaged.
+       my $msg = shift;
+       return if $msg =~ m#Win32/Registry.pm#;
+
+       ccbs::print_header();
+       ccbs::process_template('error.tmpl', 'Internal Server Error',
+               { message => $msg });
+};
+
+1;
diff --git a/html/index.pl b/html/index.pl
new file mode 100755 (executable)
index 0000000..76ec1e8
--- /dev/null
@@ -0,0 +1,8 @@
+#! /usr/bin/perl
+
+use ccbs;
+use strict;
+use warnings;
+
+ccbs::print_header();
+ccbs::process_template('index.tmpl', 'Forside');
diff --git a/html/templates/index.tmpl b/html/templates/index.tmpl
new file mode 100644 (file)
index 0000000..068631d
--- /dev/null
@@ -0,0 +1,4 @@
+[%# vim:set filetype=html: %]
+<div>
+  <p>Velkommen. Tomt foreløpig. :-)</p>
+</div>
diff --git a/html/templates/main.tmpl b/html/templates/main.tmpl
new file mode 100644 (file)
index 0000000..f9408ae
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+  "http://www.w3.org/TR/xhtml11/DTD/xhtml11-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="no">
+  <head>
+    <title>[% title %] - CCBS</title>
+    <link rel="stylesheet" type="text/css" href="ccbs.css" />
+  </head>
+  <body>
+    <h1>[% title %]</h1>
+
+    <div class="main">
+[% INCLUDE $page %]
+    </div>
+  </body>
+</html>