Annotation of loncom/interface/lonsyllabus.pm, revision 1.68
1.1 www 1: # The LearningOnline Network
2: # Syllabus
3: #
1.68 ! bisitz 4: # $Id: lonsyllabus.pm,v 1.67 2008/08/25 14:50:01 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;
32: use Apache::Constants qw(:common);
33: use Apache::loncommon;
34: use Apache::lonnet;
1.5 www 35: use Apache::lontexconvert;
1.11 www 36: use Apache::lonfeedback;
1.19 www 37: use Apache::lonannounce;
1.23 www 38: use Apache::lonlocal;
1.32 www 39: use Apache::lonhtmlcommon;
1.38 www 40: use Apache::lonspeller();
1.54 albertel 41: use HTML::Entities();
1.1 www 42:
43: sub handler {
44: my $r = shift;
1.46 www 45: &Apache::loncommon::content_type($r,'text/html');
46: $r->send_http_header;
47: return OK if $r->header_only;
1.45 www 48:
1.46 www 49: my $target=$env{'form.grade_target'};
1.45 www 50: # --------------------------------------------------- Get course info from URL
51: my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.46 www 52: # ------------------------------------------------------------ Get query string
53: &Apache::loncommon::get_unprocessed_cgi
1.47 www 54: ($ENV{'QUERY_STRING'},['forcestudent','register','forceedit','wrapperdisplay']);
1.45 www 55: # ----------------------------------------------------- Is this even a course?
56: my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom);
57: if ($homeserver eq 'no_host') {
58: &Apache::loncommon::content_type($r,'text/html');
59: $r->send_http_header;
1.49 albertel 60: &Apache::loncommon::simple_error_page($r,'No syllabus available',
61: 'No syllabus available');
1.45 www 62: return OK;
63: }
64: # ------------------------------------- There is such a course, get environment
65: my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.46 www 66:
1.1 www 67: # ------------------------------------------------------------ Print the screen
1.49 albertel 68:
69: if ($target eq 'tex') {
1.40 albertel 70: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.28 sakharuk 71: }
1.46 www 72: # -------------------------------------------------- Let's see who handles this
1.47 www 73: my $externalsyllabus=$courseenv{'externalsyllabus'};
1.49 albertel 74:
1.46 www 75: if ($externalsyllabus=~/\w/) {
1.50 albertel 76:
1.47 www 77: if ($env{'form.wrapperdisplay'} eq 'menu') {
1.50 albertel 78: $r->print(&Apache::lonwrapper::simple_menu());
79: } else {
80: $r->print(&Apache::lonwrapper::wrapper("/public/$cdom/$cnum/syllabus?wrapperdisplay=menu",
81: $externalsyllabus));
82: }
83: return OK;
1.47 www 84: }
1.42 www 85:
1.46 www 86: # ------------------------------ The buck stops here: internal syllabus display
1.5 www 87: # --------------------------------------------------------- The syllabus fields
1.23 www 88: my %syllabusfields=&Apache::lonlocal::texthash(
1.5 www 89: 'aaa_instructorinfo' => 'Instructor Information',
90: 'bbb_description' => 'Course Description',
91: 'ccc_prereq' => 'Prerequisites',
1.7 www 92: 'cdc_classhours' => 'Class Hours',
1.5 www 93: 'ddd_officehours' => 'Office Hours',
94: 'eee_helproom' => 'Helproom Hours',
1.7 www 95: 'efe_projectinfo' => 'Project Information',
1.5 www 96: 'fff_examinfo' => 'Exam Information',
1.7 www 97: 'fgf_deadlines' => 'Deadlines',
1.5 www 98: 'ggg_grading' => 'Grading Information',
1.7 www 99: 'hhh_readings' => 'Readings',
100: 'iii_coursepack' => 'Coursepack',
101: 'jjj_weblinks' => 'Web Links',
1.9 www 102: 'kkk_textbook' => 'Textbook',
103: 'lll_includeurl' => 'URLs To Include in Syllabus');
1.6 www 104: # --------------------------------------------------------------- Force Student
105: my $forcestudent='';
1.40 albertel 106: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.27 www 107: my $forceedit='';
1.40 albertel 108: if ($env{'form.forceedit'}) { $forceedit='edit'; }
1.5 www 109:
1.45 www 110: # ----------------------------------------------------------------- Make header
1.28 sakharuk 111: if ($target ne 'tex') {
1.60 albertel 112: my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
1.65 raeburn 113: my $js;
114: if ($env{'form.backto'} eq 'coursecatalog') {
115: $js .= <<"ENDSCRIPT";
116:
117: <script type="text/javascript">
118: function ToCatalog(caller) {
119: numidx = getIndexByName('coursenum');
120: if (numidx > -1) {
121: if (caller != 'details') {
122: document.backtocat.elements[numidx].value = '';
123: }
124: }
125: document.backtocat.submit();
126: }
127:
128: function getIndexByName(item) {
129: for (var i=0;i<document.backtocat.elements.length;i++) {
130: if (document.backtocat.elements[i].name == item) {
131: return i;
132: }
133: }
134: return -1;
135: }
136:
137: </script>
138:
139: ENDSCRIPT
140: }
1.49 albertel 141: my $start_page =
1.65 raeburn 142: &Apache::loncommon::start_page("Syllabus", $rss_link.$js,
1.49 albertel 143: {'function' => $forcestudent,
144: 'domain' => $cdom,
145: 'force_register' =>
146: $env{'form.register'},});
147:
1.65 raeburn 148: $r->print($start_page);
149: if ($env{'form.backto'} eq 'coursecatalog') {
150: &Apache::lonhtmlcommon::clear_breadcrumbs();
151: &Apache::lonhtmlcommon::add_breadcrumb
152: ({href=>"javascript:ToCatalog()",
153: text=>"Course Catalog"});
154: if ($env{'form.coursenum'} ne '') {
155: &Apache::lonhtmlcommon::add_breadcrumb
156: ({href=>"javascript:ToCatalog('details')",
157: text=>"Course details"});
158: }
159: &Apache::lonhtmlcommon::add_breadcrumb
160: ({href=>$r->uri,
161: text=>"Course syllabus"});
162: $r->print(&Apache::lonhtmlcommon::breadcrumbs());
163: }
164: $r->print('<h1>'.$courseenv{'description'}.'</h1><h3>'.
1.58 albertel 165: &Apache::lonnet::domain($cdom,'description').'</h3>');
1.28 sakharuk 166: } else {
1.29 sakharuk 167: $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
1.58 albertel 168: &Apache::lonnet::domain($cdom,'description').'}\\\\');
1.28 sakharuk 169: }
1.19 www 170: # -------------------------------------------------------------- Announcements?
1.49 albertel 171: my $day = &Apache::lonannounce::showday(time,2,
172: &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
1.35 sakharuk 173: if ($target ne 'tex') {
1.52 www 174: $r->print($day. &Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
1.35 sakharuk 175: } else {
1.49 albertel 176: $r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
1.35 sakharuk 177: }
1.49 albertel 178:
1.17 www 179: # -------------------------------------------------------- Get course personnel
180: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.28 sakharuk 181: if ($target ne 'tex') {
1.68 ! bisitz 182: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1.28 sakharuk 183: } else {
1.37 sakharuk 184: $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
1.28 sakharuk 185: }
1.36 sakharuk 186: foreach my $element (sort keys %coursepersonnel) {
1.28 sakharuk 187: if ($target ne 'tex') {
1.68 ! bisitz 188: $r->print(&Apache::lonhtmlcommon::row_title($element));
1.28 sakharuk 189: } else {
1.36 sakharuk 190: $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & ');
1.28 sakharuk 191: }
1.36 sakharuk 192: foreach (split(/\,/,$coursepersonnel{$element})) {
1.17 www 193: my ($puname,$pudom)=split(/\:/,$_);
1.28 sakharuk 194: if ($target ne 'tex') {
1.64 raeburn 195: my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
196: if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
197: ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
198: $r->print(' '.$courseperson);
199: } else {
1.67 raeburn 200: $r->print(' '.&Apache::loncommon::aboutmewrapper($courseperson,
201: $puname,$pudom));
1.64 raeburn 202: }
1.28 sakharuk 203: } else {
204: $r->print(' '.&Apache::loncommon::plainname($puname,
205: $pudom).' ');
206: }
1.17 www 207: }
1.28 sakharuk 208: if ($target ne 'tex') {
1.68 ! bisitz 209: $r->print(&Apache::lonhtmlcommon::row_closure());
1.28 sakharuk 210: } else {
211: $r->print('\\\\ \hline');
212: }
213: }
214: if ($target ne 'tex') {
1.68 ! bisitz 215: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1.28 sakharuk 216: } else {
217: $r->print('\end{tabular}\\\\');
1.17 www 218: }
219: # ---------------------------------------------------------- Load syllabus info
1.4 www 220: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
1.5 www 221: my $allowed=0;
1.27 www 222: my $privileged=0;
1.4 www 223:
1.2 www 224: # This handler might be called anonymously ...
225: # ----------------------------------------------------- Only if not public call
1.40 albertel 226: if ($env{'user.environment'}) {
1.1 www 227: # does this user have privileges to post, etc?
1.53 albertel 228: if ($env{'request.course.id'}
229: && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
230: && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
1.40 albertel 231: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.27 www 232: $privileged=$allowed;
233: if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
234: $forcestudent='student';
235: }
1.30 sakharuk 236: if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.2 www 237: }
1.6 www 238: if ($allowed) {
1.12 www 239: $r->print('<p>'.
1.63 bisitz 240: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).'</p><p>'.&mt('This syllabus can be publicly viewed at')
1.23 www 241: .' <tt>http://'.
1.57 albertel 242: &Apache::lonnet::hostname($homeserver).$r->uri.'</tt>'.
1.10 www 243: &Apache::loncommon::help_open_topic('Syllabus_ExtLink').'</p>'.
1.47 www 244: '<p>'.&mt('You can specify an external URL as Syllabus in the [_1].','<a href="/adm/parmset?action=crsenv">'.&mt('Course Parameters').'</a>').'</p>'.
1.27 www 245: '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.
246: &mt('Show Public View').'</font></a>'.
1.10 www 247: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').
248: '</p>');
1.27 www 249: } elsif ($privileged) {
1.28 sakharuk 250: if ($target ne 'tex') {
251: $r->print('<p><a href="'.$r->uri.'?forceedit=1"><font size="+1">'.
252: &mt('Edit').'</font></a>');
253: }
1.6 www 254: }
1.40 albertel 255: if (($allowed) && ($env{'form.storesyl'})) {
1.55 albertel 256: foreach my $syl_field (keys(%syllabusfields)) {
257: my $field=$env{'form.'.$syl_field};
1.33 www 258: chomp($field);
1.5 www 259: $field=~s/\s+$//s;
1.33 www 260: $field=~s/^\s+//s;
261: $field=~s/\<br\s*\/*\>$//s;
262: $field=&Apache::lonfeedback::clear_out_html($field,1);
1.55 albertel 263: $syllabus{$syl_field}=$field;
264: if ($syl_field eq 'lll_includeurl') { # clean up included URLs
1.9 www 265: my $field='';
1.55 albertel 266: foreach my $value (split(/\n/,$syllabus{$syl_field})) {
267: my $url=$value;
1.9 www 268: # get rid of leading and trailing spaces
269: $url=~s/^\s+//;
270: $url=~s/\s+$//;
1.55 albertel 271: if ($url=~m|^http://([^/]+)/(.+)$|) {
272: my $host = $1;
1.9 www 273: my $remainder=$2;
274: # remove the hostname from internal URLs
1.57 albertel 275: my $hostname = &Apache::lonnet::hostname($host);
276: my %all_hostnames = &Apache::lonnet::all_hostnames();
277: foreach my $possible_host (keys(%all_hostnames)) {
278: if ($possible_host =~ /\Q$hostname\E/i) {
1.9 www 279: $url=$remainder;
280: }
281: }
282: }
283: # norm internal URLs
284: unless ($url=~/^http\:/) {
285: $url=&Apache::lonnet::clutter($url);
286: }
287: # re-assemble field
288: if ($url) {
289: $field.=$url."\n";
290: }
291: }
1.55 albertel 292: $syllabus{$syl_field}=$field;
1.9 www 293: }
1.5 www 294: }
1.40 albertel 295: $syllabus{'uploaded.domain'}=$env{'user.domain'};
296: $syllabus{'uploaded.name'}=$env{'user.name'};
1.5 www 297: $syllabus{'uploaded.lastmodified'}=time;
298: &Apache::lonnet::put('syllabus',\%syllabus,$cdom,$cnum);
299: }
1.4 www 300: }
301: # ---------------------------------------------------------------- Get syllabus
1.5 www 302: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.8 www 303: my $lastmod=$syllabus{'uploaded.lastmodified'};
1.25 www 304: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
1.26 albertel 305: my $who = &Apache::loncommon::aboutmewrapper(
306: &Apache::loncommon::plainname($syllabus{'uploaded.name'},
1.7 www 307: $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
1.26 albertel 308: $syllabus{'uploaded.domain'});
1.28 sakharuk 309: if ($target ne 'tex') {
310: $r->print('<table><tr><td>'.&mt('Last updated').':</td><td>'.
1.61 albertel 311: $lastmod.'</td><td>'.
312: ($who ? &mt('by').' '.$who
313: : '' ).
1.28 sakharuk 314: '</td></tr></table><p>');
315: } else {
1.61 albertel 316: $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.
317: ($who? &mt('by').'\\\\ '.
318: &Apache::loncommon::plainname($syllabus{'uploaded.name'},$syllabus{'uploaded.domain'})
319: :'')
320: .'\\\\');
1.28 sakharuk 321: }
1.5 www 322: if ($allowed) {
1.27 www 323: $r->print('<form method="post">'.
324: '<input type="hidden" name="forceedit" value="edit" />');
1.5 www 325: }
1.33 www 326: my @htmlids=();
1.55 albertel 327: foreach my $field (sort(keys(%syllabusfields))) {
328: if (($syllabus{$field}=~/\w/) || ($allowed)) {
329: my $message=$syllabus{$field};
330: if ($field eq 'lll_includeurl') { # this is the "included" field
331: my $urls=$message;
332: $message='';
333: foreach my $filelink (split(/\n/,$urls)) {
334: my $output='';
1.9 www 335: # embed style?
1.55 albertel 336: my ($curfext)=($filelink=~/\.([^\.]+)$/);
337: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
338: if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {
1.9 www 339: # make ssi call and remove everything but the body contents
1.55 albertel 340: $output=&Apache::lonnet::ssi_body($filelink);
341: } elsif ($embstyle eq 'img') {
1.9 www 342: # embed as an image
1.55 albertel 343: $output='<img src="'.$filelink.'" />';
344: }
345: if ($target ne 'tex') {
346: $message.='<p>'.$output.'</p>';
347: } else {
348: $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
349: }
350: }
351: if ($allowed) {
352: $r->print('<h3>'.$syllabusfields{$field}.
353: &Apache::loncommon::help_open_topic('Syllabus_URLs').'</h3>'.
354: '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.&mt('Show Public View').'</font></a>'.
355: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
356: } else {
357: $r->print($message);
358: }
359: } else {
360: &Apache::lonfeedback::newline_to_br(\$message);
1.56 banghart 361: $message =~s|(https*://[^\s]+)|<a href="$1"><tt>$1</tt></a>|g;
1.55 albertel 362: if ($allowed) {
363: $message=&Apache::lonspeller::markeduptext($message);
364: }
365: $message=&Apache::lontexconvert::msgtexconverted($message);
366: if ($target ne 'tex') {
367: $r->print('<h3>'.$syllabusfields{$field}.'</h3><blockquote>'.
368: $message.'</blockquote>');
369: } else {
370: $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
371: &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
372: }
373: push(@htmlids,$field);
374: }
375: if ($allowed) {
376: $r->print('<br /><textarea cols="80" rows="12" name="'.$field.'" id="'.$field.'">'.
377: &HTML::Entities::encode($syllabus{$field},'"&<>').
1.63 bisitz 378: '</textarea> <input type="submit" name="storesyl" value="'.&mt('Save').'" />');
1.55 albertel 379: }
380: }
1.5 www 381: }
382: if ($allowed) {
1.32 www 383: $r->print('</form>'.
1.33 www 384: &Apache::lonhtmlcommon::htmlareaselectactive(@htmlids));
1.5 www 385: }
1.28 sakharuk 386: if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
1.4 www 387: } else {
1.36 sakharuk 388: if ($target ne 'tex') {$r->print('<p>');} else {$r->print('\par ');}
1.63 bisitz 389: $r->print(&mt('No syllabus information provided.'));
1.36 sakharuk 390: if ($target ne 'tex') {$r->print('</p>');}
1.1 www 391: }
1.48 albertel 392: if ($target ne 'tex') {
1.65 raeburn 393: if ($env{'form.backto'} eq 'coursecatalog') {
394: $r->print('<form name="backtocat" method="post" action="/adm/coursecatalog">'.
1.66 raeburn 395: &Apache::lonhtmlcommon::echo_form_input(['backto','courseid']).
1.65 raeburn 396: '</form>');
397: }
1.48 albertel 398: $r->print(&Apache::loncommon::end_page());
399: } else {
400: $r->print('\end{document}');
401: }
1.1 www 402: return OK;
403: }
404:
405: 1;
406: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>