Annotation of loncom/interface/lonsyllabus.pm, revision 1.100
1.1 www 1: # The LearningOnline Network
2: # Syllabus
3: #
1.100 ! bisitz 4: # $Id: lonsyllabus.pm,v 1.99 2009/09/27 11:05:06 amueller 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.47 www 55: ($ENV{'QUERY_STRING'},['forcestudent','register','forceedit','wrapperdisplay']);
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.91 amueller 61: &Apache::loncommon::simple_error_page($r,'No syllabus available',
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.86 bisitz 77:
1.47 www 78: if ($env{'form.wrapperdisplay'} eq 'menu') {
1.91 amueller 79: $r->print(&Apache::lonwrapper::simple_menu());
1.86 bisitz 80: } else {
1.91 amueller 81: $r->print(&Apache::lonwrapper::wrapper("/public/$cdom/$cnum/syllabus?wrapperdisplay=menu",
82: $externalsyllabus));
1.50 albertel 83: }
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
106: my $forcestudent='';
1.40 albertel 107: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.27 www 108: my $forceedit='';
1.40 albertel 109: if ($env{'form.forceedit'}) { $forceedit='edit'; }
1.86 bisitz 110:
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.91 amueller 142: my $start_page =
143: &Apache::loncommon::start_page("Syllabus", $rss_link.$js,
1.97 amueller 144: {'function' => undef,
1.91 amueller 145: 'domain' => $cdom,
146: 'force_register' =>
147: $env{'form.register'},});
1.49 albertel 148:
1.91 amueller 149: $r->print($start_page);
1.65 raeburn 150: if ($env{'form.backto'} eq 'coursecatalog') {
151: &Apache::lonhtmlcommon::clear_breadcrumbs();
152: &Apache::lonhtmlcommon::add_breadcrumb
1.90 amueller 153: ({href=>"javascript:ToCatalog()",
1.100 ! bisitz 154: text=>"Course/Community Catalog"});
1.65 raeburn 155: if ($env{'form.coursenum'} ne '') {
156: &Apache::lonhtmlcommon::add_breadcrumb
1.90 amueller 157: ({href=>"javascript:ToCatalog('details')",
158: text=>"Course details"});
1.65 raeburn 159: }
160: &Apache::lonhtmlcommon::add_breadcrumb
1.90 amueller 161: ({href=>$r->uri,
162: text=>"Course syllabus"});
1.65 raeburn 163: $r->print(&Apache::lonhtmlcommon::breadcrumbs());
1.86 bisitz 164: }
1.17 www 165: }
166: # ---------------------------------------------------------- Load syllabus info
1.4 www 167: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
1.5 www 168: my $allowed=0;
1.27 www 169: my $privileged=0;
1.4 www 170:
1.2 www 171: # This handler might be called anonymously ...
172: # ----------------------------------------------------- Only if not public call
1.40 albertel 173: if ($env{'user.environment'}) {
1.1 www 174: # does this user have privileges to post, etc?
1.90 amueller 175: if ($env{'request.course.id'}
1.91 amueller 176: && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
177: && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
1.90 amueller 178: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.91 amueller 179: $privileged=$allowed;
180: if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
181: $forcestudent='student';
182: }
1.90 amueller 183: if ($forcestudent or $target eq 'tex') { $allowed=0; }
184: }
1.98 amueller 185: #store what the user typed in
1.90 amueller 186: if (($allowed) && ($env{'form.storesyl'})) {
1.91 amueller 187: foreach my $syl_field (keys(%syllabusfields)) {
1.90 amueller 188: my $field=$env{'form.'.$syl_field};
1.91 amueller 189: chomp($field);
1.90 amueller 190: $field=~s/\s+$//s;
1.91 amueller 191: $field=~s/^\s+//s;
192: $field=~s/\<br\s*\/*\>$//s;
193: $field=&Apache::lonfeedback::clear_out_html($field,1);
1.98 amueller 194: #here it will be stored
1.91 amueller 195: $syllabus{$syl_field}=$field;
1.90 amueller 196: if ($syl_field eq 'lll_includeurl') { # clean up included URLs
197: my $field='';
1.91 amueller 198: foreach my $value (split(/\n/,$syllabus{$syl_field})) {
199: my $url=$value;
1.9 www 200: # get rid of leading and trailing spaces
1.90 amueller 201: $url=~s/^\s+//;
202: $url=~s/\s+$//;
203: if ($url=~m|^https?\://([^/]+)/(.+)$|) {
1.91 amueller 204: my $host = $1;
1.90 amueller 205: my $remainder=$2;
1.9 www 206: # remove the hostname from internal URLs
1.91 amueller 207: my $hostname = &Apache::lonnet::hostname($host);
208: my %all_hostnames = &Apache::lonnet::all_hostnames();
209: foreach my $possible_host (keys(%all_hostnames)) {
1.90 amueller 210: if ($possible_host =~ /\Q$hostname\E/i) {
1.91 amueller 211: $url=$remainder;
212: }
213: }
214: }
1.9 www 215: # norm internal URLs
1.90 amueller 216: unless ($url=~/^https?\:/) {
1.91 amueller 217: $url=&Apache::lonnet::clutter($url);
1.90 amueller 218: }
1.9 www 219: # re-assemble field
1.90 amueller 220: if ($url) {
1.91 amueller 221: $field.=$url."\n";
1.90 amueller 222: }
1.91 amueller 223: }
1.90 amueller 224: $syllabus{$syl_field}=$field;
1.91 amueller 225: }
1.90 amueller 226: }
227: $syllabus{'uploaded.domain'}=$env{'user.domain'};
228: $syllabus{'uploaded.name'}=$env{'user.name'};
229: $syllabus{'uploaded.lastmodified'}=time;
230: &Apache::lonnet::put('syllabus',\%syllabus,$cdom,$cnum);
231: }
1.4 www 232: }
1.85 bisitz 233:
1.93 bisitz 234: #--------Functions
1.94 droeschl 235: if( ($allowed || $privileged) && $target ne 'tex') {
236: my $functions=&Apache::lonhtmlcommon::start_funclist();
237: if ($allowed) {
1.97 amueller 238: #if you have the register flag, keep it
239: if($env{'form.register'} == 1) {
240: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
1.99 amueller 241: '<a href="'.$r->uri.'?forcestudent=1&register=1">'
1.97 amueller 242: .&mt('Show Public View').'</a>'
243: .&Apache::loncommon::help_open_topic(
244: 'Uploaded_Templates_PublicView'));
245: } else {
246: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
1.94 droeschl 247: '<a href="'.$r->uri.'?forcestudent=1">'
248: .&mt('Show Public View').'</a>'
249: .&Apache::loncommon::help_open_topic(
250: 'Uploaded_Templates_PublicView'));
1.97 amueller 251: }
1.93 bisitz 252: } elsif ($privileged) {
1.97 amueller 253: if($env{'form.register'} == 1) {
254: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
1.99 amueller 255: '<a href="'.$r->uri.'?forceedit=1&register=1">'
1.97 amueller 256: .&mt('Edit').'</a>');
257: } else {
258: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
1.94 droeschl 259: '<a href="'.$r->uri.'?forceedit=1">'
260: .&mt('Edit').'</a>');
1.97 amueller 261: }
1.93 bisitz 262: }
1.94 droeschl 263:
1.93 bisitz 264: $functions.=&Apache::lonhtmlcommon::end_funclist();
265: $r->print(&Apache::loncommon::head_subbox($functions));
266: }
267:
1.94 droeschl 268: #---------------------Print External URL Syllabus Info and Help Text
1.90 amueller 269: if( ($allowed) && ($target ne 'tex') ) {
1.91 amueller 270: my $protocol = $Apache::lonnet::protocol{$homeserver};
271: $protocol = 'http' if ($protocol ne 'https');
1.85 bisitz 272: $r->print('<p class="LC_info">'
273: .&mt('This syllabus can be publicly viewed at [_1]'
274: ,'<tt>'.$protocol.'://'.&Apache::lonnet::hostname($homeserver).$r->uri.'</tt>')
275: .' '.&Apache::loncommon::help_open_topic('Syllabus_ExtLink')
276: .'</p>'
277: .'<p class="LC_info">'
1.96 raeburn 278: .&mt('Instead of using this template you can specify an external URL as Syllabus in the [_1]Course Configuration[_2].'
1.99 amueller 279: ,'<a href="/adm/courseprefs?actions=courseinfo&phase=display">','</a>')
1.85 bisitz 280: .'</p>'
281: );
1.94 droeschl 282: #-Print Help Text
283: $r->print(&Apache::loncommon::help_open_topic(
284: 'Uploaded_Templates_TextBoxes',
285: &mt('Help with filling in text boxes')));
1.90 amueller 286: }
1.85 bisitz 287:
1.88 amueller 288: #----------Print last update
1.90 amueller 289: my $lastmod=$syllabus{'uploaded.lastmodified'};
290: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
291: my $who = &Apache::loncommon::aboutmewrapper(
292: &Apache::loncommon::plainname($syllabus{'uploaded.name'},
293: $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
294: $syllabus{'uploaded.domain'});
295: if ($target ne 'tex') {
1.91 amueller 296: $r->print('<div class="LC_info">'.&mt('Last updated').': '.
297: $lastmod . ' '.
298: ($who ? &mt('by').' '.$who
1.89 bisitz 299: : '' ) .
1.88 amueller 300: '</div>' );
1.89 bisitz 301:
1.90 amueller 302: } else {
1.91 amueller 303: $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.
304: ($who? &mt('by').'\\\\ '.
305: &Apache::loncommon::plainname($syllabus{'uploaded.name'},$syllabus{'uploaded.domain'})
306: :'')
307: .'\\\\');
1.90 amueller 308: }
1.80 neumanie 309: #----------------------------Print Headtitle
1.90 amueller 310: if ($target ne 'tex') {
1.91 amueller 311: $r->print('<h1>'.$courseenv{'description'}.'</h1>');
312: $r->print('<h3>'. &Apache::lonnet::domain($cdom,'description').'</h3>');
1.90 amueller 313: } else {
1.91 amueller 314: $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
315: &Apache::lonnet::domain($cdom,'description').'}\\\\');
1.90 amueller 316: }
1.80 neumanie 317: # -------------------------------------------------------- Get course personnel
318: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
319: if ($target ne 'tex') {
1.91 amueller 320: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1.80 neumanie 321: } else {
1.91 amueller 322: $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
1.80 neumanie 323: }
324: my @personnel=sort(keys(%coursepersonnel));
325: my $lastpers=$personnel[$#personnel];
326: foreach my $element (@personnel) {
1.91 amueller 327: if ($target ne 'tex') {
328: $r->print(&Apache::lonhtmlcommon::row_title($element));
329: } else {
330: $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & ');
331: }
1.80 neumanie 332: foreach (split(/\,/,$coursepersonnel{$element})) {
1.91 amueller 333: my ($puname,$pudom)=split(/\:/,$_);
334: if ($target ne 'tex') {
1.80 neumanie 335: my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
336: if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
337: ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
1.91 amueller 338: $r->print(' '.$courseperson);
1.80 neumanie 339: } else {
340: $r->print(' '.&Apache::loncommon::aboutmewrapper($courseperson,
341: $puname,$pudom));
342: }
1.91 amueller 343: } else {
344: $r->print(' '.&Apache::loncommon::plainname($puname,
1.80 neumanie 345: $pudom).' ');
1.91 amueller 346: }
347: }
348: if ($target ne 'tex') {
1.80 neumanie 349: my $lastclose=$element eq $lastpers?1:0;
350: $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
1.91 amueller 351: } else {
352: $r->print('\\\\ \hline');
353: }
1.80 neumanie 354: }
355: if ($target ne 'tex') {
1.91 amueller 356: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1.80 neumanie 357: } else {
1.91 amueller 358: $r->print('\end{tabular}\\\\');
1.80 neumanie 359: }
1.79 neumanie 360: # -------------------------------------------------------------- Announcements?
361: my $day = &Apache::lonannounce::showday(time,2,
1.91 amueller 362: &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
1.80 neumanie 363: if ($target ne 'tex') {
1.91 amueller 364: if ($allowed) {
1.92 bisitz 365: &Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_Box');
1.91 amueller 366: $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
367: my $editurl= &Apache::lonnet::absolute_url().'/adm/'.$cdom.'/'.$cnum.'/_rss.html';
368: $r->print( '<a href="'.$editurl.'">'.&mt('New RSS Feed or Blog').'</a>');
369: &Apache::lontemplate::print_end_template($r);
370: } elsif (&Apache::lonrss::advertisefeeds($cnum,$cdom) ne '') {
1.92 bisitz 371: &Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_Box');
1.91 amueller 372: $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
373: &Apache::lontemplate::print_end_template($r);
374: }
1.86 bisitz 375:
1.79 neumanie 376: } else {
1.91 amueller 377: $r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
1.86 bisitz 378: }
1.79 neumanie 379: # ---------------------------------------------------------------- Get syllabus
1.86 bisitz 380: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.90 amueller 381: if ($allowed) {
1.95 bisitz 382: $r->print('<form method="post" action="">'.
1.91 amueller 383: '<input type="hidden" name="forceedit" value="edit" />');
1.90 amueller 384: }
385: my @htmlids=();
1.86 bisitz 386:
1.91 amueller 387: foreach my $field (sort(keys(%syllabusfields))) {
388: if (($syllabus{$field}=~/\w/) || ($allowed)) {
389: my $message=$syllabus{$field};
390: if ($field eq 'lll_includeurl') { # this is the "included" field
391: my $urls=$message;
392: $message='';
393: foreach my $filelink (split(/\n/,$urls)) {
394: my $output='';
395: # embed style?
396: my ($curfext)=($filelink=~/\.([^\.]+)$/);
397: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
398: if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {# make ssi call and remove everything but the body contents
399: $output=&Apache::lonnet::ssi_body($filelink);
400: } elsif ($embstyle eq 'img') {# embed as an image
401: $output='<img src="'.$filelink.'" />';
402: }
403: if ($output ne '') {
404: if ($target ne 'tex') {
405: $message.='<p>'.$output.'</p>';
406: } else {
407: $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
408: }
409: }
410: }
411: if ($allowed) {
412: $r->print('<h3>'.$syllabusfields{$field}.
413: &Apache::loncommon::help_open_topic('Syllabus_URLs').'</h3>');
414: } else {
415: $r->print($message);
416: }
417: } else {
418: &Apache::lonfeedback::newline_to_br(\$message);
419: $message =~s|(https?\://[^\s]+)|<a href="$1"><tt>$1</tt></a>|g;
420: if ($allowed) {
421: $message=&Apache::lonspeller::markeduptext($message);
422: }
423: $message=&Apache::lontexconvert::msgtexconverted($message);
424: if ($target ne 'tex') {
1.98 amueller 425: #output of syllabusfields will be generated here.
1.92 bisitz 426: &Apache::lontemplate::print_template($r, $syllabusfields{$field}, $message,$allowed,'LC_Box');
1.91 amueller 427: } else {
428: $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
429: &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
430: }
431: push(@htmlids,$field);
432: }
433: if ($allowed) {
434: if ($target ne 'tex') {
435: &Apache::lontemplate::print_editbox_template($r, $syllabus{$field}, $field);
436: }
437: }
438: }
1.90 amueller 439: }
440: if ($allowed) {
1.91 amueller 441: $r->print('</form>'.
442: &Apache::lonhtmlcommon::htmlareaselectactive(@htmlids));
1.90 amueller 443: }
1.79 neumanie 444: # if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
1.4 www 445: } else {
1.91 amueller 446: if ($target ne 'tex') {$r->print('<p>');} else {$r->print('\par ');}
447: $r->print(&mt('No syllabus information provided.'));
448: if ($target ne 'tex') {$r->print('</p>');}
1.1 www 449: }
1.86 bisitz 450: if ($target ne 'tex') {
1.65 raeburn 451: if ($env{'form.backto'} eq 'coursecatalog') {
452: $r->print('<form name="backtocat" method="post" action="/adm/coursecatalog">'.
1.66 raeburn 453: &Apache::lonhtmlcommon::echo_form_input(['backto','courseid']).
1.65 raeburn 454: '</form>');
455: }
1.91 amueller 456: $r->print(&Apache::loncommon::end_page());
1.48 albertel 457: } else {
1.91 amueller 458: $r->print('\end{document}');
1.48 albertel 459: }
1.1 www 460: return OK;
1.86 bisitz 461: }
1.1 www 462:
463: 1;
464: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>