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