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

www lon-capa-cvs@mail.lon-capa.org
Mon, 08 Sep 2003 21:55:46 -0000


www		Mon Sep  8 17:55:46 2003 EDT

  Modified files:              
    /loncom/interface	loncreatecourse.pm 
  Log:
  Need to rewrite absolute URLs while cloning ... aargh.
  
  
Index: loncom/interface/loncreatecourse.pm
diff -u loncom/interface/loncreatecourse.pm:1.35 loncom/interface/loncreatecourse.pm:1.36
--- loncom/interface/loncreatecourse.pm:1.35	Wed Sep  3 19:15:27 2003
+++ loncom/interface/loncreatecourse.pm	Mon Sep  8 17:55:46 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Create a course
 #
-# $Id: loncreatecourse.pm,v 1.35 2003/09/03 23:15:27 www Exp $
+# $Id: loncreatecourse.pm,v 1.36 2003/09/08 21:55:46 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -98,11 +98,37 @@
 					  'output',$which);
 }
 
+# ===================================================================== Rewrite
+
+sub rewritefile {
+    my ($contents,%rewritehash)=@_;
+    foreach (keys %rewritehash) {
+	my $pattern=$_;
+	$pattern=~s/(\W)/\\$1/gs;
+	my $new=$rewritehash{$_};
+	$contents=~s/$pattern/$new/gs;
+    }
+    return $contents;
+}
+
 # ============================================================= Copy a userfile
 
 sub copyfile {
     my ($origcrsid,$newcrsid,$which)=@_;
-    return &writefile($newcrsid,$which,&readfile($origcrsid,$which));
+    unless ($which=~/\.sequence$/) {
+	return &writefile($newcrsid,$which,
+		      &readfile($origcrsid,$which));
+    } else {
+	my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
+	my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
+	return &writefile($newcrsid,$which,
+		 &rewritefile(
+                     &readfile($origcrsid,$which),
+	    (
+       '/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'
+    => '/uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/'
+            )));
+    }
 }
 
 # =============================================================== Copy a dbfile