--- loncom/interface/loncoursequeueadmin.pm 2021/12/31 00:38:28 1.52.2.5.2.1 +++ loncom/interface/loncoursequeueadmin.pm 2023/09/04 17:10:13 1.52.2.5.2.3 @@ -1,7 +1,7 @@ # The LearningOnline Network # Utilities to administer domain course requests and course self-enroll requests # -# $Id: loncoursequeueadmin.pm,v 1.52.2.5.2.1 2021/12/31 00:38:28 raeburn Exp $ +# $Id: loncoursequeueadmin.pm,v 1.52.2.5.2.3 2023/09/04 17:10:13 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1619,12 +1619,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}) { @@ -1632,6 +1632,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'}; @@ -1661,6 +1664,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; } @@ -1710,6 +1773,8 @@ sub build_batchcreatehash { my %clonedfrom = &Apache::lonnet::coursedescription($details->{'clonedom'}.'_'.$details->{'clonecrs'}); $batchhash{'textbook'} = $clonedfrom{'description'}; } + } elsif ($details->{'crstype'} eq 'lti') { + $batchhash{'lti'} = 1; } $batchhash{'crstype'} = 'Course'; } @@ -2253,7 +2318,7 @@ sub postprocess_crsenv { my %needcrsidput = ( 'internal.selfenroll_types' => 1, 'internal.selfenroll_start_date' => 1, - 'internal. selfenroll_end_date' => 1, + 'internal.selfenroll_end_date' => 1, ); my (@needupdate,%newcrsenv); foreach my $key (keys(%{$postprocessenv})) {