--- loncom/interface/loncoursequeueadmin.pm 2023/08/19 23:23:05 1.68 +++ loncom/interface/loncoursequeueadmin.pm 2023/08/19 23:32:13 1.69 @@ -1,7 +1,7 @@ # The LearningOnline Network # Utilities to administer domain course requests and course self-enroll requests # -# $Id: loncoursequeueadmin.pm,v 1.68 2023/08/19 23:23:05 raeburn Exp $ +# $Id: loncoursequeueadmin.pm,v 1.69 2023/08/19 23:32:13 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -2653,12 +2653,12 @@ sub course_creation { (ref($longroles) eq 'HASH')) { return ('error: Invalid request'); } - my ($result,$ownername,$ownerdom); + my ($result,$ownername,$ownerdom,$autocoowner); my $crstype = $details->{'crstype'}; my $coursedesc = $details->{'cdescr'}; my $accessstart = $details->{'accessstart'}; my $accessend = $details->{'accessend'}; - my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom); + my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses','autoenroll'],$dom); if (ref($domconfig{'requestcourses'}) eq 'HASH') { if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') { if ($domconfig{'requestcourses'}{'uniquecode'}{$crstype}) { @@ -2666,6 +2666,9 @@ sub course_creation { } } } + if (ref($domconfig{'autoenroll'}) eq 'HASH') { + $autocoowner = $domconfig{'autoenroll'}{'co-owners'}; + } if ($context eq 'domain') { $ownername = $details->{'owner'}; $ownerdom = $details->{'domain'}; @@ -2695,6 +2698,66 @@ sub course_creation { $postprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,$result,$ownername, $ownerdom,$fullname,$coursedesc,$code, $accessstart,$accessend,$customhash); + if ($autocoowner) { + my $instcode = $details->{'instcode'}; + if (($instcode ne '') && (ref($reqdetails{'users'}) eq 'HASH')) { + my @posscoowners; + my $now = time; + foreach my $person (keys(%{$reqdetails{'users'}})) { + my ($uname,$udom) = split(/:/,$person); + next if (($udom ne $dom) || (($uname eq $ownername) && ($udom eq $ownerdom))); + if ((&Apache::lonnet::homeserver($uname,$udom,1) ne 'no_host') && + (ref($reqdetails{'users'}{$person}) eq 'HASH')) { + if ((grep(/^cc$/,keys(%{$reqdetails{'users'}{$person}}))) && + (ref($reqdetails{'users'}{$person}{'cc'}) eq 'HASH')) { + my $start = $reqdetails{'users'}{$person}{'cc'}{'start'}; + my $end = $reqdetails{'users'}{$person}{'cc'}{'end'}; + if ((($start eq '') || ($start <= $now)) && + (($end eq '') || ($end >= $now))) { + push(@posscoowners,$person); + } + } + } + } + my @coowners; + if (@posscoowners) { + foreach my $user (@posscoowners) { + my ($checkcc,$desc) = + &Apache::lonnet::auto_validate_instcode($cnum,$dom,$instcode,$user); + unless ($checkcc eq 'valid') { + if (ref($reqdetails{'crosslists'}) eq 'HASH') { + foreach my $key (keys(%{$reqdetails{'crosslists'}})) { + if (ref($reqdetails{'crosslists'}{$key}) eq 'HASH') { + my $inst_crosslist = $reqdetails{'crosslists'}{$key}{'inst'}; + if ($inst_crosslist ne '') { + $checkcc = + &Apache::lonnet::auto_validate_inst_crosslist($cnum,$dom,$instcode, + $inst_crosslist,$user); + last if ($checkcc eq 'valid'); + } + } + } + } + } + if ($checkcc eq 'valid') { + if (@coowners > 0) { + unless (grep(/^\Q$user\E$/,@coowners)) { + push(@coowners,$user); + } + } else { + push(@coowners,$user); + } + } + } + } + if (@coowners > 0) { + my $chome = &Apache::lonnet::homeserver($cnum,$dom); + unless ($chome eq 'no_host') { + &Apache::lonnet::store_coowners($dom,$cnum,$chome,'',@coowners); + } + } + } + } } else { $result = 'error: '.$cid; }