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