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