File:
[LON-CAPA] /
loncom /
interface /
lonsyllabus.pm
Revision
1.110:
download - view:
text,
annotated -
select for diffs
Sat Aug 7 19:23:51 2010 UTC (14 years, 2 months ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_10_0_RC2,
version_2_10_0_RC1,
version_2_10_0,
HEAD
- Eliminate routines no longer needed following switch from FCKEditor 2 to CKEdi
tor 3
- Eliminate checking for environment.wysiwygeditor (no longer used).
- Access to "Richtext" editor available via link on each textarea for which it is
to be made available.
- When editing an HTML document provide "Edit Math" button to allow
insertion of TeX within the textarea. Button is hidden if Richtext editor in use.
- Additional tags permitted by clear_out_html() - <pre> and <chem>.
1: # The LearningOnline Network
2: # Syllabus
3: #
4: # $Id: lonsyllabus.pm,v 1.110 2010/08/07 19:23:51 raeburn 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::lontemplate;
33: use Apache::Constants qw(:common);
34: use Apache::loncommon;
35: use Apache::lonnet;
36: use Apache::lontexconvert;
37: use Apache::lonfeedback;
38: use Apache::lonannounce;
39: use Apache::lonlocal;
40: use Apache::lonhtmlcommon;
41: use Apache::lonspeller();
42: use HTML::Entities();
43:
44: sub handler {
45: my $r = shift;
46: &Apache::loncommon::content_type($r,'text/html');
47: $r->send_http_header;
48: return OK if $r->header_only;
49:
50: my $target=$env{'form.grade_target'};
51: # --------------------------------------------------- Get course info from URL
52: my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
53: # ------------------------------------------------------------ Get query string
54: &Apache::loncommon::get_unprocessed_cgi
55: ($ENV{'QUERY_STRING'},['forcestudent','register','forceedit']);
56: # ----------------------------------------------------- Is this even a course?
57: my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom);
58: if ($homeserver eq 'no_host') {
59: &Apache::loncommon::content_type($r,'text/html');
60: $r->send_http_header;
61: &Apache::loncommon::simple_error_page($r,'No syllabus available',
62: 'No syllabus available');
63: return OK;
64: }
65: # ------------------------------------- There is such a course, get environment
66: my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
67:
68: # ------------------------------------------------------------ Print the screen
69:
70: if ($target eq 'tex') {
71: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
72: }
73: # -------------------------------------------------- Let's see who handles this
74: my $externalsyllabus=$courseenv{'externalsyllabus'};
75:
76: if ($externalsyllabus=~/\w/) {
77: $r->print( Apache::lonwrapper::wrapper($externalsyllabus) );
78: return OK;
79: }
80:
81: # ------------------------------ The buck stops here: internal syllabus display
82: # --------------------------------------------------------- The syllabus fields
83: my %syllabusfields=&Apache::lonlocal::texthash(
84: 'aaa_instructorinfo' => 'Instructor Information',
85: 'bbb_description' => 'Course Description',
86: 'ccc_prereq' => 'Prerequisites',
87: 'cdc_classhours' => 'Class Hours',
88: 'ddd_officehours' => 'Office Hours',
89: 'eee_helproom' => 'Helproom Hours',
90: 'efe_projectinfo' => 'Project Information',
91: 'fff_examinfo' => 'Exam Information',
92: 'fgf_deadlines' => 'Deadlines',
93: 'ggg_grading' => 'Grading Information',
94: 'hhh_readings' => 'Readings',
95: 'iii_coursepack' => 'Coursepack',
96: 'jjj_weblinks' => 'Web Links',
97: 'kkk_textbook' => 'Textbook',
98: 'lll_includeurl' => 'URLs To Include in Syllabus');
99: # --------------------------------------------------------------- Force Student
100: my $forcestudent='';
101: if ($env{'form.forcestudent'}) { $forcestudent='student'; };
102: my $forceedit='';
103: if ($env{'form.forceedit'}) { $forceedit='edit'; }
104:
105: # ----------------------------------------------------------------- Make header
106: if ($target ne 'tex') {
107: my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
108: my $js;
109: if ($env{'form.backto'} eq 'coursecatalog') {
110: $js .= <<"ENDSCRIPT";
111:
112: <script type="text/javascript">
113: function ToCatalog(caller) {
114: numidx = getIndexByName('coursenum');
115: if (numidx > -1) {
116: if (caller != 'details') {
117: document.backtocat.elements[numidx].value = '';
118: }
119: }
120: document.backtocat.submit();
121: }
122:
123: function getIndexByName(item) {
124: for (var i=0;i<document.backtocat.elements.length;i++) {
125: if (document.backtocat.elements[i].name == item) {
126: return i;
127: }
128: }
129: return -1;
130: }
131:
132: </script>
133:
134: ENDSCRIPT
135: }
136: my $start_page =
137: &Apache::loncommon::start_page("Syllabus", $rss_link.$js,
138: {'function' => undef,
139: 'domain' => $cdom,
140: 'force_register' =>
141: $env{'form.register'},});
142:
143: $r->print($start_page);
144: if ($env{'form.backto'} eq 'coursecatalog') {
145: &Apache::lonhtmlcommon::clear_breadcrumbs();
146: &Apache::lonhtmlcommon::add_breadcrumb
147: ({href=>"javascript:ToCatalog()",
148: text=>"Course/Community Catalog"});
149: if ($env{'form.coursenum'} ne '') {
150: &Apache::lonhtmlcommon::add_breadcrumb
151: ({href=>"javascript:ToCatalog('details')",
152: text=>"Course details"});
153: }
154: &Apache::lonhtmlcommon::add_breadcrumb
155: ({href=>$r->uri,
156: text=>"Course syllabus"});
157: $r->print(&Apache::lonhtmlcommon::breadcrumbs());
158: }
159: }
160: # ---------------------------------------------------------- Load syllabus info
161: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
162: my $allowed=0;
163: my $privileged=0;
164:
165: # This handler might be called anonymously ...
166: # ----------------------------------------------------- Only if not public call
167: if ($env{'user.environment'}) {
168: # does this user have privileges to post, etc?
169: if ($env{'request.course.id'}
170: && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
171: && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
172: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
173: $privileged=$allowed;
174: if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
175: $forcestudent='student';
176: }
177: if ($forcestudent or $target eq 'tex') { $allowed=0; }
178: }
179: #store what the user typed in
180: if (($allowed) && ($env{'form.storesyl'})) {
181: foreach my $syl_field (keys(%syllabusfields)) {
182: my $field=$env{'form.'.$syl_field};
183: chomp($field);
184: $field=~s/\s+$//s;
185: $field=~s/^\s+//s;
186: $field=~s/\<br\s*\/*\>$//s;
187: $field=&Apache::lonfeedback::clear_out_html($field,1);
188: #here it will be stored
189: $syllabus{$syl_field}=$field;
190: if ($syl_field eq 'lll_includeurl') { # clean up included URLs
191: my $field='';
192: foreach my $value (split(/\n/,$syllabus{$syl_field})) {
193: my $url=$value;
194: # get rid of leading and trailing spaces
195: $url=~s/^\s+//;
196: $url=~s/\s+$//;
197: if ($url=~m|^https?\://([^/]+)/(.+)$|) {
198: my $host = $1;
199: my $remainder=$2;
200: # remove the hostname from internal URLs
201: my $hostname = &Apache::lonnet::hostname($host);
202: my %all_hostnames = &Apache::lonnet::all_hostnames();
203: foreach my $possible_host (keys(%all_hostnames)) {
204: if ($possible_host =~ /\Q$hostname\E/i) {
205: $url=$remainder;
206: }
207: }
208: }
209: # norm internal URLs
210: unless ($url=~/^https?\:/) {
211: $url=&Apache::lonnet::clutter($url);
212: }
213: # re-assemble field
214: if ($url) {
215: $field.=$url."\n";
216: }
217: }
218: $syllabus{$syl_field}=$field;
219: }
220: }
221: $syllabus{'uploaded.domain'}=$env{'user.domain'};
222: $syllabus{'uploaded.name'}=$env{'user.name'};
223: $syllabus{'uploaded.lastmodified'}=time;
224: &Apache::lonnet::put('syllabus',\%syllabus,$cdom,$cnum);
225: }
226: }
227:
228: #--------Functions
229: if( ($allowed || $privileged) && $target ne 'tex') {
230: my $functions=&Apache::lonhtmlcommon::start_funclist();
231: if ($allowed) {
232: #if you have the register flag, keep it
233: if($env{'form.register'} == 1) {
234: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
235: '<a href="'.$r->uri.'?forcestudent=1&register=1">'
236: .&mt('Show Public View').'</a>'
237: .&Apache::loncommon::help_open_topic(
238: 'Uploaded_Templates_PublicView'));
239: } else {
240: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
241: '<a href="'.$r->uri.'?forcestudent=1">'
242: .&mt('Show Public View').'</a>'
243: .&Apache::loncommon::help_open_topic(
244: 'Uploaded_Templates_PublicView'));
245: }
246: } elsif ($privileged) {
247: if($env{'form.register'} == 1) {
248: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
249: '<a href="'.$r->uri.'?forceedit=1&register=1">'
250: .&mt('Edit').'</a>');
251: } else {
252: $functions.=&Apache::lonhtmlcommon::add_item_funclist(
253: '<a href="'.$r->uri.'?forceedit=1">'
254: .&mt('Edit').'</a>');
255: }
256: }
257:
258: $functions.=&Apache::lonhtmlcommon::end_funclist();
259: $r->print(&Apache::loncommon::head_subbox($functions));
260: }
261:
262: #---------------------Print External URL Syllabus Info and Help Text
263: if( ($allowed) && ($target ne 'tex') ) {
264: my $protocol = $Apache::lonnet::protocol{$homeserver};
265: $protocol = 'http' if ($protocol ne 'https');
266: $r->print('<p class="LC_info">'
267: .&mt('This syllabus can be publicly viewed at [_1]'
268: ,'<tt>'.$protocol.'://'.&Apache::lonnet::hostname($homeserver).$r->uri.'</tt>')
269: .' '.&Apache::loncommon::help_open_topic('Syllabus_ExtLink')
270: .'</p>'
271: .'<p class="LC_info">'
272: .&mt('Instead of using this template you can specify an external URL as Syllabus in the [_1]Course Configuration[_2].'
273: ,'<a href="/adm/courseprefs?actions=courseinfo&phase=display">','</a>')
274: .'</p>'
275: );
276: #-Print Help Text
277: $r->print(&Apache::loncommon::help_open_topic(
278: 'Uploaded_Templates_TextBoxes',
279: &mt('Help with filling in text boxes')));
280: }
281:
282: #----------Print last update
283: my $lastmod=$syllabus{'uploaded.lastmodified'};
284: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
285: my $who;
286: if (($env{'user.name'} ne 'public') && ($env{'user.domain'} ne 'public')) {
287: $who = &Apache::loncommon::aboutmewrapper(
288: &Apache::loncommon::plainname($syllabus{'uploaded.name'},
289: $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
290: $syllabus{'uploaded.domain'});
291: } else {
292: # Public user?
293: # Only display name of user, but no link to personal information page
294: $who = &Apache::loncommon::plainname(
295: $syllabus{'uploaded.name'},
296: $syllabus{'uploaded.domain'});
297: }
298:
299: if ($target ne 'tex') {
300: $r->print('<div class="LC_info">'.&mt('Last updated').': '.
301: $lastmod . ' '.
302: ($who ? &mt('by').' '.$who
303: : '' ) .
304: '</div>' );
305:
306: } else {
307: $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.
308: ($who? &mt('by').'\\\\ '.
309: &Apache::loncommon::plainname($syllabus{'uploaded.name'},$syllabus{'uploaded.domain'})
310: :'')
311: .'\\\\');
312: }
313: #----------------------------Print Headtitle
314: if ($target ne 'tex') {
315: $r->print('<h1>'.$courseenv{'description'}.'</h1>');
316: $r->print('<h3>'. &Apache::lonnet::domain($cdom,'description').'</h3>');
317: } else {
318: $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
319: &Apache::lonnet::domain($cdom,'description').'}\\\\');
320: }
321: # -------------------------------------------------------- Get course personnel
322: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
323: if ($target ne 'tex') {
324: $r->print(&Apache::lonhtmlcommon::start_pick_box());
325: } else {
326: $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
327: }
328: my @personnel=sort(keys(%coursepersonnel));
329: my $lastpers=$personnel[$#personnel];
330: foreach my $element (@personnel) {
331: if ($target ne 'tex') {
332: $r->print(&Apache::lonhtmlcommon::row_title($element));
333: } else {
334: $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & ');
335: }
336: foreach (split(/\,/,$coursepersonnel{$element})) {
337: my ($puname,$pudom)=split(/\:/,$_);
338: if ($target ne 'tex') {
339: my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
340: if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
341: ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
342: $r->print(' '.$courseperson);
343: } else {
344: $r->print(' '.&Apache::loncommon::aboutmewrapper($courseperson,
345: $puname,$pudom));
346: }
347: } else {
348: $r->print(' '.&Apache::loncommon::plainname($puname,
349: $pudom).' ');
350: }
351: }
352: if ($target ne 'tex') {
353: my $lastclose=$element eq $lastpers?1:0;
354: $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
355: } else {
356: $r->print('\\\\ \hline');
357: }
358: }
359: if ($target ne 'tex') {
360: $r->print(&Apache::lonhtmlcommon::end_pick_box());
361: } else {
362: $r->print('\end{tabular}\\\\');
363: }
364: # -------------------------------------------------------------- Announcements?
365: my $day = &Apache::lonannounce::showday(time,2,
366: &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
367: if ($target ne 'tex') {
368: if ($allowed) {
369: &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box');
370: $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
371: my $editurl= &Apache::lonnet::absolute_url().'/adm/'.$cdom.'/'.$cnum.'/_rss.html';
372: $r->print( '<a href="'.$editurl.'">'.&mt('New RSS Feed or Blog').'</a>');
373: &Apache::lontemplate::print_end_template($r);
374: } elsif (&Apache::lonrss::advertisefeeds($cnum,$cdom) ne '') {
375: &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box');
376: $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit));
377: &Apache::lontemplate::print_end_template($r);
378: }
379:
380: } else {
381: $r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
382: }
383: # ---------------------------------------------------------------- Get syllabus
384: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
385: if ($allowed) {
386: $r->print('<form method="post" action="">'.
387: '<input type="hidden" name="forceedit" value="edit" />');
388: }
389: my $url_include_handler = sub {
390: my ($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed) = @_;
391: my %data = %{$data_ref};
392: my %fields = %{$fields_ref};
393: my $urls=$message;
394: $message='';
395: foreach my $filelink (split(/\n/,$urls)) {
396: my $output='';
397: # embed style?
398: my ($curfext)=($filelink=~/\.([^\.]+)$/);
399: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
400: if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {# make ssi call and remove everything but the body contents
401: $output=&Apache::lonnet::ssi_body($filelink);
402: } elsif ($embstyle eq 'img') {# embed as an image
403: $output='<img src="'.$filelink.'" />';
404: }
405: if ($output ne '') {
406: if ($target ne 'tex') {
407: $message.='<p>'.$output.'</p>';
408: } else {
409: $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
410: }
411: }
412: }
413: if ($allowed) {
414: &Apache::lonfeedback::newline_to_br(\$urls);
415: &Apache::lontemplate::print_start_template($r,$fields{$field}.
416: &Apache::loncommon::help_open_topic('Syllabus_URLs'),'LC_Box');
417: $r->print($urls);
418: $r->print("<br /><div>");
419: &Apache::lontemplate::print_textarea_template($r, $data{$field},
420: $field, Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
421: &Apache::lontemplate::print_saveall_template($r);
422: $r->print("</div>");
423: &Apache::lontemplate::print_end_template($r);
424:
425: } else {
426: $r->print($message);
427: }
428: };
429: my %custom_hash = ( 'lll_includeurl' => $url_include_handler );
430: &Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields,
431: $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_hash);
432: if ($allowed) {
433: $r->print('</form>'.
434: &Apache::lonhtmlcommon::htmlareaselectactive());
435: }
436: } else {
437: if ($target ne 'tex') {$r->print('<p>');} else {$r->print('\par ');}
438: $r->print(&mt('No syllabus information provided.'));
439: if ($target ne 'tex') {$r->print('</p>');}
440: }
441: if ($target ne 'tex') {
442: if ($env{'form.backto'} eq 'coursecatalog') {
443: $r->print('<form name="backtocat" method="post" action="/adm/coursecatalog">'.
444: &Apache::lonhtmlcommon::echo_form_input(['backto','courseid']).
445: '</form>');
446: }
447: $r->print(&Apache::loncommon::end_page());
448: } else {
449: $r->print('\end{document}');
450: }
451: return OK;
452: }
453:
454: 1;
455: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>