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