1: # The LearningOnline Network
2: # Syllabus
3: #
4: # $Id: lonsyllabus.pm,v 1.116 2012/12/07 17:15:56 raeburn 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::lontemplate;
33: use Apache::Constants qw(:common);
34: use Apache::loncommon;
35: use Apache::lonnet;
36: use Apache::lontexconvert;
37: use Apache::lonfeedback;
38: use Apache::lonannounce;
39: use Apache::lonlocal;
40: use Apache::lonhtmlcommon;
41: use Apache::lonspeller();
42: use HTML::Entities();
43:
44: sub handler {
45: my $r = shift;
46: &Apache::loncommon::content_type($r,'text/html');
47: $r->send_http_header;
48: return OK if $r->header_only;
49:
50: my $target=$env{'form.grade_target'};
51: # --------------------------------------------------- Get course info from URL
52: my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
53: # ------------------------------------------------------------ Get query string
54: &Apache::loncommon::get_unprocessed_cgi
55: ($ENV{'QUERY_STRING'},['register','forceedit','todocs',
56: 'folderpath','title']);
57: # ----------------------------------------------------- Is this even a course?
58: my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom);
59: if ($homeserver eq 'no_host') {
60: &Apache::loncommon::content_type($r,'text/html');
61: $r->send_http_header;
62: &Apache::loncommon::simple_error_page($r,'No syllabus available',
63: 'No syllabus available');
64: return OK;
65: } elsif (!&Apache::lonnet::is_course($cdom,$cnum)) {
66: &Apache::loncommon::content_type($r,'text/html');
67: $r->send_http_header;
68: &Apache::loncommon::simple_error_page($r,'No syllabus available',
69: 'The course/community for which the syllabus was requested does not exist.');
70: return OK;
71: }
72: # ------------------------------------- There is such a course, get environment
73: my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
74:
75: # ------------------------------------------------------------ Print the screen
76:
77: if ($target eq 'tex') {
78: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
79: }
80: # -------------------------------------------------- Let's see who handles this
81: my $externalsyllabus=$courseenv{'externalsyllabus'};
82:
83: if ($externalsyllabus=~/\w/) {
84: $r->print( Apache::lonwrapper::wrapper($externalsyllabus) );
85: return OK;
86: }
87:
88: # ------------------------------ The buck stops here: internal syllabus display
89: # --------------------------------------------------------- The syllabus fields
90: my %syllabusfields=&Apache::lonlocal::texthash(
91: 'aaa_instructorinfo' => 'Instructor Information',
92: 'bbb_description' => 'Course Description',
93: 'ccc_prereq' => 'Prerequisites',
94: 'cdc_classhours' => 'Class Hours',
95: 'ddd_officehours' => 'Office Hours',
96: 'eee_helproom' => 'Helproom Hours',
97: 'efe_projectinfo' => 'Project Information',
98: 'fff_examinfo' => 'Exam Information',
99: 'fgf_deadlines' => 'Deadlines',
100: 'ggg_grading' => 'Grading Information',
101: 'hhh_readings' => 'Readings',
102: 'iii_coursepack' => 'Coursepack',
103: 'jjj_weblinks' => 'Web Links',
104: 'kkk_textbook' => 'Textbook',
105: 'lll_includeurl' => 'URLs To Include in Syllabus');
106: # --------------------------------------------------------------- Force Student
107: my ($forceedit,$forcestudent);
108: if ($env{'form.forceedit'}) { $forceedit=1; }
109: if (!$forceedit) {
110: $forcestudent=1;
111: }
112: # ----------------------------------------------------------------- Make header
113: if ($target ne 'tex') {
114: my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
115: my $js;
116: if ($env{'form.backto'} eq 'coursecatalog') {
117: $js .= <<"ENDSCRIPT";
118:
119: <script type="text/javascript">
120: function ToCatalog(caller) {
121: numidx = getIndexByName('coursenum');
122: if (numidx > -1) {
123: if (caller != 'details') {
124: document.backtocat.elements[numidx].value = '';
125: }
126: }
127: document.backtocat.submit();
128: }
129:
130: function getIndexByName(item) {
131: for (var i=0;i<document.backtocat.elements.length;i++) {
132: if (document.backtocat.elements[i].name == item) {
133: return i;
134: }
135: }
136: return -1;
137: }
138:
139: </script>
140:
141: ENDSCRIPT
142: }
143: my $args = {'function' => undef,
144: 'domain' => $cdom};
145: my $forcereg;
146: if ($env{'form.register'}) {
147: $forcereg = 1;
148: $args->{'force_register'} = $forcereg;
149: }
150: if ($env{'form.backto'} eq 'coursecatalog') {
151: &Apache::lonhtmlcommon::clear_breadcrumbs();
152: my $brcrum = [{href=>"javascript:ToCatalog();",
153: text=>&mt('Course/Community Catalog'),
154: no_mt=>1}
155: ];
156: if ($env{'form.coursenum'} ne '') {
157: push(@{$brcrum},
158: {href=>"javascript:ToCatalog('details')",
159: text=>"Course details"});
160: }
161: push(@{$brcrum},
162: {href=>$r->uri,
163: text=>"Course syllabus"});
164: $args->{'bread_crumbs'} = $brcrum;
165: } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
166: my $crstype = &Apache::loncommon::course_type();
167: my $title = $env{'form.title'};
168: if ($title eq '') {
169: $title = &mt('Syllabus');
170: }
171: my $brcrum =
172: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
173: if (ref($brcrum) eq 'ARRAY') {
174: $args->{'bread_crumbs'} = $brcrum;
175: }
176: }
177: my $start_page =
178: &Apache::loncommon::start_page("Syllabus", $rss_link.$js,$args);
179: $r->print($start_page);
180: }
181: # ---------------------------------------------------------- Load syllabus info
182: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
183: my $allowed=0;
184:
185: # This handler might be called anonymously ...
186: # ----------------------------------------------------- Only if not public call
187: if ($env{'user.environment'}) {
188: # does this user have privileges to post, etc?
189: if ($env{'request.course.id'}
190: && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
191: && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
192: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
193: if ($forcestudent or $target eq 'tex') { $allowed=0; }
194: }
195: #store what the user typed in
196: if (($allowed) && ($env{'form.storesyl'})) {
197: foreach my $syl_field (keys(%syllabusfields)) {
198: my $field=$env{'form.'.$syl_field};
199: chomp($field);
200: $field=~s/\s+$//s;
201: $field=~s/^\s+//s;
202: $field=~s/\<br\s*\/*\>$//s;
203: $field=&Apache::lonfeedback::clear_out_html($field,1);
204: #here it will be stored
205: $syllabus{$syl_field}=$field;
206: if ($syl_field eq 'lll_includeurl') { # clean up included URLs
207: my $field='';
208: foreach my $value (split(/\n/,$syllabus{$syl_field})) {
209: my $url=$value;
210: # get rid of leading and trailing spaces
211: $url=~s/^\s+//;
212: $url=~s/\s+$//;
213: if ($url=~m|^https?\://([^/]+)/(.+)$|) {
214: my $host = $1;
215: my $remainder=$2;
216: # remove the hostname from internal URLs
217: my $hostname = &Apache::lonnet::hostname($host);
218: my %all_hostnames = &Apache::lonnet::all_hostnames();
219: foreach my $possible_host (keys(%all_hostnames)) {
220: if ($possible_host =~ /\Q$hostname\E/i) {
221: $url=$remainder;
222: }
223: }
224: }
225: # norm internal URLs
226: unless ($url=~/^https?\:/) {
227: $url=&Apache::lonnet::clutter($url);
228: }
229: # re-assemble field
230: if ($url) {
231: $field.=$url."\n";
232: }
233: }
234: $syllabus{$syl_field}=$field;
235: }
236: }
237: $syllabus{'uploaded.domain'}=$env{'user.domain'};
238: $syllabus{'uploaded.name'}=$env{'user.name'};
239: $syllabus{'uploaded.lastmodified'}=time;
240: &Apache::lonnet::put('syllabus',\%syllabus,$cdom,$cnum);
241: }
242: }
243:
244: if ($allowed) {
245: #---------------------------------- Print External URL Syllabus Info if editing
246: if ($target ne 'tex') {
247: my $protocol = $Apache::lonnet::protocol{$homeserver};
248: $protocol = 'http' if ($protocol ne 'https');
249: $r->print('<div class="LC_info">'
250: .'<p>'
251: .&mt('This syllabus can be publicly viewed at [_1]'
252: ,'<tt>'.$protocol.'://'.&Apache::lonnet::hostname($homeserver).$r->uri.'</tt>')
253: .' '.&Apache::loncommon::help_open_topic('Syllabus_ExtLink')
254: .'</p>'
255: .'<p>'
256: .&mt('Instead of using this template you can specify an external URL as Syllabus in the [_1]Course Configuration[_2].'
257: ,'<a href="/adm/courseprefs?actions=courseinfo&phase=display">','</a>')
258: .'</p>'
259: .'</div>');
260: }
261: } else {
262: #--------------------------------------------- Print last update unless editing
263: my $lastmod=$syllabus{'uploaded.lastmodified'};
264: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
265: my $who;
266: if ($syllabus{'uploaded.lastmodified'}) {
267: if (($env{'user.name'} ne 'public') && ($env{'user.domain'} ne 'public')) {
268: $who = &Apache::loncommon::aboutmewrapper(
269: &Apache::loncommon::plainname($syllabus{'uploaded.name'},
270: $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
271: $syllabus{'uploaded.domain'});
272: } else {
273: # Public user?
274: # Only display name of user, but no link to personal information page
275: $who = &Apache::loncommon::plainname(
276: $syllabus{'uploaded.name'},
277: $syllabus{'uploaded.domain'});
278: }
279: }
280: if ($target ne 'tex') {
281: $r->print('<div class="LC_info">'.&mt('Last updated').': '.
282: $lastmod . ' '.
283: ($who ? &mt('by').' '.$who
284: : '' ) .
285: '</div>' );
286: } else {
287: $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.
288: ($who? &mt('by').'\\\\ '.
289: &Apache::loncommon::plainname($syllabus{'uploaded.name'},$syllabus{'uploaded.domain'})
290: :'')
291: .'\\\\');
292: }
293: }
294:
295: #-------------------------------------------------------------- Print Headtitle
296: if ($target ne 'tex') {
297: $r->print('<div class="LC_Box">'.
298: '<h2 class="LC_hcell">'.$courseenv{'description'}.'</h2>');
299: if ($allowed) {
300: $r->print('<div style="margin: 0; float:left;">'.
301: '<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>'.
302: '</div>');
303: # Print Help Text if editing at right side of screen
304: $r->print('<div style="margin: 0; float:right;">'.
305: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).
306: '</div><br clear="all" />');
307: } else {
308: $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>');
309: }
310: } else {
311: $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
312: &Apache::lonnet::domain($cdom,'description').'}\\\\');
313: }
314: # -------------------------------------------------------- Get course personnel
315: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
316: if ($target ne 'tex') {
317: $r->print(&Apache::lonhtmlcommon::start_pick_box());
318: } else {
319: $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
320: }
321: my @personnel=sort(keys(%coursepersonnel));
322: my $lastpers=$personnel[$#personnel];
323: foreach my $element (@personnel) {
324: if ($target ne 'tex') {
325: $r->print(&Apache::lonhtmlcommon::row_title($element));
326: } else {
327: $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & ');
328: }
329: my @coursepersonlist;
330: foreach (split(/\,/,$coursepersonnel{$element})) {
331: my ($puname,$pudom)=split(/\:/,$_);
332: if ($target ne 'tex') {
333: my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
334: if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
335: ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
336: push(@coursepersonlist,$courseperson);
337: } else {
338: push(@coursepersonlist,&Apache::loncommon::aboutmewrapper($courseperson,
339: $puname,$pudom));
340: }
341: } else {
342: push(@coursepersonlist,&Apache::loncommon::plainname($puname,
343: $pudom).' ');
344: }
345: }
346: $r->print(join(", ",@coursepersonlist));
347: if ($target ne 'tex') {
348: my $lastclose=$element eq $lastpers?1:0;
349: $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
350: } else {
351: $r->print('\\\\ \hline');
352: }
353: }
354: if ($target ne 'tex') {
355: $r->print(&Apache::lonhtmlcommon::end_pick_box());
356: } else {
357: $r->print('\end{tabular}\\\\');
358: }
359: # -------------------------------------------------------------- Announcements?
360: my $day = &Apache::lonannounce::showday(time,2,
361: &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
362: if ($target ne 'tex') {
363: if ($allowed) {
364: &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box');
365: $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
366: my $editurl= &Apache::lonnet::absolute_url().'/adm/'.$cdom.'/'.$cnum.'/_rss.html';
367: $r->print( '<a href="'.$editurl.'">'.&mt('New RSS Feed or Blog').'</a>');
368: &Apache::lontemplate::print_end_template($r);
369: } elsif (&Apache::lonrss::advertisefeeds($cnum,$cdom) ne '') {
370: &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box');
371: $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
372: &Apache::lontemplate::print_end_template($r);
373: }
374:
375: } else {
376: $r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
377: }
378: # ---------------------------------------------------------------- Get syllabus
379: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
380: if ($allowed) {
381: $r->print('<form method="post" action="">'.
382: '<input type="hidden" name="forceedit" value="'.$env{'form.forceedit'}.'" />');
383: }
384: my $url_include_handler = sub {
385: my ($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed) = @_;
386: my %data = %{$data_ref};
387: my %fields = %{$fields_ref};
388: my $urls=$message;
389: $message='';
390: foreach my $filelink (split(/\n/,$urls)) {
391: my $output='';
392: # embed style?
393: my ($curfext)=($filelink=~/\.([^\.]+)$/);
394: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
395: if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {# make ssi call and remove everything but the body contents
396: $output=&Apache::lonnet::ssi_body($filelink);
397: } elsif ($embstyle eq 'img') {# embed as an image
398: $output='<img src="'.$filelink.'" />';
399: }
400: if ($output ne '') {
401: if ($target ne 'tex') {
402: $message.='<p>'.$output.'</p>';
403: } else {
404: $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
405: }
406: }
407: }
408: if ($allowed) {
409: &Apache::lonfeedback::newline_to_br(\$urls);
410: &Apache::lontemplate::print_start_template($r,$fields{$field}.
411: &Apache::loncommon::help_open_topic('Syllabus_URLs'),'LC_Box');
412: $r->print($urls);
413: $r->print("<br /><div>");
414: &Apache::lontemplate::print_textarea_template($r, $data{$field},
415: $field, Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
416: &Apache::lontemplate::print_saveall_template($r);
417: $r->print("</div>");
418: &Apache::lontemplate::print_end_template($r);
419:
420: } else {
421: $r->print($message);
422: }
423: };
424: my %custom_hash = ( 'lll_includeurl' => $url_include_handler );
425: &Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields,
426: $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_hash);
427: if ($allowed) {
428: $r->print('</form>'.
429: &Apache::lonhtmlcommon::htmlareaselectactive());
430: }
431: } else {
432: if ($target ne 'tex') {$r->print('<p class="LC_info">');} else {$r->print('\par ');}
433: $r->print(&mt('No syllabus information provided.'));
434: if ($target ne 'tex') {$r->print('</p>');}
435: }
436: if ($target ne 'tex') {
437: $r->print('</div>');
438: if ($env{'form.backto'} eq 'coursecatalog') {
439: $r->print('<form name="backtocat" method="post" action="/adm/coursecatalog">'.
440: &Apache::lonhtmlcommon::echo_form_input(['backto','courseid']).
441: '</form>');
442: }
443: $r->print(&Apache::loncommon::end_page());
444: } else {
445: $r->print('\end{document}');
446: }
447: return OK;
448: }
449:
450: 1;
451: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>