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);
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;
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.
__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.
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.