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