--- loncom/interface/loncoursequeueadmin.pm 2014/04/19 20:48:43 1.46 +++ loncom/interface/loncoursequeueadmin.pm 2016/04/04 01:09:48 1.53 @@ -1,7 +1,7 @@ # The LearningOnline Network # Utilities to administer domain course requests and course self-enroll requests # -# $Id: loncoursequeueadmin.pm,v 1.46 2014/04/19 20:48:43 raeburn Exp $ +# $Id: loncoursequeueadmin.pm,v 1.53 2016/04/04 01:09:48 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -523,6 +523,7 @@ sub build_queue_display { unofficial => 'Unofficial course', community => 'Community', textbook => 'Textbook course', + placement => 'Placement test', ); $output .= ''.&mt('Type').''. ''.&mt('Date requested').''. @@ -968,6 +969,9 @@ sub update_request_queue { } } } + if ($history{'details'}{'clonecrs'}) { + $customitems{'_LC_clonefrom'} = $history{'details'}{'clonedom'}.'_'.$history{'details'}{'clonecrs'}; + } my ($result,$postprocess) = &course_creation($cdom,$cnum,$context,$history{'details'},\$logmsg, \$newusermsg,\$addresult,\$enrollcount, \$response,\$keysmsg,\%domdefs,$longroles,\$code,\%customitems); @@ -1311,7 +1315,7 @@ sub update_request_queue { my $syllabuslink = &Apache::loncommon::syllabuswrapper($showcourse,$cnum,$cdom); if ($codes{$cnum}) { - $syllabuslink .= &mt('Unique code: [_1]',$codes{$cnum}); + $syllabuslink .= ' '.&mt('Unique code: [_1]',$codes{$cnum}); } $output .= '
  • '.$syllabuslink.'
  • '; } @@ -1600,12 +1604,14 @@ sub course_creation { $keysmsg,$domdefs,$longroles,$coderef,$customhash) = @_; unless ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH') && (ref($longroles) eq 'HASH')) { - return 'error: Invalid request'; + return ('error: Invalid request'); } my ($result,$ownername,$ownerdom); my $crstype = $details->{'crstype'}; my $coursedesc = $details->{'cdescr'}; - my %domconfig = &Apache::lonnet::get_dom('configuration',['requestauthor'],$dom); + my $accessstart = $details->{'accessstart'}; + my $accessend = $details->{'accessend'}; + my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$dom); if (ref($domconfig{'requestcourses'}) eq 'HASH') { if (ref($domconfig{'requestcourses'}{'uniquecode'}) eq 'HASH') { if ($domconfig{'requestcourses'}{'uniquecode'}{$crstype}) { @@ -1639,7 +1645,8 @@ sub course_creation { $code = $$coderef; } $postprocess = &Apache::lonnet::auto_crsreq_update($dom,$cnum,$crstype,$result,$ownername, - $ownerdom,$fullname,$coursedesc,$code,$customhash); + $ownerdom,$fullname,$coursedesc,$code, + $accessstart,$accessend,$customhash); } else { $result = 'error: '.$cid; } @@ -1668,6 +1675,8 @@ sub build_batchcreatehash { $batchhash{'authparam'} = $domdefs->{'auth_arg_def'}; if ($details->{'crstype'} eq 'community') { $batchhash{'crstype'} = 'Community'; + } elsif ($details->{'crstype'} eq 'placement') { + $batchhash{'crstype'} = 'Placement'; } else { if ($details->{'crstype'} eq 'textbook') { if ($details->{'clonecrs'} && $details->{'clonedom'}) { @@ -1718,7 +1727,7 @@ sub build_batchcreatehash { } sub can_clone_course { - my ($uname,$udom,$clonecrs,$clonedom,$crstype) = @_; + my ($uname,$udom,$clonecrs,$clonedom,$crstype,$dom,$instcode) = @_; my $canclone; my $ccrole = 'cc'; if ($crstype eq 'community') { @@ -1729,19 +1738,70 @@ sub can_clone_course { if (exists($roleshash{$clonecrs.':'.$clonedom.':'.$ccrole})) { $canclone = 1; } else { - my %courseenv = &Apache::lonnet::userenvironment($clonedom,$clonecrs,('cloners')); + my %courseenv = &Apache::lonnet::userenvironment($clonedom,$clonecrs, + ('cloners','internal.coursecode')); my $cloners = $courseenv{'cloners'}; + my $clonefromcode = $courseenv{'internal.coursecode'}; if ($cloners ne '') { my @cloneable = split(',',$cloners); if (grep(/^\*$/,@cloneable)) { $canclone = 1; - } - if (grep(/^\*:\Q$udom\E$/,@cloneable)) { + } elsif (grep(/^\*:\Q$udom\E$/,@cloneable)) { $canclone = 1; - } - if (grep(/^\Q$uname\E:\Q$udom\E$/,@cloneable)) { + } elsif (grep(/^\Q$uname\E:\Q$udom\E$/,@cloneable)) { $canclone = 1; } + unless ($canclone) { + if (($clonefromcode) && ($instcode) && ($clonedom eq $dom)) { + my (%gotdomdefaults,%gotcodedefaults); + foreach my $cloner (@cloneable) { + if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) && + ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) { + if ($cloner =~ /\=/) { + my (%codedefaults,@code_order); + if (ref($gotcodedefaults{$clonedom}) eq 'HASH') { + if (ref($gotcodedefaults{$clonedom}{'defaults'}) eq 'HASH') { + %codedefaults = %{$gotcodedefaults{$clonedom}{'defaults'}}; + } + if (ref($gotcodedefaults{$clonedom}{'order'}) eq 'ARRAY') { + @code_order = @{$gotcodedefaults{$dom}{'order'}}; + } + } else { + &Apache::lonnet::auto_instcode_defaults($clonedom, + \%codedefaults, + \@code_order); + $gotcodedefaults{$clonedom}{'defaults'} = \%codedefaults; + $gotcodedefaults{$clonedom}{'order'} = \@code_order; + } + if (@code_order > 0) { + if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order, + $cloner,$clonefromcode,$instcode)) { + $canclone = 1; + last; + } + } + } + } + } + } + } + } else { + my %domdefs = &Apache::lonnet::get_domain_defaults($clonedom); + if ($domdefs{'canclone'}) { + unless ($domdefs{'canclone'} eq 'none') { + if ($domdefs{'canclone'} eq 'domain') { + if ($udom eq $clonedom) { + $canclone = 1; + } + } elsif (($clonefromcode) && ($instcode) && + ($clonedom eq $dom)) { + if (&Apache::lonnet::default_instcode_cloning($clonedom,$domdefs{'canclone'}, + $clonefromcode,$instcode)) { + $canclone = 1; + } + } + } + } } unless ($canclone) { if (&Apache::lonnet::is_course_owner($clonedom,$clonecrs,$uname,$udom)) { @@ -2023,6 +2083,9 @@ sub process_official_reqs { } } } + if ($history{'details'}{'clonecrs'}) { + $customitems{'_LC_clonefrom'} = $history{'details'}{'clonedom'}.'_'.$history{'details'}{'clonecrs'}; + } my ($result,$postprocess) = &course_creation($dom,$cnum,'domain',$history{'details'},\$logmsg,\$newusermsg,\$addresult, \$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles,\$code,\%customitems); @@ -2059,6 +2122,11 @@ sub process_official_reqs { } } } + if (ref($postprocess->{'createdactions'}) eq 'HASH') { + if (ref($postprocess->{'createdactions'}{'environment'}) eq 'HASH') { + &postprocess_crsenv($dom,$cnum,$postprocess->{'createdactions'}{'environment'}); + } + } } &send_selfserve_notification($owner,$approvedmsg, $cid,$cdescr,$now, @@ -2130,6 +2198,56 @@ sub process_official_reqs { return $output; } +sub postprocess_crsenv { + my ($dom,$cnum,$postprocessenv) = @_; + if (ref($postprocessenv) eq 'HASH') { + my $cid = $dom.'_'.$cnum; + my %settablecrsenv = ( + 'internal.selfenroll_types' => 1, + 'internal.selfenroll_registered' => 1, + 'internal.selfenroll_section' => 1, + 'internal.selfenroll_start_access' => 1, + 'internal.selfenroll_end_access' => 1, + 'internal.selfenroll_limit' => 1, + 'internal.selfenroll_cap' => 1, + 'internal.selfenroll_approval' => 1, + 'internal.selfenroll_notifylist' => 1, + ); + my %needcrsidput = ( + 'internal.selfenroll_types' => 1, + 'internal.selfenroll_start_date' => 1, + 'internal. selfenroll_end_date' => 1, + ); + my (@needupdate,%newcrsenv); + foreach my $key (keys(%{$postprocessenv})) { + if ($settablecrsenv{$key}) { + $newcrsenv{$key} = $postprocessenv->{$key}; + if ($needcrsidput{$key}) { + push(@needupdate,$key); + } + } + if (keys(%newcrsenv)) { + my $putresult = &Apache::lonnet::put('environment',\%newcrsenv,$dom,$cnum); + if ($putresult eq 'ok') { + if (@needupdate) { + my %crsinfo = + &Apache::lonnet::courseiddump($dom,'.',1,'.','.',$cnum,undef,undef,'.'); + if (ref($crsinfo{$cid}) eq 'HASH') { + foreach my $key (@needupdate) { + $crsinfo{$cid}{$key} = $newcrsenv{$key}; + } + my $chome = &Apache::lonnet::homeserver($cnum,$dom); + &Apache::lonnet::courseidput($dom,\%crsinfo,$chome,'notime'); + } + } + } + } + } + } + return; +} + + sub requestcourses_validation_types { my @items = ('url','fields','button','markup'); my %names = &Apache::lonlocal::texthash (