--- loncom/interface/loncreateuser.pm 2007/07/20 23:55:12 1.158
+++ loncom/interface/loncreateuser.pm 2007/07/30 00:31:27 1.162
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.158 2007/07/20 23:55:12 albertel Exp $
+# $Id: loncreateuser.pm,v 1.162 2007/07/30 00:31:27 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -193,46 +193,62 @@ END_SCRIPT
# =================================================================== Phase one
sub print_username_entry_form {
- my ($r) = @_;
+ my ($r,$response,$srch,$forcenewuser) = @_;
my $defdom=$env{'request.role.domain'};
- my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
- my $selscript=&Apache::loncommon::studentbrowser_javascript();
+ my $formtoset = 'crtuser';
+ if (exists($env{'form.startrolename'})) {
+ $formtoset = 'docustom';
+ $env{'form.rolename'} = $env{'form.startrolename'};
+ }
+
+ my ($jsback,$elements) = &crumb_utilities();
+
+ my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
+ ''."\n";
+
+ my %loaditems = (
+ 'onload' => "javascript:setFormElements(document.$formtoset)",
+ );
my $start_page =
&Apache::loncommon::start_page('Create Users, Change User Privileges',
- $selscript);
+ $jscript,{'add_entries' => \%loaditems,});
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.crtuser)",
+ text=>"User/custom role search",
+ faq=>282,bug=>'Instructor Interface',});
- my $sellink=&Apache::loncommon::selectstudent_link
- ('crtuser','ccuname','ccdomain');
+ my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management');
my %existingroles=&my_custom_roles();
my $choice=&Apache::loncommon::select_form('make new role','rolename',
('make new role' => 'Generate new role ...',%existingroles));
my %lt=&Apache::lonlocal::texthash(
- 'siur' => "Set Individual User Roles",
+ 'srch' => "User Search",
+ or => "or",
+ 'siur' => "Set Individual User Roles",
'usr' => "Username",
'dom' => "Domain",
- 'usrr' => "User Roles",
'ecrp' => "Edit Custom Role Privileges",
'nr' => "Name of Role",
- 'cre' => "Custom Role Editor"
+ 'cre' => "Custom Role Editor",
);
my $help = &Apache::loncommon::help_open_menu(undef,undef,282,'Instructor Interface');
my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');
- $r->print(<<"ENDDOCUMENT");
+ my $sellink=&Apache::loncommon::selectstudent_link('crtuser','srchterm','srchdomain');
+ if ($sellink) {
+ $sellink = "$lt{'or'} ".$sellink;
+ }
+ $r->print("
$start_page
-
-ENDDOCUMENT
- if (&Apache::lonnet::allowed('mcr','/')) {
- $r->print(<$lt{'srch'} $sellink
+$response");
+ $r->print(&entry_form($defdom,$srch,$forcenewuser));
+ if (&Apache::lonnet::allowed('mcr','/')) {
+ $r->print(<
$lt{'ecrp'}$helpecpr
@@ -244,6 +260,20 @@ ENDCUSTOM
$r->print(&Apache::loncommon::end_page());
}
+sub entry_form {
+ my ($dom,$srch,$forcenewuser) = @_;
+ my $userpicker =
+ &Apache::loncommon::user_picker($dom,$srch,$forcenewuser);
+ my $srchbutton = &mt('Search');
+ my $output = <<"ENDDOCUMENT";
+
+ENDDOCUMENT
+ return $output;
+}
sub user_modification_js {
my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
@@ -273,16 +303,109 @@ END
}
# =================================================================== Phase two
-sub print_user_modification_page {
- my $r=shift;
- my $ccuname =&LONCAPA::clean_username($env{'form.ccuname'});
- my $ccdomain=&LONCAPA::clean_domain($env{'form.ccdomain'});
+sub print_user_selection_page {
+ my ($r,$response,$srch,$srch_results) = @_;
+ my @fields = ('username','domain','lastname','firstname','permanentemail');
+ my $sortby = $env{'form.sortby'};
+
+ if (!grep(/^\Q$sortby\E$/,@fields)) {
+ $sortby = 'lastname';
+ }
+
+ my ($jsback,$elements) = &crumb_utilities();
+
+ my $jscript = (<
+function pickuser(uname,udom) {
+ document.usersrchform.seluname.value=uname;
+ document.usersrchform.seludom.value=udom;
+ document.usersrchform.phase.value="userpicked";
+ document.usersrchform.submit();
+}
+
+$jsback
+
+ENDSCRIPT
+
+ my %lt=&Apache::lonlocal::texthash(
+ 'srch' => "User Search",
+ '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/custom role search",
+ 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').'
');
+ $r->print('');
+ $r->print($response);
+ $r->print(&Apache::loncommon::end_page());
+}
+
+sub print_user_query_page {
+ my ($r) = @_;
+# 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.
+ return;
+}
+sub print_user_modification_page {
+ my ($r,$ccuname,$ccdomain,$srch,$response) = @_;
unless (($ccuname) && ($ccdomain)) {
&print_username_entry_form($r);
return;
}
-
+ if ($response) {
+ $response = '
'.$response
+ }
my $defdom=$env{'request.role.domain'};
my ($krbdef,$krbdefdom) =
@@ -291,12 +414,10 @@ sub print_user_modification_page {
my %param = ( formname => 'document.cu',
kerb_def_dom => $krbdefdom,
kerb_def_auth => $krbdef
- );
+ );
$loginscript = &Apache::loncommon::authform_header(%param);
$authformkrb = &Apache::loncommon::authform_kerberos(%param);
- $ccuname =&LONCAPA::clean_username($ccuname);
- $ccdomain=&LONCAPA::clean_domain($ccdomain);
my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
my $dc_setcourse_code = '';
my $nondc_setsection_code = '';
@@ -498,9 +619,31 @@ ENDSECCODE
}
my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
$nondc_setsection_code,$groupslist);
+
+ my ($jsback,$elements) = &crumb_utilities();
+
+ $js .= "\n".
+ '';
+
my $start_page =
&Apache::loncommon::start_page('Create Users, Change User Privileges',
$js,{'add_entries' => \%loaditem,});
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.cu)",
+ text=>"User/custom role search",
+ faq=>282,bug=>'Instructor Interface',});
+
+ if ($env{'form.phase'} eq 'userpicked') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.cu,'get_user_info','select')",
+ text=>"Select a user",
+ faq=>282,bug=>'Instructor Interface',});
+ }
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.cu,'$env{'form.phase'}','modify')",
+ text=>"Set user role",
+ faq=>282,bug=>'Instructor Interface',});
+ my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management');
my $forminfo =<<"ENDFORMINFO";
');
$r->print(&Apache::loncommon::end_page());
}
@@ -1596,7 +1818,7 @@ sub build_roles {
# ========================================================== Custom Role Editor
sub custom_role_editor {
- my $r=shift;
+ my ($r) = @_;
my $rolename=$env{'form.rolename'};
if ($rolename eq 'make new role') {
@@ -1662,6 +1884,7 @@ sub custom_role_editor {
}
$full{$priv}=1;
}
+ my ($jsback,$elements) = &crumb_utilities();
my $button_code = "\n";
my $head_script = "\n";
$head_script .= ''."\n";
+ $head_script .= "\n".$jsback."\n".''."\n";
$r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.form1,'','')",
+ text=>"User/custom role search",
+ faq=>282,bug=>'Instructor Interface',},
+ {href=>"javascript:backPage(document.form1,'','')",
+ text=>"Edit custom role",
+ faq=>282,bug=>'Instructor Interface',});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
+
$r->print($body_top);
my %lt=&Apache::lonlocal::texthash(
'prv' => "Privilege",
@@ -1683,7 +1915,7 @@ sub custom_role_editor {
$r->print($button_code);
$r->print('');
$r->print(<
+'.
+ ''."\n".''."\n".
+ ''."\n".
+ ''.
&Apache::loncommon::end_page());
}
# --------------------------------------------------------
@@ -1796,11 +2031,27 @@ sub set_custom_role {
return;
}
- $r->print(&Apache::loncommon::start_page('Save Custom Role').'');
+ my ($jsback,$elements) = &crumb_utilities();
+ my $jscript = '';
+
+ $r->print(&Apache::loncommon::start_page('Save Custom Role'),$jscript);
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:backPage(document.customresult,'','')",
+ text=>"User/custom role search",
+ faq=>282,bug=>'Instructor Interface',},
+ {href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
+ text=>"Edit custom role",
+ faq=>282,bug=>'Instructor Interface',},
+ {href=>"javascript:backPage(document.customresult,'set_custom_roles','')",
+ text=>"Result",
+ faq=>282,bug=>'Instructor Interface',});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
+
my ($rdummy,$roledef)=
&Apache::lonnet::get('roles',["rolesdef_$rolename"]);
# ------------------------------------------------------- Does this role exist?
+ $r->print('');
if (($rdummy ne 'con_lost') && ($roledef ne '')) {
$r->print(&mt('Existing Role').' "');
} else {
@@ -1849,7 +2100,8 @@ sub set_custom_role {
$env{'user.name'},
$rolename));
}
- $r->print('
Create another role, or Create/Modify a user.
');
+ $r->print('Create another role, or Create/Modify a user.
');
$r->print(&Apache::loncommon::end_page());
}
@@ -1871,17 +2123,54 @@ sub handler {
(&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))) {
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
- if (!$env{'form.phase'}) {
- &print_username_entry_form($r);
- }
- if ($env{'form.phase'} eq 'get_user_info') {
- &print_user_modification_page($r);
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+
+ my $phase = $env{'form.phase'};
+ my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
+
+ if (($phase eq 'get_user_info') || ($phase eq 'userpicked')) {
+ my $srch;
+ foreach my $item (@search) {
+ $srch->{$item} = $env{'form.'.$item};
+ }
+ if ($env{'form.phase'} eq 'get_user_info') {
+ my ($state,$response,$forcenewuser,$results) =
+ &user_search_result($srch);
+ print STDERR "Got $state,$response,$forcenewuser\n";
+ if ($state eq 'select') {
+ &print_user_selection_page($r,$response,$srch,$results);
+ } elsif ($state eq 'modify') {
+ my ($ccuname,$ccdomain);
+ if (($srch->{'srchby'} eq 'uname') &&
+ ($srch->{'srchtype'} eq 'exact')) {
+ $ccuname = $srch->{'srchterm'};
+ $ccdomain= $srch->{'srchdomain'};
+ } else {
+ my @matchedunames = keys(%{$results});
+ ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
+ }
+ $ccuname =&LONCAPA::clean_username($ccuname);
+ $ccdomain=&LONCAPA::clean_domain($ccdomain);
+ &print_user_modification_page($r,$ccuname,$ccdomain,$srch,
+ $response);
+ } elsif ($state eq 'query') {
+ &print_user_query_page($r);
+ } else {
+ &print_username_entry_form($r,$response,$srch,$forcenewuser);
+ }
+ } elsif ($env{'form.phase'} eq 'userpicked') {
+ my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
+ my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
+ &print_user_modification_page($r,$ccuname,$ccdomain,$srch);
+ }
} elsif ($env{'form.phase'} eq 'update_user_data') {
&update_user_data($r);
} elsif ($env{'form.phase'} eq 'selected_custom_edit') {
&custom_role_editor($r);
} elsif ($env{'form.phase'} eq 'set_custom_roles') {
&set_custom_role($r);
+ } else {
+ &print_username_entry_form($r);
}
} else {
$env{'user.error.msg'}=
@@ -1889,9 +2178,327 @@ sub handler {
return HTTP_NOT_ACCEPTABLE;
}
return OK;
-}
+}
#-------------------------------------------------- functions for &phase_two
+sub user_search_result {
+ my ($srch) = @_;
+ my @alldomains = sort(&Apache::lonnet::all_domains());
+ my %allhomes;
+ my %inst_matches;
+ my %srch_results;
+ my ($response,$state,$forcenewuser);
+
+ 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)$/) {
+ $response = &mt('Invalid search.');
+ }
+ if ($srch->{'srchterm'} eq '') {
+ $response = &mt('You must enter a search term.');
+ }
+ if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
+ if (($srch->{'srchdomain'} eq '') ||
+ (!(grep/^\Q$srch->{'srchdomain'}\E$/,@alldomains))) {
+ $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
+ }
+ }
+ 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->{'srchin'} eq 'instd') {
+ my $instd_chk = &directorysrch_check($srch);
+ if ($instd_chk ne 'ok') {
+ $response = $instd_chk;
+ }
+ }
+ if ($response ne '') {
+ return ($state,$response);
+ }
+ if ($srch->{'srchby'} eq 'uname') {
+ if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
+ if ($env{'form.forcenew'}) {
+ if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
+ 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.')');
+ } else {
+ $state = 'modify';
+ }
+ } else {
+ $state = '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) =
+ &build_search_response($srch,%srch_results);
+ } else {
+ $state = 'modify';
+ }
+ } else {
+ %srch_results = &Apache::lonnet::usersearch($srch);
+ ($state,$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';
+ } else {
+ ($state,$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) {
+ $srch_results{$user} = '';
+ }
+ }
+ }
+ ($state,$response,$forcenewuser) =
+ &build_search_response($srch,%srch_results);
+ }
+ }
+ }
+ } elsif ($srch->{'srchin'} eq 'alc') {
+ $state = 'query';
+ } elsif ($srch->{'srchin'} eq 'instd') {
+ %srch_results = &Apache::lonnet::inst_directory_query($srch);
+ ($state,$response,$forcenewuser) =
+ &build_search_response($srch,%srch_results);
+ }
+ } else {
+ if ($srch->{'srchin'} eq 'dom') {
+ %srch_results = &Apache::lonnet::usersearch($srch);
+ ($state,$response,$forcenewuser) =
+ &build_search_response($srch,%srch_results);
+ } elsif ($srch->{'srchin'} eq 'crs') {
+ my %courseusers = &get_courseusers();
+ foreach my $user (keys(%courseusers)) {
+ my ($uname,$udom) = split(/:/,$user);
+ my %names = &Apache::loncommon::getnames($uname,$udom);
+ my %emails = &Apache::loncommon::getemails($uname,$udom);
+ if ($srch->{'srchby'} eq 'lastname') {
+ if ((($srch->{'srchtype'} eq 'exact') &&
+ ($names{'lastname'} eq $srch->{'srchterm'})) ||
+ (($srch->{'srchtype'} eq 'contains') &&
+ ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
+ $srch_results{$user} = {firstname => $names{'firstname'},
+ lastname => $names{'lastname'},
+ permanentemail => $emails{'permanentemail'},
+ };
+ }
+ } elsif ($srch->{'srchby'} eq 'lastfirst') {
+ my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
+ if ($srch->{'srchtype'} eq 'exact') {
+ if (($names{'lastname'} eq $srchlast) &&
+ ($names{'firstname'} eq $srchfirst)) {
+ $srch_results{$user} = {firstname => $names{'firstname'},
+ lastname => $names{'lastname'},
+ permanentemail => $emails{'permanentemail'},
+
+ };
+ }
+ } elsif ($srch->{'srchtype'} eq 'contains') {
+ 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'},
+ };
+ }
+ }
+ }
+ }
+ ($state,$response,$forcenewuser) =
+ &build_search_response($srch,%srch_results);
+ } elsif ($srch->{'srchin'} eq 'alc') {
+ $state = 'query';
+ } elsif ($srch->{'srchin'} eq 'instd') {
+ %srch_results = &Apache::lonnet::inst_directory_query($srch);
+ ($state,$response,$forcenewuser) =
+ &build_search_response($srch,%srch_results);
+ }
+ }
+ return ($state,$response,$forcenewuser,\%srch_results);
+}
+
+sub directorysrch_check {
+ my ($srch) = @_;
+ my $can_search = 0;
+ my $response;
+ my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
+ ['directorysrch'],$srch->{'srchdomain'});
+ if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
+ if (!$dom_inst_srch{'directorysrch'}{'available'}) {
+ return &mt('Directory search unavailable in domain: [_1]',$srch->{'srchdomain'});
+ }
+ if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
+ if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
+ return &mt('Directory search in domain: [_1] is only allowed for users with a current role in the domain.',$srch->{'srchdomain'});
+ }
+ my @usertypes = split(/:/,$env{'environment.inststatus'});
+ if (!@usertypes) {
+ push(@usertypes,'default');
+ }
+ if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
+ foreach my $type (@usertypes) {
+ if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
+ $can_search = 1;
+ last;
+ }
+ }
+ }
+ if (!$can_search) {
+ my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
+ my @longtypes;
+ foreach my $item (@usertypes) {
+ 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;
+ }
+ } else {
+ $can_search = 1;
+ }
+ } else {
+ return &mt('Directory search has not been configured for domain: [_1]',$srch->{'srchdomain'});
+ }
+ my %longtext = &Apache::lonlocal::texthash (
+ uname => 'username',
+ lastfirst => 'last name, first name',
+ lastname => 'last name',
+ contains => 'is contained in',
+ exact => 'as exact match to'
+ );
+ 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'}});
+ }
+ } else {
+ return &mt('Directory search in domain: [_1] is not available.', $srch->{'srchdomain'});
+ }
+ }
+ 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'}});
+ }
+ }
+}
+
+
+sub get_courseusers {
+ my %advhash;
+ my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
+ foreach my $role (sort(keys(%coursepersonnel))) {
+ foreach my $user (split(/\,/,$coursepersonnel{$role})) {
+ $advhash{$user} = '';
+ }
+ }
+ my $classlist = &Apache::loncoursedata::get_classlist();
+ my %combined = (%advhash, %{$classlist});
+ return %combined;
+}
+
+sub build_search_response {
+ my ($srch,%srch_results) = @_;
+ my ($state,$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",
+ );
+
+ my %single = (
+ contains => 'A match',
+ exact => 'An exact match',
+ );
+ my %nomatch = (
+ contains => 'No match',
+ exact => 'No exact match',
+ );
+ if (keys(%srch_results) > 1) {
+ $state = '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'});
+ } else {
+ $response = &mt("$nomatch{$srch->{'srchtype'}} found for this $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
+ if ($srch->{'srchin'} ne 'alc') {
+ $forcenewuser = 1;
+ my $cansrchinst = 0;
+ if ($srch->{'srchdomain'}) {
+ my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
+ if (ref($domconfig{'directorysrch'}) eq 'HASH') {
+ if ($domconfig{'directorysrch'}{'available'}) {
+ $cansrchinst = 1;
+ }
+ }
+ }
+ 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.');
+ }
+ }
+ }
+ $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 -".$env{'request.role.domain'}).'
';
+ }
+ }
+ }
+ return ($state,$response,$forcenewuser);
+}
+
+sub crumb_utilities {
+ my %elements = (
+ crtuser => {
+ srchterm => 'text',
+ srchin => 'selectbox',
+ srchby => 'selectbox',
+ srchtype => 'selectbox',
+ srchdomain => 'selectbox',
+ },
+ docustom => {
+ rolename => 'selectbox',
+ newrolename => 'textbox',
+ },
+ );
+
+ my $jsback .= qq|
+function backPage(formname,prevphase,prevstate) {
+ formname.phase.value = prevphase;
+ formname.state.value = prevstate;
+ formname.submit();
+}
+|;
+ return ($jsback,\%elements);
+}
+
sub course_level_table {
my (%inccourses) = @_;
my $table = '';