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