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