28require_once DOL_DOCUMENT_ROOT.
'/core/triggers/dolibarrtriggers.class.php';
45 $this->
name = preg_replace(
'/^Interface/i',
'', get_class($this));
46 $this->family =
"ticket";
47 $this->
description =
"Triggers of the module ticket to send notifications to internal users and to third-parties";
48 $this->version = self::VERSIONS[
'prod'];
49 $this->picto =
'ticket';
69 if (empty(
$conf->ticket) || !isModEnabled(
'ticket')) {
74 case 'TICKET_ASSIGNED':
75 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
77 if (
$object->fk_user_assign > 0) {
78 if (
$object->fk_user_assign != $user->id) {
79 $userstat =
new User($this->db);
80 $res = $userstat->fetch(
$object->fk_user_assign);
85 $sendto = $userstat->email;
86 $subject_assignee =
'TicketAssignedToYou';
87 $body_assignee =
'TicketAssignedEmailBody';
88 $see_ticket_assignee =
'SeeThisTicketIntomanagementInterface';
92 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
94 if (!empty($sendto)) {
98 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
102 $this->error = $userstat->error;
103 $this->errors = $userstat->errors;
109 $langs->load(
'ticket');
111 $subject_customer =
'TicketAssignedCustomerEmail';
112 $body_customer =
'TicketAssignedCustomerBody';
113 $see_ticket_customer =
'TicketNewEmailBodyInfosTrackUrlCustomer';
116 $linked_contacts =
$object->listeContact(-1,
'thirdparty');
122 $temp_emails[] =
$object->origin_email;
125 if (!empty($linked_contacts)) {
126 foreach ($linked_contacts as $contact) {
128 if (!in_array($contact[
'email'], $temp_emails)) {
129 $temp_emails[] = $contact[
'email'];
134 $sendto = implode(
", ", $temp_emails);
136 unset($linked_contacts);
147 case 'TICKET_CREATE':
148 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
150 $langs->load(
'ticket');
152 $subject_admin =
'TicketNewEmailSubjectAdmin';
153 $body_admin =
'TicketNewEmailBodyAdmin';
155 $subject_customer =
'TicketNewEmailSubjectCustomer';
156 $body_customer =
'TicketNewEmailBodyCustomer';
157 $see_ticket_customer =
'TicketNewEmailBodyInfosTrackUrlCustomer';
159 $subject_assignee =
'TicketAssignedToYou';
160 $body_assignee =
'TicketAssignedEmailBody';
161 $see_ticket_assignee =
'SeeThisTicketIntomanagementInterface';
174 if (
$object->fk_user_assign > 0 &&
$object->fk_user_assign != $user->id && empty(
$object->context[
'disableticketemail'])) {
175 $userstat =
new User($this->db);
176 $res = $userstat->fetch(
$object->fk_user_assign);
181 $sendto = $userstat->email;
182 $old_MAIN_MAIL_AUTOCOPY_TO =
'';
184 $old_MAIN_MAIL_AUTOCOPY_TO =
$conf->global->MAIN_MAIL_AUTOCOPY_TO;
185 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
188 if (!empty($sendto)) {
193 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
204 if (empty(
$object->context[
'disableticketemail']) &&
$object->notify_tiers_at_create) {
209 $contactid = empty(
$object->context[
'contact_id']) ? 0 :
$object->context[
'contact_id'];
213 if (!empty($contactid)) {
214 $contactObj =
new Contact($this->db);
215 $res = $contactObj->fetch($contactid);
218 if ($contactObj !==
null && !empty($contactObj->email) && !empty($contactObj->statut)) {
219 $sendto = $contactObj->email;
220 } elseif (!empty(
$object->fk_soc)) {
222 $sendto =
$object->thirdparty->email;
233 case 'TICKET_DELETE':
234 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
237 case 'TICKET_MODIFY':
238 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
242 dol_syslog(
"Trigger '".$this->
name.
"' for action '$action' launched by ".__FILE__.
". id=".
$object->id);
243 $langs->load(
'ticket');
245 $subject_admin =
'TicketCloseEmailSubjectAdmin';
246 $body_admin =
'TicketCloseEmailBodyAdmin';
247 $subject_customer =
'TicketCloseEmailSubjectCustomer';
248 $body_customer =
'TicketCloseEmailBodyCustomer';
249 $see_ticket_customer =
'TicketCloseEmailBodyInfosTrackUrlCustomer';
262 if (empty(
$object->context[
'disableticketemail'])) {
263 $linked_contacts =
$object->listeContact(-1,
'thirdparty');
264 $linked_contacts = array_merge($linked_contacts,
$object->listeContact(-1,
'internal'));
267 $linked_contacts[][
'email'] =
$object->thirdparty->email;
270 $contactid = empty(
$object->context[
'contact_id']) ? 0 :
$object->context[
'contact_id'];
274 if ($contactid > 0) {
277 $contactObj =
new Contact($this->db);
278 $res = $contactObj->fetch($contactid);
279 if (! in_array($contactObj->id, array_column($linked_contacts,
'id'))) {
280 $error_msg = $langs->trans(
'Error').
': ';
281 $error_msg .= $langs->transnoentities(
'TicketWrongContact');
289 if ($contactObj !==
null && $res > 0 && !empty($contactObj->email) && !empty($contactObj->statut)) {
290 $sendto = $contactObj->email;
291 } elseif (!empty($linked_contacts) && ($contactid == -2 || (
GETPOST(
'massaction',
'alpha') ==
'close' &&
GETPOST(
'confirm',
'alpha') ==
'yes'))) {
294 foreach ($linked_contacts as $contact) {
295 $temp_emails[] = $contact[
'email'];
297 $sendto = implode(
", ", $temp_emails);
299 unset($linked_contacts);
324 global
$conf, $mysoc;
331 $appli = $mysoc->name;
334 $subject =
'['.$appli.
'] '.$langs->transnoentities($base_subject,
$object->ref,
$object->track_id);
335 $message_admin = $langs->transnoentities($body,
$object->track_id).
'<br>';
336 $message_admin .=
'<ul><li>'.$langs->trans(
'Title').
' : '.
$object->subject.
'</li>';
337 $message_admin .=
'<li>'.$langs->trans(
'Type').
' : '.$langs->getLabelFromKey($this->db,
'TicketTypeShort'.
$object->type_code,
'c_ticket_type',
'code',
'label',
$object->type_code).
'</li>';
338 $message_admin .=
'<li>'.$langs->trans(
'TicketCategory').
' : '.$langs->getLabelFromKey($this->db,
'TicketCategoryShort'.
$object->category_code,
'c_ticket_category',
'code',
'label',
$object->category_code).
'</li>';
339 $message_admin .=
'<li>'.$langs->trans(
'Severity').
' : '.$langs->getLabelFromKey($this->db,
'TicketSeverityShort'.
$object->severity_code,
'c_ticket_severity',
'code',
'label',
$object->severity_code).
'</li>';
340 $message_admin .=
'<li>'.$langs->trans(
'From').
' : '.(
$object->email_from ?
$object->email_from : (
$object->fk_user_create > 0 ? $langs->trans(
'Internal') :
'')).
'</li>';
343 $extraFields->fetch_name_optionals_label(
$object->table_element);
344 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
345 foreach (
$object->array_options as $key => $value) {
346 $key = substr($key, 8);
347 $message_admin .=
'<li>'.$langs->trans($extraFields->attributes[
$object->element][
'label'][$key]).
' : '.$extraFields->showOutputField($key, $value,
'',
$object->table_element).
'</li>';
352 $message_admin .=
'<li>'.$langs->trans(
'Company').
' : '.
$object->thirdparty->name.
'</li>';
354 $message_admin .=
'</ul>';
360 $message_admin .=
'<p>'.$langs->trans(
'Message').
' : <br><br>'.$message.
'</p><br>';
361 $message_admin .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.
$object->track_id.
'">'.$langs->trans(
'SeeThisTicketIntomanagementInterface').
'</a></p>';
365 $trackid =
'tic'.$object->id;
367 $old_MAIN_MAIL_AUTOCOPY_TO =
null;
370 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
372 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
373 $mailfile =
new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename,
'',
'', 0, -1,
'',
'', $trackid,
'',
'ticket');
374 if ($mailfile->error) {
377 $result = $mailfile->sendfile();
380 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
397 global
$conf, $extrafields, $mysoc, $user;
404 $appli = $mysoc->name;
406 $subject =
'['.$appli.
'] '.$langs->transnoentities($base_subject);
407 $message_customer = $langs->transnoentities($body,
$object->track_id).
'<br>';
408 $message_customer .=
'<ul><li>'.$langs->trans(
'Title').
' : '.
$object->subject.
'</li>';
409 $message_customer .=
'<li>'.$langs->trans(
'Type').
' : '.$langs->getLabelFromKey($this->db,
'TicketTypeShort'.
$object->type_code,
'c_ticket_type',
'code',
'label',
$object->type_code).
'</li>';
410 $message_customer .=
'<li>'.$langs->trans(
'TicketCategory').
' : '.$langs->getLabelFromKey($this->db,
'TicketCategoryShort'.
$object->category_code,
'c_ticket_category',
'code',
'label',
$object->category_code).
'</li>';
411 $message_customer .=
'<li>'.$langs->trans(
'Severity').
' : '.$langs->getLabelFromKey($this->db,
'TicketSeverityShort'.
$object->severity_code,
'c_ticket_severity',
'code',
'label',
$object->severity_code).
'</li>';
414 if (is_array($extrafields->attributes[
$object->table_element][
'label'])) {
415 foreach ($extrafields->attributes[
$object->table_element][
'label'] as $key => $value) {
417 if ($enabled && isset($extrafields->attributes[
$object->table_element][
'list'][$key])) {
418 $enabled = (int)
dol_eval($extrafields->attributes[
$object->table_element][
'list'][$key], 1);
421 if ($perms && isset($extrafields->attributes[
$object->table_element][
'perms'][$key])) {
422 $perms = (int)
dol_eval($extrafields->attributes[
$object->table_element][
'perms'][$key], 1);
426 if (empty($enabled)) {
434 $message_customer .=
'<li>' . $langs->trans($key) .
' : ' . $value .
'</li>';
439 $message_customer .=
'</ul>';
445 $message_customer .=
'<p>'.$langs->trans(
'Message').
' : <br><br>'.$message.
'</p><br>';
449 $message_customer .=
'<p>'.$langs->trans($see_ticket).
' : <a href="'.$url_public_ticket.
'">'.$url_public_ticket.
'</a></p>';
450 $message_customer .=
'<p>'.$langs->trans(
'TicketEmailPleaseDoNotReplyToThisEmail').
'</p>';
452 $message_customer .=
'<p>'.$langs->trans(
'TicketEmailPleaseDoNotReplyToThisEmailNoInterface').
'</p>';
457 $trackid =
'tic'.$object->id;
459 $old_MAIN_MAIL_AUTOCOPY_TO =
null;
462 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
465 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
466 $mailfile =
new CMailFile($subject, $sendto, $from, $message_customer, $filepath, $mimetype, $filename,
'',
'', 0, -1,
'',
'', $trackid,
'',
'ticket');
467 if ($mailfile->error) {
470 $result = $mailfile->sendfile();
479 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
496 global
$conf, $user, $mysoc;
504 $appli = $mysoc->name;
506 $subject =
'['.$appli.
'] '.$langs->transnoentities($base_subject);
507 $message =
'<p>'.$langs->transnoentities($body,
$object->track_id,
dolGetFirstLastname($user->firstname, $user->lastname)).
"</p>";
508 $message .=
'<ul><li>'.$langs->trans(
'Title').
' : '.
$object->subject.
'</li>';
509 $message .=
'<li>'.$langs->trans(
'Type').
' : '.
$object->type_label.
'</li>';
510 $message .=
'<li>'.$langs->trans(
'Category').
' : '.
$object->category_label.
'</li>';
511 $message .=
'<li>'.$langs->trans(
'Severity').
' : '.
$object->severity_label.
'</li>';
513 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
514 foreach (
$object->array_options as $key => $value) {
515 $message .=
'<li>'.$langs->trans($key).
' : '.$value.
'</li>';
520 $message .=
'<p>'.$langs->trans(
'Message').
' : <br>'.
$object->message.
'</p>';
521 $message .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.
$object->track_id.
'">'.$langs->trans($see_ticket).
'</a></p>';
527 $old_MAIN_MAIL_AUTOCOPY_TO =
null;
530 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
533 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
534 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename,
'',
'', 0, -1);
535 if ($mailfile->error) {
538 $result = $mailfile->sendfile();
547 $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.
setErrorsFromObject(CommonObject $object)
setErrorsFromObject
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.
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.
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.