/**
	 * 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!' ) );
	}
	/**
	 * set event publish state status
	 *
	 * @param int       $state
	 * @param int       $id
	 * @param UserTable $user
	 */
	private function stateEvent( $state, $id, $user )
	{
		global $_CB_framework;

		$row				=	CBGroupJiveEvents::getEvent( (int) $id );
		$returnUrl			=	$_CB_framework->pluginClassUrl( $this->_gjPlugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $row->get( 'group' ) ) );

		if ( $row->get( 'id' ) ) {
			if ( ! CBGroupJive::canAccessGroup( $row->group(), $user ) ) {
				cbRedirect( $returnUrl, CBTxt::T( 'Group does not exist.' ), 'error' );
			} elseif ( ! CBGroupJive::isModerator( $user->get( 'id' ) ) ) {
				if ( CBGroupJive::getGroupStatus( $user, $row->group() ) < 2 ) {
					if ( ( $user->get( 'id' ) == $row->get( 'user_id' ) ) && ( $row->get( 'published' ) == -1 ) && ( $row->group()->params()->get( 'events', 1 ) == 2 ) ) {
						cbRedirect( $returnUrl, CBTxt::T( 'Your event is awaiting approval.' ), 'error' );
					} elseif ( ( $user->get( 'id' ) != $row->get( 'user_id' ) ) ) {
						cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to publish or unpublish this event.' ), 'error' );
					}
				}
			}
		} else {
			cbRedirect( $returnUrl, CBTxt::T( 'Event does not exist.' ), 'error' );
		}

		$currentState		=	(int) $row->get( 'published' );

		$row->set( 'published', (int) $state );

		if ( $row->getError() || ( ! $row->store() ) ) {
			cbRedirect( $returnUrl, CBTxt::T( 'GROUP_EVENT_STATE_FAILED_TO_SAVE', 'Event state failed to saved. Error: [error]', array( '[error]' => $row->getError() ) ), 'error' );
		}

		if ( $state && ( $currentState == -1 ) ) {
			$extras			=	array(	'event_title'	=>	htmlspecialchars( $row->get( 'title' ) ),
										'event'			=>	'<a href="' . $_CB_framework->pluginClassUrl( $this->_gjPlugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $row->get( 'group' ), 'tab' => 'grouptabevents' ) ) . '">' . htmlspecialchars( CBTxt::T( $row->get( 'title' ) ) ) . '</a>' );

			if ( $row->get( 'user_id' ) != $user->get( 'id' ) ) {
				CBGroupJive::sendNotification( 4, $user, (int) $row->get( 'user_id' ), CBTxt::T( 'Event schedule request accepted' ), CBTxt::T( 'Your event [event] schedule request in the group [group] has been accepted!' ), $row->group(), $extras );
			}

			CBGroupJive::sendNotifications( 'event_new', CBTxt::T( 'New group event' ), CBTxt::T( '[user] has scheduled the event [event] in the group [group]!' ), $row->group(), (int) $row->get( 'user_id' ), null, array( $user->get( 'id' ) ), 1, $extras );
		}

		cbRedirect( $returnUrl, CBTxt::T( 'Event state saved successfully!' ) );
	}
	/**
	 * set wall publish state status
	 *
	 * @param int       $state
	 * @param int       $id
	 * @param UserTable $user
	 */
	private function stateWall( $state, $id, $user )
	{
		global $_CB_framework;

		$row				=	CBGroupJiveWall::getPost( (int) $id );
		$returnUrl			=	$_CB_framework->pluginClassUrl( $this->_gjPlugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $row->get( 'group' ) ) );

		if ( $row->get( 'id' ) ) {
			if ( ! CBGroupJive::canAccessGroup( $row->group(), $user ) ) {
				cbRedirect( $returnUrl, CBTxt::T( 'Group does not exist.' ), 'error' );
			} elseif ( ! CBGroupJive::isModerator( $user->get( 'id' ) ) ) {
				if ( CBGroupJive::getGroupStatus( $user, $row->group() ) < 2 ) {
					if ( ( $user->get( 'id' ) == $row->get( 'user_id' ) ) && ( $row->get( 'published' ) == -1 ) && ( $row->group()->params()->get( 'wall', 1 ) == 2 ) ) {
						cbRedirect( $returnUrl, CBTxt::T( 'Your post is awaiting approval.' ), 'error' );
					} elseif ( ( $user->get( 'id' ) != $row->get( 'user_id' ) ) ) {
						cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to publish or unpublish this post.' ), 'error' );
					}
				}
			}
		} else {
			cbRedirect( $returnUrl, CBTxt::T( 'Post does not exist.' ), 'error' );
		}

		$currentState		=	(int) $row->get( 'published' );

		$row->set( 'published', (int) $state );

		if ( $row->getError() || ( ! $row->store() ) ) {
			cbRedirect( $returnUrl, CBTxt::T( 'GROUP_POST_STATE_FAILED_TO_SAVE', 'Post state failed to saved. Error: [error]', array( '[error]' => $row->getError() ) ), 'error' );
		}

		if ( $state && ( $currentState == -1 ) ) {
			if ( $row->get( 'user_id' ) != $user->get( 'id' ) ) {
				CBGroupJive::sendNotification( 4, $user, (int) $row->get( 'user_id' ), CBTxt::T( 'Wall post request accepted' ), CBTxt::T( 'Your wall post request in the group [group] has been accepted!' ), $row->group() );
			}

			if ( $row->reply()->get( 'id' ) ) {
				CBGroupJive::sendNotifications( 'wall_reply', CBTxt::T( 'New group post reply' ), CBTxt::T( '[user] has posted a reply on the wall in the group [group]!' ), $row->group(), (int) $row->get( 'user_id' ), (int) $row->reply()->get( 'user_id' ), array( $user->get( 'id' ) ) );
			} else {
				CBGroupJive::sendNotifications( 'wall_new', CBTxt::T( 'New group post' ), CBTxt::T( '[user] has posted on the wall in the group [group]!' ), $row->group(), (int) $row->get( 'user_id' ), null, array( $user->get( 'id' ) ) );
			}
		}

		cbRedirect( $returnUrl, CBTxt::T( 'Post state saved successfully!' ) );
	}
Esempio n. 4
0
	/**
	 * @return bool
	 */
	public function send()
	{
		if ( $this->accepted() ) {
			$this->setError( CBTxt::T( 'Invite already accepted!' ) );

			return false;
		}

		if ( $this->invited() && ( ! $this->canResend() ) ) {
			$this->setError( CBTxt::T( 'Invite already sent!' ) );

			return false;
		}

		if ( ( $this->group()->get( 'published', 1 ) != 1 ) || ( ! $this->group()->category()->get( 'published', 1 ) ) ) {
			$this->setError( CBTxt::T( 'Can not invite to an unpublished group!' ) );

			return false;
		}

		if ( $this->get( 'user' ) ) {
			$to		=	(int) $this->get( 'user' );
		} else {
			$to		=	$this->get( 'email' );
		}

		CBGroupJive::sendNotification( 4, (int) $this->get( 'user_id' ), $to, CBTxt::T( 'Group invite' ), CBTxt::T( 'GROUP_INVITE_MESSAGE', 'You have been invited to join the group [group] by [user]!<p>[message]</p>', array( '[message]' => htmlspecialchars( $this->get( 'message' ) ) ) ), $this->group() );

		$this->set( 'invited', $this->get( 'invited', Application::Database()->getUtcDateTime() ) );

		if ( ! $this->store() ) {
			return false;
		}

		return true;
	}