--- loncom/auth/lonroles.pm 2006/08/31 13:25:18 1.164
+++ loncom/auth/lonroles.pm 2006/12/20 20:46:18 1.175
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.164 2006/08/31 13:25:18 albertel Exp $
+# $Id: lonroles.pm,v 1.175 2006/12/20 20:46:18 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -40,8 +40,9 @@ use Apache::lonhtmlcommon;
use Apache::lonannounce;
use Apache::lonlocal;
use Apache::lonpageflip();
+use Apache::lonnavdisplay();
use GDBM_File;
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
sub redirect_user {
@@ -53,8 +54,8 @@ sub redirect_user {
my $swinfo=&Apache::lonmenu::rawconfig();
my $navwindow;
if ($launch_nav eq 'on') {
- $navwindow.=&Apache::lonnavmaps::launch_win('now',undef,undef,
- ($url =~ m-^/adm/whatsnew-));
+ $navwindow.=&Apache::lonnavdisplay::launch_win('now',undef,undef,
+ ($url =~ m-^/adm/whatsnew-));
} else {
$navwindow.=&Apache::lonnavmaps::close();
}
@@ -125,7 +126,7 @@ sub handler {
if ($numdc > 0) {
foreach my $envkey (keys %env) {
if (my ($domain,$coursenum) =
- ($envkey =~ m-^form\.cc\./(\w+)/(\w+)$-)) {
+ ($envkey =~ m-^form\.cc\./($match_domain)/($match_courseid)$-)) {
if ($dcroles{$domain}) {
&check_privs($domain,$coursenum,$then,$now);
}
@@ -164,7 +165,7 @@ sub handler {
my $authnum=$cnum;
if ($env{'course.'.$cdom.'_'.$cnum.'.keyauth'}) {
($authnum,$authdom)=
- split(/\W/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
+ split(/:/,$env{'course.'.$cdom.'_'.$cnum.'.keyauth'});
}
# check with key authority
unless (&Apache::lonnet::validate_access_key(
@@ -312,7 +313,7 @@ ENDENTERKEY
}
}
# Are we allowed to look at the first resource?
- if (!&Apache::lonnet::allowed('bre',$furl)) {
+ if ($furl !~ m|^/adm/|) {
# Guess not ...
$furl=&Apache::lonpageflip::first_accessible_resource();
}
@@ -406,10 +407,17 @@ ENDHEADER
# --------------------------------------------------------------- Error Header?
if ($error) {
$r->print("
LON-CAPA Access Control ");
- $r->print("Access : ".
- Apache::lonnet::plaintext($priv)."\n");
- $r->print("Resource: ".&Apache::lonenc::check_encrypt($fn)."\n");
- $r->print("Action : $msg\n ");
+ $r->print("");
+ if ($priv ne '') {
+ $r->print("Access : ".&Apache::lonnet::plaintext($priv)."\n");
+ }
+ if ($fn ne '') {
+ $r->print("Resource: ".&Apache::lonenc::check_encrypt($fn)."\n");
+ }
+ if ($msg ne '') {
+ $r->print("Action : $msg\n");
+ }
+ $r->print(" ");
my $url=$fn;
my $last;
if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
@@ -596,7 +604,7 @@ ENDHEADER
}
}
if ($tsection) {
- $twhere.=' '.&mt('Section/Group').': '.$tsection;
+ $twhere.=' '.&mt('Section').': '.$tsection;
}
if ($role ne 'st') { $twhere.=" ".&mt('Domain').":".$tdom; }
} elsif ($tdom) {
@@ -638,14 +646,14 @@ ENDHEADER
# More than one possible role
# ----------------------------------------------------------------------- Table
unless (($advanced) || ($nochoose)) {
- $r->print("".&mt('Select a Course/Group to Enter')." \n");
+ $r->print("".&mt('Select a Course to Enter')." \n");
}
$r->print('');
unless ($nochoose) { $r->print(' '); }
$r->print(''.&mt('User Role').' '.&mt('Extent').
' '.&mt('Start').' '.&mt('End').' '."\n");
my $doheaders=-1;
- foreach my $type ('Domain','Construction Space','Course','Group','Unavailable','System') {
+ foreach my $type ('Domain','Construction Space','Course','Unavailable','System') {
my $haverole=0;
foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
@@ -662,7 +670,8 @@ ENDHEADER
foreach (sort(keys(%recent_roles))) {
if (defined($roletext{'user.role.'.$_})) {
$output.=$roletext{'user.role.'.$_};
- if ($_ =~ m-dc\./(\w+)/- && $dcroles{$1}) {
+ if ($_ =~ m-dc\./($match_domain)/-
+ && $dcroles{$1}) {
$output .= &allcourses_row($1,'recent');
}
} elsif ($numdc > 0) {
@@ -684,12 +693,12 @@ ENDHEADER
$r->print(&coursepick_jscript());
$r->print(&Apache::loncommon::coursebrowser_javascript());
}
- foreach my $type ('Construction Space','Domain','Course','Group','Unavailable','System') {
+ foreach my $type ('Construction Space','Domain','Course','Unavailable','System') {
my $output;
foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
$output.=$roletext{$sortrole{$which}};
- if ($sortrole{$which} =~ m-dc\./(\w+)/-) {
+ if ($sortrole{$which} =~ m-dc\./($match_domain)/-) {
if ($dcroles{$1}) {
$output .= &allcourses_row($1,'');
}
@@ -732,57 +741,7 @@ ENDHEADER
# ------------------------------------------------------------ Privileges Info
if (($advanced) && (($env{'user.error.msg'}) || ($error))) {
$r->print('Current Privileges ');
-
- foreach $envkey (sort keys %env) {
- if ($envkey=~/^user\.priv\.$env{'request.role'}\./) {
- my $where=$envkey;
- $where=~s/^user\.priv\.$env{'request.role'}\.//;
- my $ttype;
- my $twhere;
- my ($tdom,$trest,$tsec)=
- split(/\//,Apache::lonnet::declutter($where));
- if ($trest) {
- if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
- $ttype='Construction Space';
- $twhere='User: '.$trest.', Domain: '.$tdom;
- } else {
- $ttype=
- &Apache::loncommon::course_type($tdom.'_'.$trest);
- $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
- if ($tsec) {
- $twhere.=' (Section: '.$tsec.')';
- }
- }
- } elsif ($tdom) {
- $ttype='Domain';
- $twhere=$tdom;
- } else {
- $ttype='System';
- $twhere='/';
- }
- $r->print("\n".$ttype.': '.$twhere.' ');
- foreach (sort split(/:/,$env{$envkey})) {
- if ($_) {
- my ($prv,$restr)=split(/\&/,$_);
- my $trestr='';
- if ($restr ne 'F') {
- my $i;
- $trestr.=' (';
- for ($i=0;$iprint(''.
- Apache::lonnet::plaintext($prv).$trestr.
- ' ');
- }
- }
- $r->print(' ');
- }
- }
+ $r->print(&privileges_info());
}
$r->print(&Apache::lonnet::getannounce());
if ($advanced) {
@@ -794,6 +753,61 @@ ENDHEADER
return OK;
}
+sub privileges_info {
+ my ($which) = @_;
+ my $output;
+
+ $which ||= $env{'request.role'};
+
+ foreach my $envkey (sort(keys(%env))) {
+ next if ($envkey!~/^user\.priv\.\Q$which\E\.(.*)/);
+
+ my $where=$1;
+ my $ttype;
+ my $twhere;
+ my (undef,$tdom,$trest,$tsec)=split(m{/},$where);
+ if ($trest) {
+ if ($env{'course.'.$tdom.'_'.$trest.'.description'} eq 'ca') {
+ $ttype='Construction Space';
+ $twhere='User: '.$trest.', Domain: '.$tdom;
+ } else {
+ $ttype= &Apache::loncommon::course_type($tdom.'_'.$trest);
+ $twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
+ if ($tsec) {
+ my $sec_type = 'Section';
+ if (exists($env{"user.role.gr.$where"})) {
+ $sec_type = 'Group';
+ }
+ $twhere.=' ('.$sec_type.': '.$tsec.')';
+ }
+ }
+ } elsif ($tdom) {
+ $ttype='Domain';
+ $twhere=$tdom;
+ } else {
+ $ttype='System';
+ $twhere='/';
+ }
+ $output .= "\n".$ttype.': '.$twhere.' '."\n";
+ foreach my $priv (sort(split(/:/,$env{$envkey}))) {
+ next if (!$priv);
+
+ my ($prv,$restr)=split(/\&/,$priv);
+ my $trestr='';
+ if ($restr ne 'F') {
+ $trestr.=' ('.
+ join(', ',
+ map { &Apache::lonnet::plaintext($_) }
+ (split('',$restr))).') ';
+ }
+ $output .= "\n\t".
+ ''.&Apache::lonnet::plaintext($prv).$trestr.' ';
+ }
+ $output .= "\n".' ';
+ }
+ return $output;
+}
+
sub role_status {
my ($rolekey,$then,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_;
my @pwhere = ();
@@ -854,9 +868,10 @@ sub build_roletext {
$roletext.=' ';
}
}
- $tremark.=&Apache::lonannounce::showday(time,1,
- &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
-
+ if ($trolecode !~ m/^(dc|ca|au|aa)\./) {
+ $tremark.=&Apache::lonannounce::showday(time,1,
+ &Apache::lonannounce::readcalendar($tdom.'_'.$trest));
+ }
$roletext.=''.$trole.
' '.$twhere.
' '.$tpstart.
@@ -888,7 +903,7 @@ sub check_fordc {
my $numdc = 0;
if ($env{'user.adv'}) {
foreach my $envkey (sort keys %env) {
- if ($envkey=~/^user\.role\.dc\.\/(\w+)\/$/) {
+ if ($envkey=~/^user\.role\.dc\.\/($match_domain)\/$/) {
my $dcdom = $1;
my $livedc = 1;
my ($tstart,$tend)=split(/\./,$env{$envkey});
@@ -909,7 +924,7 @@ sub courselink {
my $courseform=&Apache::loncommon::selectcourse_link
('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
- $dcdom,$dcdom,undef,$selecttype);
+ $dcdom,$dcdom,undef);
my $hiddenitems = ' '.
' '.
' '.
@@ -985,7 +1000,7 @@ sub display_cc_role {
my $advanced = $env{'user.adv'};
my $tryagain = $env{'form.tryagain'};
unless ($rolekey =~/^error\:/) {
- if ($rolekey =~ m-^user\.role.cc\./(\w+)/(\w+)$-) {
+ if ($rolekey =~ m-^user\.role.cc\./($match_domain)/($match_courseid)$-) {
my $tcourseid = $1.'_'.$2;
my $trolecode = 'cc./'.$1.'/'.$2;
my $twhere;
@@ -1015,13 +1030,11 @@ sub allcourses_row {
my ($dcdom,$rowtype) = @_;
my $output = ''.
' ';
- foreach my $type ('Course','Group') {
- my $selectlink = &courselink($dcdom,$rowtype,$type);
- my $ccrole = &Apache::lonnet::plaintext('cc',$type);
- $output.= ''.$ccrole.' '.
+ my $selectlink = &courselink($dcdom,$rowtype);
+ my $ccrole = &Apache::lonnet::plaintext('cc');
+ $output.= ''.$ccrole.' '.
' '.$selectlink.' '.
' from '.&mt('Domain').' '.$dcdom.' ';
- }
$output .= ' '."\n";
return $output;
}
@@ -1036,7 +1049,9 @@ sub set_privileges {
my $area = '/'.$dcdom.'/'.$pickedcourse;
my $role = 'cc';
my $spec = $role.'.'.$area;
- my %userroles = &Apache::lonnet::set_arearole($role,$area,'','',$dcdom,$env{'user.name'});
+ my %userroles = &Apache::lonnet::set_arearole($role,$area,'','',
+ $env{'user.domain'},
+ $env{'user.name'});
my %ccrole = ();
&Apache::lonnet::standard_roleprivs(\%ccrole,$role,$dcdom,$spec,$pickedcourse,$area);
my ($author,$adv)= &Apache::lonnet::set_userprivs(\%userroles,\%ccrole);