/** * 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; } } } }
/** * 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!' ) ); }
/** * @param cbautoactionsActionTable $trigger * @param UserTable $user */ public function execute( $trigger, $user ) { global $_CB_database; if ( ! $this->installed() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_NOT_INSTALLED', ':: Action [action] :: CB GroupJive is not installed', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } return; } foreach ( $trigger->getParams()->subTree( 'groupjive' ) as $row ) { /** @var ParamsInterface $row */ switch( (int) $row->get( 'mode', 1, GetterInterface::INT ) ) { case 3: $owner = $row->get( 'owner', null, GetterInterface::STRING ); if ( ! $owner ) { $owner = (int) $user->get( 'id' ); } else { $owner = (int) $trigger->getSubstituteString( $owner ); } if ( ! $owner ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_NO_OWNER', ':: Action [action] :: CB GroupJive skipped due to missing owner', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $name = $trigger->getSubstituteString( $row->get( 'name', null, GetterInterface::STRING ) ); if ( ! $name ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_NO_NAME', ':: Action [action] :: CB GroupJive skipped due to missing name', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $category = new CategoryTable(); $category->load( array( 'name' => $name ) ); if ( ! $category->get( 'id' ) ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_NO_CATEGORY', ':: Action [action] :: CB GroupJive skipped due to missing category', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $category->set( 'published', 1 ); $category->set( 'user_id', $owner ); $category->set( 'name', $name ); $category->set( 'description', $trigger->getSubstituteString( $row->get( 'description', null, GetterInterface::STRING ) ) ); $category->set( 'access', 1 ); $category->set( 'create_access', 0 ); $category->set( 'types', $row->get( 'types', '1|*|2|*|3', GetterInterface::STRING ) ); $category->set( 'ordering', 1 ); if ( ! $category->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_FAILED', ':: Action [action] :: CB GroupJive failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $category->getError() ) ) ); continue; } } break; case 2: $owner = $row->get( 'owner', null, GetterInterface::STRING ); if ( ! $owner ) { $owner = (int) $user->get( 'id' ); } else { $owner = (int) $trigger->getSubstituteString( $owner ); } if ( ! $owner ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_NO_OWNER', ':: Action [action] :: CB GroupJive skipped due to missing owner', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $categoryId = (int) $row->get( 'category', -1, GetterInterface::INT ); $category = new CategoryTable(); if ( $categoryId == -1 ) { $name = $trigger->getSubstituteString( $row->get( 'category_name', null, GetterInterface::STRING ) ); if ( ! $name ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_NO_CAT_NAME', ':: Action [action] :: CB GroupJive skipped due to missing category name', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $category->load( array( 'name' => $name ) ); if ( ! $category->get( 'id' ) ) { $category->set( 'published', 1 ); $category->set( 'user_id', $owner ); $category->set( 'name', $name ); $category->set( 'description', $trigger->getSubstituteString( $row->get( 'category_description', null, GetterInterface::STRING ) ) ); $category->set( 'access', 1 ); $category->set( 'create_access', 0 ); $category->set( 'types', $row->get( 'category_types', '1|*|2|*|3', GetterInterface::STRING ) ); $category->set( 'ordering', 1 ); if ( ! $category->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_FAILED', ':: Action [action] :: CB GroupJive failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $category->getError() ) ) ); } continue; } } } else { $category->load( (int) $categoryId ); } if ( ! $category->get( 'id' ) ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_NO_CATEGORY', ':: Action [action] :: CB GroupJive skipped due to missing category', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $name = $trigger->getSubstituteString( $row->get( 'name', null, GetterInterface::STRING ) ); if ( ! $name ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_NO_NAME', ':: Action [action] :: CB GroupJive skipped due to missing name', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } $group = new GroupTable(); $join = false; if ( $row->get( 'unique', 1, GetterInterface::BOOLEAN ) ) { $group->load( array( 'category' => (int) $category->get( 'id' ), 'user_id' => (int) $owner, 'name' => $name ) ); } else { $group->load( array( 'category' => (int) $category->get( 'id' ), 'name' => $name ) ); if ( $row->get( 'autojoin', 1, GetterInterface::BOOLEAN ) ) { $join = true; } } if ( ! $group->get( 'id' ) ) { $group->set( 'published', 1 ); $group->set( 'category', (int) $category->get( 'id' ) ); $group->set( 'user_id', $owner ); $group->set( 'name', $name ); $group->set( 'description', $trigger->getSubstituteString( $row->get( 'description', null, GetterInterface::STRING ) ) ); $group->set( 'types', (int) $row->get( 'type', 1, GetterInterface::INT ) ); $group->set( 'ordering', 1 ); if ( ! $group->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_FAILED', ':: Action [action] :: CB GroupJive failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $group->getError() ) ) ); } continue; } } elseif ( $join ) { $groupUser = new \CB\Plugin\GroupJive\Table\UserTable( $_CB_database ); $groupUser->load( array( 'group' => (int) $group->get( 'id' ), 'user_id' => (int) $user->get( 'id' ) ) ); if ( ! $groupUser->get( 'id' ) ) { $groupUser->set( 'user_id', (int) $user->get( 'id' ) ); $groupUser->set( 'group', (int) $group->get( 'id' ) ); $groupUser->set( 'status', (int) $row->get( 'group_status', 1, GetterInterface::INT ) ); if ( ! $groupUser->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_FAILED', ':: Action [action] :: CB GroupJive failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $groupUser->getError() ) ) ); } continue; } } } break; case 4: $groups = $row->get( 'groups', null, GetterInterface::STRING ); if ( $groups ) { $groups = explode( '|*|', $groups ); cbArrayToInts( $groups ); foreach ( $groups as $groupId ) { $group = new GroupTable(); $group->load( (int) $groupId ); if ( $group->get( 'id' ) ) { $groupUser = new \CB\Plugin\GroupJive\Table\UserTable( $_CB_database ); $groupUser->load( array( 'group' => (int) $group->get( 'id' ), 'user_id' => (int) $user->get( 'id' ) ) ); if ( $groupUser->get( 'id' ) && ( $groupUser->get( 'status' ) != 4 ) ) { $groupUser->delete(); } } } } break; case 1: default: $groups = $row->get( 'groups', null, GetterInterface::STRING ); if ( $groups ) { $groups = explode( '|*|', $groups ); cbArrayToInts( $groups ); foreach ( $groups as $groupId ) { $group = new GroupTable(); $group->load( (int) $groupId ); if ( $group->get( 'id' ) ) { $groupUser = new \CB\Plugin\GroupJive\Table\UserTable( $_CB_database ); $groupUser->load( array( 'group' => (int) $group->get( 'id' ), 'user_id' => (int) $user->get( 'id' ) ) ); if ( ! $groupUser->get( 'id' ) ) { $groupUser->set( 'user_id', (int) $user->get( 'id' ) ); $groupUser->set( 'group', (int) $group->get( 'id' ) ); $groupUser->set( 'status', (int) $row->get( 'status', 1, GetterInterface::INT ) ); if ( ! $groupUser->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_GROUPJIVE_FAILED', ':: Action [action] :: CB GroupJive failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $groupUser->getError() ) ) ); } continue; } } } } } break; } } }