|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Mail cction bar class. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright YetiForce S.A. |
|
7
|
|
|
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com) |
|
8
|
|
|
* @author Mariusz Krzaczkowski <[email protected]> |
|
9
|
|
|
* @author Radosław Skrzypczak <[email protected]> |
|
10
|
|
|
*/ |
|
11
|
|
|
class OSSMail_MailActionBar_View extends Vtiger_Index_View |
|
12
|
|
|
{ |
|
13
|
|
|
use App\Controller\ClearProcess; |
|
14
|
|
|
|
|
15
|
|
|
/** {@inheritdoc} */ |
|
16
|
|
|
public function process(App\Request $request) |
|
17
|
|
|
{ |
|
18
|
|
|
$moduleName = $request->getModule(); |
|
19
|
|
|
$uid = $request->getInteger('uid'); |
|
20
|
|
|
$account = OSSMail_Record_Model::getAccountByHash($request->getForSql('rcId')); |
|
21
|
|
|
if (!$account || !\App\Record::isExists($account['crm_ma_id'], 'MailAccount') || !\App\Privilege::isPermitted('MailAccount', 'DetailView', $account['crm_ma_id'])) { |
|
22
|
|
|
throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406); |
|
23
|
|
|
} |
|
24
|
|
|
$mailAccount = \App\Mail\Account::getInstanceById($account['crm_ma_id']); |
|
25
|
|
|
try { |
|
26
|
|
|
$mailViewModel = OSSMailView_Record_Model::getCleanInstance('OSSMailView'); |
|
27
|
|
|
$folderDecode = \App\Utils::convertCharacterEncoding($request->getRaw('folder'), 'UTF7-IMAP', 'UTF-8'); |
|
28
|
|
|
$folderDecode = \App\Purifier::purifyByType($folderDecode, 'Text'); |
|
29
|
|
|
$folderDecode = \App\Purifier::decodeHtml($folderDecode); |
|
30
|
|
|
$imap = $mailAccount->openImap(); |
|
31
|
|
|
$message = $imap->getMessageByUid($folderDecode, $uid); |
|
32
|
|
|
$record = $message ? $message->getMailCrmIdByCid() : 0; |
|
33
|
|
|
if (!$record && \in_array('CreatedMail', $mailAccount->getActions()) && \in_array($folderDecode, $mailAccount->getFolders())) { |
|
|
|
|
|
|
34
|
|
|
$scanner = (new \App\Mail\Scanner())->setLimit(1); |
|
35
|
|
|
foreach ($mailAccount->getActions() as $action) { |
|
36
|
|
|
$scanner->getAction($action)->setAccount($mailAccount)->setMessage($message)->process(); |
|
37
|
|
|
} |
|
38
|
|
|
$record = (int) $message->getProcessData('CreatedMail')['mailViewId'] ?? 0; |
|
39
|
|
|
} elseif ($record && !\App\Privilege::isPermitted('OSSMailView', 'DetailView', $record)) { |
|
|
|
|
|
|
40
|
|
|
$recordModel = Vtiger_Record_Model::getInstanceById($record, $mailViewModel->getModule()); |
|
|
|
|
|
|
41
|
|
|
$sharedOwner = $recordModel->isEmpty('shownerid') ? [] : explode(',', $recordModel->get('shownerid')); |
|
42
|
|
|
$sharedOwner[] = \App\User::getCurrentUserId(); |
|
43
|
|
|
$recordModel->set('shownerid', implode(',', $sharedOwner))->save(); |
|
44
|
|
|
} |
|
45
|
|
|
$viewer = $this->getViewer($request); |
|
46
|
|
|
$viewer->assign('RECORD', $record); |
|
47
|
|
|
if ($record) { |
|
|
|
|
|
|
48
|
|
|
$relatedRecords = $mailViewModel->getRelatedRecords($record); |
|
49
|
|
|
$viewer->assign('RELATED_RECORDS', $relatedRecords); |
|
50
|
|
|
} |
|
51
|
|
|
\App\ModuleHierarchy::getModulesByLevel(0); |
|
52
|
|
|
$viewer->assign('MODULE_NAME', $moduleName); |
|
53
|
|
|
$viewer->assign('URL', App\Config::main('site_URL')); |
|
54
|
|
|
$viewer->view('MailActionBar.tpl', $moduleName); |
|
55
|
|
|
} catch (\Throwable $e) { |
|
56
|
|
|
\App\Log::error($e->getMessage() . PHP_EOL . $e->__toString(), 'OSSMail'); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: