1: # The LearningOnline Network
2: # Bulletin Board Handler
3: #
4: # $Id: lonbulletin.pm,v 1.40 2006/08/28 13:02:24 albertel 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::lonlocal;
38: use Apache::lonhtmlcommon;
39: use HTML::Entities();
40: use LONCAPA;
41:
42: sub handler {
43: my $r = shift;
44: &Apache::loncommon::content_type($r,'text/html');
45: $r->send_http_header;
46: return OK if $r->header_only;
47: my $target=$env{'form.grade_target'};
48:
49: # ------------------------------------------------------------ Print the screen
50: if ($target eq 'tex') {
51: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
52: }
53: my (undef,undef,undef,undef,$marker)=split(/\//,$r->uri);
54: # Is this even in a course?
55: if (!$env{'request.course.id'}) {
56: &Apache::loncommon::simple_error_page($r,'Not in a course',
57: 'Not in a course');
58: return OK;
59: }
60:
61: $marker=~s/\D//g;
62:
63: if (!$marker) {
64: &Apache::loncommon::simple_error_page($r,'Invalid Call',
65: 'Invalid Call');
66: return OK;
67: }
68:
69: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
70: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
71: my ($group,$grp_desc);
72:
73: # --------------------------------------------------------- The syllabus fields
74: my %syllabusfields=&Apache::lonlocal::texthash(
75: 'aaa_title' => 'Topic',
76: 'bbb_content' => 'Task',
77: 'ccc_webreferences' => 'Web References');
78:
79: # ------------------------------------------------------------ Get Query String
80: &Apache::loncommon::get_unprocessed_cgi
81: ($ENV{'QUERY_STRING'},['forcestudent','forceedit','register',
82: 'origpage','group','ref']);
83: # ----------------------------------------------------- Force menu registration
84: my %addentries;
85: if ($env{'form.origpage'}) {
86: $addentries{'onload'} = "document.location='#newpost';";
87: }
88: # --------------------------------------------------------------- Force Student
89: my $forcestudent='';
90: if ($env{'form.forcestudent'}) { $forcestudent='student'; }
91:
92: my $forceedit='';
93: if ($env{'form.forceedit'}) { $forceedit='edit'; }
94: my $refarg = '';
95: if (exists($env{'form.ref'})) { $refarg = 'ref='.$env{'form.ref'}; }
96:
97: my %syllabus=&Apache::lonnet::dump('bulletinpage_'.$marker,$dom,$crs);
98:
99: my $boardurl = $r->uri;
100: if ($boardurl =~ m|/adm/\Q$dom\E/\Q$crs\E/\d+/bulletinboard|) {
101: if (!exists($syllabus{'group'})) {
102: &Apache::loncommon::simple_error_page($r,'Group information missing',
103: 'Group information missing');
104:
105: return OK;
106: } else {
107: $group = $syllabus{'group'};
108: if ($group eq '') {
109: &Apache::loncommon::simple_error_page($r,'Invalid group',
110: 'Invalid group');
111: return OK;
112: }
113: my %curr_groups = &Apache::longroup::coursegroups($dom,$crs,$group);
114: if (!defined($curr_groups{$group})) {
115: &Apache::loncommon::simple_error_page($r,'Invalid group',
116: 'Invalid group');
117: return OK;
118: } else {
119: my %content = &Apache::longroup::get_group_settings(
120: $curr_groups{$group});
121: $grp_desc = &unescape($content{'description'});
122: }
123: }
124: }
125:
126: # --------------------------------------- There is such a user, get environment
127: if ($target ne 'tex') {
128: my $start_page =
129: &Apache::loncommon::start_page("Bulletin Board/Discussion",undef,
130: {'function' => $forcestudent,
131: 'add_entries' => \%addentries,
132: 'domain' => $dom,
133: 'force_register' =>
134: $env{'form.register'}});
135: $r->print($start_page);
136: if ($group ne '' && $env{'form.group'} eq $group) {
137: my $gpterm = &Apache::loncommon::group_term();
138: my $ucgpterm = $gpterm;
139: $ucgpterm =~ s/^(\w)/uc($1)/e;
140: my ($groupboards,$boards) =
141: &Apache::longroup::get_group_bbinfo($dom,$crs,$group,$boardurl);
142: my $boardtitle;
143: if ((ref($groupboards) eq 'ARRAY') && (@{$groupboards} > 0)) {
144: $boardtitle = $$boards{$$groupboards[0]}{'title'};
145: }
146: $boardurl .= '?register=1&group='.$group;
147: $r->print(&groupboard_breadcrumbs($dom,$crs,$group,$refarg,$gpterm,
148: $ucgpterm,$grp_desc,$boardurl,$boardtitle));
149: }
150: }
151: my ($allowed);
152: if ($group ne '') {
153: $allowed=&Apache::lonnet::allowed('mdg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
154: if (!$allowed) {
155: $allowed = &Apache::lonnet::allowed('cgb',$env{'request.course.id'}.
156: '/'.$group);
157: }
158: if (!$allowed) {
159: if ((!&Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) &&
160: (!&Apache::lonnet::allowed('vgb',$env{'request.course.id'}.
161: '/'.$group))) {
162: &print_end_page($r,$target);
163: return OK;
164: }
165: }
166: } else {
167: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
168: }
169:
170: my $privileged=$allowed;
171: if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
172: $forcestudent='student';
173: }
174: if ($target ne 'tex') { $r->print('<table><tr><td>'); }
175: if ($forcestudent or $target eq 'tex') { $allowed=0; }
176:
177: if ($allowed) {
178: my $query_str = 'forcestudent=1';
179: if (($group ne '') && ($env{'form.group'} eq $group)) {
180: $query_str.='&group='.$group.'&'.$refarg;
181: }
182: $r->print(
183: '<p>'.
184: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'<br /><a href="'.$r->uri.'?'.$query_str.'"><font size="+1">'.&mt('Show Student View').'</font></a>'.
185: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
186: } elsif ($privileged and $target ne 'tex') {
187: my $query_str = 'forceedit=edit';
188: if (($group ne '') && ($env{'form.group'} eq $group)) {
189: $query_str.='&group='.$group.'&'.$refarg;
190: }
191: $r->print('<a href="'.$r->uri.'?'.$query_str.'"><font size="+1">'
192: .&mt('Edit').'</font></a>');
193: }
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',1,
204: 'bulletin/'.$group.'/'.$marker);
205: } else {
206: $syllabus{'uploaded.photourl'}=
207: &Apache::lonnet::userfileupload('uploaddoc',1,
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 (keys %syllabusfields) {
216: my $field=$env{'form.'.$_};
217: $field=~s/\s+$//s;
218: $field=&Apache::lonfeedback::clear_out_html($field,1);
219: $syllabus{$_}=$field;
220: }
221: $syllabus{'uploaded.lastmodified'}=time;
222: &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
223: }
224:
225: # ---------------------------------------------------------------- Get syllabus
226: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
227: if ($syllabus{'uploaded.photourl'}) {
228: &Apache::lonnet::allowuploaded('/adm/syllabus',
229: $syllabus{'uploaded.photourl'});
230: $r->print('<img src="'.$syllabus{'uploaded.photourl'}.
231: '" align="right" />');
232: }
233: if ($allowed) {
234: $r->print(
235: '<form method="post" enctype="multipart/form-data">'.
236: '<input type="hidden" name="forceedit" value="edit" />'.
237: '<h3>'.&mt('Upload a Photo').'</h3>'.
238: '<input type="file" name="uploaddoc" size="50">'.
239: '<input type="submit" name="storeupl" value="'.&mt('Upload').'">'.
240: '</form><form method="post">');
241: }
242: foreach (sort keys %syllabusfields) {
243: if (($syllabus{$_}) || ($allowed)) {
244: my $message=$syllabus{$_};
245: &Apache::lonfeedback::newline_to_br(\$message);
246: $message
247: =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
248: if ($allowed) {
249: $message=&Apache::lonspeller::markeduptext($message);
250: }
251: $message=&Apache::lontexconvert::msgtexconverted($message);
252: unless ($_ eq 'aaa_title') {
253: if (($_ ne 'bbb_content') || ($allowed)) {
254: if ($target ne 'tex') {
255: $r->print('<h3>'.$syllabusfields{$_}.'</h3>');
256: } else {
257: $r->print('\\\\\textbf{'.$syllabusfields{$_}.'}\\\\');
258: }
259: }
260: if ($target ne 'tex') {
261: $r->print('<blockquote>'.
262: $message.'</blockquote>');
263: } else {
264: $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$message).' ');
265: }
266: if ($allowed) {
267: $r->print('<br /><textarea cols="80" rows="10" name="'.$_.'">'.
268: &HTML::Entites::encode($syllabus{$_},'&"<>').
269: '</textarea><input type="submit" name="storesyl" value="'.&mt('Store').'" />');
270: }
271: } else {
272: if ($target ne 'tex') {
273: $r->print('<h1>'.$message.'</h1>');
274: } else {
275: $r->print('\\\\\textbf{'.&Apache::lonxml::xmlparse($r,'tex',$message).'}\\\\');
276: }
277: if ($allowed) {
278: $r->print(
279: '<br />'.&mt('Topic').'<br /><textarea cols="80" rows="2" name="'.$_.'">'.
280: &HTML::Entites::encode($syllabus{$_},'&"<>').
281: '</textarea><input type="submit" name="storesyl" value="'.&mt('Store').'" />');
282: }
283: }
284: }
285: }
286: if ($allowed) {
287: $r->print('</form>');
288: }
289: if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
290: } else {
291: $r->print('<p>'.&mt('No page information provided.').'</p>');
292: }
293: if ($target ne 'tex') { $r->print('</td></tr></table>'); }
294: if ($target ne 'tex') {
295: $r->print(&Apache::lonfeedback::list_discussion
296: ('board','OPEN','bulletin___'.$marker.'___'.
297: $r->uri,undef,$group));
298: } else {
299: $r->print('\\\\'.&Apache::lonxml::xmlparse($r,'tex',&Apache::lonfeedback::list_discussion
300: ('board','OPEN','bulletin___'.$marker.'___'.
301: $r->uri,undef,$group)));
302: }
303: &print_end_page($r,$target);
304: return OK;
305: }
306:
307: sub print_end_page {
308: my ($r,$target) = @_;
309: if ($target ne 'tex') {
310: $r->print(&Apache::loncommon::end_page());
311: } else {
312: $r->print('\end{document}');
313: }
314: }
315:
316: sub groupboard_breadcrumbs {
317: my ($cdom,$cnum,$group,$refarg,$gpterm,$ucgpterm,$description,$boardurl,
318: $boardtitle)= @_;
319: &Apache::lonhtmlcommon::clear_breadcrumbs();
320: if ($refarg ne '') {
321: &Apache::lonhtmlcommon::add_breadcrumb
322: ({href=>"/adm/coursegroups",
323: text=>"Groups",
324: title=>"View course groups"});
325: }
326: &Apache::lonhtmlcommon::add_breadcrumb
327: ({href=>"/adm/$cdom/$cnum/$group/smppg?$refarg",
328: text=>"$ucgpterm: $description",
329: title=>"Go to group's home page"},
330: {href=>"/adm/groupboards?group=$group&$refarg",
331: text=>"Discussion Boards",
332: title=>"Display group discussion boards"},
333: {href=>"$boardurl",
334: text=>"$boardtitle",
335: title=>"$boardtitle"},
336: );
337: my $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('[_1] discussion boards - [_2]',$gpterm,$description));
338: return $output;
339: }
340:
341: 1;
342: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>