--- loncom/interface/lonuserutils.pm	2015/08/05 18:47:21	1.171
+++ loncom/interface/lonuserutils.pm	2016/04/02 04:30:21	1.173
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.171 2015/08/05 18:47:21 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.173 2016/04/02 04:30:21 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4297,7 +4297,7 @@ sub upfile_drop_add {
         my $newuserdom = $env{'request.role.domain'};
         map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
         # Get new users list
-        my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%idinst_results,%alerts,%checkuname);
+        my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%alerts,%checkuname);
         my $counter = -1;
         foreach my $line (@userdata) {
             $counter ++;
@@ -4507,7 +4507,7 @@ sub upfile_drop_add {
                         }
                         $checkid = 1;
                         $newuser = 1;
-                        $checkuname{$username.':'.$newuserdom} = { 'newuser' => 1, 'id' => 1 };
+                        $checkuname{$username.':'.$newuserdom} = { 'newuser' => $newuser, 'id' => $id };
                     } else {
                         if ($context eq 'course' || $context eq 'author') {
                             if ($userdomain eq $domain ) {
@@ -4566,34 +4566,41 @@ sub upfile_drop_add {
         } # end of foreach (@userdata)
         if ($counter > -1) {
             my $total = $counter + 1;
-            my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,$total);
             my %checkids;
-            if (keys(%existinguser)) {
-                foreach my $dom (keys(%existinguser)) {
-                    if (ref($existinguser{$dom}) eq 'HASH') {
-                        my %idhash = &Apache::lonnet::idrget($dom,keys(%{$existinguser{$dom}}));
-                        foreach my $username (keys(%{$existinguser{$dom}})) {
-                            if ($idhash{$username} ne $existinguser{$dom}{$username}) {
-                                $checkids{$username.':'.$dom} = { 'id' => $existinguser{$dom}{$username} };
+            if ((keys(%existinguser)) || (keys(%checkuname))) {
+                $r->print(&mt('Please be patient -- checking for institutional data ...'));
+                $r->rflush();
+                if (keys(%existinguser)) {
+                    foreach my $dom (keys(%existinguser)) {
+                        if (ref($existinguser{$dom}) eq 'HASH') {
+                            my %idhash = &Apache::lonnet::idrget($dom,keys(%{$existinguser{$dom}}));
+                            foreach my $username (keys(%{$existinguser{$dom}})) {
+                                if ($idhash{$username} ne $existinguser{$dom}{$username}) {
+                                    $checkids{$username.':'.$dom} = {
+                                                                    'id' => $existinguser{$dom}{$username},
+                                                                    };
+                                }
+                            }
+                            if (keys(%checkids)) {
+                                &Apache::loncommon::user_rule_check(\%checkids,{ 'id' => 1 },
+                                                                    \%alerts,\%rulematch,
+                                                                    \%inst_results,\%curr_rules,
+                                                                    \%got_rules);
                             }
-                        }
-                        if (keys(%checkids)) {
-                            &Apache::loncommon::user_rule_check(\%checkids,{ 'id' => 1 },
-                                                                \%alerts,\%rulematch,
-                                                                \%idinst_results,\%curr_rules,
-                                                                \%got_rules);
                         }
                     }
                 }
+                if (keys(%checkuname)) {
+                    &Apache::loncommon::user_rule_check(\%checkuname,{ 'username' => 1, 'id' => 1, },
+                                                        \%alerts,\%rulematch,\%inst_results,
+                                                        \%curr_rules,\%got_rules);
+                }
+                $r->print(' '.&mt('done').'<br /><br />');
+                $r->rflush();
             }
-            if (keys(%checkuname)) {
-                &Apache::loncommon::user_rule_check(\%checkuname,{ 'username' => 1 },
-                                                    \%alerts,\%rulematch,\%inst_results,
-                                                    \%curr_rules,\%got_rules);
-            }
+            my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,$total);
             $r->print('<ul>');
             for (my $i=0; $i<=$counter; $i++) {
-                &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
                 if ($disallow{$i}) {
                     $r->print('<li>'.$disallow{$i}.'</li>');
                 } elsif (ref($userinfo{$i}) eq 'HASH') {
@@ -4627,6 +4634,40 @@ sub upfile_drop_add {
                                 }
                             }
                         }
+                        if (ref($inst_results{$user}) eq 'HASH') {
+                            if ($inst_results{$user}{'firstname'} ne '') {
+                                $fname = $inst_results{$user}{'firstname'};
+                            }
+                            if ($inst_results{$user}{'middlename'} ne '') {
+                                $mname = $inst_results{$user}{'middlename'};
+                            }
+                            if ($inst_results{$user}{'lasttname'} ne '') {
+                                $lname = $inst_results{$user}{'lastname'};
+                            }
+                            if ($inst_results{$user}{'permanentemail'} ne '') {
+                                $email = $inst_results{$user}{'permanentemail'};
+                            }
+                            if ($inst_results{$user}{'id'} ne '') {
+                                $id = $inst_results{$user}{'id'};
+                                $checkid = 0;
+                            }
+                            if (ref($inst_results{$user}{'inststatus'}) eq 'ARRAY') {
+                                $inststatus = join(':',@{$inst_results{$user}{'inststatus'}});
+                            }
+                        }
+                        if (($checkid) && ($id ne '')) {
+                            if (ref($alerts{'id'}) eq 'HASH') {
+                                if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
+                                    if ($alerts{'id'}{$userdomain}{$username}) {
+                                        $r->print('<li>'.
+                                                  &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
+                                                  '<b>'.$username.'</b>').'<br />'.
+                                                  &mt('Consequently, the user was not created.').'</li>');
+                                        next;
+                                    }
+                                }
+                            }
+                        }
                         my $usertype = 'unofficial';
                         if (ref($rulematch{$user}) eq 'HASH') {
                             if ($rulematch{$user}{'username'}) {
@@ -4639,18 +4680,17 @@ sub upfile_drop_add {
                                       &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].','<b>'.$username.'</b>',$showtype).'</li>');
                             next;
                         }
-                    }
-                    if ($id ne '') {
+                    } elsif ($id ne '') {
                         if (exists($checkids{$user})) {
                             $checkid = 1; 
                             if (ref($alerts{'id'}) eq 'HASH') {
                                 if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
-                                    if ($alerts{'id'}{$userdomain}{$id}) {
+                                    if ($alerts{'id'}{$userdomain}{$username}) {
                                         $r->print('<li>'.
-                                                  &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is found by your directory service.',
+                                                  &mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is not found by your directory service.',
                                                   '<b>'.$username.'</b>').'<br />'.
-                                                  &mt('Consequently, the user was not created.').'</li>');
-                                        next;
+                                                  &mt('Consequently, the ID was not changed.').'</li>');
+                                        $id = '';
                                     }
                                 }
                             }
@@ -4729,8 +4769,9 @@ sub upfile_drop_add {
                                                 $username,$userdomain,\%userchg);
                     }
                 }
-                $r->print('</ul>');
+                &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last user');
             } # end of loop
+            $r->print('</ul>');
             &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
         }
         # Flush the course logs so reverse user roles immediately updated
@@ -6201,6 +6242,8 @@ sub get_extended_type {
     }
     if ($crstype eq 'Community') {
         $type = 'community';
+    } elsif ($crstype eq 'Placement') {
+        $type = 'placement';
     } elsif ($settings{'internal.coursecode'}) {
         $type = 'official';
     } elsif ($settings{'internal.textbook'}) {