--- loncom/interface/loncommon.pm 2013/04/30 13:25:45 1.1075.2.34 +++ loncom/interface/loncommon.pm 2013/05/10 23:18:42 1.1075.2.35 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.1075.2.34 2013/04/30 13:25:45 raeburn Exp $ +# $Id: loncommon.pm,v 1.1075.2.35 2013/05/10 23:18:42 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -9532,18 +9532,23 @@ sub ask_for_embedded_content { my $heading = &mt('Upload embedded files'); my $buttontext = &mt('Upload'); - my $navmap; + my ($navmap,$cdom,$cnum); if ($env{'request.course.id'}) { - $navmap = Apache::lonnavmaps::navmap->new(); + if ($actionurl eq '/adm/dependencies') { + $navmap = Apache::lonnavmaps::navmap->new(); + } + $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; } - if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) { + if (($actionurl eq '/adm/portfolio') || + ($actionurl eq '/adm/coursegrp_portfolio')) { my $current_path='/'; if ($env{'form.currentpath'}) { $current_path = $env{'form.currentpath'}; } if ($actionurl eq '/adm/coursegrp_portfolio') { - $udom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - $uname = $env{'course.'.$env{'request.course.id'}.'.num'}; + $udom = $cdom; + $uname = $cnum; $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio'; } else { $udom = $env{'user.domain'}; @@ -9575,24 +9580,43 @@ sub ask_for_embedded_content { } } elsif ($actionurl eq '/adm/dependencies') { if ($env{'request.course.id'} ne '') { - $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; if (ref($args) eq 'HASH') { $url = $args->{'docs_url'}; $title = $args->{'docs_title'}; - $toplevel = "/$url"; + $toplevel = $url; + unless ($toplevel =~ m{^/}) { + $toplevel = "/$url"; + } ($rem) = ($toplevel =~ m{^(.+/)[^/]+$}); - ($path) = - ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/}); + if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) { + $path = $1; + } else { + ($path) = + ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/}); + } $fileloc = &Apache::lonnet::filelocation('',$toplevel); $fileloc =~ s{^/}{}; ($filename) = ($fileloc =~ m{.+/([^/]+)$}); $heading = &mt('Status of dependencies in [_1]',"$title ($filename)"); } } + } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") { + $udom = $cdom; + $uname = $cnum; + $url = "/uploaded/$cdom/$cnum/portfolio/syllabus"; + $toplevel = $url; + $path = $url; + $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/'; + $fileloc =~ s{^/}{}; + } } - my $now = time(); - foreach my $embed_file (keys(%{$allfiles})) { + foreach my $file (keys(%{$allfiles})) { + my $embed_file; + if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) { + $embed_file = $1; + } else { + $embed_file = $file; + } my $absolutepath; if ($embed_file =~ m{^\w+://}) { $newfiles{$embed_file} = 1; @@ -9630,7 +9654,8 @@ sub ask_for_embedded_content { my $dirptr = 16384; foreach my $path (keys(%subdependencies)) { $currsubfile{$path} = {}; - if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) { + if (($actionurl eq '/adm/portfolio') || + ($actionurl eq '/adm/coursegrp_portfolio')) { my ($sublistref,$listerror) = &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath); if (ref($sublistref) eq 'ARRAY') { @@ -9646,9 +9671,15 @@ sub ask_for_embedded_content { } } elsif (($actionurl eq '/adm/dependencies') || (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') && - ($args->{'context'} eq 'paste'))) { + ($args->{'context'} eq 'paste')) || + ($actionurl eq "/public/$cdom/$cnum/syllabus")) { if ($env{'request.course.id'} ne '') { - my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$}); + my $dir; + if ($actionurl eq "/public/$cdom/$cnum/syllabus") { + $dir = $fileloc; + } else { + ($dir) = ($fileloc =~ m{^(.+/)[^/]+$}); + } if ($dir ne '') { my ($sublistref,$listerror) = &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/'); @@ -9696,7 +9727,8 @@ sub ask_for_embedded_content { } } my %currfile; - if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) { + if (($actionurl eq '/adm/portfolio') || + ($actionurl eq '/adm/coursegrp_portfolio')) { my ($dirlistref,$listerror) = &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath); if (ref($dirlistref) eq 'ARRAY') { @@ -9712,7 +9744,8 @@ sub ask_for_embedded_content { } } elsif (($actionurl eq '/adm/dependencies') || (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') && - ($args->{'context'} eq 'paste'))) { + ($args->{'context'} eq 'paste')) || + ($actionurl eq "/public/$cdom/$cnum/syllabus")) { if ($env{'request.course.id'} ne '') { my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$}); if ($dir ne '') { @@ -9747,12 +9780,14 @@ sub ask_for_embedded_content { ($file eq $filename.'.bak') || ($dependencies{$file})) { if ($actionurl eq '/adm/dependencies') { - next if (($rem ne '') && - (($env{"httpref.$rem".$file} ne '') || - (ref($navmap) && - (($navmap->getResourceByUrl($rem.$file) ne '') || - (($file =~ /^(.*\.s?html?)\.bak$/i) && - ($navmap->getResourceByUrl($rem.$1))))))); + unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) { + next if (($rem ne '') && + (($env{"httpref.$rem".$file} ne '') || + (ref($navmap) && + (($navmap->getResourceByUrl($rem.$file) ne '') || + (($file =~ /^(.*\.s?html?)\.bak$/i) && + ($navmap->getResourceByUrl($rem.$1))))))); + } } $unused{$file} = 1; } @@ -9762,27 +9797,37 @@ sub ask_for_embedded_content { $counter = scalar(keys(%existing)); $numpathchg = scalar(keys(%pathchanges)); return ($output,$counter,$numpathchg,\%existing); + } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") && + (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) { + $counter = scalar(keys(%existing)); + $numpathchg = scalar(keys(%pathchanges)); + return ($output,$counter,$numpathchg,\%existing,\%mapping); } foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) { if ($actionurl eq '/adm/dependencies') { next if ($embed_file =~ m{^\w+://}); } $upload_output .= &start_data_table_row(). - ' '. + ' '. ''.$embed_file.''; unless ($mapping{$embed_file} eq $embed_file) { - $upload_output .= '
'.&mt('changed from: [_1]',$mapping{$embed_file}).''; + $upload_output .= '
'. + &mt('changed from: [_1]',$mapping{$embed_file}).''; } - $upload_output .= ''; + $upload_output .= ''; if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) { - $upload_output.=''.&mt("URL points to other server.").''; + $upload_output.=''. + ''. + &mt("URL points to web address").''; $numremref++; } elsif ($args->{'error_on_invalid_names'} && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) { - $upload_output.=''.&mt('Invalid characters').''; + $upload_output.=''. + &mt('Invalid characters').''; $numinvalid++; } else { - $upload_output .= &embedded_file_element('upload_embedded',$counter, + $upload_output .= ''. + &embedded_file_element('upload_embedded',$counter, $embed_file,\%mapping, $allfiles,$codebase,'upload'); $counter ++; @@ -9811,8 +9856,9 @@ sub ask_for_embedded_content { $counter ++; } else { $upload_output .= &start_data_table_row(). - ''.$embed_file.''; - ''.&mt('Already exists').''. + ' '. + ''.$embed_file.''. + ''.&mt('Already exists').''. &Apache::loncommon::end_data_table_row()."\n"; } } @@ -9907,7 +9953,7 @@ sub ask_for_embedded_content { $output = ''.&mt('Referenced files').':
'; if ($applies > 1) { $output .= - &mt('No files need to be uploaded, as one of the following applies to each reference:').'