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