--- loncom/interface/londocs.pm 2013/04/03 02:41:22 1.484.2.30
+++ loncom/interface/londocs.pm 2012/05/09 19:46:30 1.485
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.484.2.30 2013/04/03 02:41:22 raeburn Exp $
+# $Id: londocs.pm,v 1.485 2012/05/09 19:46:30 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -40,9 +40,7 @@ use Apache::lonxml;
use Apache::lonclonecourse;
use Apache::lonnavmaps;
use Apache::lonnavdisplay();
-use Apache::lonextresedit();
use HTML::Entities;
-use HTML::TokeParser;
use GDBM_File;
use Apache::lonlocal;
use Cwd;
@@ -69,14 +67,10 @@ sub mapread {
}
sub storemap {
- my ($coursenum,$coursedom,$map,$contentchg)=@_;
- my $report;
- if (($contentchg) && ($map =~ /^default/)) {
- $report = 1;
- }
+ my ($coursenum,$coursedom,$map)=@_;
my ($outtext,$errtext)=
&LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
- $map,1,$report);
+ $map,1);
if ($errtext) { return ($errtext,2); }
$hadchanges=1;
@@ -152,7 +146,7 @@ sub dumpcourse {
$r->print(&endContentScreen());
return '';
}
- my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
+ my ($ca,$cd)=split(/\@/,$env{'form.authorspace'});
$r->print('
'.&mt('Copying Files').'
');
my $title=$env{'form.authorfolder'};
$title=&clean($title);
@@ -270,9 +264,7 @@ sub dumpcourse {
sub group_import {
my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
- my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
- %removeparam,$importuploaded,$fixuperrors);
- $allmaps = {};
+
while (@files) {
my ($name, $url, $residx) = @{ shift(@files) };
if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
@@ -289,7 +281,7 @@ sub group_import {
$env{'form.output'}=$newmapstr;
my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
'output',$1.$2);
- if ($result !~ m{^/uploaded/}) {
+ if ($result != m|^/uploaded/|) {
$errtext.='Map not saved: A network error occurred when trying to save the new map. ';
$fatal = 2;
}
@@ -298,24 +290,6 @@ sub group_import {
}
}
if ($url) {
- if (($caller eq 'londocs') &&
- ($folder =~ /^default/)) {
- if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
- my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
- my $cid = $coursedom.'_'.$coursenum;
- $allmaps =
- &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
- $chome,$cid);
- $donechk = 1;
- }
- if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
- &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
- \%addedmaps,\%hierarchy,\%titles,$allmaps);
- $importuploaded = 1;
- } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
- next if ($allmaps->{$url});
- }
- }
if (!$residx
|| defined($LONCAPA::map::zombies[$residx])) {
$residx = &LONCAPA::map::getresidx($url,$residx);
@@ -323,92 +297,73 @@ sub group_import {
}
my $ext = 'false';
if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
+ $url = &LONCAPA::map::qtunescape($url);
$name = &LONCAPA::map::qtunescape($name);
- if ($name eq '') {
- $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
- }
- if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
- my $filepath = $1;
- my $fname = $name;
- if ($fname =~ /^\W+$/) {
- $fname = 'web';
- } else {
- $fname =~ s/\W/_/g;
- }
- if (length($fname > 15)) {
- $fname = substr($fname,0,14);
- }
- my $initialtext = &mt('Replace with your own content.');
- my $newhtml = <
-
-
-
-$name
-
-
-$initialtext
-
-
-END
- $env{'form.output'}=$newhtml;
- my $result =
- &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
- 'output',
- "$filepath/$residx/$fname.html");
- if ($result =~ m{^/uploaded/}) {
- $url = $result;
- if ($filepath =~ /^supplemental/) {
- $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
- $env{'user.domain'}.'___&&&___'.$name;
- }
- } else {
- return (&mt('Failed to save new web page.'),1);
- }
- }
- $url = &LONCAPA::map::qtunescape($url);
$LONCAPA::map::resources[$residx] =
join(':', ($name, $url, $ext, 'normal', 'res'));
}
}
- if ($importuploaded) {
- my %import_errors;
- my %updated = (
- removefrommap => \%removefrommap,
- removeparam => \%removeparam,
- );
- my ($result,$msgsarray,$lockerror) =
- &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
- if (keys(%import_errors) > 0) {
- $fixuperrors =
- '
'."\n".
- &mt('The following files are either dependencies of a web page or references within a folder and/or composite page for which errors occurred during import:')."\n".
- '
';
- return $output;
-}
-
-sub recurse_print {
- my ($outputref,$dir,$deps,$display) = @_;
- $$outputref .= $display->{$dir}."\n";
- if (ref($deps->{$dir}) eq 'ARRAY') {
- foreach my $subdir (@{$deps->{$dir}}) {
- &recurse_print($outputref,$subdir,$deps,$display);
- }
- }
-}
-
-sub supp_pasteable {
- my ($url) = @_;
- if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
- (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
- ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
- ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
- ($url =~ m{^/public/$match_domain/$match_courseid/syllabus})) {
- return 1;
- }
- return;
-}
-
-sub paste_popup_js {
- my %lt = &Apache::lonlocal::texthash(
- show => 'Show Options',
- hide => 'Hide Options',
- none => 'No items selected from clipboard.',
- );
- return <<"END";
-
-function showPasteOptions(suffix) {
- document.getElementById('pasteoptions_'+suffix).style.display='block';
- document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' $lt{'hide'}';
- return;
-}
+ my ($r,$container) = @_;
+ return if (!defined($env{'docs.markedcopy_url'}));
-function hidePasteOptions(suffix) {
- document.getElementById('pasteoptions_'+suffix).style.display='none';
- document.getElementById('pasteoptionstext_'+suffix).innerHTML =' $lt{'show'}';
- return;
-}
-
-function showOptions(caller,suffix) {
- if (document.getElementById('pasteoptionstext_'+suffix)) {
- if (caller.checked) {
- document.getElementById('pasteoptionstext_'+suffix).innerHTML =' $lt{'show'}';
- } else {
- document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
- }
- if (document.getElementById('pasteoptions_'+suffix)) {
- document.getElementById('pasteoptions_'+suffix).style.display='none';
- }
- }
- return;
-}
+ $r->print('');
}
sub do_paste_from_buffer {
- my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
-
-# Array of items in paste buffer
- my (@currpaste,%pastebuffer,%allerrors);
- @currpaste = split(/,/,$env{'docs.markedcopies'});
-
-# Early out if paste buffer is empty
- if (@currpaste == 0) {
- return ();
- }
- map { $pastebuffer{$_} = 1; } @currpaste;
-
-# Array of items selected items to paste
- my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
-
-# Early out if nothing selected to paste
- if (@reqpaste == 0) {
- return();
- }
- my @topaste;
- foreach my $suffix (@reqpaste) {
- next if ($suffix =~ /\D/);
- next unless (exists($pastebuffer{$suffix}));
- push(@topaste,$suffix);
- }
-
-# Early out if nothing available to paste
- if (@topaste == 0) {
- return();
- }
-
- my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
- %prefixchg,%srcdom,%srcnum,%marktomove,$save_err,$lockerrors,$allresult,
- %msgs);
-
- foreach my $suffix (@topaste) {
- my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
-# Supplemental content may only include certain types of content
-# Early out if pasted content is not supported in Supplemental area
- if ($folder =~ /^supplemental/) {
- unless (&supp_pasteable($url)) {
- $notinsupp{$suffix} = 1;
- next;
- }
- }
- if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
- my $srcd = $1;
- my $srcn = $2;
-# When paste buffer was populated using an active role in a different course
-# check for mdc privilege in the course from which the resource was pasted
- if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
- unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
- $notincrs{$suffix} = 1;
- next;
- }
- }
- $srcdom{$suffix} = $srcd;
- $srcnum{$suffix} = $srcn;
- }
-
- push(@dopaste,$suffix);
- if ($url=~/\.(page|sequence)$/) {
- $is_map{$suffix} = 1;
- }
-
- if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
- my $oldprefix = $1;
-# When pasting content from Main Content to Supplemental Content and vice versa
-# URLs will contain different paths (which depend on whether pasted item is
-# a folder/page or a document.
- if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
- $prefixchg{$suffix} = 'docstosupp';
- } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
- $prefixchg{$suffix} = 'supptodocs';
- }
-
-# If pasting an uploaded map, get list of contained uploaded maps.
- if ($env{'docs.markedcopy_nested_'.$suffix}) {
- my @nested;
- my ($type) = ($oldprefix =~ /^(default|supplemental)/);
- my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
- my @deps = map { /\d+:([\d,]+$)/ } @items;
- foreach my $dep (@deps) {
- if ($dep =~ /,/) {
- push(@nested,split(/,/,$dep));
- } else {
- push(@nested,$dep);
- }
- }
- foreach my $item (@nested) {
- if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
- push(@{$marktomove{$suffix}},$type.'_'.$item);
- }
- }
- }
- }
- }
-
-# Early out if nothing available to paste
- if (@dopaste == 0) {
- return ();
- }
-
-# Populate message hash and hashes used for main content <=> supplemental content
-# changes
-
- %msgs = &Apache::lonlocal::texthash (
- notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
- notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
- duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
- );
+ my ($coursenum,$coursedom,$folder) = @_;
- %before = (
- docstosupp => {
- map => 'default',
- doc => 'docs',
- },
- supptodocs => {
- map => 'supplemental',
- doc => 'supplemental',
- },
- );
-
- %after = (
- docstosupp => {
- map => 'supplemental',
- doc => 'supplemental'
- },
- supptodocs => {
- map => 'default',
- doc => 'docs',
- },
- );
-
-# Retrieve information about all course maps in main content area
-
- my $allmaps = {};
- if ($folder =~ /^default/) {
- $allmaps =
- &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
- $env{"course.$env{'request.course.id'}.home"},
- $env{'request.course.id'});
+ if (!$env{'form.pastemarked'}) {
+ return;
}
- my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
-
-# Loop over the items to paste
- foreach my $suffix (@dopaste) {
+# paste resource to end of list
+ 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 (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
- %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
- %newurls,%tomove);
- if (ref($marktomove{$suffix}) eq 'ARRAY') {
- map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
- }
- my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
- my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
- my $oldurl = $url;
- if ($is_map{$suffix}) {
-# If pasting a map, check if map contains other maps
- my (%hierarchy,%titles);
- &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
- \%addedmaps,\%hierarchy,\%titles,$allmaps);
- if ($url=~ m{^/uploaded/}) {
- my $newurl;
- unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
- ($newurl,my $error) =
- &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
- $coursenum,$srcdom{$suffix},$srcnum{$suffix},
- \$title,$allmaps,\%newurls);
- if ($error) {
- $allerrors{$suffix} = $error;
- next;
- }
- if ($newurl ne '') {
- if ($newurl ne $url) {
- if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
- $newsubdir{$url} = $1;
- }
- $mapchanges{$url} = 1;
- }
- }
- }
- if (($srcdom{$suffix} ne $coursedom) ||
- ($srcnum{$suffix} ne $coursenum) ||
- ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
- unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
- $coursedom,$coursenum,$srcdom{$suffix},
- $srcnum{$suffix},$allmaps,\%rewrites,
- \%retitles,\%copies,\%dbcopies,
- \%zombies,\%params,\%mapmoves,
- \%mapchanges,\%tomove,\%newsubdir,
- \%newurls)) {
- $mapmoves{$url} = 1;
- }
- $url = $newurl;
- } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
- &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
- $coursenum,$srcdom{$suffix},$srcnum{$suffix},
- $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
- \%zombies,\%params,\%mapmoves,\%mapchanges,
- \%tomove,\%newsubdir,\%newurls);
- }
- } elsif ($url=~m {^/res/}) {
-# published map can only exists once, so remove from paste buffer when done
- push(@toclear,$suffix);
-# if pasting published map (main content area only) check map not already in course
- if ($folder =~ /^default/) {
- if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
- $duplicate{$suffix} = 1;
- next;
- }
- }
- }
- }
- if ($url=~ m{/(bulletinboard|smppg)$}) {
- my $prefix = $1;
- #need to copy the db contents to a new one, unless this is a move.
- my %info = (
- src => $url,
- cdom => $coursedom,
- cnum => $coursenum,
- );
- unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
- my (%lockerr,$msg);
- my ($newurl,$result,$errtext) =
- &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
- if ($result eq 'ok') {
- $url = $newurl;
- $title=&mt('Copy of').' '.$title;
- } else {
- if ($prefix eq 'smppg') {
- $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
- } elsif ($prefix eq 'bulletinboard') {
- $msg = &mt('Paste failed: An error occurred when copying the bulletin board.').' '.$errtext;
- }
- $results{$suffix} = $result;
- $msgerrs{$suffix} = $msg;
- $lockerrs{$suffix} = $lockerr{$prefix};
- next;
- }
- if ($lockerr{$prefix}) {
- $lockerrs{$suffix} = $lockerr{$prefix};
- }
- }
- }
- $title = &LONCAPA::map::qtunescape($title);
- my $ext='false';
- if ($url=~m{^http(|s)://}) { $ext='true'; }
- if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
- if ($folder !~ /^supplemental/) {
- (undef,undef,$title) =
- &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
- }
- } else {
- if ($folder=~/^supplemental/) {
- $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
- $env{'user.domain'}.'___&&&___'.$title;
- }
- }
-
-# For uploaded files (excluding pages/sequences) path in copied file is changed
-# if paste is from Main to Supplemental (or vice versa), or if pasting between
-# courses.
-
- unless ($is_map{$suffix}) {
- my $newidx;
-# Now insert the URL at the bottom
- $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
- if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
- my $relpath = $1;
- if ($relpath ne '') {
- my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
- my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
- my $newprefix = $newloc;
- if ($newloc eq 'default') {
- $newprefix = 'docs';
- }
- if ($newdocsdir eq '') {
- $newdocsdir = 'default';
- }
- if (($prefixchg{$suffix}) ||
- ($srcdom{$suffix} ne $coursedom) ||
- ($srcnum{$suffix} ne $coursenum) ||
- ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
- my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
- $url =
- &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
- &Apache::lonnet::getfile($oldurl));
- if ($url eq '/adm/notfound.html') {
- $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
- next;
- } else {
- my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
- $newsubpath =~ s{/+$}{/};
- $docmoves{$oldurl} = $newsubpath;
- }
- }
- }
- }
- $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
- ':'.$ext.':normal:res';
- push(@LONCAPA::map::order,$newidx);
-# Store the result
- my ($errtext,$fatal) =
- &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
- if ($fatal) {
- $save_err .= $errtext;
- $allresult = 'fail';
- }
- }
-
-# Apply any changes to maps, or copy dependencies for uploaded HTML pages
- unless ($allresult eq 'fail') {
- my %updated = (
- rewrites => \%rewrites,
- zombies => \%zombies,
- removefrommap => \%removefrommap,
- removeparam => \%removeparam,
- dbcopies => \%dbcopies,
- retitles => \%retitles,
- );
- my %info = (
- newsubdir => \%newsubdir,
- params => \%params,
- );
- if ($prefixchg{$suffix}) {
- $info{'before'} = $before{$prefixchg{$suffix}};
- $info{'after'} = $after{$prefixchg{$suffix}};
- }
- my %moves = (
- copies => \%copies,
- docmoves => \%docmoves,
- mapmoves => \%mapmoves,
- );
- (my $result,$msgs{$suffix},my $lockerror) =
- &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
- \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
- $url,'paste');
- $lockerrors .= $lockerror;
- if ($result eq 'ok') {
- if ($is_map{$suffix}) {
- my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
- $folder.'.'.$container);
- if ($fatal) {
- $allresult = 'failread';
- } else {
- if ($#LONCAPA::map::order<1) {
- my $idx=&LONCAPA::map::getresidx();
- if ($idx<=0) { $idx=1; }
- $LONCAPA::map::order[0]=$idx;
- $LONCAPA::map::resources[$idx]='';
- }
- my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
- $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
- ':'.$ext.':normal:res';
- push(@LONCAPA::map::order,$newidx);
-
-# Store the result
- my ($errtext,$fatal) =
- &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
- if ($fatal) {
- $save_err .= $errtext;
- $allresult = 'failstore';
- }
- }
- }
- if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
- push(@toclear,$suffix);
- }
- }
- }
- }
- &clear_from_buffer(\@toclear,\@currpaste);
- my $msgsarray;
- foreach my $suffix (keys(%msgs)) {
- if (ref($msgs{$suffix}) eq 'ARRAY') {
- $msgsarray .= join(',',@{$msgs{$suffix}});
- }
- }
- return ($allresult,$save_err,$msgsarray,$lockerrors);
-}
-
-sub do_buffer_empty {
- my @currpaste = split(/,/,$env{'docs.markedcopies'});
- if (@currpaste == 0) {
- return &mt('Clipboard is already empty');
- }
- my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
- if (@toclear == 0) {
- return &mt('Nothing selected to clear from clipboard');
- }
- my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
- if ($numdel) {
- return &mt('[quant,_1,item] cleared from clipboard',$numdel);
- } else {
- return &mt('Clipboard unchanged');
- }
- return;
-}
-
-sub clear_from_buffer {
- my ($toclear,$currpaste) = @_;
- return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
- my %pastebuffer;
- map { $pastebuffer{$_} = 1; } @{$currpaste};
- my $numdel = 0;
- foreach my $suffix (@{$toclear}) {
- next if ($suffix =~ /\D/);
- next unless (exists($pastebuffer{$suffix}));
- my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
- if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
- delete($pastebuffer{$suffix});
- $numdel ++;
- }
- }
- my $newbuffer = join(',',sort(keys(%pastebuffer)));
- &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
- return $numdel;
-}
-
-sub get_newmap_url {
- my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
- $titleref,$allmaps,$newurls) = @_;
- my $newurl;
- if ($url=~ m{^/uploaded/}) {
- $$titleref=&mt('Copy of').' '.$$titleref;
- }
- my $now = time;
- my $suffix=$$.int(rand(100)).$now;
- my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
- if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
- my $path = $1;
- my $prefix = $2;
- my $ancestor = $3;
- if (length($ancestor) > 10) {
- $ancestor = substr($ancestor,-10,10);
- }
- my $newid;
- if ($prefixchg) {
- if ($folder =~ /^supplemental/) {
- $prefix =~ s/^default/supplemental/;
- } else {
- $prefix =~ s/^supplemental/default/;
+ if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) {
+ $title=&mt('Copy of').' '.$title;
+ my $newid=$$.int(rand(100)).time;
+ my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
+ if ($oldid =~ m{^(/uploaded/\Q$coursedom\E/\Q$coursenum\E/)(\D+)(\d+)$}) {
+ my $path = $1;
+ my $prefix = $2;
+ my $ancestor = $3;
+ if (length($ancestor) > 10) {
+ $ancestor = substr($ancestor,-10,10);
}
- }
- if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
- $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
- } else {
- $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
+ $oldid = $path.$prefix.$ancestor;
}
my $counter = 0;
+ my $newurl=$oldid.$newid.'.'.$ext;
my $is_unique = &uniqueness_check($newurl);
- if ($folder =~ /^default/) {
- if ($allmaps->{$newurl}) {
- $is_unique = 0;
- }
- }
- while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
+ while (!$is_unique && $counter < 100) {
$counter ++;
- $suffix ++;
- if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
- $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
+ $newid ++;
+ $newurl = $oldid.$newid;
+ $is_unique = &uniqueness_check($newurl);
+ }
+ if (!$is_unique) {
+ if ($url=~/\.page$/) {
+ return &mt('Paste failed: an error occurred creating a unique URL for the composite page');
} else {
- $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
+ return &mt('Paste failed: an error occurred creating a unique URL for the folder');
}
- $is_unique = &uniqueness_check($newurl);
}
- if ($is_unique) {
- $newurls->{$newurl} = 1;
- } else {
+ my $storefn=$newurl;
+ $storefn=~s{^/\w+/$match_domain/$match_username/}{};
+ my $paste_map_result =
+ &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
+ &Apache::lonnet::getfile($url));
+ if ($paste_map_result eq '/adm/notfound.html') {
if ($url=~/\.page$/) {
- return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
+ return &mt('Paste failed: an error occurred saving the composite page');
} else {
- return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
+ return &mt('Paste failed: an error occurred saving the folder');
}
}
+ $url = $newurl;
}
- return ($newurl);
-}
-
-sub dbcopy {
- my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
- my ($url,$result,$errtext);
- my $url = $dbref->{'src'};
- if (ref($dbref) eq 'HASH') {
- if ($url =~ m{/(smppg|bulletinboard)$}) {
- my $prefix = $1;
- if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
- ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
- my $db_name;
- my $marker = (split(m{/},$url))[4];
- $marker=~s/\D//g;
- if ($dbref->{'src'} =~ m{/smppg$}) {
- $db_name =
- &Apache::lonsimplepage::get_db_name($url,$marker,
- $dbref->{'cdom'},
- $dbref->{'cnum'});
- } else {
- $db_name = 'bulletinpage_'.$marker;
- }
- my ($suffix,$freedlock,$error) =
- &Apache::lonnet::get_timebased_id($prefix,'num','templated',
- $coursedom,$coursenum,
- 'concat');
- if (!$suffix) {
- if ($prefix eq 'smppg') {
- $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
- } else {
- $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a bulletin board [_1].',$url);
- }
- if ($error) {
- $errtext .= ' '.$error;
- }
- } else {
- #need to copy the db contents to a new one.
- my %contents=&Apache::lonnet::dump($db_name,
- $dbref->{'cdom'},
- $dbref->{'cnum'});
- if (exists($contents{'uploaded.photourl'})) {
- my $photo = $contents{'uploaded.photourl'};
- my ($subdir,$fname) =
- ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
- my $newphoto;
- if ($fname ne '') {
- my $content = &Apache::lonnet::getfile($photo);
- unless ($content eq '-1') {
- $env{'form.'.$suffix.'.photourl'} = $content;
- $newphoto =
- &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
- delete($env{'form.'.$suffix.'.photourl'});
- }
- }
- if ($newphoto =~ m{^/uploaded/}) {
- $contents{'uploaded.photourl'} = $newphoto;
- }
- }
- $db_name =~ s{_\d*$ }{_$suffix}x;
- $result=&Apache::lonnet::put($db_name,\%contents,
- $coursedom,$coursenum);
- if ($result eq 'ok') {
- $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
- }
- }
- if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
- $lockerrorsref->{$prefix} =
- '
'.
- &mt('There was a problem removing a lockfile.');
- if ($prefix eq 'smppg') {
- $lockerrorsref->{$prefix} .=
- &mt('This will prevent creation of additional simple pages in this course.');
- } else {
- $lockerrorsref->{$prefix} .= &mt('This will prevent creation of additional bulletin boards in this course.');
- }
- $lockerrorsref->{$prefix} .= &mt('Please contact the domain coordinator for your LON-CAPA domain.').'
'."\n".
- &mt('The following files are either dependencies of a web page or references within a folder and/or composite page which could not be copied during the paste operation:')."\n".
- '
'."\n");
- foreach my $key (sort(keys(%paste_errors))) {
- $r->print('
'.$key.'
'."\n");
- }
- $r->print('
'."\n");
- }
- } elsif ($env{'form.clearmarked'}) {
- my $output = &do_buffer_empty();
- if ($output) {
- $r->print('
'.$output.'
');
+ my $paste_res =
+ &do_paste_from_buffer($coursenum,$coursedom,$folder);
+ if ($paste_res eq 'ok') {
+ ($errtext,$fatal) = &storemap($coursenum,$coursedom,$folder.'.'.$container);
+ return $errtext if ($fatal);
+ } elsif ($paste_res ne '') {
+ $r->print('
'.$paste_res.'
');
}
- }
+ }
$r->print($upload_output);
-# Rename, cut, copy or remove a single resource
if (&handle_edit_cmd()) {
- my $contentchg;
- if ($env{'form.cmd'} =~ m{^(del|cut)_}) {
- $contentchg = 1;
- }
- ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
return $errtext if ($fatal);
}
-
-# Cut, copy and/or remove multiple resources
- if ($env{'form.multichange'}) {
- my %allchecked = (
- cut => {},
- remove => {},
- );
- my $needsupdate;
- foreach my $which (keys(%allchecked)) {
- $env{'form.multi'.$which} =~ s/,$//;
- if ($env{'form.multi'.$which}) {
- map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
- if (ref($allchecked{$which}) eq 'HASH') {
- $needsupdate += scalar(keys(%{$allchecked{$which}}));
- }
- }
- }
- if ($needsupdate) {
- my $haschanges = 0;
- my %curr_groups = &Apache::longroup::coursegroups();
- my $total = scalar(@LONCAPA::map::order) - 1;
- for (my $i=$total; $i>=0; $i--) {
- my $res = $LONCAPA::map::order[$i];
- my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
- $name=&LONCAPA::map::qtescape($name);
- $url=&LONCAPA::map::qtescape($url);
- next unless ($name && $url);
- my %denied =
- &action_restrictions($coursenum,$coursedom,$url,
- $env{'form.folderpath'},\%curr_groups);
- foreach my $which (keys(%allchecked)) {
- next if ($denied{$which});
- next unless ($allchecked{$which}{$res});
- if ($which eq 'remove') {
- if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
- ($url!~/$LONCAPA::assess_page_seq_re/)) {
- &Apache::lonnet::removeuploadedurl($url);
- } else {
- &LONCAPA::map::makezombie($res);
- }
- splice(@LONCAPA::map::order,$i,1);
- $haschanges ++;
- } elsif ($which eq 'cut') {
- &LONCAPA::map::makezombie($res);
- splice(@LONCAPA::map::order,$i,1);
- $haschanges ++;
- }
- }
- }
- if ($haschanges) {
- ($errtext,$fatal) =
- &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
- return $errtext if ($fatal);
- }
- }
- }
-
# Group import/search
if ($env{'form.importdetail'}) {
my @imports;
foreach my $item (split(/\&/,$env{'form.importdetail'})) {
if (defined($item)) {
my ($name,$url,$residx)=
- map { &unescape($_); } split(/\=/,$item);
- if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
- my ($suffix,$errortxt,$locknotfreed) =
- &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
- if ($locknotfreed) {
- $r->print($locknotfreed);
- }
- if ($suffix) {
- $url =~ s/_new\./_$suffix./;
- } else {
- return $errortxt;
- }
- } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
- my $type = $1;
- my ($suffix,$errortxt,$locknotfreed) =
- &new_timebased_suffix($coursedom,$coursenum,$type);
- if ($locknotfreed) {
- $r->print($locknotfreed);
- }
- if ($suffix) {
- $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
- } else {
- return $errortxt;
- }
- } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
- if ($supplementalflag) {
- next unless ($1 eq 'supplemental');
- if ($folder eq 'supplemental') {
- next unless ($2 eq 'default');
- } else {
- next unless ($folder eq 'supplemental_'.$2);
- }
- } else {
- next unless ($1 eq 'docs');
- if ($folder eq 'default') {
- next unless ($2 eq 'default');
- } else {
- next unless ($folder eq 'default_'.$2);
- }
- }
- }
+ map {&unescape($_)} split(/\=/,$item);
push(@imports, [$name, $url, $residx]);
}
}
- ($errtext,$fatal,my $fixuperrors) =
- &group_import($coursenum, $coursedom, $folder,$container,
- 'londocs',@imports);
+ ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
+ $container,'londocs',@imports);
return $errtext if ($fatal);
- if ($fixuperrors) {
- $r->print($fixuperrors);
- }
}
# Loading a complete map
if ($env{'form.loadmap'}) {
@@ -2553,7 +922,7 @@ sub editor {
$LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
}
($errtext,$fatal)=&storemap($coursenum,$coursedom,
- $folder.'.'.$container,1);
+ $folder.'.'.$container);
return $errtext if ($fatal);
} else {
$r->print('
'.&mt('The uploaded file has not been stored as an error occurred reading the contents of the current folder.').'
';
- return;
- }
# this is for a course, not a user, so set context to coursedoc.
my $newidx=&LONCAPA::map::getresidx();
$destination .= $newidx;
@@ -2868,7 +1102,7 @@ sub process_file_upload {
$comment.':'.$url.':'.$ext.':normal:res';
$LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
($errtext,$fatal)=&storemap($coursenum,$coursedom,
- $folder.'.'.$container,1);
+ $folder.'.'.$container);
if ($fatal) {
$$upload_output = '
'.$errtext.'
';
return;
@@ -2905,6 +1139,7 @@ sub process_file_upload {
my $archiveurl = &HTML::Entities::encode($url,'<>&"');
my %archiveitems = (
folderpath => $env{'form.folderpath'},
+ pagepath => $env{'form.pagepath'},
cmd => $nextphase,
newidx => $newidx,
position => $position,
@@ -2955,69 +1190,69 @@ sub is_supplemental_title {
return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
}
+sub parse_supplemental_title {
+ my ($title) = @_;
+
+ my ($foldertitle,$renametitle);
+ if ($title =~ /&&&/) {
+ $title = &HTML::Entites::decode($title);
+ }
+ if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
+ $renametitle=$4;
+ my ($time,$uname,$udom) = ($1,$2,$3);
+ $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
+ my $name = &Apache::loncommon::plainname($uname,$udom);
+ $name = &HTML::Entities::encode($name,'"<>&\'');
+ $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
+ $title=''.&Apache::lonlocal::locallocaltime($time).' '.
+ $name.': '.$foldertitle;
+ }
+ if (wantarray) {
+ return ($title,$foldertitle,$renametitle);
+ }
+ return $title;
+}
+
# --------------------------------------------------------------- An entry line
sub entryline {
- my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
- $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups)=@_;
- my ($foldertitle,$renametitle);
+ my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$crstype)=@_;
+ my ($foldertitle,$pagetitle,$renametitle);
if (&is_supplemental_title($title)) {
- ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
+ ($title,$foldertitle,$renametitle) = &parse_supplemental_title($title);
+ $pagetitle = $foldertitle;
} else {
$title=&HTML::Entities::encode($title,'"<>&\'');
$renametitle=$title;
$foldertitle=$title;
+ $pagetitle=$title;
}
my $orderidx=$LONCAPA::map::order[$index];
+
$renametitle=~s/\\/\\\\/g;
$renametitle=~s/\"\;/\\\"/g;
$renametitle=~s/ /%20/g;
my $line=&Apache::loncommon::start_data_table_row();
- my ($form_start,$form_end,$form_common,$form_param);
+ my ($form_start,$form_end,$form_common);
# Edit commands
- my ($esc_path, $path, $symb);
+ my ($container, $type, $esc_path, $path, $symb);
if ($env{'form.folderpath'}) {
+ $type = 'folder';
+ $container = 'sequence';
$esc_path=&escape($env{'form.folderpath'});
$path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
# $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
}
- my $isexternal;
- if ($residx) {
- my $currurl = $url;
- $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
- if ($currurl =~ m{^/adm/wrapper/ext/}) {
- $isexternal = 1;
- }
- if (!$supplementalflag) {
- my $path = 'uploaded/'.
- $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
- $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
- $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
- $residx,
- &Apache::lonnet::declutter($currurl));
- }
- }
- my ($renamelink,%lt,$ishash);
- if (ref($filtersref) eq 'HASH') {
- $ishash = 1;
+ if ($env{'form.pagepath'}) {
+ $type = $container = 'page';
+ $esc_path=&escape($env{'form.pagepath'});
+ $path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
+ $symb=&escape($env{'form.pagesymb'});
}
-
+ my $cpinfo='';
if ($allowed) {
- $form_start = '
- ';
-
my $incindex=$index+1;
my $selectbox='';
if (($#LONCAPA::map::order>0) &&
@@ -3039,24 +1274,36 @@ END
}
$selectbox.='';
}
- %lt=&Apache::lonlocal::texthash(
+ my %lt=&Apache::lonlocal::texthash(
'up' => 'Move Up',
'dw' => 'Move Down',
'rm' => 'Remove',
'ct' => 'Cut',
'rn' => 'Rename',
- 'cp' => 'Copy',
- 'ex' => 'External Resource',
- 'ed' => 'Edit',
- 'pr' => 'Preview',
- 'sv' => 'Save',
- 'ul' => 'URL',
- 'ti' => 'Title',
- );
- my %denied = &action_restrictions($coursenum,$coursedom,$url,
- $env{'form.folderpath'},
- $currgroups);
- my ($copylink,$cutlink,$removelink);
+ 'cp' => 'Copy');
+ my $nocopy=0;
+ my $nocut=0;
+ if ($url=~/\.(page|sequence)$/) {
+ if ($url =~ m{/res/}) {
+ # no copy for published maps
+ $nocopy = 1;
+ } else {
+ foreach my $item (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url),1)) {
+ my ($title,$url,$ext,$type)=split(/\:/,$item);
+ if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
+ $nocopy=1;
+ last;
+ }
+ }
+ }
+ }
+ if ($url=~/^\/res\/lib\/templates\//) {
+ $nocopy=1;
+ $nocut=1;
+ }
+ my $copylink=' ';
+ my $cutlink=' ';
+
my $skip_confirm = 0;
if ( $folder =~ /^supplemental/
|| ($url =~ m{( /smppg$
@@ -3064,112 +1311,79 @@ END
|/aboutme$
|/navmaps$
|/bulletinboard$
- |\.html$)}x)
- || $isexternal) {
+ |\.html$
+ |^/adm/wrapper/ext)}x)) {
$skip_confirm = 1;
}
- if ($denied{'copy'}) {
- $copylink=(<$lt{'cp'}
-ENDCOPY
- } else {
- my $formname = 'edit_copy_'.$orderidx;
- my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
+ if (!$nocopy) {
$copylink=(<
-$form_common
-$lt{'cp'}
-$form_end
+$lt{'cp'}
ENDCOPY
- if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
- push(@{$filtersref->{'cancopy'}},$orderidx);
- }
}
- if ($denied{'cut'}) {
- $cutlink=(<$lt{'ct'}
-ENDCUT
- } else {
- my $formname = 'edit_cut_'.$orderidx;
- my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
+ if (!$nocut) {
$cutlink=(<
-$form_common
-
-$lt{'ct'}
-$form_end
+$lt{'ct'}
ENDCUT
- if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
- push(@{$filtersref->{'cancut'}},$orderidx);
- }
- }
- if ($denied{'remove'}) {
- $removelink=(<$lt{'rm'}
-ENDREM
- } else {
- my $formname = 'edit_remove_'.$orderidx;
- my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm);";
- $removelink=(<
-$form_common
-
-$lt{'rm'}
-$form_end
-ENDREM
- if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
- push(@{$filtersref->{'canremove'}},$orderidx);
- }
- }
- unless ($isexternal) {
- $renamelink=(<$lt{'rn'}
-ENDREN
}
+ $form_start = '
+ ';
$line.=(<