--- loncom/interface/lonuserutils.pm	2017/08/07 20:22:13	1.185
+++ loncom/interface/lonuserutils.pm	2017/11/04 16:13:31	1.191
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.185 2017/08/07 20:22:13 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.191 2017/11/04 16:13:31 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'}){
@@ -2342,7 +2344,8 @@ function setCourseCat(formname) {
     }
     courseSet('$codetitles[1]');
     for (var j=0; j<formname.Department.length; j++) {
-        if (formname.Department.options[j].value == "$env{'form.Department'}") {            formname.Department.options[j].selected = true;
+        if (formname.Department.options[j].value == "$env{'form.Department'}") {
+            formname.Department.options[j].selected = true;
         }
     }
     if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
@@ -4113,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'});
@@ -4168,39 +4174,52 @@ 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 {
                     $r->print('<span class="LC_error">'.&mt('Error').
                               &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());
+                    if ($env{'form.fullup'} ne 'yes') {
+                        $r->print('</form>');
+                    }
+                    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('coremau',$env{'form.defaultdomain'},$defdom))) {
+                    (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) {
                     $domain = $env{'form.defaultdomain'};
                 } else {
                     $r->print('<span class="LC_error">'.&mt('Error').
                               &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());
+                    if ($env{'form.fullup'} ne 'yes') {
+                        $r->print('</form>');
+                    }
+                    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 {
                     $r->print('<span class="LC_error">'.&mt('Error').
                               &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());
+                    if ($env{'form.fullup'} ne 'yes') {
+                        $r->print('</form>');
+                    }
+                    return;
                 }
             }
         }
@@ -4215,7 +4234,9 @@ sub upfile_drop_add {
         if (! exists($home_servers{$desiredhost})) {
             $r->print('<span class="LC_error">'.&mt('Error').
                       &mt('Invalid home server specified').'</span>');
-            $r->print(&Apache::loncommon::end_page());
+            if ($env{'form.fullup'} ne 'yes') {
+                $r->print('</form>');
+            }
             return;
         }
     }