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