--- loncom/interface/loncreateuser.pm 2003/07/25 01:18:04 1.66
+++ loncom/interface/loncreateuser.pm 2008/07/13 09:53:16 1.254
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.66 2003/07/25 01:18:04 bowersj2 Exp $
+# $Id: loncreateuser.pm,v 1.254 2008/07/13 09:53:16 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -63,133 +63,323 @@ use strict;
use Apache::Constants qw(:common :http);
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;
my $authformfsys;
my $authformloc;
-BEGIN {
- $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
- my $krbdefdom=$1;
- $krbdefdom=~tr/a-z/A-Z/;
- my %param = ( formname => 'document.cu',
- kerb_def_dom => $krbdefdom
- );
-# no longer static due to configurable kerberos defaults
-# $loginscript = &Apache::loncommon::authform_header(%param);
- $generalrule = &Apache::loncommon::authform_authorwarning(%param);
+sub initialize_authen_forms {
+ 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):(.*)$/) {
+ 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;
+ }
+ }
+ $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);
}
+sub auth_abbrev {
+ my %abv_auth = (
+ krb4 => 'krb',
+ internal => 'int',
+ localuth => 'loc',
+ unix => 'fsys',
+ );
+ return %abv_auth;
+}
-# ======================================================= Existing Custom Roles
+# ====================================================
-sub my_custom_roles {
- my %returnhash=();
- my %rolehash=&Apache::lonnet::dump('roles');
- foreach (keys %rolehash) {
- if ($_=~/^rolesdef\_(\w+)$/) {
- $returnhash{$1}=$1;
- }
+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 ($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 | '.
+ &Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::end_data_table();
+ return $output;
}
# =================================================================== Phase one
sub print_username_entry_form {
- my $r=shift;
- my $defdom=$ENV{'request.role.domain'};
- my @domains = &Apache::loncommon::get_domains();
- my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
- my $bodytag =&Apache::loncommon::bodytag(
- 'Create Users, Change User Privileges');
- my $selscript=&Apache::loncommon::studentbrowser_javascript();
- my $sellink=&Apache::loncommon::selectstudent_link
- ('crtuser','ccuname','ccdomain');
- my %existingroles=&my_custom_roles();
+ 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();
+
+ my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
+ ''."\n";
+
+ 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,});
+ if ($env{'form.action'} eq 'custom') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.crtuser)",
+ text=>"Pick custom role",});
+ } else {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.crtuser)",
+ text=>$breadcrumb_text{'search'},
+ faq=>282,bug=>'Instructor Interface',});
+ }
+ 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));
- $r->print(<<"ENDDOCUMENT");
-
-
-The LearningOnline Network with CAPA
-$selscript
-
-$bodytag
+ my %lt=&Apache::lonlocal::texthash(
+ '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",
+ );
+ $r->print($start_page."\n".$crumbs);
+ if ($env{'form.action'} eq 'custom') {
+ if (&Apache::lonnet::allowed('mcr','/')) {
+ $r->print(<
+
+
+$lt{'ecrp'}
+$lt{'nr'}: $choice
+
+
+ENDCUSTOM
+ }
+ } else {
+ my $actiontext = $lt{'srad'};
+ if ($env{'form.action'} eq 'singlestudent') {
+ $actiontext = $lt{'srst'};
+ }
+ $r->print("
+$actiontext
");
+ if ($env{'form.origform'} ne 'crtusername') {
+ $r->print("\n".$response);
+ }
+ $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response));
+ }
+ $r->print(&Apache::loncommon::end_page());
+}
+
+sub entry_form {
+ my ($dom,$srch,$forcenewuser,$context,$responsemsg) = @_;
+ my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
+ my ($usertype,$inexact);
+ if (ref($srch) eq 'HASH') {
+ if (($srch->{'srchin'} eq 'dom') &&
+ ($srch->{'srchby'} eq 'uname') &&
+ ($srch->{'srchtype'} eq 'exact') &&
+ ($srch->{'srchdomain'} ne '') &&
+ ($srch->{'srchterm'} ne '')) {
+ 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 =
+ &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
+ my $userpicker =
+ &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 ($env{'form.phase'} eq '') {
+ my $defdom=$env{'request.role.domain'};
+ my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
+ 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',
+ '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";
+
+
-