Annotation of loncom/interface/lonbulletin.pm, revision 1.70
1.1 www 1: # The LearningOnline Network
1.5 www 2: # Bulletin Board Handler
1.1 www 3: #
1.70 ! raeburn 4: # $Id: lonbulletin.pm,v 1.69 2020/09/08 23:54:40 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.68 raeburn 40: use Apache::longroup;
41: use Apache::lonnavmaps;
1.39 albertel 42: use HTML::Entities();
1.36 raeburn 43: use LONCAPA;
1.1 www 44:
45: sub handler {
46: my $r = shift;
1.16 www 47: &Apache::loncommon::content_type($r,'text/html');
1.1 www 48: $r->send_http_header;
49: return OK if $r->header_only;
1.29 albertel 50: my $target=$env{'form.grade_target'};
1.23 sakharuk 51:
1.1 www 52: # ------------------------------------------------------------ Print the screen
1.32 albertel 53: if ($target eq 'tex') {
1.49 bisitz 54: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.23 sakharuk 55: }
1.2 www 56: my (undef,undef,undef,undef,$marker)=split(/\//,$r->uri);
1.1 www 57: # Is this even in a course?
1.32 albertel 58: if (!$env{'request.course.id'}) {
1.49 bisitz 59: &Apache::loncommon::simple_error_page($r,'Not in a course',
60: 'Not in a course');
1.1 www 61: return OK;
62: }
63:
64: $marker=~s/\D//g;
65:
1.32 albertel 66: if (!$marker) {
1.49 bisitz 67: &Apache::loncommon::simple_error_page($r,'Invalid Call',
68: 'Invalid Call');
1.1 www 69: return OK;
70: }
71:
1.29 albertel 72: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
73: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.36 raeburn 74: my ($group,$grp_desc);
1.1 www 75:
76: # --------------------------------------------------------- The syllabus fields
1.17 www 77: my %syllabusfields=&Apache::lonlocal::texthash(
1.2 www 78: 'aaa_title' => 'Topic',
79: 'bbb_content' => 'Task',
1.1 www 80: 'ccc_webreferences' => 'Web References');
81:
1.7 www 82: # ------------------------------------------------------------ Get Query String
83: &Apache::loncommon::get_unprocessed_cgi
1.66 raeburn 84: ($ENV{'QUERY_STRING'},['forceedit','register','todocs',
1.37 raeburn 85: 'origpage','group','ref']);
1.7 www 86: # ----------------------------------------------------- Force menu registration
1.35 albertel 87: my %addentries;
88: if ($env{'form.origpage'}) {
1.49 bisitz 89: $addentries{'onload'} = "document.location='#newpost';";
1.7 www 90: }
1.1 www 91: # --------------------------------------------------------------- Force Student
1.64 raeburn 92: my ($forceedit,$forcestudent);
93: $forceedit = $env{'form.forceedit'};
94: if (!$forceedit) {
95: $forcestudent=1;
96: }
1.37 raeburn 97: my $refarg = '';
98: if (exists($env{'form.ref'})) { $refarg = 'ref='.$env{'form.ref'}; }
1.1 www 99:
100: my %syllabus=&Apache::lonnet::dump('bulletinpage_'.$marker,$dom,$crs);
1.36 raeburn 101:
102: my $boardurl = $r->uri;
103: if ($boardurl =~ m|/adm/\Q$dom\E/\Q$crs\E/\d+/bulletinboard|) {
104: if (!exists($syllabus{'group'})) {
105: &Apache::loncommon::simple_error_page($r,'Group information missing',
106: 'Group information missing');
107:
108: return OK;
109: } else {
110: $group = $syllabus{'group'};
111: if ($group eq '') {
112: &Apache::loncommon::simple_error_page($r,'Invalid group',
113: 'Invalid group');
114: return OK;
115: }
116: my %curr_groups = &Apache::longroup::coursegroups($dom,$crs,$group);
117: if (!defined($curr_groups{$group})) {
118: &Apache::loncommon::simple_error_page($r,'Invalid group',
119: 'Invalid group');
120: return OK;
121: } else {
122: my %content = &Apache::longroup::get_group_settings(
123: $curr_groups{$group});
124: $grp_desc = &unescape($content{'description'});
125: }
126: }
127: }
1.49 bisitz 128:
1.1 www 129: # --------------------------------------- There is such a user, get environment
1.49 bisitz 130: if ($target ne 'tex') {
1.64 raeburn 131: my ($course_or_group,$brcrum);
1.49 bisitz 132: if($group eq '') {
133: $course_or_group="Course";
134: } else {
135: $course_or_group="Group";
136: }
1.65 raeburn 137: my $registered;
1.36 raeburn 138: if ($group ne '' && $env{'form.group'} eq $group) {
1.65 raeburn 139: unless ($env{'form.ref'} eq 'grouplist') {
140: $registered = $env{'form.register'};
141: }
1.36 raeburn 142: my $gpterm = &Apache::loncommon::group_term();
143: my $ucgpterm = $gpterm;
144: $ucgpterm =~ s/^(\w)/uc($1)/e;
1.37 raeburn 145: my ($groupboards,$boards) =
146: &Apache::longroup::get_group_bbinfo($dom,$crs,$group,$boardurl);
147: my $boardtitle;
148: if ((ref($groupboards) eq 'ARRAY') && (@{$groupboards} > 0)) {
149: $boardtitle = $$boards{$$groupboards[0]}{'title'};
150: }
1.65 raeburn 151: $boardurl .= '?group='.$group;
152: if ($registered) {
153: $boardurl .= '&register='.$env{'form.register'};
154: } else {
155: $brcrum =
156: &groupboard_breadcrumbs($dom,$crs,$group,$refarg,$gpterm,
157: $ucgpterm,$grp_desc,$boardurl,
158: $boardtitle);
159: }
1.64 raeburn 160: } else {
1.65 raeburn 161: $registered = $env{'form.register'};
1.64 raeburn 162: $brcrum = [];
1.36 raeburn 163: }
1.64 raeburn 164: my $start_page =
165: &Apache::loncommon::start_page("$course_or_group Discussion Board",undef,
166: {'add_entries' => \%addentries,
167: 'domain' => $dom,
168: 'bread_crumbs' => $brcrum,
169: 'group' => $group,
1.65 raeburn 170: 'force_register' => $registered}
171: );
1.64 raeburn 172: $r->print($start_page);
1.36 raeburn 173: }
174: my ($allowed);
175: if ($group ne '') {
1.37 raeburn 176: $allowed=&Apache::lonnet::allowed('mdg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.36 raeburn 177: if (!$allowed) {
178: $allowed = &Apache::lonnet::allowed('cgb',$env{'request.course.id'}.
179: '/'.$group);
180: }
181: if (!$allowed) {
1.37 raeburn 182: if ((!&Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) &&
1.36 raeburn 183: (!&Apache::lonnet::allowed('vgb',$env{'request.course.id'}.
1.49 bisitz 184: '/'.$group))) {
1.36 raeburn 185: &print_end_page($r,$target);
1.49 bisitz 186: return OK;
1.36 raeburn 187: }
188: }
189: } else {
190: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.23 sakharuk 191: }
1.1 www 192:
1.49 bisitz 193: if ($forcestudent or $target eq 'tex') { $allowed=0; }
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'}=
1.62 raeburn 203: &Apache::lonnet::userfileupload('uploaddoc','coursedoc',
1.49 bisitz 204: 'bulletin/'.$group.'/'.$marker);
205: } else {
206: $syllabus{'uploaded.photourl'}=
1.62 raeburn 207: &Apache::lonnet::userfileupload('uploaddoc','coursedoc',
1.38 raeburn 208: 'bulletin/'.$marker);
1.49 bisitz 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 my $syl_field (keys(%syllabusfields)) {
216: my $field=$env{'form.'.$syl_field};
1.67 raeburn 217: chomp($field);
218: my $gateway = Apache::lonhtmlgateway->new();
219: $field = $gateway->process_incoming_html($field,1);
1.49 bisitz 220: $syllabus{$syl_field}=$field;
221: }
222: $syllabus{'uploaded.lastmodified'}=time;
223: &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
224: }
1.1 www 225:
1.54 wenzelju 226: # ---------------------------------------------------------------- Get discussion board
1.1 www 227: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.56 wenzelju 228: #Print Topic as Heading
1.57 faziophi 229: my $titletext=&HTML::Entities::encode($syllabus{'aaa_title'},'<>&"');;
1.56 wenzelju 230: if ($target ne 'tex') {
231: $r->print('<h2>'.$titletext.'</h2>');
232: } else {
233: $r->print('\\\\\textbf{'.&Apache::lonxml::xmlparse($r,'tex',$titletext).'}\\\\');
234: }
235: #Outputbox and Inputbox for Topic
236: if ($allowed) {
237: $r->print('<form method="post" action="" enctype="multipart/form-data">');
1.57 faziophi 238: &Apache::lontemplate::print_start_template($r,&mt('Title'),'LC_Box');
239: $r->print($titletext);
240: $r->print("<br /><div>");
241: &Apache::lontemplate::print_textarea_template($r, $syllabus{'aaa_title'},
1.70 ! raeburn 242: 'aaa_title', $syllabusfields{'aaa_title'},
! 243: Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
1.57 faziophi 244: &Apache::lontemplate::print_saveall_template($r);
245: $r->print("</div>");
246: &Apache::lontemplate::print_end_template($r);
1.56 wenzelju 247: }
1.49 bisitz 248: if ($syllabus{'uploaded.photourl'}) {
249: &Apache::lonnet::allowuploaded('/adm/syllabus',
250: $syllabus{'uploaded.photourl'});
251: }
1.53 wenzelju 252: #Outputbox and Inputbox for Image upload
1.49 bisitz 253: if ($allowed) {
1.57 faziophi 254: my $message = '<img src="'.$syllabus{'uploaded.photourl'}.'" alt="'.&mt('Image').'"/>';
255: &Apache::lontemplate::print_start_template($r, &mt('Upload a Photo'),'LC_Box');
256: $r->print($message);
257: $r->print("<br /><br />");
1.49 bisitz 258: $r->print(
1.64 raeburn 259: '<input type="hidden" name="forceedit" value="'.$env{'form.forceedit'}.'" />'.
1.49 bisitz 260: '<input type="file" name="uploaddoc" size="50" />'.
1.64 raeburn 261: '<input type="submit" name="storeupl" value="'.&mt('Upload').'" />');
1.57 faziophi 262: &Apache::lontemplate::print_end_template($r);
1.49 bisitz 263: }
1.53 wenzelju 264: #Image in Student view.
265: elsif($syllabus{'uploaded.photourl'} && $target ne 'tex'){
1.55 wenzelju 266: $r->print('<img src="'.$syllabus{'uploaded.photourl'}.'" alt="'.&mt('Image').'"/>');
1.53 wenzelju 267: }
1.58 faziophi 268:
269: my %custom_handlers = ( 'aaa_title' => sub {} );
1.61 raeburn 270: &Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields,
1.58 faziophi 271: $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_handlers);
1.49 bisitz 272: if ($allowed) {
1.63 raeburn 273: $r->print('</form>');
1.49 bisitz 274: }
1.54 wenzelju 275: if ($target ne 'tex'){
276: $r->print('<br/><br/><hr/><br/>');
277: }
278: else {
279: $r->print(&Apache::lonxml::xmlparse($r,'tex','<br/><br/><hr/><br/>'));
280: }
1.1 www 281: } else {
1.60 www 282: if ($target ne 'tex') {
283: $r->print('<p>'.&mt('No page information provided.').'</p>');
284: }
1.1 www 285: }
1.53 wenzelju 286: #Lists discussion posts and box for a new discussion post.
1.23 sakharuk 287: if ($target ne 'tex') {
1.49 bisitz 288: $r->print(&Apache::lonfeedback::list_discussion
289: ('board','OPEN','bulletin___'.$marker.'___'.
290: $r->uri,undef,$group));
1.23 sakharuk 291: } else {
1.49 bisitz 292: $r->print('\\\\'.&Apache::lonxml::xmlparse($r,'tex',&Apache::lonfeedback::list_discussion
293: ('board','OPEN','bulletin___'.$marker.'___'.
294: $r->uri,undef,$group)));
1.23 sakharuk 295: }
1.36 raeburn 296: &print_end_page($r,$target);
297: return OK;
298: }
299:
300: sub print_end_page {
301: my ($r,$target) = @_;
1.32 albertel 302: if ($target ne 'tex') {
1.36 raeburn 303: $r->print(&Apache::loncommon::end_page());
1.32 albertel 304: } else {
1.36 raeburn 305: $r->print('\end{document}');
1.32 albertel 306: }
1.36 raeburn 307: }
308:
309: sub groupboard_breadcrumbs {
1.37 raeburn 310: my ($cdom,$cnum,$group,$refarg,$gpterm,$ucgpterm,$description,$boardurl,
311: $boardtitle)= @_;
1.36 raeburn 312: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.64 raeburn 313: my $brcrum = [];
1.37 raeburn 314: if ($refarg ne '') {
1.64 raeburn 315: push(@{$brcrum},
316: {href=>"/adm/coursegroups",
317: text=>"Groups",
318: title=>"View course groups"});
319: }
1.68 raeburn 320: my $view_permission =
321: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
322: my $navmap=Apache::lonnavmaps::navmap->new();
323: my $grouppagelink = &Apache::longroup::get_group_link($cdom,$cnum,$group,$navmap,$view_permission,$refarg);
324: if ($grouppagelink) {
325: push(@{$brcrum},
326: {href=>$grouppagelink,
1.69 raeburn 327: text=>&mt('Group').": $description",
328: title=>&mt("Go to group's home page"),
329: no_mt=>1,},
1.68 raeburn 330: );
331: } else {
332: push(@{$brcrum},
1.69 raeburn 333: {text=>&mt('Group').": $description",
334: no_mt=>1,}
1.68 raeburn 335: );
336: }
1.64 raeburn 337: push(@{$brcrum},
338: {href=>"/adm/groupboards?group=$group&$refarg",
339: text=>"Discussion Boards",
340: title=>"Display group discussion boards"},
341: {href=>"$boardurl",
342: text=>"$boardtitle",
1.69 raeburn 343: title=>"$boardtitle",
344: no_mt=>1},
1.36 raeburn 345: );
1.64 raeburn 346: return $brcrum;
1.36 raeburn 347: }
1.1 www 348:
349: 1;
350: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>