--- loncom/interface/lonparmset.pm 2004/11/23 20:36:46 1.177
+++ loncom/interface/lonparmset.pm 2004/11/24 14:57:07 1.178
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# $Id: lonparmset.pm,v 1.177 2004/11/23 20:36:46 raeburn Exp $
+# $Id: lonparmset.pm,v 1.178 2004/11/24 14:57:07 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1527,13 +1527,30 @@ sub crsenv {
if ($name =~ /^default_enrollment_(start|end)_date$/) {
$value=&Apache::lonhtmlcommon::get_date_from_form($name.'_value');
}
+ # Get existing cloners
+ my @oldcloner = ();
+ if ($name eq 'cloners') {
+ my %clonenames=&Apache::lonnet::dump('environment',$dom,$crs,'cloners');
+ if ($clonenames{'cloners'} =~ /,/) {
+ @oldcloner = split/,/,$clonenames{'cloners'};
+ } else {
+ $oldcloner[0] = $clonenames{'cloners'};
+ }
+ }
#
# Let the user know we made the changes
if ($name && defined($value)) {
+ if ($name eq 'cloners') {
+ $value =~ s/^,//;
+ $value =~ s/,$//;
+ }
my $put_result = &Apache::lonnet::put('environment',
{$name=>$value},$dom,$crs);
if ($put_result eq 'ok') {
$setoutput.=&mt('Set').' '.$name.' '.&mt('to').' '.$value.'.
';
+ if ($name eq 'cloners') {
+ &change_clone($value,\@oldcloner);
+ }
} else {
$setoutput.=&mt('Unable to set').' '.$name.' '.&mt('to').
' '.$value.' '.&mt('due to').' '.$put_result.'.
';
@@ -1908,6 +1925,90 @@ ENDOVER
}
##################################################
+##################################################
+
+=pod
+
+=item change clone
+
+Modifies the list of courses a user can clone (stored
+in the user's environemnt.db file), called when a
+change is made to the list of users allowed to clone
+a course.
+
+Inputs: $action,$cloner
+where $action is add or drop, and $cloner is identity of
+user for whom cloning ability is to be changed in course.
+
+Returns:
+
+=cut
+
+##################################################
+##################################################
+
+
+sub change_clone {
+ my ($clonelist,$oldcloner) = @_;
+ my ($uname,$udom);
+ my $cnum = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
+ my $cdom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
+ my $clone_crs = $cnum.':'.$cdom;
+
+ if ($cnum && $cdom) {
+ my @allowclone = ();
+ if ($clonelist =~ /,/) {
+ @allowclone = split/,/,$clonelist;
+ } else {
+ $allowclone[0] = $clonelist;
+ }
+ foreach my $currclone (@allowclone) {
+ if (!grep/^$currclone$/,@$oldcloner) {
+ ($uname,$udom) = split/:/,$currclone;
+ if ($uname && $udom) {
+ unless (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
+ my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
+ if ($currclonecrs{'cloneable'} !~ /\Q$clone_crs\E/) {
+ if ($currclonecrs{'cloneable'} eq '') {
+ $currclonecrs{'cloneable'} = $clone_crs;
+ } else {
+ $currclonecrs{'cloneable'} .= ','.$clone_crs;
+ }
+ &Apache::lonnet::put('environment',\%currclonecrs,$udom,$uname);
+ }
+ }
+ }
+ }
+ }
+ foreach my $oldclone (@$oldcloner) {
+ if (!grep/^$oldclone$/,@allowclone) {
+ ($uname,$udom) = split/:/,$oldclone;
+ if ($uname && $udom) {
+ unless (&Apache::lonnet::homeserver($uname,$udom) eq 'no_host') {
+ my %currclonecrs = &Apache::lonnet::dump('environment',$udom,$uname,'cloneable');
+ my %newclonecrs = ();
+ if ($currclonecrs{'cloneable'} =~ /\Q$clone_crs\E/) {
+ if ($currclonecrs{'cloneable'} =~ /,/) {
+ my @currclonecrs = split/,/,$currclonecrs{'cloneable'};
+ foreach (@currclonecrs) {
+ unless ($_ eq $clone_crs) {
+ $newclonecrs{'cloneable'} .= $_.',';
+ }
+ }
+ $newclonecrs{'cloneable'} =~ s/,$//;
+ } else {
+ $newclonecrs{'cloneable'} = '';
+ }
+ &Apache::lonnet::put('environment',\%newclonecrs,$udom,$uname);
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+##################################################
##################################################
=pod