NewMaintenance.pm
3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# --
# Kernel/Modules/NewQuickMaintenance.pm - frontend module for quick adding new maintenances
#
# Copyright (C) 2014-2018 - SeTIC - UFSC - http://setic.ufsc.br/
# Version 2015-08-01 - Adjustments for OTRS 4
# Version 2018-01-05 - Adjustments for OTRS 6
#
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
package Kernel::Modules::NewMaintenance;
use strict;
use warnings;
use DateTime;
our @ObjectDependencies = (
"Kernel::System::Maintenance",
"Kernel::System::DateUtils",
"Kernel::System::Web::Request",
"Kernel::System::DB",
"Kernel::System::Ticket",
"Kernel::Output::HTML::Layout",
"Kernel::System::Log",
"Kernel::System::Queue",
"Kernel::Config"
);
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {%Param};
bless( $Self, $Type );
return $Self;
}
sub Run {
my ( $Self, %Param ) = @_;
my %Data = ();
my $ParamObject = $Kernel::OM->Get("Kernel::System::Web::Request");
my $LayoutObject = $Kernel::OM->Get("Kernel::Output::HTML::Layout");
my $DateUtils = $Kernel::OM->Get("Kernel::System::DateUtils");
my $SubAction = $ParamObject->GetParam( Param => "Subaction" );
my $Template = 'NewMaintenance';
my $StartDateSelectionString = $LayoutObject->BuildDateSelection(
Format => 'DateInputFormatLong',
Prefix => 'StartDate',
RequestedTimeOptional => 1,
Validate => 1,
DiffTime => 3600,
);
$Data{StartDateSelectionString} = $StartDateSelectionString;
my $ScheduledEndDateSelectionString = $LayoutObject->BuildDateSelection(
Format => 'DateInputFormatLong',
Prefix => 'ScheduledEndDate',
RequestedTimeOptional => 1,
Validate => 1,
DiffTime => 7200,
);
$Data{ScheduledEndDateSelectionString} = $ScheduledEndDateSelectionString;
if ( $SubAction eq "CreateMaintenance" ) {
$Template = "NewMaintenanceCreated";
my $StartDate = $DateUtils->GetDateFromParams( Prefix => "StartDate", ParamObject => $ParamObject );
my $ScheduledEndDate = $DateUtils->GetDateFromParams( Prefix => "ScheduledEndDate", ParamObject => $ParamObject );
my $Description = $ParamObject->GetParam( Param => "Description" );
$Kernel::OM->Get("Kernel::System::Maintenance")->CreateMaintenance(
Description => $Description,
StartDate => $DateUtils->SQLDate(Timestamp => $StartDate),
ScheduledEndDate => $DateUtils->SQLDate(Timestamp => $ScheduledEndDate),
UserID => $Self->{UserID}
);
return $LayoutObject->Redirect(
OP => "Action=MaintenanceManager;Subaction=List;Type=current_scheduled",
);
}
# build output
my $Output = $LayoutObject->Header( Title => $LayoutObject->{LanguageObject}->Translate("Maintenances") );
$Output .= $LayoutObject->NavigationBar();
$Output .= $LayoutObject->Output( Data => \%Data, TemplateFile => $Template );
$Output .= $LayoutObject->Footer();
return $Output;
}
sub GetDateTime {
my ( $Self, %Param ) = @_;
my $Prefix = $Param{"Prefix"};
my $ParamObject = $Kernel::OM->Get("Kernel::System::Web::Request");
my $Date = sprintf '%04d-%02d-%02d %02d:%02d:00', $ParamObject->GetParam( Param => $Prefix . "Year" ),
$ParamObject->GetParam( Param => $Prefix . "Month" ),
$ParamObject->GetParam( Param => $Prefix . "Day" ),
$ParamObject->GetParam( Param => $Prefix . "Hour" ),
$ParamObject->GetParam( Param => $Prefix . "Minute" );
return $Date;
}
1;