AgentFAQTagAdd.pm 2.61 KB


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;