/** * save notifications * * @param int $id * @param UserTable $user */ private function saveNotifications( $id, $user ) { global $_CB_framework; $row = new NotificationTable(); $isModerator = CBGroupJive::isModerator( $user->get( 'id' ) ); $group = CBGroupJive::getGroup( $id ); $row->load( array( 'user_id' => (int) $user->get( 'id' ), 'group' => (int) $group->get( 'id' ) ) ); $returnUrl = $_CB_framework->pluginClassUrl( $this->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $group->get( 'id' ) ) ); if ( ! CBGroupJive::canAccessGroup( $group, $user ) ) { cbRedirect( $returnUrl, CBTxt::T( 'Group does not exist.' ), 'error' ); } elseif ( ! $this->params->get( 'notifications', 1 ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have access to notifications in this group.' ), 'error' ); } elseif ( $row->get( 'id' ) && ( $user->get( 'id' ) != $row->get( 'user_id' ) ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to edit this users notifications.' ), 'error' ); } elseif ( ! $isModerator ) { if ( ! CBGroupJive::canCreateGroupContent( $user, $group ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to notifications in this group.' ), 'error' ); } } $row->set( 'user_id', $row->get( 'user_id', (int) $user->get( 'id' ) ) ); $row->set( 'group', $row->get( 'group', (int) $group->get( 'id' ) ) ); 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 ( $row->getError() || ( ! $row->check() ) ) { $_CB_framework->enqueueMessage( CBTxt::T( 'GROUP_NOTIFICATIONS_FAILED_TO_SAVE', 'Notifications failed to save! Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); $this->showGroupNotifications( $id, $user ); return; } if ( $row->getError() || ( ! $row->store() ) ) { $_CB_framework->enqueueMessage( CBTxt::T( 'GROUP_NOTIFICATIONS_FAILED_TO_SAVE', 'Notifications failed to save! Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); $this->showGroupNotifications( $id, $user ); return; } cbRedirect( $returnUrl, CBTxt::T( 'Notifications saved successfully!' ) ); }
/** * delete wall * * @param int $id * @param UserTable $user */ private function deleteWall( $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 ( ( $user->get( 'id' ) != $row->get( 'user_id' ) ) && ( CBGroupJive::getGroupStatus( $user, $row->group() ) < 2 ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to delete this post.' ), 'error' ); } } } else { cbRedirect( $returnUrl, CBTxt::T( 'Post does not exist.' ), 'error' ); } if ( ! $row->canDelete() ) { cbRedirect( $returnUrl, CBTxt::T( 'GROUP_POST_FAILED_TO_DELETE', 'Post failed to delete. Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); } if ( ! $row->delete() ) { cbRedirect( $returnUrl, CBTxt::T( 'GROUP_POST_FAILED_TO_DELETE', 'Post failed to delete. Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); } cbRedirect( $returnUrl, CBTxt::T( 'Post deleted successfully!' ) ); }
/** * output file * * @param bool $preview * @param int $id * @param UserTable $user */ private function outputFile( $preview, $id, $user ) { global $_CB_framework; $row = CBGroupJiveFile::getFile( (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 ( ( $row->get( 'published' ) != 1 ) && ( CBGroupJive::getGroupStatus( $user, $row->group() ) < 2 ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have access to this file.' ), 'error' ); } } } else { cbRedirect( $returnUrl, CBTxt::T( 'File does not exist.' ), 'error' ); } if ( $preview ) { $row->preview(); } else { $row->download(); } }
/** * unattend event * * @param int $id * @param UserTable $user */ private function unattendEvent( $id, $user ) { global $_CB_framework; $event = CBGroupJiveEvents::getEvent( (int) $id ); $returnUrl = $_CB_framework->pluginClassUrl( $this->_gjPlugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $event->get( 'group' ) ) ); if ( $event->get( 'id' ) ) { if ( ! CBGroupJive::canAccessGroup( $event->group(), $user ) ) { cbRedirect( $returnUrl, CBTxt::T( 'Group does not exist.' ), 'error' ); } elseif ( ! CBGroupJive::isModerator( $user->get( 'id' ) ) ) { if ( ( $event->get( 'published' ) != 1 ) && ( CBGroupJive::getGroupStatus( $user, $event->group() ) < 2 ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have access to this event.' ), 'error' ); } elseif ( CBGroupJive::getGroupStatus( $user, $event->group() ) < 1 ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to unattend this event.' ), 'error' ); } elseif ( $event->status() == 1 ) { cbRedirect( $returnUrl, CBTxt::T( 'You can not unattend an expired event.' ), 'error' ); } } } else { cbRedirect( $returnUrl, CBTxt::T( 'Event does not exist.' ), 'error' ); } $row = new AttendanceTable(); $row->load( array( 'user_id' => (int) $user->get( 'id' ), 'event' => (int) $event->get( 'id' ) ) ); if ( ! $row->get( 'id' ) ) { cbRedirect( $returnUrl, CBTxt::T( 'You can not unattend an event you are not attending.' ), 'error' ); } if ( ! $row->canDelete() ) { cbRedirect( $returnUrl, CBTxt::T( 'GROUP_EVENT_FAILED_TO_UNATTEND', 'Event failed to unattend. Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); } if ( ! $row->delete() ) { cbRedirect( $returnUrl, CBTxt::T( 'GROUP_EVENT_FAILED_TO_UNATTEND', 'Event failed to unattend. Error: [error]', array( '[error]' => $row->getError() ) ), 'error' ); } $extras = array( 'event_title' => htmlspecialchars( $event->get( 'title' ) ), 'event' => '<a href="' . $_CB_framework->pluginClassUrl( $this->_gjPlugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $event->get( 'group' ), 'tab' => 'grouptabevents' ) ) . '">' . htmlspecialchars( CBTxt::T( $event->get( 'title' ) ) ) . '</a>' ); CBGroupJive::sendNotifications( 'event_unattend', CBTxt::T( 'User unattended your group event' ), CBTxt::T( '[user] will no longer be attending your event [event] in the group [group]!' ), $event->group(), $user, (int) $event->get( 'user_id' ), array(), 1, $extras ); cbRedirect( $returnUrl, CBTxt::T( 'Event unattended successfully!' ) ); }
/** * save about * * @param int $id * @param UserTable $user */ private function saveAboutEdit( $id, $user ) { global $_CB_framework; $row = CBGroupJive::getGroup( $id ); $returnUrl = $_CB_framework->pluginClassUrl( $this->_gjPlugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $row->get( 'id' ) ) ); if ( CBGroupJive::canAccessGroup( $row, $user ) ) { if ( ! CBGroupJive::isModerator( $user->get( 'id' ) ) ) { if ( CBGroupJive::getGroupStatus( $user, $row ) < 3 ) { cbRedirect( $returnUrl, CBTxt::T( 'You do not have sufficient permissions to edit about in this group.' ), 'error' ); } } } else { cbRedirect( $returnUrl, CBTxt::T( 'Group does not exist.' ), 'error' ); } $row->params()->set( 'about_content', trim( $this->input( 'post/about', $row->params()->get( 'about_content' ), GetterInterface::HTML ) ) ); $row->set( 'params', $row->params()->asJson() ); 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->showAboutEdit( $id, $user ); return; } cbRedirect( $returnUrl, CBTxt::T( 'Group about saved successfully!' ) ); }