~ubuntu-branches/ubuntu/natty/otrs2/natty-updates

« back to all changes in this revision

Viewing changes to Kernel/System/Ticket/Article.pm

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2007-04-14 17:58:55 UTC
  • mto: (20.1.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: package-import@ubuntu.com-20070414175855-9ne0w01yu1q44ch0
Tags: upstream-2.1.7
ImportĀ upstreamĀ versionĀ 2.1.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# --
2
2
# Kernel/System/Ticket/Article.pm - global article module for OTRS kernel
3
 
# Copyright (C) 2001-2005 Martin Edenhofer <martin+code@otrs.org>
 
3
# Copyright (C) 2001-2007 OTRS GmbH, http://otrs.org/
4
4
# --
5
 
# $Id: Article.pm,v 1.94 2005/10/31 10:07:03 martin Exp $
 
5
# $Id: Article.pm,v 1.128.2.4 2007/03/02 01:19:21 martin Exp $
6
6
# --
7
7
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
8
8
# the enclosed file COPYING for license information (GPL). If you
18
18
use Kernel::System::StdAttachment;
19
19
 
20
20
use vars qw($VERSION);
21
 
$VERSION = '$Revision: 1.94 $';
 
21
$VERSION = '$Revision: 1.128.2.4 $';
22
22
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;
23
23
 
24
24
=head1 NAME
64
64
sub ArticleCreate {
65
65
    my $Self = shift;
66
66
    my %Param = @_;
67
 
    my $ValidID         = $Param{ValidID} || 1;
68
 
    my $IncomingTime    = $Self->{TimeObject}->SystemTime();
 
67
    my $ValidID = $Param{ValidID} || 1;
 
68
    my $IncomingTime = $Self->{TimeObject}->SystemTime();
69
69
    # create ArticleContentPath
70
70
    if (!$Self->{ArticleContentPath}) {
71
71
        $Self->{LogObject}->Log(Priority => 'error', Message => "Need ArticleContentPath!");
80
80
    }
81
81
    # check needed stuff
82
82
    foreach (qw(TicketID UserID ArticleTypeID SenderTypeID HistoryType HistoryComment)) {
83
 
      if (!$Param{$_}) {
84
 
        $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
85
 
        return;
86
 
      }
 
83
        if (!$Param{$_}) {
 
84
            $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
 
85
            return;
 
86
        }
87
87
    }
88
 
    # add 'no body found!' if there is no body there!
 
88
    # add 'no body' if there is no body there!
89
89
    if (!$Param{Body}) {
90
 
        $Param{Body} = 'no body found!';
 
90
        $Param{Body} = 'No body';
91
91
    }
92
92
    # if body isn't text, attach body as attachment (mostly done by OE) :-/
93
93
    elsif ($Param{ContentType} && $Param{ContentType} !~ /\btext\b/i) {
125
125
    }
126
126
    # do db insert
127
127
    my $SQL = "INSERT INTO article ".
128
 
      " (ticket_id, article_type_id, article_sender_type_id, a_from, a_reply_to, a_to, " .
129
 
      " a_cc, a_subject, a_message_id, a_body, a_content_type, content_path, ".
130
 
      " valid_id, incoming_time,  create_time, create_by, change_time, change_by) " .
131
 
      " VALUES ".
132
 
      " ($DBParam{TicketID}, $DBParam{ArticleTypeID}, $DBParam{SenderTypeID}, ".
133
 
      " '$DBParam{From}', '$DBParam{ReplyTo}', '$DBParam{To}', '$DBParam{Cc}', ".
134
 
      " '$DBParam{Subject}', ".
135
 
      " '$DBParam{MessageID}', ?, '$DBParam{ContentType}', ?, ".
136
 
      " $ValidID,  $IncomingTime, " .
137
 
      " current_timestamp, $DBParam{UserID}, current_timestamp, $DBParam{UserID})";
 
128
        " (ticket_id, article_type_id, article_sender_type_id, a_from, a_reply_to, a_to, " .
 
129
        " a_cc, a_subject, a_message_id, a_body, a_content_type, content_path, ".
 
130
        " valid_id, incoming_time,  create_time, create_by, change_time, change_by) " .
 
131
        " VALUES ".
 
132
        " ($DBParam{TicketID}, $DBParam{ArticleTypeID}, $DBParam{SenderTypeID}, ".
 
133
        " '$DBParam{From}', '$DBParam{ReplyTo}', '$DBParam{To}', '$DBParam{Cc}', ".
 
134
        " '$DBParam{Subject}', ".
 
135
        " '$DBParam{MessageID}', ?, '$DBParam{ContentType}', ?, ".
 
136
        " $ValidID,  $IncomingTime, " .
 
137
        " current_timestamp, $DBParam{UserID}, current_timestamp, $DBParam{UserID})";
138
138
    if (!$Self->{DBObject}->Do(SQL => $SQL, Bind => [\$Param{Body}, \$Self->{ArticleContentPath}])) {
139
139
        return;
140
140
    }
141
141
    # get article id
142
142
    my $ArticleID = $Self->_ArticleGetId(
143
143
        TicketID => $Param{TicketID},
144
 
MessageID => $Param{MessageID},
 
144
        MessageID => $Param{MessageID},
145
145
        From => $Param{From},
146
146
        Subject => $Param{Subject},
147
147
        IncomingTime => $IncomingTime
183
183
        TicketID => $Param{TicketID},
184
184
        UserID => $Param{UserID},
185
185
    );
 
186
    # reset escalation if needed
 
187
    if (!$Param{SenderType}) {
 
188
        $Param{SenderType} = $Self->ArticleSenderTypeLookup(SenderTypeID => $Param{SenderTypeID});
 
189
    }
 
190
    if (!$Param{ArticleType}) {
 
191
        $Param{ArticleType} = $Self->ArticleTypeLookup(ArticleTypeID => $Param{ArticleTypeID});
 
192
    }
 
193
    # reset escalation time if customer send an update
 
194
    if ($Param{SenderType} eq 'customer') {
 
195
        # check if latest article comes from customer
 
196
        my $LastSender = '';
 
197
        my $SQL .= "SELECT ast.name ".
 
198
            " FROM ".
 
199
            " article at, article_sender_type ast ".
 
200
            " WHERE ".
 
201
            " at.ticket_id = $Param{TicketID} ".
 
202
            " AND ".
 
203
            " at.id NOT IN ($ArticleID) ".
 
204
            " AND ".
 
205
            " at.article_sender_type_id = ast.id ORDER BY at.create_time ASC";
 
206
        $Self->{DBObject}->Prepare(SQL => $SQL);
 
207
        while (my @Row = $Self->{DBObject}->FetchrowArray()) {
 
208
            if ($Row[0] ne 'system') {
 
209
                $LastSender = $Row[0];
 
210
            }
 
211
        }
 
212
        if ($LastSender eq 'agent') {
 
213
            $Self->TicketEscalationStartUpdate(
 
214
                EscalationStartTime => $Self->{TimeObject}->SystemTime(),
 
215
                TicketID => $Param{TicketID},
 
216
                UserID => $Param{UserID},
 
217
           );
 
218
            $Self->TicketUnlockTimeoutUpdate(
 
219
                 UnlockTimeout => $Self->{TimeObject}->SystemTime(),
 
220
                 TicketID => $Param{TicketID},
 
221
                 UserID => $Param{UserID},
 
222
            );
 
223
        }
 
224
    }
 
225
    elsif ($Param{SenderType} eq 'agent' && $Param{ArticleType} =~ /email-ext|phone|fax|sms|note-ext/) {
 
226
        # check if latest article is sent to customer
 
227
        $Self->TicketEscalationStartUpdate(
 
228
            EscalationStartTime => $Self->{TimeObject}->SystemTime(),
 
229
            TicketID => $Param{TicketID},
 
230
            UserID => $Param{UserID},
 
231
        );
 
232
        $Self->TicketUnlockTimeoutUpdate(
 
233
             UnlockTimeout => $Self->{TimeObject}->SystemTime(),
 
234
             TicketID => $Param{TicketID},
 
235
             UserID => $Param{UserID},
 
236
        );
 
237
    }
186
238
    # send auto response
187
239
    my %Ticket = $Self->TicketGet(TicketID => $Param{TicketID});
188
240
    my %State = $Self->{StateObject}->StateGet(ID => $Ticket{StateID});
225
277
            else {
226
278
                # write log
227
279
                if ($Param{UserID} ne $Self->{ConfigObject}->Get('PostmasterUserID') ||
228
 
                     $Self->{LoopProtectionObject}->SendEmail(To => $OrigHeader{From})) {
 
280
                    $Self->{LoopProtectionObject}->SendEmail(To => $OrigHeader{From})
 
281
                ) {
229
282
                    # get history type
230
283
                    my %SendInfo = ();
231
284
                    if ($Param{AutoResponseType} =~/^auto follow up$/i) {
261
314
                TicketID => $Param{TicketID},
262
315
                HistoryType => 'Misc',
263
316
                Name => "Sent no auto-response because the sender doesn't want ".
264
 
                  "a auto-response (e. g. loop or precedence header)",
 
317
                    "a auto-response (e. g. loop or precedence header)",
265
318
                CreateUserID => $Param{UserID},
266
319
            );
267
320
            $Self->{LogObject}->Log(
268
321
                Priority => 'notice',
269
322
                Message => "Sent no '$Param{AutoResponseType}' for Ticket [".
270
 
                  "$Ticket{TicketNumber}] ($OrigHeader{From}) because the ".
271
 
                  "sender doesn't want a auto-response (e. g. loop or precedence header)"
 
323
                    "$Ticket{TicketNumber}] ($OrigHeader{From}) because the ".
 
324
                    "sender doesn't want a auto-response (e. g. loop or precedence header)"
272
325
            );
273
326
        }
274
327
    }
275
 
    # --
 
328
 
276
329
    # send no agent notification!?
277
 
    # --
278
330
    if ($Param{NoAgentNotify}) {
279
331
        # return ArticleID
280
332
        return $ArticleID;
281
333
    }
282
 
    # --
 
334
 
283
335
    # send agent notification!?
284
 
    # --
285
336
    my $To = '';
 
337
    my %AlreadySent = ();
286
338
    if ($Param{HistoryType} =~ /^(EmailAgent|EmailCustomer|PhoneCallCustomer|WebRequestCustomer|SystemRequest)$/i) {
287
339
        foreach ($Self->GetSubscribedUserIDsByQueueID(QueueID => $Ticket{QueueID})) {
288
 
            my %UserData = $Self->{UserObject}->GetUserData(
289
 
                UserID => $_,
290
 
                Cached => 1,
291
 
                Valid => 1,
292
 
            );
293
 
            if ($UserData{UserSendNewTicketNotification}) {
294
 
                # send notification
295
 
                $Self->SendAgentNotification(
296
 
                    Type => $Param{HistoryType},
297
 
                    UserData => \%UserData,
298
 
                    CustomerMessageParams => \%Param,
299
 
                    TicketID => $Param{TicketID},
300
 
                    Queue => $Param{Queue},
301
 
                    UserID => $Param{UserID},
 
340
            if (!$AlreadySent{$_}) {
 
341
                $AlreadySent{$_} = 1;
 
342
                my %UserData = $Self->{UserObject}->GetUserData(
 
343
                    UserID => $_,
 
344
                    Cached => 1,
 
345
                    Valid => 1,
302
346
                );
 
347
                if ($UserData{UserSendNewTicketNotification}) {
 
348
                    # send notification
 
349
                    $Self->SendAgentNotification(
 
350
                        Type => $Param{HistoryType},
 
351
                        UserData => \%UserData,
 
352
                        CustomerMessageParams => \%Param,
 
353
                        TicketID => $Param{TicketID},
 
354
                        Queue => $Param{Queue},
 
355
                        UserID => $Param{UserID},
 
356
                    );
 
357
                }
303
358
            }
304
359
        }
305
360
    }
306
361
    elsif ($Param{HistoryType} =~ /^AddNote$/i) {
307
 
        # send agent notification to agent
308
 
        if ($Ticket{OwnerID} ne 1 && $Ticket{OwnerID} ne $Param{UserID}) {
309
 
            my %UserData = $Self->{UserObject}->GetUserData(
310
 
                    UserID => $Ticket{OwnerID},
311
 
                    Cached => 1,
312
 
                    Valid => 1,
313
 
            );
314
 
            # send notification
315
 
            $Self->SendAgentNotification(
316
 
                Type => $Param{HistoryType},
317
 
                UserData => \%UserData,
318
 
                CustomerMessageParams => \%Param,
319
 
                TicketID => $Param{TicketID},
320
 
                Queue => $Param{Queue},
321
 
                UserID => $Param{UserID},
322
 
            );
 
362
        # send owner/responsible notification to agent
 
363
        foreach (qw(OwnerID ResponsibleID)) {
 
364
            if ($Ticket{$_} && $Ticket{$_} ne 1 && $Ticket{$_} ne $Param{UserID}) {
 
365
                if (!$AlreadySent{$Ticket{$_}}) {
 
366
                    $AlreadySent{$Ticket{$_}} = 1;
 
367
                    my %UserData = $Self->{UserObject}->GetUserData(
 
368
                        UserID => $Ticket{$_},
 
369
                        Cached => 1,
 
370
                        Valid => 1,
 
371
                    );
 
372
                    # send notification
 
373
                    $Self->SendAgentNotification(
 
374
                        Type => $Param{HistoryType},
 
375
                        UserData => \%UserData,
 
376
                        CustomerMessageParams => \%Param,
 
377
                        TicketID => $Param{TicketID},
 
378
                        Queue => $Param{Queue},
 
379
                        UserID => $Param{UserID},
 
380
                    );
 
381
                }
 
382
            }
323
383
        }
324
 
 
325
384
    }
326
385
    elsif ($Param{HistoryType} =~ /^FollowUp$/i) {
327
386
        # send agent notification to all agents
334
393
                @OwnerIDs = $Self->GetSubscribedUserIDsByQueueID(QueueID => $Ticket{QueueID});
335
394
            }
336
395
            foreach (@OwnerIDs) {
337
 
                my %UserData = $Self->{UserObject}->GetUserData(
338
 
                    UserID => $_,
339
 
                    Cached => 1,
340
 
                    Valid => 1,
341
 
                );
342
 
                if ($UserData{UserSendFollowUpNotification}) {
343
 
                    # send notification
344
 
                    $Self->SendAgentNotification(
345
 
                        Type => $Param{HistoryType},
346
 
                        UserData => \%UserData,
347
 
                        CustomerMessageParams => \%Param,
348
 
                        TicketID => $Param{TicketID},
349
 
                        Queue => $Param{Queue},
350
 
                        UserID => $Param{UserID},
 
396
                if (!$AlreadySent{$_}) {
 
397
                    $AlreadySent{$_} = 1;
 
398
                    my %UserData = $Self->{UserObject}->GetUserData(
 
399
                        UserID => $_,
 
400
                        Cached => 1,
 
401
                        Valid => 1,
351
402
                    );
 
403
                    if ($UserData{UserSendFollowUpNotification}) {
 
404
                        # send notification
 
405
                        $Self->SendAgentNotification(
 
406
                            Type => $Param{HistoryType},
 
407
                            UserData => \%UserData,
 
408
                            CustomerMessageParams => \%Param,
 
409
                            TicketID => $Param{TicketID},
 
410
                            Queue => $Param{Queue},
 
411
                            UserID => $Param{UserID},
 
412
                        );
 
413
                    }
352
414
                }
353
415
            }
354
416
        }
355
 
        # send agent notification the agents who locked the ticket
 
417
        # send owner/responsible notification the agents who locked the ticket
356
418
        else {
357
 
            my %UserData = $Self->{UserObject}->GetUserData(UserID => $Ticket{OwnerID});
358
 
            if ($UserData{UserSendFollowUpNotification}) {
359
 
                # send notification
360
 
                $Self->SendAgentNotification(
361
 
                    Type => $Param{HistoryType},
362
 
                    UserData => \%UserData,
363
 
                    CustomerMessageParams => \%Param,
364
 
                    TicketID => $Param{TicketID},
365
 
                    Queue => $Param{Queue},
366
 
                    UserID => $Param{UserID},
367
 
                );
 
419
            foreach (qw(OwnerID ResponsibleID)) {
 
420
                if ($Ticket{$_}) {
 
421
                    if (!$AlreadySent{$Ticket{$_}}) {
 
422
                        $AlreadySent{$Ticket{$_}} = 1;
 
423
                        my %UserData = $Self->{UserObject}->GetUserData(UserID => $Ticket{$_});
 
424
                        if ($Ticket{$_} ne 1 && $UserData{UserSendFollowUpNotification}) {
 
425
                            # send notification
 
426
                            $Self->SendAgentNotification(
 
427
                                Type => $Param{HistoryType},
 
428
                                UserData => \%UserData,
 
429
                                CustomerMessageParams => \%Param,
 
430
                                TicketID => $Param{TicketID},
 
431
                                Queue => $Param{Queue},
 
432
                                UserID => $Param{UserID},
 
433
                            );
 
434
                        }
 
435
                    }
 
436
                }
368
437
            }
369
438
            # send the rest of agents follow ups
370
439
            foreach ($Self->GetSubscribedUserIDsByQueueID(QueueID => $Ticket{QueueID})) {
371
 
                my %UserData = $Self->{UserObject}->GetUserData(
372
 
                    UserID => $_,
373
 
                    Cached => 1,
374
 
                    Valid => 1,
375
 
                );
376
 
                if ($UserData{UserSendFollowUpNotification} && $UserData{UserSendFollowUpNotification} == 2 && $Ticket{OwnerID} ne 1 && $Ticket{OwnerID} ne $Param{UserID} && $Ticket{OwnerID} ne $UserData{UserID}) {
377
 
                    # send notification
378
 
                    $Self->SendAgentNotification(
379
 
                        Type => $Param{HistoryType},
380
 
                        UserData => \%UserData,
381
 
                        CustomerMessageParams => \%Param,
382
 
                        TicketID => $Param{TicketID},
383
 
                        Queue => $Param{Queue},
384
 
                        UserID => $Param{UserID},
 
440
                if (!$AlreadySent{$_}) {
 
441
                    my %UserData = $Self->{UserObject}->GetUserData(
 
442
                        UserID => $_,
 
443
                        Cached => 1,
 
444
                        Valid => 1,
385
445
                    );
 
446
                    if ($UserData{UserSendFollowUpNotification} &&
 
447
                        $UserData{UserSendFollowUpNotification} == 2 &&
 
448
                        $Ticket{OwnerID} ne 1 &&
 
449
                        $Ticket{OwnerID} ne $Param{UserID} &&
 
450
                        $Ticket{OwnerID} ne $UserData{UserID}
 
451
                    ) {
 
452
                        $AlreadySent{$_} = 1;
 
453
                        # send notification
 
454
                        $Self->SendAgentNotification(
 
455
                            Type => $Param{HistoryType},
 
456
                            UserData => \%UserData,
 
457
                            CustomerMessageParams => \%Param,
 
458
                            TicketID => $Param{TicketID},
 
459
                            Queue => $Param{Queue},
 
460
                            UserID => $Param{UserID},
 
461
                        );
 
462
                    }
386
463
                }
387
464
            }
388
465
        }
389
466
    }
390
467
    # send forced notifications
391
468
    if ($Param{ForceNotificationToUserID} && ref($Param{ForceNotificationToUserID}) eq 'ARRAY') {
392
 
        my %AlreadySent = ();
393
469
        foreach (@{$Param{ForceNotificationToUserID}}) {
394
470
            if (!$AlreadySent{$_}) {
395
471
                $AlreadySent{$_} = 1;
414
490
    my %Param = @_;
415
491
    # check needed stuff
416
492
    foreach (qw(TicketID MessageID From Subject IncomingTime)) {
417
 
      if (!defined $Param{$_}) {
418
 
        $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
419
 
        return;
420
 
      }
 
493
        if (!defined $Param{$_}) {
 
494
            $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
 
495
            return;
 
496
        }
421
497
    }
422
498
    # db quote
423
499
    foreach (qw(MessageID From Subject IncomingTime)) {
442
518
    if ($Param{Subject}) {
443
519
        $SQL .= "a_subject = '$Param{Subject}' AND ";
444
520
    }
445
 
    $SQL .= " incoming_time = '$Param{IncomingTime}'";
 
521
    $SQL .= " incoming_time = $Param{IncomingTime}";
446
522
    # start query
447
523
    $Self->{DBObject}->Prepare(SQL => $SQL);
448
524
    my $Id;
473
549
        return;
474
550
    }
475
551
    # db quote
476
 
    foreach (keys %Param) {
 
552
    foreach (qw(MessageID)) {
477
553
        $Param{$_} = $Self->{DBObject}->Quote($Param{$_});
478
554
    }
479
555
    # sql query
518
594
    my %Param = @_;
519
595
    # check needed stuff
520
596
    if (!$Param{ArticleID}) {
521
 
      $Self->{LogObject}->Log(Priority => 'error', Message => "Need ArticleID!");
522
 
      return;
 
597
        $Self->{LogObject}->Log(Priority => 'error', Message => "Need ArticleID!");
 
598
        return;
523
599
    }
524
600
    # db quote
525
601
    foreach (qw(ArticleID)) {
561
637
    my %Param = @_;
562
638
    # check needed stuff
563
639
    if (!$Param{SenderType} && !$Param{SenderTypeID}) {
564
 
      $Self->{LogObject}->Log(Priority => 'error', Message => "Need SenderType or SenderTypeID!");
565
 
      return;
 
640
        $Self->{LogObject}->Log(Priority => 'error', Message => "Need SenderType or SenderTypeID!");
 
641
        return;
566
642
    }
567
643
    # get key
568
644
    if ($Param{SenderType}) {
575
651
    if ($Self->{"ArticleSenderTypeLookup::$Param{$Param{Key}}"}) {
576
652
        return $Self->{"ArticleSenderTypeLookup::$Param{$Param{Key}}"};
577
653
    }
578
 
    # db quote
579
 
    foreach (keys %Param) {
580
 
        $Param{$_} = $Self->{DBObject}->Quote($Param{$_});
581
 
    }
582
654
    # get data
583
655
    my $SQL = '';
584
656
    if ($Param{SenderType}) {
 
657
        # db quote
 
658
        foreach (qw(SenderType)) {
 
659
            $Param{$_} = $Self->{DBObject}->Quote($Param{$_});
 
660
        }
585
661
        $SQL = "SELECT id FROM article_sender_type WHERE name = '$Param{SenderType}'";
586
662
    }
587
663
    else {
 
664
        # db quote
 
665
        foreach (qw(SenderTypeID)) {
 
666
            $Param{$_} = $Self->{DBObject}->Quote($Param{$_}, 'Integer');
 
667
        }
588
668
        $SQL = "SELECT name FROM article_sender_type WHERE id = $Param{SenderTypeID}";
589
669
    }
590
670
    $Self->{DBObject}->Prepare(SQL => $SQL);
637
717
    if ($Self->{"ArticleTypeLookup::$Param{$Param{Key}}"}) {
638
718
        return $Self->{"ArticleTypeLookup::$Param{$Param{Key}}"};
639
719
    }
640
 
    # db quote
641
 
    foreach (keys %Param) {
642
 
        $Param{$_} = $Self->{DBObject}->Quote($Param{$_});
643
 
    }
644
720
    # get data
645
721
    my $SQL = '';
646
722
    if ($Param{ArticleType}) {
 
723
        # db quote
 
724
        foreach (qw(ArticleType)) {
 
725
            $Param{$_} = $Self->{DBObject}->Quote($Param{$_});
 
726
        }
647
727
        $SQL = "SELECT id FROM article_type WHERE name = '$Param{ArticleType}'",
648
728
    }
649
729
    else {
 
730
        # db quote
 
731
        foreach (qw(ArticleTypeID)) {
 
732
            $Param{$_} = $Self->{DBObject}->Quote($Param{$_}, 'Integer');
 
733
        }
650
734
        $SQL = "SELECT name FROM article_type WHERE id = $Param{ArticleTypeID}",
651
735
    }
652
736
    $Self->{DBObject}->Prepare(SQL => $SQL);
667
751
    return $Self->{"ArticleTypeLookup::$Param{$Param{Key}}"};
668
752
}
669
753
 
 
754
=item ArticleTypeList()
 
755
 
 
756
get a article type list
 
757
 
 
758
  my @ArticleTypeList = $TicketObject->ArticleTypesList();
 
759
 
 
760
  # to get just customer shown article types
 
761
  my @ArticleTypeList = $TicketObject->ArticleTypesList(
 
762
      Type => 'Customer',
 
763
  );
 
764
 
 
765
=cut
 
766
 
 
767
sub ArticleTypeList {
 
768
    my $Self = shift;
 
769
    my %Param = @_;
 
770
    my @List = ();
 
771
    # check needed stuff
 
772
    foreach (qw()) {
 
773
        if (!$Param{$_}) {
 
774
            $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
 
775
            return;
 
776
        }
 
777
    }
 
778
    my $SQL = "SELECT id, name FROM article_type ".
 
779
        " WHERE valid_id IN (${\(join ', ', $Self->{DBObject}->GetValidIDs())}) ";
 
780
    $Self->{DBObject}->Prepare(SQL => $SQL);
 
781
    while (my @Row = $Self->{DBObject}->FetchrowArray()){
 
782
        if ($Param{Type} && $Param{Type} eq 'Customer') {
 
783
           if ($Row[1] !~ /int/i){
 
784
              push (@List, $Row[1]);
 
785
           }
 
786
        }
 
787
        else {
 
788
           push (@List, $Row[1]);
 
789
        }
 
790
    }
 
791
    return @List;
 
792
 
 
793
}
 
794
 
 
795
=item ArticleFreeTextGet()
 
796
 
 
797
get _possible_ article free text options
 
798
 
 
799
Note: the current value is accessible over ArticleGet()
 
800
 
 
801
  my $HashRef = $TicketObject->ArticleFreeTextGet(
 
802
     Type => 'ArticleFreeText3',
 
803
     ArticleID => 123,
 
804
     UserID => 123, # or CustomerUserID
 
805
  );
 
806
 
 
807
  my $HashRef = $TicketObject->ArticleFreeTextGet(
 
808
     Type => 'ArticleFreeText3',
 
809
     UserID => 123, # or CustomerUserID
 
810
  );
 
811
 
 
812
  # fill up with existing values
 
813
  my $HashRef = $TicketObject->ArticleFreeTextGet(
 
814
     Type => 'ArticleFreeText3',
 
815
     FillUp => 1,
 
816
     UserID => 123, # or CustomerUserID
 
817
  );
 
818
 
 
819
=cut
 
820
 
 
821
sub ArticleFreeTextGet {
 
822
    my $Self = shift;
 
823
    my %Param = @_;
 
824
    my $Value = $Param{Value} || '';
 
825
    my $Key = $Param{Key} || '';
 
826
    # check needed stuff
 
827
    foreach (qw(Type)) {
 
828
        if (!$Param{$_}) {
 
829
            $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
 
830
            return;
 
831
        }
 
832
    }
 
833
    if (!$Param{UserID} && !$Param{CustomerUserID}) {
 
834
        $Self->{LogObject}->Log(Priority => 'error', Message => "Need UserID or CustomerUserID!");
 
835
        return;
 
836
    }
 
837
    # get config
 
838
    my %Data = ();
 
839
    if (ref($Self->{ConfigObject}->Get($Param{Type})) eq 'HASH') {
 
840
        %Data = %{$Self->{ConfigObject}->Get($Param{Type})};
 
841
    }
 
842
    # check existing
 
843
    if ($Param{FillUp}) {
 
844
        my $Counter = $Param{Type};
 
845
        $Counter =~ s/^.*(\d)$/$1/;
 
846
        if (%Data && $Param{Type} =~ /text/i) {
 
847
            $Self->{DBObject}->Prepare(SQL => "SELECT distinct(a_freetext$Counter) FROM article");
 
848
            while (my @Row = $Self->{DBObject}->FetchrowArray()) {
 
849
                if ($Row[0] && !$Data{$Row[0]}) {
 
850
                    $Data{$Row[0]} = $Row[0];
 
851
                }
 
852
            }
 
853
        }
 
854
        elsif (%Data) {
 
855
            $Self->{DBObject}->Prepare(SQL => "SELECT distinct(a_freekey$Counter) FROM article");
 
856
            while (my @Row = $Self->{DBObject}->FetchrowArray()) {
 
857
                if ($Row[0] && !$Data{$Row[0]}) {
 
858
                    $Data{$Row[0]} = $Row[0];
 
859
                }
 
860
            }
 
861
        }
 
862
    }
 
863
    # workflow
 
864
    if ($Self->TicketAcl(
 
865
        %Param,
 
866
        ReturnType => 'Ticket',
 
867
        ReturnSubType => $Param{Type},
 
868
        Data => \%Data,
 
869
    )) {
 
870
        my %Hash = $Self->TicketAclData();
 
871
        return \%Hash;
 
872
    }
 
873
    # /workflow
 
874
    if (%Data) {
 
875
        return \%Data;
 
876
    }
 
877
    else {
 
878
        return;
 
879
    }
 
880
}
 
881
 
670
882
=item ArticleFreeTextSet()
671
883
 
672
884
set article free text
673
885
 
674
886
  $TicketObject->ArticleFreeTextSet(
675
 
      ArticleID => 123,
 
887
      TicketID => 123,
 
888
      ArticleID => 1234,
676
889
      Counter => 1,
677
890
      Key => 'Planet',
678
891
      Value => 'Sun',
685
898
    my $Self = shift;
686
899
    my %Param = @_;
687
900
    # check needed stuff
688
 
    foreach (qw(ArticleID UserID Counter)) {
689
 
      if (!$Param{$_}) {
690
 
        $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
691
 
        return;
692
 
      }
 
901
    foreach (qw(TicketID ArticleID UserID Counter)) {
 
902
        if (!$Param{$_}) {
 
903
            $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
 
904
            return;
 
905
        }
693
906
    }
694
907
    # db quote for key an value
695
908
    $Param{Value} = $Self->{DBObject}->Quote($Param{Value}) || '';
700
913
    # db update
701
914
    if ($Self->{DBObject}->Do(
702
915
        SQL => "UPDATE article SET a_freekey$Param{Counter} = '$Param{Key}', " .
703
 
          " a_freetext$Param{Counter} = '$Param{Value}', " .
704
 
          " change_time = current_timestamp, change_by = $Param{UserID} " .
705
 
          " WHERE id = $Param{ArticleID}",
 
916
            " a_freetext$Param{Counter} = '$Param{Value}', " .
 
917
            " change_time = current_timestamp, change_by = $Param{UserID} " .
 
918
            " WHERE id = $Param{ArticleID}",
706
919
    )) {
707
920
        # ticket event
708
921
        $Self->TicketEventHandlerPost(
709
 
            Event => 'ArticleFreeTextSet',
 
922
            Event => 'ArticleFreeTextUpdate',
710
923
            TicketID => $Param{TicketID},
711
924
            UserID => $Param{UserID},
712
925
        );
835
1048
    my $SQL = '';
836
1049
    if ($Param{SenderType}) {
837
1050
        $SQL .= "SELECT at.id".
838
 
          " FROM ".
839
 
          " article at, article_sender_type ast ".
840
 
          " WHERE ".
841
 
          " at.ticket_id = $Param{TicketID} ".
842
 
          " AND ".
843
 
          " at.article_sender_type_id = ast.id ".
844
 
          " AND ".
845
 
          " ast.name = '$Param{SenderType}' ";
 
1051
            " FROM ".
 
1052
            " article at, article_sender_type ast ".
 
1053
            " WHERE ".
 
1054
            " at.ticket_id = $Param{TicketID} ".
 
1055
            " AND ".
 
1056
            " at.article_sender_type_id = ast.id ".
 
1057
            " AND ".
 
1058
            " ast.name = '$Param{SenderType}' ";
846
1059
    }
847
1060
    else {
848
1061
        $SQL = "SELECT at.id".
849
 
          " FROM ".
850
 
          " article at ".
851
 
          " WHERE ".
852
 
          " at.ticket_id = $Param{TicketID} ";
 
1062
            " FROM ".
 
1063
            " article at ".
 
1064
            " WHERE ".
 
1065
            " at.ticket_id = $Param{TicketID} ";
853
1066
    }
854
1067
    $SQL .= " ORDER BY at.id";
855
1068
    $Self->{DBObject}->Prepare(SQL => $SQL);
919
1132
        return;
920
1133
    }
921
1134
    # db quote
922
 
    foreach (keys %Param) {
923
 
        $Param{$_} = $Self->{DBObject}->Quote($Param{$_});
924
 
    }
925
1135
    foreach (qw(TicketID ArticleID)) {
926
1136
        $Param{$_} = $Self->{DBObject}->Quote($Param{$_}, 'Integer');
927
1137
    }
933
1143
                if ($ArticleTypeSQL) {
934
1144
                    $ArticleTypeSQL .= ',';
935
1145
                }
936
 
                $ArticleTypeSQL .= $Self->ArticleTypeLookup(ArticleType => $_);
 
1146
                $ArticleTypeSQL .= $Self->{DBObject}->Quote($Self->ArticleTypeLookup(ArticleType => $_), 'Integer');
937
1147
            }
938
1148
        }
939
1149
        if ($ArticleTypeSQL) {
947
1157
        " st.create_time_unix, st.ticket_state_id, st.queue_id, sa.create_time, ".
948
1158
        " sa.a_content_type, sa.create_by, st.tn, article_sender_type_id, st.customer_id, ".
949
1159
        " st.until_time, st.ticket_priority_id, st.customer_user_id, st.user_id, ".
950
 
        " su.$Self->{ConfigObject}->{DatabaseUserTableUser}, sa.article_type_id, ".
 
1160
        " st.responsible_user_id, sa.article_type_id, ".
951
1161
        " sa.a_freekey1, sa.a_freetext1, sa.a_freekey2, sa.a_freetext2, ".
952
1162
        " sa.a_freekey3, sa.a_freetext3, st.ticket_answered, ".
953
1163
        " sa.incoming_time, sa.id, st.freekey1, st.freetext1, st.freekey2, st.freetext2,".
954
1164
        " st.freekey3, st.freetext3, st.freekey4, st.freetext4,".
955
1165
        " st.freekey5, st.freetext5, st.freekey6, st.freetext6,".
956
1166
        " st.freekey7, st.freetext7, st.freekey8, st.freetext8, ".
 
1167
        " st.freekey9, st.freetext9, st.freekey10, st.freetext10, ".
 
1168
        " st.freekey11, st.freetext11, st.freekey12, st.freetext12, ".
 
1169
        " st.freekey13, st.freetext13, st.freekey14, st.freetext14, ".
 
1170
        " st.freekey15, st.freetext15, st.freekey16, st.freetext16, ".
957
1171
        " st.ticket_lock_id, st.title, st.escalation_start_time, ".
958
1172
        " st.freetime1 , st.freetime2 ".
959
1173
        " FROM ".
960
 
        " article sa, ticket st, ".
961
 
        " $Self->{ConfigObject}->{DatabaseUserTable} su ".
962
 
        " where ";
 
1174
        " article sa, ticket st ".
 
1175
        " WHERE ";
963
1176
    if ($Param{ArticleID}) {
964
1177
        $SQL .= " sa.id = $Param{ArticleID}";
965
1178
    }
972
1185
    if ($ArticleTypeSQL) {
973
1186
        $SQL .= $ArticleTypeSQL;
974
1187
    }
975
 
    $SQL .= " AND ".
976
 
        " st.user_id = su.$Self->{ConfigObject}->{DatabaseUserTableUserID} ".
977
 
        " ORDER BY sa.create_time, sa.id ASC";
 
1188
    $SQL .= " ORDER BY sa.create_time, sa.id ASC";
978
1189
 
979
1190
    $Self->{DBObject}->Prepare(SQL => $SQL);
980
1191
    my %Ticket = ();
983
1194
        $Data{ArticleID} = $Row[31];
984
1195
        $Data{TicketID} = $Row[0];
985
1196
        $Ticket{TicketID} = $Data{TicketID};
986
 
        $Data{Title} = $Row[49];
 
1197
        $Data{Title} = $Row[65];
987
1198
        $Ticket{Title} = $Data{Title};
988
 
        $Data{EscalationStartTime} = $Row[50];
 
1199
        $Data{EscalationStartTime} = $Row[66];
989
1200
        $Ticket{EscalationStartTime} = $Data{EscalationStartTime};
990
1201
        $Data{From} = $Row[1];
991
1202
        $Data{To} = $Row[2];
1024
1235
        else {
1025
1236
            $Data{MimeType} = '';
1026
1237
        }
1027
 
        $Ticket{CustomerID} = $Row[16];
 
1238
        $Data{CustomerUserID} = $Row[19];
1028
1239
        $Ticket{CustomerUserID} = $Row[19];
1029
1240
        $Data{CustomerID} = $Row[16];
1030
 
        $Data{CustomerUserID} = $Row[19];
1031
 
        $Data{UserID} = $Row[20];
1032
 
        $Ticket{UserID} = $Row[20];
1033
 
        $Data{Owner} = $Row[21];
 
1241
        $Ticket{CustomerID} = $Row[16];
 
1242
        $Data{OwnerID} = $Row[20];
 
1243
        $Ticket{OwnerID} = $Row[20];
 
1244
        $Data{ResponsibleID} = $Row[21];
 
1245
        $Ticket{ResponsibleID} = $Row[21];
1034
1246
        $Data{ArticleTypeID} = $Row[22];
1035
 
        $Data{FreeKey1} = $Row[23];
1036
 
        $Data{FreeText1} = $Row[24];
1037
 
        $Data{FreeKey2} = $Row[25];
1038
 
        $Data{FreeText2} = $Row[26];
1039
 
        $Data{FreeKey3} = $Row[27];
1040
 
        $Data{FreeText3} = $Row[28];
 
1247
        $Data{ArticleFreeKey1} = $Row[23];
 
1248
        $Data{ArticleFreeText1} = $Row[24];
 
1249
        $Data{ArticleFreeKey2} = $Row[25];
 
1250
        $Data{ArticleFreeText2} = $Row[26];
 
1251
        $Data{ArticleFreeKey3} = $Row[27];
 
1252
        $Data{ArticleFreeText3} = $Row[28];
1041
1253
        $Data{TicketFreeKey1} = $Row[32];
1042
1254
        $Data{TicketFreeText1} = $Row[33];
1043
1255
        $Data{TicketFreeKey2} = $Row[34];
1054
1266
        $Data{TicketFreeText7} = $Row[45];
1055
1267
        $Data{TicketFreeKey8} = $Row[46];
1056
1268
        $Data{TicketFreeText8} = $Row[47];
1057
 
        $Data{TicketFreeTime1} = $Row[51];
1058
 
        $Data{TicketFreeTime2} = $Row[52];
 
1269
        $Data{TicketFreeKey9} = $Row[48];
 
1270
        $Data{TicketFreeText9} = $Row[49];
 
1271
        $Data{TicketFreeKey10} = $Row[50];
 
1272
        $Data{TicketFreeText10} = $Row[51];
 
1273
        $Data{TicketFreeKey11} = $Row[52];
 
1274
        $Data{TicketFreeText11} = $Row[53];
 
1275
        $Data{TicketFreeKey12} = $Row[54];
 
1276
        $Data{TicketFreeText12} = $Row[55];
 
1277
        $Data{TicketFreeKey13} = $Row[56];
 
1278
        $Data{TicketFreeText13} = $Row[57];
 
1279
        $Data{TicketFreeKey14} = $Row[58];
 
1280
        $Data{TicketFreeText14} = $Row[59];
 
1281
        $Data{TicketFreeKey15} = $Row[60];
 
1282
        $Data{TicketFreeText15} = $Row[61];
 
1283
        $Data{TicketFreeKey16} = $Row[62];
 
1284
        $Data{TicketFreeText16} = $Row[63];
 
1285
        $Data{TicketFreeTime1} = $Row[67];
 
1286
        $Data{TicketFreeTime2} = $Row[68];
1059
1287
 
1060
1288
        $Data{IncomingTime} = $Row[30];
1061
1289
        $Data{RealTillTimeNotUsed} = $Row[17];
1062
 
        $Ticket{LockID} = $Row[48];
 
1290
        $Ticket{LockID} = $Row[64];
1063
1291
        # strip not wanted stuff
1064
1292
        foreach (qw(From To Cc Subject)) {
1065
1293
            $Data{$_} =~ s/\n|\r//g if ($Data{$_});
1066
1294
        }
1067
1295
        push (@Content, {%Data, %Ticket});
1068
1296
    }
1069
 
    # get SLA time
1070
 
#    $Ticket{SLAAge} = $Self->{TimeObject}->SLATime(StartTime => $Ticket{CreateTimeUnix});
1071
 
    # get priority name
 
1297
    # get owner
 
1298
    $Ticket{Owner} = $Self->{UserObject}->UserLookup(UserID => $Ticket{OwnerID});
 
1299
    # get responsible
 
1300
    $Ticket{Responsible} = $Self->{UserObject}->UserLookup(UserID => $Ticket{ResponsibleID} || 1);
 
1301
    # get priority
1072
1302
    $Ticket{Priority} = $Self->PriorityLookup(ID => $Ticket{PriorityID});
 
1303
    # get lock
1073
1304
    $Ticket{Lock} = $Self->{LockObject}->LockLookup(ID => $Ticket{LockID});
1074
1305
    # get queue name and other stuff
1075
1306
    my %Queue = $Self->{QueueObject}->QueueGet(ID => $Ticket{QueueID}, Cache => 1);
1077
1308
    my %StateData = $Self->{StateObject}->StateGet(ID => $Ticket{StateID}, Cache => 1);
1078
1309
 
1079
1310
    # article stuff
1080
 
    my $LastCustomerCreateTime = 0;
 
1311
    my $EscalationTime = 0;
 
1312
    my $EscalationTimeLong = 0;
 
1313
    my $EscalationDate = 0;
1081
1314
    foreach my $Part (@Content) {
 
1315
        # get owner
 
1316
        $Part->{Owner} = $Ticket{Owner};
 
1317
        # get responsible
 
1318
        $Part->{Responsible} = $Ticket{Responsible};
1082
1319
        # get sender type
1083
1320
        $Part->{SenderType} = $Self->ArticleSenderTypeLookup(
1084
1321
            SenderTypeID => $Part->{SenderTypeID},
1106
1343
        my $CountedTime = $Self->{TimeObject}->WorkingTime(
1107
1344
            StartTime => $Ticket{EscalationStartTime},
1108
1345
            StopTime => $Self->{TimeObject}->SystemTime(),
1109
 
            Queue => $Queue{Name},
1110
 
        );
1111
 
        $LastCustomerCreateTime = ($Queue{EscalationTime}*60) - $CountedTime;
 
1346
            Calendar => $Queue{Calendar},
 
1347
        );
 
1348
        $EscalationTime = ($Queue{EscalationTime}*60) - $CountedTime;
 
1349
        my $CountedTime1 = $Self->{TimeObject}->DestinationTime(
 
1350
            StartTime => $Ticket{EscalationStartTime},
 
1351
            Time => $Queue{EscalationTime}*60,
 
1352
            Calendar => $Queue{Calendar},
 
1353
        );
 
1354
        $EscalationDate = $Self->{TimeObject}->SystemTime2TimeStamp(SystemTime => $CountedTime1);
 
1355
        $EscalationTimeLong = $CountedTime1 - $Self->{TimeObject}->SystemTime();
1112
1356
    }
1113
1357
    foreach my $Part (@Content) {
1114
 
        $Part->{TicketOverTime} = $LastCustomerCreateTime;
 
1358
        $Part->{TicketOverTime} = $EscalationTime;
 
1359
        $Part->{TicketOverTimeLong} = $EscalationTimeLong;
 
1360
        $Part->{TicketOverDate} = $EscalationDate;
1115
1361
    }
1116
1362
    if ($Param{ArticleID}) {
1117
1363
        return %{$Content[0]};
1132
1378
      Key => 'Body',
1133
1379
      Value => 'New Body',
1134
1380
      UserID => 123,
 
1381
      TicketID => 123,
1135
1382
  );
1136
1383
 
1137
1384
=cut
1140
1387
    my $Self = shift;
1141
1388
    my %Param = @_;
1142
1389
    # check needed stuff
1143
 
    foreach (qw(ArticleID UserID Key)) {
1144
 
      if (!$Param{$_}) {
1145
 
        $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
1146
 
        return;
1147
 
      }
 
1390
    foreach (qw(ArticleID UserID Key TicketID)) {
 
1391
        if (!$Param{$_}) {
 
1392
            $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
 
1393
            return;
 
1394
        }
1148
1395
    }
1149
1396
    # check needed stuff
1150
1397
    if (!defined($Param{Value})) {
1168
1415
    # db update
1169
1416
    if ($Self->{DBObject}->Do(
1170
1417
        SQL => "UPDATE article SET $Map{$Param{Key}} = '$Param{Value}', ".
1171
 
          " change_time = current_timestamp, change_by = $Param{UserID} " .
1172
 
          " WHERE id = $Param{ArticleID}",
 
1418
            " change_time = current_timestamp, change_by = $Param{UserID} " .
 
1419
            " WHERE id = $Param{ArticleID}",
1173
1420
    )) {
1174
1421
        # ticket event
1175
1422
        $Self->TicketEventHandlerPost(
1184
1431
    }
1185
1432
}
1186
1433
 
1187
 
 
1188
1434
=item ArticleSend()
1189
1435
 
1190
1436
send article via email and create article with attachments
1250
1496
    my $HistoryType = $Param{HistoryType} || 'SendAnswer';
1251
1497
    # check needed stuff
1252
1498
    foreach (qw(TicketID UserID From Body Type Charset)) {
1253
 
      if (!$Param{$_}) {
1254
 
        $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
1255
 
        return;
1256
 
      }
 
1499
        if (!$Param{$_}) {
 
1500
            $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
 
1501
            return;
 
1502
        }
1257
1503
    }
1258
1504
    if (!$Param{ArticleType} && !$Param{ArticleTypeID}) {
1259
1505
        $Self->{LogObject}->Log(Priority => 'error', Message => "Need ArticleType or ArticleTypeID!");
1285
1531
        foreach my $Tmp (@{$Param{Attachment}}) {
1286
1532
            my %Upload = %{$Tmp};
1287
1533
            if ($Upload{Content} && $Upload{Filename}) {
1288
 
              # add attachments to article
1289
 
              $Self->ArticleWriteAttachment(
1290
 
                %Upload,
1291
 
                ArticleID => $Param{ArticleID},
1292
 
                UserID => $Param{UserID},
1293
 
              );
 
1534
                # add attachments to article
 
1535
                $Self->ArticleWriteAttachment(
 
1536
                    %Upload,
 
1537
                    ArticleID => $Param{ArticleID},
 
1538
                    UserID => $Param{UserID},
 
1539
                );
1294
1540
            }
1295
1541
        }
1296
1542
    }
1373
1619
    my $HistoryType = $Param{HistoryType} || 'Bounce';
1374
1620
    # check needed stuff
1375
1621
    foreach (qw(From To UserID Email)) {
1376
 
      if (!$Param{$_}) {
1377
 
        $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
1378
 
        return;
1379
 
      }
 
1622
        if (!$Param{$_}) {
 
1623
            $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
 
1624
            return;
 
1625
        }
1380
1626
    }
1381
1627
    # create message id
1382
1628
    my $NewMessageID = "<$Time.$Random.$Param{TicketID}.0.$Param{UserID}\@$Self->{FQDN}>";
1427
1673
    my %Param = @_;
1428
1674
    # check needed stuff
1429
1675
    foreach (qw(CustomerMessageParams TicketID UserID Type UserData)) {
1430
 
      if (!$Param{$_}) {
1431
 
        $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
1432
 
        return;
1433
 
      }
 
1676
        if (!$Param{$_}) {
 
1677
            $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
 
1678
            return;
 
1679
        }
1434
1680
    }
1435
 
    # comapt Type
 
1681
    # compat Type
1436
1682
    if ($Param{Type} =~/(EmailAgent|EmailCustomer|PhoneCallCustomer|WebRequestCustomer|SystemRequest)/) {
1437
1683
        $Param{Type} = 'NewTicket';
1438
1684
    }
1449
1695
        }
1450
1696
        chomp $GetParam{$_};
1451
1697
    }
 
1698
    # fill up required attributes
 
1699
    foreach (qw(Subject Body)) {
 
1700
        if (!$GetParam{$_}) {
 
1701
            $GetParam{$_} = "No $_";
 
1702
        }
 
1703
    }
1452
1704
    # format body
1453
1705
    $GetParam{Body} =~ s/(^>.+|.{4,72})(?:\s|\z)/$1\n/gm if ($GetParam{Body});
1454
1706
 
1470
1722
    # replace config options
1471
1723
    $Notification{Body} =~ s{<OTRS_CONFIG_(.+?)>}{$Self->{ConfigObject}->Get($1)}egx;
1472
1724
    $Notification{Subject} =~ s{<OTRS_CONFIG_(.+?)>}{$Self->{ConfigObject}->Get($1)}egx;
 
1725
    # cleanup
 
1726
    $Notification{Subject} =~ s/<OTRS_CONFIG_.+?>/-/gi;
 
1727
    $Notification{Body} =~ s/<OTRS_CONFIG_.+?>/-/gi;
1473
1728
 
1474
1729
    # get owner data and replace it with <OTRS_OWNER_...
1475
 
    my %Preferences = $Self->{UserObject}->GetUserData(UserID => $Article{UserID});
1476
 
    foreach (keys %Preferences) {
1477
 
        if ($Preferences{$_}) {
1478
 
            $Notification{Body} =~ s/<OTRS_OWNER_$_>/$Preferences{$_}/gi;
1479
 
            $Notification{Subject} =~ s/<OTRS_OWNER_$_>/$Preferences{$_}/gi;
1480
 
        }
1481
 
    }
 
1730
    my %OwnerPreferences = $Self->{UserObject}->GetUserData(UserID => $Article{OwnerID});
 
1731
    foreach (keys %OwnerPreferences) {
 
1732
        if ($OwnerPreferences{$_}) {
 
1733
            $Notification{Body} =~ s/<OTRS_OWNER_$_>/$OwnerPreferences{$_}/gi;
 
1734
            $Notification{Subject} =~ s/<OTRS_OWNER_$_>/$OwnerPreferences{$_}/gi;
 
1735
        }
 
1736
    }
 
1737
    # cleanup
 
1738
    $Notification{Subject} =~ s/<OTRS_OWNER_.+?>/-/gi;
 
1739
    $Notification{Body} =~ s/<OTRS_OWNER_.+?>/-/gi;
 
1740
 
 
1741
    # get owner data and replace it with <OTRS_RESPONSIBLE_...
 
1742
    my %ResponsiblePreferences = $Self->{UserObject}->GetUserData(UserID => $Article{ResponsibleID});
 
1743
    foreach (keys %ResponsiblePreferences) {
 
1744
        if ($ResponsiblePreferences{$_}) {
 
1745
            $Notification{Body} =~ s/<OTRS_RESPONSIBLE_$_>/$ResponsiblePreferences{$_}/gi;
 
1746
            $Notification{Subject} =~ s/<OTRS_RESPONSIBLE_$_>/$ResponsiblePreferences{$_}/gi;
 
1747
        }
 
1748
    }
 
1749
    # cleanup
 
1750
    $Notification{Subject} =~ s/<OTRS_RESPONSIBLE_.+?>/-/gi;
 
1751
    $Notification{Body} =~ s/<OTRS_RESPONSIBLE_.+?>/-/gi;
 
1752
 
1482
1753
    # get current user data
1483
1754
    my %CurrentUser = $Self->{UserObject}->GetUserData(UserID => $Param{UserID});
1484
1755
    foreach (keys %CurrentUser) {
1487
1758
            $Notification{Subject} =~ s/<OTRS_CURRENT_$_>/$CurrentUser{$_}/gi;
1488
1759
        }
1489
1760
    }
 
1761
    # cleanup
 
1762
    $Notification{Subject} =~ s/<OTRS_CURRENT_.+?>/-/gi;
 
1763
    $Notification{Body} =~ s/<OTRS_CURRENT_.+?>/-/gi;
 
1764
 
1490
1765
    # replace it with given user params
1491
1766
    foreach (keys %User) {
1492
1767
        if ($User{$_}) {
1494
1769
            $Notification{Subject} =~ s/<OTRS_$_>/$User{$_}/gi;
1495
1770
        }
1496
1771
    }
 
1772
 
1497
1773
    # ticket data
1498
1774
    my %Ticket = $Self->TicketGet(TicketID => $Param{TicketID});
1499
1775
    foreach (keys %Ticket) {
1503
1779
        }
1504
1780
    }
1505
1781
    # COMPAT
1506
 
    $Notification{Body} =~ s/<OTRS_TICKET_ID>/$Param{TicketID}/g;
1507
 
    $Notification{Body} =~ s/<OTRS_TICKET_NUMBER>/$Article{TicketNumber}/g;
1508
 
    $Notification{Body} =~ s/<OTRS_QUEUE>/$Article{Queue}/g;
1509
 
    $Notification{Body} =~ s/<OTRS_COMMENT>/$GetParam{Comment}/g if (defined $GetParam{Comment});
 
1782
    $Notification{Body} =~ s/<OTRS_TICKET_ID>/$Param{TicketID}/gi;
 
1783
    $Notification{Body} =~ s/<OTRS_TICKET_NUMBER>/$Article{TicketNumber}/gi;
 
1784
    $Notification{Body} =~ s/<OTRS_QUEUE>/$Article{Queue}/gi;
 
1785
    $Notification{Body} =~ s/<OTRS_COMMENT>/$GetParam{Comment}/gi if (defined $GetParam{Comment});
 
1786
    # cleanup
 
1787
    $Notification{Subject} =~ s/<OTRS_TICKET_.+?>/-/gi;
 
1788
    $Notification{Body} =~ s/<OTRS_TICKET_.+?>/-/gi;
1510
1789
 
1511
1790
    # prepare subject (insert old subject)
1512
1791
    $GetParam{Subject} = $Self->TicketSubjectClean(
1521
1800
    $Notification{Subject} = $Self->TicketSubjectBuild(
1522
1801
        TicketNumber => $Article{TicketNumber},
1523
1802
        Subject => $Notification{Subject} || '',
 
1803
        Type => 'New',
1524
1804
    );
1525
1805
 
1526
1806
    # get customer data and replace it with <OTRS_CUSTOMER_DATA_...
1546
1826
            $Notification{Subject} =~ s/<OTRS_$_>/$Article{$_}/gi;
1547
1827
            $Notification{Body} =~ s/<OTRS_$_>/$Article{$_}/gi;
1548
1828
        }
1549
 
        else {
1550
 
            # cleanup
1551
 
            $Notification{Subject} =~ s/<OTRS_$_>//gi;
1552
 
            $Notification{Body} =~ s/<OTRS_$_>//gi;
1553
 
        }
1554
1829
    }
1555
1830
 
1556
 
    # cleanup all not needed <OTRS_CUSTOMER_DATA_ tags
1557
 
    $Notification{Body} =~ s/<OTRS_CUSTOMER_DATA_.+?>/-/gi;
1558
 
    $Notification{Subject} =~ s/<OTRS_CUSTOMER_DATA_.+?>/-/gi;
1559
 
 
1560
1831
    foreach (keys %GetParam) {
1561
1832
        if ($GetParam{$_}) {
1562
1833
            $Notification{Body} =~ s/<OTRS_CUSTOMER_$_>/$GetParam{$_}/gi;
1577
1848
        chomp $NewOldBody;
1578
1849
        $Notification{Body} =~ s/<OTRS_CUSTOMER_EMAIL\[.+?\]>/$NewOldBody/g;
1579
1850
    }
 
1851
    # cleanup all not needed <OTRS_CUSTOMER_ tags
 
1852
    $Notification{Body} =~ s/<OTRS_CUSTOMER_.+?>/-/gi;
 
1853
    $Notification{Subject} =~ s/<OTRS_CUSTOMER_.+?>/-/gi;
1580
1854
 
1581
1855
    # send notify
1582
1856
    $Self->{SendmailObject}->Send(
1583
1857
        From => $Self->{ConfigObject}->Get('NotificationSenderName').
1584
 
             ' <'.$Self->{ConfigObject}->Get('NotificationSenderEmail').'>',
 
1858
            ' <'.$Self->{ConfigObject}->Get('NotificationSenderEmail').'>',
1585
1859
        To => $User{UserEmail},
1586
1860
        Subject => $Notification{Subject},
1587
 
        'Reply-To' => $Self->{ConfigObject}->Get('NotificationSenderEmail'),
1588
1861
        Type => 'text/plain',
1589
1862
        Charset => $Notification{Charset},
1590
1863
        Body => $Notification{Body},
1607
1880
 
1608
1881
    # ticket event
1609
1882
    $Self->TicketEventHandlerPost(
1610
 
        Event => 'SendAgentNotification',
 
1883
        Event => 'ArticleAgentNotification',
1611
1884
        TicketID => $Param{TicketID},
1612
1885
        UserID => $Param{UserID},
1613
1886
    );
1635
1908
    my %Param = @_;
1636
1909
    # check needed stuff
1637
1910
    foreach (qw(CustomerMessageParams TicketID UserID Type)) {
1638
 
      if (!$Param{$_}) {
1639
 
        $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
1640
 
        return;
1641
 
      }
 
1911
        if (!$Param{$_}) {
 
1912
            $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
 
1913
            return;
 
1914
        }
1642
1915
    }
1643
1916
    # get old article for quoteing
1644
1917
    my %Article = $Self->ArticleLastCustomerArticle(TicketID => $Param{TicketID});
1711
1984
    # replace config options
1712
1985
    $Notification{Body} =~ s{<OTRS_CONFIG_(.+?)>}{$Self->{ConfigObject}->Get($1)}egx;
1713
1986
    $Notification{Subject} =~ s{<OTRS_CONFIG_(.+?)>}{$Self->{ConfigObject}->Get($1)}egx;
 
1987
    # cleanup
 
1988
    $Notification{Subject} =~ s/<OTRS_CONFIG_.+?>/-/gi;
 
1989
    $Notification{Body} =~ s/<OTRS_CONFIG_.+?>/-/gi;
1714
1990
 
1715
1991
    # COMPAT
1716
 
    $Notification{Body} =~ s/<OTRS_TICKET_ID>/$Param{TicketID}/g;
1717
 
    $Notification{Body} =~ s/<OTRS_TICKET_NUMBER>/$Article{TicketNumber}/g;
1718
 
    $Notification{Body} =~ s/<OTRS_QUEUE>/$Param{Queue}/g if ($Param{Queue});
 
1992
    $Notification{Body} =~ s/<OTRS_TICKET_ID>/$Param{TicketID}/gi;
 
1993
    $Notification{Body} =~ s/<OTRS_TICKET_NUMBER>/$Article{TicketNumber}/gi;
 
1994
    $Notification{Body} =~ s/<OTRS_QUEUE>/$Param{Queue}/gi if ($Param{Queue});
1719
1995
    # ticket data
1720
1996
    my %Ticket = $Self->TicketGet(TicketID => $Param{TicketID});
1721
1997
    foreach (keys %Ticket) {
1728
2004
    $Notification{Subject} =~ s/<OTRS_TICKET_.+?>/-/gi;
1729
2005
    $Notification{Body} =~ s/<OTRS_TICKET_.+?>/-/gi;
1730
2006
 
1731
 
    # get owner data
1732
 
    my ($OwnerID, $Owner) = $Self->OwnerCheck(TicketID => $Param{TicketID});
1733
 
    my %Preferences = $Self->{UserObject}->GetUserData(UserID => $OwnerID);
1734
 
    foreach (keys %Preferences) {
1735
 
        if ($Preferences{$_}) {
1736
 
            $Notification{Body} =~ s/<OTRS_OWNER_$_>/$Preferences{$_}/gi;
1737
 
            $Notification{Subject} =~ s/<OTRS_OWNER_$_>/$Preferences{$_}/gi;
1738
 
        }
1739
 
    }
1740
 
    # cleanup
1741
 
    $Notification{Subject} =~ s/<OTRS_OWNER_.+?>/-/gi;
1742
 
    $Notification{Body} =~ s/<OTRS_OWNER_.+?>/-/gi;
1743
 
 
1744
2007
    # get current user data
1745
2008
    my %CurrentPreferences = $Self->{UserObject}->GetUserData(UserID => $Param{UserID});
1746
2009
    foreach (keys %CurrentPreferences) {
1753
2016
    $Notification{Subject} =~ s/<OTRS_CURRENT_.+?>/-/gi;
1754
2017
    $Notification{Body} =~ s/<OTRS_CURRENT_.+?>/-/gi;
1755
2018
 
 
2019
    # get owner data
 
2020
    my %OwnerPreferences = $Self->{UserObject}->GetUserData(
 
2021
        UserID => $Article{OwnerID},
 
2022
    );
 
2023
    foreach (keys %OwnerPreferences) {
 
2024
        if ($OwnerPreferences{$_}) {
 
2025
            $Notification{Body} =~ s/<OTRS_OWNER_$_>/$OwnerPreferences{$_}/gi;
 
2026
            $Notification{Subject} =~ s/<OTRS_OWNER_$_>/$OwnerPreferences{$_}/gi;
 
2027
        }
 
2028
    }
 
2029
    # cleanup
 
2030
    $Notification{Subject} =~ s/<OTRS_OWNER_.+?>/-/gi;
 
2031
    $Notification{Body} =~ s/<OTRS_OWNER_.+?>/-/gi;
 
2032
 
 
2033
    # get responsible data
 
2034
    my %ResponsiblePreferences = $Self->{UserObject}->GetUserData(
 
2035
        UserID => $Article{ResponsibleID},
 
2036
    );
 
2037
    foreach (keys %ResponsiblePreferences) {
 
2038
        if ($ResponsiblePreferences{$_}) {
 
2039
            $Notification{Body} =~ s/<OTRS_RESPONSIBLE_$_>/$ResponsiblePreferences{$_}/gi;
 
2040
            $Notification{Subject} =~ s/<OTRS_RESPONSIBLE_$_>/$ResponsiblePreferences{$_}/gi;
 
2041
        }
 
2042
    }
 
2043
    # cleanup
 
2044
    $Notification{Subject} =~ s/<OTRS_RESPONSIBLE_.+?>/-/gi;
 
2045
    $Notification{Body} =~ s/<OTRS_RESPONSIBLE_.+?>/-/gi;
 
2046
 
1756
2047
    # get ref of email params
1757
2048
    my %GetParam = %{$Param{CustomerMessageParams}};
1758
2049
    foreach (keys %GetParam) {
1817
2108
        chomp $NewOldBody;
1818
2109
        $Notification{Body} =~ s/<OTRS_CUSTOMER_EMAIL\[.+?\]>/$NewOldBody/g;
1819
2110
    }
 
2111
    # cleanup all not needed <OTRS_CUSTOMER_ tags
 
2112
    $Notification{Body} =~ s/<OTRS_CUSTOMER_.+?>/-/gi;
 
2113
    $Notification{Subject} =~ s/<OTRS_CUSTOMER_.+?>/-/gi;
1820
2114
 
1821
2115
    # send notify
1822
2116
    my %Address = $Self->{QueueObject}->GetSystemAddress(QueueID => $Article{QueueID});
1844
2138
 
1845
2139
    # ticket event
1846
2140
    $Self->TicketEventHandlerPost(
1847
 
        Event => 'SendCustomerNotification',
 
2141
        Event => 'ArticleCustomerNotification',
1848
2142
        TicketID => $Param{TicketID},
1849
2143
        UserID => $Param{UserID},
1850
2144
    );
1876
2170
    my %Param = @_;
1877
2171
    # check needed stuff
1878
2172
    foreach (qw(Text Realname Address CustomerMessageParams TicketID UserID HistoryType)) {
1879
 
      if (!$Param{$_}) {
1880
 
        $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
1881
 
        return;
1882
 
      }
 
2173
        if (!$Param{$_}) {
 
2174
            $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
 
2175
            return;
 
2176
        }
1883
2177
    }
1884
2178
    $Param{Body} = $Param{Text} || 'No Std. Body found!';
1885
2179
    my %GetParam = %{$Param{CustomerMessageParams}};
1923
2217
            $Param{Body} =~ s/<OTRS_CUSTOMER_$_>/$GetParam{$_}/gi;
1924
2218
        }
1925
2219
    }
 
2220
 
 
2221
    # get current user data
 
2222
    my %CurrentPreferences = $Self->{UserObject}->GetUserData(UserID => $Param{UserID});
 
2223
    foreach (keys %CurrentPreferences) {
 
2224
        if ($CurrentPreferences{$_}) {
 
2225
            $Param{Body} =~ s/<OTRS_CURRENT_$_>/$CurrentPreferences{$_}/gi;
 
2226
            $Param{Subject} =~ s/<OTRS_CURRENT_$_>/$CurrentPreferences{$_}/gi;
 
2227
        }
 
2228
    }
 
2229
    # cleanup
 
2230
    $Param{Subject} =~ s/<OTRS_CURRENT_.+?>/-/gi;
 
2231
    $Param{Body} =~ s/<OTRS_CURRENT_.+?>/-/gi;
 
2232
 
 
2233
    # get owner data
 
2234
    my %OwnerPreferences = $Self->{UserObject}->GetUserData(
 
2235
        UserID => $Article{OwnerID},
 
2236
    );
 
2237
    foreach (keys %OwnerPreferences) {
 
2238
        if ($OwnerPreferences{$_}) {
 
2239
            $Param{Body} =~ s/<OTRS_OWNER_$_>/$OwnerPreferences{$_}/gi;
 
2240
            $Param{Subject} =~ s/<OTRS_OWNER_$_>/$OwnerPreferences{$_}/gi;
 
2241
        }
 
2242
    }
 
2243
    # cleanup
 
2244
    $Param{Subject} =~ s/<OTRS_OWNER_.+?>/-/gi;
 
2245
    $Param{Body} =~ s/<OTRS_OWNER_.+?>/-/gi;
 
2246
 
 
2247
    # get responsible data
 
2248
    my %ResponsiblePreferences = $Self->{UserObject}->GetUserData(
 
2249
        UserID => $Article{ResponsibleID},
 
2250
    );
 
2251
    foreach (keys %ResponsiblePreferences) {
 
2252
        if ($ResponsiblePreferences{$_}) {
 
2253
            $Param{Body} =~ s/<OTRS_RESPONSIBLE_$_>/$ResponsiblePreferences{$_}/gi;
 
2254
            $Param{Subject} =~ s/<OTRS_RESPONSIBLE_$_>/$ResponsiblePreferences{$_}/gi;
 
2255
        }
 
2256
    }
 
2257
 
 
2258
    # cleanup
 
2259
    $Param{Subject} =~ s/<OTRS_RESPONSIBLE_.+?>/-/gi;
 
2260
    $Param{Body} =~ s/<OTRS_RESPONSIBLE_.+?>/-/gi;
 
2261
 
 
2262
    # ticket data
 
2263
    my %Ticket = $Self->TicketGet(TicketID => $Param{TicketID});
 
2264
    foreach (keys %Ticket) {
 
2265
        if (defined($Ticket{$_})) {
 
2266
            $Param{Body} =~ s/<OTRS_TICKET_$_>/$Ticket{$_}/gi;
 
2267
            $Param{Subject} =~ s/<OTRS_TICKET_$_>/$Ticket{$_}/gi;
 
2268
        }
 
2269
    }
1926
2270
    # replace some special stuff
1927
2271
    $Param{Body} =~ s/<OTRS_TICKET_NUMBER>/$Article{TicketNumber}/gi;
1928
2272
    $Param{Body} =~ s/<OTRS_TICKET_ID>/$Param{TicketID}/gi;
 
2273
    # cleanup
 
2274
    $Param{Subject} =~ s/<OTRS_TICKET_.+?>/-/gi;
 
2275
    $Param{Body} =~ s/<OTRS_TICKET_.+?>/-/gi;
 
2276
 
 
2277
    # get customer data and replace it with <OTRS_CUSTOMER_DATA_...
 
2278
    if ($Article{CustomerUserID}) {
 
2279
        my %CustomerUser = $Self->{CustomerUserObject}->CustomerUserDataGet(
 
2280
            User => $Article{CustomerUserID},
 
2281
        );
 
2282
        # replace customer stuff with tags
 
2283
        foreach (keys %CustomerUser) {
 
2284
            if ($CustomerUser{$_}) {
 
2285
                $Param{Body} =~ s/<OTRS_CUSTOMER_DATA_$_>/$CustomerUser{$_}/gi;
 
2286
                $Param{Subject} =~ s/<OTRS_CUSTOMER_DATA_$_>/$CustomerUser{$_}/gi;
 
2287
            }
 
2288
        }
 
2289
    }
 
2290
    # cleanup all not needed <OTRS_CUSTOMER_DATA_ tags
 
2291
    $Param{Body} =~ s/<OTRS_CUSTOMER_DATA_.+?>/-/gi;
 
2292
    $Param{Subject} =~ s/<OTRS_CUSTOMER_DATA_.+?>/-/gi;
 
2293
 
 
2294
    # replace config options
 
2295
    $Param{Body} =~ s{<OTRS_CONFIG_(.+?)>}{$Self->{ConfigObject}->Get($1)}egx;
 
2296
    $Param{Subject} =~ s{<OTRS_CONFIG_(.+?)>}{$Self->{ConfigObject}->Get($1)}egx;
1929
2297
    # prepare customer realname
1930
2298
    if ($Param{Body} =~ /<OTRS_CUSTOMER_REALNAME>/) {
1931
2299
        # get realname
1969
2337
    $Subject = $Self->TicketSubjectBuild(
1970
2338
        TicketNumber => $Article{TicketNumber},
1971
2339
        Subject => $Subject || '',
 
2340
        Type => 'New',
1972
2341
    );
1973
2342
    # prepare body (insert old email)
1974
2343
    if ($Param{Body} =~ /<OTRS_CUSTOMER_EMAIL\[(.+?)\]>/g) {
1985
2354
        chomp $NewOldBody;
1986
2355
        $Param{Body} =~ s/<OTRS_CUSTOMER_EMAIL\[.+?\]>/$NewOldBody/g;
1987
2356
    }
 
2357
    # cleanup all not needed <OTRS_CUSTOMER_ tags
 
2358
    $Param{Body} =~ s/<OTRS_CUSTOMER_.+?>/-/gi;
 
2359
    $Param{Subject} =~ s/<OTRS_CUSTOMER_.+?>/-/gi;
 
2360
 
1988
2361
    # set new To address if customer user id is used
1989
2362
    my $Cc = '';
1990
2363
    my $ToAll = $GetParam{From};
2025
2398
 
2026
2399
    # ticket event
2027
2400
    $Self->TicketEventHandlerPost(
2028
 
        Event => 'SendAutoResponse',
 
2401
        Event => 'ArticleAutoResponse',
2029
2402
        TicketID => $Param{TicketID},
2030
2403
        UserID => $Param{UserID},
2031
2404
    );
2050
2423
    my %Param = @_;
2051
2424
    # check needed stuff
2052
2425
    foreach (qw(ArticleID Flag UserID)) {
2053
 
      if (!$Param{$_}) {
2054
 
        $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
2055
 
        return;
2056
 
      }
 
2426
        if (!$Param{$_}) {
 
2427
            $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
 
2428
            return;
 
2429
        }
2057
2430
    }
2058
2431
    # db quote
2059
2432
    foreach (qw(Flag)) {
2067
2440
        # do db insert
2068
2441
        $Self->{DBObject}->Do(
2069
2442
            SQL => "DELETE FROM article_flag WHERE ".
2070
 
              "article_id = $Param{ArticleID} AND create_by = $Param{UserID}",
 
2443
                "article_id = $Param{ArticleID} AND create_by = $Param{UserID}",
2071
2444
        );
2072
2445
        return $Self->{DBObject}->Do(SQL => "INSERT INTO article_flag ".
2073
2446
            " (article_id, article_flag, create_time, create_by) ".
2103
2476
    my %Flag = ();
2104
2477
    # check needed stuff
2105
2478
    foreach (qw(ArticleID UserID)) {
2106
 
      if (!$Param{$_}) {
2107
 
        $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
2108
 
        return;
2109
 
      }
 
2479
        if (!$Param{$_}) {
 
2480
            $Self->{LogObject}->Log(Priority => 'error', Message => "Need $_!");
 
2481
            return;
 
2482
        }
2110
2483
    }
2111
2484
    # db quote
2112
2485
    foreach (qw(ArticleID UserID)) {
2140
2513
    my $AccountedTime = 0;
2141
2514
    # check needed stuff
2142
2515
    if (!$Param{ArticleID}) {
2143
 
      $Self->{LogObject}->Log(Priority => 'error', Message => "Need ArticleID!");
2144
 
      return;
 
2516
        $Self->{LogObject}->Log(Priority => 'error', Message => "Need ArticleID!");
 
2517
        return;
2145
2518
    }
2146
2519
    # db quote
2147
2520
    foreach (qw(ArticleID)) {
2152
2525
        " FROM " .
2153
2526
        " time_accounting " .
2154
2527
        " WHERE " .
2155
 
        " article_id = $Param{ArticleID} " .
2156
 
        "  ";
 
2528
        " article_id = $Param{ArticleID}";
2157
2529
    $Self->{DBObject}->Prepare(SQL => $SQL);
2158
2530
    while (my @Row = $Self->{DBObject}->FetchrowArray()) {
 
2531
        $Row[0] =~ s/,/./g;
2159
2532
        $AccountedTime = $AccountedTime + $Row[0];
2160
2533
    }
2161
2534
    return $AccountedTime;
2162
2535
}
2163
2536
 
2164
 
 
2165
 
# --
 
2537
=item ArticleAccountedTimeDelete()
 
2538
 
 
2539
delete accounted time of article
 
2540
 
 
2541
  $TicketObject->ArticleAccountedTimeDelete(
 
2542
    ArticleID => $ArticleID,
 
2543
  );
 
2544
 
 
2545
=cut
 
2546
 
 
2547
sub ArticleAccountedTimeDelete {
 
2548
    my $Self = shift;
 
2549
    my %Param = @_;
 
2550
    # check needed stuff
 
2551
    if (!$Param{ArticleID}) {
 
2552
        $Self->{LogObject}->Log(Priority => 'error', Message => "Need ArticleID!");
 
2553
        return;
 
2554
    }
 
2555
    # db quote
 
2556
    foreach (qw(ArticleID UserID)) {
 
2557
        $Param{$_} = $Self->{DBObject}->Quote($Param{$_}, 'Integer');
 
2558
    }
 
2559
    # db query
 
2560
    my $SQL = "DELETE FROM time_accounting " .
 
2561
        " WHERE " .
 
2562
        " article_id = $Param{ArticleID}";
 
2563
    return $Self->{DBObject}->Do(SQL => $SQL);
 
2564
}
 
2565
 
2166
2566
# the following is the pod for Kernel/System/Ticket/ArticleStorage*.pm
2167
2567
 
2168
2568
=item ArticleDelete()
2174
2574
      UserID => 123,
2175
2575
  );
2176
2576
 
2177
 
 
2178
2577
=item ArticleDeletePlain()
2179
2578
 
2180
2579
delete a artile plain message
2184
2583
      UserID => 123,
2185
2584
  );
2186
2585
 
2187
 
 
2188
2586
=item ArticleDeleteAttachment()
2189
2587
 
2190
2588
delete all attachments of an article
2194
2592
      UserID => 123,
2195
2593
  );
2196
2594
 
2197
 
 
2198
2595
=item ArticleWritePlain()
2199
2596
 
2200
2597
write an plain email to storage
2205
2602
      UserID => 123,
2206
2603
  );
2207
2604
 
2208
 
 
2209
2605
=item ArticlePlain()
2210
2606
 
2211
2607
get plain message/email
2215
2611
      UserID => 123,
2216
2612
  );
2217
2613
 
2218
 
 
2219
2614
=item ArticleWriteAttachment()
2220
2615
 
2221
2616
write an article attachemnt to storage
2228
2623
      UserID => 123,
2229
2624
  );
2230
2625
 
2231
 
 
2232
2626
=item ArticleAttachmentIndex()
2233
2627
 
2234
2628
get article attachment index as hash (ID => hashref (Filename, Filesize))
2235
2629
 
2236
 
  my %Index = $TicketObject->ArticleAttachment(
 
2630
  my %Index = $TicketObject->ArticleAttachmentIndex(
2237
2631
      ArticleID => 123,
2238
2632
      UserID => 123,
2239
2633
  );
2240
2634
 
2241
 
 
2242
2635
=item ArticleAttachment()
2243
2636
 
2244
2637
get article attachment (Content, ContentType, Filename)