/**
	 * @param int       $id
	 * @param UserTable $user
	 */
	private function deleteInvite( $id, $user )
	{
		global $_CB_framework;

		$cbModerator			=	Application::User( (int) $user->get( 'id' ) )->isGlobalModerator();

		$row					=	new cbinvitesInviteTable();

		$row->load( (int) $id );

		$canAccess				=	false;

		if ( $row->get( 'id' ) && ( $cbModerator || ( $row->get( 'user_id' ) == $user->get( 'id' ) ) ) ) {
			$canAccess			=	true;
		}

		$profileUrl				=	$_CB_framework->userProfileUrl( $row->get( 'user_id', $user->get( 'id' ) ), false, 'cbinvitesTab' );

		if ( $canAccess ) {
			if ( $row->isAccepted() ) {
				cbRedirect( $profileUrl, CBTxt::T( 'Invite already accepted and can not be deleted.' ), 'error' );
			}

			if ( ! $row->delete() ) {
				cbRedirect( $profileUrl, CBTxt::T( 'INVITE_FAILED_DELETE_ERROR', 'Invite failed to delete! Error: [error]', array( '[error]' => $row->getError() ) ), 'error' );
			}

			cbRedirect( $profileUrl, CBTxt::T( 'Invite deleted successfully!' ) );
		} else {
			cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' );
		}
	}
Beispiel #2
0
	/**
	 * @param FieldTable $field
	 * @param UserTable  $user
	 * @param string     $columnName
	 * @param string     $value
	 * @param array      $postdata
	 * @param string     $reason
	 * @return bool
	 */
	public function validate( &$field, &$user, $columnName, &$value, &$postdata, $reason )
	{
		$validated				=	parent::validate( $field, $user, $columnName, $value, $postdata, $reason );

		if ( $validated ) {
			if ( ( $user->get( $columnName ) != $value ) && $value ) {
				$invite			=	new cbinvitesInviteTable();

				$invite->load( array( 'code' => $value ) );

				if ( ! $invite->get( 'id' ) ) {
					$this->_setValidationError( $field, $user, $reason, CBTxt::T( 'Invite code not valid.' ) );

					$validated	=	false;
				} elseif ( $invite->isAccepted() && ( $user->get( 'id' ) != $invite->get( 'user' ) ) ) {
					$this->_setValidationError( $field, $user, $reason, CBTxt::T( 'Invite code already used.' ) );

					$validated	=	false;
				}
			}
		}

		return $validated;
	}