3bc733c5a2127300094dffa4970b25679125b2f8
[buildfarm-server.git] / trunk / cgi-bin / show_members.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5 use DBI;
6 use Template;
7
8
9
10 use vars qw($dbhost $dbname $dbuser $dbpass $dbport $template_dir $sort_by);
11
12
13 require "$ENV{BFConfDir}/BuildFarmWeb.pl";
14 #require "BuildFarmWeb.pl";
15
16 my $query = new CGI;
17 my %sort_ok = ('name' => 'lower(name)' , 
18                'owner' => 'lower(owner_email)', 
19                'os' => 'lower(operating_system), os_version', 
20                'compiler' => 'lower(compiler), compiler_version' ,
21                'arch' => 'lower(architecture)' );
22 $sort_by = $query->param('sort_by');$sort_by =~ s/[^a-zA-Z0-9_ -]//g;
23 $sort_by = $sort_ok{$sort_by} || $sort_ok{name};
24
25 my $dsn="dbi:Pg:dbname=$dbname";
26 $dsn .= ";host=$dbhost" if $dbhost;
27 $dsn .= ";port=$dbport" if $dbport;
28
29 my $db = DBI->connect($dsn,$dbuser,$dbpass);
30
31 # there is possibly some redundancy in this query, but it makes
32 # a lot of the processing simpler.
33
34 my $statement = q{
35
36   select name, operating_system, os_version, compiler, compiler_version, owner_email, 
37     sys_notes_ts::date AS sys_notes_date, sys_notes,
38     architecture as arch, ARRAY(
39                                 select branch || ':' || 
40                                        extract(days from now() - l.snapshot)
41                                 from latest_snapshot l 
42                                 where l.sysname = s.name
43                                 order by branch <> 'HEAD', branch desc 
44                                 ) as branches, 
45                           ARRAY(select compiler_version || '\t' ||  os_version || '\t' || effective_date
46                                 from personality p
47                                 where p.name = s.name 
48                                 order by effective_date
49                                 ) as personalities
50   from buildsystems s
51   where status = 'approved'
52 };
53
54 $statement .= "order by $sort_by";
55
56 my $statrows=[];
57 my $sth=$db->prepare($statement);
58 $sth->execute;
59 while (my $row = $sth->fetchrow_hashref)
60 {
61     $row->{branches} =~ s/^\{(.*)\}$/$1/;
62     my $personalities = $row->{personalities};
63     $personalities =~ s/^\{(.*)\}$/$1/;
64     my @personalities = split(',',$personalities);
65     $row->{personalities} = [];
66     foreach my $personality (@personalities)
67     {
68         $personality =~ s/^"(.*)"$/$1/;
69         $personality =~ s/\\(.)/$1/g;
70         
71         my ($compiler_version, $os_version, $effective_date) = split(/\t/,$personality);
72         $effective_date =~ s/ .*//;
73         push(@{$row->{personalities}}, {compiler_version => $compiler_version, 
74                                         os_version => $os_version, 
75                                         effective_date => $effective_date });
76     }
77     $row->{owner_email} =~ s/\@/ [ a t ] /;
78     push(@$statrows,$row);
79 }
80 $sth->finish;
81
82
83 $db->disconnect;
84
85 # use Data::Dumper; print "Content-Type: text/plain\n\n",Dumper($statrows),"VERSION: ",$DBD::Pg::VERSION,"\n"; exit;
86
87
88 my $template_opts = { INCLUDE_PATH => $template_dir};
89 my $template = new Template($template_opts);
90
91 print "Content-Type: text/html\n\n";
92
93 $template->process('members.tt',
94                 {statrows=>$statrows});
95
96 exit;
97