/** * save group * * @param int $id * @param UserTable $user */ private function saveGroupEdit( $id, $user ) { global $_CB_framework, $_PLUGINS; $row = CBGroupJive::getGroup( $id ); $isModerator = CBGroupJive::isModerator( $user->get( 'id' ) ); $categoryId = $this->input( 'category', null, GetterInterface::INT ); if ( $categoryId === null ) { $category = $row->category(); } else { $category = CBGroupJive::getCategory( $categoryId ); } if ( $row->get( 'id' ) ) { $returnUrl = $_CB_framework->pluginClassUrl( $this->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $row->get( 'id' ) ) ); } else { $returnUrl = $_CB_framework->pluginClassUrl( $this->element, false, array( 'action' => 'categories', 'func' => 'show', 'id' => (int) $category->get( 'id' ) ) ); } if ( ! $isModerator ) { if ( ( ! $category->get( 'id' ) ) && ( ! $this->params->get( 'groups_uncategorized', 1 ) ) ) { CBGroupJive::returnRedirect( $returnUrl, CBTxt::T( 'Category does not exist.' ), 'error' ); } elseif ( $category->get( 'id' ) && ( ( ! $category->get( 'published' ) ) || ( ! CBGroupJive::canAccess( (int) $category->get( 'access' ), (int) $user->get( 'id' ) ) ) ) ) { CBGroupJive::returnRedirect( $returnUrl, CBTxt::T( 'You do not have access to this category.' ), 'error' ); } elseif ( $row->get( 'id' ) ) { if ( $user->get( 'id' ) != $row->get( 'user_id' ) ) { CBGroupJive::returnRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to edit this group.' ), 'error' ); } } elseif ( ! CBGroupJive::canCreateGroup( $user, $category ) ) { if ( $category->get( 'id' ) ) { CBGroupJive::returnRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to create a group in this category.' ), 'error' ); } else { CBGroupJive::returnRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to create a group.' ), 'error' ); } } } if ( $isModerator ) { $row->set( 'user_id', (int) $this->input( 'post/user_id', $row->get( 'user_id', $user->get( 'id' ) ), GetterInterface::INT ) ); } else { $row->set( 'user_id', (int) $row->get( 'user_id', $user->get( 'id' ) ) ); } $row->set( 'published', ( $isModerator || ( $row->get( 'id' ) && ( $row->get( 'published' ) != -1 ) ) || ( ! $this->params->get( 'groups_create_approval', 0 ) ) ? (int) $this->input( 'post/published', $row->get( 'published', 1 ), GetterInterface::INT ) : -1 ) ); $row->set( 'category', (int) $category->get( 'id' ) ); $row->set( 'type', (int) $this->input( 'post/type', $row->get( 'type', 1 ), GetterInterface::INT ) ); $row->set( 'name', $this->input( 'post/name', $row->get( 'name' ), GetterInterface::STRING ) ); $row->set( 'description', $this->input( 'post/description', $row->get( 'description' ), GetterInterface::STRING ) ); $row->set( 'ordering', (int) $row->get( 'ordering', 1 ) ); foreach ( $this->getInput()->subTree( 'params' ) as $k => $v ) { if ( is_array( $v ) || is_object( $v ) ) { continue; } $k = Get::clean( $k, GetterInterface::COMMAND ); if ( $k ) { if ( is_numeric( $v ) ) { $v = (int) $this->input( 'post/params.' . $k, null, GetterInterface::INT ); } else { $v = $this->input( 'post/params.' . $k, null, GetterInterface::STRING ); } $row->params()->set( $k, $v ); } } $row->set( 'params', $row->params()->asJson() ); if ( ( ! $isModerator ) && $this->params->get( 'groups_create_captcha', 0 ) ) { $_PLUGINS->loadPluginGroup( 'user' ); $_PLUGINS->trigger( 'onCheckCaptchaHtmlElements', array() ); if ( $_PLUGINS->is_errors() ) { $row->setError( $_PLUGINS->getErrorMSG() ); } } $new = ( $row->get( 'id' ) ? false : true ); if ( $row->getError() || ( ! $row->check() ) ) { $_CB_framework->enqueueMessage( CBTxt::T( 'GROUP_FAILED_TO_SAVE', 'Group failed to save! Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); $this->showGroupEdit( $id, $user ); return; } if ( $row->getError() || ( ! $row->store() ) ) { $_CB_framework->enqueueMessage( CBTxt::T( 'GROUP_FAILED_TO_SAVE', 'Group failed to save! Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); $this->showGroupEdit( $id, $user ); return; } if ( $row->get( 'published' ) == -1 ) { if ( $new ) { if ( $this->params->get( 'groups_create_approval_notify', 1 ) ) { CBGroupJive::sendNotification( 3, (int) $row->get( 'user_id' ), null, CBTxt::T( 'Group create request awaiting approval' ), CBTxt::T( '[user] has created the group [group] and is awaiting approval!' ), $row ); } CBGroupJive::returnRedirect( $returnUrl, CBTxt::T( 'Group created successfully and awaiting approval!' ) ); } else { CBGroupJive::returnRedirect( $returnUrl, CBTxt::T( 'Group saved successfully and awaiting approval!' ) ); } } else { if ( $new ) { CBGroupJive::returnRedirect( $returnUrl, CBTxt::T( 'Group created successfully!' ) ); } else { CBGroupJive::returnRedirect( $returnUrl, CBTxt::T( 'Group saved successfully!' ) ); } } }
/** * @param GroupTable $group * @param UserTable $user * @return bool */ static public function canAccessGroup( $group, $user ) { global $_PLUGINS; if ( ! $group->get( 'id' ) ) { return false; } elseif ( CBGroupJive::isModerator( $user->get( 'id' ) ) ) { return true; } static $params = null; if ( ! $params ) { $plugin = $_PLUGINS->getLoadedPlugin( 'user', 'cbgroupjive' ); $params = $_PLUGINS->getPluginParams( $plugin ); } static $cache = array(); $groupId = (int) $group->get( 'id' ); $userId = (int) $user->get( 'id' ); if ( ! isset( $cache[$userId][$groupId] ) ) { $access = true; if ( ( ! $group->category()->get( 'id' ) ) && ( ! $params->get( 'groups_uncategorized', 1 ) ) ) { $access = false; } elseif ( $group->category()->get( 'id' ) && ( ( ! $group->category()->get( 'published' ) ) || ( ! CBGroupJive::canAccess( (int) $group->category()->get( 'access' ), (int) $user->get( 'id' ) ) ) ) ) { $access = false; } elseif ( ( $group->get( 'published' ) != 1 ) && ( $user->get( 'id' ) != $group->get( 'user_id' ) ) ) { $access = false; } elseif ( $user->get( 'id' ) != $group->get( 'user_id' ) ) { $userStatus = CBGroupJive::getGroupStatus( $user, $group ); if ( $userStatus == -1 ) { $access = false; } elseif ( ( $group->get( 'type' ) == 3 ) && ( ( $userStatus === false ) || ( $userStatus === null ) ) && ( ! CBGroupJive::getGroupInvited( $user, $group ) ) ) { $access = false; } } $cache[$userId][$groupId] = $access; } return $cache[$userId][$groupId]; }