version 1.1, 2006/06/30 08:14:31
|
version 1.4, 2006/06/30 18:27:19
|
Line 25
|
Line 25
|
# |
# |
|
|
package Apache::groupboards; |
package Apache::groupboards; |
|
|
use strict; |
use strict; |
use Apache::Constants qw(:common :http); |
use Apache::Constants qw(:common :http); |
use Apache::loncommon; |
use Apache::loncommon; |
Line 73 sub handler {
|
Line 73 sub handler {
|
if (defined($env{'form.newbul'})) { |
if (defined($env{'form.newbul'})) { |
if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) { |
if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) { |
$r->print(&Apache::loncommon::start_page($bodytitle)); |
$r->print(&Apache::loncommon::start_page($bodytitle)); |
my ($outcome,$symb,$newurl,$bbtitle) = &create_board($cdom,$cnum, |
my ($outcome,$newurl,$bbtitle) = |
$group, |
&create_board($cdom,$cnum,$group,$env{'form.newbul'}); |
$env{'form.newbul'}); |
|
if ($outcome eq 'ok') { |
if ($outcome eq 'ok') { |
my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum); |
my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum); |
$r->print(&mt('The new discussion board was added successfully.<br />')); |
$r->print(&mt('The new discussion board was added successfully.<br />')); |
$r->print('<table border="0"><tr><td>'. |
$r->print('<table border="0"><tr><td>'. |
'<a href="'.$newurl.'?register=1&symb='.$symb. |
'<a href="'.$newurl.'?group='.$group.'">'. |
'&group='.$group.'">'. |
|
&mt('Edit [_1] board',$bbtitle).'</a></td>'. |
&mt('Edit [_1] board',$bbtitle).'</a></td>'. |
'<td> </td><td>'. |
'<td> </td><td>'. |
'<a href="/adm/groupboards?group='.$group.'">'. |
'<a href="/adm/groupboards?group='.$group.'">'. |
&mt('View all group discussion boards'). |
&mt('View all group discussion boards'). |
'</a></td></tr></table>'); |
'</a></td></tr></table>'); |
} else { |
} else { |
$r->print(&mt('There was a problem creating the new discussion board - [_1]',$outcome).'<br /><a href="/adm/groupboards?group='.$group.'">'. |
$r->print(&mt('There was a problem creating the new discussion board - [_1]','<span class="LC_error">'.$outcome.'</span>').'<br /><a href="/adm/groupboards?group='.$group.'">'. |
&mt('Return to discussion boards').'</a>'); |
&mt('Return to discussion boards').'</a>'); |
} |
} |
$r->print(&Apache::loncommon::end_page()); |
$r->print(&Apache::loncommon::end_page()); |
Line 116 function makebulboard() {
|
Line 114 function makebulboard() {
|
return OK; |
return OK; |
} |
} |
my $navmap = Apache::lonnavmaps::navmap->new(); |
my $navmap = Apache::lonnavmaps::navmap->new(); |
my @groupboards; |
my ($groupboards,$boards) = &Apache::longroup::get_group_bbinfo($cdom,$cnum, |
my %boards; |
$group); |
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(); |
|
my $title = $res->title(); |
|
my $symb = $res->symb(); |
|
if ($url =~ m|^/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard|) { |
|
push(@groupboards,$symb); |
|
%{$boards{$symb}} = ( |
|
title => $title, |
|
url => $url, |
|
); |
|
} |
|
} |
|
} |
|
} |
|
if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) { |
if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) { |
$r->print('<form method="post" name="newbb" action="/adm/groupboards">'. |
$r->print('<form method="post" name="newbb" action="/adm/groupboards">'. |
"\n".'<input type="button" name="bbbutton" value="'. |
"\n".'<input type="button" name="bbbutton" value="'. |
Line 146 function makebulboard() {
|
Line 125 function makebulboard() {
|
' <input type="hidden" name="group" value="'.$group.'" />'. |
' <input type="hidden" name="group" value="'.$group.'" />'. |
"\n".'</form><br />'); |
"\n".'</form><br />'); |
} |
} |
if (@groupboards) { |
if (@{$groupboards} > 0) { |
foreach my $board (@groupboards) { |
foreach my $board (@{$groupboards}) { |
$r->print('<a href="'.$boards{$board}{'url'}.'?register=1&symb='.$board.'&group='.$group.'">'.$boards{$board}{'title'}.'</a><br />'); |
$r->print('<a href="'.$$boards{$board}{'url'}.'?group='.$group.'">'.$$boards{$board}{'title'}.'</a><br />'); |
} |
} |
} else { |
} 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].', |
Line 159 function makebulboard() {
|
Line 138 function makebulboard() {
|
} |
} |
|
|
sub create_board { |
sub create_board { |
my ($cdom,$cnum,$group,$newboard,$symb) = @_; |
my ($cdom,$cnum,$group,$newboard) = @_; |
my ($bbtitle,$newurl)=split(/\=/,$newboard); |
my ($bbtitle,$newurl)=split(/\=/,$newboard); |
$bbtitle=&unescape($bbtitle); |
$bbtitle=&unescape($bbtitle); |
$newurl=&unescape($newurl); |
$newurl=&unescape($newurl); |
my $allbbsmap = &get_bbfolder_url($cdom,$cnum,$group); |
my $allbbsmap = &Apache::longroup::get_bbfolder_url($cdom,$cnum,$group); |
my ($outcome,$symb); |
my ($outcome); |
if ($allbbsmap =~ m|^/uploaded|) { |
if ($allbbsmap =~ m|^/uploaded|) { |
my ($errtext,$fatal)=&Apache::lonratedt::mapread($allbbsmap); |
my ($errtext,$fatal)=&Apache::lonratedt::mapread($allbbsmap); |
if (!$fatal) { |
if (!$fatal) { |
my $newidx=&Apache::lonratedt::getresidx($newurl); |
my $newidx=&Apache::lonratedt::getresidx($newurl); |
$Apache::lonratedt::resources[$newidx]=$bbtitle.':'.$newurl. |
$Apache::lonratedt::resources[$newidx]=$bbtitle.':'.$newurl. |
':false:normal:res'; |
':false:normal:res'; |
$Apache::lonratedt::order[1+$#Apache::lonratedt::order]=$newidx; |
push(@Apache::lonratedt::order,$newidx); |
my ($errtext,$fatal)=&Apache::lonratedt::storemap($allbbsmap,1); |
my ($errtext,$fatal)=&Apache::lonratedt::storemap($allbbsmap,1); |
if ($fatal) { |
if ($fatal) { |
$outcome = "Error: failed to store discussion boards map - $errtext\n"; |
$outcome = "error: failed to store discussion boards map - $errtext\n"; |
} else { |
} else { |
$outcome = 'ok'; |
$outcome = 'ok'; |
$symb = &Apache::lonnet::encode_symb($allbbsmap,$newidx,$newurl); |
|
} |
} |
} else { |
} else { |
$outcome = "Error: failed to read all discussion boards map - $errtext\n"; |
$outcome = "error: failed to read all discussion boards map - $errtext\n"; |
} |
} |
} else { |
} else { |
$outcome = 'Error: discussion boards folder absent, '. |
$outcome = 'error: discussion boards folder absent, '. |
'or in unexpected location - '.$allbbsmap."\n"; |
'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; |
|
} |
} |
|
|
1; |
1; |