1: # The LearningOnline Network
2: # Syllabus
3: #
4: # $Id: lonsyllabus.pm,v 1.44 2005/11/18 13:35:30 www 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::lonsyllabus;
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::lonannounce;
38: use Apache::lonlocal;
39: use Apache::lonhtmlcommon;
40: use Apache::lonspeller();
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:
48: # ------------------------------------------------------------ Print the screen
49: my $target=$env{'form.grade_target'};
50: my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
51: my $feedurl='feed://'.$ENV{'HTTP_HOST'}.'/public/'.$cdom.'/'.$cnum.'/Course_Announcements.rss';
52: if ($target ne 'tex') {
53: my $html=&Apache::lonxml::xmlbegin();
54: $r->print(<<ENDDOCUMENT);
55: $html
56: <head>
57: <title>The LearningOnline Network with CAPA</title>
58: <link rel="alternate" type="application/rss+xml" title="Course Announcements" href="$feedurl" />
59: ENDDOCUMENT
60: } else {
61: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
62: }
63:
64: # Is this even a course?
65: my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom);
66: if ($homeserver eq 'no_host') {
67: $r->print('</head><body>'.&mt('No syllabus available').'</body></html>');
68: return OK;
69: }
70: # --------------------------------------------------------- The syllabus fields
71: my %syllabusfields=&Apache::lonlocal::texthash(
72: 'aaa_instructorinfo' => 'Instructor Information',
73: 'bbb_description' => 'Course Description',
74: 'ccc_prereq' => 'Prerequisites',
75: 'cdc_classhours' => 'Class Hours',
76: 'ddd_officehours' => 'Office Hours',
77: 'eee_helproom' => 'Helproom Hours',
78: 'efe_projectinfo' => 'Project Information',
79: 'fff_examinfo' => 'Exam Information',
80: 'fgf_deadlines' => 'Deadlines',
81: 'ggg_grading' => 'Grading Information',
82: 'hhh_readings' => 'Readings',
83: 'iii_coursepack' => 'Coursepack',
84: 'jjj_weblinks' => 'Web Links',
85: 'kkk_textbook' => 'Textbook',
86: 'lll_includeurl' => 'URLs To Include in Syllabus');
87:
88: # ------------------------------------------------------------ Get query string
89: &Apache::loncommon::get_unprocessed_cgi
90: ($ENV{'QUERY_STRING'},['forcestudent','register','forceedit']);
91: # ----------------------------------------------------- Force menu registration
92: my $addentries='';
93: if ($env{'form.register'}) {
94: $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
95: '" onUnload="'.&Apache::lonmenu::unloadevents().'"';
96: $r->print(&Apache::lonmenu::registerurl(1));
97: }
98: # --------------------------------------------------------------- Force Student
99: my $forcestudent='';
100: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
101: my $forceedit='';
102: if ($env{'form.forceedit'}) { $forceedit='edit'; }
103:
104: # ------------------------------------- There is such a course, get environment
105: my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
106: if ($target ne 'tex') {
107: $r->print(&Apache::lonhtmlcommon::htmlareaheaders().
108: '</head>'.&Apache::loncommon::bodytag
109: ("Syllabus",$forcestudent,$addentries,'',$cdom,$env{'form.register'}));
110: $r->print('<h1>'.$courseenv{'description'}.'</h1><h3>'.
111: $Apache::lonnet::domaindescription{$cdom}.'</h3>');
112: } else {
113: $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
114: $Apache::lonnet::domaindescription{$cdom}.'}\\\\');
115: }
116: # -------------------------------------------------------------- Announcements?
117: if ($target ne 'tex') {
118: $r->print(&Apache::lonannounce::showday(time,2,
119: &Apache::lonannounce::readcalendar($cdom.'_'.$cnum)).
120: &Apache::lonrss::advertisefeeds($cnum,$cdom));
121: } else {
122: $r->print(&Apache::lonxml::xmlparse($r,'tex',
123: &Apache::lonannounce::showday(time,2,
124: &Apache::lonannounce::readcalendar($cdom.'_'.$cnum))));
125: }
126: # -------------------------------------------------------- Get course personnel
127: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
128: if ($target ne 'tex') {
129: $r->print('<table border="2">');
130: } else {
131: $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
132: }
133: foreach my $element (sort keys %coursepersonnel) {
134: if ($target ne 'tex') {
135: $r->print('<tr><td>'.$element.'</td><td>');
136: } else {
137: $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & ');
138: }
139: foreach (split(/\,/,$coursepersonnel{$element})) {
140: my ($puname,$pudom)=split(/\:/,$_);
141: if ($target ne 'tex') {
142: $r->print(' '.&Apache::loncommon::aboutmewrapper(
143: &Apache::loncommon::plainname($puname,
144: $pudom),$puname,$pudom));
145: } else {
146: $r->print(' '.&Apache::loncommon::plainname($puname,
147: $pudom).' ');
148: }
149: }
150: if ($target ne 'tex') {
151: $r->print('</td></tr>');
152: } else {
153: $r->print('\\\\ \hline');
154: }
155: }
156: if ($target ne 'tex') {
157: $r->print('</table>');
158: } else {
159: $r->print('\end{tabular}\\\\');
160: }
161: # ---------------------------------------------------------- Load syllabus info
162: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
163: my $allowed=0;
164: my $privileged=0;
165:
166: # This handler might be called anonymously ...
167: # ----------------------------------------------------- Only if not public call
168: if ($env{'user.environment'}) {
169: # does this user have privileges to post, etc?
170: if ($env{'request.course.id'}) {
171: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
172: $privileged=$allowed;
173: if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
174: $forcestudent='student';
175: }
176: if ($forcestudent or $target eq 'tex') { $allowed=0; }
177: }
178: if ($allowed) {
179: $r->print('<p>'.
180: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'</p><p>'.&mt('This syllabus can be publicly viewed at')
181: .' <tt>http://'.
182: $Apache::lonnet::hostname{$homeserver}.$r->uri.'</tt>'.
183: &Apache::loncommon::help_open_topic('Syllabus_ExtLink').'</p>'.
184: '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.
185: &mt('Show Public View').'</font></a>'.
186: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').
187: '</p>');
188: } elsif ($privileged) {
189: if ($target ne 'tex') {
190: $r->print('<p><a href="'.$r->uri.'?forceedit=1"><font size="+1">'.
191: &mt('Edit').'</font></a>');
192: }
193: }
194: if (($allowed) && ($env{'form.storesyl'})) {
195: foreach (keys %syllabusfields) {
196: my $field=$env{'form.'.$_};
197: chomp($field);
198: $field=~s/\s+$//s;
199: $field=~s/^\s+//s;
200: $field=~s/\<br\s*\/*\>$//s;
201: $field=&Apache::lonfeedback::clear_out_html($field,1);
202: $syllabus{$_}=$field;
203: if ($_ eq 'lll_includeurl') { # clean up included URLs
204: my $field='';
205: foreach (split(/\n/,$syllabus{$_})) {
206: my $url=$_;
207: # get rid of leading and trailing spaces
208: $url=~s/^\s+//;
209: $url=~s/\s+$//;
210: if ($url=~/^http\:\/\/([^\/]+)\/(.+)$/) {
211: my $remainder=$2;
212: # remove the hostname from internal URLs
213: foreach (keys %Apache::lonnet::hostname) {
214: if ($1=~/$Apache::lonnet::hostname{$_}/i) {
215: $url=$remainder;
216: }
217: }
218: }
219: # norm internal URLs
220: unless ($url=~/^http\:/) {
221: $url=&Apache::lonnet::clutter($url);
222: }
223: # re-assemble field
224: if ($url) {
225: $field.=$url."\n";
226: }
227: }
228: $syllabus{$_}=$field;
229: }
230: }
231: $syllabus{'uploaded.domain'}=$env{'user.domain'};
232: $syllabus{'uploaded.name'}=$env{'user.name'};
233: $syllabus{'uploaded.lastmodified'}=time;
234: &Apache::lonnet::put('syllabus',\%syllabus,$cdom,$cnum);
235: }
236: }
237: # ---------------------------------------------------------------- Get syllabus
238: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
239: my $lastmod=$syllabus{'uploaded.lastmodified'};
240: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
241: my $who = &Apache::loncommon::aboutmewrapper(
242: &Apache::loncommon::plainname($syllabus{'uploaded.name'},
243: $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
244: $syllabus{'uploaded.domain'});
245: if ($target ne 'tex') {
246: $r->print('<table><tr><td>'.&mt('Last updated').':</td><td>'.
247: $lastmod.'</td><td>'.&mt('by').' '.$who.
248: '</td></tr></table><p>');
249: } else {
250: $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.&mt('by').'\\\\ '.
251: &Apache::loncommon::plainname($syllabus{'uploaded.name'},
252: $syllabus{'uploaded.domain'}).'\\\\');
253: }
254: if ($allowed) {
255: $r->print('<form method="post">'.
256: '<input type="hidden" name="forceedit" value="edit" />');
257: }
258: my @htmlids=();
259: foreach (sort keys %syllabusfields) {
260: if (($syllabus{$_}=~/\w/) || ($allowed)) {
261: my $message=$syllabus{$_};
262: if ($_ eq 'lll_includeurl') { # this is the "included" field
263: my $urls=$message;
264: $message='';
265: foreach my $filelink (split(/\n/,$urls)) {
266: my $output='';
267: # embed style?
268: my ($curfext)=($filelink=~/\.([^\.]+)$/);
269: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
270: if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {
271: # make ssi call and remove everything but the body contents
272: $output=&Apache::lonnet::ssi_body($filelink);
273: } elsif ($embstyle eq 'img') {
274: # embed as an image
275: $output='<img src="'.$filelink.'" />';
276: }
277: if ($target ne 'tex') {
278: $message.='<p>'.$output.'</p>';
279: } else {
280: $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
281: }
282: }
283: if ($allowed) {
284: $r->print('<h3>'.$syllabusfields{$_}.
285: &Apache::loncommon::help_open_topic('Syllabus_URLs').'</h3>'.
286: '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.&mt('Show Public View').'</font></a>'.
287: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
288: } else {
289: $r->print($message);
290: }
291: } else {
292: &Apache::lonfeedback::newline_to_br(\$message);
293: $message
294: =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
295: if ($allowed) {
296: $message=&Apache::lonspeller::markeduptext($message);
297: }
298: $message=&Apache::lontexconvert::msgtexconverted($message);
299: if ($target ne 'tex') {
300: $r->print('<h3>'.$syllabusfields{$_}.'</h3><blockquote>'.
301: $message.'</blockquote>');
302: } else {
303: $r->print('\\\\\textbf{'.$syllabusfields{$_}.'}\\\\'.
304: &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
305: }
306: push @htmlids,$_;
307: }
308: if ($allowed) {
309: $r->print(
310: '<br /><textarea cols="80" rows="12" name="'.$_.'" id="'.$_.'">'.
311: $syllabus{$_}.
312: '</textarea> <input type="submit" name="storesyl" value="Store" />');
313: }
314: }
315: }
316: if ($allowed) {
317: $r->print('</form>'.
318: &Apache::lonhtmlcommon::htmlareaselectactive(@htmlids));
319: }
320: if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
321: } else {
322: if ($target ne 'tex') {$r->print('<p>');} else {$r->print('\par ');}
323: $r->print('No syllabus information provided.');
324: if ($target ne 'tex') {$r->print('</p>');}
325: }
326: if ($target ne 'tex') {$r->print('</body></html>');} else {$r->print('\end{document}');}
327: return OK;
328: }
329:
330: 1;
331: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>