Able to parse email templates.... I hope
This commit is contained in:
parent
c3e70309bc
commit
36f8de957a
@ -46,7 +46,7 @@ class EmailTemplateParser {
|
|||||||
* @param $language string
|
* @param $language string
|
||||||
* @param $ticket Ticket
|
* @param $ticket Ticket
|
||||||
*/
|
*/
|
||||||
function getFormattedEmailForLanguage($templateName, $language, $ticket, $forStaff, $heskSettings) {
|
function getFormattedEmailForLanguage($templateName, $language, $ticket, $forStaff, $heskSettings, $modsForHeskSettings) {
|
||||||
global $hesklang;
|
global $hesklang;
|
||||||
|
|
||||||
$template = self::getFromFileSystem($templateName, $language, false);
|
$template = self::getFromFileSystem($templateName, $language, false);
|
||||||
@ -54,8 +54,10 @@ class EmailTemplateParser {
|
|||||||
$subject = ValidEmailTemplates::getValidEmailTemplates()[$templateName];
|
$subject = ValidEmailTemplates::getValidEmailTemplates()[$templateName];
|
||||||
|
|
||||||
$subject = $this->parseSubject($subject, $ticket, $language, $heskSettings);
|
$subject = $this->parseSubject($subject, $ticket, $language, $heskSettings);
|
||||||
$message = $this->parseMessage($template, $ticket, $language, $forStaff, $heskSettings);
|
$message = $this->parseMessage($template, $ticket, $language, $forStaff, $heskSettings, $modsForHeskSettings, false);
|
||||||
$htmlMessage = $this->parseMessage($htmlTemplate, $ticket, $language, $forStaff, $heskSettings);
|
$htmlMessage = $this->parseMessage($htmlTemplate, $ticket, $language, $forStaff, $heskSettings, $modsForHeskSettings, true);
|
||||||
|
|
||||||
|
return new ParsedEmailProperties($subject, $message, $htmlMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -144,7 +146,7 @@ class EmailTemplateParser {
|
|||||||
* @return string
|
* @return string
|
||||||
* @throws \Exception if common.inc.php isn't loaded
|
* @throws \Exception if common.inc.php isn't loaded
|
||||||
*/
|
*/
|
||||||
private function parseMessage($messageTemplate, $ticket, $language, $admin, $heskSettings) {
|
private function parseMessage($messageTemplate, $ticket, $language, $admin, $heskSettings, $modsForHeskSettings, $html) {
|
||||||
global $hesklang;
|
global $hesklang;
|
||||||
|
|
||||||
if (!function_exists('hesk_msgToPlain')) {
|
if (!function_exists('hesk_msgToPlain')) {
|
||||||
@ -205,6 +207,105 @@ class EmailTemplateParser {
|
|||||||
$msg = str_replace('%%UPDATED%%', $ticket->lastChanged, $msg);
|
$msg = str_replace('%%UPDATED%%', $ticket->lastChanged, $msg);
|
||||||
$msg = str_replace('%%ID%%', $ticket->id, $msg);
|
$msg = str_replace('%%ID%%', $ticket->id, $msg);
|
||||||
|
|
||||||
|
/* All custom fields */
|
||||||
|
for ($i=1; $i<=50; $i++) {
|
||||||
|
$k = 'custom'.$i;
|
||||||
|
|
||||||
|
if (isset($heskSettings['custom_fields'][$k])) {
|
||||||
|
$v = $heskSettings['custom_fields'][$k];
|
||||||
|
|
||||||
|
switch ($v['type']) {
|
||||||
|
case 'checkbox':
|
||||||
|
$ticket->customFields[$i] = str_replace("<br>","\n",$ticket->customFields[$i]);
|
||||||
|
break;
|
||||||
|
case 'date':
|
||||||
|
$ticket->customFields[$i] = hesk_custom_date_display_format($ticket->customFields[$i], $v['value']['date_format']);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$msg = str_replace('%%'.strtoupper($k).'%%',stripslashes($ticket->customFields[$i]),$msg);
|
||||||
|
} else {
|
||||||
|
$msg = str_replace('%%'.strtoupper($k).'%%','',$msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Is message tag in email template?
|
||||||
|
if (strpos($msg, '%%MESSAGE%%') !== false) {
|
||||||
|
// Replace message
|
||||||
|
if ($html) {
|
||||||
|
$htmlMessage = nl2br($ticket->message);
|
||||||
|
$msg = str_replace('%%MESSAGE%%', $htmlMessage, $msg);
|
||||||
|
} else {
|
||||||
|
$plainTextMessage = $ticket->message;
|
||||||
|
|
||||||
|
$messageHtml = $ticket->usesHtml;
|
||||||
|
|
||||||
|
if (count($ticket->replies) > 0) {
|
||||||
|
$lastReply = end($ticket->replies);
|
||||||
|
$messageHtml = $lastReply->usesHtml;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($messageHtml) {
|
||||||
|
if (!function_exists('convert_html_to_text')) {
|
||||||
|
require(__DIR__ . '/../../../inc/html2text/html2text.php');
|
||||||
|
}
|
||||||
|
$plainTextMessage = convert_html_to_text($plainTextMessage);
|
||||||
|
$plainTextMessage = fix_newlines($plainTextMessage);
|
||||||
|
}
|
||||||
|
$msg = str_replace('%%MESSAGE%%', $plainTextMessage, $msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add direct links to any attachments at the bottom of the email message
|
||||||
|
if ($heskSettings['attachments']['use'] && isset($ticket->attachments) && count($ticket->attachments) > 0) {
|
||||||
|
if (!$modsForHeskSettings['attachments']) {
|
||||||
|
if ($html) {
|
||||||
|
$msg .= "<br><br><br>" . $hesklang['fatt'];
|
||||||
|
} else {
|
||||||
|
$msg .= "\n\n\n" . $hesklang['fatt'];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($ticket->attachments as $attachment) {
|
||||||
|
if ($html) {
|
||||||
|
$msg .= "<br><br>{$attachment->fileName}<br>";
|
||||||
|
} else {
|
||||||
|
$msg .= "\n\n{$attachment->fileName}\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$msg .= "{$heskSettings['hesk_url']}/download_attachment.php?att_id={$attachment->id}&track={$ticket->trackingId}{$heskSettings['e_param']}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// For customer notifications: if we allow email piping/pop 3 fetching and
|
||||||
|
// stripping quoted replies add an "reply above this line" tag
|
||||||
|
if (!$admin && ($heskSettings['email_piping'] || $heskSettings['pop3']) && $heskSettings['strip_quoted']) {
|
||||||
|
$msg = $hesklang['EMAIL_HR'] . "\n\n" . $msg;
|
||||||
|
}
|
||||||
|
} elseif (strpos($msg, '%%MESSAGE_NO_ATTACHMENTS%%') !== false) {
|
||||||
|
if ($html) {
|
||||||
|
$htmlMessage = nl2br($ticket->message);
|
||||||
|
$msg = str_replace('%%MESSAGE_NO_ATTACHMENTS%%', $htmlMessage, $msg);
|
||||||
|
} else {
|
||||||
|
$plainTextMessage = $ticket->message;
|
||||||
|
|
||||||
|
$messageHtml = $ticket->usesHtml;
|
||||||
|
|
||||||
|
if (count($ticket->replies) > 0) {
|
||||||
|
$lastReply = end($ticket->replies);
|
||||||
|
$messageHtml = $lastReply->usesHtml;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($messageHtml) {
|
||||||
|
if (!function_exists('convert_html_to_text')) {
|
||||||
|
require(__DIR__ . '/../../../inc/html2text/html2text.php');
|
||||||
|
}
|
||||||
|
$plainTextMessage = convert_html_to_text($plainTextMessage);
|
||||||
|
$plainTextMessage = fix_newlines($plainTextMessage);
|
||||||
|
}
|
||||||
|
$msg = str_replace('%%MESSAGE_NO_ATTACHMENTS%%', $plainTextMessage, $msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $msg;
|
return $msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
33
api/BusinessLogic/Emails/ParsedEmailProperties.php
Normal file
33
api/BusinessLogic/Emails/ParsedEmailProperties.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: mkoch
|
||||||
|
* Date: 2/28/2017
|
||||||
|
* Time: 9:36 PM
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BusinessLogic\Emails;
|
||||||
|
|
||||||
|
|
||||||
|
class ParsedEmailProperties {
|
||||||
|
function __construct($subject, $message, $htmlMessage) {
|
||||||
|
$this->subject = $subject;
|
||||||
|
$this->message = $message;
|
||||||
|
$this->htmlMessage = $htmlMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $subject string
|
||||||
|
*/
|
||||||
|
public $subject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $message string
|
||||||
|
*/
|
||||||
|
public $message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $htmlMessage string
|
||||||
|
*/
|
||||||
|
public $htmlMessage;
|
||||||
|
}
|
62
api/BusinessLogic/Tickets/Reply.php
Normal file
62
api/BusinessLogic/Tickets/Reply.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: mkoch
|
||||||
|
* Date: 2/28/2017
|
||||||
|
* Time: 9:17 PM
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace BusinessLogic\Tickets;
|
||||||
|
|
||||||
|
|
||||||
|
class Reply {
|
||||||
|
/**
|
||||||
|
* @var $id int
|
||||||
|
*/
|
||||||
|
public $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $ticketId int
|
||||||
|
*/
|
||||||
|
public $ticketId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $replierName string
|
||||||
|
*/
|
||||||
|
public $replierName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $message string
|
||||||
|
*/
|
||||||
|
public $message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $dateCreated string
|
||||||
|
*/
|
||||||
|
public $dateCreated;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $attachments Attachment[]
|
||||||
|
*/
|
||||||
|
public $attachments;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $staffId int|null
|
||||||
|
*/
|
||||||
|
public $staffId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $rating int|null
|
||||||
|
*/
|
||||||
|
public $rating;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $isRead bool
|
||||||
|
*/
|
||||||
|
public $isRead;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $usesHtml bool
|
||||||
|
*/
|
||||||
|
public $usesHtml;
|
||||||
|
}
|
@ -4,7 +4,7 @@ namespace BusinessLogic\Tickets;
|
|||||||
|
|
||||||
|
|
||||||
class Ticket {
|
class Ticket {
|
||||||
static function fromDatabaseRow($row, $linkedTicketsRs, $heskSettings) {
|
static function fromDatabaseRow($row, $linkedTicketsRs, $repliesRs, $heskSettings) {
|
||||||
$ticket = new Ticket();
|
$ticket = new Ticket();
|
||||||
$ticket->id = intval($row['id']);
|
$ticket->id = intval($row['id']);
|
||||||
$ticket->trackingId = $row['trackid'];
|
$ticket->trackingId = $row['trackid'];
|
||||||
@ -93,6 +93,40 @@ class Ticket {
|
|||||||
$ticket->dueDate = $row['due_date'];
|
$ticket->dueDate = $row['due_date'];
|
||||||
$ticket->dueDateOverdueEmailSent = $row['overdue_email_sent'] !== null && intval($row['overdue_email_sent']) === 1;
|
$ticket->dueDateOverdueEmailSent = $row['overdue_email_sent'] !== null && intval($row['overdue_email_sent']) === 1;
|
||||||
|
|
||||||
|
$replies = array();
|
||||||
|
while ($replyRow = hesk_dbFetchAssoc($repliesRs)) {
|
||||||
|
$reply = new Reply();
|
||||||
|
$reply->id = $replyRow['id'];
|
||||||
|
$reply->ticketId = $replyRow['replyto'];
|
||||||
|
$reply->replierName = $replyRow['name'];
|
||||||
|
$reply->message = $replyRow['message'];
|
||||||
|
$reply->dateCreated = $replyRow['dt'];
|
||||||
|
|
||||||
|
if (trim($replyRow['attachments']) !== '') {
|
||||||
|
$attachments = explode(',', $replyRow['attachments']);
|
||||||
|
$attachmentArray = array();
|
||||||
|
foreach ($attachments as $attachment) {
|
||||||
|
$attachmentRow = explode('#', $attachment);
|
||||||
|
$attachmentModel = new Attachment();
|
||||||
|
|
||||||
|
$attachmentModel->id = $attachmentRow[0];
|
||||||
|
$attachmentModel->fileName = $attachmentRow[1];
|
||||||
|
$attachmentModel->savedName = $attachmentRow[2];
|
||||||
|
|
||||||
|
$attachmentArray[] = $attachmentModel;
|
||||||
|
}
|
||||||
|
$reply->attachments = $attachmentArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
$reply->staffId = $replyRow['staffid'] > 0 ? $replyRow['staffid'] : null;
|
||||||
|
$reply->rating = $replyRow['rating'];
|
||||||
|
$reply->isRead = $replyRow['read'];
|
||||||
|
$reply->usesHtml = $replyRow['html'];
|
||||||
|
|
||||||
|
$replies[] = $reply;
|
||||||
|
}
|
||||||
|
$ticket->replies = $replies;
|
||||||
|
|
||||||
return $ticket;
|
return $ticket;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,4 +334,9 @@ class Ticket {
|
|||||||
* @var bool|null
|
* @var bool|null
|
||||||
*/
|
*/
|
||||||
public $dueDateOverdueEmailSent;
|
public $dueDateOverdueEmailSent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Reply[]
|
||||||
|
*/
|
||||||
|
public $replies;
|
||||||
}
|
}
|
@ -25,7 +25,9 @@ class TicketGateway extends CommonDao {
|
|||||||
$row = hesk_dbFetchAssoc($rs);
|
$row = hesk_dbFetchAssoc($rs);
|
||||||
$linkedTicketsRs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` WHERE `parent` = " . intval($id));
|
$linkedTicketsRs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` WHERE `parent` = " . intval($id));
|
||||||
|
|
||||||
$ticket = Ticket::fromDatabaseRow($row, $linkedTicketsRs, $heskSettings);
|
$repliesRs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "replies` WHERE `replyto` = " . intval($id) . " ORDER BY `id` ASC");
|
||||||
|
|
||||||
|
$ticket = Ticket::fromDatabaseRow($row, $linkedTicketsRs, $repliesRs, $heskSettings);
|
||||||
|
|
||||||
$this->close();
|
$this->close();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user