--- loncom/interface/groupboards.pm 2006/11/02 21:06:06 1.10
+++ loncom/interface/groupboards.pm 2020/09/08 23:54:40 1.23
@@ -1,6 +1,8 @@
# The LearningOnline Network
# Group Bulletin Boards Manager
#
+# $Id: groupboards.pm,v 1.23 2020/09/08 23:54:40 raeburn Exp $
+#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
@@ -31,6 +33,8 @@ use Apache::Constants qw(:common :http);
use Apache::loncommon();
use Apache::lonnet;
use Apache::lonuserstate();
+use Apache::longroup;
+use Apache::lonnavmaps;
use LONCAPA::map();
use Apache::lonlocal;
use LONCAPA;
@@ -59,7 +63,7 @@ sub handler {
my $gpterm = &Apache::loncommon::group_term();
my $ucgpterm = $gpterm;
$ucgpterm =~ s/^(\w)/uc($1)/e;
- my $bodytitle = $crstype.' Discussion Boards';
+ my $bodytitle = $ucgpterm.' Discussion Boards';
my $group = $env{'form.group'};
$group =~ s/\W//g;
my ($description,$earlyout,$refarg);
@@ -70,7 +74,7 @@ sub handler {
&Apache::lonhtmlcommon::clear_breadcrumbs();
if (!defined($group)) {
- $earlyout = &mt('No [_1] defined, so there are no [_1] discussion boards to display',$gpterm);
+ $earlyout = &mt("No $gpterm defined, so there are no $gpterm discussion boards to display");
$r->print(&display_error($cdom,$cnum,$group,$description,$gpterm,
$ucgpterm,$bodytitle,$earlyout,$refarg));
return OK;
@@ -94,7 +98,7 @@ sub handler {
'/'.$group);
}
if (!$can_view) {
- $earlyout=&mt('You do not have privileges to view discussion boards in this [_1]',$gpterm);
+ $earlyout=&mt("You do not have privileges to view discussion boards in this $gpterm");
$r->print(&display_error($cdom,$cnum,$group,$description,$gpterm,
$ucgpterm,$bodytitle,$earlyout,$refarg));
return OK;
@@ -103,11 +107,11 @@ sub handler {
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) =
+ my ($outcome,$newurl,$bbtitle,$lockfreed) =
&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('The new discussion board was added successfully.').'
');
$r->print('
'. ''.&mt('Edit [_1] board',$bbtitle).' | '. @@ -115,8 +119,12 @@ sub handler { ''.&mt('View all group discussion boards'). '
' + .&mt('There are currently no discussion boards in this '.$gpterm.'.',) + .'
' + ); } $r->print(&Apache::loncommon::end_page()); return OK; @@ -176,56 +197,18 @@ function makebulboard() { sub create_board { my ($cdom,$cnum,$group,$bbtitle) = @_; - my ($outcome,$boardid,$newurl); + my ($outcome,$newurl,$idtype); $bbtitle=&unescape($bbtitle); - # get lock on nohist_groupboards file - my $lockhash = { - $group."\0".'locked_boardids' => $env{'user.name'}. - ':'.$env{'user.domain'}, - }; - my $tries = 0; - my $gotlock = &Apache::lonnet::newput('nohist_groupboards',$lockhash,$cdom,$cnum); - my $dellockoutcome; - while (($gotlock ne 'ok') && $tries <3) { - $tries ++; - sleep 1; - $gotlock = &Apache::lonnet::newput('nohist_groupboards',$lockhash,$cdom,$cnum); - } - if ($gotlock eq 'ok') { - my %curr_boards = &Apache::lonnet::dump('nohist_groupboards',$cdom,$cnum,$group); - $boardid = time; - my $idtries = 0; - while(exists($curr_boards{$group."\0".$boardid}) && $idtries < 20) { - $boardid ++; - $idtries ++; - } - if (!exists($curr_boards{$group."\0".$boardid})) { - my %new_board = ( - $group."\0".$boardid => $env{'user.name'}.':'. - $env{'user.domain'}, - ); - my $putresult = &Apache::lonnet::put('nohist_groupboards',\%new_board, - $cdom,$cnum); - if ($putresult ne 'ok') { - $outcome = 'error storing new board: '.$putresult; - } else { - $newurl = '/adm/'.$cdom.'/'.$cnum.'/'.$boardid. - '/bulletinboard'; - } - } else { - $outcome = ('error: no unique ID for the new board available.'); - } - # remove lock - my @del_lock = ($group."\0".'locked_boardids'); - $dellockoutcome = &Apache::lonnet::del('nohist_groupboards',\@del_lock,$cdom,$cnum); + $idtype = 'inc'; + my ($boardid,$dellock,$error) = + &Apache::lonnet::get_timebased_id($group,'boardids','groupboards', + $cdom,$cnum); + if ($boardid) { + $newurl = '/adm/'.$cdom.'/'.$cnum.'/'.$boardid.'/bulletinboard'; } else { - $outcome = "error: could not obtain lockfile\n"; - $dellockoutcome = 'ok'; - } - if (!$newurl) { - return ($outcome,$newurl,$bbtitle,$dellockoutcome); + return ($error,$newurl,$bbtitle,$dellock); } - $newurl=&unescape($newurl); + # need to check here if group_boards_$group.sequence is in the course # if not - add it as an item in group_folder_$group.sequence my $allbbsmap = &Apache::longroup::get_bbfolder_url($cdom,$cnum,$group); @@ -236,9 +219,9 @@ sub create_board { $LONCAPA::map::resources[$newidx]=$bbtitle.':'.$newurl. ':false:normal:res'; push(@LONCAPA::map::order,$newidx); - my ($errtext,$fatal)=&LONCAPA::map::storemap($allbbsmap,1); + my ($errtext,$fatal)=&LONCAPA::map::storemap($allbbsmap,1,1); if ($fatal) { - $outcome = "error: failed to store discussion boards map - $errtext\n"; + $outcome = "error: failed to save discussion boards map - $errtext\n"; } else { my %boardinfo = ( 'group' => $group, @@ -253,7 +236,7 @@ sub create_board { $outcome = 'error: discussion boards folder absent, '. 'or in unexpected location - '.$allbbsmap."\n"; } - return ($outcome,$newurl,$bbtitle,$dellockoutcome); + return ($outcome,$newurl,$bbtitle,$dellock); } sub display_error { @@ -276,14 +259,27 @@ sub boards_header { text=>"Groups", title=>"View course groups"},); } + my $view_permission = + &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')); + my $navmap=Apache::lonnavmaps::navmap->new(); + my $grouppagelink = &Apache::longroup::get_group_link($cdom,$cnum,$group,$navmap,$view_permission,$refarg); + if ($grouppagelink) { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>$grouppagelink, + text=>&mt('Group').": $description", + title=>&mt("Go to group's home page"), + no_mt=>1}); + } else { + &Apache::lonhtmlcommon::add_breadcrumb + ({text=>&mt('Group').": $description", + no_mt=>1}); + } &Apache::lonhtmlcommon::add_breadcrumb - ({href=>"/adm/$cdom/$cnum/$group/smppg?$refarg", - text=>"$ucgpterm: $description", - title=>"Go to group's home page"}, - {href=>"/adm/groupboards?group=$group&$refarg", + ({href=>"/adm/groupboards?group=$group&$refarg", text=>"Discussion Boards", title=>"Display group discussion boards"},); - $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('[_1] discussion boards - [_2]',$gpterm,$description)); + $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Group discussion boards - [_1]',$description), + undef,undef,undef,undef,1); return $output; }