25 require_once DOL_DOCUMENT_ROOT.
'/core/triggers/dolibarrtriggers.class.php';
42 $this->
name = preg_replace(
'/^Interface/i',
'', get_class($this));
43 $this->family =
"ticket";
44 $this->
description =
"Triggers of the module ticket to send notifications to internal users and to third-parties";
45 $this->version = self::VERSION_DOLIBARR;
46 $this->picto =
'ticket';
64 if (empty($conf->ticket) || empty($conf->ticket->enabled)) {
69 case 'TICKET_ASSIGNED':
70 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
72 if ($object->fk_user_assign > 0 && $object->fk_user_assign != $user->id) {
73 $userstat =
new User($this->
db);
74 $res = $userstat->fetch($object->fk_user_assign);
78 if (empty($conf->global->TICKET_DISABLE_ALL_MAILS)) {
85 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$langs->transnoentities(
'TicketAssignedToYou');
86 $message =
'<p>'.$langs->transnoentities(
'TicketAssignedEmailBody', $object->track_id,
dolGetFirstLastname($user->firstname, $user->lastname)).
"</p>";
87 $message .=
'<ul><li>'.$langs->trans(
'Title').
' : '.$object->subject.
'</li>';
88 $message .=
'<li>'.$langs->trans(
'Type').
' : '.$object->type_label.
'</li>';
89 $message .=
'<li>'.$langs->trans(
'Category').
' : '.$object->category_label.
'</li>';
90 $message .=
'<li>'.$langs->trans(
'Severity').
' : '.$object->severity_label.
'</li>';
92 if (is_array($object->array_options) && count($object->array_options) > 0) {
93 foreach ($object->array_options as $key => $value) {
94 $message .=
'<li>'.$langs->trans($key).
' : '.$value.
'</li>';
99 $message .=
'<p>'.$langs->trans(
'Message').
' : <br>'.$object->message.
'</p>';
100 $message .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id.
'">'.$langs->trans(
'SeeThisTicketIntomanagementInterface').
'</a></p>';
102 $sendto = $userstat->email;
107 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
108 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
109 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
111 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
112 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename,
'',
'', 0, -1);
113 if ($mailfile->error) {
116 $result = $mailfile->sendfile();
118 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
119 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
125 $this->error = $userstat->error;
126 $this->errors = $userstat->errors;
131 case 'TICKET_CREATE':
132 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
134 $langs->load(
'ticket');
136 $subject_admin =
'TicketNewEmailSubjectAdmin';
137 $body_admin =
'TicketNewEmailBodyAdmin';
138 $subject_customer =
'TicketNewEmailSubjectCustomer';
139 $body_customer =
'TicketNewEmailBodyCustomer';
140 $see_ticket_customer =
'TicketNewEmailBodyInfosTrackUrlCustomer';
143 if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && empty($object->context[
'disableticketemail'])) {
144 $sendto = empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) ?
'' : $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
151 if (empty($conf->global->TICKET_DISABLE_CUSTOMER_MAILS) && empty($object->context[
'disableticketemail']) && $object->notify_tiers_at_create) {
156 $contactid =
GETPOST(
'contactid',
'alpha');
159 if (!empty($contactid)) {
161 $res = $contact->fetch($contactid);
164 if ($res > 0 && !empty($contact->email) && !empty($contact->statut)) {
165 $sendto = $contact->email;
166 } elseif (!empty($object->fk_soc)) {
167 $object->fetch_thirdparty();
168 $sendto = $object->thirdparty->email;
179 case 'TICKET_DELETE':
180 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
183 case 'TICKET_MODIFY':
184 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
188 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
189 $langs->load(
'ticket');
191 $subject_admin =
'TicketCloseEmailSubjectAdmin';
192 $body_admin =
'TicketCloseEmailBodyAdmin';
193 $subject_customer =
'TicketCloseEmailSubjectCustomer';
194 $body_customer =
'TicketCloseEmailBodyCustomer';
195 $see_ticket_customer =
'TicketCloseEmailBodyInfosTrackUrlCustomer';
198 if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && empty($object->context[
'disableticketemail'])) {
199 $sendto = empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) ?
'' : $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
206 if (empty($conf->global->TICKET_DISABLE_CUSTOMER_MAILS) && empty($object->context[
'disableticketemail'])) {
207 $linked_contacts = $object->listeContact(-1,
'thirdparty');
208 $linked_contacts = array_merge($linked_contacts, $object->listeContact(-1,
'internal'));
209 if (empty($linked_contacts) && !empty($conf->global->TICKET_NOTIFY_AT_CLOSING) && !empty($object->fk_soc)) {
210 $object->fetch_thirdparty();
211 $linked_contacts[] = $object->thirdparty->email;
214 $contactid =
GETPOST(
'contactid',
'int');
217 if ($contactid > 0) {
219 $res = $contact->fetch($contactid);
220 if (! in_array($contact, $linked_contacts)) {
221 $error_msg = $langs->trans(
'Error').
': ';
222 $error_msg .= $langs->transnoentities(
'TicketWrongContact');
230 if ($res > 0 && !empty($contact->email) && !empty($contact->statut)) {
231 $sendto = $contact->email;
232 } elseif ( !empty($linked_contacts) && ($contactid == -2 || (
GETPOST(
'massaction',
'alpha') ==
'close' &&
GETPOST(
'confirm',
'alpha') ==
'yes'))) {
235 foreach ($linked_contacts as $contact) {
236 $temp_emails[] = $contact[
'email'];
238 $sendto = implode(
", ", $temp_emails);
240 unset($linked_contacts);
273 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$langs->transnoentities($base_subject, $object->ref, $object->track_id);
274 $message_admin = $langs->transnoentities($body, $object->track_id).
'<br>';
275 $message_admin .=
'<ul><li>'.$langs->trans(
'Title').
' : '.$object->subject.
'</li>';
276 $message_admin .=
'<li>'.$langs->trans(
'Type').
' : '.$langs->getLabelFromKey($this->
db,
'TicketTypeShort'.$object->type_code,
'c_ticket_type',
'code',
'label', $object->type_code).
'</li>';
277 $message_admin .=
'<li>'.$langs->trans(
'Category').
' : '.$langs->getLabelFromKey($this->
db,
'TicketCategoryShort'.$object->category_code,
'c_ticket_category',
'code',
'label', $object->category_code).
'</li>';
278 $message_admin .=
'<li>'.$langs->trans(
'Severity').
' : '.$langs->getLabelFromKey($this->
db,
'TicketSeverityShort'.$object->severity_code,
'c_ticket_severity',
'code',
'label', $object->severity_code).
'</li>';
279 $message_admin .=
'<li>'.$langs->trans(
'From').
' : '.($object->email_from ? $object->email_from : ($object->fk_user_create > 0 ? $langs->trans(
'Internal') :
'')).
'</li>';
282 $extraFields->fetch_name_optionals_label($object->table_element);
283 if (is_array($object->array_options) && count($object->array_options) > 0) {
284 foreach ($object->array_options as $key => $value) {
285 $key = substr($key, 8);
286 $message_admin .=
'<li>'.$langs->trans($extraFields->attributes[$object->element][
'label'][$key]).
' : '.$extraFields->showOutputField($key, $value,
'', $object->table_element).
'</li>';
289 if ($object->fk_soc > 0) {
290 $object->fetch_thirdparty();
291 $message_admin .=
'<li>'.$langs->trans(
'Company').
' : '.$object->thirdparty->name.
'</li>';
293 $message_admin .=
'</ul>';
295 $message = $object->message;
299 $message_admin .=
'<p>'.$langs->trans(
'Message').
' : <br><br>'.$message.
'</p><br>';
300 $message_admin .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id.
'">'.$langs->trans(
'SeeThisTicketIntomanagementInterface').
'</a></p>';
302 $from = $conf->global->MAIN_INFO_SOCIETE_NOM.
'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.
'>';
304 $trackid =
'tic'.$object->id;
306 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
307 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
308 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
310 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
311 $mailfile =
new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename,
'',
'', 0, -1,
'',
'', $trackid,
'',
'ticket');
312 if ($mailfile->error) {
315 $result = $mailfile->sendfile();
317 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
318 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
342 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$langs->transnoentities($base_subject);
343 $message_customer = $langs->transnoentities($body, $object->track_id).
'<br>';
344 $message_customer .=
'<ul><li>'.$langs->trans(
'Title').
' : '.$object->subject.
'</li>';
345 $message_customer .=
'<li>'.$langs->trans(
'Type').
' : '.$langs->getLabelFromKey($this->
db,
'TicketTypeShort'.$object->type_code,
'c_ticket_type',
'code',
'label', $object->type_code).
'</li>';
346 $message_customer .=
'<li>'.$langs->trans(
'Category').
' : '.$langs->getLabelFromKey($this->
db,
'TicketCategoryShort'.$object->category_code,
'c_ticket_category',
'code',
'label', $object->category_code).
'</li>';
347 $message_customer .=
'<li>'.$langs->trans(
'Severity').
' : '.$langs->getLabelFromKey($this->
db,
'TicketSeverityShort'.$object->severity_code,
'c_ticket_severity',
'code',
'label', $object->severity_code).
'</li>';
350 if (is_array($this->attributes[$object->table_element][
'label'])) {
351 foreach ($this->attributes[$object->table_element][
'label'] as $key => $value) {
353 if ($enabled && isset($this->attributes[$object->table_element][
'list'][$key])) {
354 $enabled =
dol_eval($this->attributes[$object->table_element][
'list'][$key], 1);
357 if ($perms && isset($this->attributes[$object->table_element][
'perms'][$key])) {
358 $perms =
dol_eval($this->attributes[$object->table_element][
'perms'][$key], 1);
362 if (empty($enabled)) {
370 $message_customer .=
'<li>' . $langs->trans($key) .
' : ' . $value .
'</li>';
375 $message_customer .=
'</ul>';
377 $message = $object->message;
381 $message_customer .=
'<p>'.$langs->trans(
'Message').
' : <br><br>'.$message.
'</p><br>';
382 $url_public_ticket = ($conf->global->TICKET_URL_PUBLIC_INTERFACE ? $conf->global->TICKET_URL_PUBLIC_INTERFACE.
'/view.php' :
dol_buildpath(
'/public/ticket/view.php', 2)).
'?track_id='.$object->track_id;
383 $message_customer .=
'<p>'.$langs->trans($see_ticket).
' : <a href="'.$url_public_ticket.
'">'.$url_public_ticket.
'</a></p>';
384 $message_customer .=
'<p>'.$langs->trans(
'TicketEmailPleaseDoNotReplyToThisEmail').
'</p>';
386 $from = (empty($conf->global->MAIN_INFO_SOCIETE_NOM) ?
'' : $conf->global->MAIN_INFO_SOCIETE_NOM.
' ').
'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.
'>';
388 $trackid =
'tic'.$object->id;
390 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
391 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
392 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
394 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
395 $mailfile =
new CMailFile($subject, $sendto, $from, $message_customer, $filepath, $mimetype, $filename,
'',
'', 0, -1,
'',
'', $trackid,
'',
'ticket');
396 if ($mailfile->error) {
399 $result = $mailfile->sendfile();
402 $object->fetch($object->id);
403 $object->date_last_msg_sent =
dol_now();
404 $object->update($user);
407 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
408 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;