1: <?php
2: /**
3: * This code is licensed under AGPLv3 license or Afterlogic Software License
4: * if commercial version of the product was purchased.
5: * For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files.
6: */
7:
8: namespace Aurora\Modules\MailWebclient;
9:
10: /**
11: * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
12: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
13: * @copyright Copyright (c) 2023, Afterlogic Corp.
14: *
15: * @package Modules
16: */
17: class Module extends \Aurora\System\Module\AbstractWebclientModule
18: {
19: /**
20: * Initializes CoreWebclient Module.
21: *
22: * @ignore
23: */
24: public function init()
25: {
26: $this->subscribeEvent('Mail::UpdateSettings::after', array($this, 'onAfterUpdateSettings'));
27: }
28:
29: public function GetSettings()
30: {
31: \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous);
32:
33: $aSettings = array(
34: 'AllowAppRegisterMailto' => $this->getConfig('AllowAppRegisterMailto', false),
35: 'AllowChangeInputDirection' => $this->getConfig('AllowChangeInputDirection', false),
36: 'FoldersExpandedByDefault' => $this->getConfig('FoldersExpandedByDefault', false),
37: 'AllowSpamFolder' => $this->getConfig('AllowSpamFolder', true),
38: 'AllowAddNewFolderOnMainScreen' => $this->getConfig('AllowAddNewFolderOnMainScreen', false),
39: 'ComposeToolbarOrder' => $this->getConfig('ComposeToolbarOrder', array()),
40: 'DefaultFontName' => $this->getConfig('DefaultFontName', 'Tahoma'),
41: 'DefaultFontSize' => $this->getConfig('DefaultFontSize', 3),
42: 'AlwaysTryUseImageWhilePasting' => $this->getConfig('AlwaysTryUseImageWhilePasting', true),
43: 'AllowHorizontalLineButton' => $this->getConfig('AllowHorizontalLineButton', false),
44: 'AllowComposePlainText' => $this->getConfig('AllowComposePlainText', false),
45: 'AllowEditHtmlSource' => $this->getConfig('AllowEditHtmlSource', false),
46: 'JoinReplyPrefixes' => $this->getConfig('JoinReplyPrefixes', false),
47: 'MailsPerPage' => $this->getConfig('MailsPerPage', 20),
48: 'AllowChangeStarredMessagesSource' => $this->getConfig('AllowChangeStarredMessagesSource', false),
49: 'MaxMessagesBodiesSizeToPrefetch' => $this->getConfig('MaxMessagesBodiesSizeToPrefetch', 50000),
50: 'MessageBodyTruncationThreshold' => $this->getConfig('MessageBodyTruncationThreshold', 650000), // in bytes
51: 'ShowEmailAsTabName' => $this->getConfig('ShowEmailAsTabName', true),
52: 'AllowOtherModulesToReplaceTabsbarHeader' => $this->getConfig('AllowOtherModulesToReplaceTabsbarHeader', false),
53: 'AllowShowMessagesCountInFolderList' => $this->getConfig('AllowShowMessagesCountInFolderList', false),
54: 'AllowSearchMessagesBySubject' => $this->getConfig('AllowSearchMessagesBySubject', false),
55: 'PrefixesToRemoveBeforeSearchMessagesBySubject' => $this->getConfig('PrefixesToRemoveBeforeSearchMessagesBySubject', []),
56: 'AllowHorizontalLayout' => $this->getConfig('AllowHorizontalLayout', false),
57: 'HorizontalLayoutByDefault' => $this->getConfig('HorizontalLayoutByDefault', false),
58: 'DisableRtlRendering' => $this->getConfig('DisableRtlRendering', false),
59: 'AllowQuickReply' => $this->getConfig('AllowQuickReply', false),
60: 'AllowQuickSendOnCompose' => $this->getConfig('AllowQuickSendOnCompose', false),
61: 'AllowUserGroupsInComposeAutocomplete' => $this->getConfig('AllowUserGroupsInComposeAutocomplete', true),
62: 'MarkMessageSeenWhenViewing' => $this->getConfig('MarkMessageSeenWhenViewing', true),
63: 'MarkMessageSeenWhenAnswerForward' => $this->getConfig('MarkMessageSeenWhenAnswerForward', false),
64: 'UserLoginPartInAccountDropdown' => $this->getConfig('UserLoginPartInAccountDropdown', false),
65: 'UseMeRecipientForMessages' => $this->getConfig('UseMeRecipientForMessages', false),
66: 'HorizontalLayout' => $this->getConfig('HorizontalLayoutByDefault', false),
67: 'ShowMessagesCountInFolderList' => $this->getConfig('AllowShowMessagesCountInFolderList', false),
68: 'TextEditorImageResizerOptions' => $this->getConfig('TextEditorImageResizerOptions', []),
69: );
70:
71: $oUser = \Aurora\System\Api::getAuthenticatedUser();
72: if ($oUser && $oUser->isNormalOrTenant()) {
73: if (isset($oUser->{self::GetName().'::AllowChangeInputDirection'})) {
74: $aSettings['AllowChangeInputDirection'] = $oUser->{self::GetName().'::AllowChangeInputDirection'};
75: }
76: if (isset($oUser->{self::GetName().'::MailsPerPage'})) {
77: $aSettings['MailsPerPage'] = $oUser->{self::GetName().'::MailsPerPage'};
78: }
79: if (isset($oUser->{self::GetName().'::StarredMessagesSource'})) {
80: $aSettings['StarredMessagesSource'] = $oUser->{self::GetName().'::StarredMessagesSource'};
81: }
82: if (isset($oUser->{self::GetName().'::ShowMessagesCountInFolderList'})) {
83: $aSettings['ShowMessagesCountInFolderList'] = $oUser->{self::GetName().'::ShowMessagesCountInFolderList'};
84: }
85: if ($this->getConfig('AllowHorizontalLayout', false) && isset($oUser->{self::GetName().'::HorizontalLayout'})) {
86: $aSettings['HorizontalLayout'] = $oUser->{self::GetName().'::HorizontalLayout'};
87: }
88: }
89:
90: return $aSettings;
91: }
92:
93: public function onAfterUpdateSettings($Args, &$Result)
94: {
95: \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser);
96:
97: $oUser = \Aurora\System\Api::getAuthenticatedUser();
98: if ($oUser) {
99: if ($oUser->isNormalOrTenant()) {
100: $oCoreDecorator = \Aurora\Modules\Core\Module::Decorator();
101: if (isset($Args['MailsPerPage'])) {
102: $oUser->setExtendedProp(self::GetName().'::MailsPerPage', $Args['MailsPerPage']);
103: }
104: if (isset($Args['StarredMessagesSource'])) {
105: $oUser->setExtendedProp(self::GetName().'::StarredMessagesSource', $Args['StarredMessagesSource']);
106: }
107: if (isset($Args['AllowChangeInputDirection'])) {
108: $oUser->setExtendedProp(self::GetName().'::AllowChangeInputDirection', $Args['AllowChangeInputDirection']);
109: }
110: if (isset($Args['ShowMessagesCountInFolderList'])) {
111: $oUser->setExtendedProp(self::GetName().'::ShowMessagesCountInFolderList', $Args['ShowMessagesCountInFolderList']);
112: }
113: if ($this->getConfig('AllowHorizontalLayout', false) && isset($Args['HorizontalLayout'])) {
114: $oUser->setExtendedProp(self::GetName().'::HorizontalLayout', $Args['HorizontalLayout']);
115: }
116: return $oCoreDecorator->UpdateUserObject($oUser);
117: }
118: if ($oUser->Role === \Aurora\System\Enums\UserRole::SuperAdmin) {
119: if (isset($Args['MailsPerPage'])) {
120: $this->setConfig('MailsPerPage', $Args['MailsPerPage']);
121: }
122: if (isset($Args['AllowChangeInputDirection'])) {
123: $this->setConfig('AllowChangeInputDirection', $Args['AllowChangeInputDirection']);
124: }
125: if ($this->getConfig('AllowHorizontalLayout', false) && isset($Args['HorizontalLayoutByDefault'])) {
126: $this->setConfig('HorizontalLayoutByDefault', $Args['HorizontalLayoutByDefault']);
127: }
128: return $this->saveModuleConfig();
129: }
130: }
131: }
132: }
133: