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