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