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