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