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