--- loncom/interface/lonuserutils.pm 2010/11/08 21:11:14 1.109.2.7 +++ loncom/interface/lonuserutils.pm 2010/11/29 04:40:12 1.109.2.11 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.109.2.7 2010/11/08 21:11:14 raeburn Exp $ +# $Id: lonuserutils.pm,v 1.109.2.11 2010/11/29 04:40:12 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -566,6 +566,7 @@ END if (message!='') { message+='\\n'; } + message+='$alert{'section'}'; } if (foundemail==0) { if (message!='') { @@ -629,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(<=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; } @@ -748,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(<=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 @@ -1189,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; } @@ -4161,6 +4195,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) = ('','','',''); @@ -4181,13 +4216,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('
'. &mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]', - ''.$entries{$fields{'username'}}.'',$fname,$mname,$lname,$gen)); + ''.$entries{$fields{'username'}}.'',$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('
'. ''.$entries{$fields{'domain'}}. @@ -4246,6 +4288,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=''; } @@ -4292,7 +4335,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 @@ -4310,7 +4353,6 @@ sub upfile_drop_add { } $checkid = 1; $newuser = 1; - my $user = $username.':'.$domain; if ($username =~/^[^\@]+\@[^\@]+$/) { if ($email eq '') { $email = $username; @@ -4334,6 +4376,7 @@ sub upfile_drop_add { } } } + my $user = $username.':'.$userdomain; if ($newuser) { my $checkhash; my $checks = { 'username' => 1 }; @@ -4358,8 +4401,14 @@ sub upfile_drop_add { } } if (!$cancreate{$usertype}) { - $r->print('
'. - &mt("[_1]: The user does not exist, and you are not permitted to create users of type: $longtypes{$usertype}.",''.$username.'')); + my $showtype = $longtypes{$usertype}; + if ($usertype eq 'unofficial') { + $r->print('
'. + &mt("[_1]: The user does not exist, and the new user's username must be an e-mail address.",''.$username.'')); + } else { + $r->print('
'. + &mt("[_1]: The user does not exist, and you are not permitted to create users of type: [_2].",''.$username.'',$showtype)); + } next; } } else {