--- loncom/interface/loncreateuser.pm 2009/11/12 16:09:10 1.325
+++ loncom/interface/loncreateuser.pm 2009/12/15 16:40:31 1.330
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.325 2009/11/12 16:09:10 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.330 2009/12/15 16:40:31 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -552,10 +552,10 @@ sub print_username_entry_form {
&mt('View/Modify existing role:').''.
'
'.
''.
'
'.
@@ -935,7 +935,7 @@ sub print_user_modification_page {
);
my $response;
if ($env{'form.origform'} eq 'crtusername') {
- $response = ''.&mt('No match was found for the username ([_1]) in LON-CAPA domain: [_2]',$ccuname,$ccdomain).
+ $response = ''.&mt('No match found for the username [_1] in LON-CAPA domain: [_2]',''.$ccuname.'',$ccdomain).
' ';
}
$response .= '
'
@@ -1028,10 +1028,24 @@ sub print_user_modification_page {
ENDFORMINFO
- my %inccourses;
- foreach my $key (keys(%env)) {
- if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
- $inccourses{$1.'_'.$2}=1;
+ my (%inccourses,$roledom);
+ if ($context eq 'course') {
+ $inccourses{$env{'request.course.id'}}=1;
+ $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ } elsif ($context eq 'author') {
+ $roledom = $env{'request.role.domain'};
+ } elsif ($context eq 'domain') {
+ foreach my $key (keys(%env)) {
+ $roledom = $env{'request.role.domain'};
+ if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
+ $inccourses{$1.'_'.$2}=1;
+ }
+ }
+ } else {
+ foreach my $key (keys(%env)) {
+ if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
+ $inccourses{$1.'_'.$2}=1;
+ }
}
}
if ($newuser) {
@@ -1268,10 +1282,10 @@ ENDNOTOOLSPRIV
}
$r->print('
');
if ($env{'form.action'} ne 'singlestudent') {
- &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses);
+ &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
+ $roledom,$crstype);
}
} ## End of new user/old user logic
-
if ($env{'form.action'} eq 'singlestudent') {
my $btntxt;
if ($crstype eq 'Community') {
@@ -1389,13 +1403,9 @@ sub validation_javascript {
}
sub display_existing_roles {
- my ($r,$ccuname,$ccdomain,$inccourses) = @_;
- my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
- # Build up table of user roles to allow revocation and re-enabling of roles.
- my ($tmp) = keys(%rolesdump);
- if ($tmp !~ /^(con_lost|error)/i) {
- my $now=time;
- my %lt=&Apache::lonlocal::texthash(
+ my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype) = @_;
+ my $now=time;
+ my %lt=&Apache::lonlocal::texthash(
'rer' => "Existing Roles",
'rev' => "Revoke",
'del' => "Delete",
@@ -1405,198 +1415,255 @@ sub display_existing_roles {
'sta' => "Start",
'end' => "End",
);
- my (%roletext,%sortrole,%roleclass,%rolepriv);
- foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
- my $b1=join('_',(split('_',$b))[1,0]);
- return $a1 cmp $b1;
- } keys(%rolesdump)) {
- next if ($area =~ /^rolesdef/);
- my $envkey=$area;
- my $role = $rolesdump{$area};
- my $thisrole=$area;
- $area =~ s/\_\w\w$//;
- my ($role_code,$role_end_time,$role_start_time) =
- split(/_/,$role);
+ my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
+ if ($context eq 'course' || $context eq 'author') {
+ my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
+ my %roleshash =
+ &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
+ ['active','previous','future'],\@roles,$roledom,1);
+ foreach my $key (keys(%roleshash)) {
+ my ($start,$end) = split(':',$roleshash{$key});
+ next if ($start eq '-1' || $end eq '-1');
+ my ($rnum,$rdom,$role,$sec) = split(':',$key);
+ if ($context eq 'course') {
+ next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
+ && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
+ } elsif ($context eq 'author') {
+ next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
+ }
+ my ($newkey,$newvalue,$newrole);
+ $newkey = '/'.$rdom.'/'.$rnum;
+ if ($sec ne '') {
+ $newkey .= '/'.$sec;
+ }
+ $newvalue = $role;
+ if ($role =~ /^cr/) {
+ $newrole = 'cr';
+ } else {
+ $newrole = $role;
+ }
+ $newkey .= '_'.$newrole;
+ if ($start ne '' && $end ne '') {
+ $newvalue .= '_'.$end.'_'.$start;
+ }
+ $rolesdump{$newkey} = $newvalue;
+ }
+ } else {
+ %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
+ }
+ # Build up table of user roles to allow revocation and re-enabling of roles.
+ my ($tmp) = keys(%rolesdump);
+ return if ($tmp =~ /^(con_lost|error)/i);
+ foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
+ my $b1=join('_',(split('_',$b))[1,0]);
+ return $a1 cmp $b1;
+ } keys(%rolesdump)) {
+ next if ($area =~ /^rolesdef/);
+ my $envkey=$area;
+ my $role = $rolesdump{$area};
+ my $thisrole=$area;
+ $area =~ s/\_\w\w$//;
+ my ($role_code,$role_end_time,$role_start_time) =
+ split(/_/,$role);
# Is this a custom role? Get role owner and title.
- my ($croleudom,$croleuname,$croletitle)=
- ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
- my $allowed=0;
- my $delallowed=0;
- my $sortkey=$role_code;
- my $class='Unknown';
- if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
- $class='Course';
- my ($coursedom,$coursedir) = ($1,$2);
- $sortkey.="\0$coursedom";
- # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
- my %coursedata=
- &Apache::lonnet::coursedescription($1.'_'.$2);
- my $carea;
- if (defined($coursedata{'description'})) {
- $carea=$coursedata{'description'}.
- ' '.&mt('Domain').': '.$coursedom.(' 'x8).
- &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
- $sortkey.="\0".$coursedata{'description'};
- $class=$coursedata{'type'};
+ my ($croleudom,$croleuname,$croletitle)=
+ ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
+ my $allowed=0;
+ my $delallowed=0;
+ my $sortkey=$role_code;
+ my $class='Unknown';
+ if ($area =~ m{^/($match_domain)/($match_courseid)} ) {
+ $class='Course';
+ my ($coursedom,$coursedir) = ($1,$2);
+ my $cid = $1.'_'.$2;
+ # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
+ my %coursedata=
+ &Apache::lonnet::coursedescription($cid);
+ if ($coursedir =~ /^$match_community$/) {
+ $class='Community';
+ }
+ $sortkey.="\0$coursedom";
+ my $carea;
+ if (defined($coursedata{'description'})) {
+ $carea=$coursedata{'description'}.
+ ' '.&mt('Domain').': '.$coursedom.(' 'x8).
+ &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
+ $sortkey.="\0".$coursedata{'description'};
+ } else {
+ if ($class eq 'Community') {
+ $carea=&mt('Unavailable community').': '.$area;
+ $sortkey.="\0".&mt('Unavailable community').': '.$area;
} else {
$carea=&mt('Unavailable course').': '.$area;
$sortkey.="\0".&mt('Unavailable course').': '.$area;
}
- $sortkey.="\0$coursedir";
- $inccourses->{$1.'_'.$2}=1;
- if ((&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) ||
- (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
- $allowed=1;
- }
- if ((&Apache::lonnet::allowed('dro',$1)) ||
- (&Apache::lonnet::allowed('dro',$ccdomain))) {
- $delallowed=1;
+ }
+ $sortkey.="\0$coursedir";
+ $inccourses->{$cid}=1;
+ if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
+ (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
+ $allowed=1;
+ }
+ unless ($allowed) {
+ my $isowner = &is_courseowner($cid,$coursedata{'internal.courseowner'});
+ if ($isowner) {
+ if (($role_code eq 'co') && ($class eq 'Community')) {
+ $allowed = 1;
+ } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
+ $allowed = 1;
+ }
}
+ }
+ if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
+ (&Apache::lonnet::allowed('dro',$ccdomain))) {
+ $delallowed=1;
+ }
# - custom role. Needs more info, too
- if ($croletitle) {
- if (&Apache::lonnet::allowed('ccr',$1.'/'.$2)) {
- $allowed=1;
- $thisrole.='.'.$role_code;
- }
+ if ($croletitle) {
+ if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
+ $allowed=1;
+ $thisrole.='.'.$role_code;
}
- # Compute the background color based on $area
- if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
- $carea.=' Section: '.$3;
- $sortkey.="\0$3";
- if (!$allowed) {
- if ($env{'request.course.sec'} eq $3) {
- if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
- $allowed = 1;
- }
+ }
+ if ($area=~m{^/($match_domain)/($match_courseid)/(\w+)}) {
+ $carea.=' Section: '.$3;
+ $sortkey.="\0$3";
+ if (!$allowed) {
+ if ($env{'request.course.sec'} eq $3) {
+ if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2.'/'.$3)) {
+ $allowed = 1;
}
}
}
- $area=$carea;
- } else {
- $sortkey.="\0".$area;
- # Determine if current user is able to revoke privileges
- if ($area=~m{^/($match_domain)/}) {
- if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
- (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
- $allowed=1;
- }
- if (((&Apache::lonnet::allowed('dro',$1)) ||
- (&Apache::lonnet::allowed('dro',$ccdomain))) &&
- ($role_code ne 'dc')) {
- $delallowed=1;
- }
- } else {
- if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
- $allowed=1;
- }
+ }
+ $area=$carea;
+ } else {
+ $sortkey.="\0".$area;
+ # Determine if current user is able to revoke privileges
+ if ($area=~m{^/($match_domain)/}) {
+ if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
+ (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
+ $allowed=1;
}
- if ($role_code eq 'ca' || $role_code eq 'au') {
- $class='Construction Space';
- } elsif ($role_code eq 'su') {
- $class='System';
- } else {
- $class='Domain';
+ if (((&Apache::lonnet::allowed('dro',$1)) ||
+ (&Apache::lonnet::allowed('dro',$ccdomain))) &&
+ ($role_code ne 'dc')) {
+ $delallowed=1;
}
- }
- if (($role_code eq 'ca') || ($role_code eq 'aa')) {
- $area=~m{/($match_domain)/($match_username)};
- if (&Apache::lonuserutils::authorpriv($2,$1)) {
+ } else {
+ if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
$allowed=1;
- } else {
- $allowed=0;
}
}
- my $row = '';
- $row.= '