--- loncom/interface/loncreateuser.pm 2007/03/12 17:06:59 1.148
+++ loncom/interface/loncreateuser.pm 2007/11/06 04:39:19 1.191
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.148 2007/03/12 17:06:59 albertel Exp $
+# $Id: loncreateuser.pm,v 1.191 2007/11/06 04:39:19 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -65,11 +65,10 @@ use Apache::lonnet;
use Apache::loncommon;
use Apache::lonlocal;
use Apache::longroup;
-use lib '/home/httpd/lib/perl/';
+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;
@@ -77,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);
@@ -93,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
@@ -122,68 +127,175 @@ 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",
);
- my $output = '
'.$lt{'disk'}.'
'.
+ my ($currquota,$quotatype,$inststatus,$defquota) =
+ &Apache::loncommon::get_user_quota($ccuname,$ccdomain);
+ my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
+ my ($longinsttype,$showquota,$custom_on,$custom_off,$defaultinfo);
+ if ($inststatus ne '') {
+ if ($usertypes->{$inststatus} ne '') {
+ $longinsttype = $usertypes->{$inststatus};
+ }
+ }
+ $custom_on = ' ';
+ $custom_off = ' checked="checked" ';
+ my $quota_javascript = <<"END_SCRIPT";
+
+END_SCRIPT
+ if ($quotatype eq 'custom') {
+ $custom_on = $custom_off;
+ $custom_off = ' ';
+ $showquota = $currquota;
+ if ($longinsttype eq '') {
+ $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);
+ }
+ } else {
+ if ($longinsttype eq '') {
+ $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);
+ }
+ }
+ 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';
+ $showquota.'" onfocus="javascript:quota_changes('."'quota'".')" '.
+ '/> Mb | '.
+ &Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::end_data_table();
return $output;
}
# =================================================================== Phase one
sub print_username_entry_form {
- my ($r) = @_;
+ my ($r,$response,$srch,$forcenewuser) = @_;
my $defdom=$env{'request.role.domain'};
- my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
- my $selscript=&Apache::loncommon::studentbrowser_javascript();
- my $start_page =
- &Apache::loncommon::start_page('Create Users, Change User Privileges',
- $selscript);
+ my $formtoset = 'crtuser';
+ if (exists($env{'form.startrolename'})) {
+ $formtoset = 'docustom';
+ $env{'form.rolename'} = $env{'form.startrolename'};
+ }
+
+ my ($jsback,$elements) = &crumb_utilities();
+
+ my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
+ ''."\n";
- my $sellink=&Apache::loncommon::selectstudent_link
- ('crtuser','ccuname','ccdomain');
- my %existingroles=&my_custom_roles();
+ my %loaditems = (
+ 'onload' => "javascript:setFormElements(document.$formtoset)",
+ );
+ my $start_page =
+ &Apache::loncommon::start_page('User Management',
+ $jscript,{'add_entries' => \%loaditems,});
+ 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=&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(
- 'siur' => "Set Individual User Roles",
+ 'srch' => "User Search",
+ or => "or",
'usr' => "Username",
'dom' => "Domain",
- 'usrr' => "User Roles",
'ecrp' => "Edit Custom Role Privileges",
'nr' => "Name of Role",
- 'cre' => "Custom Role Editor"
+ 'cre' => "Custom Role Editor",
+ 'mod' => "to 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');
my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');
- $r->print(<<"ENDDOCUMENT");
-$start_page
-
-ENDDOCUMENT
- if (&Apache::lonnet::allowed('mcr','/')) {
- $r->print(<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));
+ } 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 $userpicker =
+ &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
+ 'document.crtuser');
+ my $srchbutton = &mt('Search');
+ my $output = <<"ENDDOCUMENT";
+
+ENDDOCUMENT
+ return $output;
+}
sub user_modification_js {
my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
@@ -213,16 +325,161 @@ END
}
# =================================================================== Phase two
-sub print_user_modification_page {
- my $r=shift;
- my $ccuname =&LONCAPA::clean_username($env{'form.ccuname'});
- my $ccdomain=&LONCAPA::clean_domain($env{'form.ccdomain'});
+sub print_user_selection_page {
+ my ($r,$response,$srch,$srch_results,$operation,$srcharray) = @_;
+ my @fields = ('username','domain','lastname','firstname','permanentemail');
+ my $sortby = $env{'form.sortby'};
+
+ if (!grep(/^\Q$sortby\E$/,@fields)) {
+ $sortby = 'lastname';
+ }
+
+ my ($jsback,$elements) = &crumb_utilities();
+
+ my $jscript = (<
+function pickuser(uname,udom) {
+ document.usersrchform.seluname.value=uname;
+ document.usersrchform.seludom.value=udom;
+ document.usersrchform.phase.value="userpicked";
+ document.usersrchform.submit();
+}
- unless (($ccuname) && ($ccdomain)) {
- &print_username_entry_form($r);
- return;
+$jsback
+
+ENDSCRIPT
+
+ my %lt=&Apache::lonlocal::texthash(
+ '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",
+ );
+ 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(''.&Apache::loncommon::end_page());
+ } else {
+ $r->print(''."\n".
+ ''."\n");
}
+}
+sub print_user_query_page {
+ 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.
+ return;
+}
+
+sub print_user_modification_page {
+ my ($r,$ccuname,$ccdomain,$srch,$response) = @_;
+ 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,$instsrch,$rulematch,$rules,%inst_results,
+ $curr_kerb_ver,$newuser);
+ 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;
+ }
+ } 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) =
@@ -230,13 +487,14 @@ 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);
-
- $ccuname =&LONCAPA::clean_username($ccuname);
- $ccdomain=&LONCAPA::clean_domain($ccdomain);
+
my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
my $dc_setcourse_code = '';
my $nondc_setsection_code = '';
@@ -368,9 +626,8 @@ ENDSCRIPT
var checkcurr = str.match(re1);
if (checkcurr != null) {
if (document.cu.elements[i-1].checked == true) {
- var re2 = /^currsec_[a-zA-Z0-9]+_[a-zA-Z0-9]+_(\\w+)\$/;
- match = re2.exec(str);
- var role = match[1];
+ var match = str.split('_');
+ var role = match[3];
if (role == 'cc') {
alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
}
@@ -439,20 +696,48 @@ ENDSECCODE
}
my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
$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=>"Create/modify user",
+ faq=>282,bug=>'Instructor Interface',});
+
+ if ($env{'form.phase'} eq 'userpicked') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.cu,'get_user_info','select')",
+ text=>"Select a user",
+ faq=>282,bug=>'Instructor Interface',});
+ }
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.cu,'$env{'form.phase'}','modify')",
+ text=>"Set user role",
+ faq=>282,bug=>'Instructor Interface',});
+ my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management');
my $forminfo =<<"ENDFORMINFO";