File:
[LON-CAPA] /
loncom /
interface /
groupboards.pm
Revision
1.23:
download - view:
text,
annotated -
select for diffs
Tue Sep 8 23:54:40 2020 UTC (4 years ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_12_X,
version_2_11_X,
version_2_11_5_msu,
version_2_11_5,
version_2_11_4_uiuc,
version_2_11_4_msu,
version_2_11_4,
version_2_11_3_uiuc,
version_2_11_3_msu,
version_2_11_3,
HEAD
- Prevent localization of group description in breadcrumbs for group tools.
1: # The LearningOnline Network
2: # Group Bulletin Boards Manager
3: #
4: # $Id: groupboards.pm,v 1.23 2020/09/08 23:54:40 raeburn 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 Apache::longroup;
37: use Apache::lonnavmaps;
38: use LONCAPA::map();
39: use Apache::lonlocal;
40: use LONCAPA;
41:
42: sub handler {
43: my ($r) = @_;
44: &Apache::loncommon::content_type($r,'text/html');
45: $r->send_http_header;
46: return OK if $r->header_only;
47:
48: # Needs to be in a course
49: if (! ($env{'request.course.fn'})) {
50: # Not in a course
51: $env{'user.error.msg'}=
52: "/adm/groupboards:mdg:0:0:Cannot edit or view course groups";
53: return HTTP_NOT_ACCEPTABLE;
54: }
55:
56: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
57: ['group','ref']);
58:
59: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
60: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
61: my $now = time;
62: my $crstype = &Apache::loncommon::course_type();
63: my $gpterm = &Apache::loncommon::group_term();
64: my $ucgpterm = $gpterm;
65: $ucgpterm =~ s/^(\w)/uc($1)/e;
66: my $bodytitle = $ucgpterm.' Discussion Boards';
67: my $group = $env{'form.group'};
68: $group =~ s/\W//g;
69: my ($description,$earlyout,$refarg);
70:
71: if (exists($env{'form.ref'})) {
72: $refarg = 'ref='.$env{'form.ref'};
73: }
74:
75: &Apache::lonhtmlcommon::clear_breadcrumbs();
76: if (!defined($group)) {
77: $earlyout = &mt("No $gpterm defined, so there are no $gpterm discussion boards to display");
78: $r->print(&display_error($cdom,$cnum,$group,$description,$gpterm,
79: $ucgpterm,$bodytitle,$earlyout,$refarg));
80: return OK;
81: }
82: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
83: if (!defined($curr_groups{$group})) {
84: $earlyout = &mt('Invalid group');
85: $r->print(&display_error($cdom,$cnum,$group,$description,$gpterm,
86: $ucgpterm,$bodytitle,$earlyout,$refarg));
87: return OK;
88: }
89: my %content = &Apache::longroup::get_group_settings($curr_groups{$group});
90: $description = &unescape($content{'description'});
91:
92: my $can_create=&Apache::lonnet::allowed('cgb',$env{'request.course.id'}.
93: '/'.$group);
94: my $can_view = &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
95:
96: if (!$can_view) {
97: $can_view = &Apache::lonnet::allowed('vgb',$env{'request.course.id'}.
98: '/'.$group);
99: }
100: if (!$can_view) {
101: $earlyout=&mt("You do not have privileges to view discussion boards in this $gpterm");
102: $r->print(&display_error($cdom,$cnum,$group,$description,$gpterm,
103: $ucgpterm,$bodytitle,$earlyout,$refarg));
104: return OK;
105: }
106: if (defined($env{'form.newbul'})) {
107: if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
108: $r->print(&boards_header($cdom,$cnum,$group,$description,$gpterm,
109: $ucgpterm,$bodytitle,$refarg));
110: my ($outcome,$newurl,$bbtitle,$lockfreed) =
111: &create_board($cdom,$cnum,$group,$env{'form.newbul'});
112: if ($outcome eq 'ok') {
113: my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
114: $r->print(&mt('The new discussion board was added successfully.').'<br />');
115: $r->print('<table border="0"><tr><td>'.
116: '<a href="'.$newurl.'?group='.$group.'&'.$refarg.
117: '">'.&mt('Edit [_1] board',$bbtitle).'</a></td>'.
118: '<td> </td><td>'.
119: '<a href="/adm/groupboards?group='.$group.'&'.
120: $refarg.'">'.&mt('View all group discussion boards').
121: '</a></td></tr></table>');
122: if ($lockfreed ne 'ok') {
123: $r->print(&mt('There was a problem removing a lockfile for the group ([_1]).',$description).'<br />'.
124: &mt('This may prevent creation of additional discussion boards in this group.').'<br />'.
125: &mt('Please contact the [_1]helpdesk[_2] for assistance.',
126: '<a href="/adm/helpdesk">','</a>')
127: );
128: }
129: } else {
130: $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.'">'.
131: &mt('Return to discussion boards').'</a>');
132: }
133: $r->print(&Apache::loncommon::end_page());
134: return OK;
135: }
136: }
137: my $jscript;
138: if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
139: $jscript = qq|
140: <script type="text/javascript">
141: function makebulboard() {
142: var title=prompt('Discussion Board Title');
143: if (title) {
144: this.document.forms.newbb.newbul.value=title;
145: this.document.forms.newbb.submit();
146: }
147: }
148: </script>
149: |;
150: }
151: $r->print(&boards_header($cdom,$cnum,$group,$description,$gpterm,$ucgpterm,
152: $bodytitle,$refarg,$jscript));
153: my ($groupboards,$boards) = &Apache::longroup::get_group_bbinfo($cdom,$cnum,
154: $group);
155: if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
156: $r->print('<br /><form method="post" name="newbb" action="/adm/groupboards">'.
157: "\n".'<input type="button" name="bbbutton" value="'.
158: &mt('New Discussion Board').
159: '" onclick="javascript:makebulboard();" />'."\n".
160: '<input type="hidden" name="newbul" />'."\n".
161: '<input type="hidden" name="group" value="'.$group.'" />'.
162: '<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />'.
163: "\n".'</form><br />');
164: }
165: if (@{$groupboards} > 0) {
166: $r->print('<br />'
167: .&Apache::loncommon::start_data_table()
168: .&Apache::loncommon::start_data_table_header_row()
169: .'<th>'.&mt('Discussion Boards').'</th>'
170: .&Apache::loncommon::end_data_table_header_row()
171: );
172: foreach my $board (@{$groupboards}) {
173: my $board_url = $$boards{$board}{'url'};
174: if ($board_url =~ /\?/) {
175: $board_url .= '&group='.$group;
176: } else {
177: $board_url .= '?group='.$group;
178: }
179: $r->print(&Apache::loncommon::start_data_table_row()
180: .'<td>'
181: .'<a href="'.$board_url.'&'.$refarg.'">'
182: .$$boards{$board}{'title'}.'</a>'
183: .'</td>'
184: .&Apache::loncommon::end_data_table_row()
185: );
186: }
187: $r->print(&Apache::loncommon::end_data_table());
188: } else {
189: $r->print('<p class="LC_info">'
190: .&mt('There are currently no discussion boards in this '.$gpterm.'.',)
191: .'</p>'
192: );
193: }
194: $r->print(&Apache::loncommon::end_page());
195: return OK;
196: }
197:
198: sub create_board {
199: my ($cdom,$cnum,$group,$bbtitle) = @_;
200: my ($outcome,$newurl,$idtype);
201: $bbtitle=&unescape($bbtitle);
202: $idtype = 'inc';
203: my ($boardid,$dellock,$error) =
204: &Apache::lonnet::get_timebased_id($group,'boardids','groupboards',
205: $cdom,$cnum);
206: if ($boardid) {
207: $newurl = '/adm/'.$cdom.'/'.$cnum.'/'.$boardid.'/bulletinboard';
208: } else {
209: return ($error,$newurl,$bbtitle,$dellock);
210: }
211:
212: # need to check here if group_boards_$group.sequence is in the course
213: # if not - add it as an item in group_folder_$group.sequence
214: my $allbbsmap = &Apache::longroup::get_bbfolder_url($cdom,$cnum,$group);
215: if ($allbbsmap =~ m|^/uploaded|) {
216: my ($errtext,$fatal)=&LONCAPA::map::mapread($allbbsmap);
217: if (!$fatal) {
218: my $newidx=&LONCAPA::map::getresidx($newurl);
219: $LONCAPA::map::resources[$newidx]=$bbtitle.':'.$newurl.
220: ':false:normal:res';
221: push(@LONCAPA::map::order,$newidx);
222: my ($errtext,$fatal)=&LONCAPA::map::storemap($allbbsmap,1,1);
223: if ($fatal) {
224: $outcome = "error: failed to save discussion boards map - $errtext\n";
225: } else {
226: my %boardinfo = (
227: 'group' => $group,
228: );
229: $outcome = &Apache::lonnet::put('bulletinpage_'.$boardid,
230: \%boardinfo,$cdom,$cnum);
231: }
232: } else {
233: $outcome = "error: failed to read all discussion boards map - $errtext\n";
234: }
235: } else {
236: $outcome = 'error: discussion boards folder absent, '.
237: 'or in unexpected location - '.$allbbsmap."\n";
238: }
239: return ($outcome,$newurl,$bbtitle,$dellock);
240: }
241:
242: sub display_error {
243: my ($cdom,$cnum,$group,$description,$gpterm,$ucgpterm,$bodytitle,$earlyout,
244: $refarg)=@_;
245: my $output = &boards_header($cdom,$cnum,$group,$description,$gpterm,
246: $ucgpterm,$bodytitle,$refarg);
247: $output .= $earlyout;
248: $output .= &Apache::loncommon::end_page();
249: return $output;
250: }
251:
252: sub boards_header {
253: my ($cdom,$cnum,$group,$description,$gpterm,$ucgpterm,$bodytitle,$refarg,
254: $jscript)=@_;
255: my $output = &Apache::loncommon::start_page($bodytitle,$jscript);
256: if ($refarg) {
257: &Apache::lonhtmlcommon::add_breadcrumb
258: ({href=>"/adm/coursegroups",
259: text=>"Groups",
260: title=>"View course groups"},);
261: }
262: my $view_permission =
263: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
264: my $navmap=Apache::lonnavmaps::navmap->new();
265: my $grouppagelink = &Apache::longroup::get_group_link($cdom,$cnum,$group,$navmap,$view_permission,$refarg);
266: if ($grouppagelink) {
267: &Apache::lonhtmlcommon::add_breadcrumb
268: ({href=>$grouppagelink,
269: text=>&mt('Group').": $description",
270: title=>&mt("Go to group's home page"),
271: no_mt=>1});
272: } else {
273: &Apache::lonhtmlcommon::add_breadcrumb
274: ({text=>&mt('Group').": $description",
275: no_mt=>1});
276: }
277: &Apache::lonhtmlcommon::add_breadcrumb
278: ({href=>"/adm/groupboards?group=$group&$refarg",
279: text=>"Discussion Boards",
280: title=>"Display group discussion boards"},);
281: $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('Group discussion boards - [_1]',$description),
282: undef,undef,undef,undef,1);
283: return $output;
284: }
285:
286: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>