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