/**
  * @param string $sTenantLogin
  * @param string $sTenantPassword Default value is **null**.
  *
  * @return string
  */
 public function getTenantIdByLogin($sTenantLogin, $sTenantPassword = null)
 {
     $sAdd = '';
     if (null !== $sTenantPassword) {
         $sAdd = sprintf(' AND login_enabled = 1 AND disabled = 0 AND %s = %s', $this->escapeColumn('password'), $this->escapeString(CTenant::hashPassword($sTenantPassword)));
     }
     $sSql = 'SELECT id_tenant FROM %sawm_tenants WHERE %s = %s%s';
     return sprintf($sSql, $this->prefix(), $this->escapeColumn('login'), $this->escapeString($sTenantLogin), $sAdd);
 }
Example #2
0
 /**
  * @param CTenant $oTenant
  */
 public function SetTenantTabsInfo($oTenant)
 {
     $this->sTabsInfo = '';
     if ($oTenant) {
         $this->sTabsInfo = '<div class="tabs_info">';
         $this->sTabsInfo .= CApi::I18N('ADMIN_PANEL/RESOURCES_USAGE') . ': ' . CApi::I18N('ADMIN_PANEL/RESOURCES_USERS') . ' - ';
         $this->sTabsInfo .= $oTenant->GetUserCount();
         if (0 < $oTenant->UserCountLimit) {
             $this->sTabsInfo .= ' ' . sprintf(CApi::I18N('ADMIN_PANEL/RESOURCES_USERS_MAX'), $oTenant->UserCountLimit);
         }
         $iUsed = 0;
         if (0 < $oTenant->QuotaInMB) {
             $iUsed = floor($oTenant->AllocatedSpaceInMB / $oTenant->QuotaInMB * 100);
             $this->sTabsInfo .= '; ' . CApi::I18N('ADMIN_PANEL/RESOURCES_DISK') . ' - ' . $iUsed . '% (' . $oTenant->AllocatedSpaceInMB . ' MB) ' . CApi::I18N('ADMIN_PANEL/RESOURCES_DISK_OF') . ' ' . $oTenant->QuotaInMB . ' MB ' . CApi::I18N('ADMIN_PANEL/RESOURCES_DISK_ALLOC');
         } else {
             $this->sTabsInfo .= '; ' . CApi::I18N('ADMIN_PANEL/RESOURCES_DISK') . ' - ' . $oTenant->AllocatedSpaceInMB . ' MB ' . CApi::I18N('ADMIN_PANEL/RESOURCES_DISK_ALLOC');
         }
         $this->sTabsInfo .= '</div>';
     }
 }
Example #3
0
 /**
  * @param mixed $mTenantId
  * @param bool $bIdIsMd5 = false
  *
  * @return CTenant
  */
 public function GetTenantById($mTenantId, $bIdIsMd5 = false)
 {
     $oTenant = null;
     if ($this->oConnection->Execute($this->oCommandCreator->GetTenantById($mTenantId, $bIdIsMd5))) {
         $oRow = $this->oConnection->GetNextRecord();
         if ($oRow) {
             $oTenant = new CTenant();
             $oTenant->InitByDbRow($oRow);
         }
         $this->oConnection->FreeResult();
         if ($oTenant !== null) {
             $oTenant->Socials = $this->GetSocials($oTenant->IdTenant);
         }
     }
     $this->throwDbExceptionIfExist();
     return $oTenant;
 }
Example #4
0
 /**
  * @param CTenant $oTenant
  */
 public function UpdateTenant(CTenant $oTenant)
 {
     $bResult = false;
     try {
         if ($oTenant->Validate()) {
             if ($oTenant->IsDefault && 0 === $oTenant->IdTenant) {
                 $this->oSettings->SetConf('Helpdesk/AdminEmailAccount', $oTenant->HelpdeskAdminEmailAccount);
                 $this->oSettings->SetConf('Helpdesk/ClientIframeUrl', $oTenant->HelpdeskClientIframeUrl);
                 $this->oSettings->SetConf('Helpdesk/AgentIframeUrl', $oTenant->HelpdeskAgentIframeUrl);
                 $this->oSettings->SetConf('Helpdesk/SiteName', $oTenant->HelpdeskSiteName);
                 $this->oSettings->SetConf('Helpdesk/StyleAllow', $oTenant->HelpdeskStyleAllow);
                 $this->oSettings->SetConf('Helpdesk/StyleImage', $oTenant->HelpdeskStyleImage);
                 $this->oSettings->SetConf('Helpdesk/StyleText', $oTenant->HelpdeskStyleText);
                 $this->oSettings->SetConf('Helpdesk/FetcherType', $oTenant->HelpdeskFetcherType);
                 $this->oSettings->SetConf('Common/LoginStyleImage', $oTenant->LoginStyleImage);
                 $this->oSettings->SetConf('Common/AppStyleImage', $oTenant->AppStyleImage);
                 $this->oSettings->SetConf('Helpdesk/FacebookAllow', $oTenant->HelpdeskFacebookAllow);
                 $this->oSettings->SetConf('Helpdesk/FacebookId', $oTenant->HelpdeskFacebookId);
                 $this->oSettings->SetConf('Helpdesk/FacebookSecret', $oTenant->HelpdeskFacebookSecret);
                 $this->oSettings->SetConf('Helpdesk/GoogleAllow', $oTenant->HelpdeskGoogleAllow);
                 $this->oSettings->SetConf('Helpdesk/GoogleId', $oTenant->HelpdeskGoogleId);
                 $this->oSettings->SetConf('Helpdesk/GoogleSecret', $oTenant->HelpdeskGoogleSecret);
                 $this->oSettings->SetConf('Helpdesk/TwitterAllow', $oTenant->HelpdeskTwitterAllow);
                 $this->oSettings->SetConf('Helpdesk/TwitterId', $oTenant->HelpdeskTwitterId);
                 $this->oSettings->SetConf('Helpdesk/TwitterSecret', $oTenant->HelpdeskTwitterSecret);
                 $this->oSettings->SetConf('Sip/AllowSip', $oTenant->SipAllow);
                 $this->oSettings->SetConf('Sip/Realm', $oTenant->SipRealm);
                 $this->oSettings->SetConf('Sip/WebsocketProxyUrl', $oTenant->SipWebsocketProxyUrl);
                 $this->oSettings->SetConf('Sip/OutboundProxyUrl', $oTenant->SipOutboundProxyUrl);
                 $this->oSettings->SetConf('Sip/CallerID', $oTenant->SipCallerID);
                 $this->oSettings->SetConf('Twilio/AllowTwilio', $oTenant->TwilioAllow);
                 $this->oSettings->SetConf('Twilio/PhoneNumber', $oTenant->TwilioPhoneNumber);
                 $this->oSettings->SetConf('Twilio/AccountSID', $oTenant->TwilioAccountSID);
                 $this->oSettings->SetConf('Twilio/AuthToken', $oTenant->TwilioAuthToken);
                 $this->oSettings->SetConf('Twilio/AppSID', $oTenant->TwilioAppSID);
                 $this->oSettings->SetConf('Socials', $oTenant->Socials);
                 $bResult = $this->oSettings->SaveToXml();
             } else {
                 if (null !== $oTenant->GetObsoleteValue('QuotaInMB')) {
                     $iQuota = $oTenant->QuotaInMB;
                     if (0 < $iQuota) {
                         $iSize = $this->GetTenantAllocatedSize($oTenant->IdTenant);
                         if ($iSize > $iQuota) {
                             throw new CApiManagerException(Errs::TenantsManager_QuotaLimitExided);
                         }
                     }
                 }
                 if (!$this->oStorage->UpdateTenant($oTenant)) {
                     throw new CApiManagerException(Errs::TenantsManager_TenantUpdateFailed);
                 }
                 if (null !== $oTenant->GetObsoleteValue('IsDisabled')) {
                     /* @var $oDomainsApi CApiDomainsManager */
                     $oDomainsApi = CApi::Manager('domains');
                     if (!$oDomainsApi->EnableOrDisableDomainsByTenantId($oTenant->IdTenant, !$oTenant->IsDisabled)) {
                         $oException = $oDomainsApi->GetLastException();
                         if ($oException) {
                             throw $oException;
                         }
                     }
                 }
             }
         }
         $bResult = true;
         //			$this->UpdateTenantMainCapa($oTenant->IdTenant);
     } catch (CApiBaseException $oException) {
         $bResult = false;
         $this->setLastException($oException);
     }
     return $bResult;
 }