--- loncom/interface/loncreateuser.pm 2007/08/02 01:04:41 1.167
+++ loncom/interface/loncreateuser.pm 2007/11/10 03:51:46 1.193
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.167 2007/08/02 01:04:41 albertel Exp $
+# $Id: loncreateuser.pm,v 1.193 2007/11/10 03:51:46 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -65,10 +65,10 @@ use Apache::lonnet;
use Apache::loncommon;
use Apache::lonlocal;
use Apache::longroup;
+use Apache::lonuserutils;
use LONCAPA qw(:DEFAULT :match);
my $loginscript; # piece of javascript used in two separate instances
-my $generalrule;
my $authformnop;
my $authformkrb;
my $authformint;
@@ -76,14 +76,24 @@ my $authformfsys;
my $authformloc;
sub initialize_authen_forms {
+ my ($dom,$curr_authtype) = @_;
my ($krbdefdom)=( $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/);
$krbdefdom= uc($krbdefdom);
my %param = ( formname => 'document.cu',
- kerb_def_dom => $krbdefdom
- );
+ kerb_def_dom => $krbdefdom,
+ domain => $dom,
+ );
+ my %abv_auth = &auth_abbrev();
+ if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):$/) {
+ my $long_auth = $1;
+ my %abv_auth = &auth_abbrev();
+ $param{'curr_authtype'} = $abv_auth{$long_auth};
+ if ($long_auth =~ /^krb(4|5)$/) {
+ $param{'curr_kerb_ver'} = $1;
+ }
+ }
# no longer static due to configurable kerberos defaults
# $loginscript = &Apache::loncommon::authform_header(%param);
- $generalrule = &Apache::loncommon::authform_authorwarning(%param);
$authformnop = &Apache::loncommon::authform_nochange(%param);
# no longer static due to configurable kerberos defaults
# $authformkrb = &Apache::loncommon::authform_kerberos(%param);
@@ -92,18 +102,14 @@ sub initialize_authen_forms {
$authformloc = &Apache::loncommon::authform_local(%param);
}
-
-# ======================================================= Existing Custom Roles
-
-sub my_custom_roles {
- my %returnhash=();
- my %rolehash=&Apache::lonnet::dump('roles');
- foreach my $key (keys %rolehash) {
- if ($key=~/^rolesdef\_(\w+)$/) {
- $returnhash{$1}=$1;
- }
- }
- return %returnhash;
+sub auth_abbrev {
+ my %abv_auth = (
+ krb4 => 'krb',
+ internal => 'int',
+ localuth => 'loc',
+ unix => 'fsys',
+ );
+ return %abv_auth;
}
# ==================================================== Figure out author access
@@ -175,8 +181,13 @@ END_SCRIPT
}
my $output = $quota_javascript.
'
'.$lt{'disk'}.'
'.
- $lt{'cuqu'}.': '.$currquota.' Mb. '.
- $defaultinfo.'
'.$lt{'chqu'}.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_row().
+ ''.$lt{'cuqu'}.': '.$currquota.' Mb. '.
+ $defaultinfo.' | '.
+ &Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::start_data_table_row().
+ ''.$lt{'chqu'}.
': | '.
+ &Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::end_data_table();
return $output;
}
@@ -212,21 +225,25 @@ sub print_username_entry_form {
'onload' => "javascript:setFormElements(document.$formtoset)",
);
my $start_page =
- &Apache::loncommon::start_page('Create Users, Change User Privileges',
+ &Apache::loncommon::start_page('User Management',
$jscript,{'add_entries' => \%loaditems,});
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"javascript:backPage(document.crtuser)",
- text=>"User modify/custom role",
- faq=>282,bug=>'Instructor Interface',});
-
+ if ($env{'form.action'} eq 'singleuser') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.crtuser)",
+ text=>"Single user search",
+ faq=>282,bug=>'Instructor Interface',});
+ } elsif ($env{'form.action'} eq 'custom') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.crtuser)",
+ text=>"Pick custom role",});
+ }
my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management');
- my %existingroles=&my_custom_roles();
+ my %existingroles=&Apache::lonuserutils::my_custom_roles();
my $choice=&Apache::loncommon::select_form('make new role','rolename',
('make new role' => 'Generate new role ...',%existingroles));
my %lt=&Apache::lonlocal::texthash(
'srch' => "User Search",
or => "or",
- 'siur' => "Set Individual User Roles",
'usr' => "Username",
'dom' => "Domain",
'ecrp' => "Edit Custom Role Privileges",
@@ -241,22 +258,24 @@ sub print_username_entry_form {
if ($sellink) {
$sellink = "$lt{'or'} ".$sellink;
}
- $r->print("
-$start_page
-$crumbs
-$lt{siur}$helpsiur
-$lt{'srch'} $sellink $lt{'mod'}
+ $r->print($start_page."\n".$crumbs);
+ if ($env{'form.action'} eq 'singleuser') {
+ $r->print("
+$lt{'srch'} $sellink $lt{'mod'}$helpsiur
$response");
- $r->print(&entry_form($defdom,$srch,$forcenewuser));
- if (&Apache::lonnet::allowed('mcr','/')) {
- $r->print(<print(&entry_form($defdom,$srch,$forcenewuser));
+ } elsif ($env{'form.action'} eq 'custom') {
+ if (&Apache::lonnet::allowed('mcr','/')) {
+ $r->print(<
+
-$lt{'ecrp'}$helpecpr
+$lt{'ecrp'}$helpecpr
$lt{'nr'}: $choice
ENDCUSTOM
+ }
}
$r->print(&Apache::loncommon::end_page());
}
@@ -264,13 +283,15 @@ ENDCUSTOM
sub entry_form {
my ($dom,$srch,$forcenewuser) = @_;
my $userpicker =
- &Apache::loncommon::user_picker($dom,$srch,$forcenewuser);
+ &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
+ 'document.crtuser');
my $srchbutton = &mt('Search');
my $output = <<"ENDDOCUMENT";
ENDDOCUMENT
return $output;
@@ -305,7 +326,7 @@ END
# =================================================================== Phase two
sub print_user_selection_page {
- my ($r,$response,$srch,$srch_results) = @_;
+ my ($r,$response,$srch,$srch_results,$operation,$srcharray) = @_;
my @fields = ('username','domain','lastname','firstname','permanentemail');
my $sortby = $env{'form.sortby'};
@@ -329,25 +350,34 @@ $jsback
ENDSCRIPT
my %lt=&Apache::lonlocal::texthash(
- 'srch' => "User Search to add/modify roles of",
+ 'usrch' => "User Search to add/modify roles",
+ 'stusrch' => "User Search to enroll student",
+ 'usel' => "Select a user to add/modify roles",
+ 'stusel' => "Select a user to enroll as a student",
'username' => "username",
'domain' => "domain",
'lastname' => "last name",
'firstname' => "first name",
'permanentemail' => "permanent e-mail",
);
- $r->print(&Apache::loncommon::start_page('Create Users, Change User Privileges',$jscript));
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"javascript:backPage(document.usersrchform,'','')",
- text=>"User modify/custom role edit",
- faq=>282,bug=>'Instructor Interface',},
- {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
- text=>"Select User",
- faq=>282,bug=>'Instructor Interface',});
- $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
- $r->print("$lt{'srch'}
");
- $r->print(&entry_form($srch->{'srchdomain'},$srch));
- $r->print(''.&mt('Select a user to add/modify roles of').'
');
+ if ($operation eq 'createuser') {
+ $r->print(&Apache::loncommon::start_page('User Management',$jscript));
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.usersrchform,'','')",
+ text=>"Create/modify user",
+ faq=>282,bug=>'Instructor Interface',},
+ {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
+ text=>"Select User",
+ faq=>282,bug=>'Instructor Interface',});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
+ $r->print("$lt{'usrch'}
");
+ $r->print(&entry_form($srch->{'srchdomain'},$srch));
+ $r->print(''.$lt{'usel'}.'
');
+ } else {
+ $r->print($jscript."$lt{'stusrch'}
");
+ $r->print(&Apache::londropadd::single_user_entry_form($srch->{'srchdomain'},$srch));
+ $r->print(''.$lt{'stusel'}.'
');
+ }
$r->print('');
+ ' '."\n");
$r->print($response);
- $r->print(&Apache::loncommon::end_page());
+ if ($operation eq 'createuser') {
+ $r->print(''.&Apache::loncommon::end_page());
+ } else {
+ $r->print(''."\n".
+ ''."\n");
+ }
}
sub print_user_query_page {
- my ($r) = @_;
+ my ($r,$caller) = @_;
# FIXME - this is for a network-wide name search (similar to catalog search)
# To use frames with similar behavior to catalog/portfolio search.
# To be implemented.
@@ -402,10 +441,50 @@ sub print_user_query_page {
sub print_user_modification_page {
my ($r,$ccuname,$ccdomain,$srch,$response) = @_;
- unless (($ccuname) && ($ccdomain)) {
- &print_username_entry_form($r);
+ if (($ccuname eq '') || ($ccdomain eq '')) {
+ my $usermsg = &mt('No username and/or domain provided.');
+ &print_username_entry_form($r,$usermsg);
return;
}
+ my %abv_auth = &auth_abbrev();
+ my ($curr_authtype,%rulematch,%inst_results,$curr_kerb_ver,$newuser,
+ %alerts,%curr_rules);
+ my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
+ if ($uhome eq 'no_host') {
+ $newuser = 1;
+ my $checkhash;
+ my $checks = { 'username' => 1 };
+ $checkhash->{$ccuname.':'.$ccdomain} = { 'status' => 'new' };
+ &Apache::loncommon::user_rule_check($checkhash,$checks,
+ \%alerts,\%rulematch,\%inst_results,\%curr_rules);
+ if (ref($alerts{$ccuname.':'.$ccdomain}) eq 'HASH') {
+ if ($alerts{$ccuname.':'.$ccdomain}{'username'}) {
+ my $domdesc =
+ &Apache::lonnet::domain($ccdomain,'description');
+ my $userchkmsg;
+ if (ref($curr_rules{$ccdomain}) eq 'HASH') {
+ $userchkmsg =
+ &Apache::loncommon::instrule_disallow_msg('username',
+ $domdesc,1).
+ &Apache::loncommon::user_rule_formats($ccdomain,
+ $domdesc,$curr_rules{$ccdomain}{'username'},
+ 'username');
+ }
+ &print_username_entry_form($r,$userchkmsg);
+ return;
+ }
+ }
+ } else {
+ $newuser = 0;
+ my $currentauth =
+ &Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
+ if ($currentauth =~ /^(krb4|krb5|unix|internal|localauth):/) {
+ $curr_authtype = $abv_auth{$1};
+ if ($currentauth =~ /^krb(4|5)/) {
+ $curr_kerb_ver = $1;
+ }
+ }
+ }
if ($response) {
$response = '
'.$response
}
@@ -416,7 +495,10 @@ sub print_user_modification_page {
my %param = ( formname => 'document.cu',
kerb_def_dom => $krbdefdom,
- kerb_def_auth => $krbdef
+ kerb_def_auth => $krbdef,
+ curr_authtype => $curr_authtype,
+ curr_kerb_ver => $curr_kerb_ver,
+ domain => $ccdomain,
);
$loginscript = &Apache::loncommon::authform_header(%param);
$authformkrb = &Apache::loncommon::authform_kerberos(%param);
@@ -624,16 +706,23 @@ ENDSECCODE
$nondc_setsection_code,$groupslist);
my ($jsback,$elements) = &crumb_utilities();
-
+ my $javascript_validations;
+ if ((&Apache::lonnet::allowed('mau',$ccdomain)) || ($uhome eq 'no_host')) {
+ my ($krbdef,$krbdefdom) =
+ &Apache::loncommon::get_kerberos_defaults($ccdomain);
+ $javascript_validations =
+ &Apache::lonuserutils::javascript_validations('auth',$krbdefdom,undef,
+ undef,$ccdomain);
+ }
$js .= "\n".
- '';
-
+ '';
my $start_page =
- &Apache::loncommon::start_page('Create Users, Change User Privileges',
+ &Apache::loncommon::start_page('User Management',
$js,{'add_entries' => \%loaditem,});
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"javascript:backPage(document.cu)",
- text=>"User modify/custom role edit",
+ text=>"Create/modify user",
faq=>282,bug=>'Instructor Interface',});
if ($env{'form.phase'} eq 'userpicked') {
@@ -650,14 +739,13 @@ ENDSECCODE
my $forminfo =<<"ENDFORMINFO";