--- loncom/interface/groupboards.pm 2012/07/21 21:20:06 1.15
+++ loncom/interface/groupboards.pm 2012/11/11 17:33:18 1.16
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Group Bulletin Boards Manager
#
-# $Id: groupboards.pm,v 1.15 2012/07/21 21:20:06 raeburn Exp $
+# $Id: groupboards.pm,v 1.16 2012/11/11 17:33:18 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -105,7 +105,7 @@ 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);
@@ -117,8 +117,10 @@ sub handler {
''.&mt('View all group discussion boards').
'');
- if ($dellockoutcome ne 'ok') {
- $r->print(&mt('There was a problem removing a lockfile for the group ([_1]). This may prevent creation of additional bulletin boards in this group. Please contact the system administrator for your LON-CAPA domain.'));
+ if ($lockfreed ne 'ok') {
+ $r->print(&mt('There was a problem removing a lockfile for the group ([_1]).',$description).'
'.
+ &mt('This may prevent creation of additional bulletin boards in this group.').'
'.
+ &mt('Please contact the domain coordinator for your LON-CAPA domain.'));
}
} else {
$r->print(&mt('There was a problem creating the new discussion board - [_1]',''.$outcome.'').'
'.
@@ -191,56 +193,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 saving 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';
+ return ($error,$newurl,$bbtitle,$dellock);
}
- if (!$newurl) {
- return ($outcome,$newurl,$bbtitle,$dellockoutcome);
- }
- $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);
@@ -268,7 +232,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 {