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