--- loncom/interface/loncreateuser.pm 2007/12/21 17:27:57 1.219
+++ loncom/interface/loncreateuser.pm 2009/02/18 19:34:08 1.282
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.219 2007/12/21 17:27:57 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.282 2009/02/18 19:34:08 schafran Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -33,11 +33,13 @@ package Apache::loncreateuser;
=head1 NAME
-Apache::loncreateuser - handler to create users and custom roles
+Apache::loncreateuser.pm
=head1 SYNOPSIS
-Apache::loncreateuser provides an Apache handler for creating users,
+ Handler to create users and custom roles
+
+ Provides an Apache handler for creating users,
editing their login parameters, roles, and removing roles, and
also creating and assigning custom roles.
@@ -66,6 +68,7 @@ use Apache::loncommon;
use Apache::lonlocal;
use Apache::longroup;
use Apache::lonuserutils;
+use Apache::selfenroll();
use LONCAPA qw(:DEFAULT :match);
my $loginscript; # piece of javascript used in two separate instances
@@ -76,30 +79,30 @@ my $authformfsys;
my $authformloc;
sub initialize_authen_forms {
- my ($dom,$curr_authtype,$mode) = @_;
- my ($krbdefdom)=( $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/);
- $krbdefdom= uc($krbdefdom);
- my %param = ( formname => 'document.cu',
+ my ($dom,$formname,$curr_authtype,$mode) = @_;
+ my ($krbdef,$krbdefdom) = &Apache::loncommon::get_kerberos_defaults($dom);
+ my %param = ( formname => $formname,
kerb_def_dom => $krbdefdom,
+ kerb_def_auth => $krbdef,
domain => $dom,
);
my %abv_auth = &auth_abbrev();
- if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):$/) {
+ if ($curr_authtype =~ /^(krb4|krb5|internal|localauth|unix):(.*)$/) {
my $long_auth = $1;
+ my $curr_autharg = $2;
my %abv_auth = &auth_abbrev();
$param{'curr_authtype'} = $abv_auth{$long_auth};
if ($long_auth =~ /^krb(4|5)$/) {
$param{'curr_kerb_ver'} = $1;
+ $param{'curr_autharg'} = $curr_autharg;
}
if ($mode eq 'modifyuser') {
$param{'mode'} = $mode;
}
}
-# no longer static due to configurable kerberos defaults
-# $loginscript = &Apache::loncommon::authform_header(%param);
+ $loginscript = &Apache::loncommon::authform_header(%param);
+ $authformkrb = &Apache::loncommon::authform_kerberos(%param);
$authformnop = &Apache::loncommon::authform_nochange(%param);
-# no longer static due to configurable kerberos defaults
-# $authformkrb = &Apache::loncommon::authform_kerberos(%param);
$authformint = &Apache::loncommon::authform_internal(%param);
$authformfsys = &Apache::loncommon::authform_filesystem(%param);
$authformloc = &Apache::loncommon::authform_local(%param);
@@ -120,11 +123,12 @@ sub auth_abbrev {
sub portfolio_quota {
my ($ccuname,$ccdomain) = @_;
my %lt = &Apache::lonlocal::texthash(
- 'disk' => "Disk space allocated to user's portfolio files",
- 'cuqu' => "Current quota",
- 'cust' => "Custom quota",
- 'defa' => "Default",
- 'chqu' => "Change quota",
+ 'usrt' => "User Tools",
+ 'disk' => "Disk space allocated to user's portfolio files",
+ 'cuqu' => "Current quota",
+ 'cust' => "Custom quota",
+ 'defa' => "Default",
+ 'chqu' => "Change quota",
);
my ($currquota,$quotatype,$inststatus,$defquota) =
&Apache::loncommon::get_user_quota($ccuname,$ccdomain);
@@ -156,44 +160,125 @@ END_SCRIPT
$custom_off = ' ';
$showquota = $currquota;
if ($longinsttype eq '') {
- $defaultinfo = &mt('For this user, the default quota would be [_1]
- Mb.',$defquota);
+ $defaultinfo = &mt('For this user, the default quota would be [_1]'
+ .' Mb.',$defquota);
} else {
- $defaultinfo = &mt("For this user, the default quota would be [_1]
- Mb, as determined by the user's institutional
- affiliation ([_2]).",$defquota,$longinsttype);
+ $defaultinfo = &mt("For this user, the default quota would be [_1]".
+ " Mb, as determined by the user's institutional".
+ " affiliation ([_2]).",$defquota,$longinsttype);
}
} else {
if ($longinsttype eq '') {
- $defaultinfo = &mt('For this user, the default quota is [_1]
- Mb.',$defquota);
+ $defaultinfo = &mt('For this user, the default quota is [_1]'
+ .' Mb.',$defquota);
} else {
- $defaultinfo = &mt("For this user, the default quota of [_1]
- Mb, is determined by the user's institutional
- affiliation ([_2]).",$defquota,$longinsttype);
+ $defaultinfo = &mt("For this user, the default quota of [_1]".
+ " Mb, is determined by the user's institutional".
+ " affiliation ([_2]).",$defquota,$longinsttype);
}
}
- my $output = $quota_javascript.
- '
'.$lt{'disk'}.'
'.
- &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'}.
- ': '.
- ' '.
- ' Mb | '.
- &Apache::loncommon::end_data_table_row().
- &Apache::loncommon::end_data_table();
+
+ my $output = $quota_javascript."\n".
+ ''.$lt{'usrt'}.'
'."\n".
+ &Apache::loncommon::start_data_table();
+
+ if (&Apache::lonnet::allowed('mut',$ccdomain)) {
+ $output .= &build_tools_display($ccuname,$ccdomain,'tools');
+ }
+ if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
+ $output .= ''."\n".
+ ' '.$lt{'disk'}.' | '."\n".
+ '
'."\n".
+ &Apache::loncommon::start_data_table_row()."\n".
+ ' '.$lt{'cuqu'}.': '.
+ $currquota.' Mb. '.
+ $defaultinfo.' | '."\n".
+ &Apache::loncommon::end_data_table_row()."\n".
+ &Apache::loncommon::start_data_table_row()."\n".
+ ' '.$lt{'chqu'}.
+ ': '.
+ ' '.
+ ' Mb | '."\n".
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ $output .= &Apache::loncommon::end_data_table();
+ return $output;
+}
+
+sub build_tools_display {
+ my ($ccuname,$ccdomain,$context) = @_;
+ my (@usertools,%userenv,$output);
+ my %lt = &Apache::lonlocal::texthash (
+ 'blog' => "Personal User Blog",
+ 'aboutme' => "Personal Information Page",
+ 'portfolio' => "Personal User Portfolio",
+ 'avai' => "Available",
+ 'cusa' => "availability",
+ 'chse' => "Change setting",
+ 'usde' => "Use default",
+ 'uscu' => "Use custom",
+ 'official' => 'Can request creation of official courses',
+ 'unofficial' => 'Can request creation of unofficial courses',
+ );
+ if ($context eq 'requestcourses') {
+ %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
+ 'requestcourses.official','requestcourses.unofficial');
+ @usertools = ('official','unofficial');
+ } else {
+ %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
+ 'tools.aboutme','tools.portfolio','tools.blog');
+ @usertools = ('aboutme','blog','portfolio');
+ }
+ foreach my $item (@usertools) {
+ my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off);
+ $cust_off = 'checked="checked" ';
+ $tool_on = 'checked="checked" ';
+ $curr_access =
+ &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
+ $context);
+ if ($userenv{$context.'.'.$item} eq '') {
+ $custom_access = 'default';
+ if (!$curr_access) {
+ $tool_off = 'checked="checked" ';
+ $tool_on = '';
+ }
+ } else {
+ $custom_access = 'custom';
+ $cust_on = ' checked="checked" ';
+ $cust_off = '';
+ if ($userenv{$context.'.'.$item} == 0) {
+ $tool_off = 'checked="checked" ';
+ $tool_on = '';
+ }
+ }
+ $output .= ' '."\n".
+ ' '.$lt{$item}.' | '."\n".
+ '
'."\n".
+ &Apache::loncommon::start_data_table_row()."\n".
+ ' '.&mt('Availability determined currently from [_1] setting.',$custom_access).
+ ' '.$lt{'avai'}.': '.
+ ($curr_access?&mt('Yes'):&mt('No')).' | '."\n".
+ &Apache::loncommon::end_data_table_row()."\n".
+ &Apache::loncommon::start_data_table_row()."\n".
+ ' '.$lt{'chse'}.': '.
+ ' -- '.
+ $lt{'cusa'}.': | '."\n".
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
return $output;
}
@@ -220,6 +305,7 @@ sub print_username_entry_form {
my %loaditems = (
'onload' => "javascript:setFormElements(document.$formtoset)",
);
+ my %breadcrumb_text = &singleuser_breadcrumb();
my $start_page =
&Apache::loncommon::start_page('User Management',
$jscript,{'add_entries' => \%loaditems,});
@@ -230,32 +316,29 @@ sub print_username_entry_form {
} else {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"javascript:backPage(document.crtuser)",
- text=>"Single user search",
+ text=>$breadcrumb_text{'search'},
faq=>282,bug=>'Instructor Interface',});
}
- my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management');
+ my $helpitem = 'Course_Change_Privileges';
+ if ($env{'form.action'} eq 'custom') {
+ $helpitem = 'Course_Editing_Custom_Roles';
+ } elsif ($env{'form.action'} eq 'singlestudent') {
+ $helpitem = 'Course_Add_Student';
+ }
+ my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
+ $helpitem);
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",
+ 'srst' => 'Search for a user and enroll as a student',
+ 'srad' => 'Search for a user and modify/add user information or roles',
'usr' => "Username",
'dom' => "Domain",
'ecrp' => "Edit Custom Role Privileges",
'nr' => "Name of Role",
- 'cre' => "Custom Role Editor",
- 'mod' => "to modify user information or add/modify roles",
- 'enrl' => "to enroll one student",
+ 'cre' => "Next",
);
- my $help = &Apache::loncommon::help_open_menu(undef,undef,282,'Instructor Interface');
- my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
- my $helpsist=&Apache::loncommon::help_open_topic('Course_Add_Student');
- my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');
- my $sellink=&Apache::loncommon::selectstudent_link('crtuser','srchterm','srchdomain');
- if ($sellink) {
- $sellink = "$lt{'or'} ".$sellink;
- }
$r->print($start_page."\n".$crumbs);
if ($env{'form.action'} eq 'custom') {
if (&Apache::lonnet::allowed('mcr','/')) {
@@ -263,19 +346,19 @@ sub print_username_entry_form {
ENDCUSTOM
}
} else {
- my $actiontext = $lt{'mod'}.$helpsiur;
+ my $actiontext = $lt{'srad'};
if ($env{'form.action'} eq 'singlestudent') {
- $actiontext = $lt{'enrl'}.$helpsist;
+ $actiontext = $lt{'srst'};
}
$r->print("
-$lt{'srch'} $sellink $actiontext
");
+$actiontext
");
if ($env{'form.origform'} ne 'crtusername') {
$r->print("\n".$response);
}
@@ -287,7 +370,7 @@ ENDCUSTOM
sub entry_form {
my ($dom,$srch,$forcenewuser,$context,$responsemsg) = @_;
my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
- my $usertype;
+ my ($usertype,$inexact);
if (ref($srch) eq 'HASH') {
if (($srch->{'srchin'} eq 'dom') &&
($srch->{'srchby'} eq 'uname') &&
@@ -297,6 +380,8 @@ sub entry_form {
my ($rules,$ruleorder) =
&Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
$usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules);
+ } else {
+ $inexact = 1;
}
}
my $cancreate =
@@ -305,6 +390,11 @@ sub entry_form {
&Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
'document.crtuser',$cancreate,$usertype);
my $srchbutton = &mt('Search');
+ if ($env{'form.action'} eq 'singlestudent') {
+ $srchbutton = &mt('Search and Enroll');
+ } elsif ($cancreate && $responsemsg ne '' && $inexact) {
+ $srchbutton = &mt('Search or Add New User');
+ }
my $output = <<"ENDBLOCK";
ENDBLOCK
- if ($cancreate && $env{'form.phase'} eq '') {
+ if ($env{'form.phase'} eq '') {
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(
+ 'enro' => 'Enroll one student',
+ 'admo' => 'Add/modify a single user',
+ 'crea' => 'create new user if required',
+ 'uskn' => "username is known",
'crnu' => 'Create a new user',
'usr' => 'Username',
'dom' => 'in domain',
- 'cra' => 'Create user',
+ 'enrl' => 'Enroll',
+ 'cram' => 'Create/Modify user',
);
+ my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
+ my ($title,$buttontext,$showresponse);
+ if ($env{'form.action'} eq 'singlestudent') {
+ $title = $lt{'enro'};
+ $buttontext = $lt{'enrl'};
+ } else {
+ $title = $lt{'admo'};
+ $buttontext = $lt{'cram'};
+ }
+ if ($cancreate) {
+ $title .= ' ('.$lt{'crea'}.')';
+ } else {
+ $title .= ' ('.$lt{'uskn'}.')';
+ }
+ if ($env{'form.origform'} eq 'crtusername') {
+ $showresponse = $responsemsg;
+ }
$output .= <<"ENDDOCUMENT";
+
@@ -377,7 +490,7 @@ END
# =================================================================== Phase two
sub print_user_selection_page {
- my ($r,$response,$srch,$srch_results,$operation,$srcharray,$context) = @_;
+ my ($r,$response,$srch,$srch_results,$srcharray,$context) = @_;
my @fields = ('username','domain','lastname','firstname','permanentemail');
my $sortby = $env{'form.sortby'};
@@ -412,27 +525,24 @@ ENDSCRIPT
'permanentemail' => "permanent e-mail",
);
$r->print(&Apache::loncommon::start_page('User Management',$jscript));
- if ($operation eq 'createuser') {
- &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'));
+
+ my %breadcrumb_text = &singleuser_breadcrumb();
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.usersrchform,'','')",
+ text=>$breadcrumb_text{'search'},
+ faq=>282,bug=>'Instructor Interface',},
+ {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
+ text=>$breadcrumb_text{'userpicked'},
+ faq=>282,bug=>'Instructor Interface',});
+ if ($env{'form.action'} eq 'singleuser') {
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
+ 'Course_Change_Privileges'));
$r->print("$lt{'usrch'}
");
$r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
$r->print(''.$lt{'usel'}.'
');
- } elsif ($operation eq 'enrollstudent') {
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"javascript:backPage(document.usersrchform,'','')",
- text=>"Create/modify student",
- faq=>282,bug=>'Instructor Interface',},
- {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
- text=>"Select Student",
- faq=>282,bug=>'Instructor Interface',});
- $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
+ } elsif ($env{'form.action'} eq 'singlestudent') {
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management',
+ 'Course_Add_Student'));
$r->print($jscript."$lt{'stusrch'}
");
$r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
$r->print(''.$lt{'stusel'}.'
');
@@ -509,8 +619,7 @@ sub print_user_modification_page {
$formname = 'cu';
}
my %abv_auth = &auth_abbrev();
- my ($curr_authtype,%rulematch,%inst_results,$curr_kerb_ver,$newuser,
- %alerts,%curr_rules,%got_rules);
+ my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
if ($uhome eq 'no_host') {
my $usertype;
@@ -565,32 +674,10 @@ sub print_user_modification_page {
}
} 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;
}
- my $defdom=$env{'request.role.domain'};
-
- my ($krbdef,$krbdefdom) =
- &Apache::loncommon::get_kerberos_defaults($defdom);
-
- my %param = ( formname => 'document.cu',
- kerb_def_dom => $krbdefdom,
- 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);
my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
my $dc_setcourse_code = '';
@@ -601,9 +688,12 @@ sub print_user_modification_page {
my $js = &validation_javascript($context,$ccdomain,$pjump_def,
$groupslist,$newuser,$formname,\%loaditem);
+ my $args = {'add_entries' => \%loaditem};
+ if ($env{'form.popup'}) {
+ $args->{'no_nav_bar'} = 1;
+ }
my $start_page =
- &Apache::loncommon::start_page('User Management',
- $js,{'add_entries' => \%loaditem,});
+ &Apache::loncommon::start_page('User Management',$js,$args);
my %breadcrumb_text = &singleuser_breadcrumb();
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"javascript:backPage($form)",
@@ -620,7 +710,12 @@ sub print_user_modification_page {
({href=>"javascript:backPage($form,'$env{'form.phase'}','modify')",
text=>$breadcrumb_text{'modify'},
faq=>282,bug=>'Instructor Interface',});
- my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management');
+ my $helpitem = 'Course_Change_Privileges';
+ if ($env{'form.action'} eq 'singlestudent') {
+ $helpitem = 'Course_Add_Student';
+ }
+ my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management',
+ $helpitem);
my $forminfo =<<"ENDFORMINFO";