- 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.
206 lines
7.3 KiB
PHP
206 lines
7.3 KiB
PHP
<?php
|
|
/* * *******************************************************************************
|
|
* The content of this file is subject to the ITS4YouMention 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 ITS4YouMention_Record_Model extends Vtiger_Record_Model
|
|
{
|
|
protected $parent;
|
|
protected $comment;
|
|
protected $mentioned = array();
|
|
|
|
public function setParent($value)
|
|
{
|
|
$this->parent = $value;
|
|
}
|
|
|
|
public function setComment($value)
|
|
{
|
|
$this->comment = $value;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getMentionedUsers()
|
|
{
|
|
$parentModule = $this->getParentModuleName();
|
|
/** @var ITS4YouMention_Module_Model $moduleModel */
|
|
$moduleModel = $this->getModule();
|
|
$userRecords = $moduleModel->getAccessibleUsers($parentModule);
|
|
$comment = $this->comment;
|
|
$mentionedUsers = array();
|
|
|
|
foreach ($userRecords as $userId => $userRecord) {
|
|
if(false !== strpos($comment, '@'.$userRecord->get('user_name'))) {
|
|
$mentionedUsers[$userId] = $userRecord;
|
|
}
|
|
}
|
|
|
|
$groupRecords = $moduleModel->getAccessibleGroups($parentModule);
|
|
/** @var Settings_Groups_Record_Model $groupRecord */
|
|
|
|
foreach ($groupRecords as $groupId => $groupRecord) {
|
|
if (false !== strpos($comment, '@' . $moduleModel->getGroupName($groupRecord))) {
|
|
|
|
foreach ($groupRecord->getUsersList() as $userId => $userRecord) {
|
|
$mentionedUsers[$userId] = $userRecord;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $mentionedUsers;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getParentModuleName()
|
|
{
|
|
return $this->getParentRecord()->getModuleName();
|
|
}
|
|
|
|
/**
|
|
* @return object
|
|
*/
|
|
public function getParentRecord()
|
|
{
|
|
return Vtiger_Record_Model::getInstanceById($this->parent);
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public function sendEmail()
|
|
{
|
|
include_once 'libraries/ToAscii/ToAscii.php';
|
|
|
|
global $log;
|
|
$log->info("ITS4YouMention:: Send->Started");
|
|
|
|
$parentRecord = $this->getParentRecord();
|
|
$emailInfo = $this->getEmailInfo();
|
|
|
|
foreach ($emailInfo as $userId => $userEmail) {
|
|
/** @var $email ITS4YouEmails_Record_Model */
|
|
$email = Vtiger_Record_Model::getCleanInstance('ITS4YouEmails');
|
|
$email->set('subject', $this->getEmailSubject());
|
|
$email->set('body', $this->getEmailMessage($userId));
|
|
$email->set('to_email', $userEmail);
|
|
$email->set('to_email_ids', implode('|', [$userId, $userEmail, 'Users']));
|
|
$email->set('related_to', $parentRecord->getId());
|
|
$email->set('email_flag', 'SAVED');
|
|
$email->set('assigned_user_id', $parentRecord->get('assigned_user_id'));
|
|
$email->save();
|
|
|
|
$email = Vtiger_Record_Model::getInstanceById($email->getId(), 'ITS4YouEmails');
|
|
$email->send();
|
|
}
|
|
|
|
$log->info("ITS4YouMention:: Send->Ended");
|
|
}
|
|
|
|
public function getEmailSubject()
|
|
{
|
|
$userRecord = Users_Record_Model::getCurrentUserModel();
|
|
$parentRecord = $this->getParentRecord();
|
|
|
|
return $userRecord->getName() . ' ' . vtranslate('mentioned you on', $this->getModuleName()) . ' ' . $parentRecord->getName();
|
|
}
|
|
|
|
public function getCommentMessage()
|
|
{
|
|
/**
|
|
* @var ITS4YouMention_Module_Model $moduleModel
|
|
* @var Settings_Groups_Record_Model $groupRecord
|
|
*/
|
|
$parentModule = $this->getParentModuleName();
|
|
$moduleModel = $this->getModule();
|
|
$comment = $this->comment;
|
|
$users = $this->getMentionedUsers();
|
|
|
|
foreach ($users as $user) {
|
|
$comment = str_replace(sprintf('@%s', $user->get('user_name')), sprintf('<b>@%s</b>', $user->getName()), $comment);
|
|
}
|
|
|
|
$groups = $moduleModel->getAccessibleGroups($parentModule);
|
|
|
|
foreach ($groups as $groupId => $group) {
|
|
$comment = str_replace(sprintf('@%s', $moduleModel->getGroupName($group)), sprintf('<b>@%s</b>', $group->getName()), $comment);
|
|
}
|
|
|
|
return $comment;
|
|
}
|
|
|
|
/**
|
|
* @param int $userId
|
|
* @return string
|
|
*/
|
|
public function getEmailMessage($userId = 0)
|
|
{
|
|
$currentUser = Users_Record_Model::getCurrentUserModel();
|
|
/** @var Vtiger_Record_Model $parentRecord */
|
|
$parentRecord = $this->getParentRecord();
|
|
$moduleName = $this->getModuleName();
|
|
$mentionedMessage = vtranslate('LBL_MENTIONED_YOU', $moduleName);
|
|
$clickMessage = vtranslate('LBL_CLICK_HERE', $moduleName);
|
|
|
|
if ($userId) {
|
|
$userRecordModel = Vtiger_Record_Model::getInstanceById($userId, 'Users');
|
|
|
|
if ($userRecordModel) {
|
|
$language = $userRecordModel->get('language');
|
|
$mentionedMessage = Vtiger_Language_Handler::getLanguageTranslatedString($language, 'LBL_MENTIONED_YOU', $moduleName);
|
|
$clickMessage = Vtiger_Language_Handler::getLanguageTranslatedString($language, 'LBL_CLICK_HERE', $moduleName);
|
|
}
|
|
}
|
|
|
|
if(empty($mentionedMessage)) {
|
|
$mentionedMessage = 'mentioned you in a comment.';
|
|
}
|
|
|
|
if(empty($clickMessage)) {
|
|
$clickMessage = 'Please click here to view the record.';
|
|
}
|
|
|
|
$viewer = new Vtiger_Viewer();
|
|
$viewer->assign('RECORD_TITLE', $parentRecord->getName());
|
|
$viewer->assign('RECORD_MESSAGE', $this->getCommentMessage());
|
|
$viewer->assign('RECORD_URL', ITS4YouMention_Module_Model::getSiteUrl() . $parentRecord->getDetailViewUrl());
|
|
$viewer->assign('MODULE', $moduleName);
|
|
$viewer->assign('RECORD_MODEL', $this);
|
|
$viewer->assign('COMPANY', Vtiger_CompanyDetails_Model::getInstanceById());
|
|
$viewer->assign('COMPANY_LOGO', $this->getCompanyImage());
|
|
$viewer->assign('CURRENT_USER', $currentUser);
|
|
$viewer->assign('CURRENT_USER_MODEL', Users_Record_Model::getCurrentUserModel());
|
|
$viewer->assign('MESSAGE_MENTIONED_YOU', $mentionedMessage);
|
|
$viewer->assign('MESSAGE_CLICK_HERE', $clickMessage);
|
|
|
|
return $viewer->view('Email.tpl', $this->getModuleName(), true);
|
|
}
|
|
|
|
public function getCompanyImage() {
|
|
$company = Vtiger_CompanyDetails_Model::getInstanceById();
|
|
$logo = $company->getLogo();
|
|
|
|
return ($logo && is_file($logo->get('imagepath'))) ? 'data:image/png;base64,'.base64_encode(file_get_contents($logo->get('imagepath'))) : '';
|
|
}
|
|
|
|
public function getEmailInfo()
|
|
{
|
|
$users = $this->getMentionedUsers();
|
|
$emails = array();
|
|
|
|
foreach ($users as $user) {
|
|
$emails[$user->getId()] = $user->get('email1');
|
|
}
|
|
|
|
return $emails;
|
|
}
|
|
} |