Exemplo n.º 1
0
 protected function _editAccountForm($iAccountId, $sDisplayName)
 {
     $oAccount = BxDolAccount::getInstance($iAccountId);
     $aAccountInfo = $oAccount ? $oAccount->getInfo() : false;
     if (!$aAccountInfo) {
         return MsgBox(_t('_sys_txt_error_account_is_not_defined'));
     }
     // check access
     if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = BxDolAccount::isAllowedEdit($this->_iProfileId, $aAccountInfo))) {
         return MsgBox($sMsg);
     }
     // check and display form
     $oForm = BxDolForm::getObjectInstance('sys_account', $sDisplayName);
     if (!$oForm) {
         return MsgBox(_t('_sys_txt_error_occured'));
     }
     if (!$oForm->isSubmitted()) {
         unset($aAccountInfo['password']);
     }
     $oForm->initChecker($aAccountInfo);
     if (!$oForm->isSubmittedAndValid()) {
         return $oForm->getCode();
     }
     $aTrackTextFieldsChanges = array();
     // track text fields changes, not-null(for example empty array) - means track, null - means don't track
     // update email and email setting in DB
     if (!$oForm->update($aAccountInfo['id'], array(), $aTrackTextFieldsChanges)) {
         if (!$oForm->isValid()) {
             return $oForm->getCode();
         } else {
             return MsgBox(_t('_sys_txt_error_account_update'));
         }
     }
     // check if email was changed
     if (!empty($aTrackTextFieldsChanges['changed_fields']) && in_array('email', $aTrackTextFieldsChanges['changed_fields'])) {
         $oAccount->updateEmailConfirmed(false);
     }
     // mark email as unconfirmed
     // check if password was changed
     if ($oForm->getCleanValue('password')) {
         // relogin with new password
         bx_logout();
         bx_login($aAccountInfo['id']);
     }
     // check if other text info was changed - if auto-appproval is off
     $isAutoApprove = $oForm->isSetPendingApproval() ? false : true;
     if (!$isAutoApprove) {
         bx_import('BxDolProfile');
         $oProfile = BxDolProfile::getInstanceAccountProfile($aAccountInfo['id']);
         // get profile associated with account, not current porfile
         $aProfileInfo = $oProfile->getInfo();
         unset($aTrackTextFieldsChanges['changed_fields']['email']);
         // email confirmation is automatic and separate, don't need to deactivate whole profile if email is changed
         if (BX_PROFILE_STATUS_ACTIVE == $aProfileInfo['status'] && !empty($aTrackTextFieldsChanges['changed_fields'])) {
             $oProfile->disapprove(BX_PROFILE_ACTION_AUTO);
         }
         // change profile to 'pending' only if some text fields were changed and profile is active
     }
     // create an alert
     bx_alert('account', 'edited', $aAccountInfo['id'], $aAccountInfo['id'], array('display' => $sDisplayName));
     // display result message
     $sMsg = MsgBox(_t('_sys_txt_data_successfully_submitted'));
     return $sMsg . $oForm->getCode();
 }