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\BrandingWebclient;
9:
10: /**
11: * Adds ability to specify logos URL for login screen and main interface of application.
12: *
13: * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
14: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
15: * @copyright Copyright (c) 2023, Afterlogic Corp.
16: *
17: * @package Modules
18: */
19: class Module extends \Aurora\System\Module\AbstractWebclientModule
20: {
21: /***** private functions *****/
22: /**
23: * Initializes module.
24: *
25: * @ignore
26: */
27: public function init()
28: {
29: $oUser = \Aurora\System\Api::getAuthenticatedUser();
30:
31: //if (!empty($oUser) && $oUser->Role === \Aurora\System\Enums\UserRole::SuperAdmin)
32: // {
33: //$this->includeTemplate('StandardAuthWebclient_StandardAccountsSettingsFormView', 'Edit-Standard-Account-After', 'templates/AccountPasswordHintView.html', $this->sName);
34: // }
35: }
36:
37:
38: /***** private functions *****/
39:
40: /***** public functions might be called with web API *****/
41: /**
42: * Obtains list of module settings for authenticated user.
43: *
44: * @return array
45: */
46: public function GetSettings($TenantId = null)
47: {
48: \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous);
49:
50: $sLoginLogo = '';
51: $sTabsbarLogo = '';
52:
53: $oSettings = $this->GetModuleSettings();
54: if (!empty($TenantId)) {
55: \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::TenantAdmin);
56: $oTenant = \Aurora\System\Api::getTenantById($TenantId);
57:
58: if ($oTenant) {
59: $sLoginLogo = $oSettings->GetTenantValue($oTenant->Name, 'LoginLogo', $sLoginLogo);
60: $sTabsbarLogo = $oSettings->GetTenantValue($oTenant->Name, 'TabsbarLogo', $sTabsbarLogo);
61: }
62: } else {
63: $sLoginLogo = $oSettings->GetValue('LoginLogo', $sLoginLogo);
64: $sTabsbarLogo = $oSettings->GetValue('TabsbarLogo', $sTabsbarLogo);
65: }
66:
67: return array(
68: 'LoginLogo' => $sLoginLogo,
69: 'TabsbarLogo' => $sTabsbarLogo,
70: 'TopIframeUrl' => $this->_getUrlWithSeed($oSettings->GetValue('TopIframeUrl', '')),
71: 'TopIframeHeightPx' => $oSettings->GetValue('TopIframeHeightPx', ''),
72: );
73: }
74:
75: private function _getUrlFromParts($aParts)
76: {
77: $sUrl = '';
78: if (!empty($aParts['scheme'])) {
79: $sUrl .= $aParts['scheme'] . ':';
80: }
81: if (!empty($aParts['user']) || !empty($aParts['host'])) {
82: $sUrl .= '//';
83: }
84: if (!empty($aParts['user'])) {
85: $sUrl .= $aParts['user'];
86: }
87: if (!empty($aParts['pass'])) {
88: $sUrl .= ':' . $aParts['pass'];
89: }
90: if (!empty($aParts['user'])) {
91: $sUrl .= '@';
92: }
93: if (!empty($aParts['host'])) {
94: $sUrl .= $aParts['host'];
95: }
96: if (!empty($aParts['port'])) {
97: $sUrl .= ':' . $aParts['port'];
98: }
99: if (!empty($aParts['path'])) {
100: $sUrl .= $aParts['path'];
101: }
102: if (!empty($aParts['query'])) {
103: if (is_array($aParts['query'])) {
104: $sUrl .= '?' . http_build_query($aParts['query']);
105: } else {
106: $sUrl .= '?' . $aParts['query'];
107: }
108: }
109: if (!empty($aParts['fragment'])) {
110: $sUrl .= '#' . $aParts['fragment'];
111: }
112:
113: return $sUrl;
114: }
115:
116: private function _getUrlWithSeed($sUrl)
117: {
118: $aParts = parse_url($sUrl);
119:
120: if (!empty($aParts['host']) || !empty($aParts['path'])) {
121: $aQuery = [];
122: if (isset($aParts['query']) && is_string($aParts['query']) && !empty($aParts['query'])) {
123: parse_str($aParts['query'], $aQuery);
124: }
125: $aQuery['datetimeseed'] = date('Y-m-d-H-i-s');
126: $aParts['query'] = http_build_query($aQuery);
127: }
128:
129: return $this->_getUrlFromParts($aParts);
130: }
131: /**
132: * Updates module's settings - saves them to config.json file or to user settings in db.
133: * @param int $ContactsPerPage Count of contacts per page.
134: * @return boolean
135: */
136: public function UpdateSettings($LoginLogo, $TabsbarLogo, $TenantId = null)
137: {
138: $result = false;
139: $oSettings = $this->GetModuleSettings();
140: if (!empty($TenantId)) {
141: \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::TenantAdmin);
142: $oTenant = \Aurora\System\Api::getTenantById($TenantId);
143:
144: if ($oTenant) {
145: $oSettings->SetTenantValue($oTenant->Name, 'LoginLogo', $LoginLogo);
146: $oSettings->SetTenantValue($oTenant->Name, 'TabsbarLogo', $TabsbarLogo);
147: $result = $oSettings->SaveTenantSettings($oTenant->Name);
148: }
149: } else {
150: \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::SuperAdmin);
151:
152: $oSettings->SetValue('LoginLogo', $LoginLogo);
153: $oSettings->SetValue('TabsbarLogo', $TabsbarLogo);
154: $result = $oSettings->Save();
155: }
156:
157: return $result;
158: }
159:
160: /***** public functions might be called with web API *****/
161: }
162: