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

« back to all changes in this revision

Viewing changes to Kernel/Modules/AgentTicketPriority.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
 
# Kernel/Modules/AgentTicketPriority.pm - to set the ticket priority
3
 
# Copyright (C) 2001-2005 Martin Edenhofer <martin+code@otrs.org>
 
2
# Kernel/Modules/AgentTicketPriority.pm - set ticket priority
 
3
# Copyright (C) 2001-2007 OTRS GmbH, http://otrs.org/
4
4
# --
5
 
# $Id: AgentTicketPriority.pm,v 1.3 2005/05/04 08:04:02 martin Exp $
 
5
# $Id: AgentTicketPriority.pm,v 1.13.2.1 2007/02/26 11:12:28 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
12
12
package Kernel::Modules::AgentTicketPriority;
13
13
 
14
14
use strict;
 
15
use Kernel::System::State;
 
16
use Kernel::System::Web::UploadCache;
15
17
 
16
18
use vars qw($VERSION);
17
 
$VERSION = '$Revision: 1.3 $';
 
19
$VERSION = '$Revision: 1.13.2.1 $';
18
20
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;
19
21
 
20
 
# --
21
22
sub new {
22
23
    my $Type = shift;
23
24
    my %Param = @_;
31
32
    }
32
33
 
33
34
    # check needed Opjects
34
 
    foreach (qw(ParamObject DBObject TicketObject LayoutObject LogObject QueueObject ConfigObject UserObject)) {
 
35
    foreach (qw(ParamObject DBObject TicketObject LayoutObject LogObject QueueObject ConfigObject)) {
35
36
        if (!$Self->{$_}) {
36
37
            $Self->{LayoutObject}->FatalError(Message => "Got no $_!");
37
38
        }
38
39
    }
39
 
 
40
 
    # get  PriorityID
41
 
    $Self->{PriorityID} = $Self->{ParamObject}->GetParam(Param => 'PriorityID') || '';
 
40
    $Self->{StateObject} = Kernel::System::State->new(%Param);
 
41
    $Self->{UploadCachObject} = Kernel::System::Web::UploadCache->new(%Param);
 
42
 
 
43
    # get form id
 
44
    $Self->{FormID} = $Self->{ParamObject}->GetParam(Param => 'FormID');
 
45
    my @InformUserID = $Self->{ParamObject}->GetArray(Param => 'InformUserID');
 
46
    $Self->{InformUserID} = \@InformUserID;
 
47
    my @InvolvedUserID = $Self->{ParamObject}->GetArray(Param => 'InvolvedUserID');
 
48
    $Self->{InvolvedUserID} = \@InvolvedUserID;
 
49
    # create form id
 
50
    if (!$Self->{FormID}) {
 
51
        $Self->{FormID} = $Self->{UploadCachObject}->FormIDCreate();
 
52
    }
 
53
 
 
54
    $Self->{Config} = $Self->{ConfigObject}->Get("Ticket::Frontend::$Self->{Action}");
42
55
 
43
56
    return $Self;
44
57
}
45
 
# --
 
58
 
46
59
sub Run {
47
60
    my $Self = shift;
48
61
    my %Param = @_;
51
64
    if (!$Self->{TicketID}) {
52
65
        # error page
53
66
        return $Self->{LayoutObject}->ErrorScreen(
54
 
            Message => "No TicketID is given!",
 
67
            Message => "Need TicketID is given!",
55
68
            Comment => 'Please contact the admin.',
56
69
        );
57
70
    }
58
71
    # check permissions
59
72
    if (!$Self->{TicketObject}->Permission(
60
 
        Type => 'priority',
 
73
        Type => $Self->{Config}->{Permission},
61
74
        TicketID => $Self->{TicketID},
62
75
        UserID => $Self->{UserID})) {
63
76
        # error screen, don't show ticket
64
 
        return $Self->{LayoutObject}->NoPermission(WithHeader => 'yes');
65
 
    }
66
 
    else {
67
 
        my ($OwnerID, $OwnerLogin) = $Self->{TicketObject}->OwnerCheck(
68
 
            TicketID => $Self->{TicketID},
 
77
        return $Self->{LayoutObject}->NoPermission(
 
78
            Message => "You need $Self->{Config}->{Permission} permissions!",
 
79
            WithHeader => 'yes',
69
80
        );
70
 
        if ($OwnerID != $Self->{UserID}) {
71
 
            $Output .= $Self->{LayoutObject}->Header(Title => 'Error');
72
 
            $Output .= $Self->{LayoutObject}->Warning(
73
 
                Message => "Sorry, the current owner is $OwnerLogin!",
74
 
                Comment => 'Please change the owner first.',
75
 
            );
76
 
            $Output .= $Self->{LayoutObject}->Footer();
77
 
            return $Output;
78
 
        }
79
81
    }
 
82
    my %Ticket = $Self->{TicketObject}->TicketGet(TicketID => $Self->{TicketID});
 
83
    $Self->{LayoutObject}->Block(
 
84
        Name => 'Properties',
 
85
        Data => {
 
86
            FormID => $Self->{FormID},
 
87
            %Ticket,
 
88
            %Param,
 
89
        },
 
90
    );
80
91
 
81
 
    if ($Self->{Subaction} eq 'Update') {
82
 
        # set id
83
 
        if ($Self->{TicketObject}->PrioritySet(
84
 
            TicketID => $Self->{TicketID},
85
 
            PriorityID => $Self->{PriorityID},
86
 
            UserID => $Self->{UserID},
87
 
        )) {
88
 
            # print redirect
89
 
            return $Self->{LayoutObject}->Redirect(OP => $Self->{LastScreenView});
 
92
    # get lock state
 
93
    if ($Self->{Config}->{RequiredLock}) {
 
94
        if (!$Self->{TicketObject}->LockIsTicketLocked(TicketID => $Self->{TicketID})) {
 
95
            $Self->{TicketObject}->LockSet(
 
96
                TicketID => $Self->{TicketID},
 
97
                Lock => 'lock',
 
98
                UserID => $Self->{UserID}
 
99
            );
 
100
            if ($Self->{TicketObject}->OwnerSet(
 
101
                TicketID => $Self->{TicketID},
 
102
                UserID => $Self->{UserID},
 
103
                NewUserID => $Self->{UserID},
 
104
            )) {
 
105
                # show lock state
 
106
                $Self->{LayoutObject}->Block(
 
107
                    Name => 'PropertiesLock',
 
108
                    Data => {
 
109
                        %Param,
 
110
                        TicketID => $Self->{TicketID},
 
111
                    },
 
112
                );
 
113
            }
90
114
        }
91
115
        else {
92
 
            $Output .= $Self->{LayoutObject}->Header(Title => 'Warning');
93
 
            $Output .= $Self->{LayoutObject}->Warning();
94
 
            $Output .= $Self->{LayoutObject}->Footer();
95
 
            return $Output;
 
116
            my $AccessOk = $Self->{TicketObject}->OwnerCheck(
 
117
                TicketID => $Self->{TicketID},
 
118
                OwnerID => $Self->{UserID},
 
119
            );
 
120
            if (!$AccessOk) {
 
121
                my $Output = $Self->{LayoutObject}->Header(Value => $Ticket{Number});
 
122
                $Output .= $Self->{LayoutObject}->Warning(
 
123
                    Message => "Sorry, you need to be the owner to do this action!",
 
124
                    Comment => 'Please change the owner first.',
 
125
                );
 
126
                $Output .= $Self->{LayoutObject}->Footer();
 
127
                return $Output;
 
128
            }
 
129
            else {
 
130
                $Self->{LayoutObject}->Block(
 
131
                    Name => 'TicketBack',
 
132
                    Data => {
 
133
                        %Param,
 
134
                        TicketID => $Self->{TicketID},
 
135
                    },
 
136
                );
 
137
            }
96
138
        }
97
139
    }
98
140
    else {
99
 
        # print form
100
 
        my %Ticket = $Self->{TicketObject}->TicketGet(TicketID => $Self->{TicketID});
101
 
        $Output .= $Self->{LayoutObject}->Header(Value => $Ticket{TicketNumber});
102
 
        $Output .= $Self->{LayoutObject}->NavigationBar();
103
 
        # get and priority priority states
104
 
        $Param{'OptionStrg'} = $Self->{LayoutObject}->OptionStrgHashRef(
 
141
        $Self->{LayoutObject}->Block(
 
142
            Name => 'TicketBack',
105
143
            Data => {
106
 
                $Self->{TicketObject}->PriorityList(
107
 
                    UserID => $Self->{UserID},
108
 
                    TicketID => $Ticket{TicketID},
109
 
                ),
 
144
                %Param,
 
145
                %Ticket,
110
146
            },
111
 
            Name => 'PriorityID',
112
 
            SelectedID => $Ticket{PriorityID},
113
 
        );
114
 
        # create & return output
115
 
        $Output .= $Self->{LayoutObject}->Output(
116
 
            TemplateFile => 'AgentTicketPriority',
117
 
            Data => { %Param, %Ticket, },
 
147
        );
 
148
    }
 
149
 
 
150
    # get params
 
151
    my %GetParam = ();
 
152
    foreach (qw(
 
153
        NewStateID NewPriorityID TimeUnits ArticleTypeID Title Body Subject
 
154
        Year Month Day Hour Minute NewOwnerID NewOwnerType OldOwnerID NewResponsibleID
 
155
        AttachmentUpload
 
156
        AttachmentDelete1 AttachmentDelete2 AttachmentDelete3 AttachmentDelete4
 
157
        AttachmentDelete5 AttachmentDelete6 AttachmentDelete7 AttachmentDelete8
 
158
        AttachmentDelete9 AttachmentDelete10 AttachmentDelete11 AttachmentDelete12
 
159
        AttachmentDelete13 AttachmentDelete14 AttachmentDelete15 AttachmentDelete16
 
160
    )) {
 
161
        $GetParam{$_} = $Self->{ParamObject}->GetParam(Param => $_);
 
162
    }
 
163
    # get ticket free text params
 
164
    foreach (1..16) {
 
165
        $GetParam{"TicketFreeKey$_"} =  $Self->{ParamObject}->GetParam(Param => "TicketFreeKey$_");
 
166
        $GetParam{"TicketFreeText$_"} =  $Self->{ParamObject}->GetParam(Param => "TicketFreeText$_");
 
167
    }
 
168
    # get ticket free text params
 
169
    foreach (1..2) {
 
170
        foreach my $Type (qw(Year Month Day Hour Minute)) {
 
171
            $GetParam{"TicketFreeTime".$_.$Type} =  $Self->{ParamObject}->GetParam(Param => "TicketFreeTime".$_.$Type);
 
172
        }
 
173
    }
 
174
    # get article free text params
 
175
    foreach (1..3) {
 
176
        $GetParam{"ArticleFreeKey$_"} =  $Self->{ParamObject}->GetParam(Param => "ArticleFreeKey$_");
 
177
        $GetParam{"ArticleFreeText$_"} =  $Self->{ParamObject}->GetParam(Param => "ArticleFreeText$_");
 
178
    }
 
179
    # rewrap body if exists
 
180
    if ($GetParam{Body}) {
 
181
        my $Size = $Self->{ConfigObject}->Get('Ticket::Frontend::TextAreaNote') || 70;
 
182
        $GetParam{Body} =~ s/(^>.+|.{4,$Size})(?:\s|\z)/$1\n/gm;
 
183
    }
 
184
 
 
185
    if ($Self->{Subaction} eq 'Store') {
 
186
        # store action
 
187
        my %Error = ();
 
188
        # check pending time
 
189
        if ($GetParam{NewStateID}) {
 
190
            my %StateData = $Self->{TicketObject}->{StateObject}->StateGet(
 
191
                ID => $GetParam{NewStateID},
 
192
            );
 
193
            # check state type
 
194
            if ($StateData{TypeName} =~ /^pending/i) {
 
195
                # check needed stuff
 
196
                foreach (qw(Year Month Day Hour Minute)) {
 
197
                    if (!defined($GetParam{$_})) {
 
198
                        $Error{"Date invalid"} = '* invalid';
 
199
                    }
 
200
                }
 
201
                # check date
 
202
                if (!$Self->{TimeObject}->Date2SystemTime(%GetParam, Second => 0)) {
 
203
                    $Error{"Date invalid"} = '* invalid';
 
204
                }
 
205
                if ($Self->{TimeObject}->Date2SystemTime(%GetParam, Second => 0) < $Self->{TimeObject}->SystemTime()) {
 
206
                    $Error{"Date invalid"} = '* invalid';
 
207
                }
 
208
            }
 
209
        }
 
210
        if ($Self->{Config}->{Note}) {
 
211
            # check subject
 
212
            if (!$GetParam{Subject}) {
 
213
                $Error{"Subject invalid"} = '* invalid';
 
214
            }
 
215
            # check body
 
216
            if (!$GetParam{Body}) {
 
217
                $Error{"Body invalid"} = '* invalid';
 
218
            }
 
219
        }
 
220
        # attachment delete
 
221
        foreach (1..16) {
 
222
            if ($GetParam{"AttachmentDelete$_"}) {
 
223
                $Error{AttachmentDelete} = 1;
 
224
                $Self->{UploadCachObject}->FormIDRemoveFile(
 
225
                    FormID => $Self->{FormID},
 
226
                    FileID => $_,
 
227
                );
 
228
            }
 
229
        }
 
230
        # attachment upload
 
231
        if ($GetParam{AttachmentUpload}) {
 
232
            $Error{AttachmentUpload} = 1;
 
233
            my %UploadStuff = $Self->{ParamObject}->GetUploadAll(
 
234
                Param => "file_upload",
 
235
                Source => 'string',
 
236
            );
 
237
            $Self->{UploadCachObject}->FormIDAddFile(
 
238
                FormID => $Self->{FormID},
 
239
                %UploadStuff,
 
240
            );
 
241
        }
 
242
        # get all attachments meta data
 
243
        my @Attachments = $Self->{UploadCachObject}->FormIDGetAllFilesMeta(
 
244
            FormID => $Self->{FormID},
 
245
        );
 
246
        # check errors
 
247
        if (%Error) {
 
248
            # ticket free text
 
249
            my %TicketFreeText = ();
 
250
            foreach (1..16) {
 
251
                $TicketFreeText{"TicketFreeKey$_"} = $Self->{TicketObject}->TicketFreeTextGet(
 
252
                    TicketID => $Self->{TicketID},
 
253
                    Type => "TicketFreeKey$_",
 
254
                    Action => $Self->{Action},
 
255
                    UserID => $Self->{UserID},
 
256
                );
 
257
                $TicketFreeText{"TicketFreeText$_"} = $Self->{TicketObject}->TicketFreeTextGet(
 
258
                    TicketID => $Self->{TicketID},
 
259
                    Type => "TicketFreeText$_",
 
260
                    Action => $Self->{Action},
 
261
                    UserID => $Self->{UserID},
 
262
                );
 
263
            }
 
264
            my %TicketFreeTextHTML = $Self->{LayoutObject}->AgentFreeText(
 
265
                Config => \%TicketFreeText,
 
266
                Ticket => \%GetParam,
 
267
            );
 
268
            # ticket free time
 
269
            my %TicketFreeTimeHTML = $Self->{LayoutObject}->AgentFreeDate(
 
270
                %Param,
 
271
                Ticket => \%GetParam,
 
272
            );
 
273
            # article free text
 
274
            my %ArticleFreeText = ();
 
275
            foreach (1..3) {
 
276
                $ArticleFreeText{"ArticleFreeKey$_"} = $Self->{TicketObject}->ArticleFreeTextGet(
 
277
                    TicketID => $Self->{TicketID},
 
278
                    Type => "ArticleFreeKey$_",
 
279
                    Action => $Self->{Action},
 
280
                    UserID => $Self->{UserID},
 
281
                );
 
282
                $ArticleFreeText{"ArticleFreeText$_"} = $Self->{TicketObject}->ArticleFreeTextGet(
 
283
                    TicketID => $Self->{TicketID},
 
284
                    Type => "ArticleFreeText$_",
 
285
                    Action => $Self->{Action},
 
286
                    UserID => $Self->{UserID},
 
287
                );
 
288
            }
 
289
            my %ArticleFreeTextHTML = $Self->{LayoutObject}->TicketArticleFreeText(
 
290
                Config => \%ArticleFreeText,
 
291
                Article => \%GetParam,
 
292
            );
 
293
            my $Output = $Self->{LayoutObject}->Header(Value => $Ticket{TicketNumber});
 
294
            $Output .= $Self->{LayoutObject}->NavigationBar();
 
295
            $Output .= $Self->_Mask(
 
296
                Attachments => \@Attachments,
 
297
                %Ticket,
 
298
                %TicketFreeTextHTML,
 
299
                %TicketFreeTimeHTML,
 
300
                %ArticleFreeTextHTML,
 
301
                %GetParam,
 
302
                %Error,
 
303
            );
 
304
            $Output .= $Self->{LayoutObject}->Footer();
 
305
            return $Output;
 
306
        }
 
307
        if ($Self->{Config}->{Title}) {
 
308
            if (defined($GetParam{Title})) {
 
309
                $Self->{TicketObject}->TicketTitleUpdate(
 
310
                    Title => $GetParam{Title},
 
311
                    TicketID => $Self->{TicketID},
 
312
                    UserID => $Self->{UserID},
 
313
                );
 
314
            }
 
315
        }
 
316
        if ($Self->{Config}->{Owner}) {
 
317
            if ($GetParam{NewOwnerType} eq 'Old' && $GetParam{OldOwnerID}) {
 
318
                $Self->{TicketObject}->LockSet(
 
319
                    TicketID => $Self->{TicketID},
 
320
                    Lock => 'lock',
 
321
                    UserID => $Self->{UserID},
 
322
                );
 
323
                $Self->{TicketObject}->OwnerSet(
 
324
                    TicketID => $Self->{TicketID},
 
325
                    UserID => $Self->{UserID},
 
326
                    NewUserID => $GetParam{OldOwnerID},
 
327
                    Comment => $GetParam{Body},
 
328
                );
 
329
                $GetParam{NoAgentNotify} = 1;
 
330
            }
 
331
            elsif ($GetParam{NewOwnerID}) {
 
332
                $Self->{TicketObject}->LockSet(
 
333
                    TicketID => $Self->{TicketID},
 
334
                    Lock => 'lock',
 
335
                    UserID => $Self->{UserID},
 
336
                );
 
337
                $Self->{TicketObject}->OwnerSet(
 
338
                    TicketID => $Self->{TicketID},
 
339
                    UserID => $Self->{UserID},
 
340
                    NewUserID => $GetParam{NewOwnerID},
 
341
                    Comment => $GetParam{Body},
 
342
                );
 
343
                $GetParam{NoAgentNotify} = 1;
 
344
            }
 
345
        }
 
346
        if ($Self->{Config}->{Responsible}) {
 
347
            if ($GetParam{NewResponsibleID}) {
 
348
                $Self->{TicketObject}->ResponsibleSet(
 
349
                    TicketID => $Self->{TicketID},
 
350
                    UserID => $Self->{UserID},
 
351
                    NewUserID => $GetParam{NewResponsibleID},
 
352
                    Comment => $GetParam{Body},
 
353
                );
 
354
                $GetParam{NoAgentNotify} = 1;
 
355
            }
 
356
        }
 
357
        # add note
 
358
        my $ArticleID = '';
 
359
        if ($Self->{Config}->{Note}) {
 
360
            $ArticleID = $Self->{TicketObject}->ArticleCreate(
 
361
                TicketID => $Self->{TicketID},
 
362
                SenderType => 'agent',
 
363
                From => "$Self->{UserFirstname} $Self->{UserLastname} <$Self->{UserEmail}>",
 
364
                ContentType => "text/plain; charset=$Self->{LayoutObject}->{'UserCharset'}",
 
365
                UserID => $Self->{UserID},
 
366
                HistoryType => $Self->{Config}->{HistoryType},
 
367
                HistoryComment => $Self->{Config}->{HistoryComment},
 
368
                ForceNotificationToUserID => [@{$Self->{InformUserID}}, @{$Self->{InvolvedUserID}}, ],
 
369
                %GetParam,
 
370
                NoAgentNotify => 0,
 
371
            );
 
372
            if (!$ArticleID) {
 
373
                return $Self->{LayoutObject}->ErrorScreen();
 
374
            }
 
375
            # time accounting
 
376
            if ($GetParam{TimeUnits}) {
 
377
                $Self->{TicketObject}->TicketAccountTime(
 
378
                    TicketID => $Self->{TicketID},
 
379
                    ArticleID => $ArticleID,
 
380
                    TimeUnit => $GetParam{TimeUnits},
 
381
                    UserID => $Self->{UserID},
 
382
                );
 
383
            }
 
384
            # get pre loaded attachment
 
385
            my @AttachmentData = $Self->{UploadCachObject}->FormIDGetAllFilesData(
 
386
                FormID => $Self->{FormID},
 
387
            );
 
388
            foreach my $Ref (@AttachmentData) {
 
389
                $Self->{TicketObject}->ArticleWriteAttachment(
 
390
                    %{$Ref},
 
391
                    ArticleID => $ArticleID,
 
392
                    UserID => $Self->{UserID},
 
393
                );
 
394
            }
 
395
            # get submit attachment
 
396
            my %UploadStuff = $Self->{ParamObject}->GetUploadAll(
 
397
                Param => 'file_upload',
 
398
                Source => 'String',
 
399
            );
 
400
            if (%UploadStuff) {
 
401
                $Self->{TicketObject}->ArticleWriteAttachment(
 
402
                    %UploadStuff,
 
403
                    ArticleID => $ArticleID,
 
404
                    UserID => $Self->{UserID},
 
405
                );
 
406
            }
 
407
            # remove pre submited attachments
 
408
            $Self->{UploadCachObject}->FormIDRemove(FormID => $Self->{FormID});
 
409
        }
 
410
        # set ticket free text
 
411
        foreach (1..16) {
 
412
            if (defined($GetParam{"TicketFreeKey$_"})) {
 
413
                $Self->{TicketObject}->TicketFreeTextSet(
 
414
                    TicketID => $Self->{TicketID},
 
415
                    Key => $GetParam{"TicketFreeKey$_"},
 
416
                    Value => $GetParam{"TicketFreeText$_"},
 
417
                    Counter => $_,
 
418
                    UserID => $Self->{UserID},
 
419
                );
 
420
            }
 
421
        }
 
422
        # set ticket free time
 
423
        foreach (1..2) {
 
424
            if (defined($GetParam{"TicketFreeTime".$_."Year"}) &&
 
425
                defined($GetParam{"TicketFreeTime".$_."Month"}) &&
 
426
                defined($GetParam{"TicketFreeTime".$_."Day"}) &&
 
427
                defined($GetParam{"TicketFreeTime".$_."Hour"}) &&
 
428
                defined($GetParam{"TicketFreeTime".$_."Minute"})) {
 
429
                my %Time = $Self->{LayoutObject}->TransfromDateSelection(
 
430
                    %GetParam,
 
431
                    Prefix => "TicketFreeTime".$_,
 
432
                );
 
433
                $Self->{TicketObject}->TicketFreeTimeSet(
 
434
                    %Time,
 
435
                    Prefix => "TicketFreeTime",
 
436
                    TicketID => $Self->{TicketID},
 
437
                    Counter => $_,
 
438
                    UserID => $Self->{UserID},
 
439
                );
 
440
            }
 
441
        }
 
442
        # set article free text
 
443
        foreach (1..3) {
 
444
            if (defined($GetParam{"ArticleFreeKey$_"})) {
 
445
                $Self->{TicketObject}->ArticleFreeTextSet(
 
446
                    TicketID => $Self->{TicketID},
 
447
                    ArticleID => $ArticleID,
 
448
                    Key => $GetParam{"ArticleFreeKey$_"},
 
449
                    Value => $GetParam{"ArticleFreeText$_"},
 
450
                    Counter => $_,
 
451
                    UserID => $Self->{UserID},
 
452
                );
 
453
            }
 
454
        }
 
455
        # set priority
 
456
        if ($Self->{Config}->{Priority} && $GetParam{NewPriorityID}) {
 
457
            $Self->{TicketObject}->PrioritySet(
 
458
                TicketID => $Self->{TicketID},
 
459
                PriorityID => $GetParam{NewPriorityID},
 
460
                UserID => $Self->{UserID},
 
461
            );
 
462
        }
 
463
        # set state
 
464
        if ($Self->{Config}->{State} && $GetParam{NewStateID}) {
 
465
            $Self->{TicketObject}->StateSet(
 
466
                TicketID => $Self->{TicketID},
 
467
                StateID => $GetParam{NewStateID},
 
468
                UserID => $Self->{UserID},
 
469
            );
 
470
            # unlock the ticket after close
 
471
            my %StateData = $Self->{TicketObject}->{StateObject}->StateGet(
 
472
                ID => $GetParam{NewStateID},
 
473
            );
 
474
            # set unlock on close
 
475
            if ($StateData{TypeName} =~ /^close/i) {
 
476
                $Self->{TicketObject}->LockSet(
 
477
                    TicketID => $Self->{TicketID},
 
478
                    Lock => 'unlock',
 
479
                    UserID => $Self->{UserID},
 
480
                );
 
481
            }
 
482
            # set pending time
 
483
            elsif ($StateData{TypeName} =~ /^pending/i) {
 
484
                $Self->{TicketObject}->TicketPendingTimeSet(
 
485
                    UserID => $Self->{UserID},
 
486
                    TicketID => $Self->{TicketID},
 
487
                    %GetParam,
 
488
                );
 
489
            }
 
490
            return $Self->{LayoutObject}->Redirect(OP => $Self->{LastScreenOverview});
 
491
        }
 
492
        # redirect
 
493
        return $Self->{LayoutObject}->Redirect(OP => $Self->{LastScreenView});
 
494
    }
 
495
    else {
 
496
        # fillup vars
 
497
        if (!defined($GetParam{Body}) && $Self->{Config}->{Body}) {
 
498
            $GetParam{Body} = $Self->{LayoutObject}->Output(Template => $Self->{Config}->{Body});
 
499
        }
 
500
        if (!defined($GetParam{Subject}) && $Self->{Config}->{Subject}) {
 
501
            $GetParam{Subject} = $Self->{LayoutObject}->Output(Template => $Self->{Config}->{Subject});
 
502
        }
 
503
        # get free text config options
 
504
        my %TicketFreeText = ();
 
505
        foreach (1..16) {
 
506
            $TicketFreeText{"TicketFreeKey$_"} = $Self->{TicketObject}->TicketFreeTextGet(
 
507
                TicketID => $Self->{TicketID},
 
508
                Type => "TicketFreeKey$_",
 
509
                Action => $Self->{Action},
 
510
                UserID => $Self->{UserID},
 
511
            );
 
512
            $TicketFreeText{"TicketFreeText$_"} = $Self->{TicketObject}->TicketFreeTextGet(
 
513
                TicketID => $Self->{TicketID},
 
514
                Type => "TicketFreeText$_",
 
515
                Action => $Self->{Action},
 
516
                UserID => $Self->{UserID},
 
517
            );
 
518
        }
 
519
        my %TicketFreeTextHTML = $Self->{LayoutObject}->AgentFreeText(
 
520
            Ticket => \%Ticket,
 
521
            Config => \%TicketFreeText,
 
522
        );
 
523
        # get free text params
 
524
        my %TicketFreeTime = ();
 
525
        foreach (1..2) {
 
526
            if ($Ticket{"TicketFreeTime".$_}) {
 
527
                ($TicketFreeTime{"TicketFreeTime".$_.'Secunde'}, $TicketFreeTime{"TicketFreeTime".$_.'Minute'}, $TicketFreeTime{"TicketFreeTime".$_.'Hour'}, $TicketFreeTime{"TicketFreeTime".$_.'Day'}, $TicketFreeTime{"TicketFreeTime".$_.'Month'},  $TicketFreeTime{"TicketFreeTime".$_.'Year'}) = $Self->{TimeObject}->SystemTime2Date(
 
528
                    SystemTime => $Self->{TimeObject}->TimeStamp2SystemTime(
 
529
                        String => $Ticket{"TicketFreeTime".$_},
 
530
                    ),
 
531
                );
 
532
            }
 
533
        }
 
534
        # free time
 
535
        my %TicketFreeTimeHTML = $Self->{LayoutObject}->AgentFreeDate(
 
536
            Ticket => \%TicketFreeTime,
 
537
        );
 
538
        # get article free text config options
 
539
        my %ArticleFreeText = ();
 
540
        foreach (1..3) {
 
541
            $ArticleFreeText{"ArticleFreeKey$_"} = $Self->{TicketObject}->ArticleFreeTextGet(
 
542
                TicketID => $Self->{TicketID},
 
543
                Type => "ArticleFreeKey$_",
 
544
                Action => $Self->{Action},
 
545
                UserID => $Self->{UserID},
 
546
            );
 
547
            $ArticleFreeText{"ArticleFreeText$_"} = $Self->{TicketObject}->ArticleFreeTextGet(
 
548
                TicketID => $Self->{TicketID},
 
549
                Type => "ArticleFreeText$_",
 
550
                Action => $Self->{Action},
 
551
                UserID => $Self->{UserID},
 
552
            );
 
553
        }
 
554
        my %ArticleFreeTextHTML = $Self->{LayoutObject}->TicketArticleFreeText(
 
555
            Config => \%ArticleFreeText,
 
556
            Article => \%GetParam,
 
557
        );
 
558
        # print form ...
 
559
        my $Output = $Self->{LayoutObject}->Header(Value => $Ticket{TicketNumber});
 
560
        $Output .= $Self->{LayoutObject}->NavigationBar();
 
561
        $Output .= $Self->_Mask(
 
562
            %GetParam,
 
563
            %Ticket,
 
564
            %TicketFreeTextHTML,
 
565
            %TicketFreeTimeHTML,
 
566
            %ArticleFreeTextHTML,
118
567
        );
119
568
        $Output .= $Self->{LayoutObject}->Footer();
120
569
        return $Output;
121
570
    }
122
571
}
 
572
 
 
573
sub _Mask {
 
574
    my $Self = shift;
 
575
    my %Param = @_;
 
576
    my %Ticket = $Self->{TicketObject}->TicketGet(TicketID => $Self->{TicketID});
 
577
 
 
578
    if ($Self->{Config}->{Title}) {
 
579
        $Self->{LayoutObject}->Block(
 
580
            Name => 'Title',
 
581
            Data => \%Param,
 
582
        );
 
583
    }
 
584
    if ($Self->{Config}->{Owner}) {
 
585
        # get user of own groups
 
586
        my %ShownUsers = ();
 
587
        my %AllGroupsMembers = $Self->{UserObject}->UserList(
 
588
            Type => 'Long',
 
589
            Valid => 1,
 
590
        );
 
591
        if ($Self->{ConfigObject}->Get('Ticket::ChangeOwnerToEveryone')) {
 
592
            %ShownUsers = %AllGroupsMembers;
 
593
        }
 
594
        else {
 
595
            my $GID = $Self->{QueueObject}->GetQueueGroupID(QueueID => $Ticket{QueueID});
 
596
            my %MemberList = $Self->{GroupObject}->GroupMemberList(
 
597
                GroupID => $GID,
 
598
                Type => 'rw',
 
599
                Result => 'HASH',
 
600
                Cached => 1,
 
601
            );
 
602
            foreach (keys %MemberList) {
 
603
                $ShownUsers{$_} = $AllGroupsMembers{$_};
 
604
            }
 
605
        }
 
606
        # get old owner
 
607
        my @OldUserInfo = $Self->{TicketObject}->OwnerList(TicketID => $Self->{TicketID});
 
608
        $Param{'OwnerStrg'} = $Self->{LayoutObject}->OptionStrgHashRef(
 
609
            Data => \%ShownUsers,
 
610
            SelectedID => $Param{NewOwnerID},
 
611
            Name => 'NewOwnerID',
 
612
            Size => 10,
 
613
            OnClick => "change_selected(0)",
 
614
        );
 
615
        my %UserHash = ();
 
616
        if (@OldUserInfo) {
 
617
            my $Counter = 0;
 
618
            foreach my $User (reverse @OldUserInfo) {
 
619
                if ($Counter) {
 
620
                    if (!$UserHash{$User->{UserID}}) {
 
621
                        $UserHash{$User->{UserID}} = "$Counter: $User->{UserLastname} ".
 
622
                            "$User->{UserFirstname} ($User->{UserLogin})";
 
623
                    }
 
624
                }
 
625
                $Counter++;
 
626
            }
 
627
        }
 
628
        if (!%UserHash) {
 
629
            $UserHash{''} = '-';
 
630
        }
 
631
        # build string
 
632
        $Param{'OldOwnerStrg'} = $Self->{LayoutObject}->OptionStrgHashRef(
 
633
            Data => \%UserHash,
 
634
            SelectedID => $Param{OldOwnerID} || $OldUserInfo[0]->{UserID}.'1',
 
635
            Name => 'OldOwnerID',
 
636
            OnClick => "change_selected(2)",
 
637
        );
 
638
        if ($Param{NewOwnerType} && $Param{NewOwnerType} eq 'Old') {
 
639
            $Param{'NewOwnerType::Old'} = 'checked="checked"';
 
640
        }
 
641
        else {
 
642
            $Param{'NewOwnerType::New'} = 'checked="checked"';
 
643
        }
 
644
        $Self->{LayoutObject}->Block(
 
645
            Name => 'OwnerJs',
 
646
            Data => \%Param,
 
647
        );
 
648
        $Self->{LayoutObject}->Block(
 
649
            Name => 'Owner',
 
650
            Data => \%Param,
 
651
        );
 
652
    }
 
653
    if ($Self->{Config}->{Responsible}) {
 
654
        # get user of own groups
 
655
        my %ShownUsers = ();
 
656
        my %AllGroupsMembers = $Self->{UserObject}->UserList(
 
657
            Type => 'Long',
 
658
            Valid => 1,
 
659
        );
 
660
        if ($Self->{ConfigObject}->Get('Ticket::ChangeOwnerToEveryone')) {
 
661
            %ShownUsers = %AllGroupsMembers;
 
662
        }
 
663
        else {
 
664
            my $GID = $Self->{QueueObject}->GetQueueGroupID(QueueID => $Ticket{QueueID});
 
665
            my %MemberList = $Self->{GroupObject}->GroupMemberList(
 
666
                GroupID => $GID,
 
667
                Type => 'rw',
 
668
                Result => 'HASH',
 
669
                Cached => 1,
 
670
            );
 
671
            foreach (keys %MemberList) {
 
672
                $ShownUsers{$_} = $AllGroupsMembers{$_};
 
673
            }
 
674
        }
 
675
        # get responsible
 
676
        $Param{'ResponsibleStrg'} = $Self->{LayoutObject}->OptionStrgHashRef(
 
677
            Data => \%ShownUsers,
 
678
            SelectedID => $Param{NewResponsibleID} || $Ticket{ResponsibleID},
 
679
            Name => 'NewResponsibleID',
 
680
            Size => 10,
 
681
        );
 
682
        $Self->{LayoutObject}->Block(
 
683
            Name => 'Responsible',
 
684
            Data => \%Param,
 
685
        );
 
686
    }
 
687
    if ($Self->{Config}->{State}) {
 
688
        my %State = ();
 
689
        my %StateList = $Self->{TicketObject}->StateList(
 
690
            Action => $Self->{Action},
 
691
            TicketID => $Self->{TicketID},
 
692
            UserID => $Self->{UserID},
 
693
        );
 
694
        if (!$Self->{Config}->{StateDefault}) {
 
695
            $StateList{''} = '-';
 
696
#            $State{SelectedID} = $Param{StateID};
 
697
        }
 
698
        if (!$Param{NewStateID}) {
 
699
            if ($Self->{Config}->{StateDefault}) {
 
700
                $State{Selected} = $Self->{Config}->{StateDefault};
 
701
            }
 
702
        }
 
703
        else {
 
704
            $State{SelectedID} = $Param{NewStateID};
 
705
        }
 
706
        # build next states string
 
707
        $Param{'StateStrg'} = $Self->{LayoutObject}->OptionStrgHashRef(
 
708
            Data => \%StateList,
 
709
            Name => 'NewStateID',
 
710
            %State,
 
711
        );
 
712
        $Self->{LayoutObject}->Block(
 
713
            Name => 'State',
 
714
            Data => \%Param,
 
715
        );
 
716
        foreach (sort keys %StateList) {
 
717
            if ($_) {
 
718
                my %StateData = $Self->{TicketObject}->{StateObject}->StateGet(
 
719
                    ID => $_,
 
720
                );
 
721
                if ($StateData{TypeName} =~ /pending/i) {
 
722
                    $Param{DateString} = $Self->{LayoutObject}->BuildDateSelection(
 
723
                        Format => 'DateInputFormatLong',
 
724
                        DiffTime => $Self->{ConfigObject}->Get('Ticket::Frontend::PendingDiffTime') || 0,
 
725
                        %Param,
 
726
                    );
 
727
                    $Self->{LayoutObject}->Block(
 
728
                        Name => 'StatePending',
 
729
                        Data => \%Param,
 
730
                    );
 
731
                    last;
 
732
                }
 
733
            }
 
734
        }
 
735
    }
 
736
    # get next states
 
737
    if ($Self->{Config}->{Priority}) {
 
738
        my %Priority = ();
 
739
        my %PriorityList = $Self->{TicketObject}->PriorityList(
 
740
            UserID => $Self->{UserID},
 
741
            TicketID => $Self->{TicketID},
 
742
        );
 
743
        if (!$Self->{Config}->{PriorityDefault}) {
 
744
            $PriorityList{''} = '-';
 
745
#            $Priority{SelectedID} = $Param{PriorityID};
 
746
        }
 
747
        if (!$Param{NewPriorityID}) {
 
748
            if ($Self->{Config}->{PriorityDefault}) {
 
749
                $Priority{Selected} = $Self->{Config}->{PriorityDefault};
 
750
            }
 
751
        }
 
752
        else {
 
753
            $Priority{SelectedID} = $Param{NewPriorityID};
 
754
        }
 
755
        $Param{'PriorityStrg'} = $Self->{LayoutObject}->OptionStrgHashRef(
 
756
            Data => \%PriorityList,
 
757
            Name => 'NewPriorityID',
 
758
            %Priority,
 
759
        );
 
760
        $Self->{LayoutObject}->Block(
 
761
            Name => 'Priority',
 
762
            Data => \%Param,
 
763
        );
 
764
    }
 
765
    if ($Self->{Config}->{Note}) {
 
766
        $Self->{LayoutObject}->Block(
 
767
            Name => 'NoteJs',
 
768
            Data => { %Param },
 
769
        );
 
770
        $Self->{LayoutObject}->Block(
 
771
            Name => 'Note',
 
772
            Data => { %Param },
 
773
        );
 
774
        # agent list
 
775
        if ($Self->{Config}->{InformAgent}) {
 
776
            my %ShownUsers = ();
 
777
            my %AllGroupsMembers = $Self->{UserObject}->UserList(
 
778
                Type => 'Long',
 
779
                Valid => 1,
 
780
            );
 
781
            my $GID = $Self->{QueueObject}->GetQueueGroupID(QueueID => $Ticket{QueueID});
 
782
            my %MemberList = $Self->{GroupObject}->GroupMemberList(
 
783
                GroupID => $GID,
 
784
                Type => 'rw',
 
785
                Result => 'HASH',
 
786
                Cached => 1,
 
787
            );
 
788
            foreach (keys %MemberList) {
 
789
                $ShownUsers{$_} = $AllGroupsMembers{$_};
 
790
            }
 
791
            $Param{'OptionStrg'} = $Self->{LayoutObject}->OptionStrgHashRef(
 
792
                Data => \%ShownUsers,
 
793
                SelectedIDRefArray => $Self->{InformUserID},
 
794
                Name => 'InformUserID',
 
795
                Multiple => 1,
 
796
                Size => 3,
 
797
            );
 
798
            $Self->{LayoutObject}->Block(
 
799
                Name => 'InformAgent',
 
800
                Data => \%Param,
 
801
            );
 
802
        }
 
803
        # get involved
 
804
        if ($Self->{Config}->{InvolvedAgent}) {
 
805
            my @UserIDs = $Self->{TicketObject}->InvolvedAgents(TicketID => $Self->{TicketID});
 
806
            my %UserHash = ();
 
807
            my $Counter = 0;
 
808
            foreach my $User (reverse @UserIDs) {
 
809
                $Counter++;
 
810
                if (!$UserHash{$User->{UserID}}) {
 
811
                    $UserHash{$User->{UserID}} = "$Counter: $User->{UserLastname} ".
 
812
                        "$User->{UserFirstname} ($User->{UserLogin})";
 
813
                }
 
814
            }
 
815
            $Param{'InvolvedAgentStrg'} = $Self->{LayoutObject}->OptionStrgHashRef(
 
816
                Data => \%UserHash,
 
817
                SelectedIDRefArray => $Self->{InvolvedUserID},
 
818
                Name => 'InvolvedUserID',
 
819
                Multiple => 1,
 
820
                Size => 3,
 
821
            );
 
822
            $Self->{LayoutObject}->Block(
 
823
                Name => 'InvolvedAgent',
 
824
                Data => \%Param,
 
825
            );
 
826
        }
 
827
        # show spell check
 
828
        if ($Self->{ConfigObject}->Get('SpellChecker') && $Self->{LayoutObject}->{BrowserJavaScriptSupport}) {
 
829
            $Self->{LayoutObject}->Block(
 
830
                Name => 'SpellCheck',
 
831
                Data => {},
 
832
            );
 
833
        }
 
834
        # show attachments
 
835
        foreach my $DataRef (@{$Param{Attachments}}) {
 
836
            $Self->{LayoutObject}->Block(
 
837
                Name => 'Attachment',
 
838
                Data => $DataRef,
 
839
            );
 
840
        }
 
841
        # build ArticleTypeID string
 
842
        my %ArticleType = ();
 
843
        if (!$Param{ArticleTypeID}) {
 
844
            $ArticleType{Selected} = $Self->{Config}->{ArticleTypeDefault};
 
845
        }
 
846
        else {
 
847
            $ArticleType{SelectedID} = $Param{ArticleTypeID};
 
848
        }
 
849
        # get possible notes
 
850
        my %DefaultNoteTypes = %{$Self->{Config}->{ArticleTypes}};
 
851
        my %NoteTypes = $Self->{DBObject}->GetTableData(
 
852
            Table => 'article_type',
 
853
            Valid => 1,
 
854
            What => 'id, name'
 
855
        );
 
856
        foreach (keys %NoteTypes) {
 
857
            if (!$DefaultNoteTypes{$NoteTypes{$_}}) {
 
858
                delete $NoteTypes{$_};
 
859
            }
 
860
        }
 
861
        $Param{'ArticleTypeStrg'} = $Self->{LayoutObject}->OptionStrgHashRef(
 
862
            Data => \%NoteTypes,
 
863
            Name => 'ArticleTypeID',
 
864
            %ArticleType,
 
865
        );
 
866
        $Self->{LayoutObject}->Block(
 
867
            Name => 'ArticleType',
 
868
            Data => \%Param,
 
869
        );
 
870
        # show time accounting box
 
871
        if ($Self->{ConfigObject}->Get('Ticket::Frontend::AccountTime')) {
 
872
            $Self->{LayoutObject}->Block(
 
873
                Name => 'TimeUnitsJs',
 
874
                Data => \%Param,
 
875
            );
 
876
            $Self->{LayoutObject}->Block(
 
877
                Name => 'TimeUnits',
 
878
                Data => \%Param,
 
879
            );
 
880
        }
 
881
    }
 
882
    # ticket free text
 
883
    my $Count = 0;
 
884
    foreach (1..16) {
 
885
        $Count++;
 
886
        if ($Self->{Config}->{'TicketFreeText'}->{$Count}) {
 
887
            $Self->{LayoutObject}->Block(
 
888
                Name => 'TicketFreeText',
 
889
                Data => {
 
890
                    TicketFreeKeyField => $Param{'TicketFreeKeyField'.$Count},
 
891
                    TicketFreeTextField => $Param{'TicketFreeTextField'.$Count},
 
892
                    Count => $Count,
 
893
                },
 
894
            );
 
895
            $Self->{LayoutObject}->Block(
 
896
                Name => 'TicketFreeText'.$Count,
 
897
                Data => {
 
898
                    %Param,
 
899
                    Count => $Count,
 
900
                },
 
901
            );
 
902
        }
 
903
    }
 
904
    $Count = 0;
 
905
    foreach (1..2) {
 
906
        $Count++;
 
907
        if ($Self->{Config}->{'TicketFreeTime'}->{$Count}) {
 
908
            $Self->{LayoutObject}->Block(
 
909
                Name => 'TicketFreeTime',
 
910
                Data => {
 
911
                    TicketFreeTimeKey => $Self->{ConfigObject}->Get('TicketFreeTimeKey'.$Count),
 
912
                    TicketFreeTime => $Param{'TicketFreeTime'.$Count},
 
913
                    Count => $Count,
 
914
                },
 
915
            );
 
916
            $Self->{LayoutObject}->Block(
 
917
                Name => 'TicketFreeTime'.$Count,
 
918
                Data => {
 
919
                    %Param,
 
920
                    Count => $Count,
 
921
                },
 
922
            );
 
923
        }
 
924
    }
 
925
    # article free text
 
926
    $Count = 0;
 
927
    foreach (1..3) {
 
928
        $Count++;
 
929
        if ($Self->{Config}->{'ArticleFreeText'}->{$Count}) {
 
930
            $Self->{LayoutObject}->Block(
 
931
                Name => 'ArticleFreeText',
 
932
                Data => {
 
933
                    ArticleFreeKeyField => $Param{'ArticleFreeKeyField'.$Count},
 
934
                    ArticleFreeTextField => $Param{'ArticleFreeTextField'.$Count},
 
935
                    Count => $Count,
 
936
                },
 
937
            );
 
938
            $Self->{LayoutObject}->Block(
 
939
                Name => 'ArticleFreeText'.$Count,
 
940
                Data => {
 
941
                    %Param,
 
942
                    Count => $Count,
 
943
                },
 
944
            );
 
945
        }
 
946
    }
 
947
    # get output back
 
948
    return $Self->{LayoutObject}->Output(TemplateFile => 'AgentTicketPriority', Data => \%Param);
 
949
}
 
950
 
123
951
1;