');
+ }
$r->print('');
+ ' '."\n".
+ ' '."\n");
$r->print($response);
- $r->print(&Apache::loncommon::end_page());
+ if ($context eq 'createuser') {
+ $r->print(''.&Apache::loncommon::end_page());
+ } else {
+ $r->print(''."\n".
+ ''."\n");
+ }
}
sub print_user_query_page {
- my ($r) = @_;
+ 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.
@@ -681,12 +699,14 @@ ENDFORMINFO
if (($instsrch->{'srchterm'} ne '') && ($instsrch->{'srchdomain'} ne '')) {
$newuser = $instsrch->{'srchterm'}.':'.$instsrch->{'srchdomain'};
}
- my (%dirsrch_results,%inst_results);
+ my (%dirsrch_results,%inst_results,$dirsrchres);
if ($newuser) {
if (&directorysrch_check($instsrch) eq 'ok') {
- %dirsrch_results = &Apache::lonnet::inst_directory_query($instsrch);
- if (ref($dirsrch_results{$newuser}) eq 'HASH') {
- %inst_results = %{$dirsrch_results{$newuser}};
+ ($dirsrchres,%dirsrch_results) = &Apache::lonnet::inst_directory_query($instsrch);
+ if ($dirsrchres eq 'ok') {
+ if (ref($dirsrch_results{$newuser}) eq 'HASH') {
+ %inst_results = %{$dirsrch_results{$newuser}};
+ }
}
}
}
@@ -1204,8 +1224,8 @@ ENDNOPRIV
$r->print(&course_level_table(%inccourses));
$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']));
+ $r->print('');
$r->print('');
$r->print("".&Apache::loncommon::end_page());
}
@@ -1750,7 +1770,7 @@ END
}
}
$r->print(''."\n".
- ''."\n".
+ ''."\n".
'');
$r->print(&Apache::loncommon::end_page());
}
@@ -1949,7 +1969,7 @@ ENDCCF
}
$r->print(&Apache::loncommon::end_data_table().
''."\n".''."\n".
+ '" />'."\n".''."\n".
''."\n".
''.
&Apache::loncommon::end_page());
@@ -2142,11 +2162,11 @@ 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 ($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')) {
@@ -2160,8 +2180,8 @@ sub handler {
$ccdomain=&LONCAPA::clean_domain($ccdomain);
&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);
}
@@ -2193,10 +2213,8 @@ sub user_search_result {
my %allhomes;
my %inst_matches;
my %srch_results;
- my ($response,$state,$forcenewuser);
- $srch->{'srchterm'} =~ s/^\s+//;
- $srch->{'srchterm'} =~ s/\s+$//;
-
+ my ($response,$currstate,$forcenewuser,$dirsrchres);
+ $srch->{'srchterm'} =~ s/\s+/ /g;
if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
$response = &mt('Invalid search.');
}
@@ -2209,6 +2227,9 @@ sub user_search_result {
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'}))) {
@@ -2223,14 +2244,18 @@ sub user_search_result {
}
}
}
+ 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')) {
@@ -2239,35 +2264,36 @@ 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 {
@@ -2293,22 +2319,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();
@@ -2360,17 +2395,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 {
@@ -2379,13 +2422,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) {
@@ -2406,13 +2450,13 @@ 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',
@@ -2425,10 +2469,10 @@ sub directorysrch_check {
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) {
@@ -2436,7 +2480,7 @@ sub directorysrch_check {
if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
return 'ok';
} else {
- return &mt('Directory search in domain [_1] is not available for the requested search type: "[_2]"',$srch->{'srchdomain'},$longtext{$srch->{'srchtype'}});
+ 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') &&
@@ -2444,7 +2488,7 @@ sub directorysrch_check {
($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'}});
+ return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
}
}
}
@@ -2467,32 +2511,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;
@@ -2504,20 +2557,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'").'