1: # The LearningOnline Network
2: # Syllabus
3: #
4: # $Id: lonsyllabus.pm,v 1.69 2008/11/07 18:06:19 bisitz 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: if ($target eq 'tex') {
70: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
71: }
72: # -------------------------------------------------- Let's see who handles this
73: my $externalsyllabus=$courseenv{'externalsyllabus'};
74:
75: if ($externalsyllabus=~/\w/) {
76:
77: if ($env{'form.wrapperdisplay'} eq 'menu') {
78: $r->print(&Apache::lonwrapper::simple_menu());
79: } else {
80: $r->print(&Apache::lonwrapper::wrapper("/public/$cdom/$cnum/syllabus?wrapperdisplay=menu",
81: $externalsyllabus));
82: }
83: return OK;
84: }
85:
86: # ------------------------------ The buck stops here: internal syllabus display
87: # --------------------------------------------------------- The syllabus fields
88: my %syllabusfields=&Apache::lonlocal::texthash(
89: 'aaa_instructorinfo' => 'Instructor Information',
90: 'bbb_description' => 'Course Description',
91: 'ccc_prereq' => 'Prerequisites',
92: 'cdc_classhours' => 'Class Hours',
93: 'ddd_officehours' => 'Office Hours',
94: 'eee_helproom' => 'Helproom Hours',
95: 'efe_projectinfo' => 'Project Information',
96: 'fff_examinfo' => 'Exam Information',
97: 'fgf_deadlines' => 'Deadlines',
98: 'ggg_grading' => 'Grading Information',
99: 'hhh_readings' => 'Readings',
100: 'iii_coursepack' => 'Coursepack',
101: 'jjj_weblinks' => 'Web Links',
102: 'kkk_textbook' => 'Textbook',
103: 'lll_includeurl' => 'URLs To Include in Syllabus');
104: # --------------------------------------------------------------- Force Student
105: my $forcestudent='';
106: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
107: my $forceedit='';
108: if ($env{'form.forceedit'}) { $forceedit='edit'; }
109:
110: # ----------------------------------------------------------------- Make header
111: if ($target ne 'tex') {
112: my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
113: my $js;
114: if ($env{'form.backto'} eq 'coursecatalog') {
115: $js .= <<"ENDSCRIPT";
116:
117: <script type="text/javascript">
118: function ToCatalog(caller) {
119: numidx = getIndexByName('coursenum');
120: if (numidx > -1) {
121: if (caller != 'details') {
122: document.backtocat.elements[numidx].value = '';
123: }
124: }
125: document.backtocat.submit();
126: }
127:
128: function getIndexByName(item) {
129: for (var i=0;i<document.backtocat.elements.length;i++) {
130: if (document.backtocat.elements[i].name == item) {
131: return i;
132: }
133: }
134: return -1;
135: }
136:
137: </script>
138:
139: ENDSCRIPT
140: }
141: my $start_page =
142: &Apache::loncommon::start_page("Syllabus", $rss_link.$js,
143: {'function' => $forcestudent,
144: 'domain' => $cdom,
145: 'force_register' =>
146: $env{'form.register'},});
147:
148: $r->print($start_page);
149: if ($env{'form.backto'} eq 'coursecatalog') {
150: &Apache::lonhtmlcommon::clear_breadcrumbs();
151: &Apache::lonhtmlcommon::add_breadcrumb
152: ({href=>"javascript:ToCatalog()",
153: text=>"Course Catalog"});
154: if ($env{'form.coursenum'} ne '') {
155: &Apache::lonhtmlcommon::add_breadcrumb
156: ({href=>"javascript:ToCatalog('details')",
157: text=>"Course details"});
158: }
159: &Apache::lonhtmlcommon::add_breadcrumb
160: ({href=>$r->uri,
161: text=>"Course syllabus"});
162: $r->print(&Apache::lonhtmlcommon::breadcrumbs());
163: }
164: $r->print('<h1>'.$courseenv{'description'}.'</h1><h3>'.
165: &Apache::lonnet::domain($cdom,'description').'</h3>');
166: } else {
167: $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
168: &Apache::lonnet::domain($cdom,'description').'}\\\\');
169: }
170: # -------------------------------------------------------------- Announcements?
171: my $day = &Apache::lonannounce::showday(time,2,
172: &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
173: if ($target ne 'tex') {
174: $r->print($day. &Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
175: } else {
176: $r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
177: }
178:
179: # -------------------------------------------------------- Get course personnel
180: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
181: if ($target ne 'tex') {
182: $r->print(&Apache::lonhtmlcommon::start_pick_box());
183: } else {
184: $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
185: }
186: my @personnel=sort keys %coursepersonnel;
187: my $lastpers=$personnel[$#personnel];
188: foreach my $element (@personnel) {
189: if ($target ne 'tex') {
190: $r->print(&Apache::lonhtmlcommon::row_title($element));
191: } else {
192: $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & ');
193: }
194: foreach (split(/\,/,$coursepersonnel{$element})) {
195: my ($puname,$pudom)=split(/\:/,$_);
196: if ($target ne 'tex') {
197: my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
198: if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
199: ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
200: $r->print(' '.$courseperson);
201: } else {
202: $r->print(' '.&Apache::loncommon::aboutmewrapper($courseperson,
203: $puname,$pudom));
204: }
205: } else {
206: $r->print(' '.&Apache::loncommon::plainname($puname,
207: $pudom).' ');
208: }
209: }
210: if ($target ne 'tex') {
211: my $lastclose=$element eq $lastpers?1:0;
212: $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
213: } else {
214: $r->print('\\\\ \hline');
215: }
216: }
217: if ($target ne 'tex') {
218: $r->print(&Apache::lonhtmlcommon::end_pick_box());
219: } else {
220: $r->print('\end{tabular}\\\\');
221: }
222: # ---------------------------------------------------------- Load syllabus info
223: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
224: my $allowed=0;
225: my $privileged=0;
226:
227: # This handler might be called anonymously ...
228: # ----------------------------------------------------- Only if not public call
229: if ($env{'user.environment'}) {
230: # does this user have privileges to post, etc?
231: if ($env{'request.course.id'}
232: && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
233: && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
234: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
235: $privileged=$allowed;
236: if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
237: $forcestudent='student';
238: }
239: if ($forcestudent or $target eq 'tex') { $allowed=0; }
240: }
241: if ($allowed) {
242: $r->print('<p>'.
243: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).'</p><p>'.&mt('This syllabus can be publicly viewed at')
244: .' <tt>http://'.
245: &Apache::lonnet::hostname($homeserver).$r->uri.'</tt>'.
246: &Apache::loncommon::help_open_topic('Syllabus_ExtLink').'</p>'.
247: '<p>'.&mt('You can specify an external URL as Syllabus in the [_1].','<a href="/adm/parmset?action=crsenv">'.&mt('Course Parameters').'</a>').'</p>'.
248: '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.
249: &mt('Show Public View').'</font></a>'.
250: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').
251: '</p>');
252: } elsif ($privileged) {
253: if ($target ne 'tex') {
254: $r->print('<p><a href="'.$r->uri.'?forceedit=1"><font size="+1">'.
255: &mt('Edit').'</font></a>');
256: }
257: }
258: if (($allowed) && ($env{'form.storesyl'})) {
259: foreach my $syl_field (keys(%syllabusfields)) {
260: my $field=$env{'form.'.$syl_field};
261: chomp($field);
262: $field=~s/\s+$//s;
263: $field=~s/^\s+//s;
264: $field=~s/\<br\s*\/*\>$//s;
265: $field=&Apache::lonfeedback::clear_out_html($field,1);
266: $syllabus{$syl_field}=$field;
267: if ($syl_field eq 'lll_includeurl') { # clean up included URLs
268: my $field='';
269: foreach my $value (split(/\n/,$syllabus{$syl_field})) {
270: my $url=$value;
271: # get rid of leading and trailing spaces
272: $url=~s/^\s+//;
273: $url=~s/\s+$//;
274: if ($url=~m|^http://([^/]+)/(.+)$|) {
275: my $host = $1;
276: my $remainder=$2;
277: # remove the hostname from internal URLs
278: my $hostname = &Apache::lonnet::hostname($host);
279: my %all_hostnames = &Apache::lonnet::all_hostnames();
280: foreach my $possible_host (keys(%all_hostnames)) {
281: if ($possible_host =~ /\Q$hostname\E/i) {
282: $url=$remainder;
283: }
284: }
285: }
286: # norm internal URLs
287: unless ($url=~/^http\:/) {
288: $url=&Apache::lonnet::clutter($url);
289: }
290: # re-assemble field
291: if ($url) {
292: $field.=$url."\n";
293: }
294: }
295: $syllabus{$syl_field}=$field;
296: }
297: }
298: $syllabus{'uploaded.domain'}=$env{'user.domain'};
299: $syllabus{'uploaded.name'}=$env{'user.name'};
300: $syllabus{'uploaded.lastmodified'}=time;
301: &Apache::lonnet::put('syllabus',\%syllabus,$cdom,$cnum);
302: }
303: }
304: # ---------------------------------------------------------------- Get syllabus
305: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
306: my $lastmod=$syllabus{'uploaded.lastmodified'};
307: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
308: my $who = &Apache::loncommon::aboutmewrapper(
309: &Apache::loncommon::plainname($syllabus{'uploaded.name'},
310: $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
311: $syllabus{'uploaded.domain'});
312: if ($target ne 'tex') {
313: $r->print('<table><tr><td>'.&mt('Last updated').':</td><td>'.
314: $lastmod.'</td><td>'.
315: ($who ? &mt('by').' '.$who
316: : '' ).
317: '</td></tr></table><p>');
318: } else {
319: $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.
320: ($who? &mt('by').'\\\\ '.
321: &Apache::loncommon::plainname($syllabus{'uploaded.name'},$syllabus{'uploaded.domain'})
322: :'')
323: .'\\\\');
324: }
325: if ($allowed) {
326: $r->print('<form method="post">'.
327: '<input type="hidden" name="forceedit" value="edit" />');
328: }
329: my @htmlids=();
330: foreach my $field (sort(keys(%syllabusfields))) {
331: if (($syllabus{$field}=~/\w/) || ($allowed)) {
332: my $message=$syllabus{$field};
333: if ($field eq 'lll_includeurl') { # this is the "included" field
334: my $urls=$message;
335: $message='';
336: foreach my $filelink (split(/\n/,$urls)) {
337: my $output='';
338: # embed style?
339: my ($curfext)=($filelink=~/\.([^\.]+)$/);
340: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
341: if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {
342: # make ssi call and remove everything but the body contents
343: $output=&Apache::lonnet::ssi_body($filelink);
344: } elsif ($embstyle eq 'img') {
345: # embed as an image
346: $output='<img src="'.$filelink.'" />';
347: }
348: if ($target ne 'tex') {
349: $message.='<p>'.$output.'</p>';
350: } else {
351: $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
352: }
353: }
354: if ($allowed) {
355: $r->print('<h3>'.$syllabusfields{$field}.
356: &Apache::loncommon::help_open_topic('Syllabus_URLs').'</h3>'.
357: '<p><a href="'.$r->uri.'?forcestudent=1"><font size="+1">'.&mt('Show Public View').'</font></a>'.
358: &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').'</p>');
359: } else {
360: $r->print($message);
361: }
362: } else {
363: &Apache::lonfeedback::newline_to_br(\$message);
364: $message =~s|(https*://[^\s]+)|<a href="$1"><tt>$1</tt></a>|g;
365: if ($allowed) {
366: $message=&Apache::lonspeller::markeduptext($message);
367: }
368: $message=&Apache::lontexconvert::msgtexconverted($message);
369: if ($target ne 'tex') {
370: $r->print('<h3>'.$syllabusfields{$field}.'</h3><blockquote>'.
371: $message.'</blockquote>');
372: } else {
373: $r->print('\\\\\textbf{'.$syllabusfields{$field}.'}\\\\'.
374: &Apache::lonxml::xmlparse($r,'tex',$message).'\\\\');
375: }
376: push(@htmlids,$field);
377: }
378: if ($allowed) {
379: $r->print('<br /><textarea cols="80" rows="12" name="'.$field.'" id="'.$field.'">'.
380: &HTML::Entities::encode($syllabus{$field},'"&<>').
381: '</textarea> <input type="submit" name="storesyl" value="'.&mt('Save').'" />');
382: }
383: }
384: }
385: if ($allowed) {
386: $r->print('</form>'.
387: &Apache::lonhtmlcommon::htmlareaselectactive(@htmlids));
388: }
389: if ($target ne 'tex') {$r->print('</p>');} else {$r->print('\\\\');}
390: } else {
391: if ($target ne 'tex') {$r->print('<p>');} else {$r->print('\par ');}
392: $r->print(&mt('No syllabus information provided.'));
393: if ($target ne 'tex') {$r->print('</p>');}
394: }
395: if ($target ne 'tex') {
396: if ($env{'form.backto'} eq 'coursecatalog') {
397: $r->print('<form name="backtocat" method="post" action="/adm/coursecatalog">'.
398: &Apache::lonhtmlcommon::echo_form_input(['backto','courseid']).
399: '</form>');
400: }
401: $r->print(&Apache::loncommon::end_page());
402: } else {
403: $r->print('\end{document}');
404: }
405: return OK;
406: }
407:
408: 1;
409: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>