Annotation of loncom/interface/lonsyllabus.pm, revision 1.48
1.1 www 1: # The LearningOnline Network
2: # Syllabus
3: #
1.48 ! albertel 4: # $Id: lonsyllabus.pm,v 1.47 2006/03/07 21:36:20 www 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.1 www 41:
42: sub handler {
43: my $r = shift;
1.46 www 44: &Apache::loncommon::content_type($r,'text/html');
45: $r->send_http_header;
46: return OK if $r->header_only;
1.45 www 47:
1.46 www 48: my $target=$env{'form.grade_target'};
1.45 www 49: # --------------------------------------------------- Get course info from URL
50: my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.46 www 51: # ------------------------------------------------------------ Get query string
52: &Apache::loncommon::get_unprocessed_cgi
1.47 www 53: ($ENV{'QUERY_STRING'},['forcestudent','register','forceedit','wrapperdisplay']);
1.45 www 54: # ----------------------------------------------------- Is this even a course?
55: my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom);
56: if ($homeserver eq 'no_host') {
57: &Apache::loncommon::content_type($r,'text/html');
58: $r->send_http_header;
1.48 ! albertel 59: $r->print(&Apache::loncommon::startpage('No syllabus available').
! 60: &mt('No syllabus available').
! 61: &Apache::loncommon::end_page());
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.46 www 68: my $feedurl='http://'.$ENV{'HTTP_HOST'}.'/public/'.$cdom.'/'.$cnum.'/Course_Announcements.rss';
1.28 sakharuk 69: if ($target ne 'tex') {
1.39 albertel 70: my $html=&Apache::lonxml::xmlbegin();
1.48 ! albertel 71: my $head=&Apache::loncommon::headtag('The LearningOnline Network with CAPA');
1.28 sakharuk 72: $r->print(<<ENDDOCUMENT);
1.39 albertel 73: $html
1.48 ! albertel 74: $head
1.42 www 75: <link rel="alternate" type="application/rss+xml" title="Course Announcements" href="$feedurl" />
1.1 www 76: ENDDOCUMENT
1.28 sakharuk 77: } else {
1.40 albertel 78: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.28 sakharuk 79: }
1.46 www 80: # ----------------------------------------------------- Force menu registration
81: my $addentries='';
82: if ($env{'form.register'}) {
83: $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
84: '" onUnload="'.&Apache::lonmenu::unloadevents().'"';
85: $r->print(&Apache::lonmenu::registerurl(1));
86: }
87: # -------------------------------------------------- Let's see who handles this
1.47 www 88: my $externalsyllabus=$courseenv{'externalsyllabus'};
1.46 www 89: if ($externalsyllabus=~/\w/) {
1.48 ! albertel 90: $r->print(&Apache::loncommon::endheadtag());
1.47 www 91: if ($env{'form.wrapperdisplay'} eq 'menu') {
92: #
93: # Producing the menu buttons
94: #
95: $r->print('<body bgcolor="#FFFFFF">'.
1.48 ! albertel 96: &Apache::lonmenu::menubuttons(1,'web',1).
! 97: &Apache::loncommon::end_page());
1.47 www 98: } else {
99: if ($env{'browser.interface'} eq 'textual') {
100: #
101: # ssi-based rendering for text-based interface
102: #
103: $r->print('<body bgcolor="#FFFFFF">'.
1.48 ! albertel 104: &Apache::lonmenu::menubuttons(1).
! 105: &Apache::lonnet::ssi_body($externalsyllabus).
! 106: &Apache::loncommon::end_page());
1.47 www 107: } elsif ($env{'environment.remote'} eq 'off') {
108: #
109: # This is inline remote
110: #
111: $r->print(<<ENDDOCUMENTINL);
1.48 ! albertel 112: <frameset rows="180,*" border="0" $addentries>
1.47 www 113: <frame src="/public/$cdom/$cnum/syllabus?wrapperdisplay=menu">
114: <frame src="$externalsyllabus">
115: </frameset>
116: </html>
117: ENDDOCUMENTINL
118: } else {
119: #
120: # frame-based rendering for graphical interface
121: #
122: $r->print(<<ENDDOCUMENT);
1.48 ! albertel 123: <frameset rows="1,*" border="0" $addentries>
1.47 www 124: <frame src="/adm/rat/empty.html">
125: <frame src="$externalsyllabus">
126: </frameset>
127: </html>
128: ENDDOCUMENT
129: }
130: }
131: return OK;
132: }
1.42 www 133:
1.46 www 134: # ------------------------------ The buck stops here: internal syllabus display
1.5 www 135: # --------------------------------------------------------- The syllabus fields
1.23 www 136: my %syllabusfields=&Apache::lonlocal::texthash(
1.5 www 137: 'aaa_instructorinfo' => 'Instructor Information',
138: 'bbb_description' => 'Course Description',
139: 'ccc_prereq' => 'Prerequisites',
1.7 www 140: 'cdc_classhours' => 'Class Hours',
1.5 www 141: 'ddd_officehours' => 'Office Hours',
142: 'eee_helproom' => 'Helproom Hours',
1.7 www 143: 'efe_projectinfo' => 'Project Information',
1.5 www 144: 'fff_examinfo' => 'Exam Information',
1.7 www 145: 'fgf_deadlines' => 'Deadlines',
1.5 www 146: 'ggg_grading' => 'Grading Information',
1.7 www 147: 'hhh_readings' => 'Readings',
148: 'iii_coursepack' => 'Coursepack',
149: 'jjj_weblinks' => 'Web Links',
1.9 www 150: 'kkk_textbook' => 'Textbook',
151: 'lll_includeurl' => 'URLs To Include in Syllabus');
1.6 www 152: # --------------------------------------------------------------- Force Student
153: my $forcestudent='';
1.40 albertel 154: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
1.27 www 155: my $forceedit='';
1.40 albertel 156: if ($env{'form.forceedit'}) { $forceedit='edit'; }
1.5 www 157:
1.45 www 158: # ----------------------------------------------------------------- Make header
1.28 sakharuk 159: if ($target ne 'tex') {
1.32 www 160: $r->print(&Apache::lonhtmlcommon::htmlareaheaders().
1.48 ! albertel 161: &Apache::loncommon::endheadtag().
! 162: &Apache::loncommon::bodytag("Syllabus",$forcestudent,$addentries,'',$cdom,$env{'form.register'}));
1.28 sakharuk 163: $r->print('<h1>'.$courseenv{'description'}.'</h1><h3>'.
164: $Apache::lonnet::domaindescription{$cdom}.'</h3>');
165: } else {
1.29 sakharuk 166: $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
1.28 sakharuk 167: $Apache::lonnet::domaindescription{$cdom}.'}\\\\');
168: }
1.19 www 169: # -------------------------------------------------------------- Announcements?
1.35 sakharuk 170: if ($target ne 'tex') {
171: $r->print(&Apache::lonannounce::showday(time,2,
1.44 www 172: &Apache::lonannounce::readcalendar($cdom.'_'.$cnum)).
173: &Apache::lonrss::advertisefeeds($cnum,$cdom));
1.35 sakharuk 174: } else {
175: $r->print(&Apache::lonxml::xmlparse($r,'tex',
176: &Apache::lonannounce::showday(time,2,
177: &Apache::lonannounce::readcalendar($cdom.'_'.$cnum))));
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') {
182: $r->print('<table border="2">');
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.36 sakharuk 188: $r->print('<tr><td>'.$element.'</td><td>');
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') {
195: $r->print(' '.&Apache::loncommon::aboutmewrapper(
196: &Apache::loncommon::plainname($puname,
197: $pudom),$puname,$pudom));
198: } else {
199: $r->print(' '.&Apache::loncommon::plainname($puname,
200: $pudom).' ');
201: }
1.17 www 202: }
1.28 sakharuk 203: if ($target ne 'tex') {
204: $r->print('</td></tr>');
205: } else {
206: $r->print('\\\\ \hline');
207: }
208: }
209: if ($target ne 'tex') {
210: $r->print('</table>');
211: } else {
212: $r->print('\end{tabular}\\\\');
1.17 www 213: }
214: # ---------------------------------------------------------- Load syllabus info
1.4 www 215: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
1.5 www 216: my $allowed=0;
1.27 www 217: my $privileged=0;
1.4 www 218:
1.2 www 219: # This handler might be called anonymously ...
220: # ----------------------------------------------------- Only if not public call
1.40 albertel 221: if ($env{'user.environment'}) {
1.1 www 222: # does this user have privileges to post, etc?
1.40 albertel 223: if ($env{'request.course.id'}) {
224: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.27 www 225: $privileged=$allowed;
226: if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
227: $forcestudent='student';
228: }
1.30 sakharuk 229: if ($forcestudent or $target eq 'tex') { $allowed=0; }
1.2 www 230: }
1.6 www 231: if ($allowed) {
1.12 www 232: $r->print('<p>'.
1.23 www 233: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'</p><p>'.&mt('This syllabus can be publicly viewed at')
234: .' <tt>http://'.
1.10 www 235: $Apache::lonnet::hostname{$homeserver}.$r->uri.'</tt>'.
236: &Apache::loncommon::help_open_topic('Syllabus_ExtLink').'</p>'.
1.47 www 237: '<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 238: '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.
239: &mt('Show Public View').'</font></a>'.
1.10 www 240: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').
241: '</p>');
1.27 www 242: } elsif ($privileged) {
1.28 sakharuk 243: if ($target ne 'tex') {
244: $r->print('<p><a href="'.$r->uri.'?forceedit=1"><font size="+1">'.
245: &mt('Edit').'</font></a>');
246: }
1.6 www 247: }
1.40 albertel 248: if (($allowed) && ($env{'form.storesyl'})) {
1.5 www 249: foreach (keys %syllabusfields) {
1.40 albertel 250: my $field=$env{'form.'.$_};
1.33 www 251: chomp($field);
1.5 www 252: $field=~s/\s+$//s;
1.33 www 253: $field=~s/^\s+//s;
254: $field=~s/\<br\s*\/*\>$//s;
255: $field=&Apache::lonfeedback::clear_out_html($field,1);
1.7 www 256: $syllabus{$_}=$field;
1.9 www 257: if ($_ eq 'lll_includeurl') { # clean up included URLs
258: my $field='';
259: foreach (split(/\n/,$syllabus{$_})) {
260: my $url=$_;
261: # get rid of leading and trailing spaces
262: $url=~s/^\s+//;
263: $url=~s/\s+$//;
264: if ($url=~/^http\:\/\/([^\/]+)\/(.+)$/) {
265: my $remainder=$2;
266: # remove the hostname from internal URLs
267: foreach (keys %Apache::lonnet::hostname) {
268: if ($1=~/$Apache::lonnet::hostname{$_}/i) {
269: $url=$remainder;
270: }
271: }
272: }
273: # norm internal URLs
274: unless ($url=~/^http\:/) {
275: $url=&Apache::lonnet::clutter($url);
276: }
277: # re-assemble field
278: if ($url) {
279: $field.=$url."\n";
280: }
281: }
282: $syllabus{$_}=$field;
283: }
1.5 www 284: }
1.40 albertel 285: $syllabus{'uploaded.domain'}=$env{'user.domain'};
286: $syllabus{'uploaded.name'}=$env{'user.name'};
1.5 www 287: $syllabus{'uploaded.lastmodified'}=time;
288: &Apache::lonnet::put('syllabus',\%syllabus,$cdom,$cnum);
289: }
1.4 www 290: }
291: # ---------------------------------------------------------------- Get syllabus
1.5 www 292: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.8 www 293: my $lastmod=$syllabus{'uploaded.lastmodified'};
1.25 www 294: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
1.26 albertel 295: my $who = &Apache::loncommon::aboutmewrapper(
296: &Apache::loncommon::plainname($syllabus{'uploaded.name'},
1.7 www 297: $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
1.26 albertel 298: $syllabus{'uploaded.domain'});
1.28 sakharuk 299: if ($target ne 'tex') {
300: $r->print('<table><tr><td>'.&mt('Last updated').':</td><td>'.
301: $lastmod.'</td><td>'.&mt('by').' '.$who.
302: '</td></tr></table><p>');
303: } else {
304: $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.&mt('by').'\\\\ '.
305: &Apache::loncommon::plainname($syllabus{'uploaded.name'},
306: $syllabus{'uploaded.domain'}).'\\\\');
307: }
1.5 www 308: if ($allowed) {
1.27 www 309: $r->print('<form method="post">'.
310: '<input type="hidden" name="forceedit" value="edit" />');
1.5 www 311: }
1.33 www 312: my @htmlids=();
1.5 www 313: foreach (sort keys %syllabusfields) {
1.32 www 314: if (($syllabus{$_}=~/\w/) || ($allowed)) {
1.5 www 315: my $message=$syllabus{$_};
1.9 www 316: if ($_ eq 'lll_includeurl') { # this is the "included" field
317: my $urls=$message;
318: $message='';
319: foreach my $filelink (split(/\n/,$urls)) {
320: my $output='';
321: # embed style?
322: my ($curfext)=($filelink=~/\.([^\.]+)$/);
323: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
1.12 www 324: if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {
1.9 www 325: # make ssi call and remove everything but the body contents
1.13 www 326: $output=&Apache::lonnet::ssi_body($filelink);
1.9 www 327: } elsif ($embstyle eq 'img') {
328: # embed as an image
329: $output='<img src="'.$filelink.'" />';
330: }
1.34 sakharuk 331: if ($target ne 'tex') {
332: $message.='<p>'.$output.'</p>';
333: } else {
334: $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
335: }
1.9 www 336: }
337: if ($allowed) {
338: $r->print('<h3>'.$syllabusfields{$_}.
1.10 www 339: &Apache::loncommon::help_open_topic('Syllabus_URLs').'</h3>'.
1.27 www 340: '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.&mt('Show Public View').'</font></a>'.
1.10 www 341: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
1.9 www 342: } else {
343: $r->print($message);
344: }
345: } else {
1.41 albertel 346: &Apache::lonfeedback::newline_to_br(\$message);
1.9 www 347: $message
1.20 www 348: =~s/(https*\:\/\/[^\s]+)/\<a href=\"$1\"\>\<tt\>$1\<\/tt\>\<\/a\>/g;
1.38 www 349: if ($allowed) {
350: $message=&Apache::lonspeller::markeduptext($message);
351: }
1.9 www 352: $message=&Apache::lontexconvert::msgtexconverted($message);
1.28 sakharuk 353: if ($target ne 'tex') {
354: $r->print('<h3>'.$syllabusfields{$_}.'</h3><blockquote>'.
355: $message.'</blockquote>');
356: } else {
357: $r->print('\\\\\textbf{'.$syllabusfields{$_}.'}\\\\'.
1.31 sakharuk 358: &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
1.28 sakharuk 359: }
1.33 www 360: push @htmlids,$_;
1.9 www 361: }
1.5 www 362: if ($allowed) {
1.33 www 363: $r->print(
364: '<br /><textarea cols="80" rows="12" name="'.$_.'" id="'.$_.'">'.
1.5 www 365: $syllabus{$_}.
1.33 www 366: '</textarea> <input type="submit" name="storesyl" value="Store" />');
1.5 www 367: }
368: }
369: }
370: if ($allowed) {
1.32 www 371: $r->print('</form>'.
1.33 www 372: &Apache::lonhtmlcommon::htmlareaselectactive(@htmlids));
1.5 www 373: }
1.28 sakharuk 374: if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
1.4 www 375: } else {
1.36 sakharuk 376: if ($target ne 'tex') {$r->print('<p>');} else {$r->print('\par ');}
377: $r->print('No syllabus information provided.');
378: if ($target ne 'tex') {$r->print('</p>');}
1.1 www 379: }
1.48 ! albertel 380: if ($target ne 'tex') {
! 381: $r->print(&Apache::loncommon::end_page());
! 382: } else {
! 383: $r->print('\end{document}');
! 384: }
1.1 www 385: return OK;
386: }
387:
388: 1;
389: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>