$lt{'usr'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"
-ENDMODIFYUSERHEAD
if (! $amode || ! $genpwd) {
- $r->print($error.'Invalid login mode or password'.$end);
+ $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
return;
}
# Only allow authentification modification if the person has authority
@@ -1455,7 +1574,7 @@ ENDMODIFYUSERHEAD
($env{'form.ccuname'},$env{'form.ccdomain'}));
} else {
# Okay, this is a non-fatal error.
- $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.');
+ $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);
}
}
##
@@ -1463,22 +1582,53 @@ ENDMODIFYUSERHEAD
# Check for need to change
my %userenv = &Apache::lonnet::get
('environment',['firstname','middlename','lastname','generation',
- 'permanentemail','portfolioquota','inststatus'],
+ 'id','permanentemail','portfolioquota','inststatus'],
$env{'form.ccdomain'},$env{'form.ccuname'});
my ($tmp) = keys(%userenv);
if ($tmp =~ /^(con_lost|error)/i) {
%userenv = ();
}
# Check to see if we need to change user information
- foreach my $item ('firstname','middlename','lastname','generation','permanentemail') {
+ foreach my $item ('firstname','middlename','lastname','generation','permanentemail','id') {
# Strip leading and trailing whitespace
- $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
+ $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
+ }
+ # Check to see if we can change the ID/student number
+ my $forceid = $env{'form.forceid'};
+ my $recurseid = $env{'form.recurseid'};
+ my $newuser = 0;
+ my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
+ my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
+ $env{'form.ccuname'});
+ if (($uidhash{$env{'form.ccuname'}}) &&
+ ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
+ (!$forceid)) {
+ if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
+ $env{'form.cid'} = $userenv{'id'};
+ }
+ }
+ if ($env{'form.cid'} ne $userenv{'id'}) {
+ my $checkhash;
+ my $checks = { 'id' => 1 };
+ $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
+ { 'newuser' => $newuser,
+ 'id' => $env{'form.cid'},
+ };
+ &Apache::loncommon::user_rule_check($checkhash,$checks,
+ \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
+ if (ref($alerts{'id'}) eq 'HASH') {
+ if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
+ $env{'form.cid'} = $userenv{'id'};
+ }
+ }
}
my ($quotachanged,$namechanged,$oldportfolioquota,$newportfolioquota,
- $inststatus,$isdefault,$defquotatext);
+ $inststatus,$oldisdefault,$newisdefault,$olddefquotatext,
+ $newdefquotatext);
my ($defquota,$settingstatus) =
&Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
my %changeHash;
+ $changeHash{'portfolioquota'} = $userenv{'portfolioquota'};
if ($userenv{'portfolioquota'} ne '') {
$oldportfolioquota = $userenv{'portfolioquota'};
if ($env{'form.customquota'} == 1) {
@@ -1488,15 +1638,16 @@ ENDMODIFYUSERHEAD
$newportfolioquota = $env{'form.portfolioquota'};
$newportfolioquota =~ s/[^\d\.]//g;
}
- if ($newportfolioquota != $userenv{'portfolioquota'}) {
+ if ($newportfolioquota != $oldportfolioquota) {
$quotachanged = "a_admin($newportfolioquota,\%changeHash);
}
} else {
$quotachanged = "a_admin('',\%changeHash);
$newportfolioquota = $defquota;
- $isdefault = 1;
+ $newisdefault = 1;
}
} else {
+ $oldisdefault = 1;
$oldportfolioquota = $defquota;
if ($env{'form.customquota'} == 1) {
if ($env{'form.portfolioquota'} eq '') {
@@ -1508,41 +1659,48 @@ ENDMODIFYUSERHEAD
$quotachanged = "a_admin($newportfolioquota,\%changeHash);
} else {
$newportfolioquota = $defquota;
- $isdefault = 1;
+ $newisdefault = 1;
}
}
- if ($isdefault) {
- if ($settingstatus eq '') {
- $defquotatext = &mt('(default)');
- } else {
- my ($usertypes,$order) =
- &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
- if ($usertypes->{$settingstatus} eq '') {
- $defquotatext = &mt('(default)');
- } else {
- $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
- }
- }
+ if ($oldisdefault) {
+ $olddefquotatext = &get_defaultquota_text($settingstatus);
+ }
+ if ($newisdefault) {
+ $newdefquotatext = &get_defaultquota_text($settingstatus);
}
if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) &&
($env{'form.cfirstname'} ne $userenv{'firstname'} ||
$env{'form.cmiddlename'} ne $userenv{'middlename'} ||
$env{'form.clastname'} ne $userenv{'lastname'} ||
$env{'form.cgeneration'} ne $userenv{'generation'} ||
+ $env{'form.cid'} ne $userenv{'id'} ||
$env{'form.cpermanentemail'} ne $userenv{'permanentemail'} )) {
$namechanged = 1;
}
- if ($namechanged) {
- # Make the change
+ if ($namechanged || $quotachanged) {
$changeHash{'firstname'} = $env{'form.cfirstname'};
$changeHash{'middlename'} = $env{'form.cmiddlename'};
$changeHash{'lastname'} = $env{'form.clastname'};
$changeHash{'generation'} = $env{'form.cgeneration'};
- $changeHash{'permanentemail'} = $env{'form.permanentemail'};
- my $putresult = &Apache::lonnet::put
- ('environment',\%changeHash,
- $env{'form.ccdomain'},$env{'form.ccuname'});
- if ($putresult eq 'ok') {
+ $changeHash{'id'} = $env{'form.cid'};
+ $changeHash{'permanentemail'} = $env{'form.cpermanentemail'};
+ my ($quotachgresult,$namechgresult);
+ if ($quotachanged) {
+ $quotachgresult =
+ &Apache::lonnet::put('environment',\%changeHash,
+ $env{'form.ccdomain'},$env{'form.ccuname'});
+ }
+ if ($namechanged) {
+ # Make the change
+ $namechgresult =
+ &Apache::lonnet::modifyuser($env{'form.ccdomain'},
+ $env{'form.ccuname'},$changeHash{'id'},undef,undef,
+ $changeHash{'firstname'},$changeHash{'middlename'},
+ $changeHash{'lastname'},$changeHash{'generation'},
+ $changeHash{'id'},undef,$changeHash{'permanentemail'});
+ }
+ if (($namechanged && $namechgresult eq 'ok') ||
+ ($quotachanged && $quotachgresult eq 'ok')) {
# Tell the user we changed the name
my %lt=&Apache::lonlocal::texthash(
'uic' => "User Information Changed",
@@ -1550,37 +1708,70 @@ ENDMODIFYUSERHEAD
'mddl' => "middle",
'lst' => "last",
'gen' => "generation",
+ 'id' => "ID/Student number",
'mail' => "permanent e-mail",
'disk' => "disk space allocated to portfolio files",
'prvs' => "Previous",
'chto' => "Changed To"
);
+ $r->print(''.$lt{'uic'}.'
'.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row());
$r->print(<<"END");
-
-$lt{'uic'}
- |
+ |
$lt{'frst'} |
$lt{'mddl'} |
$lt{'lst'} |
$lt{'gen'} |
- $lt{'disk'} | |
-$lt{'prvs'} |
+ $lt{'id'} |
+ $lt{'mail'} |
+ $lt{'disk'} |
+END
+ $r->print(&Apache::loncommon::end_data_table_header_row().
+ &Apache::loncommon::start_data_table_row());
+ $r->print(<<"END");
+ $lt{'prvs'} |
$userenv{'firstname'} |
$userenv{'middlename'} |
$userenv{'lastname'} |
$userenv{'generation'} |
+ $userenv{'id'} |
$userenv{'permanentemail'} |
- $oldportfolioquota Mb |
-
-$lt{'chto'} |
+ $oldportfolioquota Mb $olddefquotatext |
+END
+ $r->print(&Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::start_data_table_row());
+ $r->print(<<"END");
+ $lt{'chto'} |
$env{'form.cfirstname'} |
$env{'form.cmiddlename'} |
$env{'form.clastname'} |
$env{'form.cgeneration'} |
+ $env{'form.cid'} |
$env{'form.cpermanentemail'} |
- $newportfolioquota Mb $defquotatext |
-
+ $newportfolioquota Mb $newdefquotatext |
END
+ $r->print(&Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::end_data_table());
+ if ($env{'form.cid'} ne $userenv{'id'}) {
+ &Apache::lonnet::idput($env{'form.ccdomain'},
+ ($env{'form.ccuname'} => $env{'form.cid'}));
+ if (($recurseid) &&
+ (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
+ my %userupdate = (
+ lastname => $env{'form.clasaname'},
+ middlename => $env{'form.cmiddlename'},
+ firstname => $env{'form.cfirstname'},
+ generation => $env{'fora.cgeneration'},
+ id => $env{'form.cid'},
+ );
+ my $idresult =
+ &Apache::lonuserutils::propagate_id_change(
+ $env{'form.ccuname'},$env{'form.ccdomain'},
+ \%userupdate);
+ $r->print('
'.$idresult.'
');
+ }
+ }
if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
($env{'form.ccuname'} eq $env{'user.name'})) {
my %newenvhash;
@@ -1590,67 +1781,56 @@ 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;
- if ($quotachanged) {
- $putresult = &Apache::lonnet::put
- ('environment',\%changeHash,
- $env{'form.ccdomain'},$env{'form.ccuname'});
- }
- # They did not want to change the users name but we can
- # still tell them what the name is
+ # They did not want to change the users name or quota but we can
+ # still tell them what the name and quota are
my %lt=&Apache::lonlocal::texthash(
- 'usr' => "User",
- 'id' => "in domain",
- 'gen' => "Generation",
+ 'id' => "ID/Student number",
'mail' => "Permanent e-mail",
'disk' => "Disk space allocated to user's portfolio files",
);
$r->print(<<"END");
-$lt{'usr'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"
-$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'}
-$lt{'gen'}: $userenv{'generation'}
-$lt{'mail'}: $userenv{'permanentemail'}
+$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
END
- if ($putresult eq 'ok') {
- if ($oldportfolioquota != $newportfolioquota) {
- $r->print(''.$lt{'disk'}.': '.$newportfolioquota.' Mb '.
- $defquotatext.'
');
- &Apache::lonnet::appenv('environment.portfolioquota' => $changeHash{'portfolioquota'});
- }
+ if ($userenv{'permanentemail'} ne '') {
+ $r->print('
['.$lt{'mail'}.': '.
+ $userenv{'permanentemail'}.']');
}
+ $r->print('
['.$lt{'disk'}.': '.$oldportfolioquota.' Mb '.
+ $olddefquotatext.']
');
}
}
##
my $now=time;
+ my $rolechanges = 0;
$r->print(''.&mt('Modifying Roles').'
');
foreach my $key (keys (%env)) {
next if (! $env{$key});
+ next if ($key eq 'form.action');
# Revoke roles
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 ($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 =
- &Apache::lonnet::cput('classlist',
- { $user => $now },
- $env{'course.'.$cid.'.domain'},
- $env{'course.'.$cid.'.num'});
- $r->print(&mt('Drop from classlist: [_1]',
- ''.$result.'').'
');
+ &Apache::lonuserutils::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.': '.
@@ -1658,34 +1838,35 @@ END
$env{'form.ccuname'},$1,$2,$3,$4).
'
');
}
+ $rolechanges ++;
} 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 ($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 =
- &Apache::lonnet::cput('classlist',
- { $user => $now },
- $env{'course.'.$cid.'.domain'},
- $env{'course.'.$cid.'.num'});
- $r->print(&mt('Drop from classlist: [_1]',
- ''.$result.'').'
');
+ &Apache::lonuserutils::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,
0,1).'
');
}
+ $rolechanges ++;
} elsif ($key=~/^form\.ren/) {
my $udom = $env{'form.ccdomain'};
my $uname = $env{'form.ccuname'};
@@ -1724,6 +1905,7 @@ END
$r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : [_5]',
$rolename,$rnam,$rdom,$url,$result).'
');
}
+ $rolechanges ++;
} elsif ($key=~/^form\.act/) {
my $udom = $env{'form.ccdomain'};
my $uname = $env{'form.ccuname'};
@@ -1827,7 +2009,7 @@ END
}
}
} else {
- $r->print(''.&mt('ERROR').': '.&mt('Unknown command').' '.$key.'
');
+ $r->print(''.&mt('ERROR').': '.&mt('Unknown command').' '.$key.'
');
}
foreach my $key (sort(keys(%disallowed))) {
if (($key eq 'none') || ($key eq 'all')) {
@@ -1837,24 +2019,54 @@ END
}
$r->print(' '.&mt('Please go back and choose a different section name.').'
');
}
+ $rolechanges ++;
}
} # End of foreach (keys(%env))
# Flush the course logs so reverse user roles immediately updated
&Apache::lonnet::flushcourselogs();
- $r->print('Create/Modify Another User
');
- $r->print(''."\n");
+ if (!$rolechanges) {
+ $r->print(&mt('No roles to modify'));
+ }
+ $r->print(&Apache::loncommon::end_page());
+}
+
+sub get_defaultquota_text {
+ my ($settingstatus) = @_;
+ my $defquotatext;
+ if ($settingstatus eq '') {
+ $defquotatext = &mt('(default)');
+ } else {
+ my ($usertypes,$order) =
+ &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
+ if ($usertypes->{$settingstatus} eq '') {
+ $defquotatext = &mt('(default)');
+ } else {
+ $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
+ }
+ }
+ return $defquotatext;
+}
+
+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".
+ ''."\n".
+ '';
+ return $outcome;
}
sub quota_admin {
@@ -1913,7 +2125,7 @@ sub custom_role_editor {
$rolename=~s/[^A-Za-z0-9]//gs;
- if (!$rolename) {
+ if (!$rolename || $env{'form.phase'} eq 'pickrole') {
&print_username_entry_form($r);
return;
}
@@ -1982,8 +2194,8 @@ sub custom_role_editor {
$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",
+ ({href=>"javascript:backPage(document.form1,'pickrole','')",
+ text=>"Pick custom role",
faq=>282,bug=>'Instructor Interface',},
{href=>"javascript:backPage(document.form1,'','')",
text=>"Edit custom role",
@@ -2026,8 +2238,9 @@ ENDCCF
&Apache::loncommon::end_data_table_row());
}
$r->print(&Apache::loncommon::end_data_table().
+ ''.
''."\n".''."\n".
+ '" />'."\n".''."\n".
''."\n".
''.
&Apache::loncommon::end_page());
@@ -2107,23 +2320,19 @@ sub make_button_code {
# ---------------------------------------------------------- Call to definerole
sub set_custom_role {
my ($r) = @_;
-
my $rolename=$env{'form.rolename'};
-
$rolename=~s/[^A-Za-z0-9]//gs;
-
if (!$rolename) {
- &print_username_entry_form($r);
+ &custom_role_editor($r);
return;
}
-
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",
+ ({href=>"javascript:backPage(document.customresult,'pickrole','')",
+ text=>"Pick custom role",
faq=>282,bug=>'Instructor Interface',},
{href=>"javascript:backPage(document.customresult,'selected_custom_edit','')",
text=>"Edit custom role",
@@ -2137,14 +2346,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='';
@@ -2186,7 +2395,7 @@ sub set_custom_role {
$env{'user.name'},
$rolename));
}
- $r->print('Create another role, or Create/Modify a user.
');
$r->print(&Apache::loncommon::end_page());
}
@@ -2194,117 +2403,410 @@ sub set_custom_role {
# ================================================================ Main Handler
sub handler {
my $r = shift;
-
if ($r->header_only) {
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
return OK;
}
+ my $context;
+ if ($env{'request.course.id'}) {
+ $context = 'course';
+ } elsif ($env{'request.role'} =~ /^au\./) {
+ $context = 'construction_space';
+ } else {
+ $context = 'domain';
+ }
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['action','state','callingform','roletype','showrole','bulkaction']);
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ if ($env{'form.action'} ne 'dateselect') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"/adm/createuser",
+ text=>"User Management"});
+ }
+ my ($permission,$allowed) = &get_permission($context);
+ if (!$allowed) {
+ $env{'user.error.msg'}=
+ "/adm/createuser:cst:0:0:Cannot create/modify user data ".
+ "or view user status.";
+ return HTTP_NOT_ACCEPTABLE;
+ }
+
+ &Apache::loncommon::content_type($r,'text/html');
+ $r->send_http_header;
+
+ # Main switch on form.action and form.state, as appropriate
+ if (! exists($env{'form.action'})) {
+ $r->print(&header());
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
+ $r->print(&print_main_menu($permission));
+ $r->print(&Apache::loncommon::end_page());
+ } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
+ $r->print(&header());
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/createuser?action=upload&state=',
+ text=>"Upload Users List"});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Upload Users List',
+ 'User_Management_Upload'));
+ $r->print(''.&Apache::loncommon::end_page());
+ } elsif ($env{'form.action'} eq 'expire' && $permission->{'cusr'}) {
+ $r->print(&header());
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/createuser?action=expire',
+ text=>"Expire User Roles"});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Expire User Roles',
+ 'User_Management_Drops'));
+ if (! exists($env{'form.state'})) {
+ &Apache::lonuserutils::print_expire_menu($r,$context);
+ } elsif ($env{'form.state'} eq 'done') {
+ &Apache::lonuserutils::expire_user_list($r,$context);
+ } else {
+ &Apache::lonuserutils::print_expire_menu($r,$context);
+ }
+ $r->print(&Apache::loncommon::end_page());
+ } elsif ($env{'form.action'} eq 'singleuser' && $permission->{'cusr'}) {
+ my $phase = $env{'form.phase'};
+ my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
+ &Apache::loncreateuser::restore_prev_selections();
+ my $srch;
+ foreach my $item (@search) {
+ $srch->{$item} = $env{'form.'.$item};
+ }
- if ((&Apache::lonnet::allowed('cta',$env{'request.course.id'})) ||
- (&Apache::lonnet::allowed('cin',$env{'request.course.id'})) ||
- (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) ||
- (&Apache::lonnet::allowed('cep',$env{'request.course.id'})) ||
- (&authorpriv($env{'user.name'},$env{'request.role.domain'})) ||
- (&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))) {
- &Apache::loncommon::content_type($r,'text/html');
- $r->send_http_header;
- &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);
- if ($state eq 'select') {
- &print_user_selection_page($r,$response,$srch,$results);
- } elsif ($state eq 'modify') {
- my ($ccuname,$ccdomain);
- if ($srch->{'srchby'} eq 'uname') {
- $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'}=
- "/adm/createuser:mau:0:0:Cannot modify user data";
- return HTTP_NOT_ACCEPTABLE;
- }
- return OK;
+ if (($phase eq 'get_user_info') || ($phase eq 'userpicked')) {
+ if ($env{'form.phase'} eq 'get_user_info') {
+ my ($currstate,$response,$forcenewuser,$results) =
+ &user_search_result($srch);
+ 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')) {
+ $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);
+ if ($env{'form.forcenewuser'}) {
+ $response = '';
+ }
+ &print_user_modification_page($r,$ccuname,$ccdomain,
+ $srch,$response,$context);
+ } elsif ($currstate eq 'query') {
+ &print_user_query_page($r,'createuser');
+ } 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,'',
+ $context);
+ }
+ } elsif ($env{'form.phase'} eq 'update_user_data') {
+ &update_user_data($r);
+ } else {
+ &print_username_entry_form($r,undef,$srch);
+ }
+ } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
+ if ($env{'form.phase'} eq 'set_custom_roles') {
+ &set_custom_role($r);
+ } else {
+ &custom_role_editor($r);
+ }
+ } elsif ($env{'form.action'} eq 'listusers' && $permission->{'view'}) {
+ if ($env{'form.phase'} eq 'bulkchange') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'backPage(document.studentform)',
+ text=>"List Users"});
+ my $setting = $env{'form.roletype'};
+ my $choice = $env{'form.bulkaction'};
+ $r->print(&header());
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
+ 'User_Management_List'));
+ if ($permission->{'cusr'}) {
+ &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
+ }
+ } else {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/createuser?action=listusers',
+ text=>"List Users"});
+ my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
+ my $formname = 'studentform';
+ if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
+ ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
+ &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
+ $formname);
+ $jscript .= &verify_user_display();
+ my $js = &add_script($jscript).$cb_jscript;
+ my $loadcode =
+ &Apache::lonuserutils::course_selector_loadcode($formname);
+ if ($loadcode ne '') {
+ $r->print(&header($js,{'onload' => $loadcode,}));
+ } else {
+ $r->print(&header($js));
+ }
+ } else {
+ $r->print(&header(&add_script(&verify_user_display())));
+ }
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
+ 'User_Management_List'));
+ &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
+ $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
+ $r->print(&Apache::loncommon::end_page());
+ }
+ } elsif ($env{'form.action'} eq 'expire' && $permission->{'cusr'}) {
+ $r->print(&header());
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/createuser?action=drop',
+ text=>"Expire Users"});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Expire User Roles',
+ 'User_Management_Drops'));
+ if (! exists($env{'form.state'})) {
+ &Apache::lonuserutils::print_expire_menu($r,$context);
+ } elsif ($env{'form.state'} eq 'done') {
+ &Apache::lonuserutiles::expire_user_list($r,$context);
+ } else {
+ &print_expire_menu($r,$context);
+ }
+ $r->print(&Apache::loncommon::end_page());
+ } elsif ($env{'form.action'} eq 'dateselect') {
+ if ($permission->{'cusr'}) {
+ $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
+ &Apache::lonuserutils::date_section_selector($context).
+ &Apache::loncommon::end_page());
+ } else {
+ $r->print(&header().
+ ''.&mt('You do not have permission to modify dates or sections for users').''.
+ &Apache::loncommon::end_page());
+ }
+ } else {
+ $r->print(&header());
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
+ $r->print(&print_main_menu($permission));
+ $r->print(&Apache::loncommon::end_page());
+ }
+ return OK;
+}
+
+sub header {
+ my ($jscript,$loaditems,$args) = @_;
+ my $start_page;
+ if (ref($loaditems) eq 'HASH') {
+ $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
+ } else {
+ $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
+ }
+ return $start_page;
+}
+
+sub add_script {
+ my ($js) = @_;
+ return '';
+}
+
+sub verify_user_display {
+ my $output = <<"END";
+
+function display_update() {
+ document.studentform.action.value = 'listusers';
+ document.studentform.phase.value = 'display';
+ document.studentform.submit();
+}
+
+END
+ return $output;
+
+}
+
+###############################################################
+###############################################################
+# Menu Phase One
+sub print_main_menu {
+ my ($permission) = @_;
+ my @menu =
+ (
+ { text => 'Upload a File of Users to Modify/Create Users and/or Add roles',
+ help => 'User_Management_Upload',
+ action => 'upload',
+ permission => $permission->{'cusr'},
+ },
+ { text => 'Create User/Set User Roles for a single user',
+ help => 'User_Management_Single_User',
+ action => 'singleuser',
+ permission => $permission->{'cusr'},
+ },
+ { text => 'Display Lists of Users',
+ help => 'User_Management_List',
+ action => 'listusers',
+ permission => $permission->{'view'},
+ },
+# { text => 'Expire User Roles',
+# help => 'User_Management_Drops',
+# action => 'expire',
+# permission => $permission->{'cusr'},
+# },
+ { text => 'Edit Custom Roles',
+ help => 'Custom_Role_Edit',
+ action => 'custom',
+ permission => $permission->{'custom'},
+ },
+ );
+ my $menu_html = '';
+ foreach my $menu_item (@menu) {
+ next if (! $menu_item->{'permission'});
+ $menu_html.='';
+ $menu_html.='';
+ if (exists($menu_item->{'url'})) {
+ $menu_html.=qq{};
+ } else {
+ $menu_html.=
+ qq{};
+ }
+ $menu_html.= &mt($menu_item->{'text'}).'';
+ if (exists($menu_item->{'help'})) {
+ $menu_html.=
+ &Apache::loncommon::help_open_topic($menu_item->{'help'});
+ }
+ $menu_html.='
';
+ }
+ return $menu_html;
+}
+
+sub get_permission {
+ my ($context) = @_;
+ my %permission;
+ if ($context eq 'course') {
+ if ((&Apache::lonnet::allowed('cta',$env{'request.course.id'})) ||
+ (&Apache::lonnet::allowed('cin',$env{'request.course.id'})) ||
+ (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) ||
+ (&Apache::lonnet::allowed('cep',$env{'request.course.id'})) ||
+ (&Apache::lonnet::allowed('cst',$env{'request.course.id'}))) {
+ $permission{'cusr'} = 1;
+ $permission{'view'} =
+ &Apache::lonnet::allowed('vcl',$env{'request.course.id'});
+
+ }
+ if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
+ $permission{'custom'} = 1;
+ }
+ if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
+ $permission{'view'} = 1;
+ if (!$permission{'view'}) {
+ my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
+ $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
+ if ($permission{'view'}) {
+ $permission{'view_section'} = $env{'request.course.sec'};
+ }
+ }
+ }
+ } elsif ($context eq 'construction_space') {
+ $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
+ $permission{'view'} = $permission{'cusr'};
+ } else {
+ if ((&Apache::lonnet::allowed('cad',$env{'request.role.domain'})) ||
+ (&Apache::lonnet::allowed('cli',$env{'request.role.domain'})) ||
+ (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
+ (&Apache::lonnet::allowed('csc',$env{'request.role.domain'})) ||
+ (&Apache::lonnet::allowed('cdg',$env{'request.role.domain'})) ||
+ (&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))) {
+ $permission{'cusr'} = 1;
+ }
+ if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
+ $permission{'custom'} = 1;
+ }
+ $permission{'view'} = $permission{'cusr'};
+ }
+ my $allowed = 0;
+ foreach my $perm (values(%permission)) {
+ if ($perm) { $allowed=1; last; }
+ }
+ return (\%permission,$allowed);
+}
+
+sub restore_prev_selections {
+ my %saveable_parameters = ('srchby' => 'scalar',
+ 'srchin' => 'scalar',
+ 'srchtype' => 'scalar',
+ );
+ &Apache::loncommon::store_settings('user','user_picker',
+ \%saveable_parameters);
+ &Apache::loncommon::restore_settings('user','user_picker',
+ \%saveable_parameters);
}
#-------------------------------------------------- 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)$/) {
+ 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 '') ||
- (!(grep/^\Q$srch->{'srchdomain'}\E$/,@alldomains))) {
+ ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
$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->{'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')) {
@@ -2313,53 +2815,99 @@ 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') {
- my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
- if ($uhome eq 'no_host') {
- ($state,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ if ($srch->{'srchtype'} eq 'exact') {
+ my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
+ if ($uhome eq 'no_host') {
+ ($currstate,$response,$forcenewuser) =
+ &build_search_response($srch,%srch_results);
+ } else {
+ $currstate = 'modify';
+ }
} else {
- $state = 'modify';
+ %srch_results = &Apache::lonnet::usersearch($srch);
+ ($currstate,$response,$forcenewuser) =
+ &build_search_response($srch,%srch_results);
}
} else {
- my %courseusers = &get_courseusers();
- if (exists($courseusers{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
- $state = 'modify';
+ my $courseusers = &get_courseusers();
+ if ($srch->{'srchtype'} eq 'exact') {
+ if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
+ $currstate = 'modify';
+ } else {
+ ($currstate,$response,$forcenewuser) =
+ &build_search_response($srch,%srch_results);
+ }
} else {
- ($state,$response,$forcenewuser) =
+ foreach my $user (keys(%$courseusers)) {
+ my ($cuname,$cudomain) = split(/:/,$user);
+ if ($cudomain eq $srch->{'srchdomain'}) {
+ 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',
+ 'lastname',
+ 'permanentemail'],
+ $cudomain,$cuname)};
+ }
+ }
+ }
+ ($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();
- foreach my $user (keys(%courseusers)) {
+ 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 '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'},
@@ -2369,6 +2917,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)) {
@@ -2378,7 +2928,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'},
@@ -2389,17 +2947,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 {
@@ -2408,13 +2974,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('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('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) {
@@ -2435,82 +3002,101 @@ 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',
+ uname => 'username',
lastfirst => 'last name, first name',
- lastname => 'last name',
- contains => 'is contained in',
- exact => 'as exact match to'
+ lastname => 'last name',
+ 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();
my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
foreach my $role (sort(keys(%coursepersonnel))) {
foreach my $user (split(/\,/,$coursepersonnel{$role})) {
- $advhash{$user} = '';
+ if (!exists($classlist->{$user})) {
+ $classlist->{$user} = [];
+ }
}
}
- my $classlist = &Apache::loncoursedata::get_classlist();
- my %combined = (%advhash, %{$classlist});
- return %combined;
+ return $classlist;
}
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;
@@ -2522,21 +3108,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 -".$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 ($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 {
@@ -2552,12 +3153,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();
}
|;
@@ -2569,7 +3177,7 @@ sub course_level_table {
my $table = '';
# Custom Roles?
- my %customroles=&my_custom_roles();
+ my %customroles=&Apache::lonuserutils::my_custom_roles();
my %lt=&Apache::lonlocal::texthash(
'exs' => "Existing sections",
'new' => "Define new section",
@@ -2608,7 +3216,9 @@ sub course_level_table {
'.$area.' Domain: '.$domain.' | '."\n";
if ($role ne 'cc') {
if (%sections_count) {
- my $currsec = &course_sections(\%sections_count,$protectedcourse.'_'.$role);
+ my $currsec =
+ &Apache::lonuserutils::course_sections(\%sections_count,
+ $protectedcourse.'_'.$role);
$table .=
''.
'
@@ -2628,10 +3238,10 @@ sub course_level_table {
$table .= '  | ';
}
$table .= <
+
$lt{'ssd'} |
-
+ |
$lt{'sed'} |
ENDTIMEENTRY
@@ -2648,11 +3258,13 @@ ENDTIMEENTRY
'.$plrole.' |
'.$area.' | '."\n";
if (%sections_count) {
- my $currsec = &course_sections(\%sections_count,$customrole);
+ my $currsec =
+ &Apache::lonuserutils::course_sections(\%sections_count,
+ $customrole);
$table.=
- ''.
- ''.$lt{'exs'}.' '.
- $currsec.' | '.
+ ' | ';
$otheritems .= <
+
$lt{'ssd'} |
-
+ |
$lt{'sed'} |
ENDTIMEENTRY
| |