remove inline templates and replace with files in templates directory
[buildfarm-server.git] / cgi-bin / show_history.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use DBI;
5 use Template;
6 use CGI;
7
8 use vars qw($dbhost $dbname $dbuser $dbpass $dbport $template_dir);
9
10
11 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
12 #require "BuildFarmWeb.pl";
13
14 die "no dbname" unless $dbname;
15 die "no dbuser" unless $dbuser;
16
17 my $dsn="dbi:Pg:dbname=$dbname";
18 $dsn .= ";host=$dbhost" if $dbhost;
19 $dsn .= ";port=$dbport" if $dbport;
20
21 my $db = DBI->connect($dsn,$dbuser,$dbpass);
22
23 die $DBI::errstr unless $db;
24
25 my $query = new CGI;
26 my $member = $query->param('nm'); $member =~ s/[^a-zA-Z0-9_ -]//g;
27 my $branch = $query->param('br'); $branch =~ s/[^a-zA-Z0-9_ -]//g;
28 my $hm = $query->param('hm');  $hm =~ s/[^a-zA-Z0-9_ -]//g;
29 $hm = '240' unless $hm =~ /^\d+$/;
30
31 # we don't really need to do this join, since we only want
32 # one row from buildsystems. but it means we only have to run one
33 # query. If it gets heavy we'll split it up and run two
34
35 my $statement = <<EOS;
36
37   select (now() at time zone 'GMT')::timestamp(0) - snapshot as when_ago,
38       sysname, snapshot, b.status, stage,
39       operating_system, os_version, compiler, compiler_version, architecture,
40       owner_email
41   from buildsystems s, 
42        build_status b 
43   where name = ?
44         and branch = ?
45         and s.status = 'approved'
46         and name = sysname
47   order by snapshot desc
48   limit $hm
49
50 EOS
51 ;
52
53 my $statrows=[];
54 my $sth=$db->prepare($statement);
55 $sth->execute($member,$branch);
56 while (my $row = $sth->fetchrow_hashref)
57 {
58     $row->{owner_email} =~ s/\@/ [ a t ] /;
59         push(@$statrows,$row);
60 }
61 $sth->finish;
62
63 $db->disconnect;
64
65 my $template_opts = { INCLUDE_PATH => $template_dir, EVAL_PERL => 1 };
66 my $template = new Template($template_opts);
67
68 print "Content-Type: text/html\n\n";
69
70 $template->process('history.tt',
71                    {statrows=>$statrows, 
72                     branch=>$branch, 
73                     member => $member,
74                     hm => $hm
75                     });
76
77 exit;