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)) {
86 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$langs->transnoentities(
'TicketAssignedToYou');
87 $message =
'<p>'.$langs->transnoentities(
'TicketAssignedEmailBody', $object->track_id,
dolGetFirstLastname($user->firstname, $user->lastname)).
"</p>";
88 $message .=
'<ul><li>'.$langs->trans(
'Title').
' : '.$object->subject.
'</li>';
89 $message .=
'<li>'.$langs->trans(
'Type').
' : '.$object->type_label.
'</li>';
90 $message .=
'<li>'.$langs->trans(
'Category').
' : '.$object->category_label.
'</li>';
91 $message .=
'<li>'.$langs->trans(
'Severity').
' : '.$object->severity_label.
'</li>';
93 if (is_array($object->array_options) && count($object->array_options) > 0) {
94 foreach ($object->array_options as $key => $value) {
95 $message .=
'<li>'.$langs->trans($key).
' : '.$value.
'</li>';
100 $message .=
'<p>'.$langs->trans(
'Message').
' : <br>'.$object->message.
'</p>';
101 $message .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id.
'">'.$langs->trans(
'SeeThisTicketIntomanagementInterface').
'</a></p>';
103 $sendto = $userstat->email;
108 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
109 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
110 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
112 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
113 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename,
'',
'', 0, -1);
114 if ($mailfile->error) {
117 $result = $mailfile->sendfile();
119 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
120 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
124 $this->error = $userstat->error;
125 $this->errors = $userstat->errors;
130 if (!empty($conf->global->TICKET_NOTIFY_CUSTOMER_TICKET_ASSIGNED) && empty($object->oldcopy->fk_user_assign)) {
131 $langs->load(
'ticket');
133 $subject_customer =
'TicketAssignedCustomerEmail';
134 $body_customer =
'TicketAssignedCustomerBody';
135 $see_ticket_customer =
'TicketNewEmailBodyInfosTrackUrlCustomer';
138 $linked_contacts = $object->listeContact(-1,
'thirdparty');
143 if ($object->origin_email) {
144 $temp_emails[] = $object->origin_email;
147 if (!empty($linked_contacts)) {
148 foreach ($linked_contacts as $contact) {
150 if (!in_array($contact[
'email'], $temp_emails)) {
151 $temp_emails[] = $contact[
'email'];
156 $sendto = implode(
", ", $temp_emails);
158 unset($linked_contacts);
169 case 'TICKET_CREATE':
170 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
172 $langs->load(
'ticket');
174 $subject_admin =
'TicketNewEmailSubjectAdmin';
175 $body_admin =
'TicketNewEmailBodyAdmin';
176 $subject_customer =
'TicketNewEmailSubjectCustomer';
177 $body_customer =
'TicketNewEmailBodyCustomer';
178 $see_ticket_customer =
'TicketNewEmailBodyInfosTrackUrlCustomer';
181 if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && empty($object->context[
'disableticketemail'])) {
182 $sendto = empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) ?
'' : $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
189 if (empty($conf->global->TICKET_DISABLE_CUSTOMER_MAILS) && empty($object->context[
'disableticketemail']) && $object->notify_tiers_at_create) {
194 $contactid =
GETPOST(
'contactid',
'alpha');
197 if (!empty($contactid)) {
198 $contact =
new Contact($this->db);
199 $res = $contact->fetch($contactid);
202 if ($res > 0 && !empty($contact->email) && !empty($contact->statut)) {
203 $sendto = $contact->email;
204 } elseif (!empty($object->fk_soc)) {
205 $object->fetch_thirdparty();
206 $sendto = $object->thirdparty->email;
217 case 'TICKET_DELETE':
218 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
221 case 'TICKET_MODIFY':
222 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
226 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
227 $langs->load(
'ticket');
229 $subject_admin =
'TicketCloseEmailSubjectAdmin';
230 $body_admin =
'TicketCloseEmailBodyAdmin';
231 $subject_customer =
'TicketCloseEmailSubjectCustomer';
232 $body_customer =
'TicketCloseEmailBodyCustomer';
233 $see_ticket_customer =
'TicketCloseEmailBodyInfosTrackUrlCustomer';
236 if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && empty($object->context[
'disableticketemail'])) {
237 $sendto = empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) ?
'' : $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
244 if (empty($conf->global->TICKET_DISABLE_CUSTOMER_MAILS) && empty($object->context[
'disableticketemail'])) {
245 $linked_contacts = $object->listeContact(-1,
'thirdparty');
246 $linked_contacts = array_merge($linked_contacts, $object->listeContact(-1,
'internal'));
247 if (empty($linked_contacts) && !empty($conf->global->TICKET_NOTIFY_AT_CLOSING) && !empty($object->fk_soc)) {
248 $object->fetch_thirdparty();
249 $linked_contacts[][
'email'] = $object->thirdparty->email;
252 $contactid =
GETPOST(
'contactid',
'int');
255 if ($contactid > 0) {
258 $contact =
new Contact($this->db);
259 $res = $contact->fetch($contactid);
260 if (! in_array($contact, $linked_contacts)) {
261 $error_msg = $langs->trans(
'Error').
': ';
262 $error_msg .= $langs->transnoentities(
'TicketWrongContact');
270 if ($res > 0 && !empty($contact->email) && !empty($contact->statut)) {
271 $sendto = $contact->email;
272 } elseif ( !empty($linked_contacts) && ($contactid == -2 || (
GETPOST(
'massaction',
'alpha') ==
'close' &&
GETPOST(
'confirm',
'alpha') ==
'yes'))) {
275 foreach ($linked_contacts as $contact) {
276 $temp_emails[] = $contact[
'email'];
278 $sendto = implode(
", ", $temp_emails);
280 unset($linked_contacts);
313 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$langs->transnoentities($base_subject, $object->ref, $object->track_id);
314 $message_admin = $langs->transnoentities($body, $object->track_id).
'<br>';
315 $message_admin .=
'<ul><li>'.$langs->trans(
'Title').
' : '.$object->subject.
'</li>';
316 $message_admin .=
'<li>'.$langs->trans(
'Type').
' : '.$langs->getLabelFromKey($this->db,
'TicketTypeShort'.$object->type_code,
'c_ticket_type',
'code',
'label', $object->type_code).
'</li>';
317 $message_admin .=
'<li>'.$langs->trans(
'TicketCategory').
' : '.$langs->getLabelFromKey($this->db,
'TicketCategoryShort'.$object->category_code,
'c_ticket_category',
'code',
'label', $object->category_code).
'</li>';
318 $message_admin .=
'<li>'.$langs->trans(
'Severity').
' : '.$langs->getLabelFromKey($this->db,
'TicketSeverityShort'.$object->severity_code,
'c_ticket_severity',
'code',
'label', $object->severity_code).
'</li>';
319 $message_admin .=
'<li>'.$langs->trans(
'From').
' : '.($object->email_from ? $object->email_from : ($object->fk_user_create > 0 ? $langs->trans(
'Internal') :
'')).
'</li>';
322 $extraFields->fetch_name_optionals_label($object->table_element);
323 if (is_array($object->array_options) && count($object->array_options) > 0) {
324 foreach ($object->array_options as $key => $value) {
325 $key = substr($key, 8);
326 $message_admin .=
'<li>'.$langs->trans($extraFields->attributes[$object->element][
'label'][$key]).
' : '.$extraFields->showOutputField($key, $value,
'', $object->table_element).
'</li>';
329 if ($object->fk_soc > 0) {
330 $object->fetch_thirdparty();
331 $message_admin .=
'<li>'.$langs->trans(
'Company').
' : '.$object->thirdparty->name.
'</li>';
333 $message_admin .=
'</ul>';
335 $message = $object->message;
339 $message_admin .=
'<p>'.$langs->trans(
'Message').
' : <br><br>'.$message.
'</p><br>';
340 $message_admin .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id.
'">'.$langs->trans(
'SeeThisTicketIntomanagementInterface').
'</a></p>';
342 $from = $conf->global->MAIN_INFO_SOCIETE_NOM.
'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.
'>';
344 $trackid =
'tic'.$object->id;
346 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
347 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
348 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
350 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
351 $mailfile =
new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename,
'',
'', 0, -1,
'',
'', $trackid,
'',
'ticket');
352 if ($mailfile->error) {
355 $result = $mailfile->sendfile();
357 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
358 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
382 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$langs->transnoentities($base_subject);
383 $message_customer = $langs->transnoentities($body, $object->track_id).
'<br>';
384 $message_customer .=
'<ul><li>'.$langs->trans(
'Title').
' : '.$object->subject.
'</li>';
385 $message_customer .=
'<li>'.$langs->trans(
'Type').
' : '.$langs->getLabelFromKey($this->db,
'TicketTypeShort'.$object->type_code,
'c_ticket_type',
'code',
'label', $object->type_code).
'</li>';
386 $message_customer .=
'<li>'.$langs->trans(
'TicketCategory').
' : '.$langs->getLabelFromKey($this->db,
'TicketCategoryShort'.$object->category_code,
'c_ticket_category',
'code',
'label', $object->category_code).
'</li>';
387 $message_customer .=
'<li>'.$langs->trans(
'Severity').
' : '.$langs->getLabelFromKey($this->db,
'TicketSeverityShort'.$object->severity_code,
'c_ticket_severity',
'code',
'label', $object->severity_code).
'</li>';
390 if (is_array($this->attributes[$object->table_element][
'label'])) {
391 foreach ($this->attributes[$object->table_element][
'label'] as $key => $value) {
393 if ($enabled && isset($this->attributes[$object->table_element][
'list'][$key])) {
394 $enabled =
dol_eval($this->attributes[$object->table_element][
'list'][$key], 1);
397 if ($perms && isset($this->attributes[$object->table_element][
'perms'][$key])) {
398 $perms =
dol_eval($this->attributes[$object->table_element][
'perms'][$key], 1);
402 if (empty($enabled)) {
410 $message_customer .=
'<li>' . $langs->trans($key) .
' : ' . $value .
'</li>';
415 $message_customer .=
'</ul>';
417 $message = $object->message;
421 $message_customer .=
'<p>'.$langs->trans(
'Message').
' : <br><br>'.$message.
'</p><br>';
424 $message_customer .=
'<p>'.$langs->trans($see_ticket).
' : <a href="'.$url_public_ticket.
'">'.$url_public_ticket.
'</a></p>';
425 $message_customer .=
'<p>'.$langs->trans(
'TicketEmailPleaseDoNotReplyToThisEmail').
'</p>';
427 $from = (empty($conf->global->MAIN_INFO_SOCIETE_NOM) ?
'' : $conf->global->MAIN_INFO_SOCIETE_NOM.
' ').
'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.
'>';
429 $trackid =
'tic'.$object->id;
433 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
434 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
437 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
438 $mailfile =
new CMailFile($subject, $sendto, $from, $message_customer, $filepath, $mimetype, $filename,
'',
'', 0, -1,
'',
'', $trackid,
'',
'ticket');
439 if ($mailfile->error) {
442 $result = $mailfile->sendfile();
445 $object->fetch($object->id);
446 $object->date_last_msg_sent =
dol_now();
447 $object->update($user);
450 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
451 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;