68 if (empty($conf->ticket) || !isModEnabled(
'ticket')) {
73 case 'TICKET_ASSIGNED':
74 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
76 if (
$object->fk_user_assign > 0) {
77 if (
$object->fk_user_assign != $user->id) {
78 $userstat =
new User($this->db);
79 $res = $userstat->fetch(
$object->fk_user_assign);
88 $appli = $mysoc->name;
91 $subject =
'['.$appli.
'] '.$langs->transnoentities(
'TicketAssignedToYou');
92 $message =
'<p>'.$langs->transnoentities(
'TicketAssignedEmailBody',
$object->track_id,
dolGetFirstLastname($user->firstname, $user->lastname)).
"</p>";
93 $message .=
'<ul><li>'.$langs->trans(
'Title').
' : '.
$object->subject.
'</li>';
94 $message .=
'<li>'.$langs->trans(
'Type').
' : '.
$object->type_label.
'</li>';
95 $message .=
'<li>'.$langs->trans(
'Category').
' : '.
$object->category_label.
'</li>';
96 $message .=
'<li>'.$langs->trans(
'Severity').
' : '.
$object->severity_label.
'</li>';
98 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
99 foreach (
$object->array_options as $key => $value) {
100 $message .=
'<li>'.$langs->trans($key).
' : '.$value.
'</li>';
105 $message .=
'<p>'.$langs->trans(
'Message').
' : <br>'.
$object->message.
'</p>';
106 $message .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.
$object->track_id.
'">'.$langs->trans(
'SeeThisTicketIntomanagementInterface').
'</a></p>';
108 $sendto = $userstat->email;
115 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
117 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
118 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename,
'',
'', 0, -1);
119 if ($mailfile->error) {
122 $result = $mailfile->sendfile();
125 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
129 $this->error = $userstat->error;
130 $this->errors = $userstat->errors;
136 $langs->load(
'ticket');
138 $subject_customer =
'TicketAssignedCustomerEmail';
139 $body_customer =
'TicketAssignedCustomerBody';
140 $see_ticket_customer =
'TicketNewEmailBodyInfosTrackUrlCustomer';
143 $linked_contacts =
$object->listeContact(-1,
'thirdparty');
149 $temp_emails[] =
$object->origin_email;
152 if (!empty($linked_contacts)) {
153 foreach ($linked_contacts as $contact) {
155 if (!in_array($contact[
'email'], $temp_emails)) {
156 $temp_emails[] = $contact[
'email'];
161 $sendto = implode(
", ", $temp_emails);
163 unset($linked_contacts);
174 case 'TICKET_CREATE':
175 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
177 $langs->load(
'ticket');
179 $subject_admin =
'TicketNewEmailSubjectAdmin';
180 $body_admin =
'TicketNewEmailBodyAdmin';
181 $subject_customer =
'TicketNewEmailSubjectCustomer';
182 $body_customer =
'TicketNewEmailBodyCustomer';
183 $see_ticket_customer =
'TicketNewEmailBodyInfosTrackUrlCustomer';
187 $sendto = !
getDolGlobalString(
'TICKET_NOTIFICATION_EMAIL_TO') ?
'' : $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
199 $contactid = empty(
$object->context[
'contactid']) ? 0 :
$object->context[
'contactid'];
202 if (!empty($contactid)) {
203 $contact =
new Contact($this->db);
204 $res = $contact->fetch($contactid);
207 if ($res > 0 && !empty($contact->email) && !empty($contact->statut)) {
208 $sendto = $contact->email;
209 } elseif (!empty(
$object->fk_soc)) {
211 $sendto =
$object->thirdparty->email;
222 case 'TICKET_DELETE':
223 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
226 case 'TICKET_MODIFY':
227 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
231 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
232 $langs->load(
'ticket');
234 $subject_admin =
'TicketCloseEmailSubjectAdmin';
235 $body_admin =
'TicketCloseEmailBodyAdmin';
236 $subject_customer =
'TicketCloseEmailSubjectCustomer';
237 $body_customer =
'TicketCloseEmailBodyCustomer';
238 $see_ticket_customer =
'TicketCloseEmailBodyInfosTrackUrlCustomer';
242 $sendto = !
getDolGlobalString(
'TICKET_NOTIFICATION_EMAIL_TO') ?
'' : $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
250 $linked_contacts =
$object->listeContact(-1,
'thirdparty');
251 $linked_contacts = array_merge($linked_contacts,
$object->listeContact(-1,
'internal'));
254 $linked_contacts[][
'email'] =
$object->thirdparty->email;
257 $contactid = empty(
$object->context[
'contactid']) ? 0 :
$object->context[
'contactid'];
260 if ($contactid > 0) {
263 $contact =
new Contact($this->db);
264 $res = $contact->fetch($contactid);
265 if (! in_array($contact, $linked_contacts)) {
266 $error_msg = $langs->trans(
'Error').
': ';
267 $error_msg .= $langs->transnoentities(
'TicketWrongContact');
275 if ($res > 0 && !empty($contact->email) && !empty($contact->statut)) {
276 $sendto = $contact->email;
277 } elseif (!empty($linked_contacts) && ($contactid == -2 || (
GETPOST(
'massaction',
'alpha') ==
'close' &&
GETPOST(
'confirm',
'alpha') ==
'yes'))) {
280 foreach ($linked_contacts as $contact) {
281 $temp_emails[] = $contact[
'email'];
283 $sendto = implode(
", ", $temp_emails);
285 unset($linked_contacts);
310 global $conf, $mysoc;
317 $appli = $mysoc->name;
320 $subject =
'['.$appli.
'] '.$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>';
338 $message_admin .=
'<li>'.$langs->trans(
'Company').
' : '.
$object->thirdparty->name.
'</li>';
340 $message_admin .=
'</ul>';
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>';
351 $trackid =
'tic'.$object->id;
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();
365 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
382 global $conf, $extrafields, $mysoc, $user;
389 $appli = $mysoc->name;
391 $subject =
'['.$appli.
'] '.$langs->transnoentities($base_subject);
392 $message_customer = $langs->transnoentities($body,
$object->track_id).
'<br>';
393 $message_customer .=
'<ul><li>'.$langs->trans(
'Title').
' : '.
$object->subject.
'</li>';
394 $message_customer .=
'<li>'.$langs->trans(
'Type').
' : '.$langs->getLabelFromKey($this->db,
'TicketTypeShort'.
$object->type_code,
'c_ticket_type',
'code',
'label',
$object->type_code).
'</li>';
395 $message_customer .=
'<li>'.$langs->trans(
'TicketCategory').
' : '.$langs->getLabelFromKey($this->db,
'TicketCategoryShort'.
$object->category_code,
'c_ticket_category',
'code',
'label',
$object->category_code).
'</li>';
396 $message_customer .=
'<li>'.$langs->trans(
'Severity').
' : '.$langs->getLabelFromKey($this->db,
'TicketSeverityShort'.
$object->severity_code,
'c_ticket_severity',
'code',
'label',
$object->severity_code).
'</li>';
399 if (is_array($extrafields->attributes[
$object->table_element][
'label'])) {
400 foreach ($extrafields->attributes[
$object->table_element][
'label'] as $key => $value) {
402 if ($enabled && isset($extrafields->attributes[
$object->table_element][
'list'][$key])) {
403 $enabled = (int)
dol_eval($extrafields->attributes[
$object->table_element][
'list'][$key], 1);
406 if ($perms && isset($extrafields->attributes[
$object->table_element][
'perms'][$key])) {
407 $perms = (int)
dol_eval($extrafields->attributes[
$object->table_element][
'perms'][$key], 1);
411 if (empty($enabled)) {
419 $message_customer .=
'<li>' . $langs->trans($key) .
' : ' . $value .
'</li>';
424 $message_customer .=
'</ul>';
430 $message_customer .=
'<p>'.$langs->trans(
'Message').
' : <br><br>'.$message.
'</p><br>';
434 $message_customer .=
'<p>'.$langs->trans($see_ticket).
' : <a href="'.$url_public_ticket.
'">'.$url_public_ticket.
'</a></p>';
435 $message_customer .=
'<p>'.$langs->trans(
'TicketEmailPleaseDoNotReplyToThisEmail').
'</p>';
439 $trackid =
'tic'.$object->id;
444 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
447 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
448 $mailfile =
new CMailFile($subject, $sendto, $from, $message_customer, $filepath, $mimetype, $filename,
'',
'', 0, -1,
'',
'', $trackid,
'',
'ticket');
449 if ($mailfile->error) {
452 $result = $mailfile->sendfile();
461 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;