Release for 3.2.0. Changes since 3.2.0beta1:
[BackupPC.git] / lib / BackupPC / CGI / EmailSummary.pm
1 #============================================================= -*-perl-*-
2 #
3 # BackupPC::CGI::EmailSummary package
4 #
5 # DESCRIPTION
6 #
7 #   This module implements the EmailSummary action for the CGI interface.
8 #
9 # AUTHOR
10 #   Craig Barratt  <cbarratt@users.sourceforge.net>
11 #
12 # COPYRIGHT
13 #   Copyright (C) 2003-2009  Craig Barratt
14 #
15 #   This program is free software; you can redistribute it and/or modify
16 #   it under the terms of the GNU General Public License as published by
17 #   the Free Software Foundation; either version 2 of the License, or
18 #   (at your option) any later version.
19 #
20 #   This program is distributed in the hope that it will be useful,
21 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
22 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 #   GNU General Public License for more details.
24 #
25 #   You should have received a copy of the GNU General Public License
26 #   along with this program; if not, write to the Free Software
27 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28 #
29 #========================================================================
30 #
31 # Version 3.2.0, released 31 Jul 2010.
32 #
33 # See http://backuppc.sourceforge.net.
34 #
35 #========================================================================
36
37 package BackupPC::CGI::EmailSummary;
38
39 use strict;
40 use BackupPC::CGI::Lib qw(:all);
41
42 sub action
43 {
44     my $Privileged = CheckPermission();
45
46     if ( !$Privileged ) {
47         ErrorExit($Lang->{Only_privileged_users_can_view_email_summaries});
48     }
49     GetStatusInfo("hosts");
50     ReadUserEmailInfo();
51     my(%EmailStr, $str);
52     foreach my $u ( keys(%UserEmailInfo) ) {
53         my $info;
54         if ( defined($UserEmailInfo{$u}{lastTime})
55                 && ref($UserEmailInfo{$u}{lastTime}) ne 'HASH' ) {
56             #
57             # old format $UserEmailInfo - pre 3.2.0.
58             #
59             my $host = $UserEmailInfo{$u}{lastHost};
60             $info = {
61                 $host => {
62                     lastTime => $UserEmailInfo{$u}{lastTime},
63                     lastSubj => $UserEmailInfo{$u}{lastSubj},
64                 },
65             };
66         } else {
67             $info = $UserEmailInfo{$u};
68         }
69         foreach my $host ( keys(%$info) ) {
70             next if ( !defined($info->{$host}{lastTime}) );
71             my $emailTimeStr = timeStamp2($info->{$host}{lastTime});
72             $EmailStr{$info->{$host}{lastTime}} .= <<EOF;
73 <tr><td>${UserLink($u)} </td>
74     <td>${HostLink($host)} </td>
75     <td>$emailTimeStr </td>
76     <td>$info->{$host}{lastSubj} </td></tr>
77 EOF
78         }
79     }
80     foreach my $t ( sort({$b <=> $a} keys(%EmailStr)) ) {
81         $str .= $EmailStr{$t};
82     }
83     my $content = eval("qq{$Lang->{Recent_Email_Summary}}");
84     Header($Lang->{Email_Summary}, $content);
85     Trailer();
86 }
87
88 1;