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