Annotation of loncom/interface/lonsyllabus.pm, revision 1.126
1.1 www 1: # The LearningOnline Network
2: # Syllabus
3: #
1.126 ! raeburn 4: # $Id: lonsyllabus.pm,v 1.125 2013/05/15 17:47:57 raeburn Exp $
1.1 www 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;
1.70 amueller 32: use Apache::lontemplate;
1.1 www 33: use Apache::Constants qw(:common);
34: use Apache::loncommon;
35: use Apache::lonnet;
1.5 www 36: use Apache::lontexconvert;
1.11 www 37: use Apache::lonfeedback;
1.19 www 38: use Apache::lonannounce;
1.23 www 39: use Apache::lonlocal;
1.32 www 40: use Apache::lonhtmlcommon;
1.38 www 41: use Apache::lonspeller();
1.54 albertel 42: use HTML::Entities();
1.1 www 43:
44: sub handler {
45: my $r = shift;
1.46 www 46: &Apache::loncommon::content_type($r,'text/html');
47: $r->send_http_header;
48: return OK if $r->header_only;
1.45 www 49:
1.46 www 50: my $target=$env{'form.grade_target'};
1.45 www 51: # --------------------------------------------------- Get course info from URL
52: my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
1.46 www 53: # ------------------------------------------------------------ Get query string
54: &Apache::loncommon::get_unprocessed_cgi
1.116 raeburn 55: ($ENV{'QUERY_STRING'},['register','forceedit','todocs',
1.115 raeburn 56: 'folderpath','title']);
1.45 www 57: # ----------------------------------------------------- Is this even a course?
58: my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom);
59: if ($homeserver eq 'no_host') {
60: &Apache::loncommon::content_type($r,'text/html');
61: $r->send_http_header;
1.106 faziophi 62: &Apache::loncommon::simple_error_page($r,'No syllabus available',
1.91 amueller 63: 'No syllabus available');
1.45 www 64: return OK;
1.113 raeburn 65: } elsif (!&Apache::lonnet::is_course($cdom,$cnum)) {
66: &Apache::loncommon::content_type($r,'text/html');
67: $r->send_http_header;
68: &Apache::loncommon::simple_error_page($r,'No syllabus available',
69: 'The course/community for which the syllabus was requested does not exist.');
70: return OK;
1.45 www 71: }
72: # ------------------------------------- There is such a course, get environment
73: my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
1.125 raeburn 74: my $crstype = &Apache::loncommon::course_type();
1.46 www 75:
1.1 www 76: # ------------------------------------------------------------ Print the screen
1.49 albertel 77:
78: if ($target eq 'tex') {
1.91 amueller 79: $r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
1.86 bisitz 80: }
1.117 raeburn 81:
82: # --------------------------------------------------------------- Force Student
83: my ($forceedit,$forcestudent);
84: if ($env{'form.forceedit'}) { $forceedit=1; }
85: if (!$forceedit) {
86: $forcestudent=1;
87: }
88:
89: # --------------------------------------------------------------- Check Privileges
90: my $allowed = 0;
91: if ($env{'user.environment'}) {
92: # does this user have privileges to post, etc?
93: if ($env{'request.course.id'}
94: && $cdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}
95: && $cnum eq $env{'course.'.$env{'request.course.id'}.'.num'}) {
96: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
97: if ($forcestudent or $target eq 'tex') { $allowed=0; }
98: }
99: }
100:
1.46 www 101: # -------------------------------------------------- Let's see who handles this
1.117 raeburn 102: my $external=$courseenv{'externalsyllabus'};
103: my $uploaded=$courseenv{'uploadedsyllabus'};
1.122 raeburn 104: my $minimal=$courseenv{'minimalsyllabus'};
1.49 albertel 105:
1.122 raeburn 106: if (($minimal =~/\w/) || ($uploaded =~/\w/)) {
107: my $item;
108: if ($minimal =~/\w/) {
109: if ($external =~ m{\Q$minimal\E$}) {
110: undef($external);
111: }
112: $item = $minimal;
113: } elsif ($uploaded =~/\w/) {
114: if ($external =~ m{\Q$uploaded\E$}) {
115: undef($external);
116: }
117: $item = $uploaded;
1.117 raeburn 118: }
119: unless ($allowed && $forceedit) {
1.122 raeburn 120: my $file=&Apache::lonnet::filelocation("",$item);
1.125 raeburn 121: if ($file =~ /\.(tex|x?html?)$/) {
122: my $filetype = $1;
1.117 raeburn 123: my $filecontents=&Apache::lonnet::getfile($file);
124: if ($filecontents eq -1) {
125: $r->print(&mt('Syllabus file unavailable'));
1.125 raeburn 126: } elsif ($filetype eq 'tex') {
127: my $result = &Apache::lontexconvert::converted(\$filecontents,
128: $env{'form.texengine'});
129: my %args;
130: &get_breadcrumbs($cdom,$cnum,$crstype,\%args);
131: $r->print(&Apache::loncommon::start_page("Syllabus",undef,\%args).
132: $result.
133: &Apache::loncommon::end_page());
134: } else {
1.117 raeburn 135: my %mystyle;
136: &Apache::structuretags::reset_problem_globals();
137: my $oldfile = $env{'request.filename'};
1.122 raeburn 138: $env{'request.filename'} = $item;
1.125 raeburn 139: my $result = &Apache::lonxml::xmlparse($r,'web',$filecontents,
140: '',%mystyle);
1.117 raeburn 141: &Apache::structuretags::reset_problem_globals();
142: &Apache::lonhomework::finished_parsing();
143: $env{'request.filename'} = $oldfile;
144: &Apache::lonxml::add_messages(\$result);
145: $r->print($result);
146: }
147: } else {
1.122 raeburn 148: $r->print(&Apache::lonwrapper::wrapper($item));
1.117 raeburn 149: }
150: return OK;
151: }
152: } elsif ($external=~/\w/) {
153: unless ($allowed && $forceedit) {
154: $r->print(&Apache::lonwrapper::wrapper($external));
155: return OK;
156: }
1.90 amueller 157: }
1.42 www 158:
1.120 raeburn 159:
1.46 www 160: # ------------------------------ The buck stops here: internal syllabus display
1.5 www 161: # --------------------------------------------------------- The syllabus fields
1.23 www 162: my %syllabusfields=&Apache::lonlocal::texthash(
1.5 www 163: 'aaa_instructorinfo' => 'Instructor Information',
164: 'bbb_description' => 'Course Description',
165: 'ccc_prereq' => 'Prerequisites',
1.7 www 166: 'cdc_classhours' => 'Class Hours',
1.5 www 167: 'ddd_officehours' => 'Office Hours',
168: 'eee_helproom' => 'Helproom Hours',
1.7 www 169: 'efe_projectinfo' => 'Project Information',
1.5 www 170: 'fff_examinfo' => 'Exam Information',
1.7 www 171: 'fgf_deadlines' => 'Deadlines',
1.5 www 172: 'ggg_grading' => 'Grading Information',
1.7 www 173: 'hhh_readings' => 'Readings',
174: 'iii_coursepack' => 'Coursepack',
175: 'jjj_weblinks' => 'Web Links',
1.9 www 176: 'kkk_textbook' => 'Textbook',
177: 'lll_includeurl' => 'URLs To Include in Syllabus');
1.121 raeburn 178: # ---------------------------------------------------------- Load syllabus info
179: my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
180: my ($output,%displayfields,%noshow);
1.65 raeburn 181:
1.121 raeburn 182: # This handler might be called anonymously ...
183: # ----------------------------------------------------- Only if not public call
184: if ($allowed) {
1.122 raeburn 185: if (($env{'form.choice'} =~ /^(template|minimal|url|file)$/) ||
1.121 raeburn 186: ($env{'form.phase'} =~ /^(upload|check)_embedded$/)) {
187: my $earlyout;
1.122 raeburn 188: ($earlyout,$uploaded,$external,$minimal,$output) =
189: &save_changes($cnum,$cdom,$uploaded,$external,$minimal,
190: \%syllabus,\%syllabusfields,\%courseenv);
191: if (($env{'form.choice'} eq 'minimal') &&
192: ($minimal eq "/uploaded/$cdom/$cnum/portfolio/syllabus/loncapa.html")) {
193: delete($env{'form.symb'});
194: delete($env{'request.symb'});
195: $r->internal_redirect("$minimal?editmode=1&forceedit=1");
196: return OK;
197: }
1.121 raeburn 198: if ($earlyout) {
199: if ($target ne 'tex') {
200: &print_header($r,$cnum,$cdom,$crstype,$allowed,$forceedit,
201: \%syllabus,\%syllabusfields);
1.122 raeburn 202: $r->print($output.
203: &Apache::loncommon::end_page());
1.121 raeburn 204: }
205: return OK;
1.90 amueller 206: }
1.65 raeburn 207: }
208: }
1.121 raeburn 209: if ($target ne 'tex') {
210: &print_header($r,$cnum,$cdom,$crstype,$allowed,$forceedit,\%syllabus,
211: \%syllabusfields);
212: $r->print($output);
1.117 raeburn 213: }
214:
1.121 raeburn 215: # -------------------------------------------- Determine which fields are shown
1.117 raeburn 216:
1.121 raeburn 217: if ($syllabus{'uploaded.fields'}) {
218: if ($syllabus{'uploaded.fields'} eq 'none') {
219: foreach my $field (keys(%syllabusfields)) {
220: $displayfields{$field} = ' style="display:none;"';
221: $noshow{$field} = 1;
1.117 raeburn 222: }
223: } else {
1.121 raeburn 224: my %included;
225: map { $included{$_} = 1; } split(/,/,$syllabus{'uploaded.fields'});
226: foreach my $field (keys(%syllabusfields)) {
227: my ($prefix) = split(/_/,$field);
228: if ($included{$prefix}) {
229: $displayfields{$field} = ' style="display:block;"';
1.117 raeburn 230: } else {
1.121 raeburn 231: $displayfields{$field} = ' style="display:none;"';
232: $noshow{$field} = 1;
1.117 raeburn 233: }
234: }
235: }
1.121 raeburn 236: } else {
1.117 raeburn 237: foreach my $field (keys(%syllabusfields)) {
238: if ($syllabus{$field} ne '') {
239: $displayfields{$field} = ' style="display:block;"';
240: } else {
241: $displayfields{$field} = ' style="display:none;"';
242: }
1.90 amueller 243: }
1.4 www 244: }
1.85 bisitz 245:
1.113 raeburn 246: if ($allowed) {
247: #---------------------------------- Print External URL Syllabus Info if editing
248: if ($target ne 'tex') {
249: my $protocol = $Apache::lonnet::protocol{$homeserver};
250: $protocol = 'http' if ($protocol ne 'https');
1.119 raeburn 251: my $link = $protocol.'://'.&Apache::lonnet::hostname($homeserver).$r->uri;
252: $r->print('<div class="LC_left_float">'
253: .'<span class="LC_help_open_topic LC_info">'
254: .'<span class="LC_info">'
255: .&mt('Public link (no log-in): [_1]','<tt>'.$link.'</tt>')
256: .' </span>'.&Apache::loncommon::help_open_topic('Syllabus_ExtLink')
257: .'</span>'
1.121 raeburn 258: .'</div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n");
1.117 raeburn 259: my $lonhost = $r->dir_config('lonHostID');
1.122 raeburn 260: $r->print(&chooser($external,$uploaded,$minimal,$cdom,$cnum,$lonhost,
261: \%syllabusfields,\%syllabus));
1.93 bisitz 262: }
1.109 bisitz 263: } else {
1.113 raeburn 264: #--------------------------------------------- Print last update unless editing
265: my $lastmod=$syllabus{'uploaded.lastmodified'};
266: $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
267: my $who;
268: if ($syllabus{'uploaded.lastmodified'}) {
269: if (($env{'user.name'} ne 'public') && ($env{'user.domain'} ne 'public')) {
270: $who = &Apache::loncommon::aboutmewrapper(
271: &Apache::loncommon::plainname($syllabus{'uploaded.name'},
272: $syllabus{'uploaded.domain'}),$syllabus{'uploaded.name'},
273: $syllabus{'uploaded.domain'});
274: } else {
275: # Public user?
276: # Only display name of user, but no link to personal information page
277: $who = &Apache::loncommon::plainname(
278: $syllabus{'uploaded.name'},
279: $syllabus{'uploaded.domain'});
280: }
281: }
282: if ($target ne 'tex') {
283: $r->print('<div class="LC_info">'.&mt('Last updated').': '.
284: $lastmod . ' '.
285: ($who ? &mt('by').' '.$who
286: : '' ) .
287: '</div>' );
288: } else {
289: $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.
290: ($who? &mt('by').'\\\\ '.
291: &Apache::loncommon::plainname($syllabus{'uploaded.name'},$syllabus{'uploaded.domain'})
292: :'')
293: .'\\\\');
294: }
1.109 bisitz 295: }
296:
1.113 raeburn 297: #-------------------------------------------------------------- Print Headtitle
1.90 amueller 298: if ($target ne 'tex') {
1.117 raeburn 299: my $display = 'block';
1.122 raeburn 300: if ($external || $uploaded || $minimal) {
1.117 raeburn 301: $display = 'none';
302: }
303: $r->print('<div class="LC_Box" id="template" style="display: '.$display.'">'.
1.113 raeburn 304: '<h2 class="LC_hcell">'.$courseenv{'description'}.'</h2>');
305: if ($allowed) {
1.121 raeburn 306: $r->print('<div style="margin: 0; float:left;">'.
307: '<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>'.
308: '</div>');
1.113 raeburn 309: # Print Help Text if editing at right side of screen
1.121 raeburn 310: $r->print('<div style="margin: 0; float:right;">'.
311: &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).
312: '</div><br clear="all" />');
1.113 raeburn 313: } else {
314: $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>');
315: }
1.90 amueller 316: } else {
1.91 amueller 317: $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
318: &Apache::lonnet::domain($cdom,'description').'}\\\\');
1.90 amueller 319: }
1.80 neumanie 320: # -------------------------------------------------------- Get course personnel
1.121 raeburn 321: my $hidepersonnel;
322: if (($syllabus{'uploaded.fields'}) &&
323: (($syllabus{'uploaded.fields'} eq 'none') ||
324: ($syllabus{'uploaded.fields'} !~ /000/))) {
325: $hidepersonnel = 1;
326: }
1.80 neumanie 327: if ($target ne 'tex') {
1.121 raeburn 328: if ($allowed) {
329: my $display = ' style="display:block;"';
330: if ($hidepersonnel) {
331: $display = ' style="display:none;"';
332: }
333: &Apache::lontemplate::print_start_template($r,&mt('Personnel'),'LC_Box',
334: 'box_000_showpeople',$display);
335: $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed));
336: &Apache::lontemplate::print_end_template($r);
1.91 amueller 337: } else {
1.121 raeburn 338: unless ($hidepersonnel) {
339: &Apache::lontemplate::print_start_template($r,&mt('Personnel'),'LC_Box');
340: $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed));
341: &Apache::lontemplate::print_end_template($r);
1.91 amueller 342: }
343: }
1.121 raeburn 344: } else {
345: unless ($hidepersonnel) {
346: $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed));
1.91 amueller 347: }
1.80 neumanie 348: }
1.79 neumanie 349: # -------------------------------------------------------------- Announcements?
350: my $day = &Apache::lonannounce::showday(time,2,
1.91 amueller 351: &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
1.121 raeburn 352: my $hidefeeds;
353: if (($syllabus{'uploaded.fields'}) &&
354: (($syllabus{'uploaded.fields'} eq 'none') ||
355: ($syllabus{'uploaded.fields'} !~ /111/))) {
356: $hidefeeds = 1;
357: }
1.80 neumanie 358: if ($target ne 'tex') {
1.91 amueller 359: if ($allowed) {
1.117 raeburn 360: my $display = ' style="display:block;"';
1.121 raeburn 361: if ($hidefeeds) {
1.117 raeburn 362: $display = ' style="display:none;"';
363: }
364: &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box',
1.121 raeburn 365: 'box_111_showrssfeeds',$display);
1.120 raeburn 366: my ($numfeeds,$hiddenfeeds,$rsslinktext);
1.121 raeburn 367: my $feeds=&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit,\$numfeeds,
368: \$hiddenfeeds);
1.120 raeburn 369: if ($numfeeds) {
370: $r->print($feeds);
371: $rsslinktext = &mt('New RSS Feed or Blog');
372: } else {
373: my $msg = '<br />'.
374: &mt("RSS Feeds and Blogs item is not included in a student's view of the syllabus.");
375: if ($hiddenfeeds) {
376: $r->print('<p class="LC_info">'.
377: &mt('All feeds currently hidden').
378: $msg.
379: '</p>');
380: } else {
381: $r->print('<p class="LC_info">'.
382: &mt('No current feeds').
383: $msg.
384: '</p>');
385: }
386: $rsslinktext = &mt('Manage Course RSS Feeds/Blogs');
387: if ($crstype eq 'Community') {
388: $rsslinktext = &mt('Manage Communiity RSS Feeds/Blogs');
389: }
390: }
1.91 amueller 391: my $editurl= &Apache::lonnet::absolute_url().'/adm/'.$cdom.'/'.$cnum.'/_rss.html';
1.120 raeburn 392: $r->print( '<a href="'.$editurl.'">'.$rsslinktext.'</a>');
1.91 amueller 393: &Apache::lontemplate::print_end_template($r);
1.117 raeburn 394: } else {
1.121 raeburn 395: unless ($hidefeeds) {
1.120 raeburn 396: my $feeds = &Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit);
397: if ($feeds ne '') {
1.117 raeburn 398: &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box');
1.120 raeburn 399: $r->print($feeds);
1.117 raeburn 400: &Apache::lontemplate::print_end_template($r);
401: }
402: }
1.91 amueller 403: }
1.79 neumanie 404: } else {
1.91 amueller 405: $r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
1.86 bisitz 406: }
1.79 neumanie 407: # ---------------------------------------------------------------- Get syllabus
1.86 bisitz 408: if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
1.90 amueller 409: if ($allowed) {
1.121 raeburn 410: $r->print('<form method="post" action="">');
1.90 amueller 411: }
1.117 raeburn 412:
1.106 faziophi 413: my $url_include_handler = sub {
1.117 raeburn 414: my ($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed, $display) = @_;
1.106 faziophi 415: my %data = %{$data_ref};
416: my %fields = %{$fields_ref};
417: my $urls=$message;
418: $message='';
419: foreach my $filelink (split(/\n/,$urls)) {
420: my $output='';
421: # embed style?
422: my ($curfext)=($filelink=~/\.([^\.]+)$/);
423: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
424: if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {# make ssi call and remove everything but the body contents
425: $output=&Apache::lonnet::ssi_body($filelink);
426: } elsif ($embstyle eq 'img') {# embed as an image
427: $output='<img src="'.$filelink.'" />';
428: }
429: if ($output ne '') {
430: if ($target ne 'tex') {
431: $message.='<p>'.$output.'</p>';
432: } else {
433: $message.=' '.&Apache::lonxml::xmlparse($r,'tex','<p>'.$output.'</p>').' ';
434: }
435: }
436: }
437: if ($allowed) {
438: &Apache::lonfeedback::newline_to_br(\$urls);
439: &Apache::lontemplate::print_start_template($r,$fields{$field}.
1.117 raeburn 440: &Apache::loncommon::help_open_topic('Syllabus_URLs'),'LC_Box',
441: 'box_'.$field,$display);
1.106 faziophi 442: $r->print($urls);
443: $r->print("<br /><div>");
444: &Apache::lontemplate::print_textarea_template($r, $data{$field},
445: $field, Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
446: &Apache::lontemplate::print_saveall_template($r);
447: $r->print("</div>");
448: &Apache::lontemplate::print_end_template($r);
1.86 bisitz 449:
1.106 faziophi 450: } else {
451: $r->print($message);
452: }
453: };
454: my %custom_hash = ( 'lll_includeurl' => $url_include_handler );
1.110 raeburn 455: &Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields,
1.117 raeburn 456: $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_hash,
1.121 raeburn 457: undef,\%displayfields,\%noshow);
1.90 amueller 458: if ($allowed) {
1.91 amueller 459: $r->print('</form>'.
1.110 raeburn 460: &Apache::lonhtmlcommon::htmlareaselectactive());
1.90 amueller 461: }
1.4 www 462: } else {
1.112 bisitz 463: if ($target ne 'tex') {$r->print('<p class="LC_info">');} else {$r->print('\par ');}
1.91 amueller 464: $r->print(&mt('No syllabus information provided.'));
465: if ($target ne 'tex') {$r->print('</p>');}
1.1 www 466: }
1.86 bisitz 467: if ($target ne 'tex') {
1.65 raeburn 468: if ($env{'form.backto'} eq 'coursecatalog') {
469: $r->print('<form name="backtocat" method="post" action="/adm/coursecatalog">'.
1.66 raeburn 470: &Apache::lonhtmlcommon::echo_form_input(['backto','courseid']).
1.65 raeburn 471: '</form>');
472: }
1.91 amueller 473: $r->print(&Apache::loncommon::end_page());
1.48 albertel 474: } else {
1.91 amueller 475: $r->print('\end{document}');
1.48 albertel 476: }
1.1 www 477: return OK;
1.86 bisitz 478: }
1.1 www 479:
1.121 raeburn 480: sub print_header {
481: my ($r,$cnum,$cdom,$crstype,$allowed,$forceedit,$syllabus,$syllabusfields) = @_;
482: return unless ((ref($syllabus) eq 'HASH') || (ref($syllabusfields) eq 'HASH'));
483: # ----------------------------------------------------------------- Make header
484: my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
485: my $js;
486: if ($env{'form.backto'} eq 'coursecatalog') {
487: $js .= <<"ENDSCRIPT";
488:
489: <script type="text/javascript">
490: // <![CDATA[
491:
492: function ToCatalog(caller) {
493: numidx = getIndexByName('coursenum');
494: if (numidx > -1) {
495: if (caller != 'details') {
496: document.backtocat.elements[numidx].value = '';
497: }
498: }
499: document.backtocat.submit();
500: }
501:
502: function getIndexByName(item) {
503: for (var i=0;i<document.backtocat.elements.length;i++) {
504: if (document.backtocat.elements[i].name == item) {
505: return i;
506: }
507: }
508: return -1;
509: }
510:
511: // ]]>
512: </script>
513:
514: ENDSCRIPT
515: }
516: if ($allowed && $forceedit) {
517: my $check_uncheck = &Apache::loncommon::check_uncheck_jscript();
518: my @fieldnames = sort(keys(%{$syllabusfields}));
519: unshift(@fieldnames,'000_showpeople','111_showrssfeeds');
520: my (@checked,@unchecked);
521: if ($syllabus->{'uploaded.fields'} eq 'none') {
522: my $lastidx = scalar(@fieldnames)-1;
523: @unchecked = (0..$lastidx);
524: } elsif ($syllabus->{'uploaded.fields'}) {
525: my %included;
526: map { $included{$_} = 1; } split(/,/,$syllabus->{'uploaded.fields'});
527: for (my $i=0; $i<@fieldnames; $i++) {
528: my ($prefix) = split(/_/,$fieldnames[$i]);
529: if ($included{$prefix}) {
530: push(@checked,$i);
531: } else {
532: push(@unchecked,$i);
533: }
534: }
535: } else {
536: @checked = (0,1);
537: for (my $i=2; $i<@fieldnames; $i++) {
538: if ($syllabus->{$fieldnames[$i]}) {
539: push(@checked,$i);
540: } else {
541: push(@unchecked,$i);
542: }
543: }
544: }
545: my $fieldstr = "var fields = new Array('".join("','",@fieldnames)."');";
546: my $checkedstr = "var include = new Array('".join("','",@checked)."');";
547: my $uncheckedstr = "var exclude = new Array('".join("','",@unchecked)."');";
548: my $invurl = &mt('Invalid URL');
549: my $urlregexp = <<'ENDREGEXP';
550: /^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i
551: ENDREGEXP
552:
553: $js .= <<"ENDSCRIPT";
554:
555: <script type="text/javascript">
556: // <![CDATA[
557:
558: function toggleEditor(pick) {
1.122 raeburn 559: var choices = new Array('template','minimal','url','file','templatebox');
1.121 raeburn 560: for (var i=0; i<choices.length; i++) {
561: if (((choices[i] == 'templatebox') && (pick == 'template')) ||
562: (choices[i] == pick)) {
563: document.getElementById(choices[i]).style.display='block';
564: } else {
565: document.getElementById(choices[i]).style.display='none';
566: }
567: }
568: return;
569: }
570:
571: var regexp = $urlregexp;
572:
573: function extUrlPreview(caller) {
574: if (document.getElementById(caller)) {
575: var url = document.getElementById(caller).value;
576: if (regexp.test(url)) {
577: openMyModal(url,500,400,'yes');
578: } else {
579: alert("$invurl");
580: }
581: }
582: }
583:
584: function toggleBox(name,caller) {
585: if (name == 'all') {
586: if (document.syllabus.showfield.length > 0) {
587: for (var i=0; i<document.syllabus.showfield.length; i++) {
588: if (document.syllabus.showfield[i].checked) {
589: if (document.getElementById('box_'+document.syllabus.showfield[i].value)) {
590: document.getElementById('box_'+document.syllabus.showfield[i].value).style.display='block';
591: }
592: } else {
593: if (document.getElementById('box_'+document.syllabus.showfield[i].value)) {
594: document.getElementById('box_'+document.syllabus.showfield[i].value).style.display='none';
595: }
596: }
597: }
598: }
599: } else {
600: if (caller.checked) {
601: if (document.getElementById('box_'+caller.value)) {
602: document.getElementById('box_'+caller.value).style.display='block';
603: }
604: } else {
605: if (document.getElementById('box_'+caller.value)) {
606: document.getElementById('box_'+caller.value).style.display='none';
607: }
608: }
609: }
610: return;
611: }
612:
613: function setTemplateBoxes() {
614: $fieldstr
615: $checkedstr
616: $uncheckedstr
617: if (include.length > 0) {
618: for (var i=0; i<include.length; i++) {
619: if (document.getElementById('showfield_'+include[i])) {
620: document.getElementById('showfield_'+include[i]).checked = true;
621: if (document.getElementById('box_'+fields[include[i]])) {
622: document.getElementById('box_'+fields[include[i]]).style.display='block';
623: }
624: }
625: }
626: }
627: if (exclude.length > 0) {
628: for (var i=0; i<exclude.length; i++) {
629: if (document.getElementById('showfield_'+exclude[i])) {
630: document.getElementById('showfield_'+exclude[i]).checked = false;
631: if (document.getElementById('box_'+fields[exclude[i]])) {
632: document.getElementById('box_'+fields[exclude[i]]).style.display='none';
633: }
634: }
635: }
636: }
637: return;
638: }
639:
640: $check_uncheck
641:
642: // ]]>
643: </script>
644:
645: ENDSCRIPT
646: }
647: my $args = {'function' => undef,
648: 'domain' => $cdom};
649: my $forcereg;
650: if ($env{'form.register'}) {
651: $forcereg = 1;
652: $args->{'force_register'} = $forcereg;
653: }
654: if ($env{'form.backto'} eq 'coursecatalog') {
655: &Apache::lonhtmlcommon::clear_breadcrumbs();
656: my $brcrum = [{href=>"javascript:ToCatalog();",
657: text=>&mt('Course/Community Catalog'),
658: no_mt=>1}
659: ];
660: if ($env{'form.coursenum'} ne '') {
661: push(@{$brcrum},
662: {href=>"javascript:ToCatalog('details')",
663: text=>"Course details"});
664: }
665: push(@{$brcrum},
666: {href=>$r->uri,
667: text=>"Course syllabus"});
668: $args->{'bread_crumbs'} = $brcrum;
1.125 raeburn 669: } else {
670: &get_breadcrumbs($cdom,$cnum,$crstype,$args);
671: }
672: if ($allowed) {
673: my %loaditem = (
674: onload => 'setTemplateBoxes();',
675: );
676: $args->{'add_entries'} = \%loaditem;
677: }
678: my $start_page =
679: &Apache::loncommon::start_page("Syllabus", $rss_link.$js,$args);
680: if ($start_page) {
681: $r->print($start_page);
682: }
683: }
684:
685: sub get_breadcrumbs{
686: my ($cdom,$cnum,$crstype,$args) = @_;
687: return unless (ref($args) eq 'HASH');
688: if ($env{'form.folderpath'} =~ /^supplemental/) {
1.121 raeburn 689: my $title = $env{'form.title'};
690: if ($title eq '') {
691: $title = &mt('Syllabus');
692: }
693: my $brcrum =
694: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
695: if (ref($brcrum) eq 'ARRAY') {
696: $args->{'bread_crumbs'} = $brcrum;
697: }
698: } else {
699: if ((&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus"))
700: && (($env{'form.symb'}) || ($env{'form.register'}))) {
701: &Apache::lonhtmlcommon::clear_breadcrumbs();
702: } else {
703: $args->{'bread_crumbs'} = [
704: {'href' => "/public/$cdom/$cnum/syllabus",
705: 'text' => 'Syllabus'},
706: ];
707: }
708: }
1.125 raeburn 709: return;
1.121 raeburn 710: }
711:
1.117 raeburn 712: sub chooser {
1.122 raeburn 713: my ($external,$uploaded,$minimal,$cdom,$cnum,$lonhost,$fields,$values) = @_;
1.117 raeburn 714: my %lt = &Apache::lonlocal::texthash(
715: 'type' => 'Syllabus Type',
716: 'url' => 'External URL',
1.122 raeburn 717: 'file' => 'Uploaded file',
718: 'minimal' => 'Minimal template',
719: 'template' => 'Standard template',
1.117 raeburn 720: 'templateboxes' => 'Choose template items ... ',
721: 'curr' => 'Current:',
722: 'rep' => 'Replace:',
723: 'upl' => 'Upload:',
724: 'pr' => 'Preview',
725: 'save' => 'Save',
1.122 raeburn 726: 'sved' => 'Save and Edit',
727: 'chourl' => 'External URL',
1.117 raeburn 728: 'chofile' => 'Uploaded syllabus file',
729: 'parse' => 'Upload embedded images/multimedia files if HTML file',
730: );
731: my %checked = (
732: file => '',
1.122 raeburn 733: minimal => '',
1.117 raeburn 734: url => '',
735: template => '',
736: );
737: my %display = (
738: file => 'none',
1.122 raeburn 739: minimal => 'none',
1.117 raeburn 740: url => 'none',
741: templatebox => 'none',
742: );
743: my $check = ' checked="checked" ';
744: if ($uploaded) {
745: $checked{'file'} = $check;
746: $display{'file'} = 'block';
747: } elsif ($external) {
748: $checked{'url'} = $check;
749: $display{'url'} = 'block';
1.122 raeburn 750: } elsif ($minimal) {
751: $checked{'minimal'} = $check;
752: $display{'minimal'} = 'block';
1.117 raeburn 753: } else {
754: $checked{'template'} = $check;
755: $checked{'templatebox'} = $check;
756: $display{'templatebox'} = 'block';
757: }
758:
759: my $output =
760: '<form name="syllabus" method="post" enctype="multipart/form-data" action="">'."\n".
761: '<input type="hidden" name="forceedit" value="1" />'."\n".
762: '<div class="LC_left_float"><fieldset><legend>'.$lt{'type'}.'</legend>';
1.122 raeburn 763: foreach my $item ('minimal','template','url','file') {
1.117 raeburn 764: $output .= '<label><input type="radio" name="choice" value="'.$item.'" '.$checked{$item}.' onclick="toggleEditor('."'$item'".')" />'.
765: $lt{$item}.'</label><br />';
766: }
767: $output .= '</fieldset></div>'."\n".
768: '<div id="url" class="LC_left_float" style="display: '.$display{'url'}.'">'."\n".
769: '<fieldset><legend>'.$lt{'chourl'}.'</legend><span class="LC_nobreak">'."\n".
770: '<a href="javascript:extUrlPreview('."'syllabusurl'".');">'.$lt{'pr'}.'</a></span> '."\n".
771: '<input type="text" id="syllabusurl" name="externalsyllabus" value="'.$external.'" size="55" />'."\n".
772: ' <input type="submit" name="storeurl" value="'.$lt{'save'}.'" />'."\n".
773: '</fieldset></div>'."\n".
1.122 raeburn 774: '<div id="minimal" class="LC_left_float" style="display: '.$display{'minimal'}.'">'."\n".
775: '<fieldset><legend>'.$lt{'minimal'}.'</legend>';
776: if ($minimal) {
777: my ($absurl,$filename,$depbutton) = &syllabus_file_info($minimal,$cnum,$cdom,$lonhost,'minimal');
778: $output .= '<a href="javascript:extUrlPreview('."'currminimal'".');">'.$lt{'pr'}.'</a>'.
779: '<input type="hidden" name="minimalfile" value="'.&HTML::Entities::encode($absurl).'?inhibitmenu=yes" id="currminimal" />'.
780: $depbutton;
781: } else {
782: $output .= &mt('Title of Syllabus Page:').' '.
783: '<input type="text" id="minimaltitle" name="syllabustitle" value="'.&mt('Syllabus').'" size="30" />'."\n".
784: ' <input type="submit" name="storeminimal" value="'.$lt{'sved'}.'" />'."\n";
785: }
786: $output .= '</fieldset></div>'."\n".
787: '<div id="file" class="LC_left_float" style="display: '.$display{'file'}.'">'."\n".
788: '<fieldset><legend>'.$lt{'file'}.'</legend>';
1.117 raeburn 789: if ($uploaded) {
1.122 raeburn 790: my ($absurl,$filename,$depbutton) = &syllabus_file_info($uploaded,$cnum,$cdom,$lonhost,'file');
1.117 raeburn 791: $output .= '<span class="LC_nobreak">'.$lt{'curr'}.' '.
792: '<input type="hidden" name="uploadedfile" value="'.&HTML::Entities::encode($absurl).'?inhibitmenu=yes" id="currfile" />'.
1.118 raeburn 793: '<a href="javascript:extUrlPreview('."'currfile'".');">'.$filename.'</a></span>'.$depbutton.
794: '<br /><br />'.$lt{'rep'};
1.117 raeburn 795: } else {
796: $output .= $lt{'upl'};
797: }
798: $output .= '<br />'."\n".
799: '<span class="LC_nobreak">'.
800: '<input type="file" name="syllabusfile" size="55" />'."\n".
801: ' <input type="submit" name="storefile" value="'.$lt{'save'}.'" />'.
802: '</span><br />'.
803: '<label>'.
804: '<input type="checkbox" name="parserflag" checked="checked" />'.
805: $lt{'parse'}.
806: '</label>'.
807: '</fieldset></div>'.
808: '<div id="templatebox" class="LC_left_float" style="display: '.
809: $display{'templatebox'}.';"><fieldset><legend>'.$lt{'templateboxes'}.
810: ' <input type="button" value="'.&mt('check all').'" '.
811: 'onclick="javascript:checkAll('."document.syllabus.showfield".');javascript:toggleBox('."'all'".');" />'.
812: (' 'x2).
813: '<input type="button" value="'.&mt('uncheck all').'" '.
814: 'onclick="javascript:uncheckAll('."document.syllabus.showfield".');javascript:toggleBox('."'all'".');" />'.
815: '</legend>'.
816: &fields_check_uncheck($fields,$values).
1.121 raeburn 817: '</fieldset><br />'.
818: '<input type="submit" name="storesyl" value="'.&mt('Save All').'" />'.
1.117 raeburn 819: '</div>';
1.121 raeburn 820: $output .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.117 raeburn 821: return $output;
822: }
823:
1.122 raeburn 824: sub syllabus_file_info {
825: my ($item,$cnum,$cdom,$lonhost,$context) = @_;
826: my $protocol = $Apache::lonnet::protocol{$lonhost};
827: $protocol = 'http' if ($protocol ne 'https');
828: my $absurl = $protocol.'://'.&Apache::lonnet::hostname($lonhost).$item;
829: my ($filename) = ($item =~ m{([^/]+)$});
830: my $file=&Apache::lonnet::filelocation("",$item);
1.125 raeburn 831: my ($depbutton,$filetype,$editable);
832: if ($file =~ /\.(xhtml|xml|tex|html|htm)$/) {
833: $filetype=$1;
834: }
835: if ($filetype) {
836: unless ($filetype eq 'tex') {
837: $filetype='html';
838: }
839: }
840: if ($filetype eq 'html') {
1.122 raeburn 841: my $filecontents=&Apache::lonnet::getfile($file);
842: unless ($filecontents eq -1) {
843: my $mm = new File::MMagic;
844: my $mimetype = $mm->checktype_contents($filecontents);
845: if ($mimetype eq 'text/html') {
846: my (%codebase,%allfiles);
847: my $parse_result = &Apache::lonnet::extract_embedded_items($item,\%allfiles,
848: \%codebase,\$filecontents);
849: my $actionurl = "/public/$cdom/$cnum/syllabus";
850: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
851: &Apache::loncommon::ask_for_embedded_content($actionurl,undef,\%allfiles,
852: \%codebase,
853: {'context' => 'rewrites',
854: 'ignore_remote_references' => 1,});
1.125 raeburn 855: $editable = 1;
1.122 raeburn 856: }
857: }
858: }
1.125 raeburn 859: $depbutton = (' ' x 3).
860: &editfile_button($item,$context,$editable).
861: &editbutton_js();
1.122 raeburn 862: return ($absurl,$filename,$depbutton);
863: }
864:
1.117 raeburn 865: sub fields_check_uncheck {
866: my ($fields,$values) = @_;
867: return unless ((ref($fields) eq 'HASH') && (ref($values) eq 'HASH'));
868: my $numinrow = 4;
869: my $table;
870: my @fieldnames = sort(keys(%{$fields}));
1.121 raeburn 871: unshift(@fieldnames,'000_showpeople','111_showrssfeeds');
1.117 raeburn 872: my $numfields = scalar(@fieldnames);
1.121 raeburn 873: my %included;
874: if (($values->{'uploaded.fields'}) && ($values->{'uploaded.fields'} ne 'none')) {
875: map { $included{$_} = 1; } split(/,/,$values->{'uploaded.fields'});
876: }
1.117 raeburn 877: for (my $i=0; $i<$numfields; $i++) {
1.121 raeburn 878: my ($name,$checked);
879: if ($fieldnames[$i] eq '000_showpeople') {
880: $name = &mt('Personnel');
881: } elsif ($fieldnames[$i] eq '111_showrssfeeds') {
1.117 raeburn 882: $name = &mt('RSS Feeds and Blogs');
1.121 raeburn 883: } else {
884: $name = $fields->{$fieldnames[$i]};
885: }
886: if ($values->{'uploaded.fields'}) {
887: unless ($values->{'uploaded.fields'} eq 'none') {
888: my ($prefix) = split(/_/,$fieldnames[$i]);
889: if ($included{$prefix}) {
890: $checked = ' checked="checked"';
891: }
892: }
893: } else {
894: if ($fieldnames[$i] eq '000_showpeople') {
895: $checked = ' checked="checked"';
896: } elsif ($fieldnames[$i] eq '111_showrssfeeds') {
1.117 raeburn 897: $checked = ' checked="checked"';
1.121 raeburn 898: } else {
899: if ($values->{$fieldnames[$i]} ne '') {
900: $checked = ' checked="checked"';
901: }
1.117 raeburn 902: }
903: }
904: my $rem = $i%($numinrow);
905: if ($rem == 0) {
1.121 raeburn 906: if (($i > 0) && ($i < $numfields)) {
1.117 raeburn 907: $table .= '</tr>';
908: }
1.121 raeburn 909: if ($i < $numfields) {
1.117 raeburn 910: $table .= '<tr>';
911: }
912: }
1.121 raeburn 913: if ($i == $numfields-1) {
914: my $rem = $numfields%($numinrow);
915: my $colsleft = $numinrow - $rem;
916: if ($colsleft > 1) {
917: $table .= '<td colspan="'.$colsleft.'">';
918: } else {
919: $table .= '</td>';
920: }
921: } else {
922: $table .= '<td>';
923: }
1.117 raeburn 924: $table .=
1.121 raeburn 925: '<label><input type="checkbox" name="showfield" value="'.$fieldnames[$i].'" '.
1.117 raeburn 926: $checked.' id="showfield_'.$i.'" onclick="javascript:toggleBox('."'$fieldnames[$i]',this".');" />'.
927: $name.'</label></td>'."\n";
928: }
929: if ($table ne '') {
930: my $rem = $numfields%($numinrow);
931: my $colsleft = $numinrow - $rem;
932: if ($colsleft > 1 ) {
933: $table .= '<td colspan="'.$colsleft.'"> </td>';
934: } elsif ($colsleft == 1) {
935: $table .= '<td> </td>';
936: }
937: $table = '<table>'.$table.'</tr></table>';
938: }
939: return $table;
940: }
941:
1.121 raeburn 942: sub get_personnel {
943: my ($r,$target,$cdom,$cnum,$allowed) = @_;
944: my $output;
945: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
946: if ($target ne 'tex') {
947: $r->print(&Apache::lonhtmlcommon::start_pick_box());
948: } else {
949: $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
950: }
951: my @personnel=sort(keys(%coursepersonnel));
952: my $lastpers=$personnel[$#personnel];
953: foreach my $element (@personnel) {
954: if ($target ne 'tex') {
955: $r->print(&Apache::lonhtmlcommon::row_title($element));
956: } else {
957: $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & ');
958: }
959: my @coursepersonlist;
960: foreach my $user (split(/\,/,$coursepersonnel{$element})) {
961: my ($puname,$pudom)=split(/\:/,$user);
962: if ($target ne 'tex') {
963: my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
964: if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
965: ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
966: push(@coursepersonlist,$courseperson);
967: } else {
968: push(@coursepersonlist,&Apache::loncommon::aboutmewrapper($courseperson,
969: $puname,$pudom));
970: }
971: } else {
972: push(@coursepersonlist,&Apache::loncommon::plainname($puname,
973: $pudom).' ');
974: }
975: }
976: $r->print(join(", ",@coursepersonlist));
977: if ($target ne 'tex') {
978: my $lastclose=$element eq $lastpers?1:0;
979: $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
980: } else {
981: $r->print('\\\\ \hline');
982: }
983: }
984: if ($target ne 'tex') {
985: $r->print(&Apache::lonhtmlcommon::end_pick_box());
986: } else {
987: $r->print('\end{tabular}\\\\');
988: }
989: return;
990: }
991:
992: sub save_changes {
1.122 raeburn 993: my ($cnum,$cdom,$uploaded,$external,$minimal,$syllabus,$syllabusfields,$courseenv) = @_;
1.121 raeburn 994: my ($earlyout,$output);
995: unless ((ref($syllabus) eq 'HASH') && (ref($syllabusfields) eq 'HASH')) {
1.122 raeburn 996: return ($earlyout,$uploaded,$external,$minimal,$output);
1.121 raeburn 997: }
1.122 raeburn 998: if ($env{'form.deleteuploaded'}) {
999: my %storehash;
1000: if (($env{'form.choice'} eq 'file') &&
1001: ($env{'form.deleteuploaded'} eq 'file') && ($uploaded =~ /\w/)) {
1002: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus');
1003: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus');
1004: $storehash{'uploadedsyllabus'} = '';
1005: $storehash{'externalsyllabus'} = '';
1006: my $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
1007: undef($uploaded);
1008: undef($external);
1009: } elsif (($env{'form.choice'} eq 'minimal') &&
1010: ($env{'form.deleteuploaded'} eq 'minimal') && ($minimal =~ /\w/)) {
1011: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus');
1012: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.minimalsyllabus');
1013: $storehash{'externalsyllabus'} = '';
1014: $storehash{'minimalsyllabus'} = '';
1015: my $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
1016: undef($external);
1017: undef($minimal);
1018: }
1019: } elsif ($env{'form.choice'} eq 'template') {
1.121 raeburn 1020: #store what the user typed in to the template
1021: my @shown = &Apache::loncommon::get_env_multiple('form.showfield');
1022: $syllabus->{'uploaded.fields'} = '';
1023: if (@shown == 0) {
1024: $syllabus->{'uploaded.fields'} = 'none';
1025: } else {
1026: foreach my $field (sort(@shown)) {
1027: if (($field eq '000_showpeople') ||
1028: ($field eq '111_showrssfeeds') ||
1029: ($syllabusfields->{$field})) {
1030: my ($prefix) = split(/_/,$field);
1031: $syllabus->{'uploaded.fields'} .= $prefix.',';
1032: }
1033: }
1034: $syllabus->{'uploaded.fields'} =~ s/,$//;
1035: }
1036: foreach my $syl_field (keys(%{$syllabusfields})) {
1037: my $field=$env{'form.'.$syl_field};
1038: chomp($field);
1039: $field=~s/\s+$//s;
1040: $field=~s/^\s+//s;
1041: $field=~s/\<br\s*\/*\>$//s;
1042: $field=&Apache::lonfeedback::clear_out_html($field,1);
1043: #here it will be stored
1044: $syllabus->{$syl_field}=$field;
1045: if ($syl_field eq 'lll_includeurl') { # clean up included URLs
1046: my $field='';
1047: foreach my $value (split(/\n/,$syllabus->{$syl_field})) {
1048: my $url=$value;
1049: # get rid of leading and trailing spaces
1050: $url=~s/^\s+//;
1051: $url=~s/\s+$//;
1052: if ($url=~m|^https?\://([^/]+)/(.+)$|) {
1053: my $host = $1;
1054: my $remainder=$2;
1055: # remove the hostname from internal URLs
1056: my $hostname = &Apache::lonnet::hostname($host);
1057: my %all_hostnames = &Apache::lonnet::all_hostnames();
1058: foreach my $possible_host (keys(%all_hostnames)) {
1059: if ($possible_host =~ /\Q$hostname\E/i) {
1060: $url=$remainder;
1061: }
1062: }
1063: }
1064: # norm internal URLs
1065: unless ($url=~/^https?\:/) {
1066: $url=&Apache::lonnet::clutter($url);
1067: }
1068: # re-assemble field
1069: if ($url) {
1070: $field.=$url."\n";
1071: }
1072: }
1073: $syllabus->{$syl_field}=$field;
1074: }
1075: }
1076: my $now = time;
1077: $syllabus->{'uploaded.domain'}=$env{'user.domain'};
1078: $syllabus->{'uploaded.name'}=$env{'user.name'};
1079: $syllabus->{'uploaded.lastmodified'} = $now;
1080: my $putres = &Apache::lonnet::put('syllabus',$syllabus,$cdom,$cnum);
1081: if ($putres eq 'ok') {
1.123 raeburn 1082: ($uploaded,$minimal,$external) =
1083: &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
1084: $minimal,$external);
1.121 raeburn 1085: $output = '<div>'.
1086: &Apache::lonhtmlcommon::confirm_success(&mt('Template saved.')).
1087: '</div>';
1088: } else {
1089: $output = '<div class="LC_error">'.
1090: &mt('An error occurred storing the template: [_1]',$putres).
1091: '</div>';
1092: }
1093: } elsif ($env{'form.choice'} eq 'url') {
1094: if ($env{'form.externalsyllabus'} =~ m{^https?://}) {
1095: if ($env{'form.externalsyllabus'} eq $external) {
1096: $output = '<div class="LC_info">'.
1097: &mt('External URL unchanged.').
1098: '</div>';
1.123 raeburn 1099: ($uploaded,$minimal,$external) =
1100: &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
1101: $minimal,$external);
1.121 raeburn 1102: } else {
1103: $external=$env{'form.externalsyllabus'};
1104: $external =~ s/(`)//g;
1105: my $putres =
1106: &Apache::lonnet::put('environment',{externalsyllabus=>$external},
1107: $cdom,$cnum);
1108: if ($putres eq 'ok') {
1109: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.externalsyllabus' => $external});
1110: $output = '<div>'.
1111: &Apache::lonhtmlcommon::confirm_success(&mt('External URL saved.')).
1112: '</div>';
1.123 raeburn 1113: ($uploaded,$minimal,$external) =
1114: &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
1115: $minimal,$external);
1.121 raeburn 1116: } else {
1117: $output = '<div class="LC_error">'.
1118: &mt('An error occurred storing the external URL: [_1]',$putres).
1119: '</div>';
1120: }
1121: }
1122: } else {
1123: $output = '<div class="LC_error">'.
1124: &mt('External URL not saved -- invalid URL.').
1125: '</div>';
1126: }
1.122 raeburn 1127: } elsif (($env{'form.choice'} eq 'file') || ($env{'form.choice'} eq 'minimal')) {
1.121 raeburn 1128: # Process file upload - phase one - upload and parse primary file.
1.122 raeburn 1129: my ($upload_result,$uploadphase,$url,$needlink,$error,$errormsg);
1130: if ($env{'form.choice'} eq 'file') {
1131: if ($env{'form.syllabusfile.filename'}) {
1132: my %allfiles = ();
1133: my %codebase = ();
1134: ($url,$needlink) = &process_upload(\$output,$cnum,$cdom,
1135: \%allfiles,\%codebase);
1136: } else {
1137: $output = '<div class="LC_info">';
1138: &mt('No file uploaded').
1139: '</div>';
1140: }
1141: } elsif ($env{'form.choice'} eq 'minimal') {
1142: my $title = $env{'form.syllabustitle'};
1143: $title =~ s{`}{}g;
1144: $title=~s/^\s+//;
1145: $title=~s/\s+$//;
1146: if ($title eq '') {
1147: $title = &mt('Syllabus');
1148: }
1149: my $initialtext = &mt('Replace with your own content.');
1150: my $newhtml = <<END;
1151: <html>
1152: <head>
1153: <title>$title</title>
1154: </head>
1155: <body bgcolor="#ffffff">
1156: <h2>$title</h2>
1157: $initialtext
1158: </body>
1159: </html>
1160: END
1161: $env{'form.output'}=$newhtml;
1162: $url =
1163: &Apache::lonnet::finishuserfileupload($cnum,$cdom,'output',
1164: 'portfolio/syllabus/loncapa.html');
1165: }
1166: if ($url =~ m{^/uploaded/\Q$cdom\E/\Q$cnum\E.*/[^/]+$}) {
1.123 raeburn 1167: my $exturl = &home_http_host($cdom,$cnum);
1168: if ($exturl) {
1169: $exturl .= $url;
1.122 raeburn 1170: }
1171: my %storehash;
1172: if ($env{'form.choice'} eq 'minimal') {
1173: $storehash{'minimalsyllabus'} = $url;
1174: } else {
1175: $storehash{'uploadedsyllabus'} = $url;
1176: }
1177: if ($exturl) {
1178: $storehash{'externalsyllabus'} = $exturl;
1179: if ($exturl =~ /\.(html?|txt|js|css)$/) {
1180: $exturl .= '?inhibitmenu=yes';
1181: }
1182: } else {
1183: $storehash{'externalsyllabus'} = '',
1184: }
1185: my $putres =
1186: &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
1187: if ($putres eq 'ok') {
1188: &Apache::lonnet::make_public_indefinitely($url);
1189: foreach my $key (keys(%storehash)) {
1190: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash{$key}});
1191: }
1192: if ($env{'form.choice'} eq 'minimal') {
1193: $minimal = $url;
1.121 raeburn 1194: } else {
1.122 raeburn 1195: $uploaded = $url;
1.121 raeburn 1196: }
1.122 raeburn 1197: if ($needlink) {
1198: $output .= &return_to_editor($cdom,$cnum);
1199: $earlyout = 1;
1.121 raeburn 1200: }
1.123 raeburn 1201: ($uploaded,$minimal,$external) =
1202: &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
1203: $minimal,$external);
1.122 raeburn 1204: } else {
1205: $error = 1;
1206: $errormsg = $putres;
1207: }
1208: } else {
1209: $error = 1;
1210: }
1211: if ($error) {
1212: $output = '<div class="LC_error">';
1213: if ($env{'form.choice'} eq 'minimal') {
1214: $output = &mt('An error occurred creating the minimal template file [_1]',$errormsg);
1215: } else {
1216: $output = &mt('An error occurred storing the uploaded file [_1]',$errormsg);
1.121 raeburn 1217: }
1.122 raeburn 1218: $output .= '</div>';
1.121 raeburn 1219: }
1220: } elsif ($env{'form.phase'} eq 'upload_embedded') {
1221: # Process file upload - phase two - upload embedded objects
1222: my $uploadphase = 'check_embedded';
1223: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
1224: my $state = &embedded_form_elems($uploadphase,$primaryurl);
1225: my $url_root = '/uploaded/'.$cdom.'/'.$cnum;
1226: my $actionurl = "/public/$cdom/$cnum/syllabus";
1227: my ($result,$flag,$numpathchgs) =
1228: &Apache::loncommon::upload_embedded('syllabus','portfolio/syllabus',
1229: $cnum,$cdom,'/userfiles',$url_root,undef,undef,undef,$state,
1230: $actionurl);
1231: unless ($numpathchgs) {
1232: my $modres =
1233: &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
1234: $cnum,$cdom,
1235: '/userfiles',$env{'form.primaryurl'});
1236: $result .= $modres;
1237: }
1.122 raeburn 1238: $output = $result.&return_to_editor($cdom,$cnum);
1.121 raeburn 1239: $earlyout = 1;
1240: } elsif ($env{'form.phase'} eq 'check_embedded') {
1241: # Process file upload - phase three - modify references in HTML file
1242: my $uploadphase = 'modified_orightml';
1243: my $result =
1244: &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
1245: $cnum,$cdom,
1246: '/userfiles',$env{'form.primaryurl'});
1.122 raeburn 1247: $output = $result.&return_to_editor($cdom,$cnum);
1.121 raeburn 1248: $earlyout = 1;
1249: }
1.122 raeburn 1250: return ($earlyout,$uploaded,$external,$minimal,$output);
1.121 raeburn 1251: }
1252:
1.123 raeburn 1253: sub update_syllabus_env {
1.124 raeburn 1254: my ($cdom,$cnum,$courseenv,$saved,$uploaded,$minimal,$external) = @_;
1.125 raeburn 1255: return ($uploaded,$minimal,$external) unless(ref($courseenv) eq 'HASH');
1.123 raeburn 1256: my $now = time;
1257: my (@envkeys,%storehash);
1258: if ($saved eq 'template') {
1259: if ($uploaded) {
1260: push(@envkeys,'uploaded');
1261: }
1262: if ($minimal) {
1263: push(@envkeys,'minimal');
1264: }
1265: if ($external) {
1266: push(@envkeys,'external');
1267: }
1268: $storehash{'updatedsyllabus'} = $now;
1269: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.updatedsyllabus' => $now
1270: });
1271:
1272: } elsif ($saved eq 'url') {
1273: my $prefix = &home_http_host($cdom,$cnum);
1274: if ($external =~ m{^\Q$prefix/uploaded/$cdom/$cnum/portfolio/syllabus/\E(.+)$}) {
1275: my $file = $1;
1276: if ($file eq 'loncapa.html') {
1277: if ($uploaded) {
1278: push(@envkeys,'uploaded');
1279: }
1280: } elsif ($minimal) {
1281: push(@envkeys,'minimal');
1282: }
1283: } else {
1284: if ($uploaded) {
1285: push(@envkeys,'uploaded');
1286: }
1287: if ($minimal) {
1288: push(@envkeys,'minimal');
1289: }
1290: }
1291: } elsif ($saved eq 'file') {
1292: if ($minimal) {
1293: push(@envkeys,'minimal');
1294: }
1295: } elsif ($saved eq 'minimal') {
1296: if ($uploaded) {
1297: push(@envkeys,'uploaded');
1298: }
1299: }
1300: if (@envkeys > 0) {
1301: foreach my $item (@envkeys) {
1302: my $key = $item.'syllabus';
1303: if ($courseenv->{$key}) {
1304: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
1305: $storehash{$key} = '';
1306: }
1307: if ($item eq 'uploaded') {
1308: undef($uploaded);
1309: }
1310: if ($item eq 'external') {
1311: undef($external);
1312: }
1313: if ($item eq 'minimal') {
1314: undef($minimal);
1315: }
1316: }
1317: }
1318: if (keys(%storehash) > 0) {
1319: &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
1320: }
1321: return ($uploaded,$minimal,$external);
1322: }
1323:
1324: sub home_http_host {
1325: my ($cdom,$cnum) = @_;
1326: my $home=&Apache::lonnet::homeserver($cnum,$cdom);
1327: if ($home ne 'no_host') {
1328: my $protocol = $Apache::lonnet::protocol{$home};
1329: $protocol = 'http' if ($protocol ne 'https');
1.125 raeburn 1330: return $protocol.'://'.$home;
1.123 raeburn 1331: }
1332: return;
1333: }
1334:
1.117 raeburn 1335: sub process_upload {
1336: my ($upload_output,$cnum,$cdom,$allfiles,$codebase) = @_;
1337: my ($parseaction,$showupload,$mimetype);
1338: my $dest = 'portfolio/syllabus';
1339: if ($env{'form.parserflag'}) {
1340: $parseaction = 'parse';
1341: }
1342: my $url=&Apache::lonnet::userfileupload('syllabusfile','syllabus',$dest,
1343: $parseaction,$allfiles,
1344: $codebase,undef,undef,undef,undef,
1345: undef,undef,\$mimetype);
1346: if ($url =~ m{^/uploaded/\Q$cdom\E/\Q$cnum\E.*/([^/]+)$}) {
1347: my $stored = $1;
1348: $showupload = '<p>'.&mt('Uploaded [_1]',
1349: '<span class="LC_filename">'.$stored.'</span>').
1350: '</p>';
1351: } else {
1352: my ($filename) = ($env{'form.syllabusfile.filename'} =~ m{([^/]+)$});
1353: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.
1354: &mt('Unable to save file [_1].',
1355: '<span class="LC_filename">'.$filename.'</span>').
1356: '</div>';
1357: return ();
1358: }
1359: my $needlink;
1360: if (($parseaction eq 'parse') && ($mimetype eq 'text/html')) {
1361: $$upload_output = $showupload;
1362: my $total_embedded = scalar(keys(%{$allfiles}));
1363: if ($total_embedded > 0) {
1364: my $uploadphase = 'upload_embedded';
1365: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
1366: my $state = &embedded_form_elems($uploadphase,$primaryurl);
1367: my $actionurl = "/public/$cdom/$cnum/syllabus";
1368: my ($embedded,$num,$numpathchanges,$existing);
1369: ($embedded,$num,$numpathchanges,$existing) =
1370: &Apache::loncommon::ask_for_embedded_content($actionurl,$state,
1371: $allfiles,$codebase,
1372: {'error_on_invalid_names' => 1,
1373: 'ignore_remote_references' => 1,});
1374: if ($embedded) {
1375: $needlink = 1;
1376: if ($num) {
1377: $$upload_output .=
1378: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
1379: } elsif ($numpathchanges) {
1380: $$upload_output .= $embedded;
1381: } else {
1382: $$upload_output .= $embedded;
1383: &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
1384: $cnum,$cdom,'/userfiles',$url);
1385: }
1386: } else {
1387: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
1388: &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
1389: $cnum,$cdom,'/userfiles',$url);
1390:
1391: }
1392: } else {
1393: $$upload_output .= &mt('No embedded items identified').'<br />';
1394: }
1395: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1396: }
1397: return ($url,$needlink);
1398: }
1399:
1400: sub embedded_form_elems {
1401: my ($phase,$primaryurl) = @_;
1402: return <<STATE;
1403: <input type="hidden" name="forceedit" value="1" />
1404: <input type="hidden" name="cmd" value="upload_embedded" />
1405: <input type="hidden" name="phase" value="$phase" />
1406: <input type="hidden" name="primaryurl" value="$primaryurl" />
1407: STATE
1408: }
1409:
1410: sub return_to_editor {
1411: my ($cdom,$cnum) = @_;
1412: my $actionurl = "/public/$cdom/$cnum/syllabus";
1413: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'.
1414: '<input type="hidden" name="forceedit" value="1" />'."\n".
1415: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
1416: '</a></p>';
1417: }
1418:
1.118 raeburn 1419: sub editfile_button {
1.125 raeburn 1420: my ($url,$context,$editable) = @_;
1.122 raeburn 1421: my $edittext=&mt('Edit');
1422: my $deltext=&mt('Delete');
1.125 raeburn 1423: my $output;
1424: if ($editable) {
1425: $output = '
1426: <input type="button" value="'.$edittext.'" onclick="javascript:gotoeditor('."'$url'".');" name="edit_'.$context.'" />
1427: ';
1428: }
1429: $output .= '
1430: <input type="button" value="'.$deltext.'" onclick="javascript:dodelete('."'$context'".');" name="del_'.$context.'" />
1.122 raeburn 1431: <input type="hidden" value="" name="deleteuploaded" />
1.125 raeburn 1432: ';
1433: return $output;
1.118 raeburn 1434: }
1435:
1436: sub editbutton_js {
1.126 ! raeburn 1437: my %lt = &Apache::lonlocal::texthash(
! 1438: min => 'Are you sure you want to delete the contents of the syllabus template?',
! 1439: file => 'Are you sure you want to delete the uploaded syllabus file?',
! 1440: noundo => 'This action cannot be reversed.'
! 1441: );
1.118 raeburn 1442: return <<ENDJS;
1443: <script type="text/javascript">
1444: // <![CDATA[
1.122 raeburn 1445: function gotoeditor(url) {
1446: document.location.href = url+'?editmode=1&forceedit=1';
1447: }
1448: function dodelete(caller,url) {
1449: document.syllabus.deleteuploaded.value=caller;
1.126 ! raeburn 1450: if (caller == 'minimal') {
! 1451: if (confirm("$lt{'min'}"+"\\n"+"$lt{'noundo'}")) {
! 1452: document.syllabus.submit();
! 1453: }
! 1454: }
! 1455: if (caller == 'file') {
! 1456: if (confirm("$lt{'file'}"+"\\n"+"$lt{'noundo'}")) {
! 1457: document.syllabus.submit();
! 1458: }
! 1459: }
! 1460: return;
1.118 raeburn 1461: }
1462: // ]]>
1463: </script>
1464: ENDJS
1465: }
1466:
1.1 www 1467: 1;
1468: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>