File:
[LON-CAPA] /
loncom /
interface /
lonbulletin.pm
Revision
1.69:
download - view:
text,
annotated -
select for diffs
Tue Sep 8 23:54:40 2020 UTC (3 years, 11 months 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: # Bulletin Board Handler
3: #
4: # $Id: lonbulletin.pm,v 1.69 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::lonbulletin;
30:
31: use strict;
32: use Apache::Constants qw(:common);
33: use Apache::loncommon;
34: use Apache::lonnet;
35: use Apache::lontexconvert;
36: use Apache::lonfeedback;
37: use Apache::lonhtmlgateway;
38: use Apache::lonlocal;
39: use Apache::lonhtmlcommon;
40: use Apache::longroup;
41: use Apache::lonnavmaps;
42: use HTML::Entities();
43: use LONCAPA;
44:
45: sub handler {
46: my $r = shift;
47: &Apache::loncommon::content_type($r,'text/html');
48: $r->send_http_header;
49: return OK if $r->header_only;
50: my $target=$env{'form.grade_target'};
51:
52: # ------------------------------------------------------------ Print the screen
53: if ($target eq 'tex') {
54: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
55: }
56: my (undef,undef,undef,undef,$marker)=split(/\//,$r->uri);
57: # Is this even in a course?
58: if (!$env{'request.course.id'}) {
59: &Apache::loncommon::simple_error_page($r,'Not in a course',
60: 'Not in a course');
61: return OK;
62: }
63:
64: $marker=~s/\D//g;
65:
66: if (!$marker) {
67: &Apache::loncommon::simple_error_page($r,'Invalid Call',
68: 'Invalid Call');
69: return OK;
70: }
71:
72: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
73: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
74: my ($group,$grp_desc);
75:
76: # --------------------------------------------------------- The syllabus fields
77: my %syllabusfields=&Apache::lonlocal::texthash(
78: 'aaa_title' => 'Topic',
79: 'bbb_content' => 'Task',
80: 'ccc_webreferences' => 'Web References');
81:
82: # ------------------------------------------------------------ Get Query String
83: &Apache::loncommon::get_unprocessed_cgi
84: ($ENV{'QUERY_STRING'},['forceedit','register','todocs',
85: 'origpage','group','ref']);
86: # ----------------------------------------------------- Force menu registration
87: my %addentries;
88: if ($env{'form.origpage'}) {
89: $addentries{'onload'} = "document.location='#newpost';";
90: }
91: # --------------------------------------------------------------- Force Student
92: my ($forceedit,$forcestudent);
93: $forceedit = $env{'form.forceedit'};
94: if (!$forceedit) {
95: $forcestudent=1;
96: }
97: my $refarg = '';
98: if (exists($env{'form.ref'})) { $refarg = 'ref='.$env{'form.ref'}; }
99:
100: my %syllabus=&Apache::lonnet::dump('bulletinpage_'.$marker,$dom,$crs);
101:
102: my $boardurl = $r->uri;
103: if ($boardurl =~ m|/adm/\Q$dom\E/\Q$crs\E/\d+/bulletinboard|) {
104: if (!exists($syllabus{'group'})) {
105: &Apache::loncommon::simple_error_page($r,'Group information missing',
106: 'Group information missing');
107:
108: return OK;
109: } else {
110: $group = $syllabus{'group'};
111: if ($group eq '') {
112: &Apache::loncommon::simple_error_page($r,'Invalid group',
113: 'Invalid group');
114: return OK;
115: }
116: my %curr_groups = &Apache::longroup::coursegroups($dom,$crs,$group);
117: if (!defined($curr_groups{$group})) {
118: &Apache::loncommon::simple_error_page($r,'Invalid group',
119: 'Invalid group');
120: return OK;
121: } else {
122: my %content = &Apache::longroup::get_group_settings(
123: $curr_groups{$group});
124: $grp_desc = &unescape($content{'description'});
125: }
126: }
127: }
128:
129: # --------------------------------------- There is such a user, get environment
130: if ($target ne 'tex') {
131: my ($course_or_group,$brcrum);
132: if($group eq '') {
133: $course_or_group="Course";
134: } else {
135: $course_or_group="Group";
136: }
137: my $registered;
138: if ($group ne '' && $env{'form.group'} eq $group) {
139: unless ($env{'form.ref'} eq 'grouplist') {
140: $registered = $env{'form.register'};
141: }
142: my $gpterm = &Apache::loncommon::group_term();
143: my $ucgpterm = $gpterm;
144: $ucgpterm =~ s/^(\w)/uc($1)/e;
145: my ($groupboards,$boards) =
146: &Apache::longroup::get_group_bbinfo($dom,$crs,$group,$boardurl);
147: my $boardtitle;
148: if ((ref($groupboards) eq 'ARRAY') && (@{$groupboards} > 0)) {
149: $boardtitle = $$boards{$$groupboards[0]}{'title'};
150: }
151: $boardurl .= '?group='.$group;
152: if ($registered) {
153: $boardurl .= '&register='.$env{'form.register'};
154: } else {
155: $brcrum =
156: &groupboard_breadcrumbs($dom,$crs,$group,$refarg,$gpterm,
157: $ucgpterm,$grp_desc,$boardurl,
158: $boardtitle);
159: }
160: } else {
161: $registered = $env{'form.register'};
162: $brcrum = [];
163: }
164: my $start_page =
165: &Apache::loncommon::start_page("$course_or_group Discussion Board",undef,
166: {'add_entries' => \%addentries,
167: 'domain' => $dom,
168: 'bread_crumbs' => $brcrum,
169: 'group' => $group,
170: 'force_register' => $registered}
171: );
172: $r->print($start_page);
173: }
174: my ($allowed);
175: if ($group ne '') {
176: $allowed=&Apache::lonnet::allowed('mdg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
177: if (!$allowed) {
178: $allowed = &Apache::lonnet::allowed('cgb',$env{'request.course.id'}.
179: '/'.$group);
180: }
181: if (!$allowed) {
182: if ((!&Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) &&
183: (!&Apache::lonnet::allowed('vgb',$env{'request.course.id'}.
184: '/'.$group))) {
185: &print_end_page($r,$target);
186: return OK;
187: }
188: }
189: } else {
190: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
191: }
192:
193: if ($forcestudent or $target eq 'tex') { $allowed=0; }
194:
195: if (($env{'form.uploaddoc.filename'}) &&
196: ($env{'form.storeupl'}) && ($allowed)) {
197: if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
198: if ($syllabus{'uploaded.photourl'}) {
199: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
200: }
201: if ($group ne '') {
202: $syllabus{'uploaded.photourl'}=
203: &Apache::lonnet::userfileupload('uploaddoc','coursedoc',
204: 'bulletin/'.$group.'/'.$marker);
205: } else {
206: $syllabus{'uploaded.photourl'}=
207: &Apache::lonnet::userfileupload('uploaddoc','coursedoc',
208: 'bulletin/'.$marker);
209: }
210: }
211: $syllabus{'uploaded.lastmodified'}=time;
212: &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
213: }
214: if (($allowed) && ($env{'form.storesyl'})) {
215: foreach my $syl_field (keys(%syllabusfields)) {
216: my $field=$env{'form.'.$syl_field};
217: chomp($field);
218: my $gateway = Apache::lonhtmlgateway->new();
219: $field = $gateway->process_incoming_html($field,1);
220: $syllabus{$syl_field}=$field;
221: }
222: $syllabus{'uploaded.lastmodified'}=time;
223: &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
224: }
225:
226: # ---------------------------------------------------------------- Get discussion board
227: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
228: #Print Topic as Heading
229: my $titletext=&HTML::Entities::encode($syllabus{'aaa_title'},'<>&"');;
230: if ($target ne 'tex') {
231: $r->print('<h2>'.$titletext.'</h2>');
232: } else {
233: $r->print('\\\\\textbf{'.&Apache::lonxml::xmlparse($r,'tex',$titletext).'}\\\\');
234: }
235: #Outputbox and Inputbox for Topic
236: if ($allowed) {
237: $r->print('<form method="post" action="" enctype="multipart/form-data">');
238: &Apache::lontemplate::print_start_template($r,&mt('Title'),'LC_Box');
239: $r->print($titletext);
240: $r->print("<br /><div>");
241: &Apache::lontemplate::print_textarea_template($r, $syllabus{'aaa_title'},
242: 'aaa_title', Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
243: &Apache::lontemplate::print_saveall_template($r);
244: $r->print("</div>");
245: &Apache::lontemplate::print_end_template($r);
246: }
247: if ($syllabus{'uploaded.photourl'}) {
248: &Apache::lonnet::allowuploaded('/adm/syllabus',
249: $syllabus{'uploaded.photourl'});
250: }
251: #Outputbox and Inputbox for Image upload
252: if ($allowed) {
253: my $message = '<img src="'.$syllabus{'uploaded.photourl'}.'" alt="'.&mt('Image').'"/>';
254: &Apache::lontemplate::print_start_template($r, &mt('Upload a Photo'),'LC_Box');
255: $r->print($message);
256: $r->print("<br /><br />");
257: $r->print(
258: '<input type="hidden" name="forceedit" value="'.$env{'form.forceedit'}.'" />'.
259: '<input type="file" name="uploaddoc" size="50" />'.
260: '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />');
261: &Apache::lontemplate::print_end_template($r);
262: }
263: #Image in Student view.
264: elsif($syllabus{'uploaded.photourl'} && $target ne 'tex'){
265: $r->print('<img src="'.$syllabus{'uploaded.photourl'}.'" alt="'.&mt('Image').'"/>');
266: }
267:
268: my %custom_handlers = ( 'aaa_title' => sub {} );
269: &Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields,
270: $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_handlers);
271: if ($allowed) {
272: $r->print('</form>');
273: }
274: if ($target ne 'tex'){
275: $r->print('<br/><br/><hr/><br/>');
276: }
277: else {
278: $r->print(&Apache::lonxml::xmlparse($r,'tex','<br/><br/><hr/><br/>'));
279: }
280: } else {
281: if ($target ne 'tex') {
282: $r->print('<p>'.&mt('No page information provided.').'</p>');
283: }
284: }
285: #Lists discussion posts and box for a new discussion post.
286: if ($target ne 'tex') {
287: $r->print(&Apache::lonfeedback::list_discussion
288: ('board','OPEN','bulletin___'.$marker.'___'.
289: $r->uri,undef,$group));
290: } else {
291: $r->print('\\\\'.&Apache::lonxml::xmlparse($r,'tex',&Apache::lonfeedback::list_discussion
292: ('board','OPEN','bulletin___'.$marker.'___'.
293: $r->uri,undef,$group)));
294: }
295: &print_end_page($r,$target);
296: return OK;
297: }
298:
299: sub print_end_page {
300: my ($r,$target) = @_;
301: if ($target ne 'tex') {
302: $r->print(&Apache::loncommon::end_page());
303: } else {
304: $r->print('\end{document}');
305: }
306: }
307:
308: sub groupboard_breadcrumbs {
309: my ($cdom,$cnum,$group,$refarg,$gpterm,$ucgpterm,$description,$boardurl,
310: $boardtitle)= @_;
311: &Apache::lonhtmlcommon::clear_breadcrumbs();
312: my $brcrum = [];
313: if ($refarg ne '') {
314: push(@{$brcrum},
315: {href=>"/adm/coursegroups",
316: text=>"Groups",
317: title=>"View course groups"});
318: }
319: my $view_permission =
320: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
321: my $navmap=Apache::lonnavmaps::navmap->new();
322: my $grouppagelink = &Apache::longroup::get_group_link($cdom,$cnum,$group,$navmap,$view_permission,$refarg);
323: if ($grouppagelink) {
324: push(@{$brcrum},
325: {href=>$grouppagelink,
326: text=>&mt('Group').": $description",
327: title=>&mt("Go to group's home page"),
328: no_mt=>1,},
329: );
330: } else {
331: push(@{$brcrum},
332: {text=>&mt('Group').": $description",
333: no_mt=>1,}
334: );
335: }
336: push(@{$brcrum},
337: {href=>"/adm/groupboards?group=$group&$refarg",
338: text=>"Discussion Boards",
339: title=>"Display group discussion boards"},
340: {href=>"$boardurl",
341: text=>"$boardtitle",
342: title=>"$boardtitle",
343: no_mt=>1},
344: );
345: return $brcrum;
346: }
347:
348: 1;
349: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>