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