[LON-CAPA-cvs] cvs: loncom /interface lonclonecourse.pm loncommon.pm loncreatecourse.pm lonparmset.pm
www
lon-capa-cvs-allow@mail.lon-capa.org
Tue, 22 Jan 2008 22:37:19 -0000
www Tue Jan 22 17:37:19 2008 EDT
Modified files:
/loncom/interface lonclonecourse.pm loncommon.pm loncreatecourse.pm
lonparmset.pm
Log:
Bug #2917: domain coordinator decides how much to shift during cloning
Bug #3506: do not clone dates
Index: loncom/interface/lonclonecourse.pm
diff -u loncom/interface/lonclonecourse.pm:1.5 loncom/interface/lonclonecourse.pm:1.6
--- loncom/interface/lonclonecourse.pm:1.5 Mon Jan 21 12:47:21 2008
+++ loncom/interface/lonclonecourse.pm Tue Jan 22 17:37:18 2008
@@ -1,7 +1,7 @@
# The LearningOnline Network
# routines for clone a course
#
-# $Id: lonclonecourse.pm,v 1.5 2008/01/21 17:47:21 www Exp $
+# $Id: lonclonecourse.pm,v 1.6 2008/01/22 22:37:18 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -141,7 +141,8 @@
# ========================================================== Copy resourcesdata
sub copyresourcedb {
- my ($origcrsid,$newcrsid)=@_;
+ my ($origcrsid,$newcrsid,$date_mode,$date_shift)=@_;
+ my $delta=$date_shift*60*60*24;
my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid);
my %data=&Apache::lonnet::dump
@@ -162,23 +163,42 @@
$startdate = $start{'default_enrollment_start_date'};
}
# ugly retro fix for broken version of types
- foreach (keys %data) {
- if ($_=~/\wtype$/) {
- my $newkey=$_;
+ foreach my $key (keys %data) {
+ if ($key=~/\wtype$/) {
+ my $newkey=$key;
$newkey=~s/type$/\.type/;
- $data{$newkey}=$data{$_};
- delete $data{$_};
+ $data{$newkey}=$data{$key};
+ delete $data{$key};
}
}
# adjust symbs
my $pattern='uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/';
my $new= 'uploaded/'. $newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/';
- foreach (keys %data) {
- if ($_=~/\Q$pattern\E/) {
- my $newkey=$_;
+ foreach my $key (keys %data) {
+ if ($key=~/\Q$pattern\E/) {
+ my $newkey=$key;
$newkey=~s/\Q$pattern\E/$new/;
- $data{$newkey}=$data{$_};
- delete $data{$_};
+ $data{$newkey}=$data{$key};
+ delete $data{$key};
+ }
+ }
+# transfer hash
+ foreach my $key (keys %data) {
+ my $thiskey=$key;
+ $thiskey=~s/^$origcrsid/$newcrsid/;
+ $newdata{$thiskey}=$data{$key};
+# date_mode empty or "preserve": transfer dates one-to-one
+# date_mode "shift": shift dates by date_shift days
+# date_mode other: do not transfer dates
+ if (($date_mode) && ($date_mode ne 'preserve')) {
+ if ($data{$key.'.type'}=~/^date_(start|end)$/) {
+ if ($date_mode eq 'shift') {
+ $newdata{$thiskey}=$newdata{$thiskey}+$delta;
+ } else {
+ delete($newdata{$thiskey});
+ delete($newdata{$thiskey.'.type'});
+ }
+ }
}
}
return &Apache::lonnet::put
@@ -215,10 +235,10 @@
# ======================================================= Copy all course files
sub copycoursefiles {
- my ($origcrsid,$newcrsid)=@_;
+ my ($origcrsid,$newcrsid,$date_mode,$date_shift)=@_;
©userfiles($origcrsid,$newcrsid);
©dbfiles($origcrsid,$newcrsid);
- ©resourcedb($origcrsid,$newcrsid);
+ ©resourcedb($origcrsid,$newcrsid,$date_mode,$date_shift);
}
1;
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.636 loncom/interface/loncommon.pm:1.637
--- loncom/interface/loncommon.pm:1.636 Sun Jan 20 19:35:58 2008
+++ loncom/interface/loncommon.pm Tue Jan 22 17:37:18 2008
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.636 2008/01/21 00:35:58 raeburn Exp $
+# $Id: loncommon.pm,v 1.637 2008/01/22 22:37:18 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -8083,7 +8083,7 @@
$outcome .= $clonemsg.$linefeed;
my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
# Copy all files
- &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid);
+ &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
# Restore URL
$cenv{'url'}=$oldcenv{'url'};
# Restore title
Index: loncom/interface/loncreatecourse.pm
diff -u loncom/interface/loncreatecourse.pm:1.105 loncom/interface/loncreatecourse.pm:1.106
--- loncom/interface/loncreatecourse.pm:1.105 Thu Dec 13 19:24:11 2007
+++ loncom/interface/loncreatecourse.pm Tue Jan 22 17:37:18 2008
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Create a course
#
-# $Id: loncreatecourse.pm,v 1.105 2007/12/14 00:24:11 raeburn Exp $
+# $Id: loncreatecourse.pm,v 1.106 2008/01/22 22:37:18 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -128,6 +128,9 @@
'cid' => "Course ID",
'dmn' => "Domain",
'asov' => "Additional settings, if specified below, will override cloned settings",
+ 'ncd' => "Do not clone date parameters",
+ 'prd' => 'Clone date parameters as-is',
+ 'shd' => 'Shift date parameters by number of days',
'assp' => "Assessment Parameters",
'oaas' => "Open all assessments",
'mssg' => "Messaging",
@@ -300,6 +303,10 @@
$lt{'dmn'}: $cloneform
</label>
<br />
+ <label><input type="radio" name="datemode" value="delete" /> $lt{'ncd'}</label><br />
+ <label><input type="radio" name="datemode" value="preserve" /> $lt{'prd'}</label><br />
+ <label><input type="radio" name="datemode" value="shift" checked="checked" /> $lt{'shd'}</label>
+ <input type="text" size="5" name="dateshift" value="365" /><br />
<br />
$lt{'asov'}.
</td></tr>
@@ -486,7 +493,10 @@
$lt{'dmn'}: $cloneform
</label>
<br />
- <br />
+ <label><input type="radio" name="datemode" value="delete" /> $lt{'ncd'}</label><br />
+ <label><input type="radio" name="datemode" value="preserve" /> $lt{'prd'}</label><br />
+ <label><input type="radio" name="datemode" value="shift" checked="checked" /> $lt{'shd'}</label>
+ <input type="text" size="5" name="dateshift" value="365" /><br /> <br />
$lt{'asov'}.
</td></tr>
</table>
@@ -616,6 +626,8 @@
crsquota => $env{'form.crsquota'},
clonecourse => $env{'form.clonecourse'},
clonedomain => $env{'form.clonedomain'},
+ datemode => $env{'form.datemode'},
+ dateshift => $env{'form.dateshift'},
crsid => $env{'form.crsid'},
curruser => $env{'user.name'}.':'.$env{'user.domain'},
crssections => $env{'form.crssections'},
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.388 loncom/interface/lonparmset.pm:1.389
--- loncom/interface/lonparmset.pm:1.388 Fri Nov 30 22:45:17 2007
+++ loncom/interface/lonparmset.pm Tue Jan 22 17:37:18 2008
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# $Id: lonparmset.pm,v 1.388 2007/12/01 03:45:17 albertel Exp $
+# $Id: lonparmset.pm,v 1.389 2008/01/22 22:37:18 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2824,6 +2824,33 @@
return $result;
}
+#
+# Shift all start and end dates by $shift
+#
+
+sub dateshift {
+ my ($shift)=@_;
+ my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my %data=&Apache::lonnet::dump('resourcedata',$dom,$crs);
+# ugly retro fix for broken version of types
+ foreach my $key (keys %data) {
+ if ($key=~/\wtype$/) {
+ my $newkey=$key;
+ $newkey=~s/type$/\.type/;
+ $data{$newkey}=$data{$key};
+ delete $data{$key};
+ }
+ }
+# go through all parameters and look for dates
+ foreach my $key (keys %data) {
+ if ($data{$key.'.type'}=~/^date_(start|end)$/) {
+ my $newdate=$data{$key}+$shift;
+ &Apache::lonnet::put('resourcedata',{$key => $newdate},$dom,$crs);
+ }
+ }
+}
+
sub newoverview {
my ($r) = @_;