--- loncom/interface/loncreateuser.pm 2007/10/11 02:16:25 1.189
+++ loncom/interface/loncreateuser.pm 2007/12/13 01:08:47 1.208
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.189 2007/10/11 02:16:25 albertel Exp $
+# $Id: loncreateuser.pm,v 1.208 2007/12/13 01:08:47 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -65,6 +65,7 @@ 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
@@ -75,7 +76,7 @@ my $authformfsys;
my $authformloc;
sub initialize_authen_forms {
- my ($dom,$curr_authtype) = @_;
+ my ($dom,$curr_authtype,$mode) = @_;
my ($krbdefdom)=( $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/);
$krbdefdom= uc($krbdefdom);
my %param = ( formname => 'document.cu',
@@ -90,6 +91,9 @@ sub initialize_authen_forms {
if ($long_auth =~ /^krb(4|5)$/) {
$param{'curr_kerb_ver'} = $1;
}
+ if ($mode eq 'modifyuser') {
+ $param{'mode'} = $mode;
+ }
}
# no longer static due to configurable kerberos defaults
# $loginscript = &Apache::loncommon::authform_header(%param);
@@ -111,19 +115,6 @@ sub auth_abbrev {
return %abv_auth;
}
-# ======================================================= 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;
-}
-
# ==================================================== Figure out author access
sub authorpriv {
@@ -218,12 +209,14 @@ END_SCRIPT
# =================================================================== Phase one
sub print_username_entry_form {
- my ($r,$response,$srch,$forcenewuser) = @_;
+ my ($r,$context,$response,$srch,$forcenewuser) = @_;
my $defdom=$env{'request.role.domain'};
my $formtoset = 'crtuser';
if (exists($env{'form.startrolename'})) {
$formtoset = 'docustom';
$env{'form.rolename'} = $env{'form.startrolename'};
+ } elsif ($env{'form.origform'} eq 'crtusername') {
+ $formtoset = $env{'form.origform'};
}
my ($jsback,$elements) = &crumb_utilities();
@@ -237,27 +230,31 @@ 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 edit",
- 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",
'nr' => "Name of Role",
'cre' => "Custom Role Editor",
- 'mod' => "to add/modify roles",
+ 'mod' => "to edit user information or add/modify roles",
);
my $help = &Apache::loncommon::help_open_menu(undef,undef,282,'Instructor Interface');
my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
@@ -266,39 +263,78 @@ 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,$context));
+ } 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());
}
sub entry_form {
- my ($dom,$srch,$forcenewuser) = @_;
+ my ($dom,$srch,$forcenewuser,$context) = @_;
+ my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
+ my $cancreate = &Apache::lonuserutils::can_create_user($dom,$context);
+ if (!$cancreate) {
+ $forcenewuser = '';
+ }
my $userpicker =
&Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
'document.crtuser');
my $srchbutton = &mt('Search');
- my $output = <<"ENDDOCUMENT";
+ my $output = <<"ENDBLOCK";
+ENDBLOCK
+ if ($cancreate) {
+ my $defdom=$env{'request.role.domain'};
+ my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
+ my $helpcrt=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
+ my %lt=&Apache::lonlocal::texthash(
+ 'crnu' => 'Create a new user',
+ 'usr' => 'Username',
+ 'dom' => 'in domain',
+ 'cra' => 'Create user',
+ );
+ $output .= <<"ENDDOCUMENT";
+
ENDDOCUMENT
+ }
return $output;
}
@@ -331,7 +367,7 @@ END
# =================================================================== Phase two
sub print_user_selection_page {
- my ($r,$response,$srch,$srch_results,$context,$srcharray) = @_;
+ my ($r,$response,$srch,$srch_results,$operation,$srcharray,$context) = @_;
my @fields = ('username','domain','lastname','firstname','permanentemail');
my $sortby = $env{'form.sortby'};
@@ -365,18 +401,18 @@ ENDSCRIPT
'firstname' => "first name",
'permanentemail' => "permanent e-mail",
);
- if ($context eq 'createuser') {
- $r->print(&Apache::loncommon::start_page('Create Users, Change User Privileges',$jscript));
+ if ($operation eq 'createuser') {
+ $r->print(&Apache::loncommon::start_page('User Management',$jscript));
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"javascript:backPage(document.usersrchform,'','')",
- text=>"User modify/custom role edit",
+ 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(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
$r->print(''.$lt{'usel'}.'
');
} else {
$r->print($jscript."$lt{'stusrch'}
");
@@ -425,9 +461,10 @@ ENDSCRIPT
' '."\n".
' '."\n".
' '."\n".
- ' '."\n");
+ ' '."\n".
+ ' '."\n");
$r->print($response);
- if ($context eq 'createuser') {
+ if ($operation eq 'createuser') {
$r->print(''.&Apache::loncommon::end_page());
} else {
$r->print(''."\n".
@@ -444,31 +481,41 @@ sub print_user_query_page {
}
sub print_user_modification_page {
- my ($r,$ccuname,$ccdomain,$srch,$response) = @_;
+ my ($r,$ccuname,$ccdomain,$srch,$response,$context) = @_;
if (($ccuname eq '') || ($ccdomain eq '')) {
my $usermsg = &mt('No username and/or domain provided.');
- &print_username_entry_form($r,$usermsg);
+ &print_username_entry_form($r,$context,$usermsg);
return;
}
my %abv_auth = &auth_abbrev();
- my ($curr_authtype,$instsrch,$rulematch,$rules,%inst_results,
- $curr_kerb_ver,$newuser);
+ my ($curr_authtype,%rulematch,%inst_results,$curr_kerb_ver,$newuser,
+ %alerts,%curr_rules,%got_rules);
my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
if ($uhome eq 'no_host') {
$newuser = 1;
- $instsrch =
- {
- srchin => 'instd',
- srchby => 'uname',
- srchtype => 'exact',
- srchterm => $ccuname,
- srchdomain => $ccdomain,
- };
- (my $usercheckmsg,$rulematch,$rules,%inst_results) =
- &Apache::loncommon::username_rule_check($instsrch,'new');
- if ($usercheckmsg) {
- &print_username_entry_form($r,$usercheckmsg);
- return;
+ my $checkhash;
+ my $checks = { 'username' => 1 };
+ $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
+ &Apache::loncommon::user_rule_check($checkhash,$checks,
+ \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
+ if (ref($alerts{'username'}) eq 'HASH') {
+ if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
+ my $domdesc =
+ &Apache::lonnet::domain($ccdomain,'description');
+ if ($alerts{'username'}{$ccdomain}{$ccuname}) {
+ 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,$context,$userchkmsg);
+ return;
+ }
+ }
}
} else {
$newuser = 0;
@@ -621,82 +668,8 @@ sub print_user_modification_page {
}
ENDSCRIPT
} else {
- $nondc_setsection_code = <<"ENDSECCODE";
- function setSections() {
- var re1 = /^currsec_/;
- var groups = new Array($groupslist);
- for (var i=0;i 0) {
- if (document.cu.elements[i+1].value != "" && document.cu.elements[i+1].value != null) {
- sections = sections + "," + document.cu.elements[i+1].value;
- }
- }
- else {
- sections = document.cu.elements[i+1].value;
- }
- var newsecs = document.cu.elements[i+1].value;
- var numsplit;
- if (newsecs != null && newsecs != "") {
- numsplit = newsecs.split(/,/g);
- numsec = numsec + numsplit.length;
- }
-
- if ((role == 'st') && (numsec > 1)) {
- alert("In each course, each user may only have one student role at a time. You had selected "+numsec+" sections.\\nPlease modify your selections so they include no more than one section.")
- return;
- }
- else if (numsplit != null) {
- for (var j=0; j'."\n".$jsback."\n".
$javascript_validations.'';
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') {
@@ -735,7 +708,7 @@ ENDSECCODE
my $forminfo =<<"ENDFORMINFO";