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,17 +184,23 @@ if ($action == 'setvarother') {
$error++; $error++;
} }
if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
{
$param_show_module_logo = GETPOST('TICKETS_SHOW_MODULE_LOGO', 'alpha'); $param_show_module_logo = GETPOST('TICKETS_SHOW_MODULE_LOGO', 'alpha');
$res = dolibarr_set_const($db, 'TICKETS_SHOW_MODULE_LOGO', $param_show_module_logo, 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, 'TICKETS_SHOW_MODULE_LOGO', $param_show_module_logo, 'chaine', 0, '', $conf->entity);
if (!$res > 0) { if (!$res > 0) {
$error++; $error++;
} }
}
if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
{
$param_notification_also_main_addressemail = GETPOST('TICKETS_NOTIFICATION_ALSO_MAIN_ADDRESS', 'alpha'); $param_notification_also_main_addressemail = GETPOST('TICKETS_NOTIFICATION_ALSO_MAIN_ADDRESS', 'alpha');
$res = dolibarr_set_const($db, 'TICKETS_NOTIFICATION_ALSO_MAIN_ADDRESS', $param_notification_also_main_addressemail, 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, 'TICKETS_NOTIFICATION_ALSO_MAIN_ADDRESS', $param_notification_also_main_addressemail, 'chaine', 0, '', $conf->entity);
if (!$res > 0) { if (!$res > 0) {
$error++; $error++;
} }
}
$param_limit_view = GETPOST('TICKETS_LIMIT_VIEW_ASSIGNED_ONLY', 'alpha'); $param_limit_view = GETPOST('TICKETS_LIMIT_VIEW_ASSIGNED_ONLY', 'alpha');
$res = dolibarr_set_const($db, 'TICKETS_LIMIT_VIEW_ASSIGNED_ONLY', $param_limit_view, 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, 'TICKETS_LIMIT_VIEW_ASSIGNED_ONLY', $param_limit_view, 'chaine', 0, '', $conf->entity);
@ -380,6 +386,8 @@ print $form->textwithpicto('', $langs->trans("TicketsEmailMustExistHelp"), 1, 'h
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
{
// Show logo for module // Show logo for module
print '<tr class="pair"><td width="70%">' . $langs->trans("TicketsShowModuleLogo") . '</td>'; print '<tr class="pair"><td width="70%">' . $langs->trans("TicketsShowModuleLogo") . '</td>';
print '<td align="left">'; print '<td align="left">';
@ -394,6 +402,7 @@ print '<td align="center">';
print $form->textwithpicto('', $langs->trans("TicketsShowModuleLogoHelp"), 1, 'help'); print $form->textwithpicto('', $langs->trans("TicketsShowModuleLogoHelp"), 1, 'help');
print '</td>'; print '</td>';
print '</tr>'; 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,6 +455,8 @@ print '</td>';
print '</tr>'; print '</tr>';
// Also send to main email address // Also send to main email address
if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
{
print '<tr class="pair"><td width="70%">' . $langs->trans("TicketsEmailAlsoSendToMainAddress") . '</td>'; print '<tr class="pair"><td width="70%">' . $langs->trans("TicketsEmailAlsoSendToMainAddress") . '</td>';
print '<td align="left">'; print '<td align="left">';
if ($conf->use_javascript_ajax) { if ($conf->use_javascript_ajax) {
@ -459,6 +470,7 @@ print '<td align="center">';
print $form->textwithpicto('', $langs->trans("TicketsEmailAlsoSendToMainAddressHelp"), 1, 'help'); print $form->textwithpicto('', $langs->trans("TicketsEmailAlsoSendToMainAddressHelp"), 1, 'help');
print '</td>'; print '</td>';
print '</tr>'; 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,10 +110,19 @@ 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)
{
if (empty($conf->global->TICKETS_DISABLE_ALL_MAILS))
{
// Init to avoid errors
$filepath = array();
$filename = array();
$mimetype = array();
// Send email to assigned user // Send email to assigned user
$subject = '[' . $conf->global->MAIN_INFO_SOCIETE_NOM . '] ' . $langs->transnoentities('TicketAssignedToYou'); $subject = '[' . $conf->global->MAIN_INFO_SOCIETE_NOM . '] ' . $langs->transnoentities('TicketAssignedToYou');
$message = '<p>' . $langs->transnoentities('TicketAssignedEmailBody', $object->track_id, dolGetFirstLastname($user->firstname, $user->lastname)) . "</p>"; $message = '<p>' . $langs->transnoentities('TicketAssignedEmailBody', $object->track_id, dolGetFirstLastname($user->firstname, $user->lastname)) . "</p>";
@ -135,11 +144,6 @@ class InterfaceTicketEmail extends DolibarrTriggers
$sendto = $userstat->email; $sendto = $userstat->email;
$from = dolGetFirstLastname($user->firstname, $user->lastname) . '<' . $user->email . '>'; $from = dolGetFirstLastname($user->firstname, $user->lastname) . '<' . $user->email . '>';
// Init to avoid errors
$filepath = array();
$filename = array();
$mimetype = array();
$message = dol_nl2br($message); $message = dol_nl2br($message);
if (!empty($conf->global->TICKETS_DISABLE_MAIL_AUTOCOPY_TO)) { if (!empty($conf->global->TICKETS_DISABLE_MAIL_AUTOCOPY_TO)) {
@ -156,27 +160,37 @@ class InterfaceTicketEmail extends DolibarrTriggers
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; $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);
$langs->load('ticketsup');
$object->fetch('', $object->track_id); // Should be useless
// 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 // Init to avoid errors
$filepath = array(); $filepath = array();
$filename = array(); $filename = array();
$mimetype = array(); $mimetype = array();
$langs->load('ticketsup');
$object->fetch('', $object->track_id);
/* Send email to admin */ /* Send email to admin */
$sendto = $conf->global->TICKETS_NOTIFICATION_EMAIL_TO;
$subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectAdmin'); $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectAdmin');
$message_admin= $langs->transnoentities('TicketNewEmailBodyAdmin', $object->track_id)."\n\n"; $message_admin= $langs->transnoentities('TicketNewEmailBodyAdmin', $object->track_id)."\n\n";
$message_admin.='<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>'; $message_admin.='<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>';
@ -218,9 +232,13 @@ class InterfaceTicketEmail extends DolibarrTriggers
} }
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;
}
} }
/* Send email to customer */ // Send email to customer
if (empty($conf->global->TICKETS_DISABLE_ALL_MAILS) && empty($object->context['disableemailtothirdparty']) && $object->notify_tiers_at_create)
{
$sendto = ''; $sendto = '';
if (empty($user->socid) && empty($user->email)) { if (empty($user->socid) && empty($user->email)) {
$object->fetch_thirdparty(); $object->fetch_thirdparty();
@ -229,7 +247,12 @@ class InterfaceTicketEmail extends DolibarrTriggers
$sendto = $user->email; $sendto = $user->email;
} }
if ($sendto && $object->notify_tiers_at_create) { if ($sendto) {
// Init to avoid errors
$filepath = array();
$filename = array();
$mimetype = array();
$subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectCustomer'); $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectCustomer');
$message_customer= $langs->transnoentities('TicketNewEmailBodyCustomer', $object->track_id)."\n\n"; $message_customer= $langs->transnoentities('TicketNewEmailBodyCustomer', $object->track_id)."\n\n";
$message_customer.='<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>'; $message_customer.='<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>';
@ -258,22 +281,15 @@ class InterfaceTicketEmail extends DolibarrTriggers
if ($qualified) $message_customer.='<li>'.$langs->trans($key).' : '.$value.'</li>'; if ($qualified) $message_customer.='<li>'.$langs->trans($key).' : '.$value.'</li>';
} }
$message_customer.='</ul>'; $message_customer.='</ul>';
$message_customer.='<p>'.$langs->trans('Message').' : <br>'.$object->message.'</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; $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('TicketNewEmailBodyInfosTrackUrlCustomer') . ' : <a href="'.$url_public_ticket.'">'.$url_public_ticket.'</a></p>';
$message_customer.='<p>'.$langs->trans('TicketEmailPleaseDoNotReplyToThisEmail').'</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
$filepath = array();
$filename = array();
$mimetype = array();
$message_customer = dol_nl2br($message_customer); $message_customer = dol_nl2br($message_customer);
if (!empty($conf->global->TICKETS_DISABLE_MAIL_AUTOCOPY_TO)) { if (!empty($conf->global->TICKETS_DISABLE_MAIL_AUTOCOPY_TO)) {
@ -291,8 +307,8 @@ class InterfaceTicketEmail extends DolibarrTriggers
$conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO; $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
} }
} }
}
$ok = 1; $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();