*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/**
* \file htdocs/public/ticket/index.php
* \ingroup ticket
* \brief Public file to add and manage ticket
*/
if (!defined('NOCSRFCHECK')) {
define('NOCSRFCHECK', '1');
}
// Do not check anti CSRF attack test
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1');
}
// If there is no need to load and show top and left menu
if (!defined("NOLOGIN")) {
define("NOLOGIN", '1');
}
// If this page is public (can be called outside logged session)
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
// Load translation files required by the page
$langs->loadLangs(array("companies","other","ticket"));
// Get parameters
$track_id = GETPOST('track_id', 'alpha');
$action = GETPOST('action', 'alpha', 3);
$email = GETPOST('email', 'alpha');
if (GETPOST('btn_view_ticket')) {
unset($_SESSION['email_customer']);
}
if (isset($_SESSION['email_customer'])) {
$email = $_SESSION['email_customer'];
}
$object = new ActionsTicket($db);
/*
* Actions
*/
if ($action == "view_ticket" || $action == "add_message" || $action == "close" || $action == "confirm_public_close" || $action == "new_public_message") {
$error = 0;
$display_ticket = false;
if (!strlen($track_id)) {
$error++;
array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("TicketTrackId")));
$action = '';
}
if (!strlen($email)) {
$error++;
array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Email")));
$action = '';
} else {
if (!isValidEmail($email)) {
$error++;
array_push($object->errors, $langs->trans("ErrorEmailInvalid"));
$action = '';
}
}
if (!$error) {
$ret = $object->fetch('', '', $track_id);
if ($ret && $object->dao->id > 0) {
// vérifie si l'adresse email est bien dans les contacts du ticket
$contacts = $object->dao->liste_contact(-1, 'external');
foreach ($contacts as $contact) {
if ($contact['email'] == $email) {
$display_ticket = true;
$_SESSION['email_customer'] = $email;
break;
} else {
$display_ticket = false;
}
}
if ($object->dao->fk_soc > 0) {
$object->dao->fetch_thirdparty();
}
if ($email == $object->dao->origin_email || $email == $object->dao->thirdparty->email) {
$display_ticket = true;
$_SESSION['email_customer'] = $email;
}
} else {
$error++;
array_push($object->errors, $langs->trans("ErrorTicketNotFound", $track_id));
$action = '';
}
}
if ($error) {
setEventMessage($object->errors, 'errors');
$action = '';
}
}
$object->doActions($action);
/*
* View
*/
$form = new Form($db);
$formticket = new FormTicket($db);
$arrayofjs = array();
$arrayofcss = array('/ticket/css/styles.css.php');
llxHeaderTicket($langs->trans("Tickets"), "", 0, 0, $arrayofjs, $arrayofcss);
if (!$conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) {
print '
' . $langs->trans('TicketPublicInterfaceForbidden') . '
';
$db->close();
exit();
}
print '';
if ($action == "view_ticket" || $action == "add_message" || $action == "close" || $action == "confirm_public_close") {
if ($display_ticket) {
// Confirmation close
if ($action == 'close') {
$ret = $form->form_confirm($_SERVER["PHP_SELF"] . "?track_id=" . $track_id, $langs->trans("CloseATicket"), $langs->trans("ConfirmCloseAticket"), "confirm_public_close", '', '', 1);
if ($ret == 'html') {
print '
';
}
}
print '
';
print '
';
if ($action == 'add_message') {
print load_fiche_titre($langs->trans('TicketAddMessage'), '', 'messages@ticket');
$formticket = new FormTicket($db);
$formticket->action = "new_public_message";
$formticket->track_id = $object->dao->track_id;
$formticket->id = $object->dao->id;
$formticket->param = array('fk_user_create' => '-1');
$formticket->withfile = 2;
$formticket->showMessageForm('100%');
} else {
print '
\n";
print '
';
// List ticket
print '
';
if ($object->dao->fk_statut < 8) {
// New message
print '
';
// Close ticket
if ($object->dao->fk_statut > 0 && $object->dao->fk_statut < 8) {
print '
';
}
}
print '
';
}
// Message list
print load_fiche_titre($langs->trans('TicketMessagesList'), '', 'messages@ticket');
$object->viewTicketMessages(false);
print '
';
// Logs list
print load_fiche_titre($langs->trans('TicketHistory'), '', 'history@ticket');
$object->viewTicketLogs(false);
} else {
print '
';
}
} else {
print '
' . $langs->trans("TicketPublicMsgViewLogIn") . '
';
print '
\n";
}
// End of page
llxFooter();
$db->close();