Annotation of loncom/interface/lonsyllabus.pm, revision 1.138.2.2
1.1 www 1: # The LearningOnline Network
2: # Syllabus
3: #
1.138.2.2! raeburn 4: # $Id: lonsyllabus.pm,v 1.138.2.1 2016/08/05 20:56:42 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.137 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.137 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:
630: function extUrlPreview(caller) {
631: if (document.getElementById(caller)) {
632: var url = document.getElementById(caller).value;
633: if (regexp.test(url)) {
634: openMyModal(url,500,400,'yes');
635: } else {
636: alert("$invurl");
637: }
638: }
639: }
640:
641: function toggleBox(name,caller) {
642: if (name == 'all') {
643: if (document.syllabus.showfield.length > 0) {
644: for (var i=0; i<document.syllabus.showfield.length; i++) {
645: if (document.syllabus.showfield[i].checked) {
646: if (document.getElementById('box_'+document.syllabus.showfield[i].value)) {
647: document.getElementById('box_'+document.syllabus.showfield[i].value).style.display='block';
648: }
649: } else {
650: if (document.getElementById('box_'+document.syllabus.showfield[i].value)) {
651: document.getElementById('box_'+document.syllabus.showfield[i].value).style.display='none';
652: }
653: }
654: }
655: }
656: } else {
657: if (caller.checked) {
658: if (document.getElementById('box_'+caller.value)) {
659: document.getElementById('box_'+caller.value).style.display='block';
660: }
661: } else {
662: if (document.getElementById('box_'+caller.value)) {
663: document.getElementById('box_'+caller.value).style.display='none';
664: }
665: }
666: }
667: return;
668: }
669:
670: function setTemplateBoxes() {
671: $fieldstr
672: $checkedstr
673: $uncheckedstr
674: if (include.length > 0) {
675: for (var i=0; i<include.length; i++) {
676: if (document.getElementById('showfield_'+include[i])) {
677: document.getElementById('showfield_'+include[i]).checked = true;
678: if (document.getElementById('box_'+fields[include[i]])) {
679: document.getElementById('box_'+fields[include[i]]).style.display='block';
680: }
681: }
682: }
683: }
684: if (exclude.length > 0) {
685: for (var i=0; i<exclude.length; i++) {
686: if (document.getElementById('showfield_'+exclude[i])) {
687: document.getElementById('showfield_'+exclude[i]).checked = false;
688: if (document.getElementById('box_'+fields[exclude[i]])) {
689: document.getElementById('box_'+fields[exclude[i]]).style.display='none';
690: }
691: }
692: }
693: }
694: return;
695: }
696:
697: $check_uncheck
698:
699: // ]]>
700: </script>
701:
702: ENDSCRIPT
703: }
704: my $args = {'function' => undef,
705: 'domain' => $cdom};
706: my $forcereg;
707: if ($env{'form.register'}) {
708: $forcereg = 1;
709: $args->{'force_register'} = $forcereg;
710: }
711: if ($env{'form.backto'} eq 'coursecatalog') {
712: &Apache::lonhtmlcommon::clear_breadcrumbs();
713: my $brcrum = [{href=>"javascript:ToCatalog();",
714: text=>&mt('Course/Community Catalog'),
715: no_mt=>1}
716: ];
717: if ($env{'form.coursenum'} ne '') {
718: push(@{$brcrum},
719: {href=>"javascript:ToCatalog('details')",
720: text=>"Course details"});
721: }
722: push(@{$brcrum},
723: {href=>$r->uri,
724: text=>"Course syllabus"});
725: $args->{'bread_crumbs'} = $brcrum;
1.125 raeburn 726: } else {
727: &get_breadcrumbs($cdom,$cnum,$crstype,$args);
728: }
729: if ($allowed) {
730: my %loaditem = (
731: onload => 'setTemplateBoxes();',
732: );
733: $args->{'add_entries'} = \%loaditem;
1.137 raeburn 734: } else {
735: if ($env{'request.use_absolute'}) {
736: $args->{'use_absolute'} = $env{'request.use_absolute'};
737: }
1.125 raeburn 738: }
1.132 raeburn 739: if ($env{'form.only_body'}) {
740: $args->{'only_body'} = 1;
741: }
1.125 raeburn 742: my $start_page =
743: &Apache::loncommon::start_page("Syllabus", $rss_link.$js,$args);
744: if ($start_page) {
745: $r->print($start_page);
746: }
747: }
748:
749: sub get_breadcrumbs{
750: my ($cdom,$cnum,$crstype,$args) = @_;
751: return unless (ref($args) eq 'HASH');
752: if ($env{'form.folderpath'} =~ /^supplemental/) {
1.121 raeburn 753: my $title = $env{'form.title'};
754: if ($title eq '') {
755: $title = &mt('Syllabus');
756: }
757: my $brcrum =
758: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
759: if (ref($brcrum) eq 'ARRAY') {
760: $args->{'bread_crumbs'} = $brcrum;
761: }
762: } else {
763: if ((&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus"))
764: && (($env{'form.symb'}) || ($env{'form.register'}))) {
765: &Apache::lonhtmlcommon::clear_breadcrumbs();
766: } else {
767: $args->{'bread_crumbs'} = [
768: {'href' => "/public/$cdom/$cnum/syllabus",
769: 'text' => 'Syllabus'},
770: ];
771: }
772: }
1.125 raeburn 773: return;
1.121 raeburn 774: }
775:
1.117 raeburn 776: sub chooser {
1.122 raeburn 777: my ($external,$uploaded,$minimal,$cdom,$cnum,$lonhost,$fields,$values) = @_;
1.117 raeburn 778: my %lt = &Apache::lonlocal::texthash(
779: 'type' => 'Syllabus Type',
780: 'url' => 'External URL',
1.122 raeburn 781: 'file' => 'Uploaded file',
782: 'minimal' => 'Minimal template',
783: 'template' => 'Standard template',
1.117 raeburn 784: 'templateboxes' => 'Choose template items ... ',
785: 'curr' => 'Current:',
786: 'rep' => 'Replace:',
787: 'upl' => 'Upload:',
788: 'pr' => 'Preview',
789: 'save' => 'Save',
1.122 raeburn 790: 'sved' => 'Save and Edit',
791: 'chourl' => 'External URL',
1.117 raeburn 792: 'chofile' => 'Uploaded syllabus file',
793: 'parse' => 'Upload embedded images/multimedia files if HTML file',
794: );
795: my %checked = (
796: file => '',
1.122 raeburn 797: minimal => '',
1.117 raeburn 798: url => '',
799: template => '',
800: );
801: my %display = (
802: file => 'none',
1.122 raeburn 803: minimal => 'none',
1.117 raeburn 804: url => 'none',
805: templatebox => 'none',
806: );
807: my $check = ' checked="checked" ';
808: if ($uploaded) {
809: $checked{'file'} = $check;
810: $display{'file'} = 'block';
811: } elsif ($external) {
812: $checked{'url'} = $check;
813: $display{'url'} = 'block';
1.122 raeburn 814: } elsif ($minimal) {
815: $checked{'minimal'} = $check;
816: $display{'minimal'} = 'block';
1.117 raeburn 817: } else {
818: $checked{'template'} = $check;
819: $checked{'templatebox'} = $check;
820: $display{'templatebox'} = 'block';
821: }
822:
823: my $output =
824: '<form name="syllabus" method="post" enctype="multipart/form-data" action="">'."\n".
825: '<input type="hidden" name="forceedit" value="1" />'."\n".
826: '<div class="LC_left_float"><fieldset><legend>'.$lt{'type'}.'</legend>';
1.122 raeburn 827: foreach my $item ('minimal','template','url','file') {
1.117 raeburn 828: $output .= '<label><input type="radio" name="choice" value="'.$item.'" '.$checked{$item}.' onclick="toggleEditor('."'$item'".')" />'.
829: $lt{$item}.'</label><br />';
830: }
831: $output .= '</fieldset></div>'."\n".
832: '<div id="url" class="LC_left_float" style="display: '.$display{'url'}.'">'."\n".
833: '<fieldset><legend>'.$lt{'chourl'}.'</legend><span class="LC_nobreak">'."\n".
834: '<a href="javascript:extUrlPreview('."'syllabusurl'".');">'.$lt{'pr'}.'</a></span> '."\n".
835: '<input type="text" id="syllabusurl" name="externalsyllabus" value="'.$external.'" size="55" />'."\n".
836: ' <input type="submit" name="storeurl" value="'.$lt{'save'}.'" />'."\n".
837: '</fieldset></div>'."\n".
1.122 raeburn 838: '<div id="minimal" class="LC_left_float" style="display: '.$display{'minimal'}.'">'."\n".
839: '<fieldset><legend>'.$lt{'minimal'}.'</legend>';
840: if ($minimal) {
841: my ($absurl,$filename,$depbutton) = &syllabus_file_info($minimal,$cnum,$cdom,$lonhost,'minimal');
842: $output .= '<a href="javascript:extUrlPreview('."'currminimal'".');">'.$lt{'pr'}.'</a>'.
843: '<input type="hidden" name="minimalfile" value="'.&HTML::Entities::encode($absurl).'?inhibitmenu=yes" id="currminimal" />'.
844: $depbutton;
845: } else {
846: $output .= &mt('Title of Syllabus Page:').' '.
847: '<input type="text" id="minimaltitle" name="syllabustitle" value="'.&mt('Syllabus').'" size="30" />'."\n".
848: ' <input type="submit" name="storeminimal" value="'.$lt{'sved'}.'" />'."\n";
849: }
850: $output .= '</fieldset></div>'."\n".
851: '<div id="file" class="LC_left_float" style="display: '.$display{'file'}.'">'."\n".
852: '<fieldset><legend>'.$lt{'file'}.'</legend>';
1.117 raeburn 853: if ($uploaded) {
1.122 raeburn 854: my ($absurl,$filename,$depbutton) = &syllabus_file_info($uploaded,$cnum,$cdom,$lonhost,'file');
1.117 raeburn 855: $output .= '<span class="LC_nobreak">'.$lt{'curr'}.' '.
856: '<input type="hidden" name="uploadedfile" value="'.&HTML::Entities::encode($absurl).'?inhibitmenu=yes" id="currfile" />'.
1.118 raeburn 857: '<a href="javascript:extUrlPreview('."'currfile'".');">'.$filename.'</a></span>'.$depbutton.
858: '<br /><br />'.$lt{'rep'};
1.117 raeburn 859: } else {
860: $output .= $lt{'upl'};
861: }
862: $output .= '<br />'."\n".
863: '<span class="LC_nobreak">'.
864: '<input type="file" name="syllabusfile" size="55" />'."\n".
865: ' <input type="submit" name="storefile" value="'.$lt{'save'}.'" />'.
866: '</span><br />'.
867: '<label>'.
868: '<input type="checkbox" name="parserflag" checked="checked" />'.
869: $lt{'parse'}.
870: '</label>'.
871: '</fieldset></div>'.
872: '<div id="templatebox" class="LC_left_float" style="display: '.
873: $display{'templatebox'}.';"><fieldset><legend>'.$lt{'templateboxes'}.
874: ' <input type="button" value="'.&mt('check all').'" '.
875: 'onclick="javascript:checkAll('."document.syllabus.showfield".');javascript:toggleBox('."'all'".');" />'.
876: (' 'x2).
877: '<input type="button" value="'.&mt('uncheck all').'" '.
878: 'onclick="javascript:uncheckAll('."document.syllabus.showfield".');javascript:toggleBox('."'all'".');" />'.
879: '</legend>'.
880: &fields_check_uncheck($fields,$values).
1.121 raeburn 881: '</fieldset><br />'.
882: '<input type="submit" name="storesyl" value="'.&mt('Save All').'" />'.
1.117 raeburn 883: '</div>';
1.121 raeburn 884: $output .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.117 raeburn 885: return $output;
886: }
887:
1.122 raeburn 888: sub syllabus_file_info {
889: my ($item,$cnum,$cdom,$lonhost,$context) = @_;
890: my $protocol = $Apache::lonnet::protocol{$lonhost};
891: $protocol = 'http' if ($protocol ne 'https');
892: my $absurl = $protocol.'://'.&Apache::lonnet::hostname($lonhost).$item;
893: my ($filename) = ($item =~ m{([^/]+)$});
894: my $file=&Apache::lonnet::filelocation("",$item);
1.125 raeburn 895: my ($depbutton,$filetype,$editable);
896: if ($file =~ /\.(xhtml|xml|tex|html|htm)$/) {
897: $filetype=$1;
898: }
899: if ($filetype) {
900: unless ($filetype eq 'tex') {
901: $filetype='html';
902: }
903: }
904: if ($filetype eq 'html') {
1.122 raeburn 905: my $filecontents=&Apache::lonnet::getfile($file);
906: unless ($filecontents eq -1) {
907: my $mm = new File::MMagic;
908: my $mimetype = $mm->checktype_contents($filecontents);
909: if ($mimetype eq 'text/html') {
910: my (%codebase,%allfiles);
911: my $parse_result = &Apache::lonnet::extract_embedded_items($item,\%allfiles,
912: \%codebase,\$filecontents);
913: my $actionurl = "/public/$cdom/$cnum/syllabus";
914: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
915: &Apache::loncommon::ask_for_embedded_content($actionurl,undef,\%allfiles,
916: \%codebase,
917: {'context' => 'rewrites',
918: 'ignore_remote_references' => 1,});
1.125 raeburn 919: $editable = 1;
1.122 raeburn 920: }
921: }
922: }
1.125 raeburn 923: $depbutton = (' ' x 3).
924: &editfile_button($item,$context,$editable).
925: &editbutton_js();
1.122 raeburn 926: return ($absurl,$filename,$depbutton);
927: }
928:
1.117 raeburn 929: sub fields_check_uncheck {
930: my ($fields,$values) = @_;
931: return unless ((ref($fields) eq 'HASH') && (ref($values) eq 'HASH'));
932: my $numinrow = 4;
933: my $table;
934: my @fieldnames = sort(keys(%{$fields}));
1.121 raeburn 935: unshift(@fieldnames,'000_showpeople','111_showrssfeeds');
1.117 raeburn 936: my $numfields = scalar(@fieldnames);
1.121 raeburn 937: my %included;
938: if (($values->{'uploaded.fields'}) && ($values->{'uploaded.fields'} ne 'none')) {
939: map { $included{$_} = 1; } split(/,/,$values->{'uploaded.fields'});
940: }
1.117 raeburn 941: for (my $i=0; $i<$numfields; $i++) {
1.121 raeburn 942: my ($name,$checked);
943: if ($fieldnames[$i] eq '000_showpeople') {
944: $name = &mt('Personnel');
945: } elsif ($fieldnames[$i] eq '111_showrssfeeds') {
1.117 raeburn 946: $name = &mt('RSS Feeds and Blogs');
1.121 raeburn 947: } else {
948: $name = $fields->{$fieldnames[$i]};
949: }
950: if ($values->{'uploaded.fields'}) {
951: unless ($values->{'uploaded.fields'} eq 'none') {
952: my ($prefix) = split(/_/,$fieldnames[$i]);
953: if ($included{$prefix}) {
954: $checked = ' checked="checked"';
955: }
956: }
957: } else {
958: if ($fieldnames[$i] eq '000_showpeople') {
959: $checked = ' checked="checked"';
960: } elsif ($fieldnames[$i] eq '111_showrssfeeds') {
1.117 raeburn 961: $checked = ' checked="checked"';
1.121 raeburn 962: } else {
963: if ($values->{$fieldnames[$i]} ne '') {
964: $checked = ' checked="checked"';
965: }
1.117 raeburn 966: }
967: }
968: my $rem = $i%($numinrow);
969: if ($rem == 0) {
1.121 raeburn 970: if (($i > 0) && ($i < $numfields)) {
1.117 raeburn 971: $table .= '</tr>';
972: }
1.121 raeburn 973: if ($i < $numfields) {
1.117 raeburn 974: $table .= '<tr>';
975: }
976: }
1.121 raeburn 977: if ($i == $numfields-1) {
978: my $rem = $numfields%($numinrow);
979: my $colsleft = $numinrow - $rem;
980: if ($colsleft > 1) {
981: $table .= '<td colspan="'.$colsleft.'">';
982: } else {
983: $table .= '</td>';
984: }
985: } else {
986: $table .= '<td>';
987: }
1.117 raeburn 988: $table .=
1.121 raeburn 989: '<label><input type="checkbox" name="showfield" value="'.$fieldnames[$i].'" '.
1.117 raeburn 990: $checked.' id="showfield_'.$i.'" onclick="javascript:toggleBox('."'$fieldnames[$i]',this".');" />'.
991: $name.'</label></td>'."\n";
992: }
993: if ($table ne '') {
994: my $rem = $numfields%($numinrow);
995: my $colsleft = $numinrow - $rem;
996: if ($colsleft > 1 ) {
997: $table .= '<td colspan="'.$colsleft.'"> </td>';
998: } elsif ($colsleft == 1) {
999: $table .= '<td> </td>';
1000: }
1001: $table = '<table>'.$table.'</tr></table>';
1002: }
1003: return $table;
1004: }
1005:
1.121 raeburn 1006: sub get_personnel {
1.127 raeburn 1007: my ($r,$target,$cdom,$cnum,$allowed,$crstype,$syllabus) = @_;
1008: my (%hiddenroles,%hiddenusers);
1009: if (ref($syllabus) eq 'HASH') {
1010: if (ref($syllabus->{'personnel'}) eq 'HASH') {
1011: if ($syllabus->{'personnel'}{'hiderole'}) {
1012: map { $hiddenroles{$_} = 1; } split(/,/,$syllabus->{'personnel'}{'hiderole'});
1013: }
1014: if ($syllabus->{'personnel'}{'hideuser'}) {
1015: map { $hiddenusers{$_} = 1; } split(/,/,$syllabus->{'personnel'}{'hideuser'});
1016: }
1017: }
1018: }
1.121 raeburn 1019: my $output;
1.127 raeburn 1020: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum,1);
1.121 raeburn 1021: if ($target ne 'tex') {
1.127 raeburn 1022: if ($allowed) {
1023: $r->print(&Apache::loncommon::start_data_table().
1024: &Apache::loncommon::start_data_table_header_row().
1025: '<th>'.&mt('Role hidden?').'</th><th>'.&mt('Role').'</th>'.
1026: '<th>'.&mt('Personnel (hidden if checked)').'</th>'.
1027: &Apache::loncommon::end_data_table_header_row());
1028: } else {
1029: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1030: }
1.121 raeburn 1031: } else {
1032: $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
1033: }
1034: my @personnel=sort(keys(%coursepersonnel));
1035: my $lastpers=$personnel[$#personnel];
1036: foreach my $element (@personnel) {
1.127 raeburn 1037: unless ($allowed) {
1038: next if ($hiddenroles{$element})
1039: }
1040: my ($role,$sec);
1041: if ($element =~ /:/) {
1042: ($role,$sec) = split(/:/,$element);
1043: } else {
1044: $role = $element;
1045: }
1046: my $roletext = &Apache::lonnet::plaintext($role,$crstype);
1047: if ($sec) {
1048: $roletext .=' ('.&Apache::lonlocal::mt('Section [_1]',$sec).')';
1049: }
1.121 raeburn 1050: if ($target ne 'tex') {
1.127 raeburn 1051: if ($allowed) {
1052: my $checked;
1053: if ($hiddenroles{$element}) {
1054: $checked = ' checked="checked"';
1055: }
1056: $r->print(&Apache::loncommon::start_data_table_row().
1057: '<td>'.
1058: '<input type="checkbox" name="hiderole" value="'.$element.'" '.
1059: $checked.' />'.
1060: '</td><td>'.$roletext.'</td><td>');
1061: } else {
1062: $r->print(&Apache::lonhtmlcommon::row_title($roletext));
1063: }
1.121 raeburn 1064: } else {
1.127 raeburn 1065: $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$roletext).' & ');
1.121 raeburn 1066: }
1067: my @coursepersonlist;
1068: foreach my $user (split(/\,/,$coursepersonnel{$element})) {
1069: my ($puname,$pudom)=split(/\:/,$user);
1070: if ($target ne 'tex') {
1071: my $courseperson = &Apache::loncommon::plainname($puname,$pudom);
1.127 raeburn 1072: my $checked;
1073: if ($hiddenusers{$element.'&'.$puname.':'.$pudom}) {
1074: $checked = ' checked="checked"';
1075: }
1076: if ($allowed) {
1077: my $item = '<span class="LC_nobreak"><label>'.
1.129 raeburn 1078: '<input type="checkbox" name="hideuser" value="'.$element.'&'.$puname.':'.$pudom.'"'.$checked.' />'.
1.127 raeburn 1079: &Apache::loncommon::aboutmewrapper($courseperson
1080: ,
1081: $puname,$pudom).
1082: '</label>'.(' 'x2).'</span> ';
1083: push(@coursepersonlist,$item);
1084:
1.121 raeburn 1085: } else {
1.127 raeburn 1086: next if ($hiddenusers{$element.'&'.$puname.':'.$pudom});
1087: if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') ||
1088: ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) {
1089: push(@coursepersonlist,$courseperson);
1090: } else {
1091: push(@coursepersonlist,&Apache::loncommon::aboutmewrapper($courseperson,
1092: $puname,$pudom));
1093: }
1.121 raeburn 1094: }
1095: } else {
1096: push(@coursepersonlist,&Apache::loncommon::plainname($puname,
1097: $pudom).' ');
1098: }
1099: }
1.127 raeburn 1100: if ($allowed) {
1101: $r->print(join('',@coursepersonlist));
1102: } else {
1103: $r->print(join(', ',@coursepersonlist));
1104: }
1.121 raeburn 1105: if ($target ne 'tex') {
1.127 raeburn 1106: if ($allowed) {
1.129 raeburn 1107: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1.127 raeburn 1108: } else {
1109: my $lastclose=$element eq $lastpers?1:0;
1110: $r->print(&Apache::lonhtmlcommon::row_closure($lastclose));
1111: }
1.121 raeburn 1112: } else {
1113: $r->print('\\\\ \hline');
1114: }
1115: }
1116: if ($target ne 'tex') {
1.127 raeburn 1117: if ($allowed) {
1118: $r->print(&Apache::loncommon::end_data_table());
1119: } else {
1120: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1121: }
1.121 raeburn 1122: } else {
1123: $r->print('\end{tabular}\\\\');
1124: }
1125: return;
1126: }
1127:
1128: sub save_changes {
1.122 raeburn 1129: my ($cnum,$cdom,$uploaded,$external,$minimal,$syllabus,$syllabusfields,$courseenv) = @_;
1.121 raeburn 1130: my ($earlyout,$output);
1.131 raeburn 1131: unless ((ref($syllabus) eq 'HASH') && (ref($syllabusfields) eq 'HASH') ||
1132: (ref($courseenv) eq 'HASH')) {
1.122 raeburn 1133: return ($earlyout,$uploaded,$external,$minimal,$output);
1.121 raeburn 1134: }
1.128 raeburn 1135: if (($env{'form.deleteuploaded_file'}) || ($env{'form.deleteuploaded_minimal'})) {
1.122 raeburn 1136: my %storehash;
1137: if (($env{'form.choice'} eq 'file') &&
1.128 raeburn 1138: ($env{'form.deleteuploaded_file'}) && ($uploaded =~ /\w/)) {
1.131 raeburn 1139: if ($courseenv->{'uploadedsyllabus'} =~ m{^\Q/uploaded/$cdom/$cnum/portfolio\E(/syllabus/.+)$}) {
1140: my $filename = $1;
1141: &update_access_permissions($cdom,$cnum,$filename);
1142: }
1.122 raeburn 1143: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus');
1144: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus');
1145: $storehash{'uploadedsyllabus'} = '';
1146: $storehash{'externalsyllabus'} = '';
1147: my $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
1148: undef($uploaded);
1149: undef($external);
1150: } elsif (($env{'form.choice'} eq 'minimal') &&
1.128 raeburn 1151: ($env{'form.deleteuploaded_minimal'}) && ($minimal =~ /\w/)) {
1.131 raeburn 1152: my $minimalurl = "/uploaded/$cdom/$cnum/portfolio/syllabus/loncapa.html";
1153: if ($courseenv->{'minimalsyllabus'} eq "$minimalurl") {
1154: my $filecontents=&Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$minimalurl));
1155: unless ($filecontents eq -1) {
1156: $env{'form.output'} = $filecontents;
1157: &Apache::lonnet::finishuserfileupload($cnum,$cdom,'output',
1158: 'portfolio/syllabus/loncapa.html.bak');
1159: $minimalurl = &default_minimal_syllabus($cnum,$cdom);
1160: }
1161: }
1162: &update_access_permissions($cdom,$cnum,'/syllabus/loncapa.html');
1.122 raeburn 1163: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus');
1164: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.minimalsyllabus');
1165: $storehash{'externalsyllabus'} = '';
1166: $storehash{'minimalsyllabus'} = '';
1167: my $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
1168: undef($external);
1169: undef($minimal);
1170: }
1171: } elsif ($env{'form.choice'} eq 'template') {
1.121 raeburn 1172: #store what the user typed in to the template
1173: my @shown = &Apache::loncommon::get_env_multiple('form.showfield');
1174: $syllabus->{'uploaded.fields'} = '';
1175: if (@shown == 0) {
1176: $syllabus->{'uploaded.fields'} = 'none';
1177: } else {
1178: foreach my $field (sort(@shown)) {
1179: if (($field eq '000_showpeople') ||
1180: ($field eq '111_showrssfeeds') ||
1181: ($syllabusfields->{$field})) {
1182: my ($prefix) = split(/_/,$field);
1183: $syllabus->{'uploaded.fields'} .= $prefix.',';
1184: }
1.127 raeburn 1185: if ($field eq '000_showpeople') {
1186: my @hideusers = &Apache::loncommon::get_env_multiple('form.hideuser');
1187: my @hideroles = &Apache::loncommon::get_env_multiple('form.hiderole');
1188: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum,1);
1189: my %personnel;
1190: foreach my $key (keys(%coursepersonnel)) {
1191: map { $personnel{$key}{$_} = 1; } split(/,/,$coursepersonnel{$key});
1192: }
1193: %{$syllabus->{'personnel'}} = ();
1194: $syllabus->{'personnel'}{'hideuser'} = '';
1195: $syllabus->{'personnel'}{'hiderole'} = '';
1196: foreach my $role (@hideroles) {
1197: if (exists($personnel{$role})) {
1198: $syllabus->{'personnel'}{'hiderole'} .= $role.',';
1199: }
1200: }
1201: foreach my $item (@hideusers) {
1202: my ($role,$user) = split(/\&/,$item);
1203: if (ref($personnel{$role}) eq 'HASH') {
1204: if ($personnel{$role}{$user}) {
1205: $syllabus->{'personnel'}{'hideuser'} .= $item.',';
1206: }
1207: }
1208: }
1209: $syllabus->{'personnel'}{'hideuser'} =~ s/,$//;
1210: $syllabus->{'personnel'}{'hiderole'} =~ s/,$//;
1211: }
1.121 raeburn 1212: }
1213: $syllabus->{'uploaded.fields'} =~ s/,$//;
1214: }
1215: foreach my $syl_field (keys(%{$syllabusfields})) {
1216: my $field=$env{'form.'.$syl_field};
1217: chomp($field);
1.133 raeburn 1218: my $gateway = Apache::lonhtmlgateway->new();
1219: $field = $gateway->process_incoming_html($field,1);
1.121 raeburn 1220: #here it will be stored
1221: $syllabus->{$syl_field}=$field;
1222: if ($syl_field eq 'lll_includeurl') { # clean up included URLs
1223: my $field='';
1224: foreach my $value (split(/\n/,$syllabus->{$syl_field})) {
1225: my $url=$value;
1226: # get rid of leading and trailing spaces
1227: $url=~s/^\s+//;
1228: $url=~s/\s+$//;
1229: if ($url=~m|^https?\://([^/]+)/(.+)$|) {
1230: my $host = $1;
1231: my $remainder=$2;
1232: # remove the hostname from internal URLs
1233: my $hostname = &Apache::lonnet::hostname($host);
1234: my %all_hostnames = &Apache::lonnet::all_hostnames();
1235: foreach my $possible_host (keys(%all_hostnames)) {
1236: if ($possible_host =~ /\Q$hostname\E/i) {
1237: $url=$remainder;
1238: }
1239: }
1240: }
1241: # norm internal URLs
1242: unless ($url=~/^https?\:/) {
1243: $url=&Apache::lonnet::clutter($url);
1244: }
1245: # re-assemble field
1246: if ($url) {
1247: $field.=$url."\n";
1248: }
1249: }
1250: $syllabus->{$syl_field}=$field;
1251: }
1252: }
1253: my $now = time;
1254: $syllabus->{'uploaded.domain'}=$env{'user.domain'};
1255: $syllabus->{'uploaded.name'}=$env{'user.name'};
1256: $syllabus->{'uploaded.lastmodified'} = $now;
1257: my $putres = &Apache::lonnet::put('syllabus',$syllabus,$cdom,$cnum);
1258: if ($putres eq 'ok') {
1.123 raeburn 1259: ($uploaded,$minimal,$external) =
1260: &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
1261: $minimal,$external);
1.121 raeburn 1262: $output = '<div>'.
1263: &Apache::lonhtmlcommon::confirm_success(&mt('Template saved.')).
1264: '</div>';
1265: } else {
1266: $output = '<div class="LC_error">'.
1267: &mt('An error occurred storing the template: [_1]',$putres).
1268: '</div>';
1269: }
1270: } elsif ($env{'form.choice'} eq 'url') {
1271: if ($env{'form.externalsyllabus'} =~ m{^https?://}) {
1272: if ($env{'form.externalsyllabus'} eq $external) {
1273: $output = '<div class="LC_info">'.
1274: &mt('External URL unchanged.').
1275: '</div>';
1.123 raeburn 1276: ($uploaded,$minimal,$external) =
1277: &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
1278: $minimal,$external);
1.121 raeburn 1279: } else {
1280: $external=$env{'form.externalsyllabus'};
1281: $external =~ s/(`)//g;
1282: my $putres =
1283: &Apache::lonnet::put('environment',{externalsyllabus=>$external},
1284: $cdom,$cnum);
1285: if ($putres eq 'ok') {
1286: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.externalsyllabus' => $external});
1287: $output = '<div>'.
1288: &Apache::lonhtmlcommon::confirm_success(&mt('External URL saved.')).
1289: '</div>';
1.123 raeburn 1290: ($uploaded,$minimal,$external) =
1291: &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
1292: $minimal,$external);
1.121 raeburn 1293: } else {
1294: $output = '<div class="LC_error">'.
1295: &mt('An error occurred storing the external URL: [_1]',$putres).
1296: '</div>';
1297: }
1298: }
1299: } else {
1300: $output = '<div class="LC_error">'.
1301: &mt('External URL not saved -- invalid URL.').
1302: '</div>';
1303: }
1.122 raeburn 1304: } elsif (($env{'form.choice'} eq 'file') || ($env{'form.choice'} eq 'minimal')) {
1.121 raeburn 1305: # Process file upload - phase one - upload and parse primary file.
1.122 raeburn 1306: my ($upload_result,$uploadphase,$url,$needlink,$error,$errormsg);
1307: if ($env{'form.choice'} eq 'file') {
1308: if ($env{'form.syllabusfile.filename'}) {
1309: my %allfiles = ();
1310: my %codebase = ();
1311: ($url,$needlink) = &process_upload(\$output,$cnum,$cdom,
1312: \%allfiles,\%codebase);
1313: } else {
1.134 raeburn 1314: $output = '<div class="LC_info">'.
1.122 raeburn 1315: &mt('No file uploaded').
1316: '</div>';
1317: }
1318: } elsif ($env{'form.choice'} eq 'minimal') {
1.131 raeburn 1319: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus/loncapa.html";
1320: my $filecontents=&Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$url));
1321: if ($filecontents eq -1) {
1322: $url = &default_minimal_syllabus($cnum,$cdom);
1.122 raeburn 1323: }
1324: }
1325: if ($url =~ m{^/uploaded/\Q$cdom\E/\Q$cnum\E.*/[^/]+$}) {
1.123 raeburn 1326: my $exturl = &home_http_host($cdom,$cnum);
1327: if ($exturl) {
1328: $exturl .= $url;
1.122 raeburn 1329: }
1330: my %storehash;
1331: if ($env{'form.choice'} eq 'minimal') {
1332: $storehash{'minimalsyllabus'} = $url;
1333: } else {
1334: $storehash{'uploadedsyllabus'} = $url;
1335: }
1336: if ($exturl) {
1337: $storehash{'externalsyllabus'} = $exturl;
1338: if ($exturl =~ /\.(html?|txt|js|css)$/) {
1339: $exturl .= '?inhibitmenu=yes';
1340: }
1341: } else {
1342: $storehash{'externalsyllabus'} = '',
1343: }
1344: my $putres =
1345: &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
1346: if ($putres eq 'ok') {
1347: &Apache::lonnet::make_public_indefinitely($url);
1348: foreach my $key (keys(%storehash)) {
1349: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.'.$key => $storehash{$key}});
1350: }
1351: if ($env{'form.choice'} eq 'minimal') {
1352: $minimal = $url;
1.121 raeburn 1353: } else {
1.122 raeburn 1354: $uploaded = $url;
1.121 raeburn 1355: }
1.122 raeburn 1356: if ($needlink) {
1357: $output .= &return_to_editor($cdom,$cnum);
1358: $earlyout = 1;
1.121 raeburn 1359: }
1.123 raeburn 1360: ($uploaded,$minimal,$external) =
1361: &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
1362: $minimal,$external);
1.122 raeburn 1363: } else {
1364: $error = 1;
1365: $errormsg = $putres;
1366: }
1367: } else {
1368: $error = 1;
1369: }
1370: if ($error) {
1371: $output = '<div class="LC_error">';
1372: if ($env{'form.choice'} eq 'minimal') {
1373: $output = &mt('An error occurred creating the minimal template file [_1]',$errormsg);
1374: } else {
1375: $output = &mt('An error occurred storing the uploaded file [_1]',$errormsg);
1.121 raeburn 1376: }
1.122 raeburn 1377: $output .= '</div>';
1.121 raeburn 1378: }
1379: } elsif ($env{'form.phase'} eq 'upload_embedded') {
1380: # Process file upload - phase two - upload embedded objects
1381: my $uploadphase = 'check_embedded';
1382: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
1383: my $state = &embedded_form_elems($uploadphase,$primaryurl);
1384: my $url_root = '/uploaded/'.$cdom.'/'.$cnum;
1385: my $actionurl = "/public/$cdom/$cnum/syllabus";
1386: my ($result,$flag,$numpathchgs) =
1387: &Apache::loncommon::upload_embedded('syllabus','portfolio/syllabus',
1388: $cnum,$cdom,'/userfiles',$url_root,undef,undef,undef,$state,
1389: $actionurl);
1390: unless ($numpathchgs) {
1391: my $modres =
1392: &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
1393: $cnum,$cdom,
1394: '/userfiles',$env{'form.primaryurl'});
1395: $result .= $modres;
1396: }
1.122 raeburn 1397: $output = $result.&return_to_editor($cdom,$cnum);
1.121 raeburn 1398: $earlyout = 1;
1399: } elsif ($env{'form.phase'} eq 'check_embedded') {
1400: # Process file upload - phase three - modify references in HTML file
1401: my $uploadphase = 'modified_orightml';
1402: my $result =
1403: &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
1404: $cnum,$cdom,
1405: '/userfiles',$env{'form.primaryurl'});
1.122 raeburn 1406: $output = $result.&return_to_editor($cdom,$cnum);
1.121 raeburn 1407: $earlyout = 1;
1408: }
1.122 raeburn 1409: return ($earlyout,$uploaded,$external,$minimal,$output);
1.121 raeburn 1410: }
1411:
1.131 raeburn 1412: sub default_minimal_syllabus {
1413: my ($cnum,$cdom) = @_;
1414: my $title;
1415: if ($env{'form.syllabustitle'}) {
1416: $title = $env{'form.syllabustitle'};
1417: $title =~ s{`}{}g;
1418: $title=~s/^\s+//;
1419: $title=~s/\s+$//;
1420: }
1421: if ($title eq '') {
1422: $title = &mt('Syllabus');
1423: }
1424: my $initialtext = &mt('Replace with your own content.');
1425: my $newhtml = <<END;
1426: <html>
1427: <head>
1428: <title>$title</title>
1429: </head>
1430: <body bgcolor="#ffffff">
1431: <h2>$title</h2>
1432: $initialtext
1433: </body>
1434: </html>
1435: END
1436: $env{'form.output'}=$newhtml;
1437: return &Apache::lonnet::finishuserfileupload($cnum,$cdom,'output',
1438: 'portfolio/syllabus/loncapa.html');
1439: }
1440:
1.123 raeburn 1441: sub update_syllabus_env {
1.124 raeburn 1442: my ($cdom,$cnum,$courseenv,$saved,$uploaded,$minimal,$external) = @_;
1.125 raeburn 1443: return ($uploaded,$minimal,$external) unless(ref($courseenv) eq 'HASH');
1.123 raeburn 1444: my $now = time;
1445: my (@envkeys,%storehash);
1446: if ($saved eq 'template') {
1.131 raeburn 1447: if ($uploaded || $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) {
1.123 raeburn 1448: push(@envkeys,'uploaded');
1449: }
1.131 raeburn 1450: if ($minimal || $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'}) {
1.123 raeburn 1451: push(@envkeys,'minimal');
1452: }
1.131 raeburn 1453: if ($external || $env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) {
1.123 raeburn 1454: push(@envkeys,'external');
1455: }
1456: $storehash{'updatedsyllabus'} = $now;
1457: &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.updatedsyllabus' => $now
1458: });
1459: } elsif ($saved eq 'url') {
1460: my $prefix = &home_http_host($cdom,$cnum);
1461: if ($external =~ m{^\Q$prefix/uploaded/$cdom/$cnum/portfolio/syllabus/\E(.+)$}) {
1462: my $file = $1;
1463: if ($file eq 'loncapa.html') {
1.131 raeburn 1464: if ($uploaded || $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) {
1.123 raeburn 1465: push(@envkeys,'uploaded');
1466: }
1.131 raeburn 1467: } elsif ($minimal || $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'}) {
1.123 raeburn 1468: push(@envkeys,'minimal');
1469: }
1470: } else {
1.131 raeburn 1471: if ($uploaded || $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) {
1.123 raeburn 1472: push(@envkeys,'uploaded');
1473: }
1.131 raeburn 1474: if ($minimal || $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'}) {
1.123 raeburn 1475: push(@envkeys,'minimal');
1476: }
1477: }
1478: } elsif ($saved eq 'file') {
1.131 raeburn 1479: if ($minimal || $env{'course.'.$env{'request.course.id'}.'.minimalsyllabus'}) {
1.123 raeburn 1480: push(@envkeys,'minimal');
1481: }
1482: } elsif ($saved eq 'minimal') {
1.131 raeburn 1483: if ($uploaded || $env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) {
1.123 raeburn 1484: push(@envkeys,'uploaded');
1485: }
1486: }
1487: if (@envkeys > 0) {
1488: foreach my $item (@envkeys) {
1489: my $key = $item.'syllabus';
1.130 raeburn 1490: if ($courseenv->{$key} ne '') {
1.123 raeburn 1491: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
1.131 raeburn 1492: if ($item eq 'minimal') {
1493: &update_access_permissions($cdom,$cnum,'/syllabus/loncapa.html');
1494: } elsif ($item eq 'uploaded') {
1495: if ($courseenv->{$key} =~ m{^\Q/uploaded/$cdom/$cnum/portfolio\E(/syllabus/.+)$}) {
1496: my $filename = $1;
1497: &update_access_permissions($cdom,$cnum,$filename);
1498: }
1499: }
1.123 raeburn 1500: $storehash{$key} = '';
1.131 raeburn 1501: } elsif ($env{'course.'.$env{'request.course.id'}.'.'.$key} ne '') {
1502: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
1.123 raeburn 1503: }
1504: if ($item eq 'uploaded') {
1505: undef($uploaded);
1506: }
1507: if ($item eq 'external') {
1508: undef($external);
1509: }
1510: if ($item eq 'minimal') {
1511: undef($minimal);
1512: }
1513: }
1514: }
1515: if (keys(%storehash) > 0) {
1516: &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
1517: }
1518: return ($uploaded,$minimal,$external);
1519: }
1520:
1.131 raeburn 1521: sub update_access_permissions {
1522: my ($cdom,$cnum,$file_name) = @_;
1523: my $current_permissions = &Apache::lonnet::get_portfile_permissions($cdom,$cnum);
1524: my %access_controls =
1525: &Apache::lonnet::get_access_controls($current_permissions,'',$file_name);
1526: if (keys(%access_controls) > 0) {
1527: my %changes;
1528: foreach my $key (keys(%{$access_controls{$file_name}})) {
1529: $changes{'delete'}{$key} = 1;
1530: }
1531: if (keys(%changes) > 0) {
1532: my ($outcome,$deloutcome,$new_values,$translation) =
1533: &Apache::lonnet::modify_access_controls($file_name,\%changes,
1534: $cdom,$cnum);
1535: }
1536: }
1537: return;
1538: }
1539:
1.123 raeburn 1540: sub home_http_host {
1541: my ($cdom,$cnum) = @_;
1542: my $home=&Apache::lonnet::homeserver($cnum,$cdom);
1543: if ($home ne 'no_host') {
1544: my $protocol = $Apache::lonnet::protocol{$home};
1545: $protocol = 'http' if ($protocol ne 'https');
1.136 raeburn 1546: return $protocol.'://'.&Apache::lonnet::hostname($home);
1.123 raeburn 1547: }
1548: return;
1549: }
1550:
1.117 raeburn 1551: sub process_upload {
1552: my ($upload_output,$cnum,$cdom,$allfiles,$codebase) = @_;
1553: my ($parseaction,$showupload,$mimetype);
1554: my $dest = 'portfolio/syllabus';
1555: if ($env{'form.parserflag'}) {
1556: $parseaction = 'parse';
1557: }
1558: my $url=&Apache::lonnet::userfileupload('syllabusfile','syllabus',$dest,
1559: $parseaction,$allfiles,
1560: $codebase,undef,undef,undef,undef,
1561: undef,undef,\$mimetype);
1562: if ($url =~ m{^/uploaded/\Q$cdom\E/\Q$cnum\E.*/([^/]+)$}) {
1563: my $stored = $1;
1564: $showupload = '<p>'.&mt('Uploaded [_1]',
1565: '<span class="LC_filename">'.$stored.'</span>').
1566: '</p>';
1567: } else {
1568: my ($filename) = ($env{'form.syllabusfile.filename'} =~ m{([^/]+)$});
1569: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.
1570: &mt('Unable to save file [_1].',
1571: '<span class="LC_filename">'.$filename.'</span>').
1572: '</div>';
1573: return ();
1574: }
1575: my $needlink;
1576: if (($parseaction eq 'parse') && ($mimetype eq 'text/html')) {
1577: $$upload_output = $showupload;
1578: my $total_embedded = scalar(keys(%{$allfiles}));
1579: if ($total_embedded > 0) {
1580: my $uploadphase = 'upload_embedded';
1581: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
1582: my $state = &embedded_form_elems($uploadphase,$primaryurl);
1583: my $actionurl = "/public/$cdom/$cnum/syllabus";
1584: my ($embedded,$num,$numpathchanges,$existing);
1585: ($embedded,$num,$numpathchanges,$existing) =
1586: &Apache::loncommon::ask_for_embedded_content($actionurl,$state,
1587: $allfiles,$codebase,
1588: {'error_on_invalid_names' => 1,
1589: 'ignore_remote_references' => 1,});
1590: if ($embedded) {
1591: $needlink = 1;
1592: if ($num) {
1593: $$upload_output .=
1594: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
1595: } elsif ($numpathchanges) {
1596: $$upload_output .= $embedded;
1597: } else {
1598: $$upload_output .= $embedded;
1599: &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
1600: $cnum,$cdom,'/userfiles',$url);
1601: }
1602: } else {
1603: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
1604: &Apache::loncommon::modify_html_refs('syllabus','portfolio/syllabus',
1605: $cnum,$cdom,'/userfiles',$url);
1606:
1607: }
1608: } else {
1609: $$upload_output .= &mt('No embedded items identified').'<br />';
1610: }
1611: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1612: }
1613: return ($url,$needlink);
1614: }
1615:
1616: sub embedded_form_elems {
1617: my ($phase,$primaryurl) = @_;
1618: return <<STATE;
1619: <input type="hidden" name="forceedit" value="1" />
1620: <input type="hidden" name="cmd" value="upload_embedded" />
1621: <input type="hidden" name="phase" value="$phase" />
1622: <input type="hidden" name="primaryurl" value="$primaryurl" />
1623: STATE
1624: }
1625:
1626: sub return_to_editor {
1627: my ($cdom,$cnum) = @_;
1628: my $actionurl = "/public/$cdom/$cnum/syllabus";
1629: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'.
1630: '<input type="hidden" name="forceedit" value="1" />'."\n".
1631: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
1632: '</a></p>';
1633: }
1634:
1.118 raeburn 1635: sub editfile_button {
1.125 raeburn 1636: my ($url,$context,$editable) = @_;
1.122 raeburn 1637: my $edittext=&mt('Edit');
1638: my $deltext=&mt('Delete');
1.125 raeburn 1639: my $output;
1640: if ($editable) {
1641: $output = '
1642: <input type="button" value="'.$edittext.'" onclick="javascript:gotoeditor('."'$url'".');" name="edit_'.$context.'" />
1643: ';
1644: }
1645: $output .= '
1646: <input type="button" value="'.$deltext.'" onclick="javascript:dodelete('."'$context'".');" name="del_'.$context.'" />
1.128 raeburn 1647: <input type="hidden" value="" name="deleteuploaded_'.$context.'" id="deleteuploaded_'.$context.'" />
1.125 raeburn 1648: ';
1649: return $output;
1.118 raeburn 1650: }
1651:
1652: sub editbutton_js {
1.138 damieng 1653: my %js_lt = &Apache::lonlocal::texthash(
1.126 raeburn 1654: min => 'Are you sure you want to delete the contents of the syllabus template?',
1655: file => 'Are you sure you want to delete the uploaded syllabus file?',
1656: noundo => 'This action cannot be reversed.'
1657: );
1.138 damieng 1658: &js_escape(\%js_lt);
1.118 raeburn 1659: return <<ENDJS;
1660: <script type="text/javascript">
1661: // <![CDATA[
1.122 raeburn 1662: function gotoeditor(url) {
1663: document.location.href = url+'?editmode=1&forceedit=1';
1664: }
1665: function dodelete(caller,url) {
1.128 raeburn 1666: if (document.getElementById('deleteuploaded_'+caller)) {
1667: document.getElementById('deleteuploaded_'+caller).value=1;
1668: if (caller == 'minimal') {
1.138 damieng 1669: if (confirm("$js_lt{'min'}"+"\\n"+"$js_lt{'noundo'}")) {
1.128 raeburn 1670: document.syllabus.submit();
1671: }
1.126 raeburn 1672: }
1.128 raeburn 1673: if (caller == 'file') {
1.138 damieng 1674: if (confirm("$js_lt{'file'}"+"\\n"+"$js_lt{'noundo'}")) {
1.128 raeburn 1675: document.syllabus.submit();
1676: }
1.126 raeburn 1677: }
1678: }
1679: return;
1.118 raeburn 1680: }
1681: // ]]>
1682: </script>
1683: ENDJS
1684: }
1685:
1.1 www 1686: 1;
1687: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>