Annotation of loncom/interface/lonbulletin.pm, revision 1.32
1.1 www 1: # The LearningOnline Network
1.5 www 2: # Bulletin Board Handler
1.1 www 3: #
1.32 ! albertel 4: # $Id: lonbulletin.pm,v 1.31 2005/10/30 02:39:09 www 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.6 www 36: use Apache::lonfeedback;
1.15 www 37: use Apache::lonlocal;
1.1 www 38:
39: sub handler {
40: my $r = shift;
1.16 www 41: &Apache::loncommon::content_type($r,'text/html');
1.1 www 42: $r->send_http_header;
43: return OK if $r->header_only;
1.29 albertel 44: my $target=$env{'form.grade_target'};
1.23 sakharuk 45:
1.1 www 46: # ------------------------------------------------------------ Print the screen
1.32 ! albertel 47: if ($target eq 'tex') {
1.29 albertel 48: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.23 sakharuk 49: }
1.2 www 50: my (undef,undef,undef,undef,$marker)=split(/\//,$r->uri);
1.1 www 51: # Is this even in a course?
1.32 ! albertel 52: if (!$env{'request.course.id'}) {
! 53: $r->print(&Apache::loncommon::start_page('Not in a course').
! 54: &mt('Not in a course').
! 55: &Apache::loncommon::end_page());
1.1 www 56: return OK;
57: }
58:
59: $marker=~s/\D//g;
60:
1.32 ! albertel 61: if (!$marker) {
! 62: $r->print(&Apache::loncommon::start_page('Invalid Call').
! 63: &mt('Invalid Call').
! 64: &Apache::loncommon::end_page());
1.1 www 65: return OK;
66: }
67:
1.29 albertel 68: my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
69: my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1 www 70:
71: # --------------------------------------------------------- The syllabus fields
1.17 www 72: my %syllabusfields=&Apache::lonlocal::texthash(
1.2 www 73: 'aaa_title' => 'Topic',
74: 'bbb_content' => 'Task',
1.1 www 75: 'ccc_webreferences' => 'Web References');
76:
1.7 www 77: # ------------------------------------------------------------ Get Query String
78: &Apache::loncommon::get_unprocessed_cgi
1.26 raeburn 79: ($ENV{'QUERY_STRING'},['forcestudent','forceedit','register','origpage']);
1.7 www 80: # ----------------------------------------------------- Force menu registration
81: my $addentries='';
1.29 albertel 82: if ($env{'form.register'}) {
1.26 raeburn 83: $addentries=' onLoad="'.&Apache::lonmenu::loadevents();
1.29 albertel 84: if ($env{'form.origpage'}) {
1.26 raeburn 85: $addentries .= "document.location='#newpost';";
86: }
87: $addentries .= '" onUnload="'.&Apache::lonmenu::unloadevents().'"';
1.7 www 88: $r->print(&Apache::lonmenu::registerurl(1));
1.29 albertel 89: } elsif ($env{'form.origpage'}) {
1.26 raeburn 90: $addentries = "onLoad=\"document.location='#newpost';\"";
1.7 www 91: }
1.1 www 92: # --------------------------------------------------------------- Force Student
93: my $forcestudent='';
1.29 albertel 94: if ($env{'form.forcestudent'}) { $forcestudent='student'; }
1.19 www 95:
96: my $forceedit='';
1.29 albertel 97: if ($env{'form.forceedit'}) { $forceedit='edit'; }
1.1 www 98:
99: my %syllabus=&Apache::lonnet::dump('bulletinpage_'.$marker,$dom,$crs);
100:
101: # --------------------------------------- There is such a user, get environment
1.32 ! albertel 102: if ($target ne 'tex') {
! 103: my $start_page =
! 104: &Apache::loncommon::start_page("Bulletin Board/Discussion",undef,
! 105: {'function' => $forcestudent,
! 106: 'add_entries' => $addentries,
! 107: 'domain' => $domain,
! 108: 'force_register' =>
! 109: $env{'form.register'}});
! 110: $r->print($start_page);
1.23 sakharuk 111: }
1.29 albertel 112: my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.1 www 113:
1.19 www 114: my $privileged=$allowed;
115: if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
116: $forcestudent='student';
117: }
1.27 albertel 118: if ($target ne 'tex') { $r->print('<table><tr><td>'); }
1.23 sakharuk 119: if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.1 www 120:
1.23 sakharuk 121: if ($allowed) {
1.1 www 122: $r->print(
1.6 www 123: '<p>'.
1.19 www 124: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'<br /><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.&mt('Show Student View').'</font></a>'.
1.5 www 125: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
1.23 sakharuk 126: } elsif ($privileged and $target ne 'tex') {
1.19 www 127: $r->print('<a href="'.$r->uri.'?forceedit=edit"><font size="+1">'
128: .&mt('Edit').'</font></a>');
129: }
130:
1.29 albertel 131: if (($env{'form.uploaddoc.filename'}) &&
132: ($env{'form.storeupl'}) && ($allowed)) {
133: if ($env{'form.uploaddoc.filename'}=~/\.(gif|jpg|png|jpeg)$/i) {
1.20 albertel 134: if ($syllabus{'uploaded.photourl'}) {
135: &Apache::lonnet::removeuploadedurl($syllabus{'uploaded.photourl'});
136: }
137: $syllabus{'uploaded.photourl'}=
138: &Apache::lonnet::userfileupload('uploaddoc',1,'bulletin');
1.1 www 139: }
140: $syllabus{'uploaded.lastmodified'}=time;
141: &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
142: }
1.29 albertel 143: if (($allowed) && ($env{'form.storesyl'})) {
1.1 www 144: foreach (keys %syllabusfields) {
1.29 albertel 145: my $field=$env{'form.'.$_};
1.1 www 146: $field=~s/\s+$//s;
1.5 www 147: $field=&Apache::lonfeedback::clear_out_html($field,1);
1.1 www 148: $syllabus{$_}=$field;
149: }
150: $syllabus{'uploaded.lastmodified'}=time;
151: &Apache::lonnet::put('bulletinpage_'.$marker,\%syllabus,$dom,$crs);
152: }
153:
154: # ---------------------------------------------------------------- Get syllabus
155: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
156: if ($syllabus{'uploaded.photourl'}) {
1.20 albertel 157: &Apache::lonnet::allowuploaded('/adm/syllabus',
158: $syllabus{'uploaded.photourl'});
159: $r->print('<img src="'.$syllabus{'uploaded.photourl'}.
160: '" align="right" />');
1.1 www 161: }
162: if ($allowed) {
163: $r->print(
164: '<form method="post" enctype="multipart/form-data">'.
1.19 www 165: '<input type="hidden" name="forceedit" value="edit" />'.
166: '<h3>'.&mt('Upload a Photo').'</h3>'.
1.1 www 167: '<input type="file" name="uploaddoc" size="50">'.
1.19 www 168: '<input type="submit" name="storeupl" value="'.&mt('Upload').'">'.
1.1 www 169: '</form><form method="post">');
170: }
171: foreach (sort keys %syllabusfields) {
172: if (($syllabus{$_}) || ($allowed)) {
173: my $message=$syllabus{$_};
1.30 albertel 174: &Apache::lonfeedback::newline_to_br(\$message);
175: $message
1.10 www 176: =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.25 www 177: if ($allowed) {
178: $message=&Apache::lonspeller::markeduptext($message);
179: }
1.31 www 180: $message=&Apache::lontexconvert::msgtexconverted($message);
1.25 www 181: unless ($_ eq 'aaa_title') {
1.2 www 182: if (($_ ne 'bbb_content') || ($allowed)) {
1.23 sakharuk 183: if ($target ne 'tex') {
184: $r->print('<h3>'.$syllabusfields{$_}.'</h3>');
185: } else {
186: $r->print('\\\\\textbf{'.$syllabusfields{$_}.'}\\\\');
187: }
188: }
189: if ($target ne 'tex') {
190: $r->print('<blockquote>'.
191: $message.'</blockquote>');
192: } else {
193: $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$message).' ');
1.2 www 194: }
195: if ($allowed) {
1.3 www 196: $r->print('<br /><textarea cols="80" rows="10" name="'.$_.'">'.
1.1 www 197: $syllabus{$_}.
1.19 www 198: '</textarea><input type="submit" name="storesyl" value="'.&mt('Store').'" />');
1.2 www 199: }
200: } else {
1.23 sakharuk 201: if ($target ne 'tex') {
202: $r->print('<h1>'.$message.'</h1>');
203: } else {
204: $r->print('\\\\\textbf{'.&Apache::lonxml::xmlparse($r,'tex',$message).'}\\\\');
205: }
1.2 www 206: if ($allowed) {
207: $r->print(
1.19 www 208: '<br />'.&mt('Topic').'<br /><textarea cols="80" rows="2" name="'.$_.'">'.
1.2 www 209: $syllabus{$_}.
1.19 www 210: '</textarea><input type="submit" name="storesyl" value="'.&mt('Store').'" />');
1.2 www 211: }
212: }
1.1 www 213: }
214: }
215: if ($allowed) {
216: $r->print('</form>');
217: }
1.23 sakharuk 218: if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
1.1 www 219: } else {
1.19 www 220: $r->print('<p>'.&mt('No page information provided.').'</p>');
1.1 www 221: }
1.27 albertel 222: if ($target ne 'tex') { $r->print('</td></tr></table>'); }
1.23 sakharuk 223: if ($target ne 'tex') {
224: $r->print(&Apache::lonfeedback::list_discussion
225: ('board','OPEN','bulletin___'.$marker.'___'.
226: $r->uri));
227: } else {
228: $r->print('\\\\'.&Apache::lonxml::xmlparse($r,'tex',&Apache::lonfeedback::list_discussion
229: ('board','OPEN','bulletin___'.$marker.'___'.
230: $r->uri)));
231: }
1.32 ! albertel 232: if ($target ne 'tex') {
! 233: $r->print(&Apache::loncommon::end_page());
! 234: } else {
! 235: $r->print('\end{document}');
! 236: }
1.1 www 237: return OK;
238: }
239:
240: 1;
241: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>