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