--- loncom/interface/lonuserutils.pm	2010/11/09 14:14:55	1.109.2.8
+++ loncom/interface/lonuserutils.pm	2010/12/05 17:28:10	1.109.2.12
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.109.2.8 2010/11/09 14:14:55 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.109.2.12 2010/12/05 17:28:10 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -630,28 +630,43 @@ END
 ###############################################################
 sub upload_manager_javascript_forward_associate {
     my ($can_assign) = @_;
-    my $auth_update;
+    my ($auth_update,$numbuttons,$argreset);
     if (ref($can_assign) eq 'HASH') {
-        if (keys(%{$can_assign}) > 1) {
+        if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
+            $argreset .= "      vf.krbarg.value='';\n";
+            $numbuttons ++ ;
+        }
+        if ($can_assign->{'int'}) {
+            $argreset .= "      vf.intarg.value='';\n";
+            $numbuttons ++;
+        }
+        if ($can_assign->{'loc'}) {
+            $argreset .= "      vf.locarg.value='';\n";
+            $numbuttons ++;
+        }
+        if (!$can_assign->{'int'}) {
+            my $warning = &mt('You may not specify an initial password for each user, as this is only available when new users use LON-CAPA internal authentication.\n').
+                          &mt('Your current role does not have rights to create users with that authentication type.');
+            $auth_update = <<"END";
+   // Currently the initial password field is only supported for internal auth
+   // (see bug 6368).
+   if (nw==2) {
+       eval('vf.f'+tf+'.selectedIndex=0;')
+       alert('$warning');
+   }
+END
+        } elsif ($numbuttons > 1) {
             $auth_update = <<"END";
    // If we set the password, make the password form below correspond to
    // the new value.
-   if (nw==9) {
+   if (nw==2) {
       changed_radio('int',document.studentform);
       set_auth_radio_buttons('int',document.studentform);
+$argreset
+   }
+
 END
         }
-        if ($can_assign->{'krb'}) {
-           $auth_update .= "      vf.krbarg.value='';\n";
-        }
-        if ($can_assign->{'int'}) {
-           $auth_update .= "      vf.intarg.value='';\n";
-        }
-        if ($can_assign->{'loc'}) {
-           $auth_update .= "     vf.locarg.value='';\n";
-        }
-        $auth_update .= "
-   }\n";
     }
 
     return(<<ENDPICK);
@@ -749,28 +764,44 @@ ENDPICK
 ###############################################################
 sub upload_manager_javascript_reverse_associate {
     my ($can_assign) = @_;
-    my $auth_update;
+    my ($auth_update,$numbuttons,$argreset);
     if (ref($can_assign) eq 'HASH') {
-        if (keys(%{$can_assign}) > 1) {
-            $auth_update = <<"END";
-    // initial password specified, pick internal authentication
-    if (tf==8 && nw!=0) {
-        changed_radio('int',document.studentform);
-        set_auth_radio_buttons('int',document.studentform);
-END
-        }
-        if ($can_assign->{'krb'}) {
-           $auth_update .= "        vf.krbarg.value='';\n";
+        if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
+            $argreset .= "      vf.krbarg.value='';\n";
+            $numbuttons ++ ;
         }
         if ($can_assign->{'int'}) {
-           $auth_update .= "        vf.intarg.value='';\n";
+            $argreset .= "      vf.intarg.value='';\n";
+            $numbuttons ++;
         }
         if ($can_assign->{'loc'}) {
-           $auth_update .= "       vf.locarg.value='';\n";
+            $argreset .= "      vf.locarg.value='';\n";
+            $numbuttons ++;
+        }
+        if (!$can_assign->{'int'}) {
+            my $warning = &mt('You may not specify an initial password, as this is only available when new users use LON-CAPA internal authentication.\n').
+                          &mt('Your current role does not have rights to create users with that authentication type.');
+            $auth_update = <<"END";
+   // Currently the initial password field is only supported for internal auth
+   // (see bug 6368).
+   if (tf==1 && nw!=0) {
+       eval('vf.f'+tf+'.selectedIndex=0;')
+       alert('$warning');
+   }
+END
+        } elsif ($numbuttons > 1) {
+            $auth_update = <<"END";
+   // initial password specified, pick internal authentication
+   if (tf==1 && nw!=0) {
+      changed_radio('int',document.studentform);
+      set_auth_radio_buttons('int',document.studentform);
+$argreset
+   }
+
+END
         }
-        $auth_update .= "
-    }\n";
     }
+
     return(<<ENDPICK);
 function verify(vf,sec_caller) {
     var founduname=0;
@@ -883,7 +914,7 @@ sub print_upload_manager_footer {
     }
     $Str .= &set_login($defdom,$krbform,$intform,$locform);
     if ($env{'form.context'} eq 'requestcrs') {
-        $Str .= '<input type="hidden" name="defaultdomain" value="gcitest" />';
+        $Str .= '<input type="hidden" name="defaultdomain" value="'.$defdom.'" />';
     }
     my ($home_server_pick,$numlib) =
         &Apache::loncommon::home_server_form_item($defdom,'lcserver',
@@ -1192,15 +1223,15 @@ sub setup_date_selectors {
 
 
 sub get_dates_from_form {
-    my ($startname,$endname) = @_;
+    my ($startname,$endname,$timezone) = @_;
     if ($startname eq '') {
         $startname = 'startdate';
     }
     if ($endname eq '') {
         $endname = 'enddate';
     }
-    my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
-    my $enddate   = &Apache::lonhtmlcommon::get_date_from_form($endname);
+    my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname,$timezone);
+    my $enddate   = &Apache::lonhtmlcommon::get_date_from_form($endname,$timezone);
     if ($env{'form.no_end_date'}) {
         $enddate = 0;
     }
@@ -2679,7 +2710,8 @@ END
                                    );
             my $navmap = Apache::lonnavmaps::navmap->new();
             if (defined($navmap)) {
-                my @allres=$navmap->retrieveResources('/uploaded/'.$cdom.'/'.$cnum.'/default_1261144274.sequence',sub { $_[0]->is_problem() },0);
+                my $sequence = &Apache::loncommon::get_citest_map($cdom);
+                my @allres=$navmap->retrieveResources('/uploaded/'.$cdom.'/'.$cnum.'/'.$sequence,sub { $_[0]->is_problem() },0);
                 foreach my $resource (@allres) {
                     my @parts = $resource->parts();
                     my $count = scalar(@parts);
@@ -4164,6 +4196,7 @@ sub upfile_drop_add {
             my @secs;
             my %entries=&Apache::loncommon::record_sep($line);
             # Determine user name
+            $entries{$fields{'username'}} =~ s/^\s+|\s+$//g;
             unless (($entries{$fields{'username'}} eq '') ||
                     (!defined($entries{$fields{'username'}}))) {
                 my ($fname, $mname, $lname,$gen) = ('','','','');
@@ -4184,13 +4217,20 @@ sub upfile_drop_add {
                         $gen=$entries{$fields{'gen'}};
                     }
                 }
+
                 if ($entries{$fields{'username'}}
                     ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
+                    my $nowhitespace;
+                    if ($entries{$fields{'username'}} =~ /\s/) {
+                        $nowhitespace = ' - '.&mt('usernames may not contain spaces.');
+                    }
                     $r->print('<br />'.
       &mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]',
-          '<b>'.$entries{$fields{'username'}}.'</b>',$fname,$mname,$lname,$gen));
+          '<b>'.$entries{$fields{'username'}}.'</b>',$fname,$mname,$lname,$gen).
+                              $nowhitespace);
                     next;
                 } else {
+                    $entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;
                     if ($entries{$fields{'domain'}} 
                         ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
                         $r->print('<br />'. '<b>'.$entries{$fields{'domain'}}.
@@ -4249,6 +4289,7 @@ sub upfile_drop_add {
                     # determine email address
                     my $email='';
                     if (defined($fields{'email'})) {
+                        $entries{$fields{'email'}} =~ s/^\s+|\s+$//g;
                         if (defined($entries{$fields{'email'}})) {
                             $email=$entries{$fields{'email'}};
                             unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
@@ -4295,7 +4336,7 @@ sub upfile_drop_add {
                         $role = $defaultrole;
                     }
                     # Clean up whitespace
-                    foreach (\$id,\$fname,\$mname,\$lname,\$gen) {
+                    foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
                         $$_ =~ s/(\s+$|^\s+)//g;
                     }
                     # check against rules
@@ -4361,8 +4402,14 @@ sub upfile_drop_add {
                             }
                         }
                         if (!$cancreate{$usertype}) {
-                            $r->print('<br />'.
-                                      &mt("[_1]: The user does not exist, and you are not permitted to create users of type: $longtypes{$usertype}.",'<b>'.$username.'</b>'));
+                            my $showtype = $longtypes{$usertype};
+                            if ($usertype eq 'unofficial') {
+                                $r->print('<br />'.
+                                          &mt("[_1]: The user does not exist, and the new user's username must be an e-mail address.",'<b>'.$username.'</b>'));
+                            } else {
+                                $r->print('<br />'.
+                                          &mt("[_1]: The user does not exist, and you are not permitted to create users of type: [_2].",'<b>'.$username.'</b>',$showtype));
+                            }
                             next;
                         }
                     } else {