Пример #1
0
 /**
  * @param string $sSql
  * @return CHelpdeskUser
  */
 protected function getUserBySql($sSql)
 {
     $oUser = false;
     if ($this->oConnection->Execute($sSql)) {
         $oUser = null;
         $oRow = $this->oConnection->GetNextRecord();
         if ($oRow) {
             $oUser = new CHelpdeskUser();
             $oUser->InitByDbRow($oRow);
         }
         $this->oConnection->FreeResult();
     }
     $this->throwDbExceptionIfExist();
     return $oUser;
 }
Пример #2
0
 /**
  * @param string $sWhere
  * @return string
  */
 protected function getUserByWhere($sWhere)
 {
     $aMap = api_AContainer::DbReadKeys(CHelpdeskUser::GetStaticMap());
     $aMap = array_map(array($this, 'escapeColumn'), $aMap);
     $sSql = 'SELECT %s FROM %sahd_users WHERE %s';
     return sprintf($sSql, implode(', ', $aMap), $this->Prefix(), $sWhere);
 }
Пример #3
0
 /**
  * @param CHelpdeskUser $oHelpdeskUser Helpdesk user object
  * @param bool $bCreateFromFetcher Default value is **false**.
  *
  * @return bool
  */
 public function NotifyRegistration($oHelpdeskUser, $bCreateFromFetcher = false)
 {
     if ($oHelpdeskUser) {
         $oFromAccount = null;
         $aData = $this->getHelpdeskMainSettings($oHelpdeskUser->IdTenant);
         if (!empty($aData['AdminEmailAccount'])) {
             $oApiUsers = $this->_getApiUsers();
             if ($oApiUsers) {
                 $oFromAccount = $oApiUsers->getAccountByEmail($aData['AdminEmailAccount']);
             }
         }
         $sSiteName = isset($aData['SiteName']) ? $aData['SiteName'] : '';
         if ($oFromAccount) {
             $oApiMail = $this->_getApiMail();
             if ($oApiMail) {
                 $sEmail = $oHelpdeskUser->resultEmail();
                 if (!empty($sEmail)) {
                     $oFromEmail = \MailSo\Mime\Email::NewInstance($oFromAccount->Email, $sSiteName);
                     $oToEmail = \MailSo\Mime\Email::NewInstance($sEmail, $oHelpdeskUser->Name);
                     $oUserMessage = $this->_buildUserMailMail(PSEVEN_APP_ROOT_PATH . 'templates/helpdesk/user.registration' . ($bCreateFromFetcher ? '.fetcher' : '') . '.html', $oFromEmail->ToString(), $oToEmail->ToString(), 'Registration', '', '', $oHelpdeskUser, $sSiteName);
                     $oApiMail->sendMessage($oFromAccount, $oUserMessage);
                 }
             }
         }
     }
 }
Пример #4
0
 /**
  * @param \CAccount $oAccount
  * 
  * @return \CHelpdeskUser|null
  */
 public function GetHelpdeskAccountFromMainAccount(&$oAccount)
 {
     $oResult = null;
     $oApiHelpdesk = $this->ApiHelpdesk();
     if ($oAccount && $oAccount->IsDefaultAccount && $oApiHelpdesk && $this->oApiCapability->isHelpdeskSupported($oAccount)) {
         if (0 < $oAccount->User->IdHelpdeskUser) {
             $oHelpdeskUser = $oApiHelpdesk->getUserById($oAccount->IdTenant, $oAccount->User->IdHelpdeskUser);
             $oResult = $oHelpdeskUser instanceof \CHelpdeskUser ? $oHelpdeskUser : null;
         }
         if (!$oResult instanceof \CHelpdeskUser) {
             $oHelpdeskUser = $oApiHelpdesk->getUserByEmail($oAccount->IdTenant, $oAccount->Email);
             $oResult = $oHelpdeskUser instanceof \CHelpdeskUser ? $oHelpdeskUser : null;
             if ($oResult instanceof \CHelpdeskUser) {
                 $oAccount->User->IdHelpdeskUser = $oHelpdeskUser->IdHelpdeskUser;
                 $this->oApiUsers->updateAccount($oAccount);
             }
         }
         if (!$oResult instanceof \CHelpdeskUser) {
             $oHelpdeskUser = new \CHelpdeskUser();
             $oHelpdeskUser->Email = $oAccount->Email;
             $oHelpdeskUser->Name = $oAccount->FriendlyName;
             $oHelpdeskUser->IdSystemUser = $oAccount->IdUser;
             $oHelpdeskUser->IdTenant = $oAccount->IdTenant;
             $oHelpdeskUser->Activated = true;
             $oHelpdeskUser->IsAgent = true;
             $oHelpdeskUser->Language = $oAccount->User->DefaultLanguage;
             $oHelpdeskUser->DateFormat = $oAccount->User->DefaultDateFormat;
             $oHelpdeskUser->TimeFormat = $oAccount->User->DefaultTimeFormat;
             $oHelpdeskUser->setPassword($oAccount->IncomingMailPassword);
             if ($oApiHelpdesk->createUser($oHelpdeskUser)) {
                 $oAccount->User->IdHelpdeskUser = $oHelpdeskUser->IdHelpdeskUser;
                 $this->oApiUsers->updateAccount($oAccount);
                 $oResult = $oHelpdeskUser;
             }
         }
     }
     return $oResult;
 }
Пример #5
0
 /**
  * @param int $iIdTenant
  * @param string $sEmail
  * @param string $sName
  * @param string $sPassword
  * @param bool $bCreateFromFetcher Default value is **false**.
  *
  * @throws CApiManagerException(Errs::HelpdeskManager_UserAlreadyExists) 6001
  * @throws CApiManagerException(Errs::HelpdeskManager_UserCreateFailed) 6002
  *
  * @return CHelpdeskUser|bool
  */
 public function registerHelpdeskAccount($iIdTenant, $sEmail, $sName, $sPassword, $bCreateFromFetcher = false)
 {
     $mResult = false;
     $oApiHelpdeskManager = CApi::Manager('helpdesk');
     $oApiUsersManager = CApi::Manager('users');
     $oApiCapabilityManager = CApi::Manager('capability');
     if (!$oApiHelpdeskManager || !$oApiUsersManager || !$oApiCapabilityManager || !$oApiCapabilityManager->isHelpdeskSupported()) {
         return $mResult;
     }
     $oUser = $oApiHelpdeskManager->getUserByEmail($iIdTenant, $sEmail);
     if (!$oUser) {
         $oAccount = $oApiUsersManager->getAccountByEmail($sEmail);
         if ($oAccount && $oAccount->IdTenant === $iIdTenant && $oApiCapabilityManager->isHelpdeskSupported($oAccount)) {
             throw new CApiManagerException(Errs::HelpdeskManager_UserAlreadyExists);
         }
         $oUser = new CHelpdeskUser();
         $oUser->Activated = false;
         $oUser->Email = $sEmail;
         $oUser->Name = $sName;
         $oUser->IdTenant = $iIdTenant;
         $oUser->IsAgent = false;
         $oUser->setPassword($sPassword, $bCreateFromFetcher);
         $oApiHelpdeskManager->createUser($oUser, $bCreateFromFetcher);
         if (!$oUser || 0 === $oUser->IdHelpdeskUser) {
             throw new CApiManagerException(Errs::HelpdeskManager_UserCreateFailed);
         } else {
             $mResult = $oUser;
         }
     } else {
         throw new CApiManagerException(Errs::HelpdeskManager_UserAlreadyExists);
     }
     return $mResult;
 }