Annotation of loncom/interface/groupboards.pm, revision 1.7
1.1 raeburn 1: # The LearningOnline Network
2: # Group Bulletin Boards Manager
3: #
4: # Copyright Michigan State University Board of Trustees
5: #
6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
7: #
8: # LON-CAPA is free software; you can redistribute it and/or modify
9: # it under the terms of the GNU General Public License as published by
10: # the Free Software Foundation; either version 2 of the License, or
11: # (at your option) any later version.
12: #
13: # LON-CAPA is distributed in the hope that it will be useful,
14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: # GNU General Public License for more details.
17: #
18: # You should have received a copy of the GNU General Public License
19: # along with LON-CAPA; if not, write to the Free Software
20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21: #
22: # /home/httpd/html/adm/gpl.txt
23: #
24: # http://www.lon-capa.org/
25: #
26:
27: package Apache::groupboards;
1.2 albertel 28:
1.1 raeburn 29: use strict;
30: use Apache::Constants qw(:common :http);
31: use Apache::loncommon;
32: use Apache::lonnet;
33: use Apache::lonuserstate;
34: use Apache::lonratedt;
35: use Apache::lonlocal;
36: use LONCAPA;
37:
38: sub handler {
39: my ($r) = @_;
40: &Apache::loncommon::content_type($r,'text/html');
41: $r->send_http_header;
42: return OK if $r->header_only;
43:
44: # Needs to be in a course
45: if (! ($env{'request.course.fn'})) {
46: # Not in a course
47: $env{'user.error.msg'}=
48: "/adm/groupboards:mdg:0:0:Cannot edit or view course groups";
49: return HTTP_NOT_ACCEPTABLE;
50: }
51:
52: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.7 ! raeburn 53: ['group','ref']);
1.1 raeburn 54:
55: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
56: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
57: my $now = time;
58: my $crstype = &Apache::loncommon::course_type();
59: my $gpterm = &Apache::loncommon::group_term();
1.5 raeburn 60: my $ucgpterm = $gpterm;
61: $ucgpterm =~ s/^(\w)/uc($1)/e;
1.1 raeburn 62: my $bodytitle = &mt('[_1] Discussion Boards',$crstype);
63: my $group = $env{'form.group'};
1.5 raeburn 64: $group =~ s/\W//g;
1.7 ! raeburn 65: my ($description,$earlyout,$refarg);
! 66:
! 67: if (exists($env{'form.ref'})) {
! 68: $refarg = 'ref='.$env{'form.ref'};
! 69: }
1.5 raeburn 70:
71: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.1 raeburn 72: if (!defined($group)) {
1.5 raeburn 73: $earlyout = &mt('No [_1] defined, so there are no [_1] discussion boards to display',$gpterm);
74: $r->print(&display_error($cdom,$cnum,$group,$description,$gpterm,
1.7 ! raeburn 75: $ucgpterm,$bodytitle,$earlyout,$refarg));
1.5 raeburn 76: return OK;
77: }
78: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
79: if (!defined($curr_groups{$group})) {
80: $earlyout = &mt('Invalid [_1]',$gpterm);
81: $r->print(&display_error($cdom,$cnum,$group,$description,$gpterm,
1.7 ! raeburn 82: $ucgpterm,$bodytitle,$earlyout,$refarg));
1.1 raeburn 83: return OK;
84: }
1.5 raeburn 85: my %content = &Apache::longroup::get_group_settings($curr_groups{$group});
1.6 albertel 86: $description = &unescape($content{'description'});
1.5 raeburn 87:
1.1 raeburn 88: my $can_create=&Apache::lonnet::allowed('cgb',$env{'request.course.id'}.
89: '/'.$group);
1.7 ! raeburn 90: my $can_view = &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.5 raeburn 91:
92: if (!$can_view) {
1.7 ! raeburn 93: $can_view = &Apache::lonnet::allowed('vgb',$env{'request.course.id'}.
1.1 raeburn 94: '/'.$group);
1.5 raeburn 95: }
96: if (!$can_view) {
97: $earlyout=&mt('You do not have privileges to view discussion boards in this [_1]',$gpterm);
98: $r->print(&display_error($cdom,$cnum,$group,$description,$gpterm,
1.7 ! raeburn 99: $ucgpterm,$bodytitle,$earlyout,$refarg));
1.5 raeburn 100: return OK;
101: }
1.1 raeburn 102: if (defined($env{'form.newbul'})) {
103: if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
1.5 raeburn 104: $r->print(&boards_header($cdom,$cnum,$group,$description,$gpterm,
1.7 ! raeburn 105: $ucgpterm,$bodytitle,$refarg));
1.4 raeburn 106: my ($outcome,$newurl,$bbtitle) =
1.2 albertel 107: &create_board($cdom,$cnum,$group,$env{'form.newbul'});
1.1 raeburn 108: if ($outcome eq 'ok') {
109: my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
110: $r->print(&mt('The new discussion board was added successfully.<br />'));
111: $r->print('<table border="0"><tr><td>'.
1.7 ! raeburn 112: '<a href="'.$newurl.'?group='.$group.'&'.$refarg.
! 113: '">'.&mt('Edit [_1] board',$bbtitle).'</a></td>'.
1.1 raeburn 114: '<td> </td><td>'.
1.7 ! raeburn 115: '<a href="/adm/groupboards?group='.$group.'&'.
! 116: $refarg.'">'.&mt('View all group discussion boards').
1.1 raeburn 117: '</a></td></tr></table>');
118: } else {
1.2 albertel 119: $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.'">'.
1.1 raeburn 120: &mt('Return to discussion boards').'</a>');
121: }
122: $r->print(&Apache::loncommon::end_page());
123: return OK;
124: }
125: }
126: my $jscript;
127: if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
128: $jscript = qq|
1.5 raeburn 129: <script type="text/javascript">
1.1 raeburn 130: function makebulboard() {
131: var title=prompt('Discussion Board Title');
132: if (title) {
133: this.document.forms.newbb.newbul.value=
134: title+'=/adm/$cdom/$cnum/$now/bulletinboard';
135: this.document.forms.newbb.submit();
136: }
137: }
1.5 raeburn 138: </script>
1.1 raeburn 139: |;
140: }
1.5 raeburn 141: $r->print(&boards_header($cdom,$cnum,$group,$description,$gpterm,$ucgpterm,
1.7 ! raeburn 142: $bodytitle,$refarg,$jscript));
1.4 raeburn 143: my ($groupboards,$boards) = &Apache::longroup::get_group_bbinfo($cdom,$cnum,
144: $group);
1.1 raeburn 145: if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
1.5 raeburn 146: $r->print('<br /><form method="post" name="newbb" action="/adm/groupboards">'.
1.1 raeburn 147: "\n".'<input type="button" name="bbbutton" value="'.
148: &mt('New Discussion Board').
149: '" onClick="javascript:makebulboard();" />'."\n".
1.7 ! raeburn 150: '<input type="hidden" name="newbul" />'."\n".
! 151: '<input type="hidden" name="group" value="'.$group.'" />'.
! 152: '<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />'.
1.1 raeburn 153: "\n".'</form><br />');
154: }
1.4 raeburn 155: if (@{$groupboards} > 0) {
1.5 raeburn 156: $r->print('<br />');
1.4 raeburn 157: foreach my $board (@{$groupboards}) {
1.5 raeburn 158: my $board_url = $$boards{$board}{'url'};
159: if ($board_url =~ /\?/) {
160: $board_url .= '&group='.$group;
161: } else {
162: $board_url .= '?group='.$group;
163: }
1.7 ! raeburn 164: $r->print('<a href="'.$board_url.'&'.$refarg.'">'.
! 165: $$boards{$board}{'title'}.'</a><br />');
1.1 raeburn 166: }
167: } else {
1.5 raeburn 168: $r->print('<br />'.&mt('There are currently no discussion boards in this [_1].',
1.1 raeburn 169: $gpterm));
170: }
171: $r->print(&Apache::loncommon::end_page());
172: return OK;
173: }
174:
175: sub create_board {
1.4 raeburn 176: my ($cdom,$cnum,$group,$newboard) = @_;
1.1 raeburn 177: my ($bbtitle,$newurl)=split(/\=/,$newboard);
1.5 raeburn 178: my $outcome;
179: my ($boardid) = ($newurl =~ m-/adm/\Q$cdom\E/\Q$cnum\E/(\d+)/bulletinboard-);
180: if (!$boardid) {
181: $outcome = ('error: the URL for new board was invalid');
182: return ($outcome,$newurl,$bbtitle);
183: }
1.1 raeburn 184: $bbtitle=&unescape($bbtitle);
185: $newurl=&unescape($newurl);
1.4 raeburn 186: my $allbbsmap = &Apache::longroup::get_bbfolder_url($cdom,$cnum,$group);
1.1 raeburn 187: if ($allbbsmap =~ m|^/uploaded|) {
188: my ($errtext,$fatal)=&Apache::lonratedt::mapread($allbbsmap);
189: if (!$fatal) {
190: my $newidx=&Apache::lonratedt::getresidx($newurl);
191: $Apache::lonratedt::resources[$newidx]=$bbtitle.':'.$newurl.
192: ':false:normal:res';
1.2 albertel 193: push(@Apache::lonratedt::order,$newidx);
1.1 raeburn 194: my ($errtext,$fatal)=&Apache::lonratedt::storemap($allbbsmap,1);
195: if ($fatal) {
1.2 albertel 196: $outcome = "error: failed to store discussion boards map - $errtext\n";
1.1 raeburn 197: } else {
1.5 raeburn 198: my %boardinfo = (
199: 'group' => $group,
200: );
201: $outcome = &Apache::lonnet::put('bulletinpage_'.$boardid,
202: \%boardinfo,$cdom,$cnum);
1.1 raeburn 203: }
204: } else {
1.2 albertel 205: $outcome = "error: failed to read all discussion boards map - $errtext\n";
1.1 raeburn 206: }
207: } else {
1.2 albertel 208: $outcome = 'error: discussion boards folder absent, '.
1.1 raeburn 209: 'or in unexpected location - '.$allbbsmap."\n";
210: }
1.4 raeburn 211: return ($outcome,$newurl,$bbtitle);
1.1 raeburn 212: }
213:
1.5 raeburn 214: sub display_error {
1.7 ! raeburn 215: my ($cdom,$cnum,$group,$description,$gpterm,$ucgpterm,$bodytitle,$earlyout,
! 216: $refarg)=@_;
1.5 raeburn 217: my $output = &boards_header($cdom,$cnum,$group,$description,$gpterm,
1.7 ! raeburn 218: $ucgpterm,$bodytitle,$refarg);
1.5 raeburn 219: $output .= $earlyout;
220: $output .= &Apache::loncommon::end_page();
221: return $output;
222: }
223:
224: sub boards_header {
1.7 ! raeburn 225: my ($cdom,$cnum,$group,$description,$gpterm,$ucgpterm,$bodytitle,$refarg,
! 226: $jscript)=@_;
1.5 raeburn 227: my $output = &Apache::loncommon::start_page($bodytitle,$jscript);
1.7 ! raeburn 228: if ($refarg) {
! 229: &Apache::lonhtmlcommon::add_breadcrumb
! 230: ({href=>"/adm/coursegroups",
! 231: text=>"Groups",
! 232: title=>"View course groups"},);
! 233: }
1.5 raeburn 234: &Apache::lonhtmlcommon::add_breadcrumb
1.7 ! raeburn 235: ({href=>"/adm/$cdom/$cnum/$group/smppg?$refarg",
1.5 raeburn 236: text=>"$ucgpterm: $description",
237: title=>"Go to group's home page"},
1.7 ! raeburn 238: {href=>"/adm/groupboards?group=$group&$refarg",
1.5 raeburn 239: text=>"Discussion Boards",
240: title=>"Display group discussion boards"},);
241: $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('[_1] discussion boards - [_2]',$gpterm,$description));
242: return $output;
243: }
244:
1.1 raeburn 245: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>