From d55c14fd9e7a6fb5f37fef14f3636de1fd07712d Mon Sep 17 00:00:00 2001 From: Rodrigo Goncalves Date: Wed, 9 Apr 2014 20:09:15 -0300 Subject: [PATCH] first commit --- .project | 18 ++++++++++++++++++ CreateOpm.sh | 5 +++++ DBModel.mwb | Bin 0 -> 5936 bytes DBModel.mwb.bak | Bin 0 -> 3103 bytes Kernel/Config/Files/MaintenanceManager.xml | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Kernel/Language/pt_BR_MaintenanceManager.pm | 27 +++++++++++++++++++++++++++ Kernel/Modules/MaintenanceManager.pm | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Kernel/Modules/NewMaintenance.pm | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Kernel/Modules/NewQuickMaintenance.pm | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Kernel/Output/HTML/MaintenanceAdvisor.pm | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Kernel/Output/HTML/Standard/Maintenances.dtl | 38 ++++++++++++++++++++++++++++++++++++++ Kernel/Output/HTML/Standard/NewMaintenance.dtl | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Kernel/Output/HTML/Standard/NewMaintenanceCreated.dtl | 34 ++++++++++++++++++++++++++++++++++ Kernel/Output/HTML/Standard/NewQuickMaintenance.dtl | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ Kernel/System/DateUtils.pm | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Kernel/System/Maintenance.pm | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ OTRSMaintenanceManager.sopm | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ script.sql | 1 + script.sql~ | 1 + var/httpd/htdocs/js/maintenance.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 20 files changed, 1131 insertions(+), 0 deletions(-) create mode 100644 .project create mode 100755 CreateOpm.sh create mode 100644 DBModel.mwb create mode 100644 DBModel.mwb.bak create mode 100644 Kernel/Config/Files/MaintenanceManager.xml create mode 100644 Kernel/Language/pt_BR_MaintenanceManager.pm create mode 100644 Kernel/Modules/MaintenanceManager.pm create mode 100644 Kernel/Modules/NewMaintenance.pm create mode 100644 Kernel/Modules/NewQuickMaintenance.pm create mode 100644 Kernel/Output/HTML/MaintenanceAdvisor.pm create mode 100644 Kernel/Output/HTML/Standard/Maintenances.dtl create mode 100644 Kernel/Output/HTML/Standard/NewMaintenance.dtl create mode 100644 Kernel/Output/HTML/Standard/NewMaintenanceCreated.dtl create mode 100644 Kernel/Output/HTML/Standard/NewQuickMaintenance.dtl create mode 100644 Kernel/System/DateUtils.pm create mode 100644 Kernel/System/Maintenance.pm create mode 100755 OTRSMaintenanceManager.sopm create mode 100644 script.sql create mode 100644 script.sql~ create mode 100644 var/httpd/htdocs/js/maintenance.js diff --git a/.project b/.project new file mode 100644 index 0000000..d5f409f --- /dev/null +++ b/.project @@ -0,0 +1,18 @@ + + + otrs-maintenance-manager + + + otrs + + + + org.epic.perleditor.perlbuilder + + + + + + org.epic.perleditor.perlnature + + diff --git a/CreateOpm.sh b/CreateOpm.sh new file mode 100755 index 0000000..f533983 --- /dev/null +++ b/CreateOpm.sh @@ -0,0 +1,5 @@ +#!/bin/bash +LOCAL="$PWD" +cd /opt/otrs/bin +./otrs.PackageManager.pl -a build -p "$LOCAL"/NewTicketWizard.sopm -o "$LOCAL"/ +cd $LOCAL diff --git a/DBModel.mwb b/DBModel.mwb new file mode 100644 index 0000000..784b93f Binary files /dev/null and b/DBModel.mwb differ diff --git a/DBModel.mwb.bak b/DBModel.mwb.bak new file mode 100644 index 0000000..8d39eff Binary files /dev/null and b/DBModel.mwb.bak differ diff --git a/Kernel/Config/Files/MaintenanceManager.xml b/Kernel/Config/Files/MaintenanceManager.xml new file mode 100644 index 0000000..039fa51 --- /dev/null +++ b/Kernel/Config/Files/MaintenanceManager.xml @@ -0,0 +1,138 @@ + + + + + FrontendModuleRegistration for MaintenanceManager module. + ITSM + MaintenanceManager + + + Module for managing maintenances + MaintenanceManager + + Maintenances + Maintenances + + + MaintenanceManager + Menu + 8400 + + + + + + + + + + + FrontendModuleRegistration for MaintenanceManager module. + + + Module for managing maintenances + MaintenanceManager + + Maintenances + Maintenances + Action=MaintenanceManager + MaintenanceManager + + + 880 + + + + + + + + + + + New maintenance + + ITSM + MaintenanceManager + + + + New maintenance + admin + + + + New maintenance + New maintenance + overview.png + Action=NewMaintenance + MaintenanceManager + + + 920 + + + + + + + + + New quick maintenance + + ITSM + MaintenanceManager + + + + New quick maintenance + admin + + + + New quick maintenance + New quick maintenance + overview.png + Action=NewQuickMaintenance + MaintenanceManager + + + 900 + + + + + + + + + Defines the module to display maintenances in progress. + Framework + Frontend::Agent::ModuleNotify + + + Kernel::Output::HTML::MaintenanceAdvisor + + + + + + Maintenance Advisor Warning. + Framework + Core::Web + + + maintenance.js + + + + + + \ No newline at end of file diff --git a/Kernel/Language/pt_BR_MaintenanceManager.pm b/Kernel/Language/pt_BR_MaintenanceManager.pm new file mode 100644 index 0000000..b6e5fed --- /dev/null +++ b/Kernel/Language/pt_BR_MaintenanceManager.pm @@ -0,0 +1,27 @@ +# -- +# Kernel/Modules/pt_BR_MaintenanceManager.pm - frontend module for managing maintenances +# Translations +# +# Copyright (C) 2014 (Rodrigo Goncalves) (rodrigo.g@ufsc.br) +# -- +# 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::Language::pt_BR_MaintenanceManager; + +use strict; +use warnings; + +sub Data { + my $Self = shift; + $Self->{Translation}->{'Maintenances'} = 'Manutenções'; + $Self->{Translation}->{'New maintenance'} = 'Nova manutenção'; + $Self->{Translation}->{'Enter maintenance data'} = 'Informe os dados da manutenção'; + $Self->{Translation}->{'Start date'} = 'Início'; + $Self->{Translation}->{'Scheduled end date'} = 'Data prevista de término'; + $Self->{Translation}->{'Description'} = 'Descrição'; + $Self->{Translation}->{'Comments'} = 'Comentário'; + return 1; +} +1; \ No newline at end of file diff --git a/Kernel/Modules/MaintenanceManager.pm b/Kernel/Modules/MaintenanceManager.pm new file mode 100644 index 0000000..1dc1335 --- /dev/null +++ b/Kernel/Modules/MaintenanceManager.pm @@ -0,0 +1,102 @@ +# -- +# Kernel/Modules/MaintenanceManager.pm - frontend module for manager maintenances +# Copyright (C) 2014 (Rodrigo Goncalves) (rodrigo.g@ufsc.br) +# -- +# 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::MaintenanceManager; + +use strict; +use warnings; + +use Kernel::System::CustomerUser; +use Kernel::System::State; +use Kernel::System::SystemAddress; +use Kernel::System::Queue; +use Kernel::System::Web::UploadCache; +use Kernel::System::DynamicField; +use Kernel::System::DynamicField::Backend; +use Kernel::System::VariableCheck qw(:all); +use Data::Dumper; +require Kernel::Output::HTML::MaintenanceAdvisor; +require Kernel::System::Maintenance; + +sub new { + my ( $Type, %Param ) = @_; + + # allocate new hash for object + my $Self = {%Param}; + bless( $Self, $Type ); + + # check needed objects + for ( + qw(ParamObject DBObject TicketObject LayoutObject LogObject QueueObject ConfigObject) + ) + { + if ( !$Self->{$_} ) { + $Self->{LayoutObject}->FatalError( Message => "Got no $_!" ); + } + } + + # needed objects + $Self->{CustomerUserObject} = Kernel::System::CustomerUser->new(%Param); + $Self->{StateObject} = Kernel::System::State->new(%Param); + $Self->{SystemAddress} = Kernel::System::SystemAddress->new(%Param); + $Self->{UploadCacheObject} = Kernel::System::Web::UploadCache->new(%Param); + $Self->{DynamicFieldObject} = Kernel::System::DynamicField->new(%Param); + $Self->{BackendObject} = Kernel::System::DynamicField::Backend->new(%Param); + $Self->{ServiceObject} = Kernel::System::Service->new(%Param); + $Self->{MaintenanceObject} = Kernel::System::Maintenance->new(%Param); + $Self->{MaintenanceAdvisor} = Kernel::Output::HTML::MaintenanceAdvisor->new(%Param); + + return $Self; +} + + + +sub Run { + my ( $Self, %Param ) = @_; + my %Data = (); + my $Subaction = $Self->{ParamObject}->GetParam( Param => "Subaction" ); + + if ($Subaction eq "EndMaintenance") { + $Self->{MaintenanceObject}->EndMaintenance(ID => $Self->{ParamObject}->GetParam( Param => "ID" )); + } elsif ($Subaction eq "Status") { + return $Self->{LayoutObject}->Attachment( + ContentType => 'text; charset=' . $Self->{LayoutObject}->{Charset}, + Content => $Self->{MaintenanceAdvisor}->GetStatus(), + Type => 'inline', + NoCache => 1, + ); + } elsif ($Subaction eq "StatusID") { + my ($totalMaintenances, $lastMaintenance) = $Self->{MaintenanceObject}->GetStatusID(); + return $Self->{LayoutObject}->Attachment( + ContentType => 'application/json; charset=' . $Self->{LayoutObject}->{Charset}, + Content => "[$totalMaintenances, $lastMaintenance]", + Type => 'inline', + NoCache => 1, + ); + } + + # build output + my @maintenances = $Self->{MaintenanceObject}->ListCurrentMaintenances(); + for my $maintenance ( @maintenances ) { + $Self->{LayoutObject}->Block( + Name => 'Maintenance', + Data => $maintenance, + ); + } + + my $Output = $Self->{LayoutObject}->Header( Title => $Self->{LayoutObject}->{LanguageObject}->Get("Maintenances") ); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->{LayoutObject}->Output( + Data => \%Data, + TemplateFile => 'Maintenances', + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; +} + +1; diff --git a/Kernel/Modules/NewMaintenance.pm b/Kernel/Modules/NewMaintenance.pm new file mode 100644 index 0000000..3634650 --- /dev/null +++ b/Kernel/Modules/NewMaintenance.pm @@ -0,0 +1,134 @@ +# -- +# Kernel/Modules/NewMaintenance.pm - frontend module for quick adding new maintenances +# Copyright (C) 2014 (Rodrigo Goncalves) (rodrigo.g@ufsc.br) +# -- +# 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 Kernel::System::CustomerUser; +use Kernel::System::State; +use Kernel::System::SystemAddress; +use Kernel::System::Queue; +use Kernel::System::Web::UploadCache; +use Kernel::System::DynamicField; +use Kernel::System::DynamicField::Backend; +use Kernel::System::VariableCheck qw(:all); +use Data::Dumper; +require Kernel::System::ITSMChange; + +sub new { + my ( $Type, %Param ) = @_; + + # allocate new hash for object + my $Self = {%Param}; + bless( $Self, $Type ); + + # check needed objects + for ( + qw(ParamObject DBObject TicketObject LayoutObject LogObject QueueObject ConfigObject) + ) + { + if ( !$Self->{$_} ) { + $Self->{LayoutObject}->FatalError( Message => "Got no $_!" ); + } + } + + # needed objects + $Self->{CustomerUserObject} = Kernel::System::CustomerUser->new(%Param); + $Self->{StateObject} = Kernel::System::State->new(%Param); + $Self->{SystemAddress} = Kernel::System::SystemAddress->new(%Param); + $Self->{UploadCacheObject} = Kernel::System::Web::UploadCache->new(%Param); + $Self->{DynamicFieldObject} = Kernel::System::DynamicField->new(%Param); + $Self->{BackendObject} = Kernel::System::DynamicField::Backend->new(%Param); + $Self->{ServiceObject} = Kernel::System::Service->new(%Param); + $Self->{ChangeObject} = Kernel::System::ITSMChange->new(%Param); + + return $Self; +} + +sub Run { + my ( $Self, %Param ) = @_; + my %Data = (); + my $SubAction = $Self->{ParamObject}->GetParam( Param => "Subaction" ); + my $Template = 'NewMaintenance'; + + # common stuff + if ( $Self->{LayoutObject}->{BrowserRichText} ) { + $Self->{LayoutObject}->Block( + Name => 'RichText', + Data => \%Param, + ); + } + + # Date/time chooses + my $StartDateSelectionString = $Self->{LayoutObject}->BuildDateSelection( + Format => 'DateInputFormatLong', + Prefix => 'StartDate', + RequestedTimeOptional => 1, + Validate => 1, + ); + my $ScheduledEndDateSelectionString = $Self->{LayoutObject}->BuildDateSelection( + Format => 'DateInputFormatLong', + Prefix => 'ScheduledEndDate', + RequestedTimeOptional => 1, + Validate => 1, + ); + + $Data{StartDateSelectionString} = $StartDateSelectionString; + $Data{ScheduledEndDateSelectionString} = $ScheduledEndDateSelectionString; + + if ( $SubAction eq "CreateMaintenance" ) { + $Template = "NewMaintenanceCreated"; + $Self->Debug( "Params = " . Dumper( $Self->{ParamObject}->GetParamNames() ) ); + $Data{StartDate} = $Self->GetDateTime( Prefix => "StartDate" ); + $Data{ScheduledEndDate} = $Self->GetDateTime( Prefix => "ScheduledEndDate" ); + $Data{Description} = $Self->{ParamObject}->GetParam( Param => "Description" ); + + my $ChangeID = $Self->{ChangeObject}->ChangeAdd( + ChangeTitle => 'Manutenção de serviço', # (optional) + Description => $Data{Description}, # (optional) + ChangeStateID => 114, # (optional) + CategoryID => 1, # (optional) or CategoryID => 4 + ImpactID => 1, # (optional) or ImpactID => 5 + PriorityID => 1, # (optional) or PriorityID => 6 + RequestedTime => $Data{StartDate}, # (optional) + UserID => 1, + ); + } + else { + + } + + # build output + my $Output = $Self->{LayoutObject}->Header( Title => $Self->{LayoutObject}->{LanguageObject}->Get("Maintenances") ); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->{LayoutObject}->Output( Data => \%Data, TemplateFile => $Template ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; +} + +sub Debug { + my $Self = shift; + print STDERR @_; +} + +sub GetDateTime { + my ( $Self, %Param ) = @_; + my $Prefix = $Param{"Prefix"}; + + my $Date = sprintf '%04d-%02d-%02d %02d:%02d:00', $Self->{ParamObject}->GetParam( Param => $Prefix . "Year" ), + $Self->{ParamObject}->GetParam( Param => $Prefix . "Month" ), + $Self->{ParamObject}->GetParam( Param => $Prefix . "Day" ), + $Self->{ParamObject}->GetParam( Param => $Prefix . "Hour" ), + $Self->{ParamObject}->GetParam( Param => $Prefix . "Minute"); + + return $Date; +} + +1; diff --git a/Kernel/Modules/NewQuickMaintenance.pm b/Kernel/Modules/NewQuickMaintenance.pm new file mode 100644 index 0000000..50d75ee --- /dev/null +++ b/Kernel/Modules/NewQuickMaintenance.pm @@ -0,0 +1,105 @@ +# -- +# Kernel/Modules/NewQuickMaintenance.pm - frontend module for quick adding new maintenances +# Copyright (C) 2014 (Rodrigo Goncalves) (rodrigo.g@ufsc.br) +# -- +# 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::NewQuickMaintenance; + +use strict; +use warnings; + +require Kernel::System::Maintenance; +require DateTime; +require Data::Dumper; +require Kernel::System::DateUtils; +use Kernel::System::VariableCheck qw(:all); + +sub new { + my ( $Type, %Param ) = @_; + + # allocate new hash for object + my $Self = {%Param}; + bless( $Self, $Type ); + + # check needed objects + for ( + qw(ParamObject DBObject TicketObject LayoutObject LogObject QueueObject ConfigObject) + ) + { + if ( !$Self->{$_} ) { + $Self->{LayoutObject}->FatalError( Message => "Got no $_!" ); + } + } + + # needed objects + $Self->{MaintenanceObject} = Kernel::System::Maintenance->new(%Param); + $Self->{DateUtils} = Kernel::System::DateUtils->new(%Param); + + return $Self; +} + +sub Run { + my ( $Self, %Param ) = @_; + my %Data = (); + my $SubAction = $Self->{ParamObject}->GetParam( Param => "Subaction" ); + my $Template = 'NewQuickMaintenance'; + + # common stuff + my $StartDateSelectionString = $Self->{LayoutObject}->BuildDateSelection( + Format => 'DateInputFormatLong', + Prefix => 'StartDate', + RequestedTimeOptional => 1, + Validate => 1, + ); + + $Data{StartDateSelectionString} = $StartDateSelectionString; + + if ( $SubAction eq "CreateMaintenance" ) { + $Template = "NewMaintenanceCreated"; + + my $StartDate = $Self->{DateUtils}->GetDateFromParams( Prefix => "StartDate", ParamObject => $Self->{ParamObject} ); + my $ScheduledEndDate = $StartDate->clone(); + $Self->{DateUtils}->AddDays( Timestamp => $ScheduledEndDate, Days => 1 ); + my $Description = $Self->{ParamObject}->GetParam( Param => "Description" ); + + $Self->{MaintenanceObject}->CreateMaintenance( + Description => $Description, + StartDate => $Self->{DateUtils}->SQLDate(Timestamp => $StartDate), + ScheduledEndDate => $Self->{DateUtils}->SQLDate(Timestamp => $ScheduledEndDate), + UserID => $Self->{UserID} + ); + + } + else { + } + + # build output + my $Output = $Self->{LayoutObject}->Header( Title => $Self->{LayoutObject}->{LanguageObject}->Get("Maintenances") ); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->{LayoutObject}->Output( Data => \%Data, TemplateFile => $Template ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; +} + +sub Debug { + my $Self = shift; + print STDERR @_; +} + +sub GetDateTime { + my ( $Self, %Param ) = @_; + my $Prefix = $Param{"Prefix"}; + + my $Date = sprintf '%04d-%02d-%02d %02d:%02d:00', $Self->{ParamObject}->GetParam( Param => $Prefix . "Year" ), + $Self->{ParamObject}->GetParam( Param => $Prefix . "Month" ), + $Self->{ParamObject}->GetParam( Param => $Prefix . "Day" ), + $Self->{ParamObject}->GetParam( Param => $Prefix . "Hour" ), + $Self->{ParamObject}->GetParam( Param => $Prefix . "Minute" ); + + return $Date; +} + +1; diff --git a/Kernel/Output/HTML/MaintenanceAdvisor.pm b/Kernel/Output/HTML/MaintenanceAdvisor.pm new file mode 100644 index 0000000..dc25f46 --- /dev/null +++ b/Kernel/Output/HTML/MaintenanceAdvisor.pm @@ -0,0 +1,68 @@ +# -- +# Kernel/Output/HTML/MaintenanceAdvisor.pm - show maintenances in progress +# Copyright (C) 2001-2013 OTRS AG, http://otrs.com/ +# -- +# This software comes with ABSOLUTELY NO WARRANTY. For details, see +# the enclosed file COPYING for license information (AGPL). If you +# did not receive this file, see http://www.gnu.org/licenses/agpl.txt. +# -- + +package Kernel::Output::HTML::MaintenanceAdvisor; + +use strict; +use warnings; +require Kernel::System::Maintenance; + +sub new { + my ( $Type, %Param ) = @_; + + # allocate new hash for object + my $Self = {}; + bless( $Self, $Type ); + + # get needed objects + for (qw(ConfigObject LogObject DBObject LayoutObject UserID)) { + $Self->{$_} = $Param{$_} || die "Got no $_!"; + } + $Self->{MaintenanceObject} = Kernel::System::Maintenance->new(%Param); + + return $Self; +} + +sub Run { + my ( $Self, %Param ) = @_; + + my $TEMPLATE = '%s (desde %s)'; + + my %maintenances = $Self->{MaintenanceObject}->ListCurrentMaintenances(); + my $msg = $Self->GetStatus(); + + # show error notfy, don't work with user id 1 + return $Self->{LayoutObject}->Notify( + Priority => 'Warning', + Link => '', + Data => "
$msg
", + ); +} + +sub GetStatus { + my ( $Self, %Param ) = @_; + + my $TEMPLATE = '%s
(desde %s)
'; + + my @maintenances = $Self->{MaintenanceObject}->ListCurrentMaintenances(); + my $msg = ""; + for my $maintenance ( @maintenances ) { + $msg .= sprintf( $TEMPLATE, $maintenance->{"Description"}, $maintenance->{"StartDate"} ); + } + + if ( !$msg eq "" ) { + $msg = "MANUTENCOES EM ANDAMENTO:
" . $msg; + } + + return $msg; +} + + + +1; diff --git a/Kernel/Output/HTML/Standard/Maintenances.dtl b/Kernel/Output/HTML/Standard/Maintenances.dtl new file mode 100644 index 0000000..40eb975 --- /dev/null +++ b/Kernel/Output/HTML/Standard/Maintenances.dtl @@ -0,0 +1,38 @@ +# -- +# Kernel/Output/HTML/Standard/Maintenances.dtl - template for maintenances module index +# Copyright (C) (2014) (Rodrigo Goncalves) (rodrigo.g@ufsc.br) +# -- +# 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. +# -- + + + + + + + + + + + + + + + + + + +
$Text{"Actions"}
$Text{"Description"}
$Text{"Start time"}
Finalizar
$Data{"Description"}
$TimeShort{"StartDate"}
+ + + + + + diff --git a/Kernel/Output/HTML/Standard/NewMaintenance.dtl b/Kernel/Output/HTML/Standard/NewMaintenance.dtl new file mode 100644 index 0000000..66ec6a5 --- /dev/null +++ b/Kernel/Output/HTML/Standard/NewMaintenance.dtl @@ -0,0 +1,69 @@ +# -- +# Kernel/Output/HTML/Standard/NewMaintenance.dtl - template for quickly adding new maintenance +# Copyright (C) (2014) (Rodrigo Goncalves) (rodrigo.g@ufsc.br) +# -- +# 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. +# -- + +
+ +

$Text{"New maintenance"}

+ +
+
+
+

$Text{"Enter maintenance data"}

+
+
+ +
+ + + + +
+ +
+ $Data{"StartDateSelectionString"} +
+ +
+ $Data{"ScheduledEndDateSelectionString"} +
+ + +
+ + $Include{"RichTextEditor"} + + +

$Text{"This field is required."}

+

$Text{"This field is required."}

+
+ + +
+ + $Include{"RichTextEditor"} + + +

$Text{"This field is required."}

+

$Text{"This field is required."}

+
+ + +
+
+
+
+
+
+ + + + + diff --git a/Kernel/Output/HTML/Standard/NewMaintenanceCreated.dtl b/Kernel/Output/HTML/Standard/NewMaintenanceCreated.dtl new file mode 100644 index 0000000..d70f886 --- /dev/null +++ b/Kernel/Output/HTML/Standard/NewMaintenanceCreated.dtl @@ -0,0 +1,34 @@ +# -- +# Kernel/Output/HTML/Standard/NewMaintenance.dtl - template for quickly adding new maintenance +# Copyright (C) (2014) (Rodrigo Goncalves) (rodrigo.g@ufsc.br) +# -- +# 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. +# -- + +
+ +

$Text{"New maintenance"}

+ +
+
+
+

$Text{"Enter maintenance data"}

+
+
+ + Data: $Data{"StartDate"}
+ Data fim: $Data{"ScheduledEndDate"}
+ Descricao: $Data{"Description"} +
+
+
+
+ + + + + diff --git a/Kernel/Output/HTML/Standard/NewQuickMaintenance.dtl b/Kernel/Output/HTML/Standard/NewQuickMaintenance.dtl new file mode 100644 index 0000000..276f4fd --- /dev/null +++ b/Kernel/Output/HTML/Standard/NewQuickMaintenance.dtl @@ -0,0 +1,50 @@ +# -- +# Kernel/Output/HTML/Standard/NewMaintenance.dtl - template for quickly adding new maintenance +# Copyright (C) (2014) (Rodrigo Goncalves) (rodrigo.g@ufsc.br) +# -- +# 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. +# -- + +
+ +

$Text{"New maintenance"}

+ +
+
+
+

$Text{"Enter maintenance data"}

+
+
+ +
+ + + + +
+ +
+ $Data{"StartDateSelectionString"} +
+ + +
+ +
+ + +
+
+
+
+
+
+ + + + + diff --git a/Kernel/System/DateUtils.pm b/Kernel/System/DateUtils.pm new file mode 100644 index 0000000..fed088b --- /dev/null +++ b/Kernel/System/DateUtils.pm @@ -0,0 +1,109 @@ +# -- +# Kernel/System/DateUtils.pm - date/time utils +# Copyright (C) (2014) (Rodrigo Goncalves) (rodrigo.g@ufsc.br) +# -- +# $Id: writing-otrs-application.xml,v 1.1 2010/08/13 08:59:28 mg Exp $ +# -- +# 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. +# -- +# Author: Carlos Rebelato +# Date..: 19/02/2014 - First version +# +package Kernel::System::DateUtils; + +use strict; +use warnings; +use Data::Dumper; +require DateTime; + +sub new { + my ( $Type, %Param ) = @_; + + # allocate new hash for object + my $Self = {%Param}; + bless( $Self, $Type ); + + # creates required objects + + return $Self; +} + +=item NewTimestamp() + +Creates a new date from the parameters + + $ocurrenceObject->NewTimestamp( + Year => int, + Month => int, + Day => int, + Hour => int, + Minute => int, + Second => int + ); + +=cut +sub NewTimestamp { + my ( $Self, %Param ) = @_; + + my $date = DateTime->new( + year => $Param{Year}, + month => $Param{Month}, + day => $Param{Day}, + hour => $Param{Hour}, + minute => $Param{Minute}, + second => $Param{Second} + ); + + return $date; +} +=item AddDays() + +Adds a number of days to a timestamp + + $ocurrenceObject->AddDays( + Timestamp => DateTime, + Days => int + ); + +=cut +sub AddDays { + my ( $Self, %Param ) = @_; + my $timestamp = $Param{Timestamp}; + $timestamp->add( days => $Param{Days} ); +} + +=item GetDateFromParams() + +Create a DateTime based on parameter values + + $ocurrenceObject->GetDateFromParams( + Prefix => string, + ParamObject => ParamObject + ); + +=cut +sub GetDateFromParams { + my ( $Self, %Param ) = @_; + my $Prefix = $Param{"Prefix"}; + my $ParamObject = $Param{"ParamObject"}; + + return $Self->NewTimestamp( + Year => $ParamObject->GetParam(Param => $Prefix . "Year"), + Month => $ParamObject->GetParam(Param => $Prefix . "Month"), + Day => $ParamObject->GetParam(Param => $Prefix . "Day"), + Hour => $ParamObject->GetParam(Param => $Prefix . "Hour"), + Minute => $ParamObject->GetParam(Param => $Prefix . "Minute"), + Second => 0 + ); + +} + +sub SQLDate { + my ( $Self, %Param ) = @_; + my $timestamp = $Param{"Timestamp"}; + return $timestamp->strftime("%y-%m-%d %H:%M:%S"); +} + +1; diff --git a/Kernel/System/Maintenance.pm b/Kernel/System/Maintenance.pm new file mode 100644 index 0000000..7363296 --- /dev/null +++ b/Kernel/System/Maintenance.pm @@ -0,0 +1,109 @@ +# -- +# Kernel/System/Maintenanca.pm - maintenance instance +# Copyright (C) (2014) (Rodrigo Goncalves) (rodrigo.g@ufsc.br) +# -- +# $Id: writing-otrs-application.xml,v 1.1 2010/08/13 08:59:28 mg Exp $ +# -- +# 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. +# -- +# Author: Carlos Rebelato +# Date..: 19/02/2014 - First version +# +package Kernel::System::Maintenance; + +use strict; +use warnings; +use Data::Dumper; + +sub new { + my ( $Type, %Param ) = @_; + + # allocate new hash for object + my $Self = {%Param}; + bless( $Self, $Type ); + + # creates required objects + + return $Self; +} + +=item CreateMaintenance() + +Creates a maintenance + + $ocurrenceObject->CreateMaintenance( + Description => string + StartDate => string (format yyyy-mm-dd hh:nn:ss) + ScheduledEndDate => string (format yyyy-mm-dd hh:nn:ss) + UserID => integer + ); + +=cut + +sub CreateMaintenance { + my ( $Self, %Param ) = @_; + + for (qw(Description StartDate ScheduledEndDate UserID)) { + if ( !$Param{$_} ) { + $Self->{LayoutObject}->FatalError( Message => Dumper( \%Param ) . "got no $_!" ); + } + } + + $Self->{DBObject}->Do( + SQL => "insert into maintenance (description, start_date, scheduled_end_date, user_id) values (?, ?, ?, ?)", + Bind => [ \$Param{Description}, \$Param{StartDate}, \$Param{ScheduledEndDate}, \$Param{UserID} ] + ); +} + +sub ListCurrentMaintenances { + my ( $Self, %Param ) = @_; + my @retorno = (); + + $Self->{DBObject}->Prepare( + SQL => +"SELECT id,description,start_date FROM maintenance where start_date < CURRENT_TIMESTAMP and end_date = 0 ORDER BY start_date DESC", + Bind => [] + ); + + while ( my @row = $Self->{DBObject}->FetchrowArray() ) { + my %ret = (); + $ret{'Description'} = $row[1]; + $ret{'StartDate'} = $row[2]; + $ret{'ID'} = $row[0]; + push @retorno, \%ret; + } + + return @retorno; +} + +sub EndMaintenance { + my ( $Self, %Param ) = @_; + + $Self->{DBObject}->Prepare( + SQL => "UPDATE maintenance SET end_date=CURRENT_TIMESTAMP WHERE id=?", + Bind => [ \$Param{ID} ] + ); + +} + +sub GetStatusID { + my ( $Self, %Param ) = @_; + my %retorno = (); + + $Self->{DBObject}->Prepare( + SQL => "SELECT count(id), max(id) FROM maintenance where start_date < CURRENT_TIMESTAMP and end_date = 0", + Bind => [] + ); + + my @row = $Self->{DBObject}->FetchrowArray(); + if ($row[0] != 0) { + return ( $row[0], $row[1] ); + } + else { + return ( 0, 0 ); + } +} + +1; diff --git a/OTRSMaintenanceManager.sopm b/OTRSMaintenanceManager.sopm new file mode 100755 index 0000000..2d4a717 --- /dev/null +++ b/OTRSMaintenanceManager.sopm @@ -0,0 +1,72 @@ + + + NewTicketWizard + 1.1.4 + 3.x.x + SeTIC + http://www.setic.ufsc.br + Free + Assistente de chamados + + Versão 1.0.0 - Inicial + Versão 1.0.1 - Ajusta listagem de servicos do Service forms, correcao no formulario de edicao de servico + Versão 1.0.2 - Ajuste na hierarquia de servicos + Versão 1.0.9 - Primeira versao para producao + Versão 1.1.1 - Suporte para abertura pública de tickets. + Versão 1.1.2 - Suporte para múltiplos domínios. + Versão 1.1.3 - Link para abrir segundo chamado na tela de finalização da abertura + Versão 1.1.4 - Aumento na fonte do botao de enviar + + Módulo instalado com sucesso! + New Ticket Wizard + New Ticket Wizard module installed successfully! + ? + ? + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/script.sql b/script.sql new file mode 100644 index 0000000..565c04c --- /dev/null +++ b/script.sql @@ -0,0 +1 @@ +create table maintenance(id integer not null primary key auto_increment, user_id integer, description text not null, start_date timestamp not null, scheduled_end_date timestamp, end_date timestamp, comments text); diff --git a/script.sql~ b/script.sql~ new file mode 100644 index 0000000..587ca23 --- /dev/null +++ b/script.sql~ @@ -0,0 +1 @@ +create table maintenance(id integer not null primary key auto_increment, description text not null, start_date timestamp not null, scheduled_end_date timestamp, end_date timestamp, comments text); diff --git a/var/httpd/htdocs/js/maintenance.js b/var/httpd/htdocs/js/maintenance.js new file mode 100644 index 0000000..584ee4a --- /dev/null +++ b/var/httpd/htdocs/js/maintenance.js @@ -0,0 +1,51 @@ +/** + * Javascript to indicate maintenances + */ + +var maintenanceManagerLastID = ""; +var maintenanceManagerTotalMaintenance = ""; + +$(document).ready(function() { + if ($("#maintenanceList").length) { + if ($("#maintenanceList").html() == "") { + $("#maintenanceList").parent().hide(); + } + updateStatusMaintenance(); + } +}); + +function updateStatusMaintenance() { + setTimeout(function updateStatus() { + $.getJSON("/otrs/index.pl?Action=MaintenanceManager;Subaction=StatusID", + function parseJSON(data) { + var _maintenanceManagerTotalMaintenance = data[0]; + var _maintenanceManagerLastID = data[1]; + console.log("lastMaintenance=" + _maintenanceManagerLastID + " , totalMaintenance=" + _maintenanceManagerTotalMaintenance); + + if ((_maintenanceManagerLastID != maintenanceManagerLastID) + || (_maintenanceManagerTotalMaintenance != maintenanceManagerTotalMaintenance)) { + maintenanceManagerTotalMaintenance = _maintenanceManagerTotalMaintenance; + maintenanceManagerLastID = _maintenanceManagerLastID; + + if (_maintenanceManagerTotalMaintenance == 0) { + $("#maintenanceList").html(""); + $("#maintenanceList").parent().hide(); + updateStatusMaintenance(); + } else { + $("#maintenanceList").parent().show(); + updateContent(); + } + } + }); + }, 10000); +} + + + +function updateContent() { + $.get("/otrs/index.pl?Action=MaintenanceManager;Subaction=Status", + function(data) { + $("#maintenanceList").html(data); + updateStatusMaintenance(); + }); +} \ No newline at end of file -- libgit2 0.21.2