AgentFAQTagAdd.pm
2.61 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
package Kernel::Modules::AgentFAQTagAdd;
use strict;
use warnings;
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 EncodeObject MainObject)) {
if ( !$Self->{$_} ) {
$Self->{LayoutObject}->FatalError( Message => "Got no $_!" );
}
}
return $Self;
}
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");
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 {
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;
}
sub _ExisteTag {
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;
}
1;