1: # The LearningOnline Network
2: # Bulletin Board Handler
3: #
4: # $Id: lonbulletin.pm,v 1.66 2012/12/07 17:15:56 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 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'},['forceedit','register','todocs',
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 ($forceedit,$forcestudent);
90: $forceedit = $env{'form.forceedit'};
91: if (!$forceedit) {
92: $forcestudent=1;
93: }
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 ($course_or_group,$brcrum);
129: if($group eq '') {
130: $course_or_group="Course";
131: } else {
132: $course_or_group="Group";
133: }
134: my $registered;
135: if ($group ne '' && $env{'form.group'} eq $group) {
136: unless ($env{'form.ref'} eq 'grouplist') {
137: $registered = $env{'form.register'};
138: }
139: my $gpterm = &Apache::loncommon::group_term();
140: my $ucgpterm = $gpterm;
141: $ucgpterm =~ s/^(\w)/uc($1)/e;
142: my ($groupboards,$boards) =
143: &Apache::longroup::get_group_bbinfo($dom,$crs,$group,$boardurl);
144: my $boardtitle;
145: if ((ref($groupboards) eq 'ARRAY') && (@{$groupboards} > 0)) {
146: $boardtitle = $$boards{$$groupboards[0]}{'title'};
147: }
148: $boardurl .= '?group='.$group;
149: if ($registered) {
150: $boardurl .= '&register='.$env{'form.register'};
151: } else {
152: $brcrum =
153: &groupboard_breadcrumbs($dom,$crs,$group,$refarg,$gpterm,
154: $ucgpterm,$grp_desc,$boardurl,
155: $boardtitle);
156: }
157: } else {
158: $registered = $env{'form.register'};
159: $brcrum = [];
160: }
161: my $start_page =
162: &Apache::loncommon::start_page("$course_or_group Discussion Board",undef,
163: {'add_entries' => \%addentries,
164: 'domain' => $dom,
165: 'bread_crumbs' => $brcrum,
166: 'group' => $group,
167: 'force_register' => $registered}
168: );
169: $r->print($start_page);
170: }
171: my ($allowed);
172: if ($group ne '') {
173: $allowed=&Apache::lonnet::allowed('mdg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
174: if (!$allowed) {
175: $allowed = &Apache::lonnet::allowed('cgb',$env{'request.course.id'}.
176: '/'.$group);
177: }
178: if (!$allowed) {
179: if ((!&Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) &&
180: (!&Apache::lonnet::allowed('vgb',$env{'request.course.id'}.
181: '/'.$group))) {
182: &print_end_page($r,$target);
183: return OK;
184: }
185: }
186: } else {
187: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
188: }
189:
190: if ($forcestudent or $target eq 'tex') { $allowed=0; }
191:
192: if (($env{'form.uploaddoc.filename'}) &&
193: ($env{'form.storeupl'}) && ($allowed)) {
194: if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
195: if ($syllabus{'uploaded.photourl'}) {
196: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
197: }
198: if ($group ne '') {
199: $syllabus{'uploaded.photourl'}=
200: &Apache::lonnet::userfileupload('uploaddoc','coursedoc',
201: 'bulletin/'.$group.'/'.$marker);
202: } else {
203: $syllabus{'uploaded.photourl'}=
204: &Apache::lonnet::userfileupload('uploaddoc','coursedoc',
205: 'bulletin/'.$marker);
206: }
207: }
208: $syllabus{'uploaded.lastmodified'}=time;
209: &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
210: }
211: if (($allowed) && ($env{'form.storesyl'})) {
212: foreach my $syl_field (keys(%syllabusfields)) {
213: my $field=$env{'form.'.$syl_field};
214: $field=~s/\s+$//s;
215: $field=&Apache::lonfeedback::clear_out_html($field,1);
216: $syllabus{$syl_field}=$field;
217: }
218: $syllabus{'uploaded.lastmodified'}=time;
219: &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
220: }
221:
222: # ---------------------------------------------------------------- Get discussion board
223: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
224: #Print Topic as Heading
225: my $titletext=&HTML::Entities::encode($syllabus{'aaa_title'},'<>&"');;
226: if ($target ne 'tex') {
227: $r->print('<h2>'.$titletext.'</h2>');
228: } else {
229: $r->print('\\\\\textbf{'.&Apache::lonxml::xmlparse($r,'tex',$titletext).'}\\\\');
230: }
231: #Outputbox and Inputbox for Topic
232: if ($allowed) {
233: $r->print('<form method="post" action="" enctype="multipart/form-data">');
234: &Apache::lontemplate::print_start_template($r,&mt('Title'),'LC_Box');
235: $r->print($titletext);
236: $r->print("<br /><div>");
237: &Apache::lontemplate::print_textarea_template($r, $syllabus{'aaa_title'},
238: 'aaa_title', Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
239: &Apache::lontemplate::print_saveall_template($r);
240: $r->print("</div>");
241: &Apache::lontemplate::print_end_template($r);
242: }
243: if ($syllabus{'uploaded.photourl'}) {
244: &Apache::lonnet::allowuploaded('/adm/syllabus',
245: $syllabus{'uploaded.photourl'});
246: }
247: #Outputbox and Inputbox for Image upload
248: if ($allowed) {
249: my $message = '<img src="'.$syllabus{'uploaded.photourl'}.'" alt="'.&mt('Image').'"/>';
250: &Apache::lontemplate::print_start_template($r, &mt('Upload a Photo'),'LC_Box');
251: $r->print($message);
252: $r->print("<br /><br />");
253: $r->print(
254: '<input type="hidden" name="forceedit" value="'.$env{'form.forceedit'}.'" />'.
255: '<input type="file" name="uploaddoc" size="50" />'.
256: '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />');
257: &Apache::lontemplate::print_end_template($r);
258: }
259: #Image in Student view.
260: elsif($syllabus{'uploaded.photourl'} && $target ne 'tex'){
261: $r->print('<img src="'.$syllabus{'uploaded.photourl'}.'" alt="'.&mt('Image').'"/>');
262: }
263:
264: my %custom_handlers = ( 'aaa_title' => sub {} );
265: &Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields,
266: $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_handlers);
267: if ($allowed) {
268: $r->print('</form>');
269: }
270: if ($target ne 'tex'){
271: $r->print('<br/><br/><hr/><br/>');
272: }
273: else {
274: $r->print(&Apache::lonxml::xmlparse($r,'tex','<br/><br/><hr/><br/>'));
275: }
276: } else {
277: if ($target ne 'tex') {
278: $r->print('<p>'.&mt('No page information provided.').'</p>');
279: }
280: }
281: #Lists discussion posts and box for a new discussion post.
282: if ($target ne 'tex') {
283: $r->print(&Apache::lonfeedback::list_discussion
284: ('board','OPEN','bulletin___'.$marker.'___'.
285: $r->uri,undef,$group));
286: } else {
287: $r->print('\\\\'.&Apache::lonxml::xmlparse($r,'tex',&Apache::lonfeedback::list_discussion
288: ('board','OPEN','bulletin___'.$marker.'___'.
289: $r->uri,undef,$group)));
290: }
291: &print_end_page($r,$target);
292: return OK;
293: }
294:
295: sub print_end_page {
296: my ($r,$target) = @_;
297: if ($target ne 'tex') {
298: $r->print(&Apache::loncommon::end_page());
299: } else {
300: $r->print('\end{document}');
301: }
302: }
303:
304: sub groupboard_breadcrumbs {
305: my ($cdom,$cnum,$group,$refarg,$gpterm,$ucgpterm,$description,$boardurl,
306: $boardtitle)= @_;
307: &Apache::lonhtmlcommon::clear_breadcrumbs();
308: my $brcrum = [];
309: if ($refarg ne '') {
310: push(@{$brcrum},
311: {href=>"/adm/coursegroups",
312: text=>"Groups",
313: title=>"View course groups"});
314: }
315: push(@{$brcrum},
316: {href=>"/adm/$cdom/$cnum/$group/smppg?$refarg",
317: text=>"$ucgpterm: $description",
318: title=>"Go to group's home page"},
319: {href=>"/adm/groupboards?group=$group&$refarg",
320: text=>"Discussion Boards",
321: title=>"Display group discussion boards"},
322: {href=>"$boardurl",
323: text=>"$boardtitle",
324: title=>"$boardtitle"},
325: );
326: return $brcrum;
327: }
328:
329: 1;
330: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>