[LON-CAPA-cvs] cvs: loncom /interface londocs.pm

albertel lon-capa-cvs-allow@mail.lon-capa.org
Thu, 12 Jul 2007 23:56:30 -0000


albertel		Thu Jul 12 19:56:30 2007 EDT

  Modified files:              
    /loncom/interface	londocs.pm 
  Log:
  - not allowed to copy published maps (BUG#5063)
     - still allowed to cut
     - after pasting a published map clear paste buffer so multiple copies aren't instered
  
  
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.288 loncom/interface/londocs.pm:1.289
--- loncom/interface/londocs.pm:1.288	Wed Jul 11 21:04:36 2007
+++ loncom/interface/londocs.pm	Thu Jul 12 19:56:29 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.288 2007/07/12 01:04:36 albertel Exp $
+# $Id: londocs.pm,v 1.289 2007/07/12 23:56:29 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1242,6 +1242,38 @@
     $r->print('</p></form>');
 }
 
+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 {
     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$which)=@_;
     my $errtext='';
@@ -1348,38 +1380,13 @@
 	    }
 	    
 	    if ($env{'form.pastemarked'}) {
-# 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;
-		}
-		$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';
-		$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('<p><span class="LC_error">'.$errtext.'</span></p>');
 		    return;
 		}
-
 	    }
             $r->print($upload_output);
 	    if ($env{'form.cmd'}) {
@@ -1771,11 +1778,16 @@
 	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;
+		    }
 		}
 	    }
 	}