--- loncom/interface/lonuserutils.pm	2010/11/08 21:08:27	1.109.2.6
+++ loncom/interface/lonuserutils.pm	2010/11/09 14:14:55	1.109.2.8
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.109.2.6 2010/11/08 21:08:27 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.109.2.8 2010/11/09 14:14:55 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -330,7 +330,7 @@ sub print_upload_manager_header {
     my ($sectionjs,$groupslist);
     if ($context eq 'course') {
         $groupslist = &get_groupslist();
-        if ($env{'form.caller'} eq 'requestcrs') {
+        if ($env{'form.context'} eq 'requestcrs') {
             $sectionjs = <<"ENDJS";
 
 function toggleSectionsDefault() {
@@ -375,7 +375,7 @@ ENDJS
               &hidden_input('fileupload',$env{'form.fileupload'}).
               &hidden_input('upfiletype',$env{'form.upfiletype'}).
               &hidden_input('upfile_associate',$env{'form.upfile_associate'}).
-              &hidden_input('caller',$env{'form.caller'}));
+              &hidden_input('context',$env{'form.context'}));
     $r->print('<br /><label><input type="checkbox" name="noFirstLine"'.$checked.' />'.
               &mt('Ignore First Line').'</label><br />');
     $r->print('<br /><input type="button" value="'.&mt('Reverse Association').'" '.
@@ -415,7 +415,7 @@ sub javascript_validations {
             if ($context eq 'course') {
                 if ($env{'request.course.sec'} eq '') {
                     $setsection_call = 'setSections(document.'.$param{'formname'}.",'$crstype'".');';
-                    if ($env{'form.caller'} eq 'requestcrs') {
+                    if ($env{'form.context'} eq 'requestcrs') {
                         $setsections_js =  &newsections_javascript($param{'formname'});
                     } else {
                         $setsections_js =
@@ -550,7 +550,7 @@ END
     } else {
         $section_checks = &section_check_js();
 
-        unless ($env{'form.caller'} eq 'requestcrs') {
+        unless ($env{'form.context'} eq 'requestcrs') {
             $optional_checks = (<<END);
     var message='';
     if (foundname==0) {
@@ -566,6 +566,7 @@ END
         if (message!='') {
             message+='\\n';
         }
+        message+='$alert{'section'}';
     }
     if (foundemail==0) {
         if (message!='') {
@@ -598,7 +599,7 @@ END
     }
 END
         }
-        if ($env{'form.caller'} eq 'requestcrs') {
+        if ($env{'form.context'} eq 'requestcrs') {
             $optional_checks .= (<<END);
     vf.state.value='enrolling';
     $finish
@@ -668,10 +669,10 @@ function verify(vf,sec_caller) {
     for (i=0;i<=vf.nfields.value;i++) {
         tw=eval('vf.f'+i+'.selectedIndex');
         if (tw==1) { founduname=1; }
-        if ((tw>=2) && (tw<=6)) { foundname=1; }
-        if (tw==7) { foundid=1; }
-        if (tw==8) { foundsec=1; }
-        if (tw==9) { foundpwd=1; }
+        if (tw==2) { foundpwd=1; }
+        if ((tw>=3) && (tw<=7)) { foundname=1; }
+        if (tw==8) { foundid=1; }
+        if (tw==9) { foundsec=1; }
         if (tw==10) { foundemail=1; }
         if (tw==11) { foundrole=1; }
         if (tw==12) { founddomain=1; }
@@ -688,14 +689,14 @@ function verify(vf,sec_caller) {
 //
 // 0 = none
 // 1 = username
-// 2 = names (lastname, firstnames)
-// 3 = fname (firstname)
-// 4 = mname (middlename)
-// 5 = lname (lastname)
-// 6 = gen   (generation)
-// 7 = id
-// 8 = section
-// 9 = ipwd  (password)
+// 2 = ipwd  (password)
+// 3 = names (lastname, firstnames)
+// 4 = fname (firstname)
+// 5 = mname (middlename)
+// 6 = lname (lastname)
+// 7 = gen   (generation)
+// 8 = id
+// 9 = section
 // 10 = email address
 // 11 = role
 // 12 = domain
@@ -711,20 +712,20 @@ function flip(vf,tf) {
       }
    }
    // If we set this to 'lastname, firstnames', clear out all the ones
-   // set to 'fname','mname','lname','gen' (3,4,5,6) currently.
-   if (nw==2) {
+   // set to 'fname','mname','lname','gen' (4,5,6,7) currently.
+   if (nw==3) {
       for (i=0;i<=vf.nfields.value;i++) {
-         if ((eval('vf.f'+i+'.selectedIndex')>=3) &&
-             (eval('vf.f'+i+'.selectedIndex')<=6)) {
+         if ((eval('vf.f'+i+'.selectedIndex')>=4) &&
+             (eval('vf.f'+i+'.selectedIndex')<=7)) {
              eval('vf.f'+i+'.selectedIndex=0;')
          }
       }
    }
-   // If we set this to one of 'fname','mname','lname','gen' (3,4,5,6),
-   // clear out any that are set to 'lastname, firstnames' (2)
-   if ((nw>=3) && (nw<=6)) {
+   // If we set this to one of 'fname','mname','lname','gen' (4,5,6,7),
+   // clear out any that are set to 'lastname, firstnames' (3)
+   if ((nw>=4) && (nw<=7)) {
       for (i=0;i<=vf.nfields.value;i++) {
-         if (eval('vf.f'+i+'.selectedIndex')==2) {
+         if (eval('vf.f'+i+'.selectedIndex')==3) {
              eval('vf.f'+i+'.selectedIndex=0;')
          }
       }
@@ -735,7 +736,7 @@ function flip(vf,tf) {
 function clearpwd(vf) {
     var i;
     for (i=0;i<=vf.nfields.value;i++) {
-        if (eval('vf.f'+i+'.selectedIndex')==9) {
+        if (eval('vf.f'+i+'.selectedIndex')==2) {
             eval('vf.f'+i+'.selectedIndex=0;')
         }
     }
@@ -777,6 +778,7 @@ function verify(vf,sec_caller) {
     var foundname=0;
     var foundid=0;
     var foundsec=0;
+    var foundemail=0;
     var foundrole=0;
     var founddomain=0;
     var foundinststatus=0;
@@ -784,38 +786,39 @@ function verify(vf,sec_caller) {
     for (i=0;i<=vf.nfields.value;i++) {
         tw=eval('vf.f'+i+'.selectedIndex');
         if (i==0 && tw!=0) { founduname=1; }
-        if (((i>=1) && (i<=5)) && tw!=0 ) { foundname=1; }
-        if (i==6 && tw!=0) { foundid=1; }
-        if (i==7 && tw!=0) { foundsec=1; }
-        if (i==8 && tw!=0) { foundpwd=1; }
-        if (i==9 && tw!=0) { foundrole=1; }
-        if (i==10 && tw!=0) { founddomain=1; }
-        if (i==13 && tw!=0) { foundinstatus=1; }
+        if (i==1 && tw!=0) { foundpwd=1; }
+        if (((i>=2) && (i<=6)) && tw!=0 ) { foundname=1; }
+        if (i==7 && tw!=0) { foundid=1; }
+        if (i==8 && tw!=0) { foundsec=1; }
+        if (i==9 && tw!=0) { foundemail=1; }
+        if (i==10 && tw!=0) { foundrole=1; }
+        if (i==11 && tw!=0) { founddomain=1; }
+        if (i==12 && tw!=0) { foundinstatus=1; }
     }
-    verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundrole,founddomain,foundinststatus);
+    verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus);
 }
 
 function flip(vf,tf) {
    var nw=eval('vf.f'+tf+'.selectedIndex');
    var i;
    // picked the all one name field, reset the other name ones to blank
-   if (tf==1 && nw!=0) {
-      for (i=2;i<=5;i++) {
+   if (tf==2 && nw!=0) {
+      for (i=3;i<=6;i++) {
          eval('vf.f'+i+'.selectedIndex=0;')
       }
    }
    //picked one of the piecewise name fields, reset the all in
    //one field to blank
-   if ((tf>=2) && (tf<=5) && (nw!=0)) {
-      eval('vf.f1.selectedIndex=0;')
+   if ((tf>=3) && (tf<=6) && (nw!=0)) {
+      eval('vf.f2.selectedIndex=0;')
    }
    $auth_update
 }
 
 function clearpwd(vf) {
     var i;
-    if (eval('vf.f8.selectedIndex')!=0) {
-        eval('vf.f8.selectedIndex=0;')
+    if (eval('vf.f1.selectedIndex')!=0) {
+        eval('vf.f1.selectedIndex=0;')
     }
 }
 ENDPICK
@@ -838,8 +841,8 @@ sub print_upload_manager_footer {
         $env{'form.ipwd_choice'} ne '') {
         $param{'curr_authtype'} = 'int';
     }
-    if ($env{'form.caller'} eq 'requestcrs') {
-        $param{'caller'} = $env{'form.caller'};
+    if ($env{'form.context'} eq 'requestcrs') {
+        $param{'context'} = $env{'form.context'};
     }
     my $krbform = &Apache::loncommon::authform_kerberos(%param);
     my $intform = &Apache::loncommon::authform_internal(%param);
@@ -853,7 +856,7 @@ sub print_upload_manager_footer {
 
     $Str .= '<h3>'.&mt('Options').'</h3>'
            .&Apache::lonhtmlcommon::start_pick_box();
-    if ($env{'form.caller'} eq 'requestcrs') {
+    if ($env{'form.context'} eq 'requestcrs') {
         $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default password'));
     } else {
         $Str .= &Apache::lonhtmlcommon::row_title(&mt('Login Type'));
@@ -879,7 +882,7 @@ sub print_upload_manager_footer {
             $Str .= "</p>\n";
     }
     $Str .= &set_login($defdom,$krbform,$intform,$locform);
-    if ($env{'form.caller'} eq 'requestcrs') {
+    if ($env{'form.context'} eq 'requestcrs') {
         $Str .= '<input type="hidden" name="defaultdomain" value="gcitest" />';
     }
     my ($home_server_pick,$numlib) =
@@ -897,7 +900,7 @@ sub print_upload_manager_footer {
                 &Apache::lonhtmlcommon::row_closure();
     }
 
-    unless ($env{'form.caller'} eq 'requestcrs') {
+    unless ($env{'form.context'} eq 'requestcrs') {
         $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain'))
                .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1)
                .&Apache::lonhtmlcommon::row_closure()
@@ -924,7 +927,7 @@ sub print_upload_manager_footer {
                     &mt('Default role'))
                .&mt('Choose the role to assign to users without a value specified in the uploaded file.')
     } elsif ($context eq 'course') {
-        if ($env{'form.caller'} eq 'requestcrs') {
+        if ($env{'form.context'} eq 'requestcrs') {
             $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default section')).
                     &mt('Students can be assigned to different sections.').'<br />'.
                     &mt('Will you be using sections?').'&nbsp;'.
@@ -964,7 +967,7 @@ sub print_upload_manager_footer {
     } else {
         my ($cnum,$cdom) = &get_course_identity();
         my ($rowtitle,$closure);
-        if ($env{'form.caller'} eq 'requestcrs') {
+        if ($env{'form.context'} eq 'requestcrs') {
             $closure = 1;
             $rowtitle = &mt('default section name (letters/numbers only)');
         } else {
@@ -972,9 +975,9 @@ sub print_upload_manager_footer {
         }
         my $secbox = &section_picker($cdom,$cnum,'Any',$rowtitle,
                                     $permission,$context,'upload',$crstype,
-                                    $env{'form.caller'}).
+                                    $env{'form.context'}).
                      &Apache::lonhtmlcommon::row_closure($closure);
-        if ($env{'form.caller'} eq 'requestcrs') {
+        if ($env{'form.context'} eq 'requestcrs') {
             $Str .= '<div id ="defaultsec" style="display: none" />'.$secbox.'</div>';
         } else {
             $Str .= $secbox; 
@@ -991,7 +994,7 @@ sub print_upload_manager_footer {
                     stus => 'Students selected from this list can be dropped.'
             );
         }
-        unless ($env{'form.caller'} eq 'requestcrs') {
+        unless ($env{'form.context'} eq 'requestcrs') {
             $Str .= &Apache::lonhtmlcommon::row_title(&mt('Full Update'))
                    .'<label><input type="checkbox" name="fullup" value="yes" />'
                    .' '.$lt{'disp'}
@@ -1001,7 +1004,7 @@ sub print_upload_manager_footer {
         }
     }
     if ($context eq 'course' || $context eq 'domain') {
-        unless ($env{'form.caller'} eq 'requestcrs') {
+        unless ($env{'form.context'} eq 'requestcrs') {
             $Str .= &forceid_change($context);
         }
     }
@@ -3910,7 +3913,7 @@ sub print_first_users_upload_form {
            .&Apache::lonhtmlcommon::end_pick_box();
 
     $str .= '<p>'
-           .'<input type="hidden" name=caller" value="'.$caller.'" />' 
+           .'<input type="hidden" name="context" value="'.$caller.'" />' 
            .'<input type="submit" name="fileupload" value="'.&mt('Next').'" />'
            .'</p>';
 
@@ -3935,7 +3938,7 @@ sub upfile_drop_add {
             $fields{$env{'form.f'.$i}}=$keyfields[$i];
         }
     }
-    if ($env{'form.fullup'} ne 'yes') {
+    if (($env{'form.fullup'} ne 'yes') && ($env{'form.context'} ne 'requestcrs')) {
         $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
                   '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />');
     }
@@ -3974,7 +3977,7 @@ sub upfile_drop_add {
         }
     }
     my ($startdate,$enddate);
-    if ($env{'form.caller'} eq 'requestcrs') {
+    if ($env{'form.context'} eq 'requestcrs') {
         $startdate = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_start_date'};
         $enddate = $env{'course.'.$env{'request.course.id'}.'.default_enrollment_end_date'};
     } else {
@@ -4310,7 +4313,6 @@ sub upfile_drop_add {
                         }
                         $checkid = 1;
                         $newuser = 1;
-                        my $user = $username.':'.$domain;
                         if ($username =~/^[^\@]+\@[^\@]+$/) {
                             if ($email eq '') {
                                 $email = $username;
@@ -4334,6 +4336,7 @@ sub upfile_drop_add {
                             }
                         }
                     }
+                    my $user = $username.':'.$userdomain;
                     if ($newuser) {
                         my $checkhash;
                         my $checks = { 'username' => 1 };