#!/usr/bin/perl -w
# --
# create ticket with an article 
# Copyright (C) 
# --
# $Id: otrs.addUser,v 1.8 2003/03/06 22:11:59 martin Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (GPL). If you
# did not receive this file, see http://www.gnu.org/licenses/gpl.txt.
# --

use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);
use lib dirname($RealBin)."/Kernel/cpan-lib";

use Kernel::Config;
use Kernel::System::Time;
use Kernel::System::Log;
use Kernel::System::DB;
use Kernel::System::Ticket;
my $ConfigObject = Kernel::Config->new();
my $TimeObject    = Kernel::System::Time->new(
    ConfigObject => $ConfigObject,
);
my $LogObject    = Kernel::System::Log->new(
    ConfigObject => $ConfigObject,
    LogPrefix => "CreateTicket.pl",
);
my $DBObject = Kernel::System::DB->new(
    ConfigObject => $ConfigObject,
    LogObject => $LogObject,
);
my $TicketObject = Kernel::System::Ticket->new(
    ConfigObject => $ConfigObject,
    LogObject => $LogObject,
    DBObject => $DBObject,
    TimeObject => $TimeObject,
);

my $TicketID = $TicketObject->TicketCreate(
    TN => $TicketObject->TicketCreateNumber(),
    Queue => 'Raw',
    Lock => 'unlock',
    GroupID => 1,
    Priority => '3 normal',
    State => 'new',
    CustomerNo => '',
    CustomerUser => '',
    UserID => 1, # current owner
    CreateUserID => 1,
);
print "Ticket (TicketID:$TicketID) created.\n";

if ($TicketID) {
    my $ArticleID = $TicketObject->ArticleCreate(
        TicketID => $TicketID,
        ArticleType => 'note-external', # email-external|email-internal|phone|fax|...
        SenderType => 'customer',         # agent|system|customer
        From => 'Some Agent <email@example.com>',   # not required but useful
        To => 'Some Customer A <customer-a@example.com>', # not required but useful
        Cc => 'Some Customer B <customer-b@example.com>', # not required but useful
        Subject => 'some short description',        # required
        Body => 'the message text',                 # required
        ContentType => 'text/plain; charset=ISO-8859-15',
        HistoryType => 'EmailCustomer',  # EmailCustomer|Move|AddNote|PriorityUpdate|WebRequestCustomer|...
        HistoryComment => 'Some free text!',
        UserID => 1,
    );
    print "Article (ArticleID:$ArticleID) aded to TicketID $TicketID.\n";
}

exit (0);
