Debug ticket module

This commit is contained in:
Laurent Destailleur 2018-04-19 14:44:21 +02:00
parent 8aab183567
commit 8acc752195
5 changed files with 229 additions and 194 deletions

View File

@ -71,7 +71,7 @@ if ($action == 'updateMask') {
if (!empty($notification_email)) { if (!empty($notification_email)) {
$res = dolibarr_set_const($db, 'TICKETS_NOTIFICATION_EMAIL_FROM', $notification_email, 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, 'TICKETS_NOTIFICATION_EMAIL_FROM', $notification_email, 'chaine', 0, '', $conf->entity);
} else { } else {
$res = dolibarr_set_const($db, 'TICKETS_NOTIFICATION_EMAIL_FROM', '000000', 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, 'TICKETS_NOTIFICATION_EMAIL_FROM', '', 'chaine', 0, '', $conf->entity);
} }
if (!$res > 0) { if (!$res > 0) {
$error++; $error++;
@ -82,7 +82,7 @@ if ($action == 'updateMask') {
if (!empty($notification_email_to)) { if (!empty($notification_email_to)) {
$res = dolibarr_set_const($db, 'TICKETS_NOTIFICATION_EMAIL_TO', $notification_email_to, 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, 'TICKETS_NOTIFICATION_EMAIL_TO', $notification_email_to, 'chaine', 0, '', $conf->entity);
} else { } else {
$res = dolibarr_set_const($db, 'TICKETS_NOTIFICATION_EMAIL_TO', '000000', 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, 'TICKETS_NOTIFICATION_EMAIL_TO', '', 'chaine', 0, '', $conf->entity);
} }
if (!$res > 0) { if (!$res > 0) {
$error++; $error++;
@ -184,16 +184,22 @@ if ($action == 'setvarother') {
$error++; $error++;
} }
$param_show_module_logo = GETPOST('TICKETS_SHOW_MODULE_LOGO', 'alpha'); if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
$res = dolibarr_set_const($db, 'TICKETS_SHOW_MODULE_LOGO', $param_show_module_logo, 'chaine', 0, '', $conf->entity); {
if (!$res > 0) { $param_show_module_logo = GETPOST('TICKETS_SHOW_MODULE_LOGO', 'alpha');
$error++; $res = dolibarr_set_const($db, 'TICKETS_SHOW_MODULE_LOGO', $param_show_module_logo, 'chaine', 0, '', $conf->entity);
if (!$res > 0) {
$error++;
}
} }
$param_notification_also_main_addressemail = GETPOST('TICKETS_NOTIFICATION_ALSO_MAIN_ADDRESS', 'alpha'); if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
$res = dolibarr_set_const($db, 'TICKETS_NOTIFICATION_ALSO_MAIN_ADDRESS', $param_notification_also_main_addressemail, 'chaine', 0, '', $conf->entity); {
if (!$res > 0) { $param_notification_also_main_addressemail = GETPOST('TICKETS_NOTIFICATION_ALSO_MAIN_ADDRESS', 'alpha');
$error++; $res = dolibarr_set_const($db, 'TICKETS_NOTIFICATION_ALSO_MAIN_ADDRESS', $param_notification_also_main_addressemail, 'chaine', 0, '', $conf->entity);
if (!$res > 0) {
$error++;
}
} }
$param_limit_view = GETPOST('TICKETS_LIMIT_VIEW_ASSIGNED_ONLY', 'alpha'); $param_limit_view = GETPOST('TICKETS_LIMIT_VIEW_ASSIGNED_ONLY', 'alpha');
@ -380,20 +386,23 @@ print $form->textwithpicto('', $langs->trans("TicketsEmailMustExistHelp"), 1, 'h
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
// Show logo for module if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
print '<tr class="pair"><td width="70%">' . $langs->trans("TicketsShowModuleLogo") . '</td>'; {
print '<td align="left">'; // Show logo for module
if ($conf->use_javascript_ajax) { print '<tr class="pair"><td width="70%">' . $langs->trans("TicketsShowModuleLogo") . '</td>';
print ajax_constantonoff('TICKETS_SHOW_MODULE_LOGO'); print '<td align="left">';
} else { if ($conf->use_javascript_ajax) {
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); print ajax_constantonoff('TICKETS_SHOW_MODULE_LOGO');
print $form->selectarray("TICKETS_SHOW_MODULE_LOGO", $arrval, $conf->global->TICKETS_SHOW_MODULE_LOGO); } else {
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
print $form->selectarray("TICKETS_SHOW_MODULE_LOGO", $arrval, $conf->global->TICKETS_SHOW_MODULE_LOGO);
}
print '</td>';
print '<td align="center">';
print $form->textwithpicto('', $langs->trans("TicketsShowModuleLogoHelp"), 1, 'help');
print '</td>';
print '</tr>';
} }
print '</td>';
print '<td align="center">';
print $form->textwithpicto('', $langs->trans("TicketsShowModuleLogoHelp"), 1, 'help');
print '</td>';
print '</tr>';
// Show logo for company // Show logo for company
print '<tr class="pair"><td width="70%">' . $langs->trans("TicketsShowCompanyLogo") . '</td>'; print '<tr class="pair"><td width="70%">' . $langs->trans("TicketsShowCompanyLogo") . '</td>';
@ -446,19 +455,22 @@ print '</td>';
print '</tr>'; print '</tr>';
// Also send to main email address // Also send to main email address
print '<tr class="pair"><td width="70%">' . $langs->trans("TicketsEmailAlsoSendToMainAddress") . '</td>'; if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
print '<td align="left">'; {
if ($conf->use_javascript_ajax) { print '<tr class="pair"><td width="70%">' . $langs->trans("TicketsEmailAlsoSendToMainAddress") . '</td>';
print ajax_constantonoff('TICKETS_NOTIFICATION_ALSO_MAIN_ADDRESS'); print '<td align="left">';
} else { if ($conf->use_javascript_ajax) {
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); print ajax_constantonoff('TICKETS_NOTIFICATION_ALSO_MAIN_ADDRESS');
print $form->selectarray("TICKETS_NOTIFICATION_ALSO_MAIN_ADDRESS", $arrval, $conf->global->TICKETS_NOTIFICATION_ALSO_MAIN_ADDRESS); } else {
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
print $form->selectarray("TICKETS_NOTIFICATION_ALSO_MAIN_ADDRESS", $arrval, $conf->global->TICKETS_NOTIFICATION_ALSO_MAIN_ADDRESS);
}
print '</td>';
print '<td align="center">';
print $form->textwithpicto('', $langs->trans("TicketsEmailAlsoSendToMainAddressHelp"), 1, 'help');
print '</td>';
print '</tr>';
} }
print '</td>';
print '<td align="center">';
print $form->textwithpicto('', $langs->trans("TicketsEmailAlsoSendToMainAddressHelp"), 1, 'help');
print '</td>';
print '</tr>';
// Limiter la vue des tickets à ceux assignés à l'utilisateur // Limiter la vue des tickets à ceux assignés à l'utilisateur
print '<tr class="pair"><td width="70%">' . $langs->trans("TicketsLimitViewAssignedOnly") . '</td>'; print '<tr class="pair"><td width="70%">' . $langs->trans("TicketsLimitViewAssignedOnly") . '</td>';

View File

@ -113,10 +113,10 @@ class FormTicketsup
/** /**
* Show the form to input ticket * Show the form to input ticket
* *
* @param string $width Width of form * @param int $withdolfichehead With dol_fiche_head
* @return void * @return void
*/ */
public function showForm($width = '100%') public function showForm($withdolfichehead=0)
{ {
global $conf, $langs, $user, $hookmanager; global $conf, $langs, $user, $hookmanager;
@ -140,7 +140,9 @@ class FormTicketsup
print "\n<!-- Begin form TICKETSUP -->\n"; print "\n<!-- Begin form TICKETSUP -->\n";
print '<form method="POST" style="margin-bottom: 30px;" name="ticketsup" id="form_create_ticket" enctype="multipart/form-data" action="' . $this->param["returnurl"] . '">'; if ($withdolfichehead) dol_fiche_head(null, 'card', '', 0, '');
print '<form method="POST" '.($withdolfichehead?'':'style="margin-bottom: 30px;" ').'name="ticketsup" id="form_create_ticket" enctype="multipart/form-data" action="' . $this->param["returnurl"] . '">';
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="action" value="' . $this->action . '">'; print '<input type="hidden" name="action" value="' . $this->action . '">';
foreach ($this->param as $key => $value) { foreach ($this->param as $key => $value) {
@ -149,7 +151,7 @@ class FormTicketsup
print '<input type="hidden" name="fk_user_create" value="' . $this->fk_user_create . '">'; print '<input type="hidden" name="fk_user_create" value="' . $this->fk_user_create . '">';
print '<div class="">'; print '<div class="">';
print '<table class="tableticket" width="' . $width . '">'; print '<table class="tableticket centpercent">';
if ($this->withref) { if ($this->withref) {
@ -394,6 +396,8 @@ class FormTicketsup
print '</table>'; print '</table>';
print '</div>'; print '</div>';
if ($withdolfichehead) dol_fiche_end();
print '<center>'; print '<center>';
print '<input class="button" type="submit" name="add_ticket" value="' . $langs->trans(($this->withthreadid > 0 ? "SendResponse" : "NewTicket")) . '" />'; print '<input class="button" type="submit" name="add_ticket" value="' . $langs->trans(($this->withthreadid > 0 ? "SendResponse" : "NewTicket")) . '" />';

View File

@ -110,189 +110,205 @@ class InterfaceTicketEmail extends DolibarrTriggers
case 'TICKET_ASSIGNED': case 'TICKET_ASSIGNED':
dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id);
if ($object->fk_user_assign > 0 && $object->fk_user_assign != $user->id) { if ($object->fk_user_assign > 0 && $object->fk_user_assign != $user->id)
{
$userstat = new User($this->db); $userstat = new User($this->db);
$res = $userstat->fetch($object->fk_user_assign); $res = $userstat->fetch($object->fk_user_assign);
if ($res) { if ($res > 0)
// Send email to assigned user {
$subject = '[' . $conf->global->MAIN_INFO_SOCIETE_NOM . '] ' . $langs->transnoentities('TicketAssignedToYou'); if (empty($conf->global->TICKETS_DISABLE_ALL_MAILS))
$message = '<p>' . $langs->transnoentities('TicketAssignedEmailBody', $object->track_id, dolGetFirstLastname($user->firstname, $user->lastname)) . "</p>"; {
$message .= '<ul><li>' . $langs->trans('Title') . ' : ' . $object->subject . '</li>'; // Init to avoid errors
$message .= '<li>' . $langs->trans('Type') . ' : ' . $object->type_label . '</li>'; $filepath = array();
$message .= '<li>' . $langs->trans('Category') . ' : ' . $object->category_label . '</li>'; $filename = array();
$message .= '<li>' . $langs->trans('Severity') . ' : ' . $object->severity_label . '</li>'; $mimetype = array();
// Extrafields
if (is_array($object->array_options) && count($object->array_options) > 0) { // Send email to assigned user
foreach ($object->array_options as $key => $value) { $subject = '[' . $conf->global->MAIN_INFO_SOCIETE_NOM . '] ' . $langs->transnoentities('TicketAssignedToYou');
$message .= '<li>' . $langs->trans($key) . ' : ' . $value . '</li>'; $message = '<p>' . $langs->transnoentities('TicketAssignedEmailBody', $object->track_id, dolGetFirstLastname($user->firstname, $user->lastname)) . "</p>";
$message .= '<ul><li>' . $langs->trans('Title') . ' : ' . $object->subject . '</li>';
$message .= '<li>' . $langs->trans('Type') . ' : ' . $object->type_label . '</li>';
$message .= '<li>' . $langs->trans('Category') . ' : ' . $object->category_label . '</li>';
$message .= '<li>' . $langs->trans('Severity') . ' : ' . $object->severity_label . '</li>';
// Extrafields
if (is_array($object->array_options) && count($object->array_options) > 0) {
foreach ($object->array_options as $key => $value) {
$message .= '<li>' . $langs->trans($key) . ' : ' . $value . '</li>';
}
}
$message .= '</ul>';
$message .= '<p>' . $langs->trans('Message') . ' : <br>' . $object->message . '</p>';
$message .= '<p><a href="' . dol_buildpath('/ticketsup/card.php', 2) . '?track_id=' . $object->track_id . '">' . $langs->trans('SeeThisTicketIntomanagementInterface') . '</a></p>';
$sendto = $userstat->email;
$from = dolGetFirstLastname($user->firstname, $user->lastname) . '<' . $user->email . '>';
$message = dol_nl2br($message);
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, $filepath, $mimetype, $filename, '', '', 0, -1);
$message .= '</ul>'; if ($mailfile->error) {
$message .= '<p>' . $langs->trans('Message') . ' : <br>' . $object->message . '</p>'; setEventMessage($mailfile->error, 'errors');
$message .= '<p><a href="' . dol_buildpath('/ticketsup/card.php', 2) . '?track_id=' . $object->track_id . '">' . $langs->trans('SeeThisTicketIntomanagementInterface') . '</a></p>'; } else {
$result = $mailfile->sendfile();
$sendto = $userstat->email; }
$from = dolGetFirstLastname($user->firstname, $user->lastname) . '<' . $user->email . '>'; if (!empty($conf->global->TICKETS_DISABLE_MAIL_AUTOCOPY_TO)) {
$conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
// Init to avoid errors }
$filepath = array(); }
$filename = array();
$mimetype = array();
$message = dol_nl2br($message);
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, $filepath, $mimetype, $filename, '', '', 0, -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;
}
$ok = 1; $ok = 1;
} }
else
{
$this->error = $userstat->error;
$this->errors = $userstat->errors;
}
} }
break; break;
case 'TICKET_CREATE': case 'TICKET_CREATE':
dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id); dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id);
// Init to avoid errors
$filepath = array();
$filename = array();
$mimetype = array();
$langs->load('ticketsup'); $langs->load('ticketsup');
$object->fetch('', $object->track_id); $object->fetch('', $object->track_id); // Should be useless
// Send email to notification email
/* Send email to admin */
$sendto = $conf->global->TICKETS_NOTIFICATION_EMAIL_TO; $sendto = $conf->global->TICKETS_NOTIFICATION_EMAIL_TO;
$subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectAdmin'); if (empty($conf->global->TICKETS_DISABLE_ALL_MAILS) && $sendto)
$message_admin= $langs->transnoentities('TicketNewEmailBodyAdmin', $object->track_id)."\n\n"; {
$message_admin.='<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>'; // Init to avoid errors
$message_admin.='<li>'.$langs->trans('Type').' : '.$object->type_label.'</li>'; $filepath = array();
$message_admin.='<li>'.$langs->trans('Category').' : '.$object->category_label.'</li>'; $filename = array();
$message_admin.='<li>'.$langs->trans('Severity').' : '.$object->severity_label.'</li>'; $mimetype = array();
$message_admin.='<li>'.$langs->trans('From').' : '.( $object->email_from ? $object->email_from : ( $object->fk_user_create > 0 ? $langs->trans('Internal') : '') ).'</li>';
// Extrafields
if (is_array($object->array_options) && count($object->array_options) > 0) {
foreach ($object->array_options as $key => $value) {
$message_admin.='<li>'.$langs->trans($key).' : '.$value.'</li>';
}
}
$message_admin.='</ul>';
if ($object->fk_soc > 0) {
$object->fetch_thirdparty();
$message_admin.='<p>'.$langs->trans('Company'). ' : '.$object->thirdparty->name.'</p>';
}
$message_admin.='<p>'.$langs->trans('Message').' : <br>'.$object->message.'</p>';
$message_admin.='<p><a href="'.dol_buildpath('/ticketsup/card.php', 2).'?track_id='.$object->track_id.'">'.$langs->trans('SeeThisTicketIntomanagementInterface').'</a></p>';
$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;
}
/* Send email to customer */
$sendto = '';
if (empty($user->socid) && empty($user->email)) {
$object->fetch_thirdparty();
$sendto = $object->thirdparty->email;
} else {
$sendto = $user->email;
}
if ($sendto && $object->notify_tiers_at_create) {
$subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectCustomer');
$message_customer= $langs->transnoentities('TicketNewEmailBodyCustomer', $object->track_id)."\n\n";
$message_customer.='<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>';
$message_customer.='<li>'.$langs->trans('Type').' : '.$object->type_label.'</li>';
$message_customer.='<li>'.$langs->trans('Category').' : '.$object->category_label.'</li>';
$message_customer.='<li>'.$langs->trans('Severity').' : '.$object->severity_label.'</li>';
/* 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.='<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>';
$message_admin.='<li>'.$langs->trans('Type').' : '.$object->type_label.'</li>';
$message_admin.='<li>'.$langs->trans('Category').' : '.$object->category_label.'</li>';
$message_admin.='<li>'.$langs->trans('Severity').' : '.$object->severity_label.'</li>';
$message_admin.='<li>'.$langs->trans('From').' : '.( $object->email_from ? $object->email_from : ( $object->fk_user_create > 0 ? $langs->trans('Internal') : '') ).'</li>';
// Extrafields // Extrafields
foreach ($this->attributes[$object->table_element]['label'] as $key => $value) if (is_array($object->array_options) && count($object->array_options) > 0) {
{ foreach ($object->array_options as $key => $value) {
$enabled = 1; $message_admin.='<li>'.$langs->trans($key).' : '.$value.'</li>';
if ($enabled && isset($this->attributes[$object->table_element]['list'][$key])) }
{ }
$enabled = dol_eval($this->attributes[$object->table_element]['list'][$key], 1); $message_admin.='</ul>';
}
$perms = 1;
if ($perms && isset($this->attributes[$object->table_element]['perms'][$key]))
{
$perms = dol_eval($this->attributes[$object->table_element]['perms'][$key], 1);
}
$qualified = true; if ($object->fk_soc > 0) {
if (empty($enabled)) $qualified = false; $object->fetch_thirdparty();
if (empty($perms)) $qualified = false; $message_admin.='<p>'.$langs->trans('Company'). ' : '.$object->thirdparty->name.'</p>';
if ($qualified) $message_customer.='<li>'.$langs->trans($key).' : '.$value.'</li>';
} }
$message_admin.='<p>'.$langs->trans('Message').' : <br>'.$object->message.'</p>';
$message_customer.='</ul>'; $message_admin.='<p><a href="'.dol_buildpath('/ticketsup/card.php', 2).'?track_id='.$object->track_id.'">'.$langs->trans('SeeThisTicketIntomanagementInterface').'</a></p>';
$message_customer.='<p>'.$langs->trans('Message').' : <br>'.$object->message.'</p>';
$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;
$message_customer.='<p>' . $langs->trans('TicketNewEmailBodyInfosTrackUrlCustomer') . ' : <a href="'.$url_public_ticket.'">'.$url_public_ticket.'</a></p>';
$message_customer.='<p>'.$langs->trans('TicketEmailPleaseDoNotReplyToThisEmail').'</p>';
$from = $conf->global->MAIN_INFO_SOCIETE_NOM.'<'.$conf->global->TICKETS_NOTIFICATION_EMAIL_FROM.'>'; $from = $conf->global->MAIN_INFO_SOCIETE_NOM.'<'.$conf->global->TICKETS_NOTIFICATION_EMAIL_FROM.'>';
$replyto = $from; $replyto = $from;
// Init to avoid errors $message_admin = dol_nl2br($message_admin);
$filepath = array();
$filename = array();
$mimetype = array();
$message_customer = dol_nl2br($message_customer); if (!empty($conf->global->TICKETS_DISABLE_MAIL_AUTOCOPY_TO)) {
$old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
if (!empty($conf->global->TICKETS_DISABLE_MAIL_AUTOCOPY_TO)) { $conf->global->MAIN_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);
include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
$mailfile = new CMailFile($subject, $sendto, $from, $message_customer, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1);
if ($mailfile->error) { if ($mailfile->error) {
dol_syslog($mailfile->error, LOG_DEBUG); dol_syslog($mailfile->error, LOG_DEBUG);
} else { } else {
$result=$mailfile->sendfile(); $result=$mailfile->sendfile();
} }
if (!empty($conf->global->TICKETS_DISABLE_MAIL_AUTOCOPY_TO)) { if (!empty($conf->global->TICKETS_DISABLE_MAIL_AUTOCOPY_TO)) {
$conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
} }
} }
$ok = 1;
// Send email to customer
if (empty($conf->global->TICKETS_DISABLE_ALL_MAILS) && empty($object->context['disableemailtothirdparty']) && $object->notify_tiers_at_create)
{
$sendto = '';
if (empty($user->socid) && empty($user->email)) {
$object->fetch_thirdparty();
$sendto = $object->thirdparty->email;
} else {
$sendto = $user->email;
}
if ($sendto) {
// Init to avoid errors
$filepath = array();
$filename = array();
$mimetype = array();
$subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectCustomer');
$message_customer= $langs->transnoentities('TicketNewEmailBodyCustomer', $object->track_id)."\n\n";
$message_customer.='<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>';
$message_customer.='<li>'.$langs->trans('Type').' : '.$object->type_label.'</li>';
$message_customer.='<li>'.$langs->trans('Category').' : '.$object->category_label.'</li>';
$message_customer.='<li>'.$langs->trans('Severity').' : '.$object->severity_label.'</li>';
// Extrafields
foreach ($this->attributes[$object->table_element]['label'] as $key => $value)
{
$enabled = 1;
if ($enabled && isset($this->attributes[$object->table_element]['list'][$key]))
{
$enabled = dol_eval($this->attributes[$object->table_element]['list'][$key], 1);
}
$perms = 1;
if ($perms && isset($this->attributes[$object->table_element]['perms'][$key]))
{
$perms = dol_eval($this->attributes[$object->table_element]['perms'][$key], 1);
}
$qualified = true;
if (empty($enabled)) $qualified = false;
if (empty($perms)) $qualified = false;
if ($qualified) $message_customer.='<li>'.$langs->trans($key).' : '.$value.'</li>';
}
$message_customer.='</ul>';
$message_customer.='<p>'.$langs->trans('Message').' : <br>'.$object->message.'</p>';
$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;
$message_customer.='<p>' . $langs->trans('TicketNewEmailBodyInfosTrackUrlCustomer') . ' : <a href="'.$url_public_ticket.'">'.$url_public_ticket.'</a></p>';
$message_customer.='<p>'.$langs->trans('TicketEmailPleaseDoNotReplyToThisEmail').'</p>';
$from = $conf->global->MAIN_INFO_SOCIETE_NOM.'<'.$conf->global->TICKETS_NOTIFICATION_EMAIL_FROM.'>';
$replyto = $from;
$message_customer = dol_nl2br($message_customer);
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_customer, $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;
}
}
}
$ok = 1;
break; break;
case 'TICKET_DELETE': case 'TICKET_DELETE':

View File

@ -175,7 +175,10 @@ if ($action == 'create_ticket' && GETPOST('add_ticket')) {
if (!is_object($user)) { if (!is_object($user)) {
$user = new User($db); $user = new User($db);
} }
$id = $object->create($user, 1); // Disable trigger for email (send by this page)
$object->context['disableemailtothirdparty']=1; // Disable email sent by ticketsup trigger when creation is done from this page
$id = $object->create($user);
if ($id <= 0) { if ($id <= 0) {
$error++; $error++;
$errors = ($object->error ? array($object->error) : $object->errors); $errors = ($object->error ? array($object->error) : $object->errors);

View File

@ -88,7 +88,7 @@ if ($action == 'create_ticket') {
$defaultref = ''; $defaultref = '';
} }
$formticket->showForm(); $formticket->showForm(1);
} }
//$somethingshown=$object->showLinkedObjectBlock(); //$somethingshown=$object->showLinkedObjectBlock();