NewMaintenance.pm 3.5 KB
# --
# 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;