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