Annotation of loncom/interface/lonsyllabus.pm, revision 1.115
1.1 www 1: # The LearningOnline Network
2: # Syllabus
3: #
1.115 ! raeburn 4: # $Id: lonsyllabus.pm,v 1.114 2012/12/03 23:53:03 raeburn Exp $
1.1 www 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;
1.70 amueller 32: use Apache::lontemplate;
1.1 www 33: use Apache::Constants qw(:common);
34: use Apache::loncommon;
35: use Apache::lonnet;
1.5 www 36: use Apache::lontexconvert;
1.11 www 37: use Apache::lonfeedback;
1.19 www 38: use Apache::lonannounce;
1.23 www 39: use Apache::lonlocal;
1.32 www 40: use Apache::lonhtmlcommon;
1.38 www 41: use Apache::lonspeller();
1.54 albertel 42: use HTML::Entities();
1.1 www 43:
44: sub handler {
45: my $r = shift;
1.46 www 46: &Apache::loncommon::content_type($r,'text/html');
47: $r->send_http_header;
48: return OK if $r->header_only;
1.45 www 49:
1.46 www 50: my $target=$env{'form.grade_target'};
1.45 www 51: # --------------------------------------------------- Get course info from URL
52: my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.46 www 53: # ------------------------------------------------------------ Get query string
54: &Apache::loncommon::get_unprocessed_cgi
1.115 ! raeburn 55: ($ENV{'QUERY_STRING'},['register','forceedit',
! 56: 'folderpath','title']);
1.45 www 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;
1.106 faziophi 62: &Apache::loncommon::simple_error_page($r,'No syllabus available',
1.91 amueller 63: 'No syllabus available');
1.45 www 64: return OK;
1.113 raeburn 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;
1.45 www 71: }
72: # ------------------------------------- There is such a course, get environment
73: my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.46 www 74:
1.1 www 75: # ------------------------------------------------------------ Print the screen
1.49 albertel 76:
77: if ($target eq 'tex') {
1.91 amueller 78: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.86 bisitz 79: }
1.46 www 80: # -------------------------------------------------- Let's see who handles this
1.47 www 81: my $externalsyllabus=$courseenv{'externalsyllabus'};
1.49 albertel 82:
1.46 www 83: if ($externalsyllabus=~/\w/) {
1.107 droeschl 84: $r->print( Apache::lonwrapper::wrapper($externalsyllabus) );
85: return OK;
1.90 amueller 86: }
1.42 www 87:
1.46 www 88: # ------------------------------ The buck stops here: internal syllabus display
1.5 www 89: # --------------------------------------------------------- The syllabus fields
1.23 www 90: my %syllabusfields=&Apache::lonlocal::texthash(
1.5 www 91: 'aaa_instructorinfo' => 'Instructor Information',
92: 'bbb_description' => 'Course Description',
93: 'ccc_prereq' => 'Prerequisites',
1.7 www 94: 'cdc_classhours' => 'Class Hours',
1.5 www 95: 'ddd_officehours' => 'Office Hours',
96: 'eee_helproom' => 'Helproom Hours',
1.7 www 97: 'efe_projectinfo' => 'Project Information',
1.5 www 98: 'fff_examinfo' => 'Exam Information',
1.7 www 99: 'fgf_deadlines' => 'Deadlines',
1.5 www 100: 'ggg_grading' => 'Grading Information',
1.7 www 101: 'hhh_readings' => 'Readings',
102: 'iii_coursepack' => 'Coursepack',
103: 'jjj_weblinks' => 'Web Links',
1.9 www 104: 'kkk_textbook' => 'Textbook',
105: 'lll_includeurl' => 'URLs To Include in Syllabus');
1.6 www 106: # --------------------------------------------------------------- Force Student
1.113 raeburn 107: my ($forceedit,$forcestudent);
108: if ($env{'form.forceedit'}) { $forceedit=1; }
109: if (!$forceedit) {
110: $forcestudent=1;
111: }
1.86 bisitz 112: # ----------------------------------------------------------------- Make header
1.28 sakharuk 113: if ($target ne 'tex') {
1.91 amueller 114: my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
1.65 raeburn 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');
1.90 amueller 122: if (numidx > -1) {
123: if (caller != 'details') {
124: document.backtocat.elements[numidx].value = '';
125: }
1.65 raeburn 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: }
1.115 ! raeburn 143: my $args = {'function' => undef,
! 144: 'domain' => $cdom};
1.113 raeburn 145: my $forcereg;
146: if ($env{'form.register'}) {
147: $forcereg = 1;
1.115 ! raeburn 148: $args->{'force_register'} = $forcereg;
1.113 raeburn 149: }
150: if ($env{'form.backto'} eq 'coursecatalog') {
151: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.115 ! raeburn 152: my $brcrum = [{href=>"javascript:ToCatalog();",
! 153: text=>&mt('Course/Community Catalog'),
! 154: no_mt=>1}
! 155: ];
1.113 raeburn 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"});
1.114 raeburn 164: $args->{'bread_crumbs'} = $brcrum;
1.115 ! raeburn 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: }
1.114 raeburn 176: }
1.91 amueller 177: my $start_page =
1.114 raeburn 178: &Apache::loncommon::start_page("Syllabus", $rss_link.$js,$args);
1.91 amueller 179: $r->print($start_page);
1.17 www 180: }
181: # ---------------------------------------------------------- Load syllabus info
1.4 www 182: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
1.5 www 183: my $allowed=0;
1.4 www 184:
1.2 www 185: # This handler might be called anonymously ...
186: # ----------------------------------------------------- Only if not public call
1.40 albertel 187: if ($env{'user.environment'}) {
1.1 www 188: # does this user have privileges to post, etc?
1.90 amueller 189: if ($env{'request.course.id'}
1.91 amueller 190: && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
191: && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
1.90 amueller 192: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
193: if ($forcestudent or $target eq 'tex') { $allowed=0; }
194: }
1.113 raeburn 195: #store what the user typed in
1.90 amueller 196: if (($allowed) && ($env{'form.storesyl'})) {
1.91 amueller 197: foreach my $syl_field (keys(%syllabusfields)) {
1.90 amueller 198: my $field=$env{'form.'.$syl_field};
1.91 amueller 199: chomp($field);
1.90 amueller 200: $field=~s/\s+$//s;
1.91 amueller 201: $field=~s/^\s+//s;
202: $field=~s/\<br\s*\/*\>$//s;
203: $field=&Apache::lonfeedback::clear_out_html($field,1);
1.98 amueller 204: #here it will be stored
1.91 amueller 205: $syllabus{$syl_field}=$field;
1.90 amueller 206: if ($syl_field eq 'lll_includeurl') { # clean up included URLs
207: my $field='';
1.91 amueller 208: foreach my $value (split(/\n/,$syllabus{$syl_field})) {
209: my $url=$value;
1.9 www 210: # get rid of leading and trailing spaces
1.90 amueller 211: $url=~s/^\s+//;
212: $url=~s/\s+$//;
213: if ($url=~m|^https?\://([^/]+)/(.+)$|) {
1.91 amueller 214: my $host = $1;
1.90 amueller 215: my $remainder=$2;
1.9 www 216: # remove the hostname from internal URLs
1.91 amueller 217: my $hostname = &Apache::lonnet::hostname($host);
218: my %all_hostnames = &Apache::lonnet::all_hostnames();
219: foreach my $possible_host (keys(%all_hostnames)) {
1.90 amueller 220: if ($possible_host =~ /\Q$hostname\E/i) {
1.91 amueller 221: $url=$remainder;
222: }
223: }
224: }
1.9 www 225: # norm internal URLs
1.90 amueller 226: unless ($url=~/^https?\:/) {
1.91 amueller 227: $url=&Apache::lonnet::clutter($url);
1.90 amueller 228: }
1.9 www 229: # re-assemble field
1.90 amueller 230: if ($url) {
1.91 amueller 231: $field.=$url."\n";
1.90 amueller 232: }
1.91 amueller 233: }
1.90 amueller 234: $syllabus{$syl_field}=$field;
1.91 amueller 235: }
1.90 amueller 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: }
1.4 www 242: }
1.85 bisitz 243:
1.113 raeburn 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>');
1.93 bisitz 260: }
1.109 bisitz 261: } else {
1.113 raeburn 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: }
1.109 bisitz 293: }
294:
1.113 raeburn 295: #-------------------------------------------------------------- Print Headtitle
1.90 amueller 296: if ($target ne 'tex') {
1.113 raeburn 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: }
1.90 amueller 310: } else {
1.91 amueller 311: $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
312: &Apache::lonnet::domain($cdom,'description').'}\\\\');
1.90 amueller 313: }
1.80 neumanie 314: # -------------------------------------------------------- Get course personnel
315: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
316: if ($target ne 'tex') {
1.91 amueller 317: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1.80 neumanie 318: } else {
1.91 amueller 319: $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
1.80 neumanie 320: }
321: my @personnel=sort(keys(%coursepersonnel));
322: my $lastpers=$personnel[$#personnel];
323: foreach my $element (@personnel) {
1.91 amueller 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: }
1.111 christia 329: my @coursepersonlist;
1.80 neumanie 330: foreach (split(/\,/,$coursepersonnel{$element})) {
1.91 amueller 331: my ($puname,$pudom)=split(/\:/,$_);
332: if ($target ne 'tex') {
1.80 neumanie 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')) {
1.111 christia 336: push(@coursepersonlist,$courseperson);
1.80 neumanie 337: } else {
1.111 christia 338: push(@coursepersonlist,&Apache::loncommon::aboutmewrapper($courseperson,
1.80 neumanie 339: $puname,$pudom));
340: }
1.91 amueller 341: } else {
1.111 christia 342: push(@coursepersonlist,&Apache::loncommon::plainname($puname,
1.80 neumanie 343: $pudom).' ');
1.91 amueller 344: }
345: }
1.111 christia 346: $r->print(join(", ",@coursepersonlist));
1.91 amueller 347: if ($target ne 'tex') {
1.80 neumanie 348: my $lastclose=$element eq $lastpers?1:0;
349: $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
1.91 amueller 350: } else {
351: $r->print('\\\\ \hline');
352: }
1.80 neumanie 353: }
354: if ($target ne 'tex') {
1.91 amueller 355: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1.80 neumanie 356: } else {
1.91 amueller 357: $r->print('\end{tabular}\\\\');
1.80 neumanie 358: }
1.79 neumanie 359: # -------------------------------------------------------------- Announcements?
360: my $day = &Apache::lonannounce::showday(time,2,
1.91 amueller 361: &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
1.80 neumanie 362: if ($target ne 'tex') {
1.91 amueller 363: if ($allowed) {
1.108 wenzelju 364: &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box');
1.91 amueller 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 '') {
1.108 wenzelju 370: &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box');
1.91 amueller 371: $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
372: &Apache::lontemplate::print_end_template($r);
373: }
1.86 bisitz 374:
1.79 neumanie 375: } else {
1.91 amueller 376: $r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
1.86 bisitz 377: }
1.79 neumanie 378: # ---------------------------------------------------------------- Get syllabus
1.86 bisitz 379: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.90 amueller 380: if ($allowed) {
1.95 bisitz 381: $r->print('<form method="post" action="">'.
1.113 raeburn 382: '<input type="hidden" name="forceedit" value="'.$env{'form.forceedit'}.'" />');
1.90 amueller 383: }
1.106 faziophi 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);
1.86 bisitz 419:
1.106 faziophi 420: } else {
421: $r->print($message);
422: }
423: };
424: my %custom_hash = ( 'lll_includeurl' => $url_include_handler );
1.110 raeburn 425: &Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields,
1.106 faziophi 426: $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_hash);
1.90 amueller 427: if ($allowed) {
1.91 amueller 428: $r->print('</form>'.
1.110 raeburn 429: &Apache::lonhtmlcommon::htmlareaselectactive());
1.90 amueller 430: }
1.4 www 431: } else {
1.112 bisitz 432: if ($target ne 'tex') {$r->print('<p class="LC_info">');} else {$r->print('\par ');}
1.91 amueller 433: $r->print(&mt('No syllabus information provided.'));
434: if ($target ne 'tex') {$r->print('</p>');}
1.1 www 435: }
1.86 bisitz 436: if ($target ne 'tex') {
1.113 raeburn 437: $r->print('</div>');
1.65 raeburn 438: if ($env{'form.backto'} eq 'coursecatalog') {
439: $r->print('<form name="backtocat" method="post" action="/adm/coursecatalog">'.
1.66 raeburn 440: &Apache::lonhtmlcommon::echo_form_input(['backto','courseid']).
1.65 raeburn 441: '</form>');
442: }
1.91 amueller 443: $r->print(&Apache::loncommon::end_page());
1.48 albertel 444: } else {
1.91 amueller 445: $r->print('\end{document}');
1.48 albertel 446: }
1.1 www 447: return OK;
1.86 bisitz 448: }
1.1 www 449:
450: 1;
451: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>