| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | namespace Aurora\Modules\BrandingWebclient; |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | class Module extends \Aurora\System\Module\AbstractWebclientModule |
| 20: | { |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | public function init() |
| 28: | { |
| 29: | $oUser = \Aurora\System\Api::getAuthenticatedUser(); |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | } |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 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: | |
| 133: | |
| 134: | |
| 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: | |
| 161: | } |
| 162: | |