/** * delete user * * @param int $id * @param UserTable $user */ private function deleteUser( $id, $user ) { global $_CB_framework; $row = new \CB\Plugin\GroupJive\Table\UserTable(); $row->load( (int) $id ); $returnUrl = $_CB_framework->pluginClassUrl( $this->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $row->group()->get( 'id' ) ) ); if ( $row->get( 'id' ) ) { if ( ! CBGroupJive::canAccessGroup( $row->group(), $user ) ) { cbRedirect( $returnUrl, CBTxt::T( 'Group does not exist.' ), 'error' ); } elseif ( $row->get( 'user_id' ) == $row->group()->get( 'user_id' ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You can not delete the group owner.' ), 'error' ); } elseif ( ! CBGroupJive::isModerator( $user->get( 'id' ) ) ) { if ( $user->get( 'id' ) == $row->get( 'user_id' ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You can not delete your self.' ), 'error' ); } elseif ( $user->get( 'id' ) != $row->group()->get( 'user_id' ) ) { $userStatus = CBGroupJive::getGroupStatus( $user, $row->group() ); if ( ( $userStatus < 3 ) || ( $row->get( 'status' ) > $userStatus ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to delete this user.' ), 'error' ); } } } } else { cbRedirect( $returnUrl, CBTxt::T( 'User does not exist.' ), 'error' ); } if ( ! $row->canDelete() ) { cbRedirect( $returnUrl, CBTxt::T( 'GROUP_USER_FAILED_TO_DELETE', 'User failed to delete. Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); } if ( ! $row->delete() ) { cbRedirect( $returnUrl, CBTxt::T( 'GROUP_USER_FAILED_TO_DELETE', 'User failed to delete. Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); } if ( ( $row->get( 'status' ) == 0 ) && ( $row->get( 'user_id' ) != $user->get( 'id' ) ) ) { CBGroupJive::sendNotification( 4, $user, (int) $row->get( 'user_id' ), CBTxt::T( 'Group join request rejected' ), CBTxt::T( 'Your join request to group [group] has been rejected!' ), $row->group() ); } cbRedirect( $returnUrl, CBTxt::T( 'User deleted successfully!' ) ); }
/** * Mutator: * Prepares field data rollback * Override * * @param FieldTable $field * @param UserTable $user RETURNED populated: touch only variables related to saving this field (also when not validating for showing re-edit) * @param array $postdata Typically $_POST (but not necessarily), filtering required. * @param string $reason 'edit' for save user edit, 'register' for save registration */ public function rollbackFieldDataSave( &$field, &$user, &$postdata, $reason ) { if ( ! in_array( $reason, array( 'register', 'edit' ) ) ) { return; } $value = $this->getValue( $field, $user, $postdata, true ); if ( $value ) { $groups = explode( '|*|', $value ); cbArrayToInts( $groups ); foreach ( $groups as $groupId ) { $row = new \CB\Plugin\GroupJive\Table\UserTable(); $row->load( array( 'user_id' => (int) $user->get( 'id' ), 'group' => (int) $groupId ) ); if ( ! $row->get( 'id' ) ) { continue; } if ( ! $row->canDelete() ) { $this->_setValidationError( $field, $user, $reason, $row->getError() ); break; } if ( ! $row->delete() ) { $this->_setValidationError( $field, $user, $reason, $row->getError() ); break; } } } }