'.&mt('Target directory: [_1] name is already in a use for a file -- not overwriting.',
+ ''.$desturl.'/'.$subdir.'/'.$file.'').
+ '
'."\n");
+ } elsif (($src ne '') && ($dest ne '')) {
+ my $ressrc = $docroot.$resurl.'/'.$file;
+ my $ressrcmeta = $ressrc.'.meta';
+ my ($ext) = ($file =~ /\.(\w+)$/);
+ my $embstyle=&Apache::loncommon::fileembstyle($ext);
+ my ($getres,$getresmeta);
+ if ($respublish) {
+ if ($path eq '') {
+ if ((ref($resfiles{'/'}) eq 'HASH') &&
+ (exists($resfiles{'/'}{$fname}))) {
+ $getres = 1;
+ $getresmeta = 1;
+ }
+ } elsif ((ref($resfiles{$path}) eq 'HASH') &&
+ (exists($resfiles{$path}{$fname}))) {
+ $getres = 1;
+ $getresmeta = 1;
+ }
+ }
+ if ($is_course_home) {
+ my ($needpriv,$needprivmeta);
+ if ($respublish) {
+ if ($getres) {
+ if (&Apache::londiff::are_different_files($src,$ressrc)) {
+ $needpriv = 1;
+ if (&File::Copy::copy($ressrc,$dest)) {
+ if ($embstyle eq 'ssi') {
+ &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd);
+ }
+ }
+ } else {
+ if (&File::Copy::copy($src,$dest)) {
+ $newfile{$file} = $desturl.'/'.$subdir.'/'.$file;
+ if ($embstyle eq 'ssi') {
+ &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
+ }
+ }
+ }
+ } else {
+ $needpriv = 1;
+ }
+ if ($getresmeta) {
+ if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
+ if (&Apache::londiff::are_different_files($src.'.meta',$ressrc.'.meta')) {
+ if (&File::Copy::copy($ressrc.'.meta',$dest.'.meta')) {
+ &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
+ $customdistfile,$sourceavail,\%checkdeps);
+ }
+ $needprivmeta = 1;
+ } else {
+ if (&File::Copy::copy($src.'.meta',$dest.'.meta')) {
+ &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
+ $customdistfile,$sourceavail,\%checkdeps);
+ }
+ }
+ }
+ }
+ if ($getres) {
+ my $destresfile = $docroot.$destresurl.'/'.$subdir.'/'.$file;
+ if (-e $dest) {
+ my $output = &Apache::lonpublisher::batchpublish($r,$dest,$destresfile,$nokeyref,1);
+ if (-e $destresfile) {
+ $newresfile{$file} = $destresurl.'/'.$subdir.'/'.$file;
+ }
+ }
+ }
+ } else {
+ $needpriv = 1;
+ if ((-e $src.'.meta') && (!-e $dest.'.meta')) {
+ $needprivmeta = 1;
+ }
+ }
+ if ($needpriv) {
+ if (&File::Copy::copy($src,$dest)) {
+ $newfile{$file} = $desturl.'/'.$subdir.'/'.$file;
+ if ($embstyle eq 'ssi') {
+ &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
+ }
+ }
+ }
+ if ($needprivmeta) {
+ if (&File::Copy::copy($src.'.meta',$dest.'.meta')) {
+ &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
+ $customdistfile,$sourceavail,\%checkdeps);
+ }
+ }
+ } else {
+ my ($needpriv,$needprivmeta);
+ if ($respublish) {
+ if ($getres) {
+ &Apache::lonnet::repcopy($docroot.$resurl.'/'.$file);
+ }
+ if ($getresmeta) {
+ &Apache::lonnet::repcopy($docroot.$resurl.'/'.$file.'.meta');
+ }
+ if (-e $docroot.$resurl.'/'.$file) {
+ if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file,$dest) eq 'ok') {
+ if (&Apache::londiff::are_different_files($docroot.$resurl.'/'.$file,$dest)) {
+ $needpriv = 1;
+ if (&File::Copy::copy($docroot.$resurl.'/'.$file,$dest)) {
+ if ($embstyle eq 'ssi') {
+ &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd);
+ }
+ }
+ } else {
+ if ($embstyle eq 'ssi') {
+ &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
+ }
+ $newfile{$file} = $desturl.'/'.$subdir.'/'.$file;
+ }
+ }
+ } else {
+ $needpriv = 1;
+ }
+ if (-e $docroot.$resurl.'/'.$file.'.meta') {
+ if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file.'.meta',$dest.'.meta') eq 'ok') {
+ if (&Apache::londiff::are_different_files($docroot.$resurl.'/'.$file.'.meta',$dest.'.meta')) {
+ $needprivmeta = 1;
+ if (&File::Copy::copy($docroot.$resurl.'/'.$file.'.meta',$dest.'.meta')) {
+ &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
+ $customdistfile,$sourceavail,\%checkdeps);
+ }
+ } else {
+ &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
+ $customdistfile,$sourceavail,\%checkdeps);
+ }
+ }
+ } else {
+ if (!-e $dest.'.meta') {
+ $needprivmeta = 1;
+ }
+ }
+ if ($getres) {
+ my $destresfile = $docroot.$destresurl.'/'.$subdir.'/'.$file;
+ if (-e $dest) {
+ my $output = &Apache::lonpublisher::batchpublish($r,$dest,$destresfile,$nokeyref,1);
+ if (-e $destresfile) {
+ $newresfile{$file} = $destresurl.'/'.$subdir.'/'.$file;
+ }
+ }
+ }
+ } else {
+ $needpriv = 1;
+ if (!-e $dest.'.meta') {
+ $needprivmeta = 1;
+ }
+ }
+ if ($needpriv) {
+ if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file,$dest) eq 'ok') {
+ if ($embstyle eq 'ssi') {
+ &crsres_fixup($dest,$coursenum,$coursedom,$ca,$cd,$subdir);
+ }
+ $newfile{$file} = $desturl.'/'.$subdir.'/'.$file;
+ }
+ }
+ if ($needprivmeta) {
+ if (&Apache::lonnet::repcopy_crsprivfile($srcurl.'/'.$file.'.meta',$dest.'.meta') eq 'ok') {
+ &crsres_fixup_meta($dest,$coursenum,$coursedom,$ca,$cd,$copyright,
+ $customdistfile,$sourceavail,\%checkdeps);
+ }
+ }
+ }
+ }
+ }
+ } else {
+ $notopdir = 1;
+ }
+ }
+ if ($notopdir) {
+ $r->print('
'.&mt('No files or sub-directories copied').' '."\n".
+ ''.&mt('Target directory: [_1] does not exist, and could not be created.',
+ ''.$desturl.'/'.$subdir.'').
+ '
'."\n");
+ }
+ if (keys(%newdir)) {
+ $r->print('
'.&mt('Created the following directories in [_1]:',''.$desturl.'/'.$subdir.'').
+ '
'."\n".
+ '
'.join('
',sort(keys(%newdir))).'
'."\n");
+ }
+ if (keys(%newfile)) {
+ $r->print('
'.&mt('Copied the following files to [_1]:',''.$desturl.'/'.$subdir.'').
+ '
'."\n".
+ '
'.join('
',sort(keys(%newfile))).'
'."\n");
+ foreach my $file (keys(%newfile)) {
+ my %storehash = (
+ 'priv' => $newfile{$file},
+ 'who' => $env{'user.name'}.':'.$env{'user.domain'},
+ );
+ if (exists($newresfile{$file})) {
+ $storehash{'res'} = 1;
+ }
+ &Apache::lonnet::store_userdata(\%storehash,$file,'copycourseauthor',$coursedom,$coursenum);
+ }
+ }
+ if (keys(%checkdeps)) {
+ my %missingdep;
+ foreach my $depfile (sort(keys(%checkdeps))) {
+ unless (-e "$desttop/$depfile") {
+ $missingdep{$depfile} = 1;
+ }
+ }
+ if (keys(%missingdep)) {
+ $r->print('
'.&mt('You may also need to copy the following missing dependencies for files copied to [_1]:',
+ ''.$desturl.'/'.$subdir.'').
+ '
'."\n".
+ '
'.join('
',sort(keys(%missingdep))).'
'."\n");
+ }
}
- close($copiedfile);
} else {
- $$message = 'Could not open destination file for '.$filename." \n";
+ $r->print('
'.&mt('No currently existing files or directories in Course Authoring Space selected for copying').'
');
+ $r->print(&endContentScreen());
+ return '';
}
} else {
- $$message = 'Could not determine name of file for '.$symb." \n";
- }
- if ($repstatus eq 'ok') {
- $content_name = 'resources/'.$count.'/'.$filename;
- }
- return $content_name;
-}
-
-sub extract_media {
- my ($url,$cdom,$cnum,$content,$count,$tempexport,$href,$message,$caller) = @_;
- my ($dirpath,$container);
- my %allfiles = ();
- my %codebase = ();
- if ($url =~ m-(.*/)([^/]+)$-) {
- $dirpath = $1;
- $container = $2;
- } else {
- $dirpath = $url;
- $container = '';
- }
- &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,$content);
- foreach my $embed_file (keys(%allfiles)) {
- my $filename;
- if ($embed_file =~ m#([^/]+)$#) {
- $filename = $1;
- } else {
- $filename = $embed_file;
- }
- my $newname = 'res/'.$filename;
- my ($rtncode,$embed_content,$repstatus);
- my $embed_url;
- if ($embed_file =~ m-^/-) {
- $embed_url = $embed_file; # points to absolute path
- } else {
- if ($embed_file =~ m-https?://-) {
- next; # points to url
+ my $chkname = 'copytouser';
+ my $context = 'crsauthored';
+ my (%subdirs,%files,@dirs_by_depth,@files_by_depth,%parent,%children,%hierarchy,@checked_maps);
+ &Apache::lonnet::recursedirs($is_course_home,1,undef,$exclude,0,0,$srcurl,'',\%subdirs,\%files,1);
+ foreach my $key (keys(%subdirs)) {
+ next if (($key eq '/') || ($key eq ''));
+ my @items = split(/\//,$key);
+ my $dir = pop(@items);
+ my $depth = scalar(@items);
+ my $path;
+ if (!$depth) {
+ $path = '/';
} else {
- $embed_url = $dirpath.$embed_file; # points to relative path
- }
- }
- if ($caller eq 'resource') {
- my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
- my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url);
- $embed_content = &Apache::lonnet::getfile($embed_path);
- unless ($embed_content eq -1) {
- $repstatus = 'ok';
+ $path = join('/',@items);
}
- } elsif ($caller eq 'uploaded') {
-
- $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode);
+ $dirs_by_depth[$depth]{$path}{$dir} = 1;
}
- if ($repstatus eq 'ok') {
- my $destination = $tempexport.'/resources/'.$count.'/res';
- if (!-e "$destination") {
- mkdir($destination,0755);
+ foreach my $path (keys(%files)) {
+ next if ($path eq '');
+ my $depth;
+ if ($path eq '/') {
+ $depth = 0;
+ } else {
+ $depth = scalar(split(/\//,$path));
}
- $destination .= '/'.$filename;
- my $copiedfile;
- if ($copiedfile = Apache::File->new('>'.$destination)) {
- print $copiedfile $embed_content;
- push @{$href}, 'resources/'.$count.'/res/'.$filename;
- my $attrib_regexp = '';
- if (@{$allfiles{$embed_file}} > 1) {
- $attrib_regexp = join('|',@{$allfiles{$embed_file}});
- } else {
- $attrib_regexp = $allfiles{$embed_file}[0];
+ if (ref($files{$path}) eq 'HASH') {
+ foreach my $file (keys(%{$files{$path}})) {
+ $files_by_depth[$depth]{$path}{$file} = $files{$path}{$file};
}
- $$content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$embed_file\E(['"]?)#$1$newname$2#gi;
- if ($caller eq 'resource' && $container =~ /\.(problem|library)$/) {
- $$content =~ s#\Q$embed_file\E#$newname#gi;
+ }
+ }
+ my ($info,$display,$onsubmit,$togglebuttons,$disabled);
+ my (%resdirs,%resfiles);
+ &Apache::lonnet::recursedirs($is_course_home,1,undef,$res_exclude,0,0,$resurl,'',\%resdirs,\%resfiles);
+ my $numpub = 0;
+ if (keys(%resfiles)) {
+ foreach my $dir (keys(%resfiles)) {
+ if (ref($resfiles{$dir}) eq 'HASH') {
+ foreach my $file (keys(%{$resfiles{$dir}})) {
+ if (exists($files{$dir}{$file})) {
+ $numpub ++;
+ }
+ }
}
}
+ }
+ if ($readonly) {
+ $disabled = ' disabled="disabled"';
+ }
+ if ($disabled) {
+ $togglebuttons = ' ';
} else {
- $$message .= 'replication of embedded file - '.$embed_file.' in '.$url.' failed, reason -'.$rtncode." \n";
+ $togglebuttons = ''.
+ ' ';
+ }
+ my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash).
+ &courseresource_options($formname,$numpub).
+ ''."\n";
+ my $display = '