- 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.
504 lines
16 KiB
PHP
504 lines
16 KiB
PHP
<?php
|
|
|
|
/* * *******************************************************************************
|
|
* The content of this file is subject to the Quick Reminder 4 You 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 ITS4YouQuickReminder extends CRMEntity
|
|
{
|
|
|
|
public $log;
|
|
public $db;
|
|
public $LBL_MODULE_NAME = 'Quick Reminder 4 You';
|
|
public $LBL_MORE_VALUE = 'Create Quick Reminder';
|
|
public $LBL_MORE_MENU = 'DETAILVIEW';
|
|
public $LBL_MORE_LINK = 'javascript:ITS4YouQuickReminder_Js.addToReminder()';
|
|
public $moduleName = 'ITS4YouQuickReminder';
|
|
public $parentName = 'Tools';
|
|
public $table_name = 'its4you_reminder';
|
|
public $table_index = 'its4youquickreminderid';
|
|
public $entity_table = "vtiger_crmentity";
|
|
|
|
public $customFieldTable = array(
|
|
'its4you_remindercf',
|
|
'its4youquickreminderid'
|
|
);
|
|
|
|
public $tab_name = array(
|
|
'vtiger_crmentity',
|
|
'its4you_reminder',
|
|
'its4you_remindercf',
|
|
);
|
|
|
|
public $tab_name_index = array(
|
|
'vtiger_crmentity' => 'crmid',
|
|
'its4you_reminder' => 'its4youquickreminderid',
|
|
'its4you_remindercf' => 'its4youquickreminderid',
|
|
);
|
|
|
|
public $list_fields_name = array(
|
|
'Subject' => 'subject',
|
|
'Type' => 'remindertype',
|
|
'Related to' => 'parent_id',
|
|
'Status' => 'reminderstatus',
|
|
'Due Date' => 'due_date',
|
|
);
|
|
|
|
public $list_fields = array(
|
|
'Subject' => array('its4you_reminder' => 'subject'),
|
|
'Type' => array('its4you_reminder' => 'remindertype'),
|
|
'Related to' => array('its4you_reminder' => 'parent_id'),
|
|
'Status' => array('its4you_reminder' => 'reminderstatus'),
|
|
'Due Date' => array('its4you_reminder' => 'due_date'),
|
|
);
|
|
|
|
public $column_fields = array();
|
|
|
|
/**
|
|
* @var false|Vtiger_Module
|
|
*/
|
|
public $moduleInstance;
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
public $layout;
|
|
/**
|
|
* [module, type, label, url, icon, sequence, handlerInfo]
|
|
* @return array
|
|
*/
|
|
public $registerCustomLinks = array(
|
|
['ITS4YouQuickReminder', 'HEADERSCRIPT', 'ITS4YouQuickReminder', 'layouts/$LAYOUT$/modules/ITS4YouQuickReminder/resources/ITS4YouQuickReminder_Js.js']
|
|
);
|
|
|
|
/**
|
|
* @var array
|
|
* [Module, RelatedModule, RelatedLabel, RelatedActions, RelatedFunction]
|
|
*/
|
|
public $registerRelatedLists = [];
|
|
|
|
public function __construct()
|
|
{
|
|
global $log;
|
|
$this->column_fields = getColumnFields(get_class($this));
|
|
$this->db = PearDatabase::getInstance();
|
|
$this->log = $log;
|
|
}
|
|
|
|
public function save_module($module)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public function vtlib_handler($moduleName, $eventType)
|
|
{
|
|
require_once 'include/utils/utils.php';
|
|
require_once 'vtlib/Vtiger/Module.php';
|
|
require_once 'modules/ModComments/ModComments.php';
|
|
require_once 'modules/ModTracker/ModTracker.php';
|
|
require_once 'vtlib/Vtiger/Field.php';
|
|
|
|
$this->moduleInstance = Vtiger_Module::getInstance($moduleName);
|
|
|
|
switch ($eventType) {
|
|
case 'module.postupdate':
|
|
case 'module.enabled':
|
|
case 'module.postinstall':
|
|
$this->addCustomLinks();
|
|
break;
|
|
case 'module.disabled':
|
|
case 'module.preuninstall':
|
|
case 'module.preupdate':
|
|
$this->deleteCustomLinks();
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
* @return bool|void
|
|
*/
|
|
public function updateRelatedModulesBySettings($register = true)
|
|
{
|
|
$fieldInstance = Vtiger_Field_Model::getInstance('parent_id', $this->moduleInstance);
|
|
|
|
if(!$fieldInstance) {
|
|
return false;
|
|
}
|
|
|
|
$result = $this->db->pquery('SELECT module_name FROM its4you_reminder_settings WHERE active=?',
|
|
array('1')
|
|
);
|
|
|
|
while ($row = $this->db->fetchByAssoc($result)) {
|
|
$moduleModel = Vtiger_Module_Model::getInstance($row['module_name']);
|
|
|
|
if ($moduleModel && $moduleModel->isActive()) {
|
|
$this->deleteRelatedLink($moduleModel, $fieldInstance, false);
|
|
|
|
if ($register) {
|
|
$entityInstance = CRMEntity::getInstance($moduleModel->getName());
|
|
|
|
if ($entityInstance && is_subclass_of($entityInstance, 'CRMEntity')) {
|
|
$this->setRelatedLink($moduleModel, $fieldInstance, false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
* @return bool|void
|
|
*/
|
|
public function updateRelatedModules($register = true)
|
|
{
|
|
$fieldInstance = Vtiger_Field_Model::getInstance('parent_id', $this->moduleInstance);
|
|
|
|
if(!$fieldInstance) {
|
|
return false;
|
|
}
|
|
|
|
$entityModules = Vtiger_Module_Model::getEntityModules();
|
|
|
|
foreach ($entityModules as $entityModule) {
|
|
if ($entityModule) {
|
|
$this->deleteRelatedLink($entityModule, $fieldInstance);
|
|
|
|
if ($register) {
|
|
$entityInstance = CRMEntity::getInstance($entityModule->getName());
|
|
|
|
if ($entityInstance && is_subclass_of($entityInstance, 'CRMEntity')) {
|
|
$this->setRelatedLink($entityModule, $fieldInstance);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param Vtiger_Module $moduleInstance
|
|
* @param Vtiger_Field $fieldInstance
|
|
* @param bool $updateSettings
|
|
* @throws Exception
|
|
*/
|
|
public function deleteRelatedLink(Vtiger_Module $moduleInstance, Vtiger_Field $fieldInstance, $updateSettings = true)
|
|
{
|
|
$link = $this->getLinkInfo();
|
|
$reminderInstance = $fieldInstance->getModuleInstance();
|
|
$moduleName = $moduleInstance->name;
|
|
$moduleInstance->unsetRelatedlist($reminderInstance, $link['moduleLabel'], $link['function']);
|
|
$fieldInstance->unsetRelatedModules([$moduleName]);
|
|
$moduleInstance->deleteLink($link['type'], $link['label'], $link['url']);
|
|
|
|
if($updateSettings) {
|
|
$integration = Settings_ITS4YouQuickReminder_Integration_Model::getInstance($moduleName);
|
|
$integration->set('active', '0');
|
|
$integration->save();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getLinkInfo()
|
|
{
|
|
return [
|
|
'type' => 'DETAILVIEW',
|
|
'label' => 'Create Quick Reminder',
|
|
'url' => 'javascript:ITS4YouQuickReminder_Js.addToReminder()',
|
|
'moduleLabel' => 'Quick Reminder 4 You',
|
|
'fieldName' => 'parent_id',
|
|
'actions' => 'ADD',
|
|
'function' => 'get_dependents_list',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param Vtiger_Module $moduleInstance
|
|
* @param Vtiger_Field $fieldInstance
|
|
* @param bool $updateSettings
|
|
* @throws Exception
|
|
*/
|
|
public function setRelatedLink(Vtiger_Module $moduleInstance, Vtiger_Field $fieldInstance, $updateSettings = true)
|
|
{
|
|
$link = $this->getLinkInfo();
|
|
$moduleName = $moduleInstance->name;
|
|
|
|
$reminderInstance = $fieldInstance->getModuleInstance();
|
|
$moduleInstance->setRelatedlist($reminderInstance, $link['moduleLabel'], $link['actions'], $link['function'], $fieldInstance->id);
|
|
$moduleInstance->addLink($link['type'], $link['label'], $link['url']);
|
|
|
|
if ('Events' !== $moduleName) {
|
|
$fieldInstance->setRelatedModules([$moduleName]);
|
|
}
|
|
|
|
if($updateSettings) {
|
|
$integration = Settings_ITS4YouQuickReminder_Integration_Model::getInstance($moduleName);
|
|
$integration->set('active', '1');
|
|
$integration->save();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
public function addCustomLinks()
|
|
{
|
|
$this->updateNumbering();
|
|
$this->updateTables();
|
|
|
|
if (Settings_ITS4YouQuickReminder_Integration_Model::isInstalled()) {
|
|
$this->updateRelatedModulesBySettings();
|
|
} else {
|
|
$this->updateRelatedModules();
|
|
}
|
|
|
|
$this->updatePermissions();
|
|
$this->updateSettings();
|
|
$this->updateCustomLinks();
|
|
$this->setPicklistAndColors();
|
|
|
|
ModComments::addWidgetTo([$this->moduleName]);
|
|
ModTracker::enableTrackingForModule(getTabid($this->moduleName));
|
|
Settings_MenuEditor_Module_Model::addModuleToApp($this->moduleName, $this->parentName);
|
|
}
|
|
|
|
public function updateNumbering()
|
|
{
|
|
$this->setModuleSeqNumber('configure', $this->moduleName, 'QR', 1);
|
|
$this->updateMissingSeqNumber($this->moduleName);
|
|
}
|
|
|
|
public function updateTables()
|
|
{
|
|
$this->db->query('CREATE TABLE IF NOT EXISTS `its4you_reminder_settings` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`module_name` varchar(100) NULL,
|
|
`active` int(11) NULL,
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8');
|
|
}
|
|
|
|
public function updateSettings($register = true)
|
|
{
|
|
$this->db->pquery('DELETE FROM vtiger_settings_field WHERE name=?', array($this->LBL_MODULE_NAME));
|
|
|
|
if ($register) {
|
|
$this->db->pquery(
|
|
'INSERT INTO vtiger_settings_field(fieldid, blockid, name, description, linkto, sequence, iconpath) VALUES (?,?,?,?,?,?,?)',
|
|
array(
|
|
$this->db->getUniqueID('vtiger_settings_field'),
|
|
Vtiger_Deprecated::getSettingsBlockId('LBL_OTHER_SETTINGS'),
|
|
$this->LBL_MODULE_NAME,
|
|
'Add your work to reminder...',
|
|
'index.php?module=ITS4YouQuickReminder&parent=Settings&view=List',
|
|
1,
|
|
0
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @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]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function setPicklistAndColors()
|
|
{
|
|
$values_type = array(
|
|
array('Message', '#009688'),
|
|
array('Alert', '#2196f3'),
|
|
array('Warning', '#f44336'),
|
|
);
|
|
$values_status = array(
|
|
array('Open', '#f44236'),
|
|
array('In Progress', '#2195f3'),
|
|
array('Closed', '#ffffff'),
|
|
array('Is Readed', '#009687'),
|
|
);
|
|
|
|
$field = Vtiger_Field::getInstance('remindertype', $this->moduleInstance);
|
|
$field->setPicklistValues($values_type);
|
|
|
|
$field = Vtiger_Field::getInstance('reminderstatus', $this->moduleInstance);
|
|
$field->setPicklistValues($values_status);
|
|
}
|
|
|
|
public function updatePermissions()
|
|
{
|
|
$moduleModel = Settings_SharingAccess_Module_Model::getInstance(getTabid($this->moduleName));
|
|
$moduleModel->set('permission', 3);
|
|
$moduleModel->save();
|
|
}
|
|
|
|
/**
|
|
* @throws Exception
|
|
*/
|
|
function deleteCustomLinks()
|
|
{
|
|
$this->updateTables();
|
|
$this->clearPicklistValues();
|
|
$this->clearRelatedSettings();
|
|
$this->clearModuleLinks();
|
|
|
|
if (Settings_ITS4YouQuickReminder_Integration_Model::isInstalled()) {
|
|
$this->updateRelatedModulesBySettings(false);
|
|
} else {
|
|
$this->updateRelatedModules(false);
|
|
}
|
|
|
|
$this->updateSettings(false);
|
|
$this->updateCustomLinks(false);
|
|
|
|
ModComments::removeWidgetFrom([$this->moduleName]);
|
|
ModTracker::disableTrackingForModule(getTabid($this->moduleName));
|
|
}
|
|
|
|
public function clearModuleLinks()
|
|
{
|
|
$this->moduleInstance->deleteLinks();
|
|
}
|
|
|
|
public function clearPicklistValues()
|
|
{
|
|
$this->db->pquery('TRUNCATE vtiger_remindertype');
|
|
$this->db->pquery('TRUNCATE vtiger_reminderstatus');
|
|
}
|
|
|
|
public function clearRelatedSettings()
|
|
{
|
|
$this->db->pquery('DELETE FROM vtiger_relatedlists WHERE label=?', array($this->LBL_MODULE_NAME));
|
|
$this->db->pquery('DELETE FROM vtiger_fieldmodulerel WHERE `module`=?', array($this->moduleName));
|
|
$this->db->pquery('DELETE FROM vtiger_relatedlists WHERE related_tabid=?', array(getTabid($this->moduleName)));
|
|
}
|
|
|
|
/**
|
|
* @param string $value
|
|
* @return bool
|
|
*/
|
|
public function isAllowedLink($value)
|
|
{
|
|
return $this->getLinkCount($value) > 0;
|
|
}
|
|
|
|
/**
|
|
* @param string $value
|
|
* @return int
|
|
*/
|
|
public function getLinkCount($value)
|
|
{
|
|
$adb = PearDatabase::getInstance();
|
|
$sql = 'SELECT * FROM vtiger_links WHERE tabid = ? AND linklabel = ?';
|
|
$result = $adb->pquery($sql, array(getTabid($value), $this->getLinkInfo()['label']));
|
|
|
|
return (int)$adb->num_rows($result);
|
|
}
|
|
|
|
/**
|
|
* @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 retrieveCustomLinks() {
|
|
$link = $this->getLinkInfo();
|
|
$relatedModules = Settings_ITS4YouQuickReminder_Integration_Model::getActiveModules();
|
|
|
|
foreach ($relatedModules as $relatedModule) {
|
|
$this->registerCustomLinks[] = [$relatedModule, $link['type'], $link['label'], $link['url']];
|
|
}
|
|
}
|
|
|
|
public function retrieveRelatedList() {
|
|
$link = $this->getLinkInfo();
|
|
$relatedModules = Settings_ITS4YouQuickReminder_Integration_Model::getActiveModules();
|
|
|
|
foreach ($relatedModules as $relatedModule) {
|
|
$this->registerRelatedLists[] = [$relatedModule, 'ITS4YouQuickReminder', $link['moduleLabel'], $link['actions'], $link['function']];
|
|
}
|
|
}
|
|
|
|
public function getRequirementValidations() {
|
|
return [
|
|
[
|
|
'type' => 'parent_id',
|
|
'label' => vtranslate('LBL_PARENT_ID_MODULES', $this->moduleName),
|
|
'function' => 'getParentIdModules',
|
|
],
|
|
];
|
|
}
|
|
|
|
public function getParentIdModules() {
|
|
$info = [];
|
|
$moduleInstance = Vtiger_Module_Model::getInstance('ITS4YouQuickReminder');
|
|
$fieldInstance = Vtiger_Field_Model::getInstance('parent_id', $moduleInstance);
|
|
$fieldModules = $fieldInstance ? $fieldInstance->getReferenceList() : [];
|
|
$relatedModules = Settings_ITS4YouQuickReminder_Integration_Model::getActiveModules();
|
|
|
|
foreach ($relatedModules as $relatedModule) {
|
|
$validate = in_array($relatedModule, $fieldModules);
|
|
|
|
$info[] = [
|
|
'module' => $relatedModule,
|
|
'validate' => $validate,
|
|
'validate_message' => $validate ? '' : vtranslate('LBL_PARENT_ID_MODULE_REQUIERED', $this->moduleName),
|
|
];
|
|
}
|
|
|
|
return $info;
|
|
}
|
|
|
|
public function getRequirementHeaders()
|
|
{
|
|
return array(
|
|
vtranslate('LBL_MODULE', $this->moduleName) => 'module',
|
|
);
|
|
}
|
|
} |