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