Annotation of loncom/interface/lonbulletin.pm, revision 1.67
1.1 www 1: # The LearningOnline Network
1.5 www 2: # Bulletin Board Handler
1.1 www 3: #
1.67 ! raeburn 4: # $Id: lonbulletin.pm,v 1.66 2012/12/07 17:15:56 raeburn Exp $
1.1 www 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;
1.67 ! raeburn 36: use Apache::lonfeedback;
! 37: use Apache::lonhtmlgateway;
1.15 www 38: use Apache::lonlocal;
1.36 raeburn 39: use Apache::lonhtmlcommon;
1.39 albertel 40: use HTML::Entities();
1.36 raeburn 41: use LONCAPA;
1.1 www 42:
43: sub handler {
44: my $r = shift;
1.16 www 45: &Apache::loncommon::content_type($r,'text/html');
1.1 www 46: $r->send_http_header;
47: return OK if $r->header_only;
1.29 albertel 48: my $target=$env{'form.grade_target'};
1.23 sakharuk 49:
1.1 www 50: # ------------------------------------------------------------ Print the screen
1.32 albertel 51: if ($target eq 'tex') {
1.49 bisitz 52: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.23 sakharuk 53: }
1.2 www 54: my (undef,undef,undef,undef,$marker)=split(/\//,$r->uri);
1.1 www 55: # Is this even in a course?
1.32 albertel 56: if (!$env{'request.course.id'}) {
1.49 bisitz 57: &Apache::loncommon::simple_error_page($r,'Not in a course',
58: 'Not in a course');
1.1 www 59: return OK;
60: }
61:
62: $marker=~s/\D//g;
63:
1.32 albertel 64: if (!$marker) {
1.49 bisitz 65: &Apache::loncommon::simple_error_page($r,'Invalid Call',
66: 'Invalid Call');
1.1 www 67: return OK;
68: }
69:
1.29 albertel 70: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
71: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.36 raeburn 72: my ($group,$grp_desc);
1.1 www 73:
74: # --------------------------------------------------------- The syllabus fields
1.17 www 75: my %syllabusfields=&Apache::lonlocal::texthash(
1.2 www 76: 'aaa_title' => 'Topic',
77: 'bbb_content' => 'Task',
1.1 www 78: 'ccc_webreferences' => 'Web References');
79:
1.7 www 80: # ------------------------------------------------------------ Get Query String
81: &Apache::loncommon::get_unprocessed_cgi
1.66 raeburn 82: ($ENV{'QUERY_STRING'},['forceedit','register','todocs',
1.37 raeburn 83: 'origpage','group','ref']);
1.7 www 84: # ----------------------------------------------------- Force menu registration
1.35 albertel 85: my %addentries;
86: if ($env{'form.origpage'}) {
1.49 bisitz 87: $addentries{'onload'} = "document.location='#newpost';";
1.7 www 88: }
1.1 www 89: # --------------------------------------------------------------- Force Student
1.64 raeburn 90: my ($forceedit,$forcestudent);
91: $forceedit = $env{'form.forceedit'};
92: if (!$forceedit) {
93: $forcestudent=1;
94: }
1.37 raeburn 95: my $refarg = '';
96: if (exists($env{'form.ref'})) { $refarg = 'ref='.$env{'form.ref'}; }
1.1 www 97:
98: my %syllabus=&Apache::lonnet::dump('bulletinpage_'.$marker,$dom,$crs);
1.36 raeburn 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: }
1.49 bisitz 126:
1.1 www 127: # --------------------------------------- There is such a user, get environment
1.49 bisitz 128: if ($target ne 'tex') {
1.64 raeburn 129: my ($course_or_group,$brcrum);
1.49 bisitz 130: if($group eq '') {
131: $course_or_group="Course";
132: } else {
133: $course_or_group="Group";
134: }
1.65 raeburn 135: my $registered;
1.36 raeburn 136: if ($group ne '' && $env{'form.group'} eq $group) {
1.65 raeburn 137: unless ($env{'form.ref'} eq 'grouplist') {
138: $registered = $env{'form.register'};
139: }
1.36 raeburn 140: my $gpterm = &Apache::loncommon::group_term();
141: my $ucgpterm = $gpterm;
142: $ucgpterm =~ s/^(\w)/uc($1)/e;
1.37 raeburn 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: }
1.65 raeburn 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: }
1.64 raeburn 158: } else {
1.65 raeburn 159: $registered = $env{'form.register'};
1.64 raeburn 160: $brcrum = [];
1.36 raeburn 161: }
1.64 raeburn 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,
1.65 raeburn 168: 'force_register' => $registered}
169: );
1.64 raeburn 170: $r->print($start_page);
1.36 raeburn 171: }
172: my ($allowed);
173: if ($group ne '') {
1.37 raeburn 174: $allowed=&Apache::lonnet::allowed('mdg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.36 raeburn 175: if (!$allowed) {
176: $allowed = &Apache::lonnet::allowed('cgb',$env{'request.course.id'}.
177: '/'.$group);
178: }
179: if (!$allowed) {
1.37 raeburn 180: if ((!&Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) &&
1.36 raeburn 181: (!&Apache::lonnet::allowed('vgb',$env{'request.course.id'}.
1.49 bisitz 182: '/'.$group))) {
1.36 raeburn 183: &print_end_page($r,$target);
1.49 bisitz 184: return OK;
1.36 raeburn 185: }
186: }
187: } else {
188: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.23 sakharuk 189: }
1.1 www 190:
1.49 bisitz 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'}=
1.62 raeburn 201: &Apache::lonnet::userfileupload('uploaddoc','coursedoc',
1.49 bisitz 202: 'bulletin/'.$group.'/'.$marker);
203: } else {
204: $syllabus{'uploaded.photourl'}=
1.62 raeburn 205: &Apache::lonnet::userfileupload('uploaddoc','coursedoc',
1.38 raeburn 206: 'bulletin/'.$marker);
1.49 bisitz 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};
1.67 ! raeburn 215: chomp($field);
! 216: my $gateway = Apache::lonhtmlgateway->new();
! 217: $field = $gateway->process_incoming_html($field,1);
1.49 bisitz 218: $syllabus{$syl_field}=$field;
219: }
220: $syllabus{'uploaded.lastmodified'}=time;
221: &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
222: }
1.1 www 223:
1.54 wenzelju 224: # ---------------------------------------------------------------- Get discussion board
1.1 www 225: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.56 wenzelju 226: #Print Topic as Heading
1.57 faziophi 227: my $titletext=&HTML::Entities::encode($syllabus{'aaa_title'},'<>&"');;
1.56 wenzelju 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">');
1.57 faziophi 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);
1.56 wenzelju 244: }
1.49 bisitz 245: if ($syllabus{'uploaded.photourl'}) {
246: &Apache::lonnet::allowuploaded('/adm/syllabus',
247: $syllabus{'uploaded.photourl'});
248: }
1.53 wenzelju 249: #Outputbox and Inputbox for Image upload
1.49 bisitz 250: if ($allowed) {
1.57 faziophi 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 />");
1.49 bisitz 255: $r->print(
1.64 raeburn 256: '<input type="hidden" name="forceedit" value="'.$env{'form.forceedit'}.'" />'.
1.49 bisitz 257: '<input type="file" name="uploaddoc" size="50" />'.
1.64 raeburn 258: '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />');
1.57 faziophi 259: &Apache::lontemplate::print_end_template($r);
1.49 bisitz 260: }
1.53 wenzelju 261: #Image in Student view.
262: elsif($syllabus{'uploaded.photourl'} && $target ne 'tex'){
1.55 wenzelju 263: $r->print('<img src="'.$syllabus{'uploaded.photourl'}.'" alt="'.&mt('Image').'"/>');
1.53 wenzelju 264: }
1.58 faziophi 265:
266: my %custom_handlers = ( 'aaa_title' => sub {} );
1.61 raeburn 267: &Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields,
1.58 faziophi 268: $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_handlers);
1.49 bisitz 269: if ($allowed) {
1.63 raeburn 270: $r->print('</form>');
1.49 bisitz 271: }
1.54 wenzelju 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: }
1.1 www 278: } else {
1.60 www 279: if ($target ne 'tex') {
280: $r->print('<p>'.&mt('No page information provided.').'</p>');
281: }
1.1 www 282: }
1.53 wenzelju 283: #Lists discussion posts and box for a new discussion post.
1.23 sakharuk 284: if ($target ne 'tex') {
1.49 bisitz 285: $r->print(&Apache::lonfeedback::list_discussion
286: ('board','OPEN','bulletin___'.$marker.'___'.
287: $r->uri,undef,$group));
1.23 sakharuk 288: } else {
1.49 bisitz 289: $r->print('\\\\'.&Apache::lonxml::xmlparse($r,'tex',&Apache::lonfeedback::list_discussion
290: ('board','OPEN','bulletin___'.$marker.'___'.
291: $r->uri,undef,$group)));
1.23 sakharuk 292: }
1.36 raeburn 293: &print_end_page($r,$target);
294: return OK;
295: }
296:
297: sub print_end_page {
298: my ($r,$target) = @_;
1.32 albertel 299: if ($target ne 'tex') {
1.36 raeburn 300: $r->print(&Apache::loncommon::end_page());
1.32 albertel 301: } else {
1.36 raeburn 302: $r->print('\end{document}');
1.32 albertel 303: }
1.36 raeburn 304: }
305:
306: sub groupboard_breadcrumbs {
1.37 raeburn 307: my ($cdom,$cnum,$group,$refarg,$gpterm,$ucgpterm,$description,$boardurl,
308: $boardtitle)= @_;
1.36 raeburn 309: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.64 raeburn 310: my $brcrum = [];
1.37 raeburn 311: if ($refarg ne '') {
1.64 raeburn 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"},
1.36 raeburn 327: );
1.64 raeburn 328: return $brcrum;
1.36 raeburn 329: }
1.1 www 330:
331: 1;
332: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>