--- loncom/interface/loncreateuser.pm 2007/08/02 01:04:41 1.167
+++ loncom/interface/loncreateuser.pm 2007/09/12 23:42:37 1.185
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.167 2007/08/02 01:04:41 albertel Exp $
+# $Id: loncreateuser.pm,v 1.185 2007/09/12 23:42:37 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -216,7 +216,7 @@ sub print_username_entry_form {
$jscript,{'add_entries' => \%loaditems,});
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"javascript:backPage(document.crtuser)",
- text=>"User modify/custom role",
+ text=>"User modify/custom role edit",
faq=>282,bug=>'Instructor Interface',});
my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management');
@@ -264,13 +264,14 @@ ENDCUSTOM
sub entry_form {
my ($dom,$srch,$forcenewuser) = @_;
my $userpicker =
- &Apache::loncommon::user_picker($dom,$srch,$forcenewuser);
+ &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
+ 'document.crtuser');
my $srchbutton = &mt('Search');
my $output = <<"ENDDOCUMENT";
ENDDOCUMENT
return $output;
@@ -305,7 +306,7 @@ END
# =================================================================== Phase two
sub print_user_selection_page {
- my ($r,$response,$srch,$srch_results) = @_;
+ my ($r,$response,$srch,$srch_results,$context,$srcharray) = @_;
my @fields = ('username','domain','lastname','firstname','permanentemail');
my $sortby = $env{'form.sortby'};
@@ -329,25 +330,34 @@ $jsback
ENDSCRIPT
my %lt=&Apache::lonlocal::texthash(
- 'srch' => "User Search to add/modify roles of",
+ '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",
);
- $r->print(&Apache::loncommon::start_page('Create Users, Change User Privileges',$jscript));
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"javascript:backPage(document.usersrchform,'','')",
- text=>"User modify/custom role edit",
- 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{'srch'} ");
- $r->print(&entry_form($srch->{'srchdomain'},$srch));
- $r->print(''.&mt('Select a user to add/modify roles of').' ');
+ if ($context eq 'createuser') {
+ $r->print(&Apache::loncommon::start_page('Create Users, Change User Privileges',$jscript));
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.usersrchform,'','')",
+ text=>"User modify/custom role edit",
+ 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('');
+ ' '."\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.
@@ -402,10 +420,29 @@ sub print_user_query_page {
sub print_user_modification_page {
my ($r,$ccuname,$ccdomain,$srch,$response) = @_;
- unless (($ccuname) && ($ccdomain)) {
- &print_username_entry_form($r);
+ if (($ccuname eq '') || ($ccdomain eq '')) {
+ my $usermsg = &mt('No username and/or domain provided.');
+ &print_username_entry_form($r,$usermsg);
return;
}
+ my ($instsrch,$rulematch,$rules,%inst_results);
+ my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
+ if ($uhome eq 'no_host') {
+ $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;
+ }
+ }
if ($response) {
$response = ' '.$response
}
@@ -657,7 +694,6 @@ ENDSECCODE
ENDFORMINFO
- my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
my %inccourses;
foreach my $key (keys(%env)) {
if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
@@ -665,49 +701,41 @@ ENDFORMINFO
}
}
if ($uhome eq 'no_host') {
- my $newuser;
- my $instsrch = {
- srchin => 'instd',
- srchby => 'uname',
- srchtype => 'exact',
- };
- if ($env{'form.phase'} eq 'userpicked') {
- $instsrch->{'srchterm'} = $env{'form.seluname'};
- $instsrch->{'srchdomain'} = $env{'form.seludom'};
- } else {
- $instsrch->{'srchterm'} = $ccuname;
- $instsrch->{'srchdomain'} = $ccdomain,
- }
- if (($instsrch->{'srchterm'} ne '') && ($instsrch->{'srchdomain'} ne '')) {
- $newuser = $instsrch->{'srchterm'}.':'.$instsrch->{'srchdomain'};
- }
- my (%dirsrch_results,%inst_results);
- 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}};
- }
- }
- }
my $home_server_list=
'default '."\n".
&Apache::loncommon::home_server_option_list($ccdomain);
my %lt=&Apache::lonlocal::texthash(
- 'cnu' => "Create New User",
- 'nu' => "New User",
- 'id' => "in domain",
- 'pd' => "Personal Data",
- 'fn' => "First Name",
- 'mn' => "Middle Name",
- 'ln' => "Last Name",
- 'gen' => "Generation",
- 'mail' => "Permanent e-mail address",
- 'idsn' => "ID/Student Number",
- 'hs' => "Home Server",
- 'lg' => "Login Data"
+ 'cnu' => "Create New User",
+ 'nu' => "New User",
+ 'ind' => "in domain",
+ '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 %element = (
+ firstname => 'cfirst',
+ middlename => 'cmiddle',
+ lastname => 'clast',
+ generation => 'cgen',
+ permanentemail => 'cemail',
+ id => 'cstid',
+ );
my $portfolioform;
if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
# Current user has quota modification privileges
@@ -715,43 +743,91 @@ ENDFORMINFO
}
my $genhelp=&Apache::loncommon::help_open_topic('Generation');
&initialize_authen_forms();
- $r->print(<print(<$lt{'cnu'}
$response
$forminfo
-$lt{'nu'} "$ccuname" $lt{'id'} $ccdomain
+$lt{'nu'} "$ccuname" $lt{'ind'} $ccdomain
$lt{'pd'}
-
-$lt{'idsn'}
+ENDTITLE
+ $r->print(&Apache::lonhtmlcommon::start_pick_box());
+ foreach my $item (@userinfo) {
+ my $rowtitle = $lt{$item};
+ if ($item eq 'generation') {
+ $rowtitle = $genhelp.$rowtitle;
+ }
+ $r->print(&Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n");
+ if ($inst_results{$item} ne '') {
+ $r->print(' '.$inst_results{$item});
+ } else {
+ $r->print(' ');
+ }
+ $r->print(&Apache::lonhtmlcommon::row_closure(1));
+ }
+ $r->print(&Apache::lonhtmlcommon::end_pick_box());
+ $r->print(<
$lt{'hs'}: $home_server_list
+
$lt{'lg'}
-$generalrule
-$authformkrb
-$authformint
-$authformfsys
-$authformloc
+ENDNEWUSER
+ my ($fixedauth,$varauth,$authmsg);
+ if ($rulematch) {
+ if (ref($rules) eq 'HASH') {
+ if (ref($rules->{$rulematch}) eq 'HASH') {
+ my $authtype = $rules->{$rulematch}{'authtype'};
+ if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
+ $r->print(&set_login());
+ } else {
+ my $authparm = $rules->{$rulematch}{'authparm'};
+ if ($authtype =~ /^krb(4|5)$/) {
+ my $ver = $1;
+ if ($authparm ne '') {
+ $fixedauth = <<"KERB";
+
+
+
+KERB
+ $authmsg = $rules->{$rulematch}{'authmsg'};
+ }
+ } else {
+ $fixedauth =
+' '."\n";
+ if ($rules->{$rulematch}{'authparmfixed'}) {
+ $fixedauth .=
+' '."\n";
+ } else {
+ $varauth =
+' '."\n";
+ }
+ }
+ }
+ } else {
+ $r->print(&set_login());
+ }
+ }
+ if ($authmsg) {
+ $r->print(<print(&set_login());
+ }
+ $r->print(<
$portfolioform
-ENDNEWUSER
+ENDPORT
} else { # user already exists
my %lt=&Apache::lonlocal::texthash(
'cup' => "Change User Privileges",
@@ -783,7 +859,7 @@ ENDCHANGEUSER
''.$lt{'fn'}.' '.$lt{'mn'}.' '.$lt{'ln'}.' '.$lt{'gen'}.' '.$lt{'email'}.' '.
&Apache::loncommon::end_data_table_header_row().
&Apache::loncommon::start_data_table_row());
- foreach my $item ('firstname','middlename','lastname','generation','permenanentemail') {
+ foreach my $item ('firstname','middlename','lastname','generation','permanentemail') {
if (&Apache::lonnet::allowed('mau',$ccdomain)) {
$r->print(<<"END");
@@ -1136,7 +1212,7 @@ ENDNOPRIV
'.$lt{'ssd'}.'
-
+
'.$lt{'sed'}.' '."\n".
&Apache::loncommon::end_data_table_row()."\n".
@@ -1144,10 +1220,10 @@ ENDNOPRIV
'
'.$lt{'caa'}.'
'.$cudom.'_'.$cuname.'
-
+
'.$lt{'ssd'}.'
-
+
'.$lt{'sed'}.' '."\n".
&Apache::loncommon::end_data_table_row()."\n".
@@ -1179,10 +1255,10 @@ ENDNOPRIV
'
'.$plrole.'
'.$thisdomain.'
-
+
'.$lt{'ssd'}.'
-
+
'.$lt{'sed'}.' '.
&Apache::loncommon::end_data_table_row();
@@ -1204,12 +1280,23 @@ 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());
}
+sub set_login {
+ my $response = (<$generalrule
+$authformkrb
+$authformint
+$authformfsys
+$authformloc
+ENDAUTH
+ return $response;
+}
+
# ================================================================= Phase Three
sub update_user_data {
my ($r) = @_;
@@ -1339,7 +1426,7 @@ sub update_user_data {
($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
+ undef,$desiredhost,$env{'form.cemail'}
);
$r->print(&mt('Generating user').': '.$result);
my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},
@@ -1446,7 +1533,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 +1558,8 @@ sub update_user_data {
$lt{'mddl'}
$lt{'lst'}
$lt{'gen'}
- $lt{'disk'}
+ $lt{'mail'}
+ $lt{'disk'}
$lt{'prvs'}
$userenv{'firstname'}
$userenv{'middlename'}
@@ -1537,23 +1625,20 @@ END
if ($key=~/^form\.rev/) {
if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
# Revoke standard role
- $r->print(&mt('Revoking').' '.$2.' in '.$1.': '.
- &Apache::lonnet::revokerole($env{'form.ccdomain'},
- $env{'form.ccuname'},$1,$2).' ');
- if ($2 eq 'st') {
- $1=~m{^/($match_domain)/($match_courseid)};
- my $cid=$1.'_'.$2;
- my $user = $env{'form.ccuname'}.':'.$env{'form.ccdomain'};
- my $result =
- &Apache::lonnet::cput('classlist',
- { $user => $now },
- $env{'course.'.$cid.'.domain'},
- $env{'course.'.$cid.'.num'});
- $r->print(&mt('Drop from classlist: [_1]',
- ''.$result.' ').' ');
+ my ($scope,$role) = ($1,$2);
+ my $result =
+ &Apache::lonnet::revokerole($env{'form.ccdomain'},
+ $env{'form.ccuname'},
+ $scope,$role);
+ $r->print(&mt('Revoking [_1] in [_2]: [_3]',
+ $role,$scope,''.$result.' ').' ');
+ if ($role eq 'st') {
+ my $result = &classlist_drop($scope,$env{'form.ccuname'},
+ $env{'form.ccdomain'},$now);
+ $r->print($result);
}
}
- if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
+ if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$ }s) {
# Revoke custom role
$r->print(&mt('Revoking custom role:').
' '.$4.' by '.$3.':'.$2.' in '.$1.': '.
@@ -1564,26 +1649,23 @@ END
} elsif ($key=~/^form\.del/) {
if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
# Delete standard role
- $r->print(&mt('Deleting').' '.$2.' in '.$1.': '.
- &Apache::lonnet::assignrole($env{'form.ccdomain'},
- $env{'form.ccuname'},$1,$2,$now,0,1).' ');
- if ($2 eq 'st') {
- $1=~m{^/($match_domain)/($match_courseid)};
- my $cid=$1.'_'.$2;
- my $user = $env{'form.ccuname'}.':'.$env{'form.ccdomain'};
- my $result =
- &Apache::lonnet::cput('classlist',
- { $user => $now },
- $env{'course.'.$cid.'.domain'},
- $env{'course.'.$cid.'.num'});
- $r->print(&mt('Drop from classlist: [_1]',
- ''.$result.' ').' ');
+ my ($scope,$role) = ($1,$2);
+ my $result =
+ &Apache::lonnet::assignrole($env{'form.ccdomain'},
+ $env{'form.ccuname'},
+ $scope,$role,$now,0,1);
+ $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
+ ''.$result.' ').' ');
+ if ($role eq 'st') {
+ my $result = &classlist_drop($scope,$env{'form.ccuname'},
+ $env{'form.ccdomain'},$now);
+ $r->print($result);
}
}
if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
# Delete custom role
- $r->print(&mt('Deleting custom role [_1] by [_2]@[_3] in [_4]',
+ $r->print(&mt('Deleting custom role [_1] by [_2]:[_3] in [_4]',
$rolename,$rnam,$rdom,$url).': '.
&Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
$env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
@@ -1755,11 +1837,35 @@ END
}
}
$r->print(' '."\n".
- ' '."\n".
+ ' '."\n".
'');
$r->print(&Apache::loncommon::end_page());
}
+sub classlist_drop {
+ my ($scope,$uname,$udom,$now) = @_;
+ my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
+ my $cid=$cdom.'_'.$cnum;
+ my $user = $uname.':'.$udom;
+ if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
+ my $result =
+ &Apache::lonnet::cput('classlist',
+ { $user => $now },
+ $env{'course.'.$cid.'.domain'},
+ $env{'course.'.$cid.'.num'});
+ return &mt('Drop from classlist: [_1]',
+ ''.$result.' ').' ';
+ }
+}
+
+sub active_student_roles {
+ my ($cnum,$cdom,$uname,$udom) = @_;
+ my %roles =
+ &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
+ ['future','active'],['st']);
+ return exists($roles{"$cnum:$cdom:st"});
+}
+
sub quota_admin {
my ($setquota,$changeHash) = @_;
my $quotachanged;
@@ -1930,7 +2036,7 @@ ENDCCF
}
$r->print(&Apache::loncommon::end_data_table().
' '."\n".' '."\n".
+ '" />'."\n".' '."\n".
' '."\n".
' '.
&Apache::loncommon::end_page());
@@ -2123,11 +2229,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')) {
@@ -2141,8 +2247,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);
}
@@ -2174,20 +2280,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'}))) {
@@ -2196,18 +2305,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')) {
@@ -2216,42 +2331,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',
@@ -2260,22 +2386,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();
@@ -2286,6 +2421,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'},
@@ -2295,6 +2432,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)) {
@@ -2304,7 +2443,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'},
@@ -2315,17 +2462,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 {
@@ -2334,13 +2489,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) {
@@ -2361,41 +2517,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 => 'is contained in',
- exact => 'as exact match to'
+ contains => 'contains',
+ 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();
@@ -2412,32 +2577,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;
@@ -2449,21 +2623,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.');
}
}
- $response .= ' '.&mt("To add as a new user:").''.&mt("Enter the proposed username in the 'Search for' box").' '.&mt("Set 'Make new user if no match found ' to Yes ").' '.&mt("Click 'Search' ").' '.&mt("Note: you can only create new users in the domain of your current role - [_1]",$env{'request.role.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 ($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 ($state,$response,$forcenewuser);
+ return $output;
}
sub crumb_utilities {
@@ -2479,12 +2668,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();
}
|;
@@ -2555,10 +2751,10 @@ sub course_level_table {
$table .= '   ';
}
$table .= <
+
$lt{'ssd'}
-
+
$lt{'sed'}
ENDTIMEENTRY
@@ -2591,10 +2787,10 @@ ENDTIMEENTRY
'name="sec_'.$customrole.'" />';
}
$table .= <
+
$lt{'ssd'}
-
+
$lt{'sed'}
ENDENTRY
@@ -2686,10 +2882,10 @@ sub course_level_dc {
' '.
' ';
$otheritems .= <
+
$lt{'ssd'}
-
+
$lt{'sed'}
ENDTIMEENTRY