'.
- &mt('Dump '.$type.
- ' DOCS to Construction Space: available on other servers').
- '
';
- }
-}
-
sub clean {
my ($title)=@_;
$title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
- return $title;
+ return $title;
}
+sub default_folderpath {
+ my ($coursenum,$coursedom,$navmapref) = @_;
+ return unless ($coursenum && $coursedom && ref($navmapref));
+# Check if entire course is hidden and/or encrypted
+ my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
+ my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
+ unless (ref($$navmapref)) {
+ $$navmapref = Apache::lonnavmaps::navmap->new();
+ }
+ if (ref($$navmapref)) {
+ if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
+ my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
+ my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
+ unless (@resources) {
+ $hiddenmap = 1;
+ unless ($env{'request.role.adv'}) {
+ $hiddentop = 1;
+ if ($env{'form.folder'}) {
+ undef($env{'form.folder'});
+ }
+ }
+ }
+ }
+ if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
+ $encryptmap = 1;
+ }
+ }
+ unless ($hiddentop) {
+ $folderpath='default&'.&escape(&mt('Main Content')).
+ '::'.$hiddenmap.':'.$encryptmap.'::';
+ }
+ if (wantarray) {
+ return ($folderpath,$hiddentop);
+ } else {
+ return $folderpath;
+ }
+}
+sub validate_supppath {
+ my ($coursenum,$coursedom) = @_;
+ my $backto;
+ if ($env{'form.supppath'} ne '') {
+ my @items = split(/\&/,$env{'form.supppath'});
+ my ($badpath,$got_supp,$supppath,%supphidden,%suppids);
+ for (my $i=0; $i<@items; $i++) {
+ my $odd = $i%2;
+ if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
+ $badpath = 1;
+ last;
+ } elsif ($odd) {
+ my $suffix;
+ my $idx = $i-1;
+ if ($items[$i] =~ /^([^:]*)::(|1):::$/) {
+ $backto .= '&'.$1;
+ } elsif ($items[$idx] eq 'supplemental') {
+ $backto .= '&'.$items[$i];
+ } else {
+ $backto .= '&'.$items[$i];
+ my $is_hidden;
+ unless ($got_supp) {
+ my ($supplemental) = &Apache::loncommon::get_supplemental($coursenum,$coursedom);
+ if (ref($supplemental) eq 'HASH') {
+ if (ref($supplemental->{'hidden'}) eq 'HASH') {
+ %supphidden = %{$supplemental->{'hidden'}};
+ }
+ if (ref($supplemental->{'ids'}) eq 'HASH') {
+ %suppids = %{$supplemental->{'ids'}};
+ }
+ }
+ $got_supp = 1;
+ }
+ if (ref($suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}) eq 'ARRAY') {
+ my $mapid = $suppids{"/uploaded/$coursedom/$coursenum/$items[$idx].sequence"}->[0];
+ if ($supphidden{$mapid}) {
+ $is_hidden = 1;
+ }
+ }
+ $suffix = '::'.$is_hidden.':::';
+ }
+ $supppath .= '&'.$items[$i].$suffix;
+ } else {
+ $supppath .= '&'.$items[$i];
+ $backto .= '&'.$items[$i];
+ }
+ }
+ if ($badpath) {
+ delete($env{'form.supppath'});
+ } else {
+ $supppath =~ s/^\&//;
+ $backto =~ s/^\&//;
+ $env{'form.supppath'} = $supppath;
+ }
+ }
+ return $backto;
+}
sub dumpcourse {
my ($r) = @_;
- my $type = &Apache::loncommon::course_type();
- $r->print(&Apache::loncommon::start_page('Dump '.$type.' DOCS to Construction Space').
- '');
+ my $formname = 'dumpdoc';
+ my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash).
+ ''."\n";
+ my %uploadedfiles;
+ &tiehash();
+ foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
+ my ($ext)=($file=~/\.(\w+)$/);
+# FIXME Check supplemental here
+ my $title=$hash{'title_'.$hash{
+ 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
+ if (!$title) {
+ $title=$file;
+ } else {
+ $title=~s|/|_|g;
+ }
+ $title=~s/\.(\w+)$//;
+ $title=&clean($title);
+ $title.='.'.$ext;
+# $r->print("\n
"
+ $uploadedfiles{$file} = $title;
+ }
+ &untiehash();
+ $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
+ undef,undef,$preamble,$home,\%uploadedfiles));
+ }
}
+ $r->print(&endContentScreen());
}
-
-
-sub exportbutton {
- my $type = &Apache::loncommon::course_type();
- return ''.
- &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').' ';
-}
-
-
-
-sub exportcourse {
- my $r=shift;
- my $type = &Apache::loncommon::course_type();
- my %discussiontime = &Apache::lonnet::dump('discussiontimes',
- $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
- my $numdisc = keys(%discussiontime);
- my $navmap = Apache::lonnavmaps::navmap->new();
- if (!defined($navmap)) {
- $r->print(&Apache::loncommon::start_page('Export '.$type.' to IMS Package').
- '
'.&mt('IMS Export Failed').'
'.
- '
');
- if ($crstype eq 'Community') {
- $r->print(&mt('Unable to retrieve information about community contents'));
- } else {
- $r->print(&mt('Unable to retrieve information about course contents'));
- }
- $r->print('
'.&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 {
- $$message = 'Could not render '.$url.' server message - '.$rtncode." \n";
+ $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);
}
- } elsif ($caller eq 'noedit') {
-# Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this.
- $repstatus = 'ok';
- $content = 'Not the owner of this resource';
}
- if ($repstatus eq 'ok') {
- print $copiedfile $content;
+ 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 $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 {
+ $path = join('/',@items);
+ }
+ $dirs_by_depth[$depth]{$path}{$dir} = 1;
}
- 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
+ foreach my $path (keys(%files)) {
+ next if ($path eq '');
+ my $depth;
+ if ($path eq '/') {
+ $depth = 0;
} else {
- $embed_url = $dirpath.$embed_file; # points to relative path
+ $depth = scalar(split(/\//,$path));
+ }
+ if (ref($files{$path}) eq 'HASH') {
+ foreach my $file (keys(%{$files{$path}})) {
+ $files_by_depth[$depth]{$path}{$file} = $files{$path}{$file};
+ }
}
}
- 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';
+ 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 ++;
+ }
+ }
+ }
}
- } elsif ($caller eq 'uploaded') {
-
- $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode);
}
- if ($repstatus eq 'ok') {
- my $destination = $tempexport.'/resources/'.$count.'/res';
- if (!-e "$destination") {
- mkdir($destination,0755);
+ if ($readonly) {
+ $disabled = ' disabled="disabled"';
+ }
+ if ($disabled) {
+ $togglebuttons = ' ';
+ } else {
+ $togglebuttons = ''.
+ ' ';
+ }
+ my $preamble = &authorspace_selector($r,$formname,$home,$title,%outhash).
+ &courseresource_options($formname,$numpub).
+ ''."\n";
+ my $display = '