From 0358e0f29f3aa049d17cd52004426743434f2169 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 19 Apr 2018 15:11:26 +0200 Subject: [PATCH] Debug ticketsup --- .../core/class/html.formticketsup.class.php | 11 +- htdocs/core/lib/ticketsup.lib.php | 2 +- ...face_50_modTicketsup_TicketEmail.class.php | 108 ++++++------ htdocs/public/ticketsup/create_ticket.php | 161 ++++++++++-------- htdocs/public/ticketsup/index.php | 6 +- htdocs/public/ticketsup/list.php | 10 +- htdocs/public/ticketsup/view.php | 4 +- .../class/actions_ticketsup.class.php | 4 +- htdocs/ticketsup/class/ticketsup.class.php | 2 +- 9 files changed, 164 insertions(+), 144 deletions(-) diff --git a/htdocs/core/class/html.formticketsup.class.php b/htdocs/core/class/html.formticketsup.class.php index 732d495efb2..9090fae90ca 100644 --- a/htdocs/core/class/html.formticketsup.class.php +++ b/htdocs/core/class/html.formticketsup.class.php @@ -272,7 +272,7 @@ class FormTicketsup dol_include_once('/' . $element . '/class/' . $subelement . '.class.php'); $classname = ucfirst($subelement); $objectsrc = new $classname($this->db); - $objectsrc->fetch(GETPOST('originid')); + $objectsrc->fetch(GETPOST('originid','int')); if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) { $objectsrc->fetch_lines(); @@ -299,9 +299,12 @@ class FormTicketsup print ''; // Notify thirdparty at creation - print ''; - print 'withnotifytiersatcreate?' checked="checked"':'').'>'; - print ''; + if (empty($this->ispublic)) + { + print ''; + print 'withnotifytiersatcreate?' checked="checked"':'').'>'; + print ''; + } // TITLE if ($this->withtitletopic) { diff --git a/htdocs/core/lib/ticketsup.lib.php b/htdocs/core/lib/ticketsup.lib.php index 040dad6c656..e377fb5e064 100644 --- a/htdocs/core/lib/ticketsup.lib.php +++ b/htdocs/core/lib/ticketsup.lib.php @@ -195,7 +195,7 @@ function showlogo() $urllogo = DOL_URL_ROOT . '/theme/dolibarr_logo.png'; } print '
'; - print 'Logo
'; + print 'Logo
'; print '' . ($conf->global->TICKETS_PUBLIC_INTERFACE_TOPIC ? $conf->global->TICKETS_PUBLIC_INTERFACE_TOPIC : $langs->trans("TicketSystem")) . ''; print '

'; } diff --git a/htdocs/core/triggers/interface_50_modTicketsup_TicketEmail.class.php b/htdocs/core/triggers/interface_50_modTicketsup_TicketEmail.class.php index d46738d4318..d27f0d6aa67 100644 --- a/htdocs/core/triggers/interface_50_modTicketsup_TicketEmail.class.php +++ b/htdocs/core/triggers/interface_50_modTicketsup_TicketEmail.class.php @@ -182,62 +182,66 @@ class InterfaceTicketEmail extends DolibarrTriggers // Send email to notification email - $sendto = $conf->global->TICKETS_NOTIFICATION_EMAIL_TO; - if (empty($conf->global->TICKETS_DISABLE_ALL_MAILS) && $sendto) - { - // Init to avoid errors - $filepath = array(); - $filename = array(); - $mimetype = array(); + if (empty($conf->global->TICKETS_DISABLE_ALL_MAILS) && empty($object->context['disableticketsupemail'])) + { + $sendto = $conf->global->TICKETS_NOTIFICATION_EMAIL_TO; - /* Send email to admin */ - $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectAdmin'); - $message_admin= $langs->transnoentities('TicketNewEmailBodyAdmin', $object->track_id)."\n\n"; - $message_admin.=''; - - if ($object->fk_soc > 0) { - $object->fetch_thirdparty(); - $message_admin.='

'.$langs->trans('Company'). ' : '.$object->thirdparty->name.'

'; - } - - $message_admin.='

'.$langs->trans('Message').' :
'.$object->message.'

'; - $message_admin.='

'.$langs->trans('SeeThisTicketIntomanagementInterface').'

'; - - $from = $conf->global->MAIN_INFO_SOCIETE_NOM.'<'.$conf->global->TICKETS_NOTIFICATION_EMAIL_FROM.'>'; - $replyto = $from; - - $message_admin = dol_nl2br($message_admin); - - if (!empty($conf->global->TICKETS_DISABLE_MAIL_AUTOCOPY_TO)) { - $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; - $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; - } - include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $mailfile = new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1); - if ($mailfile->error) { - dol_syslog($mailfile->error, LOG_DEBUG); - } else { - $result=$mailfile->sendfile(); - } - if (!empty($conf->global->TICKETS_DISABLE_MAIL_AUTOCOPY_TO)) { - $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; - } - } + include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; + $mailfile = new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1); + if ($mailfile->error) { + dol_syslog($mailfile->error, LOG_DEBUG); + } else { + $result=$mailfile->sendfile(); + } + if (!empty($conf->global->TICKETS_DISABLE_MAIL_AUTOCOPY_TO)) { + $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; + } + } + } // Send email to customer - if (empty($conf->global->TICKETS_DISABLE_ALL_MAILS) && empty($object->context['disableemailtothirdparty']) && $object->notify_tiers_at_create) + if (empty($conf->global->TICKETS_DISABLE_ALL_MAILS) && empty($object->context['disableticketsupemail']) && $object->notify_tiers_at_create) { $sendto = ''; if (empty($user->socid) && empty($user->email)) { @@ -283,7 +287,7 @@ class InterfaceTicketEmail extends DolibarrTriggers $message_customer.=''; $message_customer.='

'.$langs->trans('Message').' :
'.$object->message.'

'; - $url_public_ticket = ($conf->global->TICKETS_URL_PUBLIC_INTERFACE?$conf->global->TICKETS_URL_PUBLIC_INTERFACE.'/':dol_buildpath('/ticketsup/public/view.php', 2)).'?track_id='.$object->track_id; + $url_public_ticket = ($conf->global->TICKETS_URL_PUBLIC_INTERFACE?$conf->global->TICKETS_URL_PUBLIC_INTERFACE.'/':dol_buildpath('/public/ticketsup/view.php', 2)).'?track_id='.$object->track_id; $message_customer.='

' . $langs->trans('TicketNewEmailBodyInfosTrackUrlCustomer') . ' : '.$url_public_ticket.'

'; $message_customer.='

'.$langs->trans('TicketEmailPleaseDoNotReplyToThisEmail').'

'; diff --git a/htdocs/public/ticketsup/create_ticket.php b/htdocs/public/ticketsup/create_ticket.php index 7dc6da87bcc..6ac1fa6c33a 100644 --- a/htdocs/public/ticketsup/create_ticket.php +++ b/htdocs/public/ticketsup/create_ticket.php @@ -17,9 +17,9 @@ */ /** - * Display public form to add new ticket - * - * \ingroup ticketsup + * \file htdocs/public/ticketsup/index.php + * \ingroup ticketsup + * \brief Display public form to add new ticket */ if (!defined('NOREQUIREUSER')) { define('NOREQUIREUSER', '1'); @@ -130,11 +130,11 @@ if ($action == 'create_ticket' && GETPOST('add_ticket')) { } } - if (!GETPOST("subject")) { + if (!GETPOST("subject","none")) { $error++; array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Subject"))); $action = ''; - } elseif (!GETPOST("message")) { + } elseif (!GETPOST("message","none")) { $error++; array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("message"))); $action = ''; @@ -152,13 +152,13 @@ if ($action == 'create_ticket' && GETPOST('add_ticket')) { $object->track_id = generate_random_id(16); - $object->subject = GETPOST("subject"); - $object->message = GETPOST("message"); + $object->subject = GETPOST("subject","none"); + $object->message = GETPOST("message","none"); $object->origin_email = $origin_email; - $object->type_code = GETPOST("type_code"); - $object->category_code = GETPOST("category_code"); - $object->severity_code = GETPOST("severity_code"); + $object->type_code = GETPOST("type_code", 'az09'); + $object->category_code = GETPOST("category_code", 'az09'); + $object->severity_code = GETPOST("severity_code", 'az09'); if (is_array($searched_companies)) { $object->fk_soc = $searched_companies[0]->id; } @@ -176,7 +176,7 @@ if ($action == 'create_ticket' && GETPOST('add_ticket')) { $user = new User($db); } - $object->context['disableemailtothirdparty']=1; // Disable email sent by ticketsup trigger when creation is done from this page + $object->context['disableticketsupemail']=1; // Disable emails sent by ticketsup trigger when creation is done from this page, emails are already sent later $id = $object->create($user); if ($id <= 0) { @@ -190,9 +190,20 @@ if ($action == 'create_ticket' && GETPOST('add_ticket')) { if ($usertoassign > 0) { $object->add_contact($usertoassign, "SUPPORTCLI", 'external', $notrigger = 0); } + } - $object->db->commit(); + if (! $error) + { + $object->db->commit(); + $action = "infos_success"; + } else { + $object->db->rollback(); + setEventMessage($object->errors, 'errors'); + $action = 'create_ticket'; + } + if (! $error) + { $res = $object->fetch($id); if ($res) { // Create form object @@ -211,18 +222,19 @@ if ($action == 'create_ticket' && GETPOST('add_ticket')) { $mimetype = $attachedfiles['mimes']; // Send email to customer + $subject = '[' . $conf->global->MAIN_INFO_SOCIETE_NOM . '] ' . $langs->transnoentities('TicketNewEmailSubject'); $message .= ($conf->global->TICKETS_MESSAGE_MAIL_NEW ? $conf->global->TICKETS_MESSAGE_MAIL_NEW : $langs->transnoentities('TicketNewEmailBody')) . "\n\n"; $message .= $langs->transnoentities('TicketNewEmailBodyInfosTicket') . "\n"; - $url_public_ticket = ($conf->global->TICKETS_URL_PUBLIC_INTERFACE ? $conf->global->TICKETS_URL_PUBLIC_INTERFACE . '/' : dol_buildpath('/ticketsup/public/view.php', 2)) . '?track_id=' . $object->track_id; + $url_public_ticket = ($conf->global->TICKETS_URL_PUBLIC_INTERFACE ? $conf->global->TICKETS_URL_PUBLIC_INTERFACE . '/' : dol_buildpath('/public/ticketsup/view.php', 2)) . '?track_id=' . $object->track_id; $infos_new_ticket = $langs->transnoentities('TicketNewEmailBodyInfosTrackId', '' . $object->track_id . '') . "\n"; $infos_new_ticket .= $langs->transnoentities('TicketNewEmailBodyInfosTrackUrl') . "\n\n"; $message .= dol_nl2br($infos_new_ticket); $message .= $conf->global->TICKETS_MESSAGE_MAIL_SIGNATURE ? $conf->global->TICKETS_MESSAGE_MAIL_SIGNATURE : $langs->transnoentities('TicketMessageMailSignatureText'); - $sendto = GETPOST('email'); + $sendto = GETPOST('email','alpha'); $from = $conf->global->MAIN_INFO_SOCIETE_NOM . '<' . $conf->global->TICKETS_NOTIFICATION_EMAIL_FROM . '>'; $replyto = $from; @@ -244,79 +256,80 @@ if ($action == 'create_ticket' && GETPOST('add_ticket')) { $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; } - /* Send email to admin */ + + // Send email to TICKETS_NOTIFICATION_EMAIL_TO + $sendto = $conf->global->TICKETS_NOTIFICATION_EMAIL_TO; - $subject = '[' . $conf->global->MAIN_INFO_SOCIETE_NOM . '] ' . $langs->transnoentities('TicketNewEmailSubjectAdmin'); - $message_admin = $langs->transnoentities('TicketNewEmailBodyAdmin', $object->track_id) . "\n\n"; - $message_admin .= ''; + $message_admin .= '

' . $langs->trans('Message') . ' :
' . $object->message . '

'; + $message_admin .= '

' . $langs->trans('SeeThisTicketIntomanagementInterface') . '

'; - $message_admin = dol_nl2br($message_admin); + $from = $conf->global->MAIN_INFO_SOCIETE_NOM . '<' . $conf->global->TICKETS_NOTIFICATION_EMAIL_FROM . '>'; + $replyto = $from; - if (!empty($conf->global->TICKETS_DISABLE_MAIL_AUTOCOPY_TO)) { - $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; - $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; - } - include_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php'; - $mailfile = new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1); - if ($mailfile->error) { - setEventMessage($mailfile->error, 'errors'); - } else { - $result = $mailfile->sendfile(); - } - if (!empty($conf->global->TICKETS_DISABLE_MAIL_AUTOCOPY_TO)) { - $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; - } + $message_admin = dol_nl2br($message_admin); - // Copy files into ticket directory - $destdir = $conf->ticketsup->dir_output . '/' . $object->track_id; - if (!dol_is_dir($destdir)) { - dol_mkdir($destdir); - } - foreach ($filename as $i => $val) { - dol_move($filepath[$i], $destdir . '/' . $filename[$i], 0, 1); - $formmail->remove_attached_files($i); + if (!empty($conf->global->TICKETS_DISABLE_MAIL_AUTOCOPY_TO)) { + $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO; + $conf->global->MAIN_MAIL_AUTOCOPY_TO = ''; + } + include_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php'; + $mailfile = new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1); + if ($mailfile->error) { + setEventMessage($mailfile->error, 'errors'); + } else { + $result = $mailfile->sendfile(); + } + if (!empty($conf->global->TICKETS_DISABLE_MAIL_AUTOCOPY_TO)) { + $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; + } } } + // Copy files into ticket directory + $destdir = $conf->ticketsup->dir_output . '/' . $object->track_id; + if (! dol_is_dir($destdir)) { + dol_mkdir($destdir); + } + foreach ($filename as $i => $val) { + dol_move($filepath[$i], $destdir . '/' . $filename[$i], 0, 1); + $formmail->remove_attached_files($i); + } + setEventMessage($langs->trans('YourTicketSuccessfullySaved')); - $action = "infos_success"; - } else { - $object->db->rollback(); - setEventMessage($object->errors, 'errors'); - $action = 'create_ticket'; } } else { setEventMessage($object->errors, 'errors'); diff --git a/htdocs/public/ticketsup/index.php b/htdocs/public/ticketsup/index.php index 576eee32bc4..bbb0be1d471 100644 --- a/htdocs/public/ticketsup/index.php +++ b/htdocs/public/ticketsup/index.php @@ -16,9 +16,9 @@ */ /** - * \file ticketsup/public/index.php - * \ingroup ticketsup - * \brief Public file to add and manage ticket + * \file htdocs/public/ticketsup/index.php + * \ingroup ticketsup + * \brief Public file to add and manage ticket */ //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); diff --git a/htdocs/public/ticketsup/list.php b/htdocs/public/ticketsup/list.php index 2b8f3d821d2..d0388841c7e 100644 --- a/htdocs/public/ticketsup/list.php +++ b/htdocs/public/ticketsup/list.php @@ -16,9 +16,9 @@ */ /** - * \file ticketsup/public/index.php - * \ingroup ticketsup - * \brief Public file to add and manage ticket + * \file htdocs/public/ticketsup/list.php + * \ingroup ticketsup + * \brief Public file to add and manage ticket */ if (!defined('NOCSRFCHECK')) { @@ -155,7 +155,7 @@ if ($action == "view_ticketlist") { $search_fk_user_assign = GETPOST("search_fk_user_assign", 'int'); // Store current page url - $url_page_current = dol_buildpath('/ticketsup/public/list.php', 1); + $url_page_current = dol_buildpath('/public/ticketsup/list.php', 1); // Do we click on purge search criteria ? if (GETPOST("button_removefilter_x")) { @@ -635,7 +635,7 @@ if ($action == "view_ticketlist") { print ''; print ''; - print '