65 if (empty($conf->ticket) || !isModEnabled(
'ticket')) {
70 case 'TICKET_ASSIGNED':
71 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
73 if ($object->fk_user_assign > 0) {
74 if ($object->fk_user_assign != $user->id) {
75 $userstat =
new User($this->db);
76 $res = $userstat->fetch($object->fk_user_assign);
79 if (empty($conf->global->TICKET_DISABLE_ALL_MAILS)) {
81 $sendto = $userstat->email;
82 $subject_assignee =
'TicketAssignedToYou';
83 $body_assignee =
'TicketAssignedEmailBody';
84 $see_ticket_assignee =
'SeeThisTicketIntomanagementInterface';
86 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
87 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
88 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
90 if (!empty($sendto)) {
93 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
94 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
98 $this->error = $userstat->error;
99 $this->errors = $userstat->errors;
104 if (!empty($conf->global->TICKET_NOTIFY_CUSTOMER_TICKET_ASSIGNED) && empty($object->oldcopy->fk_user_assign)) {
105 $langs->load(
'ticket');
107 $subject_customer =
'TicketAssignedCustomerEmail';
108 $body_customer =
'TicketAssignedCustomerBody';
109 $see_ticket_customer =
'TicketNewEmailBodyInfosTrackUrlCustomer';
112 $linked_contacts = $object->listeContact(-1,
'thirdparty');
117 if ($object->origin_email) {
118 $temp_emails[] = $object->origin_email;
121 if (!empty($linked_contacts)) {
122 foreach ($linked_contacts as $contact) {
124 if (!in_array($contact[
'email'], $temp_emails)) {
125 $temp_emails[] = $contact[
'email'];
130 $sendto = implode(
", ", $temp_emails);
132 unset($linked_contacts);
143 case 'TICKET_CREATE':
144 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
146 $langs->load(
'ticket');
148 $subject_admin =
'TicketNewEmailSubjectAdmin';
149 $body_admin =
'TicketNewEmailBodyAdmin';
151 $subject_customer =
'TicketNewEmailSubjectCustomer';
152 $body_customer =
'TicketNewEmailBodyCustomer';
153 $see_ticket_customer =
'TicketNewEmailBodyInfosTrackUrlCustomer';
155 $subject_assignee =
'TicketAssignedToYou';
156 $body_assignee =
'TicketAssignedEmailBody';
157 $see_ticket_assignee =
'SeeThisTicketIntomanagementInterface';
160 if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && empty($object->context[
'disableticketemail'])) {
161 $sendto = empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) ?
'' : $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
168 if ($object->fk_user_assign > 0 && $object->fk_user_assign != $user->id && empty($object->context[
'disableticketemail'])) {
169 $userstat =
new User($this->db);
170 $res = $userstat->fetch($object->fk_user_assign);
175 $sendto = $userstat->email;
177 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
178 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
181 if (!empty($sendto)) {
186 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
190 $this->error = $userstat->error;
191 $this->errors = $userstat->errors;
196 if (empty($conf->global->TICKET_DISABLE_CUSTOMER_MAILS) && empty($object->context[
'disableticketemail']) && $object->notify_tiers_at_create) {
201 $contactid =
GETPOST(
'contactid',
'alpha');
204 if (!empty($contactid)) {
205 $contact =
new Contact($this->db);
206 $res = $contact->fetch($contactid);
209 if ($res > 0 && !empty($contact->email) && !empty($contact->statut)) {
210 $sendto = $contact->email;
211 } elseif (!empty($object->fk_soc)) {
212 $object->fetch_thirdparty();
213 $sendto = $object->thirdparty->email;
224 case 'TICKET_DELETE':
225 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
228 case 'TICKET_MODIFY':
229 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
233 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
234 $langs->load(
'ticket');
236 $subject_admin =
'TicketCloseEmailSubjectAdmin';
237 $body_admin =
'TicketCloseEmailBodyAdmin';
238 $subject_customer =
'TicketCloseEmailSubjectCustomer';
239 $body_customer =
'TicketCloseEmailBodyCustomer';
240 $see_ticket_customer =
'TicketCloseEmailBodyInfosTrackUrlCustomer';
243 if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && empty($object->context[
'disableticketemail'])) {
244 $sendto = empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) ?
'' : $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
251 if (empty($conf->global->TICKET_DISABLE_CUSTOMER_MAILS) && empty($object->context[
'disableticketemail'])) {
252 $linked_contacts = $object->listeContact(-1,
'thirdparty');
253 $linked_contacts = array_merge($linked_contacts, $object->listeContact(-1,
'internal'));
254 if (empty($linked_contacts) && !empty($conf->global->TICKET_NOTIFY_AT_CLOSING) && !empty($object->fk_soc)) {
255 $object->fetch_thirdparty();
256 $linked_contacts[][
'email'] = $object->thirdparty->email;
259 $contactid =
GETPOST(
'contactid',
'int');
262 if ($contactid > 0) {
265 $contact =
new Contact($this->db);
266 $res = $contact->fetch($contactid);
267 if (! in_array($contact, $linked_contacts)) {
268 $error_msg = $langs->trans(
'Error').
': ';
269 $error_msg .= $langs->transnoentities(
'TicketWrongContact');
277 if ($res > 0 && !empty($contact->email) && !empty($contact->statut)) {
278 $sendto = $contact->email;
279 } elseif ( !empty($linked_contacts) && ($contactid == -2 || (
GETPOST(
'massaction',
'alpha') ==
'close' &&
GETPOST(
'confirm',
'alpha') ==
'yes'))) {
282 foreach ($linked_contacts as $contact) {
283 $temp_emails[] = $contact[
'email'];
285 $sendto = implode(
", ", $temp_emails);
287 unset($linked_contacts);
320 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$langs->transnoentities($base_subject, $object->ref, $object->track_id);
321 $message_admin = $langs->transnoentities($body, $object->track_id).
'<br>';
322 $message_admin .=
'<ul><li>'.$langs->trans(
'Title').
' : '.$object->subject.
'</li>';
323 $message_admin .=
'<li>'.$langs->trans(
'Type').
' : '.$langs->getLabelFromKey($this->db,
'TicketTypeShort'.$object->type_code,
'c_ticket_type',
'code',
'label', $object->type_code).
'</li>';
324 $message_admin .=
'<li>'.$langs->trans(
'TicketCategory').
' : '.$langs->getLabelFromKey($this->db,
'TicketCategoryShort'.$object->category_code,
'c_ticket_category',
'code',
'label', $object->category_code).
'</li>';
325 $message_admin .=
'<li>'.$langs->trans(
'Severity').
' : '.$langs->getLabelFromKey($this->db,
'TicketSeverityShort'.$object->severity_code,
'c_ticket_severity',
'code',
'label', $object->severity_code).
'</li>';
326 $message_admin .=
'<li>'.$langs->trans(
'From').
' : '.($object->email_from ? $object->email_from : ($object->fk_user_create > 0 ? $langs->trans(
'Internal') :
'')).
'</li>';
329 $extraFields->fetch_name_optionals_label($object->table_element);
330 if (is_array($object->array_options) && count($object->array_options) > 0) {
331 foreach ($object->array_options as $key => $value) {
332 $key = substr($key, 8);
333 $message_admin .=
'<li>'.$langs->trans($extraFields->attributes[$object->element][
'label'][$key]).
' : '.$extraFields->showOutputField($key, $value,
'', $object->table_element).
'</li>';
336 if ($object->fk_soc > 0) {
337 $object->fetch_thirdparty();
338 $message_admin .=
'<li>'.$langs->trans(
'Company').
' : '.$object->thirdparty->name.
'</li>';
340 $message_admin .=
'</ul>';
342 $message = $object->message;
346 $message_admin .=
'<p>'.$langs->trans(
'Message').
' : <br><br>'.$message.
'</p><br>';
347 $message_admin .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id.
'">'.$langs->trans(
'SeeThisTicketIntomanagementInterface').
'</a></p>';
349 $from = $conf->global->MAIN_INFO_SOCIETE_NOM.
'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.
'>';
351 $trackid =
'tic'.$object->id;
353 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
354 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
355 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
357 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
358 $mailfile =
new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename,
'',
'', 0, -1,
'',
'', $trackid,
'',
'ticket');
359 if ($mailfile->error) {
362 $result = $mailfile->sendfile();
364 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
365 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
389 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$langs->transnoentities($base_subject);
390 $message_customer = $langs->transnoentities($body, $object->track_id).
'<br>';
391 $message_customer .=
'<ul><li>'.$langs->trans(
'Title').
' : '.$object->subject.
'</li>';
392 $message_customer .=
'<li>'.$langs->trans(
'Type').
' : '.$langs->getLabelFromKey($this->db,
'TicketTypeShort'.$object->type_code,
'c_ticket_type',
'code',
'label', $object->type_code).
'</li>';
393 $message_customer .=
'<li>'.$langs->trans(
'TicketCategory').
' : '.$langs->getLabelFromKey($this->db,
'TicketCategoryShort'.$object->category_code,
'c_ticket_category',
'code',
'label', $object->category_code).
'</li>';
394 $message_customer .=
'<li>'.$langs->trans(
'Severity').
' : '.$langs->getLabelFromKey($this->db,
'TicketSeverityShort'.$object->severity_code,
'c_ticket_severity',
'code',
'label', $object->severity_code).
'</li>';
397 if (is_array($this->attributes[$object->table_element][
'label'])) {
398 foreach ($this->attributes[$object->table_element][
'label'] as $key => $value) {
400 if ($enabled && isset($this->attributes[$object->table_element][
'list'][$key])) {
401 $enabled =
dol_eval($this->attributes[$object->table_element][
'list'][$key], 1);
404 if ($perms && isset($this->attributes[$object->table_element][
'perms'][$key])) {
405 $perms =
dol_eval($this->attributes[$object->table_element][
'perms'][$key], 1);
409 if (empty($enabled)) {
417 $message_customer .=
'<li>' . $langs->trans($key) .
' : ' . $value .
'</li>';
422 $message_customer .=
'</ul>';
424 $message = $object->message;
428 $message_customer .=
'<p>'.$langs->trans(
'Message').
' : <br><br>'.$message.
'</p><br>';
432 $message_customer .=
'<p>'.$langs->trans($see_ticket).
' : <a href="'.$url_public_ticket.
'">'.$url_public_ticket.
'</a></p>';
433 $message_customer .=
'<p>'.$langs->trans(
'TicketEmailPleaseDoNotReplyToThisEmail').
'</p>';
435 $message_customer .=
'<p>'.$langs->trans(
'TicketEmailPleaseDoNotReplyToThisEmailNoInterface').
'</p>';
438 $from = (empty($conf->global->MAIN_INFO_SOCIETE_NOM) ?
'' : $conf->global->MAIN_INFO_SOCIETE_NOM.
' ').
'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.
'>';
440 $trackid =
'tic'.$object->id;
442 $old_MAIN_MAIL_AUTOCOPY_TO =
null;
445 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
448 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
449 $mailfile =
new CMailFile($subject, $sendto, $from, $message_customer, $filepath, $mimetype, $filename,
'',
'', 0, -1,
'',
'', $trackid,
'',
'ticket');
450 if ($mailfile->error) {
453 $result = $mailfile->sendfile();
456 $object->fetch($object->id);
457 $object->date_last_msg_sent =
dol_now();
458 $object->update($user);
461 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
462 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
479 global $conf, $user, $mysoc;
487 $appli = $mysoc->name;
489 $subject =
'['.$appli.
'] '.$langs->transnoentities($base_subject);
490 $message =
'<p>'.$langs->transnoentities($body, $object->track_id,
dolGetFirstLastname($user->firstname, $user->lastname)).
"</p>";
491 $message .=
'<ul><li>'.$langs->trans(
'Title').
' : '.$object->subject.
'</li>';
492 $message .=
'<li>'.$langs->trans(
'Type').
' : '.$object->type_label.
'</li>';
493 $message .=
'<li>'.$langs->trans(
'Category').
' : '.$object->category_label.
'</li>';
494 $message .=
'<li>'.$langs->trans(
'Severity').
' : '.$object->severity_label.
'</li>';
496 if (is_array($object->array_options) && count($object->array_options) > 0) {
497 foreach ($object->array_options as $key => $value) {
498 $message .=
'<li>'.$langs->trans($key).
' : '.$value.
'</li>';
503 $message .=
'<p>'.$langs->trans(
'Message').
' : <br>'.$object->message.
'</p>';
504 $message .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id.
'">'.$langs->trans($see_ticket).
'</a></p>';
510 $old_MAIN_MAIL_AUTOCOPY_TO =
null;
513 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
516 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
517 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename,
'',
'', 0, -1);
518 if ($mailfile->error) {
521 $result = $mailfile->sendfile();
524 $object->fetch($object->id);
525 $object->date_last_msg_sent =
dol_now();
526 $object->update($user);
530 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;