File:
[LON-CAPA] /
loncom /
interface /
lonbulletin.pm
Revision
1.61:
download - view:
text,
annotated -
select for diffs
Sat Aug 7 19:23:50 2010 UTC (14 years ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_10_0_RC1,
HEAD
- Eliminate routines no longer needed following switch from FCKEditor 2 to CKEdi
tor 3
- Eliminate checking for environment.wysiwygeditor (no longer used).
- Access to "Richtext" editor available via link on each textarea for which it is
to be made available.
- When editing an HTML document provide "Edit Math" button to allow
insertion of TeX within the textarea. Button is hidden if Richtext editor in use.
- Additional tags permitted by clear_out_html() - <pre> and <chem>.
1: # The LearningOnline Network
2: # Bulletin Board Handler
3: #
4: # $Id: lonbulletin.pm,v 1.61 2010/08/07 19:23: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 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 $course_or_group;
129: if($group eq '') {
130: $course_or_group="Course";
131: } else {
132: $course_or_group="Group";
133: }
134: my $start_page =
135: &Apache::loncommon::start_page("$course_or_group Discussion Board",undef,
136: {'function' => $forcestudent,
137: 'add_entries' => \%addentries,
138: 'domain' => $dom,
139: 'force_register' =>
140: $env{'form.register'}});
141: $r->print($start_page);
142: if ($group ne '' && $env{'form.group'} eq $group) {
143: my $gpterm = &Apache::loncommon::group_term();
144: my $ucgpterm = $gpterm;
145: $ucgpterm =~ s/^(\w)/uc($1)/e;
146: my ($groupboards,$boards) =
147: &Apache::longroup::get_group_bbinfo($dom,$crs,$group,$boardurl);
148: my $boardtitle;
149: if ((ref($groupboards) eq 'ARRAY') && (@{$groupboards} > 0)) {
150: $boardtitle = $$boards{$$groupboards[0]}{'title'};
151: }
152: $boardurl .= '?register=1&group='.$group;
153: $r->print(&groupboard_breadcrumbs($dom,$crs,$group,$refarg,$gpterm,
154: $ucgpterm,$grp_desc,$boardurl,$boardtitle));
155: }
156: }
157: my ($allowed);
158: if ($group ne '') {
159: $allowed=&Apache::lonnet::allowed('mdg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
160: if (!$allowed) {
161: $allowed = &Apache::lonnet::allowed('cgb',$env{'request.course.id'}.
162: '/'.$group);
163: }
164: if (!$allowed) {
165: if ((!&Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) &&
166: (!&Apache::lonnet::allowed('vgb',$env{'request.course.id'}.
167: '/'.$group))) {
168: &print_end_page($r,$target);
169: return OK;
170: }
171: }
172: } else {
173: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
174: }
175:
176: my $privileged=$allowed;
177: if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
178: $forcestudent='student';
179: }
180: if ($forcestudent or $target eq 'tex') { $allowed=0; }
181:
182: if ($allowed) {
183: my $query_str = 'forcestudent=1';
184: if (($group ne '') && ($env{'form.group'} eq $group)) {
185: $query_str.='&group='.$group.'&'.$refarg;
186: }
187: if ($env{'form.register'}) {
188: $query_str .= '&register='.$env{'form.register'};
189: }
190: #Function Box for Edit Mode.
191: my $functionbox = &Apache::lonhtmlcommon::start_funclist();
192: $functionbox .= &Apache::lonhtmlcommon::add_item_funclist(
193: '<a href="'.$r->uri.'?'.$query_str.'">'.&mt('Show Student View').'</a>'.
194: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView'));
195: $functionbox.=&Apache::lonhtmlcommon::end_funclist();
196: $r->print(&Apache::loncommon::head_subbox($functionbox).&Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')));
197: } elsif ($privileged and $target ne 'tex') {
198: my $query_str = 'forceedit=edit';
199: if (($group ne '') && ($env{'form.group'} eq $group)) {
200: $query_str.='&group='.$group.'&'.$refarg;
201: }
202: if ($env{'form.register'}) {
203: $query_str .= '&register='.$env{'form.register'};
204: }
205: #Functionbox for Student view.
206: my $functionbox = &Apache::lonhtmlcommon::start_funclist();
207: $functionbox .= &Apache::lonhtmlcommon::add_item_funclist(
208: "<a href='".$r->uri.'?'.$query_str."'>".&mt('Edit')."</a>");
209: $functionbox.=&Apache::lonhtmlcommon::end_funclist();
210: $r->print(&Apache::loncommon::head_subbox($functionbox));
211: }
212:
213: if (($env{'form.uploaddoc.filename'}) &&
214: ($env{'form.storeupl'}) && ($allowed)) {
215: if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
216: if ($syllabus{'uploaded.photourl'}) {
217: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
218: }
219: if ($group ne '') {
220: $syllabus{'uploaded.photourl'}=
221: &Apache::lonnet::userfileupload('uploaddoc',1,
222: 'bulletin/'.$group.'/'.$marker);
223: } else {
224: $syllabus{'uploaded.photourl'}=
225: &Apache::lonnet::userfileupload('uploaddoc',1,
226: 'bulletin/'.$marker);
227: }
228: }
229: $syllabus{'uploaded.lastmodified'}=time;
230: &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
231: }
232: if (($allowed) && ($env{'form.storesyl'})) {
233: foreach my $syl_field (keys(%syllabusfields)) {
234: my $field=$env{'form.'.$syl_field};
235: $field=~s/\s+$//s;
236: $field=&Apache::lonfeedback::clear_out_html($field,1);
237: $syllabus{$syl_field}=$field;
238: }
239: $syllabus{'uploaded.lastmodified'}=time;
240: &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
241: }
242:
243: # ---------------------------------------------------------------- Get discussion board
244: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
245: #Print Topic as Heading
246: my $titletext=&HTML::Entities::encode($syllabus{'aaa_title'},'<>&"');;
247: if ($target ne 'tex') {
248: $r->print('<h2>'.$titletext.'</h2>');
249: } else {
250: $r->print('\\\\\textbf{'.&Apache::lonxml::xmlparse($r,'tex',$titletext).'}\\\\');
251: }
252: #Outputbox and Inputbox for Topic
253: if ($allowed) {
254: $r->print('<form method="post" action="" enctype="multipart/form-data">');
255: &Apache::lontemplate::print_start_template($r,&mt('Title'),'LC_Box');
256: $r->print($titletext);
257: $r->print("<br /><div>");
258: &Apache::lontemplate::print_textarea_template($r, $syllabus{'aaa_title'},
259: 'aaa_title', Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
260: &Apache::lontemplate::print_saveall_template($r);
261: $r->print("</div>");
262: &Apache::lontemplate::print_end_template($r);
263: }
264: if ($syllabus{'uploaded.photourl'}) {
265: &Apache::lonnet::allowuploaded('/adm/syllabus',
266: $syllabus{'uploaded.photourl'});
267: }
268: #Outputbox and Inputbox for Image upload
269: if ($allowed) {
270: my $message = '<img src="'.$syllabus{'uploaded.photourl'}.'" alt="'.&mt('Image').'"/>';
271: &Apache::lontemplate::print_start_template($r, &mt('Upload a Photo'),'LC_Box');
272: $r->print($message);
273: $r->print("<br /><br />");
274: $r->print(
275: '<input type="hidden" name="forceedit" value="edit" />'.
276: '<input type="file" name="uploaddoc" size="50" />'.
277: '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />'.
278: '<input type="hidden" name="forceedit" value="edit" />');
279: &Apache::lontemplate::print_end_template($r);
280: }
281: #Image in Student view.
282: elsif($syllabus{'uploaded.photourl'} && $target ne 'tex'){
283: $r->print('<img src="'.$syllabus{'uploaded.photourl'}.'" alt="'.&mt('Image').'"/>');
284: }
285:
286: my %custom_handlers = ( 'aaa_title' => sub {} );
287: &Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields,
288: $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_handlers);
289: if ($allowed) {
290: $r->print('</form>'.
291: &Apache::lonhtmlcommon::htmlareaselectactive());
292: }
293: if ($target ne 'tex'){
294: $r->print('<br/><br/><hr/><br/>');
295: }
296: else {
297: $r->print(&Apache::lonxml::xmlparse($r,'tex','<br/><br/><hr/><br/>'));
298: }
299: } else {
300: if ($target ne 'tex') {
301: $r->print('<p>'.&mt('No page information provided.').'</p>');
302: }
303: }
304: #Lists discussion posts and box for a new discussion post.
305: if ($target ne 'tex') {
306: $r->print(&Apache::lonfeedback::list_discussion
307: ('board','OPEN','bulletin___'.$marker.'___'.
308: $r->uri,undef,$group));
309: } else {
310: $r->print('\\\\'.&Apache::lonxml::xmlparse($r,'tex',&Apache::lonfeedback::list_discussion
311: ('board','OPEN','bulletin___'.$marker.'___'.
312: $r->uri,undef,$group)));
313: }
314: &print_end_page($r,$target);
315: return OK;
316: }
317:
318: sub print_end_page {
319: my ($r,$target) = @_;
320: if ($target ne 'tex') {
321: $r->print(&Apache::loncommon::end_page());
322: } else {
323: $r->print('\end{document}');
324: }
325: }
326:
327: sub groupboard_breadcrumbs {
328: my ($cdom,$cnum,$group,$refarg,$gpterm,$ucgpterm,$description,$boardurl,
329: $boardtitle)= @_;
330: &Apache::lonhtmlcommon::clear_breadcrumbs();
331: if ($refarg ne '') {
332: &Apache::lonhtmlcommon::add_breadcrumb
333: ({href=>"/adm/coursegroups",
334: text=>"Groups",
335: title=>"View course groups"});
336: }
337: &Apache::lonhtmlcommon::add_breadcrumb
338: ({href=>"/adm/$cdom/$cnum/$group/smppg?$refarg",
339: text=>"$ucgpterm: $description",
340: title=>"Go to group's home page"},
341: {href=>"/adm/groupboards?group=$group&$refarg",
342: text=>"Discussion Boards",
343: title=>"Display group discussion boards"},
344: {href=>"$boardurl",
345: text=>"$boardtitle",
346: title=>"$boardtitle"},
347: );
348: my $output .= &Apache::lonhtmlcommon::breadcrumbs(&mt('[_1] discussion boards - [_2]',$gpterm,$description));
349: return $output;
350: }
351:
352: 1;
353: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>