'.&mt('Last updated').': '.
+ $lastmod . ' '.
+ ($who ? &mt('by').' '.$who
+ : '' ) .
+ '
' );
+ } else {
+ $r->print('\\\\ '.&mt('Last updated').': '.$lastmod.' '.
+ ($who? &mt('by').'\\\\ '.
+ &Apache::loncommon::plainname($syllabus{'uploaded.name'},$syllabus{'uploaded.domain'})
+ :'')
+ .'\\\\');
+ }
+ }
+
+#-------------------------------------------------------------- Print Headtitle
if ($target ne 'tex') {
- $r->print(&Apache::lonannounce::showday(time,2,
- &Apache::lonannounce::readcalendar($cdom.'_'.$cnum)).
- &Apache::lonrss::advertisefeeds($cnum,$cdom));
- } else {
- $r->print(&Apache::lonxml::xmlparse($r,'tex',
- &Apache::lonannounce::showday(time,2,
- &Apache::lonannounce::readcalendar($cdom.'_'.$cnum))));
+ my $display = 'block';
+ if ($external || $uploaded || $minimal) {
+ $display = 'none';
+ }
+ $r->print(''.
+ '
'.$courseenv{'description'}.'
');
+ if ($allowed) {
+ $r->print('
'.
+ '
'.&Apache::lonnet::domain($cdom,'description').'
'.
+ '');
+# Print Help Text if editing at right side of screen
+ $r->print('
'.
+ &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).
+ '
');
+ } else {
+ $r->print('
'.&Apache::lonnet::domain($cdom,'description').'
');
+ }
+ } else {
+ $r->print('\noindent{\large\textbf{'.$courseenv{'description'}.'}}\\\\\\\\\textbf{'.
+ &Apache::lonnet::domain($cdom,'description').'}\\\\');
}
# -------------------------------------------------------- Get course personnel
- my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
+ my $hidepersonnel;
+ if (($syllabus{'uploaded.fields'}) &&
+ (($syllabus{'uploaded.fields'} eq 'none') ||
+ ($syllabus{'uploaded.fields'} !~ /000/))) {
+ $hidepersonnel = 1;
+ }
if ($target ne 'tex') {
- $r->print('
');
+ if ($allowed) {
+ my $display = ' style="display:block;"';
+ if ($hidepersonnel) {
+ $display = ' style="display:none;"';
+ }
+ &Apache::lontemplate::print_start_template($r,&mt('Personnel'),'LC_Box',
+ 'box_000_showpeople',$display);
+ $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed,$crstype,\%syllabus));
+ &Apache::lontemplate::print_end_template($r);
+ } else {
+ unless ($hidepersonnel) {
+ &Apache::lontemplate::print_start_template($r,&mt('Personnel'),'LC_Box');
+ $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed,$crstype,\%syllabus));
+ &Apache::lontemplate::print_end_template($r);
+ }
+ }
} else {
- $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline');
+ unless ($hidepersonnel) {
+ $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed,$crstype,%syllabus));
+ }
+ }
+# -------------------------------------------------------------- Announcements?
+ my $day = &Apache::lonannounce::showday(time,2,
+ &Apache::lonannounce::readcalendar($cdom.'_'.$cnum));
+ my $hidefeeds;
+ if (($syllabus{'uploaded.fields'}) &&
+ (($syllabus{'uploaded.fields'} eq 'none') ||
+ ($syllabus{'uploaded.fields'} !~ /111/))) {
+ $hidefeeds = 1;
+ }
+ if ($target ne 'tex') {
+ if ($allowed) {
+ my $display = ' style="display:block;"';
+ if ($hidefeeds) {
+ $display = ' style="display:none;"';
+ }
+ &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box',
+ 'box_111_showrssfeeds',$display);
+ my ($numfeeds,$hiddenfeeds,$rsslinktext);
+ my $feeds=&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit,\$numfeeds,
+ \$hiddenfeeds);
+ if ($numfeeds) {
+ $r->print($feeds);
+ $rsslinktext = &mt('New RSS Feed or Blog');
+ } else {
+ my $msg = '
'.
+ &mt("RSS Feeds and Blogs item is not included in a student's view of the syllabus.");
+ if ($hiddenfeeds) {
+ $r->print(''.
+ &mt('All feeds currently hidden').
+ $msg.
+ '
');
+ } else {
+ $r->print(''.
+ &mt('No current feeds').
+ $msg.
+ '
');
+ }
+ $rsslinktext = &mt('Manage Course RSS Feeds/Blogs');
+ if ($crstype eq 'Community') {
+ $rsslinktext = &mt('Manage Communiity RSS Feeds/Blogs');
+ }
+ }
+ my $editurl= &Apache::lonnet::absolute_url().'/adm/'.$cdom.'/'.$cnum.'/_rss.html';
+ $r->print( ''.$rsslinktext.'');
+ &Apache::lontemplate::print_end_template($r);
+ } else {
+ unless ($hidefeeds) {
+ my $feeds = &Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit);
+ if ($feeds ne '') {
+ &Apache::lontemplate::print_start_template($r,&mt('RSS Feeds and Blogs'),'LC_Box');
+ $r->print($feeds);
+ &Apache::lontemplate::print_end_template($r);
+ }
+ }
+ }
+ } else {
+ $r->print(&Apache::lonxml::xmlparse($r,'tex',$day));
+ }
+# ---------------------------------------------------------------- Get syllabus
+ if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
+ my $url_include_handler = sub {
+ my ($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed, $display) = @_;
+ my %data = %{$data_ref};
+ my %fields = %{$fields_ref};
+ my $urls=$message;
+ $message='';
+ foreach my $filelink (split(/\n/,$urls)) {
+ my $output='';
+ # embed style?
+ my ($curfext)=($filelink=~/\.([^\.]+)$/);
+ my $embstyle=&Apache::loncommon::fileembstyle($curfext);
+ if (($embstyle eq 'ssi') || ($curfext=~/\/$/)) {# make ssi call and remove everything but the body contents
+ $output=&Apache::lonnet::ssi_body($filelink);
+ } elsif ($embstyle eq 'img') {# embed as an image
+ $output='';
+ }
+ if ($output ne '') {
+ if ($target ne 'tex') {
+ $message.=''.$output.'
';
+ } else {
+ $message.=' '.&Apache::lonxml::xmlparse($r,'tex',''.$output.'
').' ';
+ }
+ }
+ }
+ if ($allowed) {
+ &Apache::lonfeedback::newline_to_br(\$urls);
+ &Apache::lontemplate::print_start_template($r,$fields{$field}.
+ &Apache::loncommon::help_open_topic('Syllabus_URLs'),'LC_Box',
+ 'box_'.$field,$display);
+ $r->print($urls);
+ $r->print("
");
+ &Apache::lontemplate::print_textarea_template($r, $data{$field},
+ $field, Apache::lontemplate->RICH_TEXT_ALWAYS_OFF);
+ &Apache::lontemplate::print_saveall_template($r);
+ $r->print("
");
+ &Apache::lontemplate::print_end_template($r);
+
+ } else {
+ $r->print($message);
+ }
+ };
+ my %custom_hash = ( 'lll_includeurl' => $url_include_handler );
+ &Apache::lontemplate::print_template_fields($r, \%syllabus, \%syllabusfields,
+ $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_hash,
+ undef,\%displayfields,\%noshow);
+ if ($allowed) {
+ $r->print(''.
+ &Apache::lonhtmlcommon::htmlareaselectactive());
+ }
+ } else {
+ if ($target ne 'tex') {$r->print('');} else {$r->print('\par ');}
+ $r->print(&mt('No syllabus information provided.'));
+ if ($target ne 'tex') {$r->print('
');}
+ }
+ if ($target ne 'tex') {
+ if ($env{'form.backto'} eq 'coursecatalog') {
+ $r->print('');
+ }
+ $r->print(&Apache::loncommon::end_page());
+ } else {
+ $r->print('\end{document}');
+ }
+ return OK;
+}
+
+sub print_header {
+ my ($r,$cnum,$cdom,$crstype,$allowed,$forceedit,$syllabus,$syllabusfields) = @_;
+ return unless ((ref($syllabus) eq 'HASH') || (ref($syllabusfields) eq 'HASH'));
+# ----------------------------------------------------------------- Make header
+ my $rss_link = &Apache::lonrss::rss_link($cnum,$cdom);
+ my $js;
+ if ($env{'form.backto'} eq 'coursecatalog') {
+ $js .= <<"ENDSCRIPT";
+
+
+
+ENDSCRIPT
+ }
+ if ($allowed && $forceedit) {
+ my $check_uncheck = &Apache::loncommon::check_uncheck_jscript();
+ my @fieldnames = sort(keys(%{$syllabusfields}));
+ unshift(@fieldnames,'000_showpeople','111_showrssfeeds');
+ my (@checked,@unchecked);
+ if ($syllabus->{'uploaded.fields'} eq 'none') {
+ my $lastidx = scalar(@fieldnames)-1;
+ @unchecked = (0..$lastidx);
+ } elsif ($syllabus->{'uploaded.fields'}) {
+ my %included;
+ map { $included{$_} = 1; } split(/,/,$syllabus->{'uploaded.fields'});
+ for (my $i=0; $i<@fieldnames; $i++) {
+ my ($prefix) = split(/_/,$fieldnames[$i]);
+ if ($included{$prefix}) {
+ push(@checked,$i);
+ } else {
+ push(@unchecked,$i);
+ }
+ }
+ } else {
+ @checked = (0,1);
+ for (my $i=2; $i<@fieldnames; $i++) {
+ if ($syllabus->{$fieldnames[$i]}) {
+ push(@checked,$i);
+ } else {
+ push(@unchecked,$i);
+ }
+ }
+ }
+ my $fieldstr = "var fields = new Array('".join("','",@fieldnames)."');";
+ my $checkedstr = "var include = new Array('".join("','",@checked)."');";
+ my $uncheckedstr = "var exclude = new Array('".join("','",@unchecked)."');";
+ my $invurl = &mt('Invalid URL');
+ my $urlregexp = <<'ENDREGEXP';
+/^([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
+ENDREGEXP
+
+ $js .= <<"ENDSCRIPT";
+
+
+
+ENDSCRIPT
+ }
+ my $args = {'function' => undef,
+ 'domain' => $cdom};
+ my $forcereg;
+ if ($env{'form.register'}) {
+ $forcereg = 1;
+ $args->{'force_register'} = $forcereg;
+ }
+ if ($env{'form.backto'} eq 'coursecatalog') {
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ my $brcrum = [{href=>"javascript:ToCatalog();",
+ text=>&mt('Course/Community Catalog'),
+ no_mt=>1}
+ ];
+ if ($env{'form.coursenum'} ne '') {
+ push(@{$brcrum},
+ {href=>"javascript:ToCatalog('details')",
+ text=>"Course details"});
+ }
+ push(@{$brcrum},
+ {href=>$r->uri,
+ text=>"Course syllabus"});
+ $args->{'bread_crumbs'} = $brcrum;
+ } else {
+ &get_breadcrumbs($cdom,$cnum,$crstype,$args);
+ }
+ if ($allowed) {
+ my %loaditem = (
+ onload => 'setTemplateBoxes();',
+ );
+ $args->{'add_entries'} = \%loaditem;
+ }
+ my $start_page =
+ &Apache::loncommon::start_page("Syllabus", $rss_link.$js,$args);
+ if ($start_page) {
+ $r->print($start_page);
+ }
+}
+
+sub get_breadcrumbs{
+ my ($cdom,$cnum,$crstype,$args) = @_;
+ return unless (ref($args) eq 'HASH');
+ if ($env{'form.folderpath'} =~ /^supplemental/) {
+ my $title = $env{'form.title'};
+ if ($title eq '') {
+ $title = &mt('Syllabus');
+ }
+ my $brcrum =
+ &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
+ if (ref($brcrum) eq 'ARRAY') {
+ $args->{'bread_crumbs'} = $brcrum;
+ }
+ } else {
+ if ((&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus"))
+ && (($env{'form.symb'}) || ($env{'form.register'}))) {
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ } else {
+ $args->{'bread_crumbs'} = [
+ {'href' => "/public/$cdom/$cnum/syllabus",
+ 'text' => 'Syllabus'},
+ ];
+ }
+ }
+ return;
+}
+
+sub chooser {
+ my ($external,$uploaded,$minimal,$cdom,$cnum,$lonhost,$fields,$values) = @_;
+ my %lt = &Apache::lonlocal::texthash(
+ 'type' => 'Syllabus Type',
+ 'url' => 'External URL',
+ 'file' => 'Uploaded file',
+ 'minimal' => 'Minimal template',
+ 'template' => 'Standard template',
+ 'templateboxes' => 'Choose template items ... ',
+ 'curr' => 'Current:',
+ 'rep' => 'Replace:',
+ 'upl' => 'Upload:',
+ 'pr' => 'Preview',
+ 'save' => 'Save',
+ 'sved' => 'Save and Edit',
+ 'chourl' => 'External URL',
+ 'chofile' => 'Uploaded syllabus file',
+ 'parse' => 'Upload embedded images/multimedia files if HTML file',
+ );
+ my %checked = (
+ file => '',
+ minimal => '',
+ url => '',
+ template => '',
+ );
+ my %display = (
+ file => 'none',
+ minimal => 'none',
+ url => 'none',
+ templatebox => 'none',
+ );
+ my $check = ' checked="checked" ';
+ if ($uploaded) {
+ $checked{'file'} = $check;
+ $display{'file'} = 'block';
+ } elsif ($external) {
+ $checked{'url'} = $check;
+ $display{'url'} = 'block';
+ } elsif ($minimal) {
+ $checked{'minimal'} = $check;
+ $display{'minimal'} = 'block';
+ } else {
+ $checked{'template'} = $check;
+ $checked{'templatebox'} = $check;
+ $display{'templatebox'} = 'block';
+ }
+
+ my $output =
+ '
');
+ if ($allowed) {
+ $r->print(&Apache::loncommon::end_data_table());
+ } else {
+ $r->print(&Apache::lonhtmlcommon::end_pick_box());
+ }
} else {
- $r->print('\end{tabular}\\\\');
+ $r->print('\end{tabular}\\\\');
}
-# ---------------------------------------------------------- Load syllabus info
- my %syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum);
- my $allowed=0;
- my $privileged=0;
+ return;
+}
-# This handler might be called anonymously ...
-# ----------------------------------------------------- Only if not public call
- if ($env{'user.environment'}) {
-# does this user have privileges to post, etc?
- if ($env{'request.course.id'}) {
- $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
- $privileged=$allowed;
- if (($syllabus{'uploaded.lastmodified'}) && (!$forceedit)) {
- $forcestudent='student';
- }
- if ($forcestudent or $target eq 'tex') { $allowed=0; }
- }
- if ($allowed) {
- $r->print('
'.
-&Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes','Help with filling in text boxes').'
'.&mt('This syllabus can be publicly viewed at')
- .' http://'.
- $Apache::lonnet::hostname{$homeserver}.$r->uri.''.
- &Apache::loncommon::help_open_topic('Syllabus_ExtLink').'
'.
- '
'.
-&mt('Show Public View').''.
- &Apache::loncommon::help_open_topic('Uploaded_Templates_PublicView').
- '
');
- } elsif ($privileged) {
- if ($target ne 'tex') {
- $r->print('
'.
- &mt('Edit').'');
- }
- }
- if (($allowed) && ($env{'form.storesyl'})) {
- foreach (keys %syllabusfields) {
- my $field=$env{'form.'.$_};
- chomp($field);
- $field=~s/\s+$//s;
- $field=~s/^\s+//s;
- $field=~s/\
$//s;
- $field=&Apache::lonfeedback::clear_out_html($field,1);
- $syllabus{$_}=$field;
- if ($_ eq 'lll_includeurl') { # clean up included URLs
- my $field='';
- foreach (split(/\n/,$syllabus{$_})) {
- my $url=$_;
+sub save_changes {
+ my ($cnum,$cdom,$uploaded,$external,$minimal,$syllabus,$syllabusfields,$courseenv) = @_;
+ my ($earlyout,$output);
+ unless ((ref($syllabus) eq 'HASH') && (ref($syllabusfields) eq 'HASH')) {
+ return ($earlyout,$uploaded,$external,$minimal,$output);
+ }
+ if (($env{'form.deleteuploaded_file'}) || ($env{'form.deleteuploaded_minimal'})) {
+ my %storehash;
+ if (($env{'form.choice'} eq 'file') &&
+ ($env{'form.deleteuploaded_file'}) && ($uploaded =~ /\w/)) {
+ &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus');
+ &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus');
+ $storehash{'uploadedsyllabus'} = '';
+ $storehash{'externalsyllabus'} = '';
+ my $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
+ undef($uploaded);
+ undef($external);
+ } elsif (($env{'form.choice'} eq 'minimal') &&
+ ($env{'form.deleteuploaded_minimal'}) && ($minimal =~ /\w/)) {
+ &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus');
+ &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.minimalsyllabus');
+ $storehash{'externalsyllabus'} = '';
+ $storehash{'minimalsyllabus'} = '';
+ my $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
+ undef($external);
+ undef($minimal);
+ }
+ } elsif ($env{'form.choice'} eq 'template') {
+#store what the user typed in to the template
+ my @shown = &Apache::loncommon::get_env_multiple('form.showfield');
+ $syllabus->{'uploaded.fields'} = '';
+ if (@shown == 0) {
+ $syllabus->{'uploaded.fields'} = 'none';
+ } else {
+ foreach my $field (sort(@shown)) {
+ if (($field eq '000_showpeople') ||
+ ($field eq '111_showrssfeeds') ||
+ ($syllabusfields->{$field})) {
+ my ($prefix) = split(/_/,$field);
+ $syllabus->{'uploaded.fields'} .= $prefix.',';
+ }
+ if ($field eq '000_showpeople') {
+ my @hideusers = &Apache::loncommon::get_env_multiple('form.hideuser');
+ my @hideroles = &Apache::loncommon::get_env_multiple('form.hiderole');
+ my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum,1);
+ my %personnel;
+ foreach my $key (keys(%coursepersonnel)) {
+ map { $personnel{$key}{$_} = 1; } split(/,/,$coursepersonnel{$key});
+ }
+ %{$syllabus->{'personnel'}} = ();
+ $syllabus->{'personnel'}{'hideuser'} = '';
+ $syllabus->{'personnel'}{'hiderole'} = '';
+ foreach my $role (@hideroles) {
+ if (exists($personnel{$role})) {
+ $syllabus->{'personnel'}{'hiderole'} .= $role.',';
+ }
+ }
+ foreach my $item (@hideusers) {
+ my ($role,$user) = split(/\&/,$item);
+ if (ref($personnel{$role}) eq 'HASH') {
+ if ($personnel{$role}{$user}) {
+ $syllabus->{'personnel'}{'hideuser'} .= $item.',';
+ }
+ }
+ }
+ $syllabus->{'personnel'}{'hideuser'} =~ s/,$//;
+ $syllabus->{'personnel'}{'hiderole'} =~ s/,$//;
+ }
+ }
+ $syllabus->{'uploaded.fields'} =~ s/,$//;
+ }
+ foreach my $syl_field (keys(%{$syllabusfields})) {
+ my $field=$env{'form.'.$syl_field};
+ chomp($field);
+ $field=~s/\s+$//s;
+ $field=~s/^\s+//s;
+ $field=~s/\
$//s;
+ $field=&Apache::lonfeedback::clear_out_html($field,1);
+ #here it will be stored
+ $syllabus->{$syl_field}=$field;
+ if ($syl_field eq 'lll_includeurl') { # clean up included URLs
+ my $field='';
+ foreach my $value (split(/\n/,$syllabus->{$syl_field})) {
+ my $url=$value;
# get rid of leading and trailing spaces
- $url=~s/^\s+//;
- $url=~s/\s+$//;
- if ($url=~/^http\:\/\/([^\/]+)\/(.+)$/) {
- my $remainder=$2;
+ $url=~s/^\s+//;
+ $url=~s/\s+$//;
+ if ($url=~m|^https?\://([^/]+)/(.+)$|) {
+ my $host = $1;
+ my $remainder=$2;
# remove the hostname from internal URLs
- foreach (keys %Apache::lonnet::hostname) {
- if ($1=~/$Apache::lonnet::hostname{$_}/i) {
- $url=$remainder;
- }
- }
- }
+ my $hostname = &Apache::lonnet::hostname($host);
+ my %all_hostnames = &Apache::lonnet::all_hostnames();
+ foreach my $possible_host (keys(%all_hostnames)) {
+ if ($possible_host =~ /\Q$hostname\E/i) {
+ $url=$remainder;
+ }
+ }
+ }
# norm internal URLs
- unless ($url=~/^http\:/) {
- $url=&Apache::lonnet::clutter($url);
- }
+ unless ($url=~/^https?\:/) {
+ $url=&Apache::lonnet::clutter($url);
+ }
# re-assemble field
- if ($url) {
- $field.=$url."\n";
- }
- }
- $syllabus{$_}=$field;
- }
- }
- $syllabus{'uploaded.domain'}=$env{'user.domain'};
- $syllabus{'uploaded.name'}=$env{'user.name'};
- $syllabus{'uploaded.lastmodified'}=time;
- &Apache::lonnet::put('syllabus',\%syllabus,$cdom,$cnum);
- }
+ if ($url) {
+ $field.=$url."\n";
+ }
+ }
+ $syllabus->{$syl_field}=$field;
+ }
+ }
+ my $now = time;
+ $syllabus->{'uploaded.domain'}=$env{'user.domain'};
+ $syllabus->{'uploaded.name'}=$env{'user.name'};
+ $syllabus->{'uploaded.lastmodified'} = $now;
+ my $putres = &Apache::lonnet::put('syllabus',$syllabus,$cdom,$cnum);
+ if ($putres eq 'ok') {
+ ($uploaded,$minimal,$external) =
+ &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
+ $minimal,$external);
+ $output = '
'.
+ &Apache::lonhtmlcommon::confirm_success(&mt('Template saved.')).
+ '
';
+ } else {
+ $output = '
'.
+ &mt('An error occurred storing the template: [_1]',$putres).
+ '
';
+ }
+ } elsif ($env{'form.choice'} eq 'url') {
+ if ($env{'form.externalsyllabus'} =~ m{^https?://}) {
+ if ($env{'form.externalsyllabus'} eq $external) {
+ $output = '
'.
+ &mt('External URL unchanged.').
+ '
';
+ ($uploaded,$minimal,$external) =
+ &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
+ $minimal,$external);
+ } else {
+ $external=$env{'form.externalsyllabus'};
+ $external =~ s/(`)//g;
+ my $putres =
+ &Apache::lonnet::put('environment',{externalsyllabus=>$external},
+ $cdom,$cnum);
+ if ($putres eq 'ok') {
+ &Apache::lonnet::appenv({'course.'.$env{'request.course.id'}.'.externalsyllabus' => $external});
+ $output = '
'.
+ &Apache::lonhtmlcommon::confirm_success(&mt('External URL saved.')).
+ '
';
+ ($uploaded,$minimal,$external) =
+ &update_syllabus_env($cdom,$cnum,$courseenv,$env{'form.choice'},$uploaded,
+ $minimal,$external);
+ } else {
+ $output = '
'.
+ &mt('An error occurred storing the external URL: [_1]',$putres).
+ '
';
+ }
+ }
+ } else {
+ $output = '
'.
+ &mt('External URL not saved -- invalid URL.').
+ '
';
+ }
+ } elsif (($env{'form.choice'} eq 'file') || ($env{'form.choice'} eq 'minimal')) {
+ # Process file upload - phase one - upload and parse primary file.
+ my ($upload_result,$uploadphase,$url,$needlink,$error,$errormsg);
+ if ($env{'form.choice'} eq 'file') {
+ if ($env{'form.syllabusfile.filename'}) {
+ my %allfiles = ();
+ my %codebase = ();
+ ($url,$needlink) = &process_upload(\$output,$cnum,$cdom,
+ \%allfiles,\%codebase);
+ } else {
+ $output = '
';
+ &mt('No file uploaded').
+ '
';
+ }
+ } elsif ($env{'form.choice'} eq 'minimal') {
+ my $title = $env{'form.syllabustitle'};
+ $title =~ s{`}{}g;
+ $title=~s/^\s+//;
+ $title=~s/\s+$//;
+ if ($title eq '') {
+ $title = &mt('Syllabus');
+ }
+ my $initialtext = &mt('Replace with your own content.');
+ my $newhtml = <
+
+$title
+
+
+$title
+$initialtext
+
+