1 package PciIds::Notifications;
10 our @EXPORT = qw(¬ify &sendNotifs &flushNotifs);
13 my( $tables, $location, $comment, $priority, $reason ) = @_;
14 $tables->pushNotifications( $location, $comment, $priority, $reason );
17 sub sendNotif( $$$ ) {
18 my( $address, $message, $sendFun ) = @_;
19 return unless defined $address;
22 "Item change notifications for $config{hostname}",
23 "$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" );
27 my( $notifs, $sendFun ) = @_;
28 my( $last_address, $last_user );
30 foreach( @{$notifs} ) {
31 my( $user, $address, $reason, $text, $newname, $newdesc, $time, $author, $location, $name, $desc ) = @{$_};
32 if( ( !defined $last_user ) || ( $last_user != $user ) ) {
33 sendNotif( $last_address, $message, $sendFun );
34 $last_address = $address;
39 my $addr = PciIds::Address::new( $location );
41 $note = "New item was created.\n Id: ".$addr->pretty()."\n Name: $newname\n";
42 $note .= " Description: $newdesc\n" if( defined $newdesc && ( $newdesc ne '' ) );
43 $note .= " Comment text: $text\n" if( defined $text && ( $text ne '' ) );
44 $note .= " Author: $author\n" if( defined $author && ( $author ne '' ) );
45 $note .= " Time: $time\n";
46 $note .= " Address: http://".$config{'hostname'}."/read/".$addr->get()."\n";
47 } elsif( $reason == 1 ) {
48 $note = "New comment created.\n Item:\n";
49 $note .= " Id: ".$addr->pretty()."\n";
50 $note .= " Name: $name\n" if( defined $name && ( $name ne '' ) && ( $name ne $newname ) );
51 $note .= " Description: $desc\n" if( defined $desc && ( $desc ne '' ) && ( $desc ne $newdesc ) );
52 $note .= " Address: http://".$config{'hostname'}."/read/".$addr->get()."\n";
53 $note .= " Comment:\n";
54 $note .= " Proposed name: $newname\n" if( defined $newname && ( $newname ne '' ) );
55 $note .= " Deletion request\n" if defined $newname && $newname eq '';
56 $note .= " Proposed description: $newdesc\n" if( defined $newdesc && ( $newdesc ne '' ) );
57 $note .= " Text: $text\n" if( defined $text && ( $text ne '' ) );
58 $note .= " Author: $author\n" if( defined $author && ( $author ne '' ) );
59 $note .= " Time: $time\n";
60 } elsif( $reason == 2 ) {
62 $note = "Item name validated.\n Id:".$addr->pretty()."\n";
63 $note .= " Name: $newname\n";
64 $note .= " Description: $newdesc\n" if( defined $newdesc && ( $newdesc ne '' ) );
65 $note .= " Comment text: $text\n" if( defined $text && ( $text ne '' ) );
66 $note .= " Address: http://".$config{'hostname'}."/read/".$addr->get()."\n";
68 $note = "Item deletion validated.\n Id:".$addr->pretty()."\n";
69 $note .= " Address: http://".$config{'hostname'}."/read/".$addr->get()."\n";
72 $message .= "\n" unless $message eq '';
75 sendNotif( $last_address, $message, $sendFun );
80 my $time = $tables->time();
81 sendOut( $tables->mailNotifs( $time ), \&PciIds::Email::sendMail );
82 sendOut( $tables->xmppNotifs( $time ), \&PciIds::Xmpp::sendXmpp );
83 $tables->dropNotifs( $time );
86 checkConf( [ 'hostname' ] );