/usr/share/otrs/Kernel/System/Notification.pm is in otrs2 3.3.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | # --
# Kernel/System/Notification.pm - lib for notifications
# Copyright (C) 2001-2014 OTRS AG, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
package Kernel::System::Notification;
use strict;
use warnings;
=head1 NAME
Kernel::System::Notification - notification functions
=head1 SYNOPSIS
This module is managing notifications.
=head1 PUBLIC INTERFACE
=over 4
=cut
=item new()
create a notification object
use Kernel::Config;
use Kernel::System::Encode;
use Kernel::System::Log;
use Kernel::System::Main;
use Kernel::System::DB;
use Kernel::System::Notification;
my $ConfigObject = Kernel::Config->new();
my $EncodeObject = Kernel::System::Encode->new(
ConfigObject => $ConfigObject,
);
my $LogObject = Kernel::System::Log->new(
ConfigObject => $ConfigObject,
EncodeObject => $EncodeObject,
);
my $MainObject = Kernel::System::Main->new(
ConfigObject => $ConfigObject,
EncodeObject => $EncodeObject,
LogObject => $LogObject,
);
my $DBObject = Kernel::System::DB->new(
ConfigObject => $ConfigObject,
EncodeObject => $EncodeObject,
LogObject => $LogObject,
MainObject => $MainObject,
);
my $NotificationObject = Kernel::System::Notification->new(
EncodeObject => $EncodeObject,
ConfigObject => $ConfigObject,
LogObject => $LogObject,
MainObject => $MainObject,
DBObject => $DBObject,
);
=cut
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
# get needed objects
for (qw(ConfigObject LogObject DBObject EncodeObject)) {
die "Got no $_!" if !$Param{$_};
$Self->{$_} = $Param{$_};
}
return $Self;
}
=item NotificationGet()
get notification attributes
my %Notification = $NotificationObject->NotificationGet(
Name => 'de::NewTicket',
);
=cut
sub NotificationGet {
my ( $Self, %Param ) = @_;
# check needed stuff
if ( !$Param{Name} ) {
$Self->{LogObject}->Log( Priority => 'error', Message => 'Need Name!' );
return;
}
my ( $Language, $Type ) = $Param{Name} =~ m{^(.+?)::(.*)}smx;
$Self->{DBObject}->Prepare(
SQL => 'SELECT id, notification_type, notification_charset, '
. ' notification_language, subject, text, content_type '
. ' FROM notifications WHERE '
. ' notification_type = ? AND notification_language = ?',
Bind => [ \$Type, \$Language, ],
Limit => 1,
);
my %Data;
while ( my @Data = $Self->{DBObject}->FetchrowArray() ) {
# convert body
$Data[5] = $Self->{EncodeObject}->Convert(
Text => $Data[5],
From => $Data[2],
To => 'utf-8',
Force => 1,
);
# convert subject
$Data[3] = $Self->{EncodeObject}->Convert(
Text => $Data[3],
From => $Data[2],
To => 'utf-8',
Force => 1,
);
# set new charset
$Data[2] = 'utf-8';
# fix some bad stuff from some browsers (Opera)!
$Data[5] =~ s/(\n\r|\r\r\n|\r\n|\r)/\n/g;
%Data = (
Type => $Data[1],
Charset => $Data[2],
Language => $Data[3],
Subject => $Data[4],
Body => $Data[5],
ContentType => $Data[6] || 'text/plain',
);
}
if ( !%Data && !$Param{Loop} ) {
return $Self->NotificationGet(
%Param,
Name => 'en::' . $Type,
Loop => $Language,
);
}
elsif ( !%Data && $Param{Loop} ) {
$Self->{LogObject}->Log(
Priority => 'error',
Message => "Can't find notification for $Type and $Language!",
);
return;
}
return ( %Data, Language => $Param{Loop} || $Language );
}
=item NotificationList()
get notification list
my %List = $NotificationObject->NotificationList();
=cut
sub NotificationList {
my ( $Self, %Param ) = @_;
# sql
return if !$Self->{DBObject}->Prepare(
SQL => 'SELECT id, notification_type, notification_charset, '
. ' notification_language FROM notifications',
);
# get languages
my %Languages = %{ $Self->{ConfigObject}->{DefaultUsedLanguages} };
# get possible notification types
my %Types;
while ( my @Data = $Self->{DBObject}->FetchrowArray() ) {
# do not use customer notifications this way anymore (done by notification event now)
next if $Data[1] =~ /Customer::(Owner|Queue|State)Update/;
$Types{ $Data[1] } = 1;
}
for (qw(NewTicket FollowUp LockTimeout OwnerUpdate AddNote Move PendingReminder Escalation)) {
$Types{ 'Agent::' . $_ } = 1;
}
# create list
my %List;
for my $Language ( sort keys %Languages ) {
for my $Type ( sort keys %Types ) {
$List{ $Language . '::' . $Type } = $Language . '::' . $Type;
}
}
# get real list
return if !$Self->{DBObject}->Prepare(
SQL => 'SELECT id, notification_type, notification_charset, '
. ' notification_language FROM notifications',
);
while ( my @Data = $Self->{DBObject}->FetchrowArray() ) {
# do not use customer notifications this way anymore (done by notification event now)
next if $Data[1] =~ /Customer::(Owner|Queue|State)Update/;
# remember list
$List{ $Data[3] . '::' . $Data[1] } = $Data[3] . '::' . $Data[1];
}
return %List;
}
=item NotificationUpdate()
update notification attributes
$NotificationObject->NotificationUpdate(
Type => 'NewTicket',
Charset => 'utf-8',
Language => 'en',
Subject => 'Some Subject with <OTRS_TAGS>',
Body => 'Some Body with <OTRS_TAGS>',
ContentType => 'text/plain',
UserID => 123,
);
=cut
sub NotificationUpdate {
my ( $Self, %Param ) = @_;
# check needed stuff
for (qw(Type Charset Language Subject Body ContentType UserID)) {
if ( !defined( $Param{$_} ) ) {
$Self->{LogObject}->Log( Priority => 'error', Message => "Need $_!" );
return;
}
}
# fix some bad stuff from some browsers (Opera)!
$Param{Body} =~ s/(\n\r|\r\r\n|\r\n|\r)/\n/g;
# sql
$Self->{DBObject}->Do(
SQL => 'DELETE FROM notifications WHERE notification_type = ? '
. 'AND notification_language = ?',
Bind => [
\$Param{Type}, \$Param{Language},
],
);
# sql
return if !$Self->{DBObject}->Prepare(
SQL => 'INSERT INTO notifications '
. '(notification_type, notification_charset, notification_language, subject, text, '
. 'content_type, create_time, create_by, change_time, change_by) '
. 'VALUES (?, ?, ?, ?, ?, ?, current_timestamp, ?, current_timestamp, ?)',
Bind => [
\$Param{Type}, \$Param{Charset}, \$Param{Language}, \$Param{Subject},
\$Param{Body}, \$Param{ContentType}, \$Param{UserID}, \$Param{UserID},
],
);
return 1;
}
1;
=back
=head1 TERMS AND CONDITIONS
This software is part of the OTRS project (L<http://otrs.org/>).
This software comes with ABSOLUTELY NO WARRANTY. For details, see
the enclosed file COPYING for license information (AGPL). If you
did not receive this file, see L<http://www.gnu.org/licenses/agpl.txt>.
=cut
|