- 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.
370 lines
14 KiB
PHP
370 lines
14 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.
|
|
* ****************************************************************************** */
|
|
|
|
require_once('data/CRMEntity.php');
|
|
require_once('data/Tracker.php');
|
|
|
|
class ITS4YouEmailMarketing extends CRMEntity
|
|
{
|
|
|
|
public $log;
|
|
public $db;
|
|
|
|
public $relModuleNames = array();
|
|
public $customLinks = array();
|
|
|
|
public $moduleName = 'ITS4YouEmailMarketing';
|
|
public $parentName = 'Marketing';
|
|
public $table_name = 'its4you_emailmarketing';
|
|
public $table_index = 'its4youemailmarketingid';
|
|
public $entity_table = "vtiger_crmentity";
|
|
|
|
public $customFieldTable = array(
|
|
'its4you_emailmarketingcf',
|
|
'its4youemailmarketingid',
|
|
);
|
|
|
|
public $tab_name = array(
|
|
'vtiger_crmentity',
|
|
'its4you_emailmarketing',
|
|
'its4you_emailmarketingcf',
|
|
);
|
|
|
|
public $tab_name_index = array(
|
|
'vtiger_crmentity' => 'crmid',
|
|
'its4you_emailmarketing' => 'its4youemailmarketingid',
|
|
'its4you_emailmarketingcf' => 'its4youemailmarketingid',
|
|
);
|
|
|
|
/**
|
|
* @var array [<fieldlabel> => array(<tablename> => <columnname>)]
|
|
*/
|
|
public $list_fields = array(
|
|
'Assigned To' => array('crmentity' => 'smownerid'),
|
|
'Description' => array('crmentity' => 'description'),
|
|
);
|
|
|
|
/**
|
|
* @var array [<fieldlabel> => <fieldname>]
|
|
*/
|
|
public $list_fields_name = array(
|
|
'Assigned To' => 'assigned_user_id',
|
|
'Description' => 'description',
|
|
);
|
|
|
|
/**
|
|
* @var array
|
|
* [module, related module, relate label, related actions, related function]
|
|
* $moduleInstance->setRelatedList($relatedListModule, $relatedLabel, $relatedActions, $relatedFunction);
|
|
*/
|
|
public $registerRelatedLists = [
|
|
['ITS4YouEmailMarketing', 'Documents', 'Documents', 'ADD,SELECT', 'get_attachments'],
|
|
['ITS4YouEmailMarketing', 'ITS4YouEmails', 'ITS4YouEmails', 'SELECT', 'get_related_list'],
|
|
['ITS4YouEmailMarketing', 'Emails', 'Emails', '', 'get_emails'],
|
|
['ITS4YouEmailMarketing', 'ITS4YouEmailMarketing', 'Opened Recipients', '', 'get_related_list'],
|
|
['ITS4YouEmailMarketing', 'ITS4YouEmailMarketing', 'Clicked Links', '', 'get_related_list'],
|
|
];
|
|
|
|
/**
|
|
* [module, type, label, url, icon, sequence, handlerInfo]
|
|
* @return array
|
|
*/
|
|
public $registerCustomLinks = array(
|
|
['ITS4YouEmailMarketing', 'DETAILVIEW', 'Duplicate with All Recipients', 'index.php?module=ITS4YouEmailMarketing&view=Edit&record=$RECORD$&isDuplicate=true&duplicate=All'],
|
|
['ITS4YouEmailMarketing', 'DETAILVIEW', 'Duplicate with Not Opened Recipients', 'index.php?module=ITS4YouEmailMarketing&view=Edit&record=$RECORD$&isDuplicate=true&duplicate=NotOpened'],
|
|
['ITS4YouEmailMarketing', 'DETAILVIEW', 'Duplicate with Opened Recipients', 'index.php?module=ITS4YouEmailMarketing&view=Edit&record=$RECORD$&isDuplicate=true&duplicate=OpenRecipients'],
|
|
);
|
|
public $module;
|
|
public $layout;
|
|
public $column_fields;
|
|
/**
|
|
* name, handler, frequency, module, sequence, description
|
|
*/
|
|
public $registerCron = array(
|
|
array('ITS4YouEmailMarketing', 'modules/ITS4YouEmailMarketing/cron/SendEmails.service', 900, 'ITS4YouEmailMarketing', 0, 'Recommended frequency for EmailMarketing is 15 mins'),
|
|
);
|
|
|
|
public function __construct()
|
|
{
|
|
global $log;
|
|
$this->column_fields = getColumnFields(get_class($this));
|
|
$this->db = PearDatabase::getInstance();
|
|
$this->log = $log;
|
|
}
|
|
|
|
/**
|
|
* @param bool $register
|
|
*/
|
|
public function updateCustomLinks($register = true)
|
|
{
|
|
foreach ($this->registerCustomLinks as $customLink) {
|
|
$module = Vtiger_Module::getInstance($customLink[0]);
|
|
$type = $customLink[1];
|
|
$label = $customLink[2];
|
|
$url = str_replace('$LAYOUT$', Vtiger_Viewer::getDefaultLayoutName(), $customLink[3]);
|
|
|
|
if ($module) {
|
|
$module->deleteLink($type, $label);
|
|
|
|
if ($register) {
|
|
$module->addLink($type, $label, $url, $customLink[4], $customLink[5], $customLink[6]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function save_module($module)
|
|
{
|
|
if(!empty($_REQUEST['duplicateMode']) && !empty($_REQUEST['duplicateRecord'])) {
|
|
$recordId = $this->id;
|
|
$duplicateMode = $_REQUEST['duplicateMode'];
|
|
$duplicateRecordId = intval($_REQUEST['duplicateRecord']);
|
|
|
|
ITS4YouEmailMarketing_Record_Model::copyConfig($duplicateRecordId, $recordId);
|
|
|
|
if ('Default' !== $duplicateMode) {
|
|
ITS4YouEmailMarketing_Record_Model::copyRecipients($duplicateMode, $duplicateRecordId, $recordId);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param $moduleName
|
|
* @param $eventType
|
|
*/
|
|
public function vtlib_handler($moduleName, $eventType)
|
|
{
|
|
|
|
require_once 'include/utils/utils.php';
|
|
require_once 'vtlib/Vtiger/Module.php';
|
|
require_once 'vtlib/Vtiger/Cron.php';
|
|
include_once 'modules/ModComments/ModComments.php';
|
|
include_once 'modules/ModTracker/ModTracker.php';
|
|
|
|
$this->module = Vtiger_Module::getInstance($moduleName);
|
|
$this->layout = Vtiger_Viewer::getDefaultLayoutName();
|
|
|
|
$this->retrieveRelatedList();
|
|
|
|
switch ($eventType) {
|
|
case 'module.postinstall':
|
|
case 'module.enabled':
|
|
$this->updateCron();
|
|
case 'module.postupdate':
|
|
$this->addCustomLinks();
|
|
break;
|
|
case 'module.preuninstall':
|
|
case 'module.disabled':
|
|
$this->updateCron(false);
|
|
case 'module.preupdate':
|
|
$this->deleteCustomLinks();
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function retrieveRelatedList()
|
|
{
|
|
$modules = getEmailRelatedModules();
|
|
|
|
foreach ($modules as $module) {
|
|
array_push($this->registerRelatedLists, array('ITS4YouEmailMarketing', $module, $module, 'ADD,SELECT'));
|
|
}
|
|
}
|
|
|
|
public function updateCron($register = true)
|
|
{
|
|
foreach ($this->registerCron as $cronInfo) {
|
|
list($name, $handler, $frequency, $module, $sequence, $description) = $cronInfo;
|
|
|
|
Vtiger_Cron::deregister($name);
|
|
|
|
if ($register) {
|
|
Vtiger_Cron::register($name, $handler, $frequency, $module, 1, $sequence, $description);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function addCustomLinks()
|
|
{
|
|
$this->installUnsubscribe();
|
|
|
|
$this->updateTables();
|
|
$this->updateNumbering();
|
|
$this->updateRelatedList();
|
|
$this->updateCustomLinks();
|
|
|
|
if (method_exists('Settings_MenuEditor_Module_Model', 'addModuleToApp')) {
|
|
Settings_MenuEditor_Module_Model::addModuleToApp($this->moduleName, $this->parentName);
|
|
}
|
|
|
|
ModComments::addWidgetTo([$this->moduleName]);
|
|
ModTracker::enableTrackingForModule(getTabid($this->moduleName));
|
|
}
|
|
|
|
public function installUnsubscribe()
|
|
{
|
|
$file = 'modules/ITS4YouEmailMarketing/resources/ITS4YouUnsubscribe.php';
|
|
$newFile = 'ITS4YouUnsubscribe.php';
|
|
|
|
if (!copy($file, $newFile)) {
|
|
$this->log->debug('You should copy ITS4YouUnsubscribe.php to root');
|
|
}
|
|
}
|
|
|
|
public function updateTables()
|
|
{
|
|
$createTable = 'CREATE TABLE IF NOT EXISTS vtiger_%s (
|
|
%sid int(11) NOT NULL AUTO_INCREMENT,
|
|
%s varchar(200) NOT NULL,
|
|
presence int(1) NOT NULL DEFAULT 1,
|
|
picklist_valueid int(11) NOT NULL DEFAULT 0,
|
|
sortorderid int(11) DEFAULT 0,
|
|
color varchar(10) DEFAULT NULL,
|
|
PRIMARY KEY (`%sid`)
|
|
)';
|
|
$picklistTables = array('emailmarketingsmtp', 'emailmarketingmodule', 'templatelanguage', 'template', 'templaterelation');
|
|
|
|
foreach ($picklistTables as $picklistTable) {
|
|
$this->db->query(sprintf($createTable, $picklistTable, $picklistTable, $picklistTable, $picklistTable));
|
|
}
|
|
|
|
$fields = [
|
|
'errormessage' => 'ALTER TABLE its4you_emailmarketing ADD COLUMN errormessage text DEFAULT NULL',
|
|
'templatesource' => 'ALTER TABLE its4you_emailmarketing ADD COLUMN templatesource varchar(100) DEFAULT NULL',
|
|
'templatelanguage' => 'ALTER TABLE its4you_emailmarketing ADD COLUMN templatelanguage varchar(100) DEFAULT NULL',
|
|
'email_sending_pause' => 'ALTER TABLE its4you_emailmarketing ADD COLUMN email_sending_pause int(11) DEFAULT NULL',
|
|
];
|
|
|
|
foreach ($fields as $field => $sql) {
|
|
preg_match('/ALTER\ TABLE\ ([a-z0-9\_]+)\ ADD/', $sql, $matches);
|
|
|
|
if ($matches[1] && !columnExists($field, $matches[1])) {
|
|
$this->db->pquery($sql);
|
|
}
|
|
}
|
|
|
|
$this->db->pquery(
|
|
'UPDATE vtiger_field SET typeofdata=?, uitype=? WHERE tablename=? AND fieldname=?',
|
|
['V~M', 16, 'its4you_emailmarketing', 'emailmarketingmodule']
|
|
);
|
|
}
|
|
|
|
public function updateNumbering()
|
|
{
|
|
$this->setModuleSeqNumber('configure', $this->moduleName, 'EM', 1);
|
|
$this->updateMissingSeqNumber($this->moduleName);
|
|
}
|
|
|
|
/**
|
|
* @param bool $register
|
|
*/
|
|
public function updateRelatedList($register = true)
|
|
{
|
|
foreach ($this->registerRelatedLists as $relatedList) {
|
|
$module = Vtiger_Module::getInstance($relatedList[0]);
|
|
$relatedModule = Vtiger_Module::getInstance($relatedList[1]);
|
|
|
|
if ($module && $relatedModule) {
|
|
$relatedLabel = isset($relatedList[2]) ? $relatedList[2] : $relatedModule->name;
|
|
$relatedActions = isset($relatedList[3]) ? $relatedList[3] : '';
|
|
$relatedFunction = isset($relatedList[4]) ? $relatedList[4] : 'get_related_list';
|
|
$field = isset($relatedList[5]) ? Vtiger_Field_Model::getInstance($relatedList[5], $relatedModule) : '';
|
|
$fieldId = $field ? $field->getId() : '';
|
|
|
|
$module->unsetRelatedList($relatedModule, $relatedLabel);
|
|
$module->unsetRelatedList($relatedModule, $relatedLabel, $relatedFunction);
|
|
|
|
if ($register) {
|
|
$module->setRelatedList($relatedModule, $relatedLabel, $relatedActions, $relatedFunction, $fieldId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function deleteCustomLinks()
|
|
{
|
|
$this->updateRelatedList(false);
|
|
$this->updateCustomLinks(false);
|
|
|
|
ModComments::removeWidgetFrom([$this->moduleName]);
|
|
ModTracker::disableTrackingForModule(getTabid($this->moduleName));
|
|
}
|
|
|
|
public function getTableColumns($table)
|
|
{
|
|
$resultColumns = $this->db->pquery('SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ?', array($table));
|
|
$columns = array();
|
|
while ($column = $this->db->fetchByAssoc($resultColumns)) {
|
|
$columns[] = $column['COLUMN_NAME'];
|
|
}
|
|
|
|
return $columns;
|
|
}
|
|
|
|
/** Returns a list of the associated emails
|
|
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
|
|
* All Rights Reserved..
|
|
* Contributor(s): ______________________________________..
|
|
*/
|
|
public function get_emails($id, $cur_tab_id, $rel_tab_id, $actions = false)
|
|
{
|
|
|
|
global $log, $singlepane_view, $currentModule, $current_user;
|
|
$log->debug("Entering get_emails(" . $id . ") method ...");
|
|
$this_module = $currentModule;
|
|
|
|
$related_module = vtlib_getModuleNameById($rel_tab_id);
|
|
require_once("modules/$related_module/$related_module.php");
|
|
$other = new $related_module();
|
|
vtlib_setup_modulevars($related_module, $other);
|
|
|
|
if ($singlepane_view == 'true') {
|
|
$returnset = '&return_module=' . $this_module . '&return_action=DetailView&return_id=' . $id;
|
|
} else {
|
|
$returnset = '&return_module=' . $this_module . '&return_action=CallRelatedList&return_id=' . $id;
|
|
}
|
|
|
|
$button = '';
|
|
$button .= '<input type="hidden" name="email_directing_module"><input type="hidden" name="record">';
|
|
$query = sprintf('SELECT DISTINCT vtiger_activity.activityid,
|
|
vtiger_activity.subject,
|
|
vtiger_activity.activitytype,
|
|
vtiger_crmentity.modifiedtime,
|
|
vtiger_crmentity.crmid,
|
|
vtiger_crmentity.smownerid,
|
|
vtiger_activity.date_start,
|
|
vtiger_activity.time_start,
|
|
vtiger_seactivityrel.crmid as parent_id,
|
|
vtiger_email_track.access_count,
|
|
CONCAT(vtiger_users.first_name," ",vtiger_users.last_name) as user_name
|
|
FROM vtiger_crmentityrel
|
|
LEFT JOIN vtiger_seactivityrel ON vtiger_seactivityrel.activityid = vtiger_crmentityrel.relcrmid
|
|
LEFT JOIN vtiger_activity ON vtiger_activity.activityid = vtiger_seactivityrel.activityid
|
|
LEFT JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_activity.activityid
|
|
LEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid
|
|
LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid
|
|
LEFT JOIN vtiger_email_track ON vtiger_email_track.crmid = vtiger_crmentityrel.crmid AND vtiger_email_track.mailid = vtiger_activity.activityid
|
|
WHERE vtiger_crmentityrel.crmid = "%s"
|
|
AND vtiger_crmentityrel.relmodule = "Emails"
|
|
AND vtiger_crmentity.deleted = 0 ', $id);
|
|
|
|
$return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset);
|
|
|
|
|
|
if ($return_value == null) {
|
|
$return_value = array();
|
|
}
|
|
$return_value['CUSTOM_BUTTON'] = $button;
|
|
|
|
$log->debug("Exiting get_emails method ...");
|
|
|
|
return $return_value;
|
|
}
|
|
|
|
} |