reformat trigger/interface_50_modTicket_TicketEmail.class.php to create methods for email composition and sending
This commit is contained in:
parent
e1e643efba
commit
5b1b862687
@ -133,19 +133,75 @@ class InterfaceTicketEmail extends DolibarrTriggers
|
|||||||
|
|
||||||
$langs->load('ticket');
|
$langs->load('ticket');
|
||||||
|
|
||||||
|
$subject_admin = 'TicketNewEmailSubjectAdmin';
|
||||||
|
$body_admin = 'TicketNewEmailBodyAdmin';
|
||||||
|
$subject_customer = 'TicketNewEmailSubjectCustomer';
|
||||||
|
$body_customer = 'TicketNewEmailBodyCustomer';
|
||||||
|
$see_ticket_customer = 'TicketNewEmailBodyInfosTrackUrlCustomer';
|
||||||
|
|
||||||
// Send email to notification email
|
// Send email to notification email
|
||||||
if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && empty($object->context['disableticketemail'])) {
|
if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && empty($object->context['disableticketemail'])) {
|
||||||
$sendto = empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) ? '' : $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
|
$sendto = empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) ? '' : $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
|
||||||
|
if ($sendto) {
|
||||||
|
$this->ComposeAndSendAdminMessage($sendto, $subject_admin, $body_admin, $object, $langs, $conf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send email to customer
|
||||||
|
if (empty($conf->global->TICKET_DISABLE_CUSTOMER_MAILS) && empty($object->context['disableticketemail']) && $object->notify_tiers_at_create) {
|
||||||
|
$sendto = '';
|
||||||
|
|
||||||
|
//if contact selected send to email's contact else send to email's thirdparty
|
||||||
|
|
||||||
|
$contactid = GETPOST('contactid', 'alpha');
|
||||||
|
|
||||||
|
if (!empty($contactid)) {
|
||||||
|
$contact = new Contact($this->db);
|
||||||
|
$res = $contact->fetch($contactid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($res > 0 && !empty($contact->email) && !empty($contact->statut)) {
|
||||||
|
$sendto = $contact->email;
|
||||||
|
} elseif (!empty($object->fk_soc)) {
|
||||||
|
$object->fetch_thirdparty();
|
||||||
|
$sendto = $object->thirdparty->email;
|
||||||
|
}
|
||||||
|
|
||||||
if ($sendto) {
|
if ($sendto) {
|
||||||
|
$this->ComposeAndSendCustomerMessage($sendto, $subject_customer, $body_customer, $see_ticket_customer, $object, $langs, $conf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$ok = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'TICKET_DELETE':
|
||||||
|
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'TICKET_MODIFY':
|
||||||
|
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'TICKET_CLOSE':
|
||||||
|
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function ComposeAndSendAdminMessage($sendto, $base_subject, $body, Ticket $object, Translate $langs, $conf)
|
||||||
|
{
|
||||||
// Init to avoid errors
|
// Init to avoid errors
|
||||||
$filepath = array();
|
$filepath = array();
|
||||||
$filename = array();
|
$filename = array();
|
||||||
$mimetype = array();
|
$mimetype = array();
|
||||||
|
|
||||||
/* Send email to admin */
|
/* Send email to admin */
|
||||||
$subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectAdmin');
|
$subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities($base_subject);
|
||||||
$message_admin = $langs->transnoentities('TicketNewEmailBodyAdmin', $object->track_id).'<br><br>';
|
$message_admin = $langs->transnoentities($body, $object->track_id).'<br><br>';
|
||||||
$message_admin .= '<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>';
|
$message_admin .= '<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>';
|
||||||
$message_admin .= '<li>'.$langs->trans('Type').' : '.$langs->getLabelFromKey($this->db, 'TicketTypeShort'.$object->type_code, 'c_ticket_type', 'code', 'label', $object->type_code).'</li>';
|
$message_admin .= '<li>'.$langs->trans('Type').' : '.$langs->getLabelFromKey($this->db, 'TicketTypeShort'.$object->type_code, 'c_ticket_type', 'code', 'label', $object->type_code).'</li>';
|
||||||
$message_admin .= '<li>'.$langs->trans('Category').' : '.$langs->getLabelFromKey($this->db, 'TicketCategoryShort'.$object->category_code, 'c_ticket_category', 'code', 'label', $object->category_code).'</li>';
|
$message_admin .= '<li>'.$langs->trans('Category').' : '.$langs->getLabelFromKey($this->db, 'TicketCategoryShort'.$object->category_code, 'c_ticket_category', 'code', 'label', $object->category_code).'</li>';
|
||||||
@ -175,7 +231,6 @@ class InterfaceTicketEmail extends DolibarrTriggers
|
|||||||
$message_admin .= '<p><a href="'.dol_buildpath('/ticket/card.php', 2).'?track_id='.$object->track_id.'">'.$langs->trans('SeeThisTicketIntomanagementInterface').'</a></p>';
|
$message_admin .= '<p><a href="'.dol_buildpath('/ticket/card.php', 2).'?track_id='.$object->track_id.'">'.$langs->trans('SeeThisTicketIntomanagementInterface').'</a></p>';
|
||||||
|
|
||||||
$from = $conf->global->MAIN_INFO_SOCIETE_NOM.'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.'>';
|
$from = $conf->global->MAIN_INFO_SOCIETE_NOM.'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.'>';
|
||||||
$replyto = $from;
|
|
||||||
|
|
||||||
$trackid = 'tic'.$object->id;
|
$trackid = 'tic'.$object->id;
|
||||||
|
|
||||||
@ -194,37 +249,16 @@ class InterfaceTicketEmail extends DolibarrTriggers
|
|||||||
$conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
|
$conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Send email to customer
|
private function ComposeAndSendCustomerMessage ($sendto, $base_subject, $body, $see_ticket, Ticket $object, Translate $langs, $conf)
|
||||||
|
{
|
||||||
if (empty($conf->global->TICKET_DISABLE_CUSTOMER_MAILS) && empty($object->context['disableticketemail']) && $object->notify_tiers_at_create) {
|
|
||||||
$sendto = '';
|
|
||||||
|
|
||||||
//if contact selected send to email's contact else send to email's thirdparty
|
|
||||||
|
|
||||||
$contactid = GETPOST('contactid', 'alpha');
|
|
||||||
|
|
||||||
if (!empty($contactid)) {
|
|
||||||
$contact = new Contact($this->db);
|
|
||||||
$res = $contact->fetch($contactid);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($res > 0 && !empty($contact->email) && !empty($contact->statut)) {
|
|
||||||
$sendto = $contact->email;
|
|
||||||
} elseif (!empty($object->fk_soc)) {
|
|
||||||
$object->fetch_thirdparty();
|
|
||||||
$sendto = $object->thirdparty->email;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($sendto) {
|
|
||||||
// Init to avoid errors
|
// Init to avoid errors
|
||||||
$filepath = array();
|
$filepath = array();
|
||||||
$filename = array();
|
$filename = array();
|
||||||
$mimetype = array();
|
$mimetype = array();
|
||||||
|
|
||||||
$subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNewEmailSubjectCustomer');
|
$subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities($base_subject);
|
||||||
$message_customer = $langs->transnoentities('TicketNewEmailBodyCustomer', $object->track_id).'<br><br>';
|
$message_customer = $langs->transnoentities($body, $object->track_id).'<br><br>';
|
||||||
$message_customer .= '<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>';
|
$message_customer .= '<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>';
|
||||||
$message_customer .= '<li>'.$langs->trans('Type').' : '.$langs->getLabelFromKey($this->db, 'TicketTypeShort'.$object->type_code, 'c_ticket_type', 'code', 'label', $object->type_code).'</li>';
|
$message_customer .= '<li>'.$langs->trans('Type').' : '.$langs->getLabelFromKey($this->db, 'TicketTypeShort'.$object->type_code, 'c_ticket_type', 'code', 'label', $object->type_code).'</li>';
|
||||||
$message_customer .= '<li>'.$langs->trans('Category').' : '.$langs->getLabelFromKey($this->db, 'TicketCategoryShort'.$object->category_code, 'c_ticket_category', 'code', 'label', $object->category_code).'</li>';
|
$message_customer .= '<li>'.$langs->trans('Category').' : '.$langs->getLabelFromKey($this->db, 'TicketCategoryShort'.$object->category_code, 'c_ticket_category', 'code', 'label', $object->category_code).'</li>';
|
||||||
@ -262,11 +296,10 @@ class InterfaceTicketEmail extends DolibarrTriggers
|
|||||||
}
|
}
|
||||||
$message_customer .= '<p>'.$langs->trans('Message').' : <br>'.$message.'</p>';
|
$message_customer .= '<p>'.$langs->trans('Message').' : <br>'.$message.'</p>';
|
||||||
$url_public_ticket = ($conf->global->TICKET_URL_PUBLIC_INTERFACE ? $conf->global->TICKET_URL_PUBLIC_INTERFACE.'/' : dol_buildpath('/public/ticket/view.php', 2)).'?track_id='.$object->track_id;
|
$url_public_ticket = ($conf->global->TICKET_URL_PUBLIC_INTERFACE ? $conf->global->TICKET_URL_PUBLIC_INTERFACE.'/' : dol_buildpath('/public/ticket/view.php', 2)).'?track_id='.$object->track_id;
|
||||||
$message_customer .= '<p>'.$langs->trans('TicketNewEmailBodyInfosTrackUrlCustomer').' : <a href="'.$url_public_ticket.'">'.$url_public_ticket.'</a></p>';
|
$message_customer .= '<p>'.$langs->trans($see_ticket).' : <a href="'.$url_public_ticket.'">'.$url_public_ticket.'</a></p>';
|
||||||
$message_customer .= '<p>'.$langs->trans('TicketEmailPleaseDoNotReplyToThisEmail').'</p>';
|
$message_customer .= '<p>'.$langs->trans('TicketEmailPleaseDoNotReplyToThisEmail').'</p>';
|
||||||
|
|
||||||
$from = (empty($conf->global->MAIN_INFO_SOCIETE_NOM) ? '' : $conf->global->MAIN_INFO_SOCIETE_NOM.' ').'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.'>';
|
$from = (empty($conf->global->MAIN_INFO_SOCIETE_NOM) ? '' : $conf->global->MAIN_INFO_SOCIETE_NOM.' ').'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.'>';
|
||||||
$replyto = $from;
|
|
||||||
|
|
||||||
$trackid = 'tic'.$object->id;
|
$trackid = 'tic'.$object->id;
|
||||||
|
|
||||||
@ -290,25 +323,5 @@ class InterfaceTicketEmail extends DolibarrTriggers
|
|||||||
$conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
|
$conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$ok = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'TICKET_DELETE':
|
|
||||||
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'TICKET_MODIFY':
|
|
||||||
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'TICKET_CLOSE':
|
|
||||||
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return $ok;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user