<?php

/**
 * @copyright      2001-2015 Kayako
 * @license        https://www.freebsd.org/copyright/freebsd-license.html
 * @link           https://github.com/kayako/joomla-integration
 */
defined('_JEXEC') or die;
require_once 'modules/mod_kayako/includes/kayako-php-api/kyIncludes.php';
require_once 'modules/mod_kayako/helper.php';
$email = JFactory::getUser()->email;
$ticket_obj = new JTickets();
$ticket_obj->fetchAllDepartment();
?>
<link rel="stylesheet" type="text/css" href="modules/mod_kayako/resources/css/style.css">

<div class="<?php 
echo $params->get('moduleclass_sfx');
?>
">
	<form method="POST" name="ticketform" autocomplete="off">
		<fieldset>
			<legend class="small">Deparment</legend>
			<table class="create">
				<tr>
					<td>Select Department</td>
					<td>
						<select name="dep_type" required>
							<?php 
foreach ($ticket_obj->all_departments as $key => $value) {
    ?>
/**
 * @copyright      2001-2015 Kayako
 * @license        https://www.freebsd.org/copyright/freebsd-license.html
 * @link           https://github.com/kayako/joomla-integration
 */
defined('_JEXEC') or die;
require_once 'modules/mod_kayako/includes/kayako-php-api/kyIncludes.php';
require_once 'modules/mod_kayako/helper.php';
$email = JFactory::getUser()->email;
if (empty($email) || !isset($email)) {
    throw new kyException();
}
$input = JFactory::getApplication()->input;
$get_dep_id = $input->get('dep_type');
$ticket_object = new JTickets();
$ticket_object->fetchAllDepartment();
$ticket_object->view($get_dep_id);
?>

<link rel="stylesheet" type="text/css" href="modules/mod_kayako/resources/css/style.css">
<div class="<?php 
echo $params->get('moduleclass_sfx');
?>
">
	<div>
		<form method="POST" name="department_form">
			<select name="dep_type" onchange="this.form.submit()">
				<option value="0">Select a department</option>
				<?php 
foreach ($ticket_object->all_departments as $key => $value) {
 * @link           https://github.com/kayako/joomla-integration
 */
defined('_JEXEC') or die;
$input = new JInput();
if ($input->get('add', null)) {
    require_once dirname(__FILE__) . "/helper.php";
    $status = JTickets::createTickets();
    if ($status) {
        printf("The ticket was created and its ID is: %s\n", $status);
    } else {
        echo "Some fields are missing or invalid";
    }
} else {
    if ($input->get('update', null)) {
        require_once dirname(__FILE__) . "/helper.php";
        $update_status = JTickets::editTicket();
        header('location:' . $_SERVER['HTTP_REFERER']);
    } else {
        if ($input->get('reply', null)) {
            require_once dirname(__FILE__) . "/helper.php";
            $update_status = JTickets::postReply();
            header('location:' . $_SERVER['HTTP_REFERER']);
        } else {
            $user =& JFactory::getUser();
            if ($user->id != 0) {
                require_once __DIR__ . '/helper.php';
                require JModuleHelper::getLayoutPath('mod_kayako', $params->get('layout', 'default'));
            }
        }
    }
}
 * @copyright      2001-2015 Kayako
 * @license        https://www.freebsd.org/copyright/freebsd-license.html
 * @link           https://github.com/kayako/joomla-integration
 */
defined('_JEXEC') or die;
require_once 'modules/mod_kayako/includes/kayako-php-api/kyIncludes.php';
require_once 'modules/mod_kayako/helper.php';
$email = JFactory::getUser()->email;
if (empty($email) || !isset($email)) {
    throw new kyException();
}
//Retrieve the get value
$input = JFactory::getApplication()->input;
//$edit_id = $input->get('id', null);
$edit_id = $_REQUEST['ticketid'];
JTickets::init();
$all_departments = kyDepartment::getAll()->filterByModule(kyDepartment::MODULE_TICKETS)->filterByType(kyDepartment::TYPE_PUBLIC);
$department_titles = kyDepartment::getAll()->collectTitle();
$department_id = kyDepartment::getAll()->collectId();
$priority_list = kyTicketPriority::getAll();
$status_list = kyTicketStatus::getAll();
$ticket_type = kyTicketType::getAll();
$ticket_details = kyTicket::get($edit_id);
$document =& JFactory::getDocument();
$document->addScript('/media/jui/js/jquery.min.js');
?>

<link rel="stylesheet" type="text/css" href="modules/mod_kayako/resources/css/style.css">

<script>
	jQuery(document).ready(function() {
 /**
  * Post a message to the user
  *
  * @return bool
  */
 public function postReply()
 {
     require_once 'modules/mod_kayako/includes/kayako-php-api/kyIncludes.php';
     $confObject = JFactory::getApplication();
     $tmp_path = $confObject->getCfg('tmp_path');
     JTickets::init();
     //Fetch Post data
     $input = JFactory::getApplication()->input;
     $form_value = $input->getArray(array('content' => null, 'id' => null, 'replyattachments' => null));
     $img = $_FILES['replyattachments']['name'];
     //Fetch the email of login User
     $email = JFactory::getUser()->email;
     $user = kyUser::search($email)->getRawArray();
     $ticket_object = kyTicket::get($form_value['id']);
     $user_reply_post = $ticket_object->newPost($user[0], $form_value['content'])->create();
     foreach ($img as $key => $value) {
         $name = time() . $_FILES["replyattachments"]["name"][$key];
         $temp_name = $_FILES["replyattachments"]["tmp_name"][$key];
         $size = $_FILES["replyattachments"]["size"][$key];
         if ($size < 1024 * 1024) {
             move_uploaded_file($temp_name, $tmp_path . "/" . $name);
             $user_reply_post->newAttachmentFromFile(JURI::Root() . "tmp/" . $name)->create();
         }
     }
     return true;
 }