--- loncom/interface/lonuserutils.pm	2017/08/09 19:20:50	1.187
+++ loncom/interface/lonuserutils.pm	2017/08/11 20:14:44	1.190
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.187 2017/08/09 19:20:50 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.190 2017/08/11 20:14:44 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -943,14 +943,14 @@ sub print_upload_manager_footer {
                 &Apache::lonhtmlcommon::row_closure();
     }
 
-    my ($trustedref,$untrustedref);
+    my ($trusted,$untrusted);
     if ($context eq 'course') {
-        ($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('enroll',$defdom);
+        ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
     } elsif ($context eq 'author') {
-        ($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
+        ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
     }
     $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain'))
-           .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1,undef,$trustedref,$untrustedref)
+           .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1,undef,$trusted,$untrusted)
            .&Apache::lonhtmlcommon::row_closure();
 
     $Str .= &Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates'))
@@ -1127,8 +1127,10 @@ sub print_upload_manager_form {
     if (!$env{'form.datatoken'}) {
         $datatoken=&Apache::loncommon::upfile_store($r);
     } else {
-        $datatoken=$env{'form.datatoken'};
-        &Apache::loncommon::load_tmp_file($r);
+        $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'});
+        if ($datatoken ne '') {
+            &Apache::loncommon::load_tmp_file($r,$datatoken);
+        }
     }
     my @records=&Apache::loncommon::upfile_record_sep();
     if($env{'form.noFirstLine'}){
@@ -4114,7 +4116,10 @@ sub print_first_users_upload_form {
 # ================================================= Drop/Add from uploaded file
 sub upfile_drop_add {
     my ($r,$context,$permission,$showcredits) = @_;
-    &Apache::loncommon::load_tmp_file($r);
+    my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});
+    if ($datatoken ne '') {
+        &Apache::loncommon::load_tmp_file($r,$datatoken);
+    }
     my @userdata=&Apache::loncommon::upfile_record_sep();
     if($env{'form.noFirstLine'}){shift(@userdata);}
     my @keyfields = split(/\,/,$env{'form.keyfields'});
@@ -4169,7 +4174,9 @@ sub upfile_drop_add {
     my $domain;
     if ($env{'form.defaultdomain'} ne '') {
         if (($context eq 'course') || ($setting eq 'course')) {
-            unless ($env{'form.defaultdomain'} eq $crsdom) {
+            if ($env{'form.defaultdomain'} eq $crsdom) {
+                $domain = $env{'form.defaultdomain'};
+            } else {
                 if (&Apache::lonnet::will_trust('enroll',$crsdom,$env{'form.defaultdomain'})) {
                     $domain = $env{'form.defaultdomain'};
                 } else {
@@ -4177,11 +4184,13 @@ sub upfile_drop_add {
                               &mt('Enrollment of users not permitted for specified default domain: [_1].',
                                   &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
                     $r->print(&Apache::loncommon::end_page());
+                    return;
                 }
-                return;
             }
         } elsif ($context eq 'author') {
-            unless ($env{'form.defaultdomain'} eq $defdom) {
+            if ($env{'form.defaultdomain'} eq $defdom) {
+                $domain = $env{'form.defaultdomain'}; 
+            } else {
                 if ((&Apache::lonnet::will_trust('othcoau',$defdom,$env{'form.defaultdomain'})) &&
                     (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) {
                     $domain = $env{'form.defaultdomain'};
@@ -4190,11 +4199,13 @@ sub upfile_drop_add {
                               &mt('Addition of users not permitted for specified default domain: [_1].',
                                   &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
                     $r->print(&Apache::loncommon::end_page());
+                    return;
                 }
-                return; 
             }
         } elsif (($context eq 'domain') && ($setting eq 'domain')) {
-            unless ($env{'form.defaultdomain'} eq $defdom) {
+            if ($env{'form.defaultdomain'} eq $defdom) {
+                $domain = $env{'form.defaultdomain'};
+            } else {
                 if (&Apache::lonnet::will_trust('domroles',$defdom,$env{'form.defaultdomain'})) {
                     $domain = $env{'form.defaultdomain'};
                 } else {
@@ -4202,6 +4213,7 @@ sub upfile_drop_add {
                               &mt('Addition of users not permitted for specified default domain: [_1].',
                                   &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
                     $r->print(&Apache::loncommon::end_page());
+                    return;
                 }
             }
         }