2 # Copyright (C) 2008 Michal Vaner (vorner@ucw.cz)
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # he Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 package PciIds::Notifications;
28 our @EXPORT = qw(¬ify &sendNotifs &flushNotifs);
31 my( $tables, $location, $comment, $priority, $reason ) = @_;
32 $tables->pushNotifications( $location, $comment, $priority, $reason );
35 sub sendNotif( $$$ ) {
36 my( $address, $message, $sendFun ) = @_;
37 return unless defined $address;
40 "Item change notifications for $config{hostname}",
41 "$message\nThis is automatic notification message, do not respond to it.\nYou can change your notifications at http://$config{hostname}/mods/PC/?action=notifications\n" );
45 my( $notifs, $sendFun ) = @_;
46 my( $last_address, $last_user );
48 foreach( @{$notifs} ) {
49 my( $user, $address, $reason, $text, $newname, $newdesc, $time, $author, $location, $name, $desc ) = @{$_};
50 if( ( !defined $last_user ) || ( $last_user != $user ) ) {
51 sendNotif( $last_address, $message, $sendFun );
52 $last_address = $address;
57 my $addr = PciIds::Address::new( $location );
59 $note = "New item was created.\n Id: ".$addr->pretty()."\n Name: $newname\n";
60 $note .= " Description: $newdesc\n" if( defined $newdesc && ( $newdesc ne '' ) );
61 $note .= " Comment text: $text\n" if( defined $text && ( $text ne '' ) );
62 $note .= " Author: $author\n" if( defined $author && ( $author ne '' ) );
63 $note .= " Time: $time\n";
64 $note .= " Address: http://".$config{'hostname'}."/read/".$addr->get()."\n";
65 } elsif( $reason == 1 ) {
66 $note = "New comment created.\n Item:\n";
67 $note .= " Id: ".$addr->pretty()."\n";
68 $note .= " Name: $name\n" if( defined $name && ( $name ne '' ) && ( ( !defined $newname ) || ( $name ne $newname ) ) );
69 $note .= " Description: $desc\n" if( defined $desc && ( $desc ne '' ) && ( ( !defined $newdesc ) || ( $desc ne $newdesc ) ) );
70 $note .= " Address: http://".$config{'hostname'}."/read/".$addr->get()."\n";
71 $note .= " Comment:\n";
72 $note .= " Proposed name: $newname\n" if( defined $newname && ( $newname ne '' ) );
73 $note .= " Deletion request\n" if defined $newname && $newname eq '';
74 $note .= " Proposed description: $newdesc\n" if( defined $newdesc && ( $newdesc ne '' ) );
75 $note .= " Text: $text\n" if( defined $text && ( $text ne '' ) );
76 $note .= " Author: $author\n" if( defined $author && ( $author ne '' ) );
77 $note .= " Time: $time\n";
78 } elsif( $reason == 2 ) {
80 $note = "Item name approved.\n Id: ".$addr->pretty()."\n";
81 $note .= " Name: $newname\n";
82 $note .= " Description: $newdesc\n" if( defined $newdesc && ( $newdesc ne '' ) );
83 $note .= " Comment text: $text\n" if( defined $text && ( $text ne '' ) );
84 $note .= " Address: http://".$config{'hostname'}."/read/".$addr->get()."\n";
86 $note = "Item deletion approved.\n Id: ".$addr->pretty()."\n";
87 $note .= " Address: http://".$config{'hostname'}."/read/".$addr->get()."\n";
90 $message .= "\n" unless $message eq '';
93 sendNotif( $last_address, $message, $sendFun );
98 my $time = $tables->time();
99 sendOut( $tables->mailNotifs( $time ), \&PciIds::Email::sendMail );
100 sendOut( $tables->xmppNotifs( $time ), \&PciIds::Xmpp::sendXmpp );
101 $tables->dropNotifs( $time );
104 checkConf( [ 'hostname' ] );