--- loncom/interface/groupboards.pm 2006/06/30 14:08:35 1.2
+++ loncom/interface/groupboards.pm 2006/07/08 01:07:34 1.5
@@ -30,7 +30,6 @@ use strict;
use Apache::Constants qw(:common :http);
use Apache::loncommon;
use Apache::lonnet;
-use Apache::lonnavmaps;
use Apache::lonuserstate;
use Apache::lonratedt;
use Apache::lonlocal;
@@ -58,29 +57,55 @@ sub handler {
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 = &mt('[_1] Discussion Boards',$crstype);
my $group = $env{'form.group'};
+ $group =~ s/\W//g;
+ my ($description,$earlyout);
+
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
if (!defined($group)) {
- $r->print(&Apache::loncommon::start_page($bodytitle));
- $r->print(&mt('No [_1] defined, so there are no [_1] discussion boards to display',$gpterm));
- $r->print(&Apache::loncommon::end_page());
+ $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));
+ return OK;
+ }
+ my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
+ if (!defined($curr_groups{$group})) {
+ $earlyout = &mt('Invalid [_1]',$gpterm);
+ $r->print(&display_error($cdom,$cnum,$group,$description,$gpterm,
+ $ucgpterm,$bodytitle,$earlyout));
return OK;
}
+ my %content = &Apache::longroup::get_group_settings($curr_groups{$group});
+ my $description = &unescape($content{'description'});
+
my $can_create=&Apache::lonnet::allowed('cgb',$env{'request.course.id'}.
'/'.$group);
- my $can_view=&Apache::lonnet::allowed('pgd',$env{'request.course.id'}.
+ my $can_view = &Apache::lonnet::allowed('vcg',$env{'request.course.id'});
+
+ if (!$can_view) {
+ $can_view = &Apache::lonnet::allowed('pgd',$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));
+ return OK;
+ }
if (defined($env{'form.newbul'})) {
if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
- $r->print(&Apache::loncommon::start_page($bodytitle));
- my ($outcome,$symb,$newurl,$bbtitle) =
+ $r->print(&boards_header($cdom,$cnum,$group,$description,$gpterm,
+ $ucgpterm,$bodytitle));
+ my ($outcome,$newurl,$bbtitle) =
&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).' | '. ''.
''.
@@ -97,6 +122,7 @@ sub handler {
my $jscript;
if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
$jscript = qq|
+
|;
}
- $r->print(&Apache::loncommon::start_page($bodytitle,
- ''));
- if (!$can_view) {
- $r->print(&mt('You do not have privileges to view discussion boards in this [_1]',$crstype));
- return OK;
- }
- my $navmap = Apache::lonnavmaps::navmap->new();
- my @groupboards;
- my %boards;
- my $grpbbmap = &get_bbfolder_url($cdom,$cnum,$group);
- if ($grpbbmap) {
- my $bbfolderres = $navmap->getResourceByUrl($grpbbmap);
- if ($bbfolderres) {
- my @boards = $navmap->retrieveResources($bbfolderres,undef,0,0);
- foreach my $res (@boards) {
- my $url = $res->src();
- if ($url =~ m|^/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard|) {
- push(@groupboards,$res->symb());
- $boards{$res->symb()} = {
- title => $res->title(),
- url => $res->src(),
- };
- }
- }
- }
- }
+ $r->print(&boards_header($cdom,$cnum,$group,$description,$gpterm,$ucgpterm,
+ $bodytitle,$jscript));
+ my ($groupboards,$boards) = &Apache::longroup::get_group_bbinfo($cdom,$cnum,
+ $group);
if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
- $r->print(' '); } - if (@groupboards) { - foreach my $board (@groupboards) { - $r->print(''.$boards{$board}{'title'}.' '); + if (@{$groupboards} > 0) { + $r->print(' '); + foreach my $board (@{$groupboards}) { + my $board_url = $$boards{$board}{'url'}; + if ($board_url =~ /\?/) { + $board_url .= '&group='.$group; + } else { + $board_url .= '?group='.$group; + } + $r->print(''.$$boards{$board}{'title'}.' '); } } else { - $r->print(&mt('There are currently no discussion boards in this [_1].', + $r->print(' '.&mt('There are currently no discussion boards in this [_1].', $gpterm)); } $r->print(&Apache::loncommon::end_page()); @@ -156,12 +167,17 @@ function makebulboard() { } sub create_board { - my ($cdom,$cnum,$group,$newboard,$symb) = @_; + my ($cdom,$cnum,$group,$newboard) = @_; my ($bbtitle,$newurl)=split(/\=/,$newboard); + my $outcome; + my ($boardid) = ($newurl =~ m-/adm/\Q$cdom\E/\Q$cnum\E/(\d+)/bulletinboard-); + if (!$boardid) { + $outcome = ('error: the URL for new board was invalid'); + return ($outcome,$newurl,$bbtitle); + } $bbtitle=&unescape($bbtitle); $newurl=&unescape($newurl); - my $allbbsmap = &get_bbfolder_url($cdom,$cnum,$group); - my ($outcome,$symb); + my $allbbsmap = &Apache::longroup::get_bbfolder_url($cdom,$cnum,$group); if ($allbbsmap =~ m|^/uploaded|) { my ($errtext,$fatal)=&Apache::lonratedt::mapread($allbbsmap); if (!$fatal) { @@ -173,8 +189,11 @@ sub create_board { if ($fatal) { $outcome = "error: failed to store discussion boards map - $errtext\n"; } else { - $outcome = 'ok'; - $symb = &Apache::lonnet::encode_symb($allbbsmap,$newidx,$newurl); + my %boardinfo = ( + 'group' => $group, + ); + $outcome = &Apache::lonnet::put('bulletinpage_'.$boardid, + \%boardinfo,$cdom,$cnum); } } else { $outcome = "error: failed to read all discussion boards map - $errtext\n"; @@ -183,22 +202,30 @@ sub create_board { $outcome = 'error: discussion boards folder absent, '. 'or in unexpected location - '.$allbbsmap."\n"; } - return ($outcome,$symb,$newurl,$bbtitle); + return ($outcome,$newurl,$bbtitle); } -sub get_bbfolder_url { - my ($cdom,$cnum,$group) = @_; - my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group); - my $grpbbmap; - if (%curr_groups) { - my %group_info = &Apache::longroup::get_group_settings( - $curr_groups{$group}); - my $creation = $group_info{'creation'}; - my $bbfolder = $creation + 1; - my $crspath = '/uploaded/'.$cdom.'/'.$cnum.'/'; - $grpbbmap = $crspath.'default_'.$bbfolder.'.sequence'; - } - return $grpbbmap; +sub display_error { + my ($cdom,$cnum,$group,$description,$gpterm,$ucgpterm,$bodytitle,$earlyout)=@_; + my $output = &boards_header($cdom,$cnum,$group,$description,$gpterm, + $ucgpterm,$bodytitle); + $output .= $earlyout; + $output .= &Apache::loncommon::end_page(); + return $output; +} + +sub boards_header { + my ($cdom,$cnum,$group,$description,$gpterm,$ucgpterm,$bodytitle,$jscript)=@_; + my $output = &Apache::loncommon::start_page($bodytitle,$jscript); + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"/adm/$cdom/$cnum/$group/smppg", + text=>"$ucgpterm: $description", + title=>"Go to group's home page"}, + {href=>"/adm/groupboards?group=$group", + text=>"Discussion Boards", + title=>"Display group discussion boards"},); + $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('[_1] discussion boards - [_2]',$gpterm,$description)); + return $output; } 1; |