'.
+ &personal_data_display($ccuname,$ccdomain,$newuser,
+ %inst_results).
+ '
');
+ my $user_auth_text =
+ &user_authentication($ccuname,$ccdomain,$krbdefdom,\%abv_auth);
+ my $user_quota_text;
+ if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
+ # Current user has quota modification privileges
+ $user_quota_text = &portfolio_quota($ccuname,$ccdomain);
+ } elsif (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
+ # Get the user's portfolio information
+ my %portq = &Apache::lonnet::get('environment',['portfolioquota'],
+ $ccdomain,$ccuname);
+
+ my %lt=&Apache::lonlocal::texthash(
+ 'dska' => "Disk space allocated to user's portfolio files",
+ 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
+ 'ichr' => "If a change is required, contact a domain coordinator for the domain",
+ );
+ $user_quota_text = <$lt{'dska'}
+$lt{'youd'} $lt{'ichr'}: $ccdomain
+ENDNOPORTPRIV
+ }
+ if ($user_auth_text ne '') {
+ $r->print(''.$user_auth_text);
+ if ($user_quota_text ne '') {
+ $r->print($user_quota_text);
+ }
+ $r->print('
');
+
+ } elsif ($user_quota_text ne '') {
+ $r->print(''.$user_quota_text.'
');
}
- $r->print(&Apache::loncommon::end_data_table_row().
- &Apache::loncommon::end_data_table());
+ $r->print('');
+ my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
# Build up table of user roles to allow revocation of a role.
my ($tmp) = keys(%rolesdump);
unless ($tmp =~ /^(con_lost|error)/i) {
@@ -932,7 +1022,7 @@ END
$plaintext=&Apache::lonnet::plaintext($role_code,$class)
} else {
$plaintext=
- "Customrole '$croletitle' defined by $croleuname\@$croleudom";
+ "Customrole '$croletitle'
defined by $croleuname\@$croleudom";
}
$row.= ''.$plaintext.
' | '.$area.
@@ -968,7 +1058,6 @@ END
}
if ($rolesdisplay == 1) {
$r->print('
-
'.$lt{'rer'}.''.
&Apache::loncommon::start_data_table("LC_createuser").
&Apache::loncommon::start_data_table_header_row().
@@ -984,128 +1073,16 @@ END
$r->print(&Apache::loncommon::end_data_table());
}
} # End of unless
- my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
- if ($currentauth=~/^krb(4|5):/) {
- $currentauth=~/^krb(4|5):(.*)/;
- my $krbdefdom=$2;
- my %param = ( formname => 'document.cu',
- kerb_def_dom => $krbdefdom
- );
- $loginscript = &Apache::loncommon::authform_header(%param);
- }
- # Check for a bad authentication type
- unless ($currentauth=~/^krb(4|5):/ or
- $currentauth=~/^unix:/ or
- $currentauth=~/^internal:/ or
- $currentauth=~/^localauth:/
- ) { # bad authentication scheme
- if (&Apache::lonnet::allowed('mau',$ccdomain)) {
- &initialize_authen_forms();
- my %lt=&Apache::lonlocal::texthash(
- 'err' => "ERROR",
- 'uuas' => "This user has an unrecognized authentication scheme",
- 'sldb' => "Please specify login data below",
- 'ld' => "Login Data"
- );
- $r->print(<
-
-$lt{'err'}:
-$lt{'uuas'} ($currentauth). $lt{'sldb'}.
-$lt{'ld'}
-$generalrule
-$authformkrb
-$authformint
-$authformfsys
-$authformloc
-ENDBADAUTH
- } else {
- # This user is not allowed to modify the user's
- # authentication scheme, so just notify them of the problem
- my %lt=&Apache::lonlocal::texthash(
- 'err' => "ERROR",
- 'uuas' => "This user has an unrecognized authentication scheme",
- 'adcs' => "Please alert a domain coordinator of this situation"
- );
- $r->print(<
- $lt{'err'}:
-$lt{'uuas'} ($currentauth). $lt{'adcs'}.
-
-ENDBADAUTH
- }
- } else { # Authentication type is valid
- my $authformcurrent='';
- my $authform_other='';
- &initialize_authen_forms();
- if ($currentauth=~/^krb(4|5):/) {
- $authformcurrent=$authformkrb;
- $authform_other="$authformint \n".
- "$authformfsys $authformloc ";
- }
- elsif ($currentauth=~/^internal:/) {
- $authformcurrent=$authformint;
- $authform_other="$authformkrb ".
- "$authformfsys $authformloc ";
- }
- elsif ($currentauth=~/^unix:/) {
- $authformcurrent=$authformfsys;
- $authform_other="$authformkrb ".
- "$authformint $authformloc; ";
- }
- elsif ($currentauth=~/^localauth:/) {
- $authformcurrent=$authformloc;
- $authform_other="$authformkrb ".
- "$authformint $authformfsys ";
- }
- $authformcurrent.=' (will override current values) ';
- if (&Apache::lonnet::allowed('mau',$ccdomain)) {
- # Current user has login modification privileges
- my %lt=&Apache::lonlocal::texthash(
- 'ccld' => "Change Current Login Data",
- 'enld' => "Enter New Login Data"
- );
- $r->print(<
-
-$lt{'ccld'}
-$generalrule
-$authformnop
-$authformcurrent
-$lt{'enld'}
-$authform_other
-ENDOTHERAUTHS
- } else {
- if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
- my %lt=&Apache::lonlocal::texthash(
- 'ccld' => "Change Current Login Data",
- 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
- 'ifch' => "If a change is required, contact a domain coordinator for the domain",
- );
- $r->print(<
-$lt{'ccld'}
-$lt{'yodo'} $lt{'ifch'}: $ccdomain
-ENDNOPRIV
- }
- }
- if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
- # Current user has quota modification privileges
- $r->print(&portfolio_quota($ccuname,$ccdomain));
- }
- } ## End of "check for bad authentication type" logic
} ## End of new user/old user logic
- $r->print('
'.&mt('Add Roles').'');
+ my $addrolesdisplay = 0;
+ $r->print(''.&mt('Add Roles').'');
#
# Co-Author
#
if (&authorpriv($env{'user.name'},$env{'request.role.domain'}) &&
($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
# No sense in assigning co-author role to yourself
+ $addrolesdisplay = 1;
my $cuname=$env{'user.name'};
my $cudom=$env{'request.role.domain'};
my %lt=&Apache::lonlocal::texthash(
@@ -1152,6 +1129,13 @@ ENDNOPRIV
"javascript:pjump('."'date_end','End Date Assistant Co-Author',document.cu.end_$cudom\_$cuname\_aa.value,'end_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'sed'}.' | '."\n".
&Apache::loncommon::end_data_table_row()."\n".
&Apache::loncommon::end_data_table());
+ } elsif (!(&authorpriv($env{'user.name'},$env{'request.role.domain'}))) {
+ $r->print(''.
+ &mt('You do not have privileges to assign co-author roles.').
+ '');
+ } elsif (($env{'user.name'} eq $ccuname) &&
+ ($env{'user.domain'} eq $ccdomain)) {
+ $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Construction Space is not permitted'));
}
#
# Domain level
@@ -1192,33 +1176,314 @@ ENDNOPRIV
$domaintext.= &Apache::loncommon::end_data_table();
if ($num_domain_level > 0) {
$r->print($domaintext);
+ $addrolesdisplay = 1;
}
#
-# Course and group levels
+# Course level
#
if ($env{'request.role'} =~ m{^dc\./($match_domain)/$}) {
$r->print(&course_level_dc($1,'Course'));
- $r->print('
'."\n");
+ $r->print('
'."\n");
+ } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/$}) {
+ if ($addrolesdisplay) {
+ $r->print('
print(' onClick="verify_message(this.form)" \>'."\n");
+ } else {
+ $r->print('onClick="this.form.submit()" \>'."\n");
+ }
+ } else {
+ $r->print('
'.
+ &mt('Back to previous page').'');
+ }
} else {
$r->print(&course_level_table(%inccourses));
- $r->print('
'."\n");
+ $r->print('
'."\n");
}
- $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','state']));
- $r->print('');
+ $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
+ $r->print('');
$r->print('');
$r->print("".&Apache::loncommon::end_page());
}
+sub user_authentication {
+ my ($ccuname,$ccdomain,$krbdefdom,$abv_auth) = @_;
+ my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
+ my ($loginscript,$outcome);
+ if ($currentauth=~/^(krb)(4|5):(.*)/) {
+ my $long_auth = $1.$2;
+ my $curr_kerb_ver = $2;
+ my $krbdefdom=$3;
+ my $curr_authtype = $abv_auth->{$long_auth};
+ my %param = ( formname => 'document.cu',
+ kerb_def_dom => $krbdefdom,
+ domain => $ccdomain,
+ curr_authtype => $curr_authtype,
+ curr_kerb_ver => $curr_kerb_ver,
+ );
+ $loginscript = &Apache::loncommon::authform_header(%param);
+ }
+ # Check for a bad authentication type
+ if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
+ # bad authentication scheme
+ my %lt=&Apache::lonlocal::texthash(
+ 'err' => "ERROR",
+ 'uuas' => "This user has an unrecognized authentication scheme",
+ 'adcs' => "Please alert a domain coordinator of this situation",
+ 'sldb' => "Please specify login data below",
+ 'ld' => "Login Data"
+ );
+ if (&Apache::lonnet::allowed('mau',$ccdomain)) {
+ &initialize_authen_forms($ccdomain);
+ my $choices = &set_login($ccdomain);
+ $outcome = <
+$loginscript
+
+$lt{'err'}:
+$lt{'uuas'} ($currentauth). $lt{'sldb'}.
+$lt{'ld'}
+$choices
+ENDBADAUTH
+ } else {
+ # This user is not allowed to modify the user's
+ # authentication scheme, so just notify them of the problem
+ $outcome = < $lt{'err'}:
+$lt{'uuas'} ($currentauth). $lt{'adcs'}.
+
+ENDBADAUTH
+ }
+ } else { # Authentication type is valid
+ my $authformcurrent='';
+ my $authform_other='';
+ &initialize_authen_forms($ccdomain,$currentauth);
+ my ($authformcurrent,$authform_other,$can_modify) =
+ &modify_login_block($ccdomain,$currentauth);
+ if (&Apache::lonnet::allowed('mau',$ccdomain)) {
+ # Current user has login modification privileges
+ my %lt=&Apache::lonlocal::texthash (
+ 'ld' => "Login Data",
+ 'ccld' => "Change Current Login Data",
+ 'enld' => "Enter New Login Data"
+ );
+ $outcome =
+ ''."\n".
+ ''.$lt{'ld'}.'
'.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_row().
+ ''.$authformnop;
+ if ($can_modify) {
+ $outcome .= ' | '."\n".
+ &Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::start_data_table_row().
+ ''.$authformcurrent.' | '.
+ &Apache::loncommon::end_data_table_row()."\n";
+ } else {
+ $outcome .= ' ('.$authformcurrent.')';
+ }
+ if ($authform_other ne '') {
+ $outcome .= $authform_other;
+ }
+ $outcome .= &Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::end_data_table();
+ } else {
+ if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
+ my %lt=&Apache::lonlocal::texthash(
+ 'ccld' => "Change Current Login Data",
+ 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
+ 'ifch' => "If a change is required, contact a domain coordinator for the domain",
+ );
+ $outcome .= <$lt{'ccld'}
+$lt{'yodo'} $lt{'ifch'}: $ccdomain
+ENDNOPRIV
+ }
+ }
+ } ## End of "check for bad authentication type" logic
+ return $outcome;
+}
+
+sub set_login {
+ my ($dom) = @_;
+ my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
+ my $response;
+ my ($authnum,%can_assign) =
+ &Apache::loncommon::get_assignable_auth($dom);
+ if ($authnum) {
+ $response = &Apache::loncommon::start_data_table();
+ if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
+ $response .= &Apache::loncommon::start_data_table_row().
+ ''.$authformkrb.' | '.
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ if ($can_assign{'int'}) {
+ $response .= &Apache::loncommon::start_data_table_row().
+ ''.$authformint.' | '.
+ &Apache::loncommon::end_data_table_row()."\n"
+ }
+ if ($can_assign{'loc'}) {
+ $response .= &Apache::loncommon::start_data_table_row().
+ ''.$authformloc.' | '.
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ $response .= &Apache::loncommon::end_data_table();
+ }
+ return $response;
+}
+
+sub modify_login_block {
+ my ($dom,$currentauth) = @_;
+ my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
+ my ($authnum,%can_assign) =
+ &Apache::loncommon::get_assignable_auth($dom);
+ my ($authformcurrent,$authform_other,$show_override_msg);
+ if ($currentauth=~/^krb(4|5):/) {
+ $authformcurrent=$authformkrb;
+ if ($can_assign{'int'}) {
+ $authform_other = &Apache::loncommon::start_data_table_row().
+ ''.$authformint.' | '.
+ &Apache::loncommon::end_data_table_row()."\n"
+ }
+ if ($can_assign{'loc'}) {
+ $authform_other .= &Apache::loncommon::start_data_table_row().
+ ''.$authformloc.' | '.
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
+ $show_override_msg = 1;
+ }
+ } elsif ($currentauth=~/^internal:/) {
+ $authformcurrent=$authformint;
+ if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
+ $authform_other = &Apache::loncommon::start_data_table_row().
+ ''.$authformkrb.' | '.
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ if ($can_assign{'loc'}) {
+ $authform_other .= &Apache::loncommon::start_data_table_row().
+ ''.$authformloc.' | '.
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ if ($can_assign{'int'}) {
+ $show_override_msg = 1;
+ }
+ } elsif ($currentauth=~/^unix:/) {
+ $authformcurrent=$authformfsys;
+ if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
+ $authform_other = &Apache::loncommon::start_data_table_row().
+ ''.$authformkrb.' | '.
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ if ($can_assign{'int'}) {
+ $authform_other .= &Apache::loncommon::start_data_table_row().
+ ''.$authformint.' | '.
+ &Apache::loncommon::end_data_table_row()."\n"
+ }
+ if ($can_assign{'loc'}) {
+ $authform_other .= &Apache::loncommon::start_data_table_row().
+ ''.$authformloc.' | '.
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ if ($can_assign{'fsys'}) {
+ $show_override_msg = 1;
+ }
+ } elsif ($currentauth=~/^localauth:/) {
+ $authformcurrent=$authformloc;
+ if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
+ $authform_other = &Apache::loncommon::start_data_table_row().
+ ''.$authformkrb.' | '.
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ if ($can_assign{'int'}) {
+ $authform_other .= &Apache::loncommon::start_data_table_row().
+ ''.$authformint.' | '.
+ &Apache::loncommon::end_data_table_row()."\n"
+ }
+ if ($can_assign{'loc'}) {
+ $show_override_msg = 1;
+ }
+ }
+ if ($show_override_msg) {
+ $authformcurrent.= ' '.
+ &mt('will override current values').
+ '
';
+ }
+ return ($authformcurrent,$authform_other,$show_override_msg);
+}
+
+sub personal_data_display {
+ my ($ccuname,$ccdomain,$newuser,%inst_results) = @_;
+ my ($output,%userenv);
+ if (!$newuser) {
+ # Get the users information
+ %userenv = &Apache::lonnet::get('environment',
+ ['firstname','middlename','lastname','generation',
+ 'permanentemail','id'],$ccdomain,$ccuname);
+ }
+ my %lt=&Apache::lonlocal::texthash(
+ 'pd' => "Personal Data",
+ 'firstname' => "First Name",
+ 'middlename' => "Middle Name",
+ 'lastname' => "Last Name",
+ 'generation' => "Generation",
+ 'permanentemail' => "Permanent e-mail address",
+ 'id' => "ID/Student Number",
+ 'hs' => "Home Server",
+ 'lg' => "Login Data"
+ );
+ my @userinfo = ('firstname','middlename','lastname','generation',
+ 'permanentemail','id');
+ my %textboxsize = (
+ firstname => '15',
+ middlename => '15',
+ lastname => '15',
+ generation => '5',
+ permanentemail => '25',
+ id => '15',
+ );
+ my $genhelp=&Apache::loncommon::help_open_topic('Generation');
+ $output = ''.$lt{'pd'}.'
'.
+ &Apache::lonhtmlcommon::start_pick_box();
+ foreach my $item (@userinfo) {
+ my $rowtitle = $lt{$item};
+ if ($item eq 'generation') {
+ $rowtitle = $genhelp.$rowtitle;
+ }
+ $output .= &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
+ if ($newuser) {
+ if ($inst_results{$item} ne '') {
+ $output .= ''.$inst_results{$item};
+ } else {
+ $output .= '';
+ }
+ } else {
+ if (&Apache::lonnet::allowed('mau',$ccdomain)) {
+ $output .= '';
+ } else {
+ $output .= $userenv{$item};
+ }
+ }
+ $output .= &Apache::lonhtmlcommon::row_closure(1);
+ }
+ $output .= &Apache::lonhtmlcommon::end_pick_box();
+ return $output;
+}
+
# ================================================================= Phase Three
sub update_user_data {
my ($r) = @_;
my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
$env{'form.ccdomain'});
# Error messages
- my $error = ''.&mt('Error').':';
- my $end = &Apache::loncommon::end_page();
-
+ my $error = ''.&mt('Error').': ';
+ my $end = '
'.
+ ''.
+ &mt('Return to previous page').''.&Apache::loncommon::end_page();
my $title;
if (exists($env{'form.makeuser'})) {
$title='Set Privileges for New User';
@@ -1251,6 +1516,7 @@ sub update_user_data {
$r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
my %disallowed;
+ $r->print(&update_result_form($uhome));
# Check Inputs
if (! $env{'form.ccuname'} ) {
$r->print($error.&mt('No login name specified').'.'.$end);
@@ -1312,8 +1578,8 @@ sub update_user_data {
}
- $r->print(''.&mt('User [_1] in domain [_2]',
- $env{'form.ccuname'}, $env{'form.ccdomain'}).'
');
+ $r->print(''.&mt('User [_1] in domain [_2]',
+ $env{'form.ccuname'}, $env{'form.ccdomain'}).'
');
if ($env{'form.makeuser'}) {
$r->print(''.&mt('Creating new account.').'
');
@@ -1337,10 +1603,10 @@ sub update_user_data {
# Call modifyuser
my $result = &Apache::lonnet::modifyuser
($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cstid'},
- $amode,$genpwd,$env{'form.cfirst'},
- $env{'form.cmiddle'},$env{'form.clast'},$env{'form.cgen'},
- undef,$desiredhost
- );
+ $amode,$genpwd,$env{'form.cfirstname'},
+ $env{'form.cmiddlename'},$env{'form.clastname'},
+ $env{'form.cgeneration'},undef,$desiredhost,
+ $env{'form.cpermanentemail'});
$r->print(&mt('Generating user').': '.$result);
my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},
$env{'form.ccdomain'});
@@ -1446,7 +1712,7 @@ sub update_user_data {
$changeHash{'middlename'} = $env{'form.cmiddlename'};
$changeHash{'lastname'} = $env{'form.clastname'};
$changeHash{'generation'} = $env{'form.cgeneration'};
- $changeHash{'permanentemail'} = $env{'form.permanentemail'};
+ $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
my $putresult = &Apache::lonnet::put
('environment',\%changeHash,
$env{'form.ccdomain'},$env{'form.ccuname'});
@@ -1471,7 +1737,8 @@ sub update_user_data {
$lt{'mddl'} |
$lt{'lst'} |
$lt{'gen'} |
- $lt{'disk'} |
+ | $lt{'mail'} |
+ $lt{'disk'} |
$lt{'prvs'} |
$userenv{'firstname'} |
$userenv{'middlename'} |
@@ -1498,9 +1765,9 @@ END
&Apache::lonnet::appenv(%newenvhash);
}
} else { # error occurred
- $r->print("".&mt('Unable to successfully change environment for')." ".
- $env{'form.ccuname'}." ".&mt('in domain')." ".
- $env{'form.ccdomain'}."
");
+ $r->print(''.&mt('Unable to successfully change environment for').' '.
+ $env{'form.ccuname'}.' '.&mt('in domain').' '.
+ $env{'form.ccdomain'}.'');
}
} else { # End of if ($env ... ) logic
my $putresult;
@@ -1516,8 +1783,7 @@ END
'disk' => "Disk space allocated to user's portfolio files",
);
$r->print(<<"END");
-$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
-$lt{'mail'}: $userenv{'permanentemail'}
+$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'} ($lt{'mail'}: $userenv{'permanentemail'})
END
if ($putresult eq 'ok') {
if ($oldportfolioquota != $newportfolioquota) {
@@ -1738,20 +2004,28 @@ END
} # End of foreach (keys(%env))
# Flush the course logs so reverse user roles immediately updated
&Apache::lonnet::flushcourselogs();
- $r->print(''.&mt('Create/Modify Another User').'
');
- $r->print(''."\n");
+ $r->print(&Apache::loncommon::end_page());
+}
+
+sub update_result_form {
+ my ($uhome) = @_;
+ my $outcome =
+ ''."\n";
foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
- $r->print(''."\n");
+ $outcome .= ''."\n";
}
foreach my $item ('sortby','seluname','seludom') {
if (exists($env{'form.'.$item})) {
- $r->print(''."\n");
+ $outcome .= ''."\n";
}
}
- $r->print(''."\n".
- ''."\n".
- '');
- $r->print(&Apache::loncommon::end_page());
+ if ($uhome eq 'no_host') {
+ $outcome .= ''."\n";
+ }
+ $outcome .= ''."\n".
+ ''."\n".
+ '';
+ return $outcome;
}
sub classlist_drop {
@@ -1948,7 +2222,7 @@ ENDCCF
}
$r->print(&Apache::loncommon::end_data_table().
''."\n".''."\n".
+ '" />'."\n".''."\n".
''."\n".
''.
&Apache::loncommon::end_page());
@@ -2058,14 +2332,14 @@ sub set_custom_role {
&Apache::lonnet::get('roles',["rolesdef_$rolename"]);
# ------------------------------------------------------- Does this role exist?
- $r->print('');
+ $r->print('');
if (($rdummy ne 'con_lost') && ($roledef ne '')) {
$r->print(&mt('Existing Role').' "');
} else {
$r->print(&mt('New Role').' "');
$roledef='';
}
- $r->print($rolename.'"
');
+ $r->print($rolename.'"');
# ------------------------------------------------------- What can be assigned?
my $sysrole='';
my $domrole='';
@@ -2141,11 +2415,14 @@ sub handler {
$srch->{$item} = $env{'form.'.$item};
}
if ($env{'form.phase'} eq 'get_user_info') {
- my ($state,$response,$forcenewuser,$results) =
+ my ($currstate,$response,$forcenewuser,$results) =
&user_search_result($srch);
- if ($state eq 'select') {
- &print_user_selection_page($r,$response,$srch,$results);
- } elsif ($state eq 'modify') {
+ if ($env{'form.currstate'} eq 'modify') {
+ $currstate = $env{'form.currstate'};
+ }
+ if ($currstate eq 'select') {
+ &print_user_selection_page($r,$response,$srch,$results,'createuser',\@search);
+ } elsif ($currstate eq 'modify') {
my ($ccuname,$ccdomain);
if (($srch->{'srchby'} eq 'uname') &&
($srch->{'srchtype'} eq 'exact')) {
@@ -2157,10 +2434,13 @@ sub handler {
}
$ccuname =&LONCAPA::clean_username($ccuname);
$ccdomain=&LONCAPA::clean_domain($ccdomain);
+ if ($env{'form.forcenewuser'}) {
+ $response = '';
+ }
&print_user_modification_page($r,$ccuname,$ccdomain,$srch,
$response);
- } elsif ($state eq 'query') {
- &print_user_query_page($r);
+ } elsif ($currstate eq 'query') {
+ &print_user_query_page($r,'createuser');
} else {
&print_username_entry_form($r,$response,$srch,$forcenewuser);
}
@@ -2192,20 +2472,23 @@ sub user_search_result {
my %allhomes;
my %inst_matches;
my %srch_results;
- my ($response,$state,$forcenewuser);
-
- if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
+ my ($response,$currstate,$forcenewuser,$dirsrchres);
+ $srch->{'srchterm'} =~ s/\s+/ /g;
+ if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
$response = &mt('Invalid search.');
}
if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
$response = &mt('Invalid search.');
}
- if ($srch->{'srchtype'} !~ /^(exact|contains)$/) {
+ if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
$response = &mt('Invalid search.');
}
if ($srch->{'srchterm'} eq '') {
$response = &mt('You must enter a search term.');
}
+ if ($srch->{'srchterm'} =~ /^\s+$/) {
+ $response = &mt('Your search term must contain more than just spaces.');
+ }
if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
if (($srch->{'srchdomain'} eq '') ||
! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
@@ -2214,18 +2497,24 @@ sub user_search_result {
}
if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
($srch->{'srchin'} eq 'alc')) {
- if ($srch->{'srchterm'} !~ /^$match_username$/) {
- $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
+ if ($srch->{'srchby'} eq 'uname') {
+ if ($srch->{'srchterm'} !~ /^$match_username$/) {
+ $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
+ }
}
}
+ if ($response ne '') {
+ $response = ''.$response.'';
+ }
if ($srch->{'srchin'} eq 'instd') {
my $instd_chk = &directorysrch_check($srch);
if ($instd_chk ne 'ok') {
- $response = $instd_chk;
+ $response = ''.$instd_chk.''.
+ '
'.&mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').'
';
}
}
if ($response ne '') {
- return ($state,''.$response.'');
+ return ($currstate,$response);
}
if ($srch->{'srchby'} eq 'uname') {
if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
@@ -2234,42 +2523,53 @@ sub user_search_result {
my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
if ($uhome eq 'no_host') {
my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
- $response = &mt('New users can only be created in the domain to which you current role belongs - [_1].',$env{'request.role.domain'}.' ('.$domdesc.')');
+ my $showdom = &display_domain_info($env{'request.role.domain'});
+ $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
} else {
- $state = 'modify';
+ $currstate = 'modify';
}
} else {
- $state = 'modify';
+ $currstate = 'modify';
}
} else {
if ($srch->{'srchin'} eq 'dom') {
if ($srch->{'srchtype'} eq 'exact') {
my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
if ($uhome eq 'no_host') {
- ($state,$response,$forcenewuser) =
+ ($currstate,$response,$forcenewuser) =
&build_search_response($srch,%srch_results);
} else {
- $state = 'modify';
+ $currstate = 'modify';
}
} else {
%srch_results = &Apache::lonnet::usersearch($srch);
- ($state,$response,$forcenewuser) =
+ ($currstate,$response,$forcenewuser) =
&build_search_response($srch,%srch_results);
}
} else {
my $courseusers = &get_courseusers();
if ($srch->{'srchtype'} eq 'exact') {
if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
- $state = 'modify';
+ $currstate = 'modify';
} else {
- ($state,$response,$forcenewuser) =
+ ($currstate,$response,$forcenewuser) =
&build_search_response($srch,%srch_results);
}
} else {
foreach my $user (keys(%$courseusers)) {
my ($cuname,$cudomain) = split(/:/,$user);
if ($cudomain eq $srch->{'srchdomain'}) {
- if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
+ my $matched = 0;
+ if ($srch->{'srchtype'} eq 'begins') {
+ if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
+ $matched = 1;
+ }
+ } else {
+ if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
+ $matched = 1;
+ }
+ }
+ if ($matched) {
$srch_results{$user} =
{&Apache::lonnet::get('environment',
['firstname',
@@ -2278,22 +2578,31 @@ sub user_search_result {
}
}
}
- ($state,$response,$forcenewuser) =
+ ($currstate,$response,$forcenewuser) =
&build_search_response($srch,%srch_results);
}
}
}
} elsif ($srch->{'srchin'} eq 'alc') {
- $state = 'query';
+ $currstate = 'query';
} elsif ($srch->{'srchin'} eq 'instd') {
- %srch_results = &Apache::lonnet::inst_directory_query($srch);
- ($state,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
+ if ($dirsrchres eq 'ok') {
+ ($currstate,$response,$forcenewuser) =
+ &build_search_response($srch,%srch_results);
+ } else {
+ my $showdom = &display_domain_info($srch->{'srchdomain'});
+ $response = ''.
+ &mt('Institutional directory search is not available in domain: [_1]',$showdom).
+ '
'.
+ &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
+ '
';
+ }
}
} else {
if ($srch->{'srchin'} eq 'dom') {
%srch_results = &Apache::lonnet::usersearch($srch);
- ($state,$response,$forcenewuser) =
+ ($currstate,$response,$forcenewuser) =
&build_search_response($srch,%srch_results);
} elsif ($srch->{'srchin'} eq 'crs') {
my $courseusers = &get_courseusers();
@@ -2304,6 +2613,8 @@ sub user_search_result {
if ($srch->{'srchby'} eq 'lastname') {
if ((($srch->{'srchtype'} eq 'exact') &&
($names{'lastname'} eq $srch->{'srchterm'})) ||
+ (($srch->{'srchtype'} eq 'begins') &&
+ ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
(($srch->{'srchtype'} eq 'contains') &&
($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
$srch_results{$user} = {firstname => $names{'firstname'},
@@ -2313,6 +2624,8 @@ sub user_search_result {
}
} elsif ($srch->{'srchby'} eq 'lastfirst') {
my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
+ $srchlast =~ s/\s+$//;
+ $srchfirst =~ s/^\s+//;
if ($srch->{'srchtype'} eq 'exact') {
if (($names{'lastname'} eq $srchlast) &&
($names{'firstname'} eq $srchfirst)) {
@@ -2322,7 +2635,15 @@ sub user_search_result {
};
}
- } elsif ($srch->{'srchtype'} eq 'contains') {
+ } elsif ($srch->{'srchtype'} eq 'begins') {
+ if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
+ ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
+ $srch_results{$user} = {firstname => $names{'firstname'},
+ lastname => $names{'lastname'},
+ permanentemail => $emails{'permanentemail'},
+ };
+ }
+ } else {
if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
$srch_results{$user} = {firstname => $names{'firstname'},
@@ -2333,17 +2654,25 @@ sub user_search_result {
}
}
}
- ($state,$response,$forcenewuser) =
+ ($currstate,$response,$forcenewuser) =
&build_search_response($srch,%srch_results);
} elsif ($srch->{'srchin'} eq 'alc') {
- $state = 'query';
+ $currstate = 'query';
} elsif ($srch->{'srchin'} eq 'instd') {
- %srch_results = &Apache::lonnet::inst_directory_query($srch);
- ($state,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
+ if ($dirsrchres eq 'ok') {
+ ($currstate,$response,$forcenewuser) =
+ &build_search_response($srch,%srch_results);
+ } else {
+ my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = ''.
+ &mt('Institutional directory search is not available in domain: [_1]',$showdom).
+ '
'.
+ &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
+ '
';
+ }
}
}
- return ($state,$response,$forcenewuser,\%srch_results);
+ return ($currstate,$response,$forcenewuser,\%srch_results);
}
sub directorysrch_check {
@@ -2352,13 +2681,14 @@ sub directorysrch_check {
my $response;
my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
['directorysrch'],$srch->{'srchdomain'});
+ my $showdom = &display_domain_info($srch->{'srchdomain'});
if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
if (!$dom_inst_srch{'directorysrch'}{'available'}) {
- return &mt('Institutional directory search unavailable in domain: [_1]',$srch->{'srchdomain'});
+ return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
}
if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
- return &mt('Insitutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$srch->{'srchdomain'});
+ return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
}
my @usertypes = split(/:/,$env{'environment.inststatus'});
if (!@usertypes) {
@@ -2379,41 +2709,50 @@ sub directorysrch_check {
push (@longtypes,$insttypes->{$item});
}
my $insttype_str = join(', ',@longtypes);
- return &mt('Directory search in domain: [_1] is unavailable to your user type: ',$srch->{'srchdomain'}).$insttype_str;
+ return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
}
} else {
$can_search = 1;
}
} else {
- return &mt('Directory search has not been configured for domain: [_1]',$srch->{'srchdomain'});
+ return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
}
my %longtext = &Apache::lonlocal::texthash (
uname => 'username',
lastfirst => 'last name, first name',
lastname => 'last name',
contains => 'contains',
- exact => 'as exact match to'
+ exact => 'as exact match to',
+ begins => 'begins with',
);
if ($can_search) {
if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
- return &mt('Directory search in domain: [_1] is not available for searching by "[_2]"',$srch->{'srchdomain'},$longtext{$srch->{'srchby'}});
+ return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
}
} else {
- return &mt('Directory search in domain: [_1] is not available.', $srch->{'srchdomain'});
+ return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
}
}
if ($can_search) {
- if (($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') ||
- ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
- return 'ok';
- } else {
- return &mt('Directory search in domain [_1] is not available for the requested search type: "[_2]"',$srch->{'srchdomain'},$longtext{$srch->{'srchtype'}});
+ if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
+ if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
+ return 'ok';
+ } else {
+ return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
+ }
+ } else {
+ if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
+ ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
+ ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
+ return 'ok';
+ } else {
+ return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
+ }
}
}
}
-
sub get_courseusers {
my %advhash;
my $classlist = &Apache::loncoursedata::get_classlist();
@@ -2430,32 +2769,41 @@ sub get_courseusers {
sub build_search_response {
my ($srch,%srch_results) = @_;
- my ($state,$response,$forcenewuser);
+ my ($currstate,$response,$forcenewuser);
my %names = (
'uname' => 'username',
'lastname' => 'last name',
'lastfirst' => 'last name, first name',
'crs' => 'this course',
- 'dom' => 'this domain',
- 'instd' => "your institution's directory",
+ 'dom' => 'LON-CAPA domain: ',
+ 'instd' => 'the institutional directory for domain: ',
);
my %single = (
+ begins => 'A match',
contains => 'A match',
- exact => 'An exact match',
+ exact => 'An exact match',
);
my %nomatch = (
+ begins => 'No match',
contains => 'No match',
- exact => 'No exact match',
+ exact => 'No exact match',
);
if (keys(%srch_results) > 1) {
- $state = 'select';
+ $currstate = 'select';
} else {
if (keys(%srch_results) == 1) {
- $state = 'modify';
- $response = &mt("$single{$srch->{'srchtype'}} was found for this $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
+ $currstate = 'modify';
+ $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
+ if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
+ $response .= &display_domain_info($srch->{'srchdomain'});
+ }
} else {
- $response = ''.&mt("$nomatch{$srch->{'srchtype'}} found for this $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'}).'';
+ $response = ''.&mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}",$srch->{'srchterm'});
+ if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
+ $response .= &display_domain_info($srch->{'srchdomain'});
+ }
+ $response .= '';
if ($srch->{'srchin'} ne 'alc') {
$forcenewuser = 1;
my $cansrchinst = 0;
@@ -2467,20 +2815,36 @@ sub build_search_response {
}
}
}
- if (($srch->{'srchby'} eq 'lastfirst') ||
- ($srch->{'srchby'} eq 'lastname')) {
- if ($srch->{'srchin'} eq 'crs') {
- $response .= '
'.&mt('You may want to broaden your search to the whole domain.');
- } elsif ($srch->{'srchin'} eq 'dom') {
- if ($cansrchinst) {
- $response .= '
'.&mt('You may want to broaden your search to a search of the institutional directory for this domain.');
- }
+ if ((($srch->{'srchby'} eq 'lastfirst') ||
+ ($srch->{'srchby'} eq 'lastname')) &&
+ ($srch->{'srchin'} eq 'dom')) {
+ if ($cansrchinst) {
+ $response .= '
'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
}
}
+ if ($srch->{'srchin'} eq 'crs') {
+ $response .= '
'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
+ }
+ }
+ if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) {
+ my $showdom = &display_domain_info($env{'request.role.domain'});
+ $response .= '
'.&mt("To add a new user (you can only create new users in your current role's domain - [_1]):",$env{'request.role.domain'}).'- '.&mt("Set 'Domain/institution to search' to: [_1]",$showdom).'
- '.&mt("Set 'Search criteria' to: 'username is ...... in selected LON-CAPA domain'").'
- '.&mt('Provide the proposed username').'
- '.&mt('Search').'
';
}
}
}
- return ($state,$response,$forcenewuser);
+ return ($currstate,$response,$forcenewuser);
+}
+
+sub display_domain_info {
+ my ($dom) = @_;
+ my $output = $dom;
+ if ($dom ne '') {
+ my $domdesc = &Apache::lonnet::domain($dom,'description');
+ if ($domdesc ne '') {
+ $output .= ' ('.$domdesc.')';
+ }
+ }
+ return $output;
}
sub crumb_utilities {
@@ -2496,12 +2860,19 @@ sub crumb_utilities {
rolename => 'selectbox',
newrolename => 'textbox',
},
+ studentform => {
+ srchterm => 'text',
+ srchin => 'selectbox',
+ srchby => 'selectbox',
+ srchtype => 'selectbox',
+ srchdomain => 'selectbox',
+ },
);
my $jsback .= qq|
function backPage(formname,prevphase,prevstate) {
formname.phase.value = prevphase;
- formname.state.value = prevstate;
+ formname.currstate.value = prevstate;
formname.submit();
}
|;
@@ -2594,9 +2965,9 @@ ENDTIMEENTRY
if (%sections_count) {
my $currsec = &course_sections(\%sections_count,$customrole);
$table.=
- ''.
- ''.$lt{'exs'}.' '.
- $currsec.' | '.
+ ' | |