--- loncom/interface/londocs.pm 2012/06/30 23:11:11 1.488 +++ loncom/interface/londocs.pm 2012/07/05 21:33:39 1.489 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.488 2012/06/30 23:11:11 raeburn Exp $ +# $Id: londocs.pm,v 1.489 2012/07/05 21:33:39 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -438,7 +438,7 @@ sub docs_change_log { ''."\n"; $r->print(&Apache::loncommon::start_page('Content Change Log',$js)); $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log')); - $r->print(&startContentScreen('docs')); + $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs'))); my %orderhash; my $container='sequence'; my $pathitem; @@ -457,6 +457,9 @@ sub docs_change_log { my $jumpto = $readfile; $jumpto =~ s{^/}{}; my $tid = 1; + if ($supplementalflag) { + $tid = 2; + } my ($breadcrumbtrail) = &breadcrumbs($allowed,$crstype); $r->print($breadcrumbtrail. &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto, @@ -729,7 +732,9 @@ sub do_paste_from_buffer { my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'}); my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'}); # Maps need to be copied first - my ($oldurl,%removefrommap,%addedmaps,%rewrites,%copies,%dbcopies,%zombies,%params); + my ($oldurl,%removefrommap,%addedmaps,%rewrites,%copies,%dbcopies,%zombies,%params, + %moves,$srcdom,$srcnum); + $oldurl = $url; if ($url=~/\.(page|sequence)$/) { # If pasting a map, check if map contains other maps &contained_map_check($url,$folder,\%removefrommap,\%addedmaps); @@ -770,10 +775,12 @@ sub do_paste_from_buffer { } if ($is_unique) { if ($path =~ m{^/uploaded/($match_domain)/($match_courseid)/$}) { - my $srcdom = $1; - my $srcnum = $2; - if (($srcdom ne $coursedom) && ($srcnum ne $coursenum)) { - if (&Apache::lonnet::allowed('mdc',$srcdom.'_'.$srcnum)) { + $srcdom = $1; + $srcnum = $2; + if (($1 ne $coursedom) && ($2 ne $coursenum)) { + my $srcdom = $1; + my $srcnum = $2; + if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) { &url_paste_fixups($oldid,$ext,$coursedom,$coursenum, \%allmaps, \%rewrites,\%copies,\%dbcopies,\%zombies,\%params); } else { @@ -808,6 +815,14 @@ sub do_paste_from_buffer { return &mt('Paste failed: only one instance of a particular published sequence or page is allowed within each course.'); } } + } elsif ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) { + if (($1 ne $coursedom) || ($2 ne $coursenum)) { + $srcdom = $1; + $srcnum = $2; + unless ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) { + return &mt('Paste failed: Item is from a different course which you do not have rights to edit'); + } + } } if ($url=~ m{/smppg$}) { my $db_name = &Apache::lonsimplepage::get_db_name($url); @@ -822,20 +837,22 @@ sub do_paste_from_buffer { $title=&mt('Copy of').' '.$title; } } + my ($relpath,$oldprefix,$prefixchg); + if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(.+)$}) { + $oldprefix = $1; + $relpath = $2; + if (($folder =~ /^supplemental/) && ($oldprefix eq 'docs')) { + $prefixchg = 1; + } elsif (($folder =~ /^default/) && ($oldprefix eq 'supplemental')) { + $prefixchg = 1; + } + } $title = &LONCAPA::map::qtunescape($title); my $ext='false'; if ($url=~m{^http(|s)://}) { $ext='true'; } $url = &LONCAPA::map::qtunescape($url); # Now insert the URL at the bottom my $newidx = &LONCAPA::map::getresidx($url); - my $relpath; - if (($folder =~ /^supplemental/) && - ($url =~ m{^/uploaded/$coursedom/$coursenum/docs/(.+)})) { - $relpath = $1; - } elsif (($folder =~ /^default/) && - ($url =~ m{^/uploaded/$coursedom/$coursenum/supplemental/(.+)})) { - $relpath = $1; - } if ($relpath ne '') { my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$}); my ($newloc,$newsubdir) = ($folder =~ /^(default|supplemental)_?(\d*)/); @@ -846,19 +863,26 @@ sub do_paste_from_buffer { if ($newsubdir eq '') { $newsubdir = 'default'; } - my $newpath = "$newprefix/$newsubdir/$newidx/$rem"; - $url = - &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath, - &Apache::lonnet::getfile($url)); - if ($url eq '/adm/notfound.html') { - return &mt('Paste failed: an error occurred saving the file.'); + if (($prefixchg) || ($srcdom ne '') && ($srcnum ne '')) { + my $newpath = "$newprefix/$newsubdir/$newidx/$rem"; + $url = + &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath, + &Apache::lonnet::getfile($oldurl)); + if ($url eq '/adm/notfound.html') { + return &mt('Paste failed: an error occurred saving the file.'); + } else { + my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$}); + $newsubpath =~ s{/+$}{/}; + $moves{$oldurl} = $newsubpath; + } } } my $noparams = 0; if ((ref($params{$oldurl}) eq 'HASH') && ($relpath ne '') && ($folder =~ /^supplemental/)) { $noparams = 1; } - &apply_fixups($coursedom,$coursenum,$oldurl,$url,$noparams,\%rewrites,\%copies,\%dbcopies,\%zombies,\%params); + &apply_fixups($coursedom,$coursenum,$oldurl,$url,$noparams,\%rewrites,\%copies, + \%dbcopies,\%zombies,\%params,\%moves); if ($env{'docs.markedcopy_supplemental'}) { if ($folder =~ /^supplemental/) { $title = $env{'docs.markedcopy_supplemental'}; @@ -978,6 +1002,7 @@ sub url_paste_fixups { $rewrites->{$oldurl}{$ressrc} = $id; &url_paste_fixups($ressrc,$3,$cdom,$cnum,$allmaps,$rewrites,$copies,$dbcopies,$zombies,$params); } else { + $rewrites->{$oldurl}{$ressrc} = $id; $copies->{$oldurl}{$ressrc} = $id; } } @@ -1011,38 +1036,68 @@ sub url_paste_fixups { } sub apply_fixups { - my ($cdom,$cnum,$oldurl,$url,$noparams,$rewrites,$copies,$dbcopies,$zombies,$params) = @_; + my ($cdom,$cnum,$oldurl,$url,$noparams,$rewrites,$copies,$dbcopies,$zombies,$params, + $moves) = @_; my (%newdb,%newdoc); if (ref($dbcopies->{$oldurl}) eq 'HASH') { foreach my $item (keys(%{$dbcopies->{$oldurl}})) { $newdb{$item} = &dbcopy($item); } } + my @allcopies; if (ref($copies->{$oldurl}) eq 'HASH') { - foreach my $item (keys(%{$copies->{$oldurl}})) { + push(@allcopies,keys(%{$copies->{$oldurl}})); + } + if ((ref($moves) eq 'HASH') && (exists($moves->{$oldurl}))) { + push(@allcopies,$oldurl); + } + if (@allcopies > 0) { + foreach my $item (@allcopies) { my $content = &Apache::lonnet::getfile($item); - my $newcontent; unless ($content eq '-1') { my $mm = new File::MMagic; my $mimetype = $mm->checktype_contents($content); if ($mimetype eq 'text/html') { my (%allfiles,%codebase,$state); - my ($embedded,$num,$delnum) = - &Apache::loncommon::ask_for_embedded_content( - '/adm/dependencies',$state,\%allfiles,\%codebase, - {'error_on_invalid_names' => 1, - 'ignore_remote_references' => 1, - 'docs_url' => $oldurl}); - if ($embedded) { - #FIXME Need to check for dependencies and copy and update refs. + if (&Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content) eq 'ok') { + my ($numexisting,$numpathchanges,$existing); + (undef,$numexisting,$numpathchanges,$existing) = + &Apache::loncommon::ask_for_embedded_content( + '/adm/coursedocs',$state,\%allfiles,\%codebase, + {'error_on_invalid_names' => 1, + 'ignore_remote_references' => 1, + 'docs_url' => $oldurl, + 'context' => 'paste'}); + if ($numexisting > 0) { + if (ref($existing) eq 'HASH') { + my ($relpath) = ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(?:default|\d+)/.*/)[^/]+$}); + foreach my $dep (keys(%{$existing})) { + $dep =~ s{^\Q$relpath\E}{}; + my $depfile = $relpath.$dep; + my $depstorefn; + if ((ref($copies->{$oldurl}) eq 'HASH') && + ($copies->{$oldurl}{$item})) { + $depstorefn = $relpath; + $depstorefn =~s{^/\w+/$match_domain/$match_courseid/}{}; + } elsif ((ref($moves) eq 'HASH') && + (exists($moves->{$oldurl}))) { + $depstorefn = $moves->{$oldurl}; + } + $depstorefn .= $dep; + my $depcontent = &Apache::lonnet::getfile($depfile); + unless ($depcontent eq '-1') { + &Apache::lonclonecourse::writefile($env{'request.course.id'},$depstorefn,$depcontent); + } + } + } + } } - $newcontent = $content; - } else { - $newcontent = $content; } my $storefn=$item; - $storefn=~s{^/\w+/$match_domain/$match_courseid/}{}; - $newdoc{$item} = &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,$newcontent); + unless (exists($moves->{$oldurl})) { + $storefn=~s{^/\w+/$match_domain/$match_courseid/}{}; + $newdoc{$item} = &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,$content); + } } } }