diff --git a/Kernel/Config/Files/FAQTag.xml b/Kernel/Config/Files/FAQTag.xml index b0c457f..4be6497 100755 --- a/Kernel/Config/Files/FAQTag.xml +++ b/Kernel/Config/Files/FAQTag.xml @@ -14,7 +14,7 @@ faq Cadastro de tags para categorias Tag - Action=AgentFAQTagOverview + Action=AgentFAQTagOverview;Subaction=overview FAQ diff --git a/Kernel/Modules/AgentFAQTagAdd.pm b/Kernel/Modules/AgentFAQTagAdd.pm index 3fb1cf3..d68d702 100755 --- a/Kernel/Modules/AgentFAQTagAdd.pm +++ b/Kernel/Modules/AgentFAQTagAdd.pm @@ -4,6 +4,7 @@ package Kernel::Modules::AgentFAQTagAdd; use strict; use warnings; +use Data::Dumper; sub new { my ( $Type, %Param ) = @_; @@ -25,86 +26,99 @@ sub Run { my ( $Self, %Param ) = @_; my %Data = (); - my $Tag_id = $Self->{ParamObject}->GetParam( Param => 'id' ); - my $Category = $Self->{ParamObject}->GetParam( Param => 'category' ); - my $Tag = $Self->{ParamObject}->GetParam( Param => 'tag' ); - my $Existe_Tag = 0; - - if ($Self->{ParamObject}->GetParam( Param => 'Subaction' ) eq "update") { - - if ($Self->_ExisteTag(tag => $Tag)){ - $Existe_Tag = 1; - - }else{ - if($Self->_GetTag(id => $Tag_id) eq undef){ - $Self->{DBObject}->Do( - SQL => "INSERT into faq_tag (category_id, tag) values ((select id from faq_category where name= ?), ?)", - Bind => [\$Category, \$Tag], - ); - return $Self->{LayoutObject}->Redirect( OP => 'Action=AgentFAQTagOverview&added='.$Tag ); - - }else{ - $Self->{DBObject}->Do( - SQL => "update faq_tag set tag=? where id=?", - Bind => [\$Tag, \$Tag_id], - ); - return $Self->{LayoutObject}->Redirect( OP => 'Action=AgentFAQTagOverview&edited='.$Tag ); - } - } - } - - $Self->{LayoutObject}->Block( - Name=> 'info', - Data=> {id => $Tag_id, - category => $Category, - tag => $Tag, - } - ); - - # build output - my $Output = $Self->{LayoutObject}->Header(Title => "Tag"); +# my $Tag_id = $Self->{ParamObject}->GetParam( Param => 'id' ); +# my $Category = $Self->{ParamObject}->GetParam( Param => 'category' ); +# my $Tag = $Self->{ParamObject}->GetParam( Param => 'tag' ); +# my $Existe_Tag = 0; + +# if ($Self->{ParamObject}->GetParam( Param => 'Subaction' ) eq "update") { +# print STDERR Dumper("peguei subaction"); +# if ($Self->_ExisteTag(tag => $Tag)){ +# $Existe_Tag = 1; + +# }else{ +# if($Self->_GetTag(id => $Tag_id) eq undef){ +# $Self->{DBObject}->Do( +# SQL => "INSERT into faq_tag (category_id, tag) values ((select id from faq_category where name= ?), ?)", +# Bind => [\$Category, \$Tag], +# ); +# return $Self->{LayoutObject}->Redirect( OP => 'Action=AgentFAQTagOverview&added='.$Tag ); + +# }else{ +# $Self->{DBObject}->Do( +# SQL => "update faq_tag set tag=? where id=?", +# Bind => [\$Tag, \$Tag_id], +# ); +# return $Self->{LayoutObject}->Redirect( OP => 'Action=AgentFAQTagOverview&edited='.$Tag ); +# } +# } +# } + +# $Self->{LayoutObject}->Block( +# Name=> 'info', +# Data=> {id => $Tag_id, +# category => $Category, +# tag => $Tag, +# } +# ); + +# # build output +# my $Output = $Self->{LayoutObject}->Header(Title => "Tag"); - if($Existe_Tag == 1){ - $Output .= $Self->{LayoutObject}->Notify(Priority => 'Error', Info=> "A tag ".$Tag." j\x{e1} existe."); - } - $Output .= $Self->{LayoutObject}->NavigationBar(); - $Output .= $Self->{LayoutObject}->Output( - Data => \%Data, - TemplateFile => 'AgentFAQTagAdd', - ); - $Output .= $Self->{LayoutObject}->Footer(); - return $Output; +# if($Existe_Tag == 1){ +# $Output .= $Self->{LayoutObject}->Notify(Priority => 'Error', Info=> "A tag ".$Tag." j\x{e1} existe."); +# } +# $Output .= $Self->{LayoutObject}->NavigationBar(); +# $Output .= $Self->{LayoutObject}->Output( +# Data => \%Data, +# TemplateFile => 'AgentFAQTagAdd', +# ); +# $Output .= $Self->{LayoutObject}->Footer(); +# return $Output; } -sub _GetTag { +# sub _GetTag { - my ( $Self, %Param ) = @_; +# my ( $Self, %Param ) = @_; - $Self->{DBObject}->Prepare( - SQL => "select tag from faq_tag where id = $Param{id}", - ); - my $TAG; - while (my @Row = $Self->{DBObject}->FetchrowArray()) { - $TAG = $Row[0]; - } - return $TAG; +# $Self->{DBObject}->Prepare( +# SQL => "select tag from faq_tag where id = $Param{id}", +# ); +# my $TAG; +# while (my @Row = $Self->{DBObject}->FetchrowArray()) { +# $TAG = $Row[0]; +# } +# return $TAG; -} +# } -sub _ExisteTag { +# sub _ExisteTag { - my ( $Self, %Param ) = @_; +# my ( $Self, %Param ) = @_; +# $Self->{DBObject}->Prepare( +# SQL => "select id from faq_tag where tag = '$Param{tag}'", +# ); +# my $Id; +# while (my @Row = $Self->{DBObject}->FetchrowArray()) { +# $Id = $Row[0]; +# } +# return $Id; +# } + + + +sub verificaExistenciaTag { + my ( $Self, %Param ) = @_; + $Self->{DBObject}->Prepare( - SQL => "select id from faq_tag where tag = '$Param{tag}'", - ); - my $Id; - while (my @Row = $Self->{DBObject}->FetchrowArray()) { - $Id = $Row[0]; - } - return $Id; + SQL => "select tag from faq_tag where tag = ?", + Bind => [\$Param{Tag}] + ); + return $Self->{DBObject}->FetchrowArray(); } + 1; diff --git a/Kernel/Modules/AgentFAQTagOverview.pm b/Kernel/Modules/AgentFAQTagOverview.pm index bd570a6..2ea0d94 100755 --- a/Kernel/Modules/AgentFAQTagOverview.pm +++ b/Kernel/Modules/AgentFAQTagOverview.pm @@ -2,7 +2,10 @@ package Kernel::Modules::AgentFAQTagOverview; use strict; -use warnings; +require warnings; +use Kernel::System::FAQ; +use Kernel::System::Valid; +use Data::Dumper; sub new { my ( $Type, %Param ) = @_; @@ -18,6 +21,9 @@ sub new { } } + $Self->{ValidObject} = Kernel::System::Valid->new(%Param); + $Self->{FAQObject} = Kernel::System::FAQ->new(%Param); + return $Self; } @@ -25,45 +31,209 @@ sub Run { my ( $Self, %Param ) = @_; my %Data = (); - if ($Self->{ParamObject}->GetParam( Param => 'Subaction' ) eq "delete") { - my $Var1 = $Self->{ParamObject}->GetParam( Param => 'id' ); - $Self->{DBObject}->Do( - SQL => "DELETE FROM faq_tag where id=?", - Bind => [ \$Var1 ], - ); + my $SubAction = $Self->{ParamObject}->GetParam( Param => 'Subaction' ); + + if($SubAction eq "overview"){ + + # get all categories with their long names + my $CategoryTree = $Self->{FAQObject}->CategoryTreeList( + Valid => 0, + UserID => $Self->{UserID}, + ); + + # if there are any categories, they are shown + if ( $CategoryTree && ref $CategoryTree eq 'HASH' && %{$CategoryTree} ) { + + # get the valid list + my %ValidList = $Self->{ValidObject}->ValidList(); + + # sort the category ids by the long category name + my @CategoryIDsSorted + = sort { $CategoryTree->{$a} cmp $CategoryTree->{$b} } keys %{$CategoryTree}; + + # show all categories + for my $CategoryID (@CategoryIDsSorted) { + + # get category data + my %CategoryData = $Self->{FAQObject}->CategoryGet( + CategoryID => $CategoryID, + UserID => $Self->{UserID}, + ); + + # get valid string based on ValidID + $CategoryData{Valid} = $ValidList{ $CategoryData{ValidID} }; + + # overwrite the name with the long name + $CategoryData{Name} = $CategoryTree->{$CategoryID}; + + #get faq_tag data + $Self->{DBObject}->Prepare( + SQL => "select id, tag from faq_tag where category_id = ?", + Bind => [ \$CategoryID ] + ); + + my @retornoSelect = $Self->{DBObject}->FetchrowArray(); + + $CategoryData{Tag} = $retornoSelect[1]; + $CategoryData{TagID} = $retornoSelect[0]; + $CategoryData{CategoryID} = $CategoryID; + + # output the category data + $Self->{LayoutObject}->Block( + Name => 'OverviewResultRow', + Data => {%CategoryData}, + ); + } + } + + my $Output = $Self->{LayoutObject}->Header( Title => "Tags Overview" ); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->{LayoutObject}->Output( + Data => \%Data, + TemplateFile => 'AgentFAQTagOverview', + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + elsif($SubAction eq "showAlterar"){ + + + my $TagID = $Self->{ParamObject}->GetParam(Param => "TagID"); + my $CategoryID = $Self->{ParamObject}->GetParam(Param => "CategoryID"); + my $CategoryName = $Self->{ParamObject}->GetParam(Param => "CategoryName"); + my $Tag = ""; + + if($TagID){ + $Tag = $Self->getTagName(TagID => $TagID); + $Data{Update} = 1; + } + + $Data{TagID} = $TagID; + $Data{Tag} = $Tag; + $Data{CategoryID} = $CategoryID; + $Data{CategoryName} = $CategoryName; + + my $Output = $Self->{LayoutObject}->Header( Title => "Alterar" ); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->{LayoutObject}->Output( + Data => \%Data, + TemplateFile => 'AgentFAQTagAdd', + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; } + elsif($SubAction eq "alterar"){ + my $Tag = $Self->{ParamObject}->GetParam(Param => "Tag"); + my $Update = $Self->{ParamObject}->GetParam(Param => "Update"); + my $CategoryID = $Self->{ParamObject}->GetParam(Param => "CategoryID"); + my $TagID = $Self->{ParamObject}->GetParam(Param => "TagID"); + + if($Self->checkTag(Tag => $Tag)){ + $Data{MensagemErro} = "Tag já existente"; + $Data{Update} = $Update; + $Data{Tag} = $Tag; + $Data{TagID} = $TagID; + $Data{CategoryID} = $CategoryID; + + my $Output = $Self->{LayoutObject}->Header( Title => "Alterar" ); + $Output .= $Self->{LayoutObject}->NavigationBar(); + $Output .= $Self->{LayoutObject}->Output( + Data => \%Data, + TemplateFile => 'AgentFAQTagAdd', + ); + $Output .= $Self->{LayoutObject}->Footer(); + return $Output; + } + + if($Update){ + $Self->updateTag(TagID => $TagID, Tag => $Tag); + }else{ + $Self->adicionaTag(Tag => $Tag, CategoryID => $CategoryID); + } + + return $Self->{LayoutObject}->Redirect( OP => 'Action=AgentFAQTagOverview&Subaction=overview' ); + } + elsif($SubAction eq "delete"){ + $Self->removeTag(TagID => $Self->{ParamObject}->GetParam(Param => "TagID")); + return $Self->{LayoutObject}->Redirect( OP => 'Action=AgentFAQTagOverview&Subaction=overview' ); + } +} + +sub getTagName { + my ( $Self, %Param ) = @_; + + $Self->{DBObject}->Prepare( + SQL => "select tag from faq_tag where id = ?", + Bind => [\$Param{TagID}] + ); + + my @Tag = $Self->{DBObject}->FetchrowArray(); + + return $Tag[0]; +} + +sub checkTag { + my ( $Self, %Param ) = @_; $Self->{DBObject}->Prepare( - SQL => "select faq_tag.id, faq_tag.tag, faq_category.name from faq_category left join faq_tag on (faq_category.id = faq_tag.category_id)", + SQL => "select tag from faq_tag where tag = ?", + Bind => [\$Param{Tag}] ); - while (my @Row = $Self->{DBObject}->FetchrowArray()) { - $Self->{LayoutObject}->Block( - Name=> 'dadostabela', - Data=> {id=>$Row[0], tag=>$Row[1], category=>$Row[2]} - ); + if($Self->{DBObject}->FetchrowArray()){ + return 1; } - - # build output - my $Output = $Self->{LayoutObject}->Header(Title => "Tag"); - - if ($Self->{ParamObject}->GetParam( Param => 'added' )) { - my $Added = $Self->{ParamObject}->GetParam( Param => 'added' ); - $Output .= $Self->{LayoutObject}->Notify( Info => 'Tag '.$Added.' adicionada!' ); + + return 0; +} + +sub updateTag{ + my ( $Self, %Param ) = @_; + + for (qw(TagID Tag)) { + if ( !$Param{$_} ) { + $Self->{LayoutObject} + ->FatalError( Message => Dumper( \%Param ) . "got no $_!" ); + } } - if ($Self->{ParamObject}->GetParam( Param => 'edited' )) { - my $Edited = $Self->{ParamObject}->GetParam( Param => 'edited' ); - $Output .= $Self->{LayoutObject}->Notify( Info => 'Tag '.$Edited.' modificada!' ); + + $Self->{DBObject}->Do( + SQL => "update faq_tag set tag= ? where id = ?", + Bind => [\$Param{Tag}, \$Param{TagID} ] + ); +} + +sub adicionaTag{ + my ( $Self, %Param ) = @_; + + for (qw( CategoryID Tag)) { + if ( !$Param{$_} ) { + $Self->{LayoutObject} + ->FatalError( Message => Dumper( \%Param ) . "got no $_!" ); + } } - $Output .= $Self->{LayoutObject}->NavigationBar(); - $Output .= $Self->{LayoutObject}->Output( - Data => \%Data, - TemplateFile => 'AgentFAQTagOverview', + $Self->{DBObject}->Do( + SQL => "insert into faq_tag (category_id, tag) values (?,?)", + Bind => [\$Param{CategoryID}, \$Param{Tag}] ); - $Output .= $Self->{LayoutObject}->Footer(); - return $Output; +} + +sub removeTag{ + my ( $Self, %Param ) = @_; + for (qw( TagID )) { + if ( !$Param{$_} ) { + $Self->{LayoutObject} + ->FatalError( Message => Dumper( \%Param ) . "got no $_!" ); + } + } + + $Self->{DBObject}->Do( + SQL => "delete from faq_tag where id = ?", + Bind => [\$Param{TagID}] + ); } + 1; diff --git a/Kernel/Output/HTML/Standard/AgentFAQTagAdd.dtl b/Kernel/Output/HTML/Standard/AgentFAQTagAdd.dtl index 9024750..18dba76 100755 --- a/Kernel/Output/HTML/Standard/AgentFAQTagAdd.dtl +++ b/Kernel/Output/HTML/Standard/AgentFAQTagAdd.dtl @@ -5,14 +5,12 @@ } -
- -
+ - +
-

$Text{"Gerenciamento de Materiais"}

+

$Text{"Gerenciamento de Tags"}

@@ -21,7 +19,7 @@ @@ -30,18 +28,19 @@
- -

Editar Tag: $QData{"category"}

+

Editar Tag: $QData{"CategoryName"}

- +
- - - + + + +
+ $QData{"MensagemErro"}
@@ -49,13 +48,12 @@ Cancelar
- +
-
diff --git a/Kernel/Output/HTML/Standard/AgentFAQTagOverview.dtl b/Kernel/Output/HTML/Standard/AgentFAQTagOverview.dtl index 45a1c43..7f3af0a 100755 --- a/Kernel/Output/HTML/Standard/AgentFAQTagOverview.dtl +++ b/Kernel/Output/HTML/Standard/AgentFAQTagOverview.dtl @@ -21,21 +21,24 @@ - - - + + + - - - - - + + + + + - +
CategoriaTagExcluir
Categoria
Tag
Opções
$QData{"category"}$QData{"tag"} - -
$QData{"Name"}
$QData{"Tag"}
+
+ + $Text{"Alterar Tag"} +
+
@@ -44,13 +47,13 @@
-- libgit2 0.21.2