- Added comprehensive AI Assistant system (aiassist/ directory): * Vector search and embedding capabilities * Typebot proxy integration * Elastic search functionality * Message classification and chat history * MCP proxy for external integrations - Implemented Court Status API (GetCourtStatus.php): * Real-time court document status checking * Integration with external court systems * Comprehensive error handling and logging - Enhanced S3 integration: * Improved file backup system with metadata * Batch processing capabilities * Enhanced error logging and recovery * Copy operations with URL fixing - Added Telegram contact creation API - Improved error logging across all modules - Enhanced callback system for AI responses - Extensive backup file storage with timestamps - Updated documentation and README files - File storage improvements: * Thousands of backup files with proper metadata * Fix operations for broken file references * Project-specific backup and recovery systems * Comprehensive file integrity checking Total: 26,461+ files added/modified including AWS SDK, vendor dependencies, and extensive backup system.
231 lines
10 KiB
PHP
231 lines
10 KiB
PHP
<?php
|
|
/* * *******************************************************************************
|
|
* The content of this file is subject to the ITS4YouEmailMarketing license.
|
|
* ("License"); You may not use this file except in compliance with the License
|
|
* The Initial Developer of the Original Code is IT-Solutions4You s.r.o.
|
|
* Portions created by IT-Solutions4You s.r.o. are Copyright(C) IT-Solutions4You s.r.o.
|
|
* All Rights Reserved.
|
|
* ****************************************************************************** */
|
|
|
|
class ITS4YouEmailMarketing_EmailsV7_Model extends Emails_Record_Model
|
|
{
|
|
|
|
public static function getCleanInstance($moduleName)
|
|
{
|
|
$focus = CRMEntity::getInstance($moduleName);
|
|
$instance = new self();
|
|
|
|
return $instance->setData($focus->column_fields)->setModule($moduleName)->setEntity($focus);
|
|
}
|
|
|
|
public function send($addToQueue = false)
|
|
{
|
|
$userId = $this->get('assigned_user_id');
|
|
$currentUserModel = Users_Record_Model::getInstanceById($userId, 'Users');
|
|
$rootDirectory = vglobal('root_directory');
|
|
|
|
$mailer = Emails_Mailer_Model::getInstance();
|
|
$mailer->IsHTML(true);
|
|
|
|
$logo = '';
|
|
$emailMarketingId = $this->get('emailmarketingid');
|
|
$fromEmail = $this->get('from_email');
|
|
$replyTo = $this->get('reply_to');
|
|
$userName = $this->get('from_name');
|
|
$toEmailInfo = $this->get('toemailinfo');
|
|
$attachments = $this->getAttachmentDetails();
|
|
$status = false;
|
|
|
|
// Merge Users module merge tags based on current user.
|
|
$mergedDescription = getMergedDescription($this->get('description'), $currentUserModel->getId(), 'Users');
|
|
$mergedSubject = getMergedDescription($this->get('subject'), $currentUserModel->getId(), 'Users');
|
|
foreach ($toEmailInfo as $id => $emails) {
|
|
$inReplyToMessageId = '';
|
|
$generatedMessageId = '';
|
|
$mailer->reinitialize();
|
|
$mailer->ConfigSenderInfo($fromEmail, $userName, $replyTo);
|
|
$old_mod_strings = vglobal('mod_strings');
|
|
$description = $this->get('description');
|
|
$subject = $this->get('subject');
|
|
$parentModule = $this->getEntityType($id);
|
|
if ($parentModule) {
|
|
$currentLanguage = Vtiger_Language_Handler::getLanguage();
|
|
$moduleLanguageStrings = Vtiger_Language_Handler::getModuleStringsFromFile($currentLanguage, $parentModule);
|
|
vglobal('mod_strings', $moduleLanguageStrings['languageStrings']);
|
|
$mergedDescriptionWithHyperLinkConversion = $this->replaceBrowserMergeTagWithValue($mergedDescription, $parentModule, $id);
|
|
if ($parentModule != 'Users') {
|
|
//Retrieve MessageID from Mailroom table only if module is not users
|
|
$inReplyToMessageId = $mailer->retrieveMessageIdFromMailroom($id);
|
|
|
|
$generatedMessageId = $mailer->generateMessageID();
|
|
//If there is no reference id exist in crm.
|
|
//Generate messageId for sending email and attach to mailer header
|
|
if (empty($inReplyToMessageId)) {
|
|
$inReplyToMessageId = $generatedMessageId;
|
|
}
|
|
// Apply merge for non-Users module merge tags.
|
|
$description = getMergedDescription($mergedDescriptionWithHyperLinkConversion, $id, $parentModule);
|
|
$subject = getMergedDescription($mergedSubject, $id, $parentModule);
|
|
} else {
|
|
// Re-merge the description for user tags based on actual user.
|
|
$description = getMergedDescription($mergedDescriptionWithHyperLinkConversion, $id, 'Users');
|
|
$subject = getMergedDescription($mergedSubject, $id, 'Users');
|
|
vglobal('mod_strings', $old_mod_strings);
|
|
}
|
|
}
|
|
|
|
//If variable is not empty then add custom header
|
|
if (!empty($inReplyToMessageId)) {
|
|
$mailer->AddCustomHeader("In-Reply-To", $inReplyToMessageId);
|
|
}
|
|
|
|
if (!empty($generatedMessageId)) {
|
|
$mailer->MessageID = $generatedMessageId;
|
|
}
|
|
|
|
if (strpos($description, '$logo$')) {
|
|
$description = str_replace('$logo$', "<img src='cid:companyLogo' />", $description);
|
|
$logo = true;
|
|
}
|
|
|
|
foreach ($emails as $email) {
|
|
$mailer->Body = $description;
|
|
if ($parentModule) {
|
|
$mailer->Body = $this->convertUrlsToTrackUrls($mailer->Body, $emailMarketingId);
|
|
$mailer->Body .= $this->getTrackImageDetails($emailMarketingId);
|
|
}
|
|
if ($this->get('signature') == 'Yes') {
|
|
$mailer->Signature = $currentUserModel->get('signature');
|
|
if ($mailer->Signature != '') {
|
|
$mailer->Body .= '<br><br>' . decode_html($mailer->Signature);
|
|
}
|
|
}
|
|
//Checking whether user requested to add signature or not
|
|
$mailer->Subject = decode_html(strip_tags($subject));
|
|
|
|
$plainBody = decode_emptyspace_html($description);
|
|
$plainBody = preg_replace(array("/<p>/i", "/<br>/i", "/<br \/>/i"), array("\n", "\n", "\n"), $plainBody);
|
|
$plainBody = utf8_encode(strip_tags($plainBody));
|
|
$plainBody = Emails_Mailer_Model::convertToAscii($plainBody);
|
|
$plainBody = $this->convertUrlsToTrackUrls($plainBody, $id, 'plain');
|
|
$mailer->AltBody = $plainBody;
|
|
$mailer->AddAddress($email);
|
|
|
|
//Adding attachments to mail
|
|
if (is_array($attachments)) {
|
|
foreach ($attachments as $attachment) {
|
|
$fileNameWithPath = $rootDirectory . $attachment['path'] . $attachment['fileid'] . "_" . $attachment['attachment'];
|
|
if (is_file($fileNameWithPath)) {
|
|
$mailer->AddAttachment($fileNameWithPath, $attachment['attachment']);
|
|
}
|
|
}
|
|
}
|
|
if ($logo) {
|
|
$companyDetails = Vtiger_CompanyDetails_Model::getInstanceById();
|
|
$companyLogoDetails = $companyDetails->getLogo();
|
|
//While sending email template and which has '$logo$' then it should replace with company logo
|
|
$mailer->AddEmbeddedImage($companyLogoDetails->get('imagepath'), 'companyLogo', 'attachment', 'base64', 'image/jpg');
|
|
}
|
|
|
|
$ccs = array_filter(explode(',', $this->get('ccmail')));
|
|
$bccs = array_filter(explode(',', $this->get('bccmail')));
|
|
|
|
if (!empty($ccs)) {
|
|
foreach ($ccs as $cc) {
|
|
$mailer->AddCC($cc);
|
|
}
|
|
}
|
|
if (!empty($bccs)) {
|
|
foreach ($bccs as $bcc) {
|
|
$mailer->AddBCC($bcc);
|
|
}
|
|
}
|
|
}
|
|
// to convert external css to inline css
|
|
$mailer->Body = Emails_Mailer_Model::convertCssToInline($mailer->Body);
|
|
//To convert image url to valid
|
|
$mailer->Body = $mailer->makeImageURLValid($mailer->Body);
|
|
$mailer->Body = ITS4YouEmailMarketing_Module_Model::convertCustomVariables($mailer->Body, $this->get('customer_id'));
|
|
$this->saveDescription($mailer->Body);
|
|
$images = (array) $this->get('images');
|
|
|
|
if (count($images) > 0) {
|
|
foreach ($images as $cid => $cdata) {
|
|
$mailer->AddEmbeddedImage($cdata["path"], $cid, $cdata["name"]);
|
|
}
|
|
}
|
|
|
|
$status = $mailer->Send(true);
|
|
|
|
|
|
if (!$status) {
|
|
$status = $mailer->getError();
|
|
|
|
} else {
|
|
//If mail sending is success store message Id for given crmId
|
|
if ($generatedMessageId && $id) {
|
|
$mailer->updateMessageIdByCrmId($generatedMessageId, $id);
|
|
}
|
|
|
|
$mailString = $mailer->getMailString();
|
|
$mailBoxModel = MailManager_Mailbox_Model::activeInstance();
|
|
$folderName = $mailBoxModel->folder();
|
|
if (!empty($folderName) && !empty($mailString)) {
|
|
$connector = MailManager_Connector_Connector::connectorWithModel($mailBoxModel, '');
|
|
$message = str_replace("\n", "\r\n", $mailString);
|
|
if (function_exists('mb_convert_encoding')) {
|
|
$folderName = mb_convert_encoding($folderName, "UTF7-IMAP", "UTF-8");
|
|
}
|
|
imap_append($connector->mBox, $connector->mBoxUrl . $folderName, $message, "\\Seen");
|
|
}
|
|
}
|
|
}
|
|
|
|
return $status;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function isEmailTrackEnabled()
|
|
{
|
|
$emailTracking = vglobal('email_tracking');
|
|
|
|
if ('No' === $emailTracking) {
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param $content
|
|
* @param $crmid
|
|
* @param string $type
|
|
* @return string
|
|
*/
|
|
public function convertUrlsToTrackUrls($content, $crmid, $type = 'html')
|
|
{
|
|
if ($this->isEmailTrackEnabled()) {
|
|
$extractedUrls = Vtiger_Functions::getUrlsFromHtml($content);
|
|
|
|
foreach ($extractedUrls as $sourceUrl => $value) {
|
|
$trackingUrl = $this->getTrackUrlForClicks($crmid, $sourceUrl);
|
|
$content = $this->replaceLinkWithShortUrl($content, $trackingUrl, $sourceUrl, $type);
|
|
}
|
|
}
|
|
|
|
return $content;
|
|
}
|
|
|
|
public function saveDescription($description)
|
|
{
|
|
$emailmarketingid = $this->get('emailmarketingid');
|
|
$emailsid = $this->getId();
|
|
|
|
$adb = PearDatabase::getInstance();
|
|
$adb->pquery('INSERT INTO its4you_emailmarketing_emails(emailmarketingid, emailsid, description) VALUES (?,?,?)', array($emailmarketingid, $emailsid, $description));
|
|
|
|
return true;
|
|
}
|
|
} |