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