--- loncom/interface/loncreateuser.pm	2017/08/03 16:22:09	1.443
+++ loncom/interface/loncreateuser.pm	2017/08/11 00:24:53	1.446
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.443 2017/08/03 16:22:09 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.446 2017/08/11 00:24:53 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -886,7 +886,15 @@ ENDBLOCK
         (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
         (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
         my $defdom=$env{'request.role.domain'};
-        my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
+        my ($trusted,$untrusted);
+        if ($context eq 'course') {
+            ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
+        } elsif ($context eq 'author') {
+            ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
+        } elsif ($context eq 'domain') {
+            ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom); 
+        }
+        my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain',undef,undef,undef,$trusted,$untrusted);
         my %lt=&Apache::lonlocal::texthash(
                   'enro' => 'Enroll one student',
                   'enrm' => 'Enroll one member',
@@ -1476,8 +1484,10 @@ ENDAUTH
             if ($env{'request.role.domain'} eq $ccdomain) {
                 $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
             } else {
-                $r->print(&coursereq_externaluser($ccuname,$ccdomain,
-                                                  $env{'request.role.domain'}));
+                if (&Apache::lonnet::will_trust('reqcrs',$ccdomain,$env{'request.role.domain'})) {
+                    $r->print(&coursereq_externaluser($ccuname,$ccdomain,
+                                                      $env{'request.role.domain'}));
+                }
             }
             $r->print(&Apache::loncommon::end_data_table());
         }
@@ -2135,11 +2145,20 @@ sub new_domain_roles {
     '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
     &Apache::loncommon::end_data_table_header_row();
     my @allroles = &Apache::lonuserutils::roles_by_context('domain');
+    my $uprimary = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
+    my $uintdom = &Apache::lonnet::internet_dom($uprimary);
     foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
         foreach my $role (@allroles) {
             next if ($role eq 'ad');
             next if (($role eq 'au') && ($ccdomain ne $thisdomain));
             if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
+               if ($role eq 'dc') {
+                   unless ($thisdomain eq $env{'request.role.domain'}) {
+                       my $domprim = &Apache::lonnet::domain($thisdomain,'primary');
+                       my $intdom = &Apache::lonnet::internet_dom($domprim);
+                       next unless ($uintdom eq $intdom);
+                   }
+               }
                my $plrole=&Apache::lonnet::plaintext($role);
                my %lt=&Apache::lonlocal::texthash(
                     'ssd'  => "Set Start Date",
@@ -6129,10 +6148,11 @@ ENDSCRIPT
                 } elsif ($curr_types eq '') {
                     $add_domtitle = &mt('Users in other domain:');
                 }
+                my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$cdom);
                 $output .= &Apache::loncommon::start_data_table_row()
                            .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
                            .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
-                                                                $includeempty,$showdomdesc,'','','',$readonly)
+                                                                $includeempty,$showdomdesc,'',$trusted,$untrusted,$readonly)
                            .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
                            .'</td>'.&Apache::loncommon::end_data_table_row()
                            .&Apache::loncommon::end_data_table();