# The LearningOnline Network
# Group Bulletin Boards Manager
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
package Apache::groupboards;
use strict;
use Apache::Constants qw(:common :http);
use Apache::loncommon();
use Apache::lonnet;
use Apache::lonuserstate();
use LONCAPA::map();
use Apache::lonlocal;
use LONCAPA;
sub handler {
my ($r) = @_;
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
return OK if $r->header_only;
# Needs to be in a course
if (! ($env{'request.course.fn'})) {
# Not in a course
$env{'user.error.msg'}=
"/adm/groupboards:mdg:0:0:Cannot edit or view course groups";
return HTTP_NOT_ACCEPTABLE;
}
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['group','ref']);
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
my $now = time;
my $crstype = &Apache::loncommon::course_type();
my $gpterm = &Apache::loncommon::group_term();
my $ucgpterm = $gpterm;
$ucgpterm =~ s/^(\w)/uc($1)/e;
my $bodytitle = $crstype.' Discussion Boards';
my $group = $env{'form.group'};
$group =~ s/\W//g;
my ($description,$earlyout,$refarg);
if (exists($env{'form.ref'})) {
$refarg = 'ref='.$env{'form.ref'};
}
&Apache::lonhtmlcommon::clear_breadcrumbs();
if (!defined($group)) {
$earlyout = &mt('No [_1] defined, so there are no [_1] discussion boards to display',$gpterm);
$r->print(&display_error($cdom,$cnum,$group,$description,$gpterm,
$ucgpterm,$bodytitle,$earlyout,$refarg));
return OK;
}
my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
if (!defined($curr_groups{$group})) {
$earlyout = &mt('Invalid group');
$r->print(&display_error($cdom,$cnum,$group,$description,$gpterm,
$ucgpterm,$bodytitle,$earlyout,$refarg));
return OK;
}
my %content = &Apache::longroup::get_group_settings($curr_groups{$group});
$description = &unescape($content{'description'});
my $can_create=&Apache::lonnet::allowed('cgb',$env{'request.course.id'}.
'/'.$group);
my $can_view = &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
if (!$can_view) {
$can_view = &Apache::lonnet::allowed('vgb',$env{'request.course.id'}.
'/'.$group);
}
if (!$can_view) {
$earlyout=&mt('You do not have privileges to view discussion boards in this [_1]',$gpterm);
$r->print(&display_error($cdom,$cnum,$group,$description,$gpterm,
$ucgpterm,$bodytitle,$earlyout,$refarg));
return OK;
}
if (defined($env{'form.newbul'})) {
if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
$r->print(&boards_header($cdom,$cnum,$group,$description,$gpterm,
$ucgpterm,$bodytitle,$refarg));
my ($outcome,$newurl,$bbtitle,$dellockoutcome) =
&create_board($cdom,$cnum,$group,$env{'form.newbul'});
if ($outcome eq 'ok') {
my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
$r->print(&mt('The new discussion board was added successfully.
'));
$r->print('
'. ''.&mt('Edit [_1] board',$bbtitle).' | '. ''. ''.&mt('View all group discussion boards'). ' |