1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | namespace Aurora\Modules\BrandingWebclient; |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | class Module extends \Aurora\System\Module\AbstractWebclientModule |
22: | { |
23: | |
24: | |
25: | |
26: | |
27: | public static function getInstance() |
28: | { |
29: | return parent::getInstance(); |
30: | } |
31: | |
32: | |
33: | |
34: | |
35: | public static function Decorator() |
36: | { |
37: | return parent::Decorator(); |
38: | } |
39: | |
40: | |
41: | |
42: | |
43: | public function getModuleSettings() |
44: | { |
45: | return $this->oModuleSettings; |
46: | } |
47: | |
48: | private function _getUrlFromParts($aParts) |
49: | { |
50: | $sUrl = ''; |
51: | if (!empty($aParts['scheme'])) { |
52: | $sUrl .= $aParts['scheme'] . ':'; |
53: | } |
54: | if (!empty($aParts['user']) || !empty($aParts['host'])) { |
55: | $sUrl .= '//'; |
56: | } |
57: | if (!empty($aParts['user'])) { |
58: | $sUrl .= $aParts['user']; |
59: | } |
60: | if (!empty($aParts['pass'])) { |
61: | $sUrl .= ':' . $aParts['pass']; |
62: | } |
63: | if (!empty($aParts['user'])) { |
64: | $sUrl .= '@'; |
65: | } |
66: | if (!empty($aParts['host'])) { |
67: | $sUrl .= $aParts['host']; |
68: | } |
69: | if (!empty($aParts['port'])) { |
70: | $sUrl .= ':' . $aParts['port']; |
71: | } |
72: | if (!empty($aParts['path'])) { |
73: | $sUrl .= $aParts['path']; |
74: | } |
75: | if (!empty($aParts['query'])) { |
76: | if (is_array($aParts['query'])) { |
77: | $sUrl .= '?' . http_build_query($aParts['query']); |
78: | } else { |
79: | $sUrl .= '?' . $aParts['query']; |
80: | } |
81: | } |
82: | if (!empty($aParts['fragment'])) { |
83: | $sUrl .= '#' . $aParts['fragment']; |
84: | } |
85: | |
86: | return $sUrl; |
87: | } |
88: | |
89: | private function _getUrlWithSeed($sUrl) |
90: | { |
91: | $aParts = parse_url($sUrl); |
92: | |
93: | if (!empty($aParts['host']) || !empty($aParts['path'])) { |
94: | $aQuery = []; |
95: | if (isset($aParts['query']) && is_string($aParts['query']) && !empty($aParts['query'])) { |
96: | parse_str($aParts['query'], $aQuery); |
97: | } |
98: | $aQuery['datetimeseed'] = date('Y-m-d-H-i-s'); |
99: | $aParts['query'] = http_build_query($aQuery); |
100: | } |
101: | |
102: | return $this->_getUrlFromParts($aParts); |
103: | } |
104: | |
105: | |
106: | |
107: | |
108: | |
109: | |
110: | |
111: | |
112: | |
113: | |
114: | public function GetSettings($TenantId = null) |
115: | { |
116: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
117: | |
118: | $sLoginLogo = ''; |
119: | $sTabsbarLogo = ''; |
120: | |
121: | if (!empty($TenantId)) { |
122: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::TenantAdmin); |
123: | $oAuthenticatedUser = \Aurora\System\Api::getAuthenticatedUser(); |
124: | |
125: | $oTenant = \Aurora\System\Api::getTenantById($TenantId); |
126: | if ($oTenant && ($oAuthenticatedUser->isAdmin() || $oAuthenticatedUser->IdTenant === $oTenant->Id)) { |
127: | $sLoginLogo = $this->oModuleSettings->GetTenantValue($oTenant->Name, 'LoginLogo', $sLoginLogo); |
128: | $sTabsbarLogo = $this->oModuleSettings->GetTenantValue($oTenant->Name, 'TabsbarLogo', $sTabsbarLogo); |
129: | } |
130: | } else { |
131: | $sLoginLogo = $this->oModuleSettings->LoginLogo; |
132: | $sTabsbarLogo = $this->oModuleSettings->TabsbarLogo; |
133: | } |
134: | |
135: | return array( |
136: | 'LoginLogo' => $sLoginLogo, |
137: | 'TabsbarLogo' => $sTabsbarLogo, |
138: | 'TopIframeUrl' => $this->_getUrlWithSeed($this->oModuleSettings->TopIframeUrl), |
139: | 'TopIframeHeightPx' => $this->oModuleSettings->TopIframeHeightPx, |
140: | ); |
141: | } |
142: | |
143: | |
144: | |
145: | |
146: | |
147: | |
148: | |
149: | |
150: | |
151: | public function UpdateSettings($LoginLogo, $TabsbarLogo, $TenantId = null) |
152: | { |
153: | $result = false; |
154: | $oSettings = $this->oModuleSettings; |
155: | if (!empty($TenantId)) { |
156: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::TenantAdmin); |
157: | $oTenant = \Aurora\System\Api::getTenantById($TenantId); |
158: | $oAuthenticatedUser = \Aurora\System\Api::getAuthenticatedUser(); |
159: | |
160: | if ($oTenant && ($oAuthenticatedUser->isAdmin() || $oAuthenticatedUser->IdTenant === $oTenant->Id)) { |
161: | $result = $oSettings->SaveTenantSettings($oTenant->Name, [ |
162: | 'LoginLogo' => $LoginLogo, |
163: | 'TabsbarLogo' => $TabsbarLogo |
164: | ]); |
165: | } |
166: | } else { |
167: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::SuperAdmin); |
168: | $oSettings->LoginLogo = $LoginLogo; |
169: | $oSettings->TabsbarLogo = $TabsbarLogo; |
170: | |
171: | $result = $oSettings->Save(); |
172: | } |
173: | |
174: | return $result; |
175: | } |
176: | |
177: | |
178: | } |
179: | |