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