[LON-CAPA-cvs] cvs: loncom /interface lonparmset.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Wed, 24 Nov 2004 14:57:08 -0000
raeburn Wed Nov 24 09:57:08 2004 EDT
Modified files:
/loncom/interface lonparmset.pm
Log:
Can now add and remove from list of users who can clone course. Appropriate changes made in environment.db for course, as well as in environment.db for users who were added or dropped.
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.177 loncom/interface/lonparmset.pm:1.178
--- loncom/interface/lonparmset.pm:1.177 Tue Nov 23 15:36:46 2004
+++ loncom/interface/lonparmset.pm Wed Nov 24 09:57:07 2004
@@ -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 @@
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').' <b>'.$name.'</b> '.&mt('to').' <b>'.$value.'</b>.<br />';
+ if ($name eq 'cloners') {
+ &change_clone($value,\@oldcloner);
+ }
} else {
$setoutput.=&mt('Unable to set').' <b>'.$name.'</b> '.&mt('to').
' <b>'.$value.'</b> '.&mt('due to').' '.$put_result.'.<br />';
@@ -1909,6 +1926,90 @@
##################################################
##################################################
+
+=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