--- loncom/interface/loncreateuser.pm 2007/08/02 01:02:56 1.166
+++ loncom/interface/loncreateuser.pm 2007/08/10 23:01:51 1.170
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.166 2007/08/02 01:02:56 albertel Exp $
+# $Id: loncreateuser.pm,v 1.170 2007/08/10 23:01:51 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -360,11 +360,13 @@ ENDSCRIPT
$r->print(&Apache::loncommon::end_data_table_header_row());
my @sorted_users = sort {
- lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
+ lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
||
- lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
+ lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
||
lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
+ ||
+ lc($a) cmp lc($b)
} (keys(%$srch_results));
foreach my $user (@sorted_users) {
@@ -1134,7 +1136,7 @@ ENDNOPRIV
'.$lt{'ssd'}.' |
-
+ |
'.$lt{'sed'}.' | '."\n".
&Apache::loncommon::end_data_table_row()."\n".
@@ -1142,10 +1144,10 @@ ENDNOPRIV
' |
'.$lt{'caa'}.' |
'.$cudom.'_'.$cuname.' |
-
+ |
'.$lt{'ssd'}.' |
-
+ |
'.$lt{'sed'}.' | '."\n".
&Apache::loncommon::end_data_table_row()."\n".
@@ -1177,10 +1179,10 @@ ENDNOPRIV
' |
'.$plrole.' |
'.$thisdomain.' |
-
+ |
'.$lt{'ssd'}.' |
-
+ |
'.$lt{'sed'}.' | '.
&Apache::loncommon::end_data_table_row();
@@ -1535,23 +1537,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.': '.
@@ -1562,26 +1561,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,
@@ -1758,6 +1754,30 @@ END
$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_role {
+ 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;
@@ -2237,20 +2257,24 @@ sub user_search_result {
&build_search_response($srch,%srch_results);
}
} else {
- my %courseusers = &get_courseusers();
+ my $courseusers = &get_courseusers();
if ($srch->{'srchtype'} eq 'exact') {
- if (exists($courseusers{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
+ 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)) {
+ 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} = '';
+ $srch_results{$user} =
+ {&Apache::lonnet::get('environment',
+ ['firstname',
+ 'lastname',
+ 'permanentemail'])};
}
}
}
@@ -2272,8 +2296,8 @@ sub user_search_result {
($state,$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);
@@ -2364,11 +2388,11 @@ sub directorysrch_check {
return &mt('Directory search has not been configured for domain: [_1]',$srch->{'srchdomain'});
}
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 => 'is contained in',
+ exact => 'as exact match to'
);
if ($can_search) {
if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
@@ -2392,15 +2416,16 @@ sub directorysrch_check {
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 {
@@ -2452,7 +2477,6 @@ sub build_search_response {
}
}
}
- $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'}).'
';
}
}
}
@@ -2463,7 +2487,7 @@ sub crumb_utilities {
my %elements = (
crtuser => {
srchterm => 'text',
- srchin => 'selectbox',
+ srchin => 'radio',
srchby => 'selectbox',
srchtype => 'selectbox',
srchdomain => 'selectbox',
@@ -2548,10 +2572,10 @@ sub course_level_table {
$table .= '  | ';
}
$table .= <
+
$lt{'ssd'} |
-
+ |
$lt{'sed'} |
ENDTIMEENTRY
@@ -2584,10 +2608,10 @@ ENDTIMEENTRY
'name="sec_'.$customrole.'" />';
}
$table .= <
+
$lt{'ssd'} |
-
+ |
$lt{'sed'} |
ENDENTRY
@@ -2679,10 +2703,10 @@ sub course_level_dc {
''.
'';
$otheritems .= <
+
$lt{'ssd'} |
-
+ |
$lt{'sed'} |
ENDTIMEENTRY