26require_once DOL_DOCUMENT_ROOT.
'/core/triggers/dolibarrtriggers.class.php';
43 $this->
name = preg_replace(
'/^Interface/i',
'', get_class($this));
44 $this->family =
"ticket";
45 $this->
description =
"Triggers of the module ticket to send notifications to internal users and to third-parties";
46 $this->version = self::VERSIONS[
'prod'];
47 $this->picto =
'ticket';
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 $sendto = $userstat->email;
91 $subject_assignee =
'TicketAssignedToYou';
92 $body_assignee =
'TicketAssignedEmailBody';
93 $see_ticket_assignee =
'SeeThisTicketIntomanagementInterface';
97 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
99 if (!empty($sendto)) {
103 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
107 $this->error = $userstat->error;
108 $this->errors = $userstat->errors;
114 $langs->load(
'ticket');
116 $subject_customer =
'TicketAssignedCustomerEmail';
117 $body_customer =
'TicketAssignedCustomerBody';
118 $see_ticket_customer =
'TicketNewEmailBodyInfosTrackUrlCustomer';
121 $linked_contacts =
$object->listeContact(-1,
'thirdparty');
127 $temp_emails[] =
$object->origin_email;
130 if (!empty($linked_contacts)) {
131 foreach ($linked_contacts as $contact) {
133 if (!in_array($contact[
'email'], $temp_emails)) {
134 $temp_emails[] = $contact[
'email'];
139 $sendto = implode(
", ", $temp_emails);
141 unset($linked_contacts);
152 case 'TICKET_CREATE':
153 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
155 $langs->load(
'ticket');
157 $subject_admin =
'TicketNewEmailSubjectAdmin';
158 $body_admin =
'TicketNewEmailBodyAdmin';
160 $subject_customer =
'TicketNewEmailSubjectCustomer';
161 $body_customer =
'TicketNewEmailBodyCustomer';
162 $see_ticket_customer =
'TicketNewEmailBodyInfosTrackUrlCustomer';
164 $subject_assignee =
'TicketAssignedToYou';
165 $body_assignee =
'TicketAssignedEmailBody';
166 $see_ticket_assignee =
'SeeThisTicketIntomanagementInterface';
179 if (
$object->fk_user_assign > 0 &&
$object->fk_user_assign != $user->id && empty(
$object->context[
'disableticketemail'])) {
180 $userstat =
new User($this->db);
181 $res = $userstat->fetch(
$object->fk_user_assign);
186 $sendto = $userstat->email;
188 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
189 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
192 if (!empty($sendto)) {
197 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
201 $this->error = $userstat->error;
202 $this->errors = $userstat->errors;
209 if (empty(
$object->context[
'disableticketemail']) &&
$object->notify_tiers_at_create) {
214 $contactid = empty(
$object->context[
'contactid']) ? 0 :
$object->context[
'contactid'];
217 if (!empty($contactid)) {
218 $contact =
new Contact($this->db);
219 $res = $contact->fetch($contactid);
222 if ($res > 0 && !empty($contact->email) && !empty($contact->statut)) {
223 $sendto = $contact->email;
224 } elseif (!empty(
$object->fk_soc)) {
226 $sendto =
$object->thirdparty->email;
237 case 'TICKET_DELETE':
238 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
241 case 'TICKET_MODIFY':
242 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
246 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
247 $langs->load(
'ticket');
249 $subject_admin =
'TicketCloseEmailSubjectAdmin';
250 $body_admin =
'TicketCloseEmailBodyAdmin';
251 $subject_customer =
'TicketCloseEmailSubjectCustomer';
252 $body_customer =
'TicketCloseEmailBodyCustomer';
253 $see_ticket_customer =
'TicketCloseEmailBodyInfosTrackUrlCustomer';
266 if (empty(
$object->context[
'disableticketemail'])) {
267 $linked_contacts =
$object->listeContact(-1,
'thirdparty');
268 $linked_contacts = array_merge($linked_contacts,
$object->listeContact(-1,
'internal'));
271 $linked_contacts[][
'email'] =
$object->thirdparty->email;
274 $contactid = empty(
$object->context[
'contactid']) ? 0 :
$object->context[
'contactid'];
277 if ($contactid > 0) {
280 $contact =
new Contact($this->db);
281 $res = $contact->fetch($contactid);
282 if (! in_array($contact, $linked_contacts)) {
283 $error_msg = $langs->trans(
'Error').
': ';
284 $error_msg .= $langs->transnoentities(
'TicketWrongContact');
292 if ($res > 0 && !empty($contact->email) && !empty($contact->statut)) {
293 $sendto = $contact->email;
294 } elseif (!empty($linked_contacts) && ($contactid == -2 || (
GETPOST(
'massaction',
'alpha') ==
'close' &&
GETPOST(
'confirm',
'alpha') ==
'yes'))) {
297 foreach ($linked_contacts as $contact) {
298 $temp_emails[] = $contact[
'email'];
300 $sendto = implode(
", ", $temp_emails);
302 unset($linked_contacts);
327 global $conf, $mysoc;
334 $appli = $mysoc->name;
337 $subject =
'['.$appli.
'] '.$langs->transnoentities($base_subject,
$object->ref,
$object->track_id);
338 $message_admin = $langs->transnoentities($body,
$object->track_id).
'<br>';
339 $message_admin .=
'<ul><li>'.$langs->trans(
'Title').
' : '.
$object->subject.
'</li>';
340 $message_admin .=
'<li>'.$langs->trans(
'Type').
' : '.$langs->getLabelFromKey($this->db,
'TicketTypeShort'.
$object->type_code,
'c_ticket_type',
'code',
'label',
$object->type_code).
'</li>';
341 $message_admin .=
'<li>'.$langs->trans(
'TicketCategory').
' : '.$langs->getLabelFromKey($this->db,
'TicketCategoryShort'.
$object->category_code,
'c_ticket_category',
'code',
'label',
$object->category_code).
'</li>';
342 $message_admin .=
'<li>'.$langs->trans(
'Severity').
' : '.$langs->getLabelFromKey($this->db,
'TicketSeverityShort'.
$object->severity_code,
'c_ticket_severity',
'code',
'label',
$object->severity_code).
'</li>';
343 $message_admin .=
'<li>'.$langs->trans(
'From').
' : '.(
$object->email_from ?
$object->email_from : (
$object->fk_user_create > 0 ? $langs->trans(
'Internal') :
'')).
'</li>';
346 $extraFields->fetch_name_optionals_label(
$object->table_element);
347 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
348 foreach (
$object->array_options as $key => $value) {
349 $key = substr($key, 8);
350 $message_admin .=
'<li>'.$langs->trans($extraFields->attributes[
$object->element][
'label'][$key]).
' : '.$extraFields->showOutputField($key, $value,
'',
$object->table_element).
'</li>';
355 $message_admin .=
'<li>'.$langs->trans(
'Company').
' : '.
$object->thirdparty->name.
'</li>';
357 $message_admin .=
'</ul>';
363 $message_admin .=
'<p>'.$langs->trans(
'Message').
' : <br><br>'.$message.
'</p><br>';
364 $message_admin .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.
$object->track_id.
'">'.$langs->trans(
'SeeThisTicketIntomanagementInterface').
'</a></p>';
368 $trackid =
'tic'.$object->id;
372 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
374 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
375 $mailfile =
new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename,
'',
'', 0, -1,
'',
'', $trackid,
'',
'ticket');
376 if ($mailfile->error) {
379 $result = $mailfile->sendfile();
382 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
399 global $conf, $extrafields, $mysoc, $user;
406 $appli = $mysoc->name;
408 $subject =
'['.$appli.
'] '.$langs->transnoentities($base_subject);
409 $message_customer = $langs->transnoentities($body,
$object->track_id).
'<br>';
410 $message_customer .=
'<ul><li>'.$langs->trans(
'Title').
' : '.
$object->subject.
'</li>';
411 $message_customer .=
'<li>'.$langs->trans(
'Type').
' : '.$langs->getLabelFromKey($this->db,
'TicketTypeShort'.
$object->type_code,
'c_ticket_type',
'code',
'label',
$object->type_code).
'</li>';
412 $message_customer .=
'<li>'.$langs->trans(
'TicketCategory').
' : '.$langs->getLabelFromKey($this->db,
'TicketCategoryShort'.
$object->category_code,
'c_ticket_category',
'code',
'label',
$object->category_code).
'</li>';
413 $message_customer .=
'<li>'.$langs->trans(
'Severity').
' : '.$langs->getLabelFromKey($this->db,
'TicketSeverityShort'.
$object->severity_code,
'c_ticket_severity',
'code',
'label',
$object->severity_code).
'</li>';
416 if (is_array($extrafields->attributes[
$object->table_element][
'label'])) {
417 foreach ($extrafields->attributes[
$object->table_element][
'label'] as $key => $value) {
419 if ($enabled && isset($extrafields->attributes[
$object->table_element][
'list'][$key])) {
420 $enabled = (int)
dol_eval($extrafields->attributes[
$object->table_element][
'list'][$key], 1);
423 if ($perms && isset($extrafields->attributes[
$object->table_element][
'perms'][$key])) {
424 $perms = (int)
dol_eval($extrafields->attributes[
$object->table_element][
'perms'][$key], 1);
428 if (empty($enabled)) {
436 $message_customer .=
'<li>' . $langs->trans($key) .
' : ' . $value .
'</li>';
441 $message_customer .=
'</ul>';
447 $message_customer .=
'<p>'.$langs->trans(
'Message').
' : <br><br>'.$message.
'</p><br>';
451 $message_customer .=
'<p>'.$langs->trans($see_ticket).
' : <a href="'.$url_public_ticket.
'">'.$url_public_ticket.
'</a></p>';
452 $message_customer .=
'<p>'.$langs->trans(
'TicketEmailPleaseDoNotReplyToThisEmail').
'</p>';
454 $message_customer .=
'<p>'.$langs->trans(
'TicketEmailPleaseDoNotReplyToThisEmailNoInterface').
'</p>';
459 $trackid =
'tic'.$object->id;
464 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
467 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
468 $mailfile =
new CMailFile($subject, $sendto, $from, $message_customer, $filepath, $mimetype, $filename,
'',
'', 0, -1,
'',
'', $trackid,
'',
'ticket');
469 if ($mailfile->error) {
472 $result = $mailfile->sendfile();
481 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
498 global $conf, $user, $mysoc;
506 $appli = $mysoc->name;
508 $subject =
'['.$appli.
'] '.$langs->transnoentities($base_subject);
509 $message =
'<p>'.$langs->transnoentities($body,
$object->track_id,
dolGetFirstLastname($user->firstname, $user->lastname)).
"</p>";
510 $message .=
'<ul><li>'.$langs->trans(
'Title').
' : '.
$object->subject.
'</li>';
511 $message .=
'<li>'.$langs->trans(
'Type').
' : '.
$object->type_label.
'</li>';
512 $message .=
'<li>'.$langs->trans(
'Category').
' : '.
$object->category_label.
'</li>';
513 $message .=
'<li>'.$langs->trans(
'Severity').
' : '.
$object->severity_label.
'</li>';
515 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
516 foreach (
$object->array_options as $key => $value) {
517 $message .=
'<li>'.$langs->trans($key).
' : '.$value.
'</li>';
522 $message .=
'<p>'.$langs->trans(
'Message').
' : <br>'.
$object->message.
'</p>';
523 $message .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.
$object->track_id.
'">'.$langs->trans($see_ticket).
'</a></p>';
529 $old_MAIN_MAIL_AUTOCOPY_TO =
null;
532 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
535 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
536 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename,
'',
'', 0, -1);
537 if ($mailfile->error) {
540 $result = $mailfile->sendfile();
549 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to stock current configuration.
Class that all triggers must inherit.
Class of triggers for ticket module.
composeAndSendAssigneeMessage($sendto, $base_subject, $body, $see_ticket, Ticket $object, Translate $langs)
Composes and sends a message concerning a ticket, to be sent to user assigned to the ticket.
__construct($db)
Constructor.
composeAndSendCustomerMessage($sendto, $base_subject, $body, $see_ticket, Ticket $object, Translate $langs)
Composes and sends a message concerning a ticket, to be sent to customer addresses.
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarr business event is done.
composeAndSendAdminMessage($sendto, $base_subject, $body, Ticket $object, Translate $langs)
Composes and sends a message concerning a ticket, to be sent to admin address.
Class to manage translations.
Class to manage Dolibarr users.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
getDolUserString($key, $default='', $tmpuser=null)
Return Dolibarr user constant string value.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_textishtml($msg, $option=0)
Return if a text is a html content.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Class to generate the form for creating a new ticket.
$conf db name
Only used if Module[ID]Name translation string is not found.