/usr/share/otrs/Kernel/System/StandardTemplate.pm is in otrs2 6.0.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 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | # --
# Copyright (C) 2001-2018 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::StandardTemplate;
use strict;
use warnings;
our @ObjectDependencies = (
'Kernel::System::Cache',
'Kernel::System::DB',
'Kernel::System::Log',
'Kernel::System::Valid',
);
=head1 NAME
Kernel::System::StandardTemplate - standard template lib
=head1 DESCRIPTION
All standard template functions. E. g. to add standard template or other functions.
=head1 PUBLIC INTERFACE
=head2 new()
create an object
my $StandardTemplateObject = $Kernel::OM->Get('Kernel::System::StandardTemplate');
=cut
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
return $Self;
}
=head2 StandardTemplateAdd()
add new standard template
my $ID = $StandardTemplateObject->StandardTemplateAdd(
Name => 'New Standard Template',
Template => 'Thank you for your email.',
ContentType => 'text/plain; charset=utf-8',
TemplateType => 'Answer', # or 'Forward' or 'Create'
ValidID => 1,
UserID => 123,
);
=cut
sub StandardTemplateAdd {
my ( $Self, %Param ) = @_;
# check needed stuff
for (qw(Name ValidID Template ContentType UserID TemplateType)) {
if ( !defined( $Param{$_} ) ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $_!"
);
return;
}
}
# check if a standard template with this name already exists
if ( $Self->NameExistsCheck( Name => $Param{Name} ) ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "A standard template with the name '$Param{Name}' already exists.",
);
return;
}
# get database object
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
# sql
return if !$DBObject->Do(
SQL => '
INSERT INTO standard_template (name, valid_id, comments, text,
content_type, create_time, create_by, change_time, change_by, template_type)
VALUES (?, ?, ?, ?, ?, current_timestamp, ?, current_timestamp, ?, ?)',
Bind => [
\$Param{Name}, \$Param{ValidID}, \$Param{Comment}, \$Param{Template},
\$Param{ContentType}, \$Param{UserID}, \$Param{UserID}, \$Param{TemplateType},
],
);
return if !$DBObject->Prepare(
SQL => 'SELECT id FROM standard_template WHERE name = ? AND change_by = ?',
Bind => [ \$Param{Name}, \$Param{UserID}, ],
);
my $ID;
while ( my @Row = $DBObject->FetchrowArray() ) {
$ID = $Row[0];
}
# clear queue cache, due to Queue <-> Template relations
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
Type => 'Queue',
);
return $ID;
}
=head2 StandardTemplateGet()
get standard template attributes
my %StandardTemplate = $StandardTemplateObject->StandardTemplateGet(
ID => 123,
);
Returns:
%StandardTemplate = (
ID => '123',
Name => 'Simple remplate',
Comment => 'Some comment',
Template => 'Template content',
ContentType => 'text/plain',
TemplateType => 'Answer',
ValidID => '1',
CreateTime => '2010-04-07 15:41:15',
CreateBy => '321',
ChangeTime => '2010-04-07 15:59:45',
ChangeBy => '223',
);
=cut
sub StandardTemplateGet {
my ( $Self, %Param ) = @_;
# check needed stuff
if ( !$Param{ID} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => 'Need ID!'
);
return;
}
# get database object
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
# sql
return if !$DBObject->Prepare(
SQL => '
SELECT name, valid_id, comments, text, content_type, create_time, create_by,
change_time, change_by ,template_type
FROM standard_template
WHERE id = ?',
Bind => [ \$Param{ID} ],
);
my %Data;
while ( my @Data = $DBObject->FetchrowArray() ) {
%Data = (
ID => $Param{ID},
Name => $Data[0],
Comment => $Data[2],
Template => $Data[3],
ContentType => $Data[4] || 'text/plain',
ValidID => $Data[1],
CreateTime => $Data[5],
CreateBy => $Data[6],
ChangeTime => $Data[7],
ChangeBy => $Data[8],
TemplateType => $Data[9],
);
}
return %Data;
}
=head2 StandardTemplateDelete()
delete a standard template
$StandardTemplateObject->StandardTemplateDelete(
ID => 123,
);
=cut
sub StandardTemplateDelete {
my ( $Self, %Param ) = @_;
# check needed stuff
if ( !$Param{ID} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => 'Need ID!'
);
return;
}
# get database object
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
# delete queue<->std template relation
return if !$DBObject->Do(
SQL => 'DELETE FROM queue_standard_template WHERE standard_template_id = ?',
Bind => [ \$Param{ID} ],
);
# delete attachment<->std template relation
return if !$DBObject->Do(
SQL => 'DELETE FROM standard_template_attachment WHERE standard_template_id = ?',
Bind => [ \$Param{ID} ],
);
# sql
return if !$DBObject->Do(
SQL => 'DELETE FROM standard_template WHERE id = ?',
Bind => [ \$Param{ID} ],
);
# clear queue cache, due to Queue <-> Template relations
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
Type => 'Queue',
);
return 1;
}
=head2 StandardTemplateUpdate()
update standard template attributes
$StandardTemplateObject->StandardTemplateUpdate(
ID => 123,
Name => 'New Standard Template',
Template => 'Thank you for your email.',
ContentType => 'text/plain; charset=utf-8',
TemplateType => 'Answer',
ValidID => 1,
UserID => 123,
);
=cut
sub StandardTemplateUpdate {
my ( $Self, %Param ) = @_;
# check needed stuff
for (qw(ID Name ValidID TemplateType ContentType UserID TemplateType)) {
if ( !defined( $Param{$_} ) ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Need $_!"
);
return;
}
}
# check if a standard template with this name already exists
if (
$Self->NameExistsCheck(
Name => $Param{Name},
ID => $Param{ID}
)
)
{
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "A standard template with the name '$Param{Name}' already exists.",
);
return;
}
# sql
return if !$Kernel::OM->Get('Kernel::System::DB')->Do(
SQL => '
UPDATE standard_template
SET name = ?, text = ?, content_type = ?, comments = ?, valid_id = ?,
change_time = current_timestamp, change_by = ? ,template_type = ?
WHERE id = ?',
Bind => [
\$Param{Name}, \$Param{Template}, \$Param{ContentType}, \$Param{Comment},
\$Param{ValidID}, \$Param{UserID}, \$Param{TemplateType}, \$Param{ID},
],
);
# clear queue cache, due to Queue <-> Template relations
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
Type => 'Queue',
);
return 1;
}
=head2 StandardTemplateLookup()
return the name or the standard template id
my $StandardTemplateName = $StandardTemplateObject->StandardTemplateLookup(
StandardTemplateID => 123,
);
or
my $StandardTemplateID = $StandardTemplateObject->StandardTemplateLookup(
StandardTemplate => 'Std Template Name',
);
=cut
sub StandardTemplateLookup {
my ( $Self, %Param ) = @_;
# check needed stuff
if ( !$Param{StandardTemplate} && !$Param{StandardTemplateID} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => 'Got no StandardTemplate or StandardTemplateID!'
);
return;
}
# check if we ask the same request?
if ( $Param{StandardTemplateID} && $Self->{"StandardTemplateLookup$Param{StandardTemplateID}"} )
{
return $Self->{"StandardTemplateLookup$Param{StandardTemplateID}"};
}
if ( $Param{StandardTemplate} && $Self->{"StandardTemplateLookup$Param{StandardTemplate}"} ) {
return $Self->{"StandardTemplateLookup$Param{StandardTemplate}"};
}
# get data
my $SQL;
my $Suffix;
my @Bind;
if ( $Param{StandardTemplate} ) {
$Suffix = 'StandardTemplateID';
$SQL = 'SELECT id FROM standard_template WHERE name = ?';
@Bind = ( \$Param{StandardTemplate} );
}
else {
$Suffix = 'StandardTemplate';
$SQL = 'SELECT name FROM standard_template WHERE id = ?';
@Bind = ( \$Param{StandardTemplateID} );
}
# get database object
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
return if !$DBObject->Prepare(
SQL => $SQL,
Bind => \@Bind,
);
while ( my @Row = $DBObject->FetchrowArray() ) {
# store result
$Self->{"StandardTemplate$Suffix"} = $Row[0];
}
# check if data exists
if ( !exists $Self->{"StandardTemplate$Suffix"} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Found no \$$Suffix!"
);
return;
}
return $Self->{"StandardTemplate$Suffix"};
}
=head2 StandardTemplateList()
get all valid standard templates
my %StandardTemplates = $StandardTemplatesObject->StandardTemplateList();
Returns:
%StandardTemplates = (
1 => 'Some Name',
2 => 'Some Name2',
3 => 'Some Name3',
);
get all standard templates
my %StandardTemplates = $StandardTemplateObject->StandardTemplateList(
Valid => 0,
);
Returns:
%StandardTemplates = (
1 => 'Some Name',
2 => 'Some Name2',
);
get standard templates from a certain type
my %StandardTemplates = $StandardTemplateObject->StandardTemplateList(
Valid => 0,
Type => 'Answer',
);
Returns:
%StandardTemplates = (
1 => 'Answer - Some Name',
);
=cut
sub StandardTemplateList {
my ( $Self, %Param ) = @_;
my $Valid = 1;
if ( defined $Param{Valid} && $Param{Valid} eq '0' ) {
$Valid = 0;
}
my $SQL = '
SELECT id, name
FROM standard_template';
if ($Valid) {
$SQL .= ' WHERE valid_id IN (' . join ', ',
$Kernel::OM->Get('Kernel::System::Valid')->ValidIDsGet() . ')';
}
my @Bind;
if ( defined $Param{Type} && $Param{Type} ne '' ) {
if ($Valid) {
$SQL .= ' AND';
}
else {
$SQL .= ' WHERE';
}
$SQL .= ' template_type = ?';
push @Bind, \$Param{Type};
}
# get database object
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
return if !$DBObject->Prepare(
SQL => $SQL,
Bind => \@Bind,
);
my %Data;
while ( my @Row = $DBObject->FetchrowArray() ) {
$Data{ $Row[0] } = $Row[1];
}
return %Data;
}
=head2 NameExistsCheck()
return 1 if another standard template with this name already exists
$Exist = $StandardTemplateObject->NameExistsCheck(
Name => 'Some::Template',
ID => 1, # optional
);
=cut
sub NameExistsCheck {
my ( $Self, %Param ) = @_;
# get database object
my $DBObject = $Kernel::OM->Get('Kernel::System::DB');
return if !$DBObject->Prepare(
SQL => 'SELECT id FROM standard_template WHERE name = ?',
Bind => [ \$Param{Name} ],
);
# fetch the result
my $Flag;
while ( my @Row = $DBObject->FetchrowArray() ) {
if ( !$Param{ID} || $Param{ID} ne $Row[0] ) {
$Flag = 1;
}
}
if ($Flag) {
return 1;
}
return 0;
}
1;
=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
|