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