--- loncom/interface/londocs.pm 2007/07/04 00:21:42 1.286
+++ loncom/interface/londocs.pm 2007/07/13 23:08:07 1.291
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.286 2007/07/04 00:21:42 albertel Exp $
+# $Id: londocs.pm,v 1.291 2007/07/13 23:08:07 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'});
@@ -1214,15 +1217,17 @@ ENDPASTE
$r->print(' ');
my $type;
- if ($env{'docs.markedcopy_url'} =~ m{^/adm/wrapper/ext}) {
+ if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
$type = &mt('External Resource');
- $r->print($type.': '.&Apache::map::qtescape($env{'docs.markedcopy_title'}));
+ $r->print($type.': '.
+ &LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('.
+ &LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')');
} else {
my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];
my $type = &Apache::loncommon::filedescription($extension);
my $icon = '';
- $r->print($icon.$type.': '. &parse_supplemental_title($env{'docs.markedcopy_title'}));
+ $r->print($icon.$type.': '. &parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'})));
}
if ($container eq 'page') {
$r->print('
@@ -1237,6 +1242,52 @@ ENDPASTE
$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;
+ }
+# published maps can only exists once, so remove it from paste buffer when done
+ if (($url=~/\.(page|sequence)$/) && ($url=~m {^/res/})) {
+ &Apache::lonnet::delenv('docs\\.markedcopy');
+ }
+ if ($url=~ m{/smppg$}) {
+ my $db_name = &Apache::lonsimplepage::get_db_name($url);
+ if ($db_name =~ /^smppage_/) {
+ #simple pages, need to copy the db contents to a new one.
+ my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum);
+ my $now = time();
+ $db_name =~ s{_\d*$ }{_$now}x;
+ my $result=&Apache::lonnet::put($db_name,\%contents,
+ $coursedom,$coursenum);
+ $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
+ $title=&mt('Copy of').' '.$title;
+ }
+ }
+ $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 {
my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$which)=@_;
my $errtext='';
@@ -1343,38 +1394,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 +1461,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 +1580,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);
@@ -1768,11 +1792,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;
+ }
}
}
}
@@ -1783,6 +1812,18 @@ sub entryline {
my $copylink=' ';
my $cutlink=' ';
+ my $skip_confirm = 0;
+ if ( $folder =~ /^supplemental/
+ || ($url =~ m{( /smppg$
+ |/syllabus$
+ |/aboutme$
+ |/navmaps$
+ |/bulletinboard$
+ |\.html$
+ |^/adm/wrapper/ext)}x)) {
+ $skip_confirm = 1;
+ }
+
if (!$nocopy) {
$copylink=(<$lt{'cp'}
@@ -1790,7 +1831,7 @@ ENDCOPY
}
if (!$nocut) {
$cutlink=(<$lt{'ct'}
+$lt{'ct'}
ENDCUT
}
$form_start = (<
- $lt{'rm'}
+ $lt{'rm'}
$cutlink
$lt{'rn'}
$copylink
@@ -1856,7 +1897,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/'.
@@ -1879,6 +1922,7 @@ END
}
} elsif ($url=~m|^/ext/|) {
$url='/adm/wrapper'.$url;
+ $external = 1;
}
if (&Apache::lonnet::symbverify($symb,$url)) {
$url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
@@ -1932,12 +1976,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.='