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