67 if (empty($conf->ticket) || !isModEnabled(
'ticket')) {
72 case 'TICKET_ASSIGNED':
73 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
75 if ($object->fk_user_assign > 0) {
76 if ($object->fk_user_assign != $user->id) {
77 $userstat =
new User($this->db);
78 $res = $userstat->fetch($object->fk_user_assign);
87 $appli = $mysoc->name;
90 $subject =
'['.$appli.
'] '.$langs->transnoentities(
'TicketAssignedToYou');
91 $message =
'<p>'.$langs->transnoentities(
'TicketAssignedEmailBody', $object->track_id,
dolGetFirstLastname($user->firstname, $user->lastname)).
"</p>";
92 $message .=
'<ul><li>'.$langs->trans(
'Title').
' : '.$object->subject.
'</li>';
93 $message .=
'<li>'.$langs->trans(
'Type').
' : '.$object->type_label.
'</li>';
94 $message .=
'<li>'.$langs->trans(
'Category').
' : '.$object->category_label.
'</li>';
95 $message .=
'<li>'.$langs->trans(
'Severity').
' : '.$object->severity_label.
'</li>';
97 if (is_array($object->array_options) && count($object->array_options) > 0) {
98 foreach ($object->array_options as $key => $value) {
99 $message .=
'<li>'.$langs->trans($key).
' : '.$value.
'</li>';
104 $message .=
'<p>'.$langs->trans(
'Message').
' : <br>'.$object->message.
'</p>';
105 $message .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id.
'">'.$langs->trans(
'SeeThisTicketIntomanagementInterface').
'</a></p>';
107 $sendto = $userstat->email;
113 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
114 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
116 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
117 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename,
'',
'', 0, -1);
118 if ($mailfile->error) {
121 $result = $mailfile->sendfile();
124 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
128 $this->error = $userstat->error;
129 $this->errors = $userstat->errors;
134 if (
getDolGlobalString(
'TICKET_NOTIFY_CUSTOMER_TICKET_ASSIGNED') && empty($object->oldcopy->fk_user_assign)) {
135 $langs->load(
'ticket');
137 $subject_customer =
'TicketAssignedCustomerEmail';
138 $body_customer =
'TicketAssignedCustomerBody';
139 $see_ticket_customer =
'TicketNewEmailBodyInfosTrackUrlCustomer';
142 $linked_contacts = $object->listeContact(-1,
'thirdparty');
147 if ($object->origin_email) {
148 $temp_emails[] = $object->origin_email;
151 if (!empty($linked_contacts)) {
152 foreach ($linked_contacts as $contact) {
154 if (!in_array($contact[
'email'], $temp_emails)) {
155 $temp_emails[] = $contact[
'email'];
160 $sendto = implode(
", ", $temp_emails);
162 unset($linked_contacts);
173 case 'TICKET_CREATE':
174 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
176 $langs->load(
'ticket');
178 $subject_admin =
'TicketNewEmailSubjectAdmin';
179 $body_admin =
'TicketNewEmailBodyAdmin';
180 $subject_customer =
'TicketNewEmailSubjectCustomer';
181 $body_customer =
'TicketNewEmailBodyCustomer';
182 $see_ticket_customer =
'TicketNewEmailBodyInfosTrackUrlCustomer';
185 if (
getDolGlobalString(
'TICKET_NOTIFICATION_EMAIL_TO') && empty($object->context[
'disableticketemail'])) {
186 $sendto = !
getDolGlobalString(
'TICKET_NOTIFICATION_EMAIL_TO') ?
'' : $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
193 if (!
getDolGlobalString(
'TICKET_DISABLE_CUSTOMER_MAILS') && empty($object->context[
'disableticketemail']) && $object->notify_tiers_at_create) {
198 $contactid =
GETPOST(
'contactid',
'alpha');
201 if (!empty($contactid)) {
202 $contact =
new Contact($this->db);
203 $res = $contact->fetch($contactid);
206 if ($res > 0 && !empty($contact->email) && !empty($contact->statut)) {
207 $sendto = $contact->email;
208 } elseif (!empty($object->fk_soc)) {
209 $object->fetch_thirdparty();
210 $sendto = $object->thirdparty->email;
221 case 'TICKET_DELETE':
222 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
225 case 'TICKET_MODIFY':
226 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
230 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".$object->id);
231 $langs->load(
'ticket');
233 $subject_admin =
'TicketCloseEmailSubjectAdmin';
234 $body_admin =
'TicketCloseEmailBodyAdmin';
235 $subject_customer =
'TicketCloseEmailSubjectCustomer';
236 $body_customer =
'TicketCloseEmailBodyCustomer';
237 $see_ticket_customer =
'TicketCloseEmailBodyInfosTrackUrlCustomer';
240 if (
getDolGlobalString(
'TICKET_NOTIFICATION_EMAIL_TO') && empty($object->context[
'disableticketemail'])) {
241 $sendto = !
getDolGlobalString(
'TICKET_NOTIFICATION_EMAIL_TO') ?
'' : $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
248 if (!
getDolGlobalString(
'TICKET_DISABLE_CUSTOMER_MAILS') && empty($object->context[
'disableticketemail'])) {
249 $linked_contacts = $object->listeContact(-1,
'thirdparty');
250 $linked_contacts = array_merge($linked_contacts, $object->listeContact(-1,
'internal'));
251 if (empty($linked_contacts) &&
getDolGlobalString(
'TICKET_NOTIFY_AT_CLOSING') && !empty($object->fk_soc)) {
252 $object->fetch_thirdparty();
253 $linked_contacts[][
'email'] = $object->thirdparty->email;
256 $contactid =
GETPOST(
'contactid',
'int');
259 if ($contactid > 0) {
262 $contact =
new Contact($this->db);
263 $res = $contact->fetch($contactid);
264 if (! in_array($contact, $linked_contacts)) {
265 $error_msg = $langs->trans(
'Error').
': ';
266 $error_msg .= $langs->transnoentities(
'TicketWrongContact');
274 if ($res > 0 && !empty($contact->email) && !empty($contact->statut)) {
275 $sendto = $contact->email;
276 } elseif (!empty($linked_contacts) && ($contactid == -2 || (
GETPOST(
'massaction',
'alpha') ==
'close' &&
GETPOST(
'confirm',
'alpha') ==
'yes'))) {
279 foreach ($linked_contacts as $contact) {
280 $temp_emails[] = $contact[
'email'];
282 $sendto = implode(
", ", $temp_emails);
284 unset($linked_contacts);
309 global $conf, $mysoc;
316 $appli = $mysoc->name;
319 $subject =
'['.$appli.
'] '.$langs->transnoentities($base_subject, $object->ref, $object->track_id);
320 $message_admin = $langs->transnoentities($body, $object->track_id).
'<br>';
321 $message_admin .=
'<ul><li>'.$langs->trans(
'Title').
' : '.$object->subject.
'</li>';
322 $message_admin .=
'<li>'.$langs->trans(
'Type').
' : '.$langs->getLabelFromKey($this->db,
'TicketTypeShort'.$object->type_code,
'c_ticket_type',
'code',
'label', $object->type_code).
'</li>';
323 $message_admin .=
'<li>'.$langs->trans(
'TicketCategory').
' : '.$langs->getLabelFromKey($this->db,
'TicketCategoryShort'.$object->category_code,
'c_ticket_category',
'code',
'label', $object->category_code).
'</li>';
324 $message_admin .=
'<li>'.$langs->trans(
'Severity').
' : '.$langs->getLabelFromKey($this->db,
'TicketSeverityShort'.$object->severity_code,
'c_ticket_severity',
'code',
'label', $object->severity_code).
'</li>';
325 $message_admin .=
'<li>'.$langs->trans(
'From').
' : '.($object->email_from ? $object->email_from : ($object->fk_user_create > 0 ? $langs->trans(
'Internal') :
'')).
'</li>';
328 $extraFields->fetch_name_optionals_label($object->table_element);
329 if (is_array($object->array_options) && count($object->array_options) > 0) {
330 foreach ($object->array_options as $key => $value) {
331 $key = substr($key, 8);
332 $message_admin .=
'<li>'.$langs->trans($extraFields->attributes[$object->element][
'label'][$key]).
' : '.$extraFields->showOutputField($key, $value,
'', $object->table_element).
'</li>';
335 if ($object->fk_soc > 0) {
336 $object->fetch_thirdparty();
337 $message_admin .=
'<li>'.$langs->trans(
'Company').
' : '.$object->thirdparty->name.
'</li>';
339 $message_admin .=
'</ul>';
341 $message = $object->message;
345 $message_admin .=
'<p>'.$langs->trans(
'Message').
' : <br><br>'.$message.
'</p><br>';
346 $message_admin .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id.
'">'.$langs->trans(
'SeeThisTicketIntomanagementInterface').
'</a></p>';
350 $trackid =
'tic'.$object->id;
353 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
354 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
356 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
357 $mailfile =
new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename,
'',
'', 0, -1,
'',
'', $trackid,
'',
'ticket');
358 if ($mailfile->error) {
361 $result = $mailfile->sendfile();
364 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
381 global $conf, $extrafields, $mysoc, $user;
388 $appli = $mysoc->name;
390 $subject =
'['.$appli.
'] '.$langs->transnoentities($base_subject);
391 $message_customer = $langs->transnoentities($body, $object->track_id).
'<br>';
392 $message_customer .=
'<ul><li>'.$langs->trans(
'Title').
' : '.$object->subject.
'</li>';
393 $message_customer .=
'<li>'.$langs->trans(
'Type').
' : '.$langs->getLabelFromKey($this->db,
'TicketTypeShort'.$object->type_code,
'c_ticket_type',
'code',
'label', $object->type_code).
'</li>';
394 $message_customer .=
'<li>'.$langs->trans(
'TicketCategory').
' : '.$langs->getLabelFromKey($this->db,
'TicketCategoryShort'.$object->category_code,
'c_ticket_category',
'code',
'label', $object->category_code).
'</li>';
395 $message_customer .=
'<li>'.$langs->trans(
'Severity').
' : '.$langs->getLabelFromKey($this->db,
'TicketSeverityShort'.$object->severity_code,
'c_ticket_severity',
'code',
'label', $object->severity_code).
'</li>';
398 if (is_array($extrafields->attributes[$object->table_element][
'label'])) {
399 foreach ($extrafields->attributes[$object->table_element][
'label'] as $key => $value) {
401 if ($enabled && isset($extrafields->attributes[$object->table_element][
'list'][$key])) {
402 $enabled =
dol_eval($extrafields->attributes[$object->table_element][
'list'][$key], 1);
405 if ($perms && isset($extrafields->attributes[$object->table_element][
'perms'][$key])) {
406 $perms =
dol_eval($extrafields->attributes[$object->table_element][
'perms'][$key], 1);
410 if (empty($enabled)) {
418 $message_customer .=
'<li>' . $langs->trans($key) .
' : ' . $value .
'</li>';
423 $message_customer .=
'</ul>';
425 $message = $object->message;
429 $message_customer .=
'<p>'.$langs->trans(
'Message').
' : <br><br>'.$message.
'</p><br>';
433 $message_customer .=
'<p>'.$langs->trans($see_ticket).
' : <a href="'.$url_public_ticket.
'">'.$url_public_ticket.
'</a></p>';
434 $message_customer .=
'<p>'.$langs->trans(
'TicketEmailPleaseDoNotReplyToThisEmail').
'</p>';
438 $trackid =
'tic'.$object->id;
443 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
446 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
447 $mailfile =
new CMailFile($subject, $sendto, $from, $message_customer, $filepath, $mimetype, $filename,
'',
'', 0, -1,
'',
'', $trackid,
'',
'ticket');
448 if ($mailfile->error) {
451 $result = $mailfile->sendfile();
454 $object->fetch($object->id);
455 $object->date_last_msg_sent =
dol_now();
456 $object->update($user);
460 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;