27require_once DOL_DOCUMENT_ROOT.
'/core/triggers/dolibarrtriggers.class.php';
44 $this->
name = preg_replace(
'/^Interface/i',
'', get_class($this));
45 $this->family =
"ticket";
46 $this->
description =
"Triggers of the module ticket to send notifications to internal users and to third-parties";
47 $this->version = self::VERSIONS[
'prod'];
48 $this->picto =
'ticket';
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);
84 $sendto = $userstat->email;
85 $subject_assignee =
'TicketAssignedToYou';
86 $body_assignee =
'TicketAssignedEmailBody';
87 $see_ticket_assignee =
'SeeThisTicketIntomanagementInterface';
91 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
93 if (!empty($sendto)) {
97 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
101 $this->error = $userstat->error;
102 $this->errors = $userstat->errors;
108 $langs->load(
'ticket');
110 $subject_customer =
'TicketAssignedCustomerEmail';
111 $body_customer =
'TicketAssignedCustomerBody';
112 $see_ticket_customer =
'TicketNewEmailBodyInfosTrackUrlCustomer';
115 $linked_contacts =
$object->listeContact(-1,
'thirdparty');
121 $temp_emails[] =
$object->origin_email;
124 if (!empty($linked_contacts)) {
125 foreach ($linked_contacts as $contact) {
127 if (!in_array($contact[
'email'], $temp_emails)) {
128 $temp_emails[] = $contact[
'email'];
133 $sendto = implode(
", ", $temp_emails);
135 unset($linked_contacts);
146 case 'TICKET_CREATE':
147 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
149 $langs->load(
'ticket');
151 $subject_admin =
'TicketNewEmailSubjectAdmin';
152 $body_admin =
'TicketNewEmailBodyAdmin';
154 $subject_customer =
'TicketNewEmailSubjectCustomer';
155 $body_customer =
'TicketNewEmailBodyCustomer';
156 $see_ticket_customer =
'TicketNewEmailBodyInfosTrackUrlCustomer';
158 $subject_assignee =
'TicketAssignedToYou';
159 $body_assignee =
'TicketAssignedEmailBody';
160 $see_ticket_assignee =
'SeeThisTicketIntomanagementInterface';
173 if (
$object->fk_user_assign > 0 &&
$object->fk_user_assign != $user->id && empty(
$object->context[
'disableticketemail'])) {
174 $userstat =
new User($this->db);
175 $res = $userstat->fetch(
$object->fk_user_assign);
180 $sendto = $userstat->email;
182 $old_MAIN_MAIL_AUTOCOPY_TO =
$conf->global->MAIN_MAIL_AUTOCOPY_TO;
183 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
186 if (!empty($sendto)) {
191 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
195 $this->error = $userstat->error;
196 $this->errors = $userstat->errors;
203 if (empty(
$object->context[
'disableticketemail']) &&
$object->notify_tiers_at_create) {
208 $contactid = empty(
$object->context[
'contactid']) ? 0 :
$object->context[
'contactid'];
212 if (!empty($contactid)) {
213 $contactObj =
new Contact($this->db);
214 $res = $contactObj->fetch($contactid);
217 if ($contactObj !==
null && !empty($contactObj->email) && !empty($contactObj->statut)) {
218 $sendto = $contactObj->email;
219 } elseif (!empty(
$object->fk_soc)) {
221 $sendto =
$object->thirdparty->email;
232 case 'TICKET_DELETE':
233 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
236 case 'TICKET_MODIFY':
237 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
241 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
242 $langs->load(
'ticket');
244 $subject_admin =
'TicketCloseEmailSubjectAdmin';
245 $body_admin =
'TicketCloseEmailBodyAdmin';
246 $subject_customer =
'TicketCloseEmailSubjectCustomer';
247 $body_customer =
'TicketCloseEmailBodyCustomer';
248 $see_ticket_customer =
'TicketCloseEmailBodyInfosTrackUrlCustomer';
261 if (empty(
$object->context[
'disableticketemail'])) {
262 $linked_contacts =
$object->listeContact(-1,
'thirdparty');
263 $linked_contacts = array_merge($linked_contacts,
$object->listeContact(-1,
'internal'));
266 $linked_contacts[][
'email'] =
$object->thirdparty->email;
269 $contactid = empty(
$object->context[
'contactid']) ? 0 :
$object->context[
'contactid'];
273 if ($contactid > 0) {
276 $contactObj =
new Contact($this->db);
277 $res = $contactObj->fetch($contactid);
278 if (! in_array($contactObj, $linked_contacts)) {
279 $error_msg = $langs->trans(
'Error').
': ';
280 $error_msg .= $langs->transnoentities(
'TicketWrongContact');
288 if ($contactObj !==
null && $res > 0 && !empty($contactObj->email) && !empty($contactObj->statut)) {
289 $sendto = $contactObj->email;
290 } elseif (!empty($linked_contacts) && ($contactid == -2 || (
GETPOST(
'massaction',
'alpha') ==
'close' &&
GETPOST(
'confirm',
'alpha') ==
'yes'))) {
293 foreach ($linked_contacts as $contact) {
294 $temp_emails[] = $contact[
'email'];
296 $sendto = implode(
", ", $temp_emails);
298 unset($linked_contacts);
323 global
$conf, $mysoc;
330 $appli = $mysoc->name;
333 $subject =
'['.$appli.
'] '.$langs->transnoentities($base_subject,
$object->ref,
$object->track_id);
334 $message_admin = $langs->transnoentities($body,
$object->track_id).
'<br>';
335 $message_admin .=
'<ul><li>'.$langs->trans(
'Title').
' : '.
$object->subject.
'</li>';
336 $message_admin .=
'<li>'.$langs->trans(
'Type').
' : '.$langs->getLabelFromKey($this->db,
'TicketTypeShort'.
$object->type_code,
'c_ticket_type',
'code',
'label',
$object->type_code).
'</li>';
337 $message_admin .=
'<li>'.$langs->trans(
'TicketCategory').
' : '.$langs->getLabelFromKey($this->db,
'TicketCategoryShort'.
$object->category_code,
'c_ticket_category',
'code',
'label',
$object->category_code).
'</li>';
338 $message_admin .=
'<li>'.$langs->trans(
'Severity').
' : '.$langs->getLabelFromKey($this->db,
'TicketSeverityShort'.
$object->severity_code,
'c_ticket_severity',
'code',
'label',
$object->severity_code).
'</li>';
339 $message_admin .=
'<li>'.$langs->trans(
'From').
' : '.(
$object->email_from ?
$object->email_from : (
$object->fk_user_create > 0 ? $langs->trans(
'Internal') :
'')).
'</li>';
342 $extraFields->fetch_name_optionals_label(
$object->table_element);
343 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
344 foreach (
$object->array_options as $key => $value) {
345 $key = substr($key, 8);
346 $message_admin .=
'<li>'.$langs->trans($extraFields->attributes[
$object->element][
'label'][$key]).
' : '.$extraFields->showOutputField($key, $value,
'',
$object->table_element).
'</li>';
351 $message_admin .=
'<li>'.$langs->trans(
'Company').
' : '.
$object->thirdparty->name.
'</li>';
353 $message_admin .=
'</ul>';
359 $message_admin .=
'<p>'.$langs->trans(
'Message').
' : <br><br>'.$message.
'</p><br>';
360 $message_admin .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.
$object->track_id.
'">'.$langs->trans(
'SeeThisTicketIntomanagementInterface').
'</a></p>';
364 $trackid =
'tic'.$object->id;
366 $old_MAIN_MAIL_AUTOCOPY_TO =
null;
369 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
371 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
372 $mailfile =
new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename,
'',
'', 0, -1,
'',
'', $trackid,
'',
'ticket');
373 if ($mailfile->error) {
376 $result = $mailfile->sendfile();
379 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
396 global
$conf, $extrafields, $mysoc, $user;
403 $appli = $mysoc->name;
405 $subject =
'['.$appli.
'] '.$langs->transnoentities($base_subject);
406 $message_customer = $langs->transnoentities($body,
$object->track_id).
'<br>';
407 $message_customer .=
'<ul><li>'.$langs->trans(
'Title').
' : '.
$object->subject.
'</li>';
408 $message_customer .=
'<li>'.$langs->trans(
'Type').
' : '.$langs->getLabelFromKey($this->db,
'TicketTypeShort'.
$object->type_code,
'c_ticket_type',
'code',
'label',
$object->type_code).
'</li>';
409 $message_customer .=
'<li>'.$langs->trans(
'TicketCategory').
' : '.$langs->getLabelFromKey($this->db,
'TicketCategoryShort'.
$object->category_code,
'c_ticket_category',
'code',
'label',
$object->category_code).
'</li>';
410 $message_customer .=
'<li>'.$langs->trans(
'Severity').
' : '.$langs->getLabelFromKey($this->db,
'TicketSeverityShort'.
$object->severity_code,
'c_ticket_severity',
'code',
'label',
$object->severity_code).
'</li>';
413 if (is_array($extrafields->attributes[
$object->table_element][
'label'])) {
414 foreach ($extrafields->attributes[
$object->table_element][
'label'] as $key => $value) {
416 if ($enabled && isset($extrafields->attributes[
$object->table_element][
'list'][$key])) {
417 $enabled = (int)
dol_eval($extrafields->attributes[
$object->table_element][
'list'][$key], 1);
420 if ($perms && isset($extrafields->attributes[
$object->table_element][
'perms'][$key])) {
421 $perms = (int)
dol_eval($extrafields->attributes[
$object->table_element][
'perms'][$key], 1);
425 if (empty($enabled)) {
433 $message_customer .=
'<li>' . $langs->trans($key) .
' : ' . $value .
'</li>';
438 $message_customer .=
'</ul>';
444 $message_customer .=
'<p>'.$langs->trans(
'Message').
' : <br><br>'.$message.
'</p><br>';
448 $message_customer .=
'<p>'.$langs->trans($see_ticket).
' : <a href="'.$url_public_ticket.
'">'.$url_public_ticket.
'</a></p>';
449 $message_customer .=
'<p>'.$langs->trans(
'TicketEmailPleaseDoNotReplyToThisEmail').
'</p>';
453 $trackid =
'tic'.$object->id;
455 $old_MAIN_MAIL_AUTOCOPY_TO =
null;
458 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
461 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
462 $mailfile =
new CMailFile($subject, $sendto, $from, $message_customer, $filepath, $mimetype, $filename,
'',
'', 0, -1,
'',
'', $trackid,
'',
'ticket');
463 if ($mailfile->error) {
466 $result = $mailfile->sendfile();
475 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
492 global
$conf, $user, $mysoc;
500 $appli = $mysoc->name;
502 $subject =
'['.$appli.
'] '.$langs->transnoentities($base_subject);
503 $message =
'<p>'.$langs->transnoentities($body,
$object->track_id,
dolGetFirstLastname($user->firstname, $user->lastname)).
"</p>";
504 $message .=
'<ul><li>'.$langs->trans(
'Title').
' : '.
$object->subject.
'</li>';
505 $message .=
'<li>'.$langs->trans(
'Type').
' : '.
$object->type_label.
'</li>';
506 $message .=
'<li>'.$langs->trans(
'Category').
' : '.
$object->category_label.
'</li>';
507 $message .=
'<li>'.$langs->trans(
'Severity').
' : '.
$object->severity_label.
'</li>';
509 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
510 foreach (
$object->array_options as $key => $value) {
511 $message .=
'<li>'.$langs->trans($key).
' : '.$value.
'</li>';
516 $message .=
'<p>'.$langs->trans(
'Message').
' : <br>'.
$object->message.
'</p>';
517 $message .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.
$object->track_id.
'">'.$langs->trans($see_ticket).
'</a></p>';
523 $old_MAIN_MAIL_AUTOCOPY_TO =
null;
526 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
529 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
530 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename,
'',
'', 0, -1);
531 if ($mailfile->error) {
534 $result = $mailfile->sendfile();
543 $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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Class to generate the form for creating a new ticket.
$conf db name
Only used if Module[ID]Name translation string is not found.