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

albertel lon-capa-cvs-allow@mail.lon-capa.org
Fri, 13 Jul 2007 00:29:22 -0000


albertel		Thu Jul 12 20:29:22 2007 EDT

  Modified files:              
    /loncom/interface	lonsimplepage.pm londocs.pm 
  Log:
  - BUG#4769 - copy paste on simple pages needs to copy pase the db contents and update the url
  
  
Index: loncom/interface/lonsimplepage.pm
diff -u loncom/interface/lonsimplepage.pm:1.50 loncom/interface/lonsimplepage.pm:1.51
--- loncom/interface/lonsimplepage.pm:1.50	Tue May  1 21:33:49 2007
+++ loncom/interface/lonsimplepage.pm	Thu Jul 12 20:29:21 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Simple Page Editor
 #
-# $Id: lonsimplepage.pm,v 1.50 2007/05/02 01:33:49 albertel Exp $
+# $Id: lonsimplepage.pm,v 1.51 2007/07/13 00:29:21 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -41,6 +41,26 @@
 use HTML::Entities();
 use LONCAPA;
 
+sub get_db_name {
+    my ($url) = @_;
+    my ($udom,$uname,$marker)=(split(m{/},$url))[2,3,4];
+    my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+    my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
+
+    my $db_name;
+
+    if ($dom && $crs && ($udom eq $dom) && ($uname eq $crs)) {
+	$marker =~ s/\W//g;
+	$db_name = 'grppage_'.$marker;
+    } else {
+	$marker=~s/\D//g;
+        $db_name = 'smppage_'.$marker;
+    }
+    return if (!defined($marker));
+
+    return $db_name;
+}
+
 sub handler {
     my $r = shift;
     &Apache::loncommon::content_type($r,'text/html');
@@ -51,7 +71,7 @@
     if ($target eq 'tex') {
 	$r->print(&Apache::lonprintout::print_latex_header($env{'form.latex_type'}));
     } 
-    my (undef,undef,$udom,$uname,$marker)=split(/\//,$r->uri);
+
 # Is this even in a course?
     unless ($env{'request.course.id'}) {
 	if ($target ne 'tex') {
@@ -62,15 +82,17 @@
 	return OK;
     }
 
+    my $db_name = &get_db_name($r->uri);
+
     my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
-    my ($namespace,$group,$group_desc,$group_home_view,$group_home_edit,
+    my ($group,$group_desc,$group_home_view,$group_home_edit,
         $group_view_perm,$group_edit_perm);
     my %curr_group = ();
     my %groupinfo = ();
-    if ($dom && $crs && ($udom eq $dom) && ($uname eq $crs)) {
-        $marker =~ s/\W//g;
-        $group = $marker;
+    if ($db_name =~ /^grppage_/) {
+        my ($group)=(split(m{/},$r->uri))[4];  
+	$group =~ s/\W//g;
         my %curr_groups = &Apache::longroup::coursegroups($dom,$crs,$group);
         if (!%curr_groups) {
 	    &Apache::loncommon::simple_error_page($r,'','Invalid group name');
@@ -79,13 +101,9 @@
         %groupinfo = 
 	    &Apache::longroup::get_group_settings($curr_groups{$group});
         $group_desc = &unescape($groupinfo{'description'});
-        $namespace = 'grppage_'.$group;
-    } else {
-        $marker=~s/\D//g;
-        $namespace = 'smppage_'.$marker;
     }
 
-    if (!$marker) {
+    if (!$db_name) {
 	&Apache::loncommon::simple_error_page($r,'','Invalid call');
 	return OK;
     }
@@ -115,7 +133,7 @@
         $refarg = '&ref='.$env{'form.ref'};
     }
    
-    my %syllabus=&Apache::lonnet::dump($namespace,$dom,$crs);
+    my %syllabus=&Apache::lonnet::dump($db_name,$dom,$crs);
        
 # --------------------------------------- There is such a user, get environment
 
@@ -230,7 +248,7 @@
             }
 	}
 	$syllabus{'uploaded.lastmodified'}=time;
-	&Apache::lonnet::put($namespace,\%syllabus,$dom,$crs);
+	&Apache::lonnet::put($db_name,\%syllabus,$dom,$crs);
     }
     if (($allowed) && ($env{'form.storesyl'})) {
 	foreach my $syl_field (keys(%syllabusfields)) {
@@ -243,7 +261,7 @@
 	    $syllabus{$syl_field}=$field;
 	}
 	$syllabus{'uploaded.lastmodified'}=time;
-	&Apache::lonnet::put($namespace,\%syllabus,$dom,$crs);
+	&Apache::lonnet::put($db_name,\%syllabus,$dom,$crs);
     }
 
 # ---------------------------------------------------------------- Get syllabus
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.289 loncom/interface/londocs.pm:1.290
--- loncom/interface/londocs.pm:1.289	Thu Jul 12 19:56:29 2007
+++ loncom/interface/londocs.pm	Thu Jul 12 20:29:21 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.289 2007/07/12 23:56:29 albertel Exp $
+# $Id: londocs.pm,v 1.290 2007/07/13 00:29:21 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1259,9 +1259,23 @@
 					   &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'; }