/** * resend invite * * @param int $id * @param UserTable $user */ private function sendInvite( $id, $user ) { global $_CB_framework; $row = new InviteTable(); $row->load( (int) $id ); $returnUrl = $_CB_framework->pluginClassUrl( $this->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 ( $user->get( 'id' ) != $row->get( 'user_id' ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to send this invite.' ), 'error' ); } elseif ( ! CBGroupJive::isModerator( $user->get( 'id' ) ) ) { if ( ( $row->group()->get( 'published' ) == -1 ) || ( ( ! $this->params->get( 'groups_invites_display', 1 ) ) && ( $row->group()->get( 'type' ) != 3 ) ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have access to invites in this group.' ), 'error' ); } } } else { cbRedirect( $returnUrl, CBTxt::T( 'Invite does not exist.' ), 'error' ); } if ( ! $row->send() ) { cbRedirect( $returnUrl, CBTxt::T( 'GROUP_INVITE_FAILED_TO_SEND', 'Invite failed to send. Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); } cbRedirect( $returnUrl, CBTxt::T( 'Invite sent successfully!' ) ); }
/** * @return bool */ public function check() { if ( $this->get( 'user_id' ) == '' ) { $this->setError( CBTxt::T( 'Owner not specified!' ) ); return false; } elseif ( $this->get( 'group' ) == '' ) { $this->setError( CBTxt::T( 'Group not specified!' ) ); return false; } elseif ( ( $this->get( 'email' ) == '' ) && ( $this->get( 'user' ) == '' ) ) { $this->setError( CBTxt::T( 'Recipient not specified or invalid!' ) ); return false; } else { $group = $this->group(); if ( ! $group->get( 'id' ) ) { $this->setError( CBTxt::T( 'Group does not exist!' ) ); return false; } elseif ( ! $this->get( 'id' ) ) { $user = new \CB\Database\Table\UserTable(); if ( $this->get( 'email' ) ) { $user->load( array( 'email' => $this->get( 'email' ) ) ); } elseif ( $this->get( 'user' ) ) { $user->load( (int) $this->get( 'user' ) ); if ( ! $user->get( 'id' ) ) { $this->setError( CBTxt::T( 'The user you are inviting does not exist!' ) ); return false; } } if ( $user->get( 'id' ) ) { if ( $this->get( 'user_id' ) == $user->get( 'id' ) ) { $this->setError( CBTxt::T( 'You can not invite your self!' ) ); return false; } elseif ( $group->get( 'user_id' ) == $user->get( 'id' ) ) { $this->setError( CBTxt::T( 'You can not invite the group owner!' ) ); return false; } elseif ( $user->get( 'block' ) || ( ! $user->get( 'approved' ) ) || ( ! $user->get( 'confirmed' ) ) ) { $this->setError( CBTxt::T( 'The user you are inviting does not exist!' ) ); return false; } else { $groupUser = new UserTable(); $groupUser->load( array( 'group' => (int) $this->get( 'group' ), 'user_id' => (int) $user->get( 'id' ) ) ); if ( $groupUser->get( 'id' ) ) { $this->setError( CBTxt::T( 'The user you are inviting already belongs to this group!' ) ); return false; } } } $invite = new InviteTable(); if ( $this->get( 'email' ) ) { $invite->load( array( 'group' => (int) $this->get( 'group' ), 'email' => $this->get( 'email' ) ) ); if ( $invite->get( 'id' ) ) { $this->setError( CBTxt::T( 'The email address you are inviting has already been invited to this group!' ) ); return false; } } elseif ( $this->get( 'user' ) ) { $invite->load( array( 'group' => (int) $this->get( 'group' ), 'user' => (int) $this->get( 'user' ) ) ); if ( $invite->get( 'id' ) ) { $this->setError( CBTxt::T( 'The user you are inviting has already been invited to this group!' ) ); return false; } } } } return true; }