--- loncom/interface/loncommon.pm 2007/11/06 19:02:57 1.610
+++ loncom/interface/loncommon.pm 2007/11/10 03:51:46 1.612
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.610 2007/11/06 19:02:57 albertel Exp $
+# $Id: loncommon.pm,v 1.612 2007/11/10 03:51:46 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -257,6 +257,7 @@ sub browser_and_searcher_javascript {
}
url += 'catalogmode=interactive&';
url += 'mode=$mode&';
+ url += 'inhibitmenu=yes&';
url += 'form=' + formname + '&';
if (only != null) {
url += 'only=' + only + '&';
@@ -6429,57 +6430,127 @@ END_BLOCK
return $output;
}
-sub username_rule_check {
- my ($srch,$caller) = @_;
- my ($response,@curr_rules,%inst_results,$rulematch);
- my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($srch->{'srchdomain'});
- if (ref($srch) eq 'HASH') {
- (my $inst_response,%inst_results) =
- &Apache::lonnet::get_instuser($srch->{'srchdomain'},
- $srch->{'srchterm'});
- my %domconfig = &Apache::lonnet::get_dom('configuration',
- ['usercreation'],$srch->{'srchdomain'});
- if (ref($domconfig{'usercreation'}) eq 'HASH') {
- if (ref($domconfig{'usercreation'}{'username_rule'}) eq 'ARRAY') {
- @curr_rules = @{$domconfig{'usercreation'}{'username_rule'}};
- }
- }
- if (@curr_rules > 0) {
- my $domdesc = &Apache::lonnet::domain($srch->{'srchdomain'},'description');
- my $instuser_reqd;
- my %rule_check = &Apache::lonnet::inst_rulecheck($srch->{'srchdomain'},$srch->{'srchterm'},\@curr_rules);
- foreach my $rule (@curr_rules) {
- if ($rule_check{$rule}) {
- $rulematch = $rule;
- if ($inst_response eq 'ok') {
- if (keys(%inst_results) == 0) {
- if ($caller eq 'new') {
- $response = &mt('The username you chose matches the format of usernames defined for [_1], but the user does not exist in the institutional directory.',$domdesc).'
'.&mt("You must choose a username with a different format -- one that will not conflict with 'official' institutional usernames.");
- }
+sub user_rule_check {
+ my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules) = @_;
+ my $response;
+ if (ref($usershash) eq 'HASH') {
+ my %got_rules;
+ foreach my $user (keys(%{$usershash})) {
+ my ($uname,$udom) = split(/:/,$user);
+ next if ($udom eq '' || $uname eq '');
+ my ($userstatus,$id);
+ if (ref($usershash->{$user}) eq 'HASH') {
+ $userstatus = $usershash->{$user}->{'status'};
+ $id = $usershash->{$user}->{'id'};
+ }
+ my $inst_response;
+ if (ref($checks) eq 'HASH') {
+ if (defined($checks->{'username'})) {
+ ($inst_response,%{$inst_results}) =
+ &Apache::lonnet::get_instuser($udom,$uname);
+ } elsif (defined($checks->{'id'})) {
+ ($inst_response,%{$inst_results}) =
+ &Apache::lonnet::get_instuser($udom,undef,$id);
+ }
+ }
+ if (!$got_rules{$udom}) {
+ my %domconfig = &Apache::lonnet::get_dom('configuration',
+ ['usercreation'],$udom);
+ if (ref($domconfig{'usercreation'}) eq 'HASH') {
+ foreach my $item (keys(%{$checks})) {
+ if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
+ $$curr_rules{$udom}{$item} =
+ $domconfig{'usercreation'}{$item.'_rule'};
}
}
- last;
}
+ $got_rules{$udom} = 1;
}
- if ($response) {
- if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
- if (@{$ruleorder} > 0) {
- $response .= '
'.&mt('Usernames with the following format(s) may only be used for verified users at [_1]:',$domdesc).'