--- loncom/interface/londocs.pm 2007/07/03 23:02:53 1.285
+++ loncom/interface/londocs.pm 2007/07/12 23:56:29 1.289
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.285 2007/07/03 23:02:53 albertel Exp $
+# $Id: londocs.pm,v 1.289 2007/07/12 23:56:29 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -908,9 +908,7 @@ sub group_import {
my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
while (@files) {
- my $name = shift(@files);
- my $url = shift(@files);
- #FIXME check if file exists before overwriting, might be restoring it
+ my ($name, $url, $residx) = @{ shift(@files) };
if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
&& ($caller eq 'londocs')
&& (!&Apache::lonnet::stat_file($url))) {
@@ -934,14 +932,17 @@ sub group_import {
}
}
if ($url) {
- my $idx = &LONCAPA::map::getresidx($url);
- $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
+ if (!$residx
+ || defined($LONCAPA::map::zombies[$residx])) {
+ $residx = &LONCAPA::map::getresidx($url,$residx);
+ push(@LONCAPA::map::order, $residx);
+ }
my $ext = 'false';
if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
$url = &LONCAPA::map::qtunescape($url);
$name = &LONCAPA::map::qtunescape($name);
- $LONCAPA::map::resources[$idx] =
- join ':', ($name, $url, $ext, 'normal', 'res');
+ $LONCAPA::map::resources[$residx] =
+ join(':', ($name, $url, $ext, 'normal', 'res'));
}
}
return &storemap($coursenum, $coursedom, $folder.'.'.$container);
@@ -1199,6 +1200,8 @@ sub update_paste_buffer {
if (&is_supplemental_title($title)) {
($title) = &parse_supplemental_title($title);
}
+ $url=~s{http(:|:)//https(:|:)//}{https$2//};
+
&Apache::lonnet::appenv('docs.markedcopy_title' => $title,
'docs.markedcopy_url' => $url);
delete($env{'form.markcopy'});
@@ -1209,32 +1212,66 @@ sub print_paste_buffer {
return if (!defined($env{'docs.markedcopy_url'}));
$r->print(<
');
+ $r->print('');
+}
+
+sub do_paste_from_buffer {
+ my ($coursenum,$coursedom,$folder,$container) = @_;
+# 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
+ if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) {
+ $title=&mt('Copy of').' '.$title;
+ my $newid=$$.time;
+ $url=~/^(.+)\.(\w+)$/;
+ my $newurl=$1.$newid.'.'.$2;
+ my $storefn=$newurl;
+ $storefn=~s{^/\w+/$match_domain/$match_username/}{};
+ &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
+ &Apache::lonnet::getfile($url));
+ $url = $newurl;
+ }
+ if (($url=~/\.(page|sequence)$/) && ($url=~m {^/res/})) {
+ &Apache::lonnet::delenv('docs\\.markedcopy');
+ }
+ $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);
+ $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res';
+ push(@LONCAPA::map::order, $newidx);
+# Store the result
+ return &storemap($coursenum,$coursedom,$folder.'.'.$container);
}
sub editor {
@@ -1343,38 +1380,13 @@ sub editor {
}
if ($env{'form.pastemarked'}) {
-# paste resource to end of list
- my $url=$env{'docs.markedcopy_url'};
- my $title=$env{'docs.markedcopy_title'};
-# Maps need to be copied first
- if (($url=~/\.(page|sequence)$/) || ($url=~/^\/uploaded\//)) {
- $title=&mt('Copy of').' '.$title;
- my $newid=$$.time;
- $url=~/^(.+)\.(\w+)$/;
- my $newurl=$1.$newid.'.'.$2;
- my $storefn=$newurl;
- $storefn=~s{^/\w+/$match_domain/$match_username/}{};
- &Apache::lonclonecourse::writefile
- ($env{'request.course.id'},$storefn,
- &Apache::lonnet::getfile($url));
- $url=$newurl;
- }
- $title = &LONCAPA::map::qtunescape($title);
- my $ext='false';
- if ($url=~/^http\:\/\//) { $ext='true'; }
- $url = &LONCAPA::map::qtunescape($url);
-# Now insert the URL at the bottom
- my $newidx=&LONCAPA::map::getresidx($url);
- $LONCAPA::map::resources[$newidx]=
- $title.':'.$url.':'.$ext.':normal:res';
- $LONCAPA::map::order[1+$#LONCAPA::map::order]=$newidx;
-# Store the result
- ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
+ my ($errtext,$fatal) =
+ &do_paste_from_buffer($coursenum,$coursedom,$folder,
+ $container);
if ($fatal) {
$r->print('
'.$errtext.'
');
return;
}
-
}
$r->print($upload_output);
if ($env{'form.cmd'}) {
@@ -1435,13 +1447,11 @@ sub editor {
# Group import/search
if ($env{'form.importdetail'}) {
my @imports;
-# &Apache::lonnet::logthis("imp detail ".$env{'form.importdetail'});
foreach (split(/\&/,$env{'form.importdetail'})) {
if (defined($_)) {
- my ($name,$url)=split(/\=/,$_);
- $name=&unescape($name);
- $url=&unescape($url);
- push @imports, $name, $url;
+ my ($name,$url,$residx)=
+ map {&unescape($_)} split(/\=/,$_);
+ push(@imports, [$name, $url, $residx]);
}
}
# Store the changed version
@@ -1556,7 +1566,7 @@ sub process_file_upload {
$parseaction,$allfiles,
$codebase);
my $ext='false';
- if ($url=~/^http\:\/\//) { $ext='true'; }
+ if ($url=~m{^http://}) { $ext='true'; }
$url = &LONCAPA::map::qtunescape($url);
my $comment=$env{'form.comment'};
$comment = &LONCAPA::map::qtunescape($comment);
@@ -1715,7 +1725,9 @@ sub entryline {
$renametitle=~s/\\/\\\\/g;
$renametitle=~s/\"\;/\\\"/g;
+ $renametitle=~s/ /%20/g;
my $line='
';
+ my ($form_start,$form_end);
# Edit commands
my $container;
my ($container, $type, $esc_path, $path, $symb);
@@ -1766,11 +1778,16 @@ sub entryline {
my $nocopy=0;
my $nocut=0;
if ($url=~/\.(page|sequence)$/) {
- foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url))) {
- my ($title,$url,$ext,$type)=split(/\:/,$_);
- if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
- $nocopy=1;
- last;
+ if ($url =~ m{/res/}) {
+ # no copy for published maps
+ $nocopy = 1;
+ } else {
+ foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url))) {
+ my ($title,$url,$ext,$type)=split(/\:/,$_);
+ if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
+ $nocopy=1;
+ last;
+ }
}
}
}
@@ -1791,12 +1808,15 @@ ENDCOPY
$lt{'ct'}
ENDCUT
}
- $line.=(<
+ $form_start = (<
+END
+ $form_end = '';
+ $line.=(<
@@ -1812,7 +1832,9 @@ ENDCUT
+ $form_start
$selectbox
+ $form_end
$lt{'rm'}
@@ -1849,7 +1871,9 @@ END
&Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
}
}
- $url=~s-^http(\&colon\;|:)//-/adm/wrapper/ext/-;
+
+ my $orig_url = $url;
+ my $external = ($url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/});
if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
my $symb=&Apache::lonnet::symbclean(
&Apache::lonnet::declutter('uploaded/'.
@@ -1872,6 +1896,7 @@ END
}
} elsif ($url=~m|^/ext/|) {
$url='/adm/wrapper'.$url;
+ $external = 1;
}
if (&Apache::lonnet::symbverify($symb,$url)) {
$url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
@@ -1925,12 +1950,18 @@ END
$url.='pagepath='.&escape($pagepath).
'&pagesymb='.&escape($symb).$cpinfo;
}
+ if ($external) {
+ my $form = ($folder =~ /^default/)? 'newext' : 'supnewext';
+ $external = ' '.&mt('Edit').'';
+ } else {
+ undef($external);
+ }
$line.='
- '.($url?"":'').$title.($url?'':' '.&mt('(re-initialize course to access)').'')."
+ '.($url?"":'').$title.($url?'':' '.&mt('(re-initialize course to access)').'').$external."
";
if (($allowed) && ($folder!~/^supplemental/)) {
my %lt=&Apache::lonlocal::texthash(
@@ -1942,15 +1973,19 @@ END
((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
$line.=(<
+ $form_start
+ $form_end
+ $form_start
+ $form_end
-
$parameterset
+
$form_start $parameterset $form_end
ENDPARMS
}
- $line.="
";
+ $line.="";
return $line;
}
@@ -2398,7 +2433,7 @@ sub changewarning {
$message='Changes will become active for your current session after [_1], or the next time you log in.';
}
$r->print("\n\n".
-''."\n".
+''."\n".
'