Annotation of loncom/interface/lonsyllabus.pm, revision 1.70
1.1 www 1: # The LearningOnline Network
2: # Syllabus
3: #
1.70 ! amueller 4: # $Id: lonsyllabus.pm,v 1.69 2008/11/07 18:06:19 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.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.49 albertel 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.40 albertel 71: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.28 sakharuk 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.50 albertel 77:
1.47 www 78: if ($env{'form.wrapperdisplay'} eq 'menu') {
1.50 albertel 79: $r->print(&Apache::lonwrapper::simple_menu());
80: } else {
81: $r->print(&Apache::lonwrapper::wrapper("/public/$cdom/$cnum/syllabus?wrapperdisplay=menu",
82: $externalsyllabus));
83: }
84: return OK;
1.47 www 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.5 www 110:
1.45 www 111: # ----------------------------------------------------------------- Make header
1.28 sakharuk 112: if ($target ne 'tex') {
1.60 albertel 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');
121: if (numidx > -1) {
122: if (caller != 'details') {
123: document.backtocat.elements[numidx].value = '';
124: }
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.49 albertel 142: my $start_page =
1.65 raeburn 143: &Apache::loncommon::start_page("Syllabus", $rss_link.$js,
1.49 albertel 144: {'function' => $forcestudent,
145: 'domain' => $cdom,
146: 'force_register' =>
147: $env{'form.register'},});
148:
1.65 raeburn 149: $r->print($start_page);
150: if ($env{'form.backto'} eq 'coursecatalog') {
151: &Apache::lonhtmlcommon::clear_breadcrumbs();
152: &Apache::lonhtmlcommon::add_breadcrumb
153: ({href=>"javascript:ToCatalog()",
154: text=>"Course Catalog"});
155: if ($env{'form.coursenum'} ne '') {
156: &Apache::lonhtmlcommon::add_breadcrumb
157: ({href=>"javascript:ToCatalog('details')",
158: text=>"Course details"});
159: }
160: &Apache::lonhtmlcommon::add_breadcrumb
161: ({href=>$r->uri,
162: text=>"Course syllabus"});
163: $r->print(&Apache::lonhtmlcommon::breadcrumbs());
164: }
165: $r->print('<h1>'.$courseenv{'description'}.'</h1><h3>'.
1.58 albertel 166: &Apache::lonnet::domain($cdom,'description').'</h3>');
1.28 sakharuk 167: } else {
1.29 sakharuk 168: $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
1.58 albertel 169: &Apache::lonnet::domain($cdom,'description').'}\\\\');
1.28 sakharuk 170: }
1.19 www 171: # -------------------------------------------------------------- Announcements?
1.49 albertel 172: my $day = &Apache::lonannounce::showday(time,2,
173: &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
1.35 sakharuk 174: if ($target ne 'tex') {
1.52 www 175: $r->print($day. &Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
1.35 sakharuk 176: } else {
1.49 albertel 177: $r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
1.35 sakharuk 178: }
1.49 albertel 179:
1.17 www 180: # -------------------------------------------------------- Get course personnel
181: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
1.28 sakharuk 182: if ($target ne 'tex') {
1.68 bisitz 183: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1.28 sakharuk 184: } else {
1.37 sakharuk 185: $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
1.28 sakharuk 186: }
1.69 bisitz 187: my @personnel=sort keys %coursepersonnel;
188: my $lastpers=$personnel[$#personnel];
189: foreach my $element (@personnel) {
1.28 sakharuk 190: if ($target ne 'tex') {
1.68 bisitz 191: $r->print(&Apache::lonhtmlcommon::row_title($element));
1.28 sakharuk 192: } else {
1.36 sakharuk 193: $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & ');
1.28 sakharuk 194: }
1.36 sakharuk 195: foreach (split(/\,/,$coursepersonnel{$element})) {
1.17 www 196: my ($puname,$pudom)=split(/\:/,$_);
1.28 sakharuk 197: if ($target ne 'tex') {
1.64 raeburn 198: my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
199: if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
200: ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
201: $r->print(' '.$courseperson);
202: } else {
1.67 raeburn 203: $r->print(' '.&Apache::loncommon::aboutmewrapper($courseperson,
204: $puname,$pudom));
1.64 raeburn 205: }
1.28 sakharuk 206: } else {
207: $r->print(' '.&Apache::loncommon::plainname($puname,
208: $pudom).' ');
209: }
1.17 www 210: }
1.28 sakharuk 211: if ($target ne 'tex') {
1.69 bisitz 212: my $lastclose=$element eq $lastpers?1:0;
213: $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
1.28 sakharuk 214: } else {
215: $r->print('\\\\ \hline');
216: }
217: }
218: if ($target ne 'tex') {
1.68 bisitz 219: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1.28 sakharuk 220: } else {
221: $r->print('\end{tabular}\\\\');
1.17 www 222: }
223: # ---------------------------------------------------------- Load syllabus info
1.4 www 224: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
1.5 www 225: my $allowed=0;
1.27 www 226: my $privileged=0;
1.4 www 227:
1.2 www 228: # This handler might be called anonymously ...
229: # ----------------------------------------------------- Only if not public call
1.40 albertel 230: if ($env{'user.environment'}) {
1.1 www 231: # does this user have privileges to post, etc?
1.53 albertel 232: if ($env{'request.course.id'}
233: && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
234: && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
1.40 albertel 235: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.27 www 236: $privileged=$allowed;
237: if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
238: $forcestudent='student';
239: }
1.30 sakharuk 240: if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.2 www 241: }
1.6 www 242: if ($allowed) {
1.12 www 243: $r->print('<p>'.
1.63 bisitz 244: &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 245: .' <tt>http://'.
1.57 albertel 246: &Apache::lonnet::hostname($homeserver).$r->uri.'</tt>'.
1.10 www 247: &Apache::loncommon::help_open_topic('Syllabus_ExtLink').'</p>'.
1.47 www 248: '<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 249: '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.
250: &mt('Show Public View').'</font></a>'.
1.10 www 251: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').
252: '</p>');
1.27 www 253: } elsif ($privileged) {
1.28 sakharuk 254: if ($target ne 'tex') {
255: $r->print('<p><a href="'.$r->uri.'?forceedit=1"><font size="+1">'.
256: &mt('Edit').'</font></a>');
257: }
1.6 www 258: }
1.40 albertel 259: if (($allowed) && ($env{'form.storesyl'})) {
1.55 albertel 260: foreach my $syl_field (keys(%syllabusfields)) {
261: my $field=$env{'form.'.$syl_field};
1.33 www 262: chomp($field);
1.5 www 263: $field=~s/\s+$//s;
1.33 www 264: $field=~s/^\s+//s;
265: $field=~s/\<br\s*\/*\>$//s;
266: $field=&Apache::lonfeedback::clear_out_html($field,1);
1.55 albertel 267: $syllabus{$syl_field}=$field;
268: if ($syl_field eq 'lll_includeurl') { # clean up included URLs
1.9 www 269: my $field='';
1.55 albertel 270: foreach my $value (split(/\n/,$syllabus{$syl_field})) {
271: my $url=$value;
1.9 www 272: # get rid of leading and trailing spaces
273: $url=~s/^\s+//;
274: $url=~s/\s+$//;
1.55 albertel 275: if ($url=~m|^http://([^/]+)/(.+)$|) {
276: my $host = $1;
1.9 www 277: my $remainder=$2;
278: # remove the hostname from internal URLs
1.57 albertel 279: my $hostname = &Apache::lonnet::hostname($host);
280: my %all_hostnames = &Apache::lonnet::all_hostnames();
281: foreach my $possible_host (keys(%all_hostnames)) {
282: if ($possible_host =~ /\Q$hostname\E/i) {
1.9 www 283: $url=$remainder;
284: }
285: }
286: }
287: # norm internal URLs
288: unless ($url=~/^http\:/) {
289: $url=&Apache::lonnet::clutter($url);
290: }
291: # re-assemble field
292: if ($url) {
293: $field.=$url."\n";
294: }
295: }
1.55 albertel 296: $syllabus{$syl_field}=$field;
1.9 www 297: }
1.5 www 298: }
1.40 albertel 299: $syllabus{'uploaded.domain'}=$env{'user.domain'};
300: $syllabus{'uploaded.name'}=$env{'user.name'};
1.5 www 301: $syllabus{'uploaded.lastmodified'}=time;
302: &Apache::lonnet::put('syllabus',\%syllabus,$cdom,$cnum);
303: }
1.4 www 304: }
305: # ---------------------------------------------------------------- Get syllabus
1.5 www 306: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.8 www 307: my $lastmod=$syllabus{'uploaded.lastmodified'};
1.25 www 308: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
1.26 albertel 309: my $who = &Apache::loncommon::aboutmewrapper(
310: &Apache::loncommon::plainname($syllabus{'uploaded.name'},
1.7 www 311: $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
1.26 albertel 312: $syllabus{'uploaded.domain'});
1.28 sakharuk 313: if ($target ne 'tex') {
314: $r->print('<table><tr><td>'.&mt('Last updated').':</td><td>'.
1.61 albertel 315: $lastmod.'</td><td>'.
316: ($who ? &mt('by').' '.$who
317: : '' ).
1.28 sakharuk 318: '</td></tr></table><p>');
319: } else {
1.61 albertel 320: $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.
321: ($who? &mt('by').'\\\\ '.
322: &Apache::loncommon::plainname($syllabus{'uploaded.name'},$syllabus{'uploaded.domain'})
323: :'')
324: .'\\\\');
1.28 sakharuk 325: }
1.5 www 326: if ($allowed) {
1.27 www 327: $r->print('<form method="post">'.
328: '<input type="hidden" name="forceedit" value="edit" />');
1.5 www 329: }
1.33 www 330: my @htmlids=();
1.55 albertel 331: foreach my $field (sort(keys(%syllabusfields))) {
332: if (($syllabus{$field}=~/\w/) || ($allowed)) {
333: my $message=$syllabus{$field};
334: if ($field eq 'lll_includeurl') { # this is the "included" field
335: my $urls=$message;
336: $message='';
337: foreach my $filelink (split(/\n/,$urls)) {
338: my $output='';
1.9 www 339: # embed style?
1.55 albertel 340: my ($curfext)=($filelink=~/\.([^\.]+)$/);
341: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
342: if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {
1.9 www 343: # make ssi call and remove everything but the body contents
1.55 albertel 344: $output=&Apache::lonnet::ssi_body($filelink);
345: } elsif ($embstyle eq 'img') {
1.9 www 346: # embed as an image
1.55 albertel 347: $output='<img src="'.$filelink.'" />';
348: }
349: if ($target ne 'tex') {
350: $message.='<p>'.$output.'</p>';
351: } else {
352: $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
353: }
354: }
355: if ($allowed) {
356: $r->print('<h3>'.$syllabusfields{$field}.
1.70 ! amueller 357: &Apache::loncommon::help_open_topic('Syllabus_URLs').'</h3>'.
! 358: '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.&mt('Show Public View').'</font></a>'.
1.55 albertel 359: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
360: } else {
361: $r->print($message);
362: }
363: } else {
364: &Apache::lonfeedback::newline_to_br(\$message);
1.56 banghart 365: $message =~s|(https*://[^\s]+)|<a href="$1"><tt>$1</tt></a>|g;
1.55 albertel 366: if ($allowed) {
367: $message=&Apache::lonspeller::markeduptext($message);
368: }
369: $message=&Apache::lontexconvert::msgtexconverted($message);
370: if ($target ne 'tex') {
1.70 ! amueller 371: &Apache::lontemplate::print_template($r, $syllabusfields{$field}, $message);
! 372: # $r->print('<h3>'.$syllabusfields{$field}.'</h3><blockquote>'.
! 373: # $message.'</blockquote>');
1.55 albertel 374: } else {
375: $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
376: &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
377: }
378: push(@htmlids,$field);
379: }
380: if ($allowed) {
1.70 ! amueller 381: &Apache::lontemplate::print_editbox_template($r, $syllabus{$field}, $field);
! 382: # $r->print('<br /><textarea cols="80" rows="12" name="'.$field.'" id="'.$field.'">'.
! 383: # &HTML::Entities::encode($syllabus{$field},'"&<>').
! 384: # '</textarea> <input type="submit" name="storesyl" value="'.&mt('Save').'" />');
1.55 albertel 385: }
386: }
1.5 www 387: }
388: if ($allowed) {
1.32 www 389: $r->print('</form>'.
1.33 www 390: &Apache::lonhtmlcommon::htmlareaselectactive(@htmlids));
1.5 www 391: }
1.28 sakharuk 392: if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
1.4 www 393: } else {
1.36 sakharuk 394: if ($target ne 'tex') {$r->print('<p>');} else {$r->print('\par ');}
1.63 bisitz 395: $r->print(&mt('No syllabus information provided.'));
1.36 sakharuk 396: if ($target ne 'tex') {$r->print('</p>');}
1.1 www 397: }
1.48 albertel 398: if ($target ne 'tex') {
1.65 raeburn 399: if ($env{'form.backto'} eq 'coursecatalog') {
400: $r->print('<form name="backtocat" method="post" action="/adm/coursecatalog">'.
1.66 raeburn 401: &Apache::lonhtmlcommon::echo_form_input(['backto','courseid']).
1.65 raeburn 402: '</form>');
403: }
1.48 albertel 404: $r->print(&Apache::loncommon::end_page());
405: } else {
406: $r->print('\end{document}');
407: }
1.1 www 408: return OK;
409: }
410:
411: 1;
412: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>