--- loncom/interface/loncreateuser.pm	2017/08/15 23:42:33	1.406.2.14.2.1
+++ 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.406.2.14.2.1 2017/08/15 23:42:33 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.446 2017/08/11 00:24:53 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -252,13 +252,15 @@ sub build_tools_display {
                    'unofficial' => 'Can request creation of unofficial courses',
                    'community'  => 'Can request creation of communities',
                    'textbook'   => 'Can request creation of textbook courses',
+                   'placement'  => 'Can request creation of placement tests',
                    'requestauthor'  => 'Can request author space',
     );
     if ($context eq 'requestcourses') {
         %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
                       'requestcourses.official','requestcourses.unofficial',
-                      'requestcourses.community','requestcourses.textbook');
-        @usertools = ('official','unofficial','community','textbook');
+                      'requestcourses.community','requestcourses.textbook',
+                      'requestcourses.placement');
+        @usertools = ('official','unofficial','community','textbook','placement');
         @options =('norequest','approval','autolimit','validate');
         %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
         %reqtitles = &courserequest_titles();
@@ -333,6 +335,7 @@ sub build_tools_display {
                    '   <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
                    '  </tr>'."\n".
                    &Apache::loncommon::start_data_table_row()."\n";
+  
         if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
             my ($curroption,$currlimit);
             my $envkey = $context.'.'.$item;
@@ -451,12 +454,14 @@ sub coursereq_externaluser {
                    'unofficial' => 'Can request creation of unofficial courses',
                    'community'  => 'Can request creation of communities',
                    'textbook'   => 'Can request creation of textbook courses',
+                   'placement'  => 'Can request creation of placement tests',
     );
 
     %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
                       'reqcrsotherdom.official','reqcrsotherdom.unofficial',
-                      'reqcrsotherdom.community','reqcrsotherdom.textbook');
-    @usertools = ('official','unofficial','community','textbook');
+                      'reqcrsotherdom.community','reqcrsotherdom.textbook',
+                      'reqcrsotherdom.placement');
+    @usertools = ('official','unofficial','community','textbook','placement');
     @options = ('approval','validate','autolimit');
     %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
     my $optregex = join('|',@options);
@@ -537,6 +542,7 @@ sub courserequest_titles {
                                    unofficial => 'Unofficial',
                                    community  => 'Communities',
                                    textbook   => 'Textbook',
+                                   placement  => 'Placement Tests',
                                    norequest  => 'Not allowed',
                                    approval   => 'Approval by Dom. Coord.',
                                    validate   => 'With validation',
@@ -880,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',
@@ -1470,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());
         }
@@ -2129,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",
@@ -2202,6 +2227,7 @@ $lt{'uuas'} ($currentauth). $lt{'adcs'}.
 ENDBADAUTH
         }
     } else { # Authentication type is valid
+        
         &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
         my ($authformcurrent,$can_modify,@authform_others) =
             &modify_login_block($ccdomain,$currentauth);
@@ -2428,7 +2454,7 @@ sub personal_data_display {
             } else {
                 undef($condition);
             }
-        }
+        } 
         if ($excluded) {
             unless ($excluded =~ /^\@[^\@]+$/) {
                 undef($condition);
@@ -2468,7 +2494,7 @@ sub personal_data_display {
                    $upasstwo.
                    &Apache::lonhtmlcommon::row_closure()."\n";
         if ($usernameset eq 'free') {
-            my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
+            my $onclick = "toggleUsernameDisp(this,'selfcreateusername');"; 
             $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
                        &mt('Use e-mail address: ').
                        '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.&mt('Yes').'</label>'."\n".
@@ -2807,7 +2833,7 @@ sub update_user_data {
     my (%alerts,%rulematch,%inst_results,%curr_rules);
     my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
     my @usertools = ('aboutme','blog','webdav','portfolio');
-    my @requestcourses = ('official','unofficial','community','textbook');
+    my @requestcourses = ('official','unofficial','community','textbook','placement');
     my @requestauthor = ('requestauthor');
     my ($othertitle,$usertypes,$types) = 
         &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
@@ -2980,7 +3006,7 @@ sub update_user_data {
              'requestcourses.community','requestcourses.textbook',
              'reqcrsotherdom.official','reqcrsotherdom.unofficial',
              'reqcrsotherdom.community','reqcrsotherdom.textbook',
-             'requestauthor'],
+             'reqcrsotherdom.placement','requestauthor'],
               $env{'form.ccdomain'},$env{'form.ccuname'});
         my ($tmp) = keys(%userenv);
         if ($tmp =~ /^(con_lost|error)/i) { 
@@ -3271,8 +3297,9 @@ sub update_user_data {
                         ($env{'user.domain'} eq $env{'form.ccdomain'})) {
                         my %newenvhash;
                         foreach my $key (keys(%changed)) {
-                            if (($key eq 'official') || ($key eq 'unofficial')
-                                || ($key eq 'community') || ($key eq 'textbook')) {
+                            if (($key eq 'official') || ($key eq 'unofficial') ||
+                                ($key eq 'community') || ($key eq 'textbook') ||
+                                ($key eq 'placement')) {
                                 $newenvhash{'environment.requestcourses.'.$key} =
                                     $changeHash{'requestcourses.'.$key};
                                 if ($changeHash{'requestcourses.'.$key}) {
@@ -3338,7 +3365,7 @@ sub update_user_data {
                                   \%newsettingstext);
                 if ($env{'form.cid'} ne $userenv{'id'}) {
                     &Apache::lonnet::idput($env{'form.ccdomain'},
-                         {$env{'form.ccuname'} => $env{'form.cid'}});
+                         {$env{'form.ccuname'} => $env{'form.cid'}},$uhome,'ids');
                     if (($recurseid) &&
                         (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
                         my $idresult = 
@@ -3481,6 +3508,7 @@ sub display_userinfo {
          'unofficial'     => 'Can Request Unofficial Courses',
          'community'      => 'Can Request Communities',
          'textbook'       => 'Can Request Textbook Courses',
+         'placement'      => 'Can Request Placement Tests',
          'requestauthor'  => 'Can Request Author Role',
          'inststatus'     => "Affiliation",
          'prvs'           => 'Previous Value:',
@@ -5011,7 +5039,7 @@ sub handler {
                                               &Apache::lonhtmlcommon::row_closure(1));
                                 }
                             }
-                            if ($pickstart) {
+                            if ($pickstart) { 
                                 $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
                             } else {
                                 $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
@@ -5601,6 +5629,7 @@ sub print_main_menu {
                                           groups => 'Community Groups',
                                         },
                        );
+        $linktext{'Placement'} = $linktext{'Course'};
 
         my %linktitle = (
             'Course' => {
@@ -5615,6 +5644,8 @@ sub print_main_menu {
                            },
         );
 
+        $linktitle{'Placement'} = $linktitle{'Course'};
+
         push(@{ $menu[0]->{items} }, #Category: Single Users
             {   
              linktext => $linktext{$crstype}{'single'},
@@ -6117,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();
@@ -8430,7 +8462,7 @@ sub user_search_result {
             my $domd_chk = &domdirectorysrch_check($srch);
             $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
             if ($domd_chk eq 'ok') {
-                $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
+                $response .= &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.');
             }
             $response .= '<br />';
         }
@@ -8441,7 +8473,7 @@ sub user_search_result {
                 my $instd_chk = &instdirectorysrch_check($srch);
                 $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
                 if ($instd_chk eq 'ok') {
-                    $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
+                    $response .= &mt('You may want to search in the institutional directory instead of in the LON-CAPA domain.');
                 }
                 $response .= '<br />';
             }
@@ -8542,7 +8574,7 @@ sub user_search_result {
                 $response = '<span class="LC_warning">'.
                     &mt('Institutional directory search is not available in domain: [_1]',$showdom).
                     '</span><br />'.
-                    &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
+                    &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
                     '<br />'; 
             }
         }
@@ -8615,7 +8647,7 @@ sub user_search_result {
                 $response = '<span class="LC_warning">'.
                     &mt('Institutional directory search is not available in domain: [_1]',$showdom).
                     '</span><br />'.
-                    &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
+                    &mt('You may want to search in the LON-CAPA domain instead of in the institutional directory.').
                     '<br />';
             }
         }