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