--- loncom/interface/londocs.pm 2007/07/03 00:30:47 1.284
+++ loncom/interface/londocs.pm 2007/07/13 00:29:21 1.290
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.284 2007/07/03 00:30:47 albertel Exp $
+# $Id: londocs.pm,v 1.290 2007/07/13 00:29:21 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,80 @@ 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;
+ }
+# 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 {
@@ -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
@@ -1489,7 +1513,7 @@ sub editor {
if ($randompick>=0) {
$r->print('
'.&mt('Caution: this folder is set to randomly pick a subset of resources. Adding or removing resources from this folder will change the set of resources that the students see, resulting in spurious or missing credit for completed problems, not limited to ones you modify. Do not modify the contents of this folder if it is in active student use.').'
');
}
- $r->print('
');
+ $r->print('
');
foreach my $res (@LONCAPA::map::order) {
my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
$name=&LONCAPA::map::qtescape($name);
@@ -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);
@@ -1715,7 +1739,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 +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;
+ }
}
}
}
@@ -1791,30 +1822,35 @@ ENDCOPY
$lt{'ct'}
ENDCUT
}
- $line.=(<
+ $form_start = (<
+END
+ $form_end = '';
+ $line.=(<
-
+
-
+
-
+
+ $form_start
$selectbox
+ $form_end
-
+
$lt{'rm'}
$cutlink
$lt{'rn'}
@@ -1849,7 +1885,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 +1910,7 @@ END
}
} elsif ($url=~m|^/ext/|) {
$url='/adm/wrapper'.$url;
+ $external = 1;
}
if (&Apache::lonnet::symbverify($symb,$url)) {
$url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
@@ -1904,7 +1943,7 @@ END
(&LONCAPA::map::getparameter($orderidx,
'parameter_randompick'))[0].
'" />'.
-''.&mt('Save').'';
+''.&mt('Save').'';
}
if ($ispage) {
@@ -1925,10 +1964,19 @@ END
$url.='pagepath='.&escape($pagepath).
'&pagesymb='.&escape($symb).$cpinfo;
}
- $line.='
+ '.($url?"":'').$title.($url?'':' '.&mt('(re-initialize course to access)').'').$external."
+
";
if (($allowed) && ($folder!~/^supplemental/)) {
my %lt=&Apache::lonlocal::texthash(
'hd' => 'Hidden',
@@ -1938,14 +1986,20 @@ END
my $hidtext=
((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
$line.=(<
-
-
-
-
$parameterset
+
+ $form_start
+
+ $form_end
+
+
+ $form_start
+
+ $form_end
+
+
$form_start $parameterset $form_end
ENDPARMS
}
- $line.="";
+ $line.="";
return $line;
}
@@ -2393,7 +2447,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".
'