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