--- loncom/auth/lonroles.pm 2006/10/10 20:16:19 1.166 +++ loncom/auth/lonroles.pm 2007/03/02 23:17:48 1.176 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # User Roles Screen # -# $Id: lonroles.pm,v 1.166 2006/10/10 20:16:19 albertel Exp $ +# $Id: lonroles.pm,v 1.176 2007/03/02 23:17:48 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 { @@ -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', @@ -437,8 +445,8 @@ ENDHEADER } else { if ($advanced) { $r->print(&mt("Your home server is "). - $Apache::lonnet::hostname{&Apache::lonnet::homeserver - ($env{'user.name'},$env{'user.domain'})}. + &Apache::lonnet::hostname(&Apache::lonnet::homeserver + ($env{'user.name'},$env{'user.domain'})). "
\n"); $r->print(&mt( "Author and Co-Author roles are not available on servers other than their respective home servers.")); @@ -538,7 +546,7 @@ ENDHEADER $switchserver='otherserver='.$home.'&role='.$trolecode; } #next if ($home eq 'no_host'); - $home = $Apache::lonnet::hostname{$home}; + $home = &Apache::lonnet::hostname($home); $ttype='Construction Space'; $twhere=&mt('User').': '.$trest.'
'.&mt('Domain'). ': '.$tdom.'
'. @@ -558,7 +566,7 @@ ENDHEADER $switchserver='otherserver='.$home.'&role='.$trolecode; } #next if ($home eq 'no_host'); - $home = $Apache::lonnet::hostname{$home}; + $home = &Apache::lonnet::hostname($home); $ttype='Construction Space'; $twhere=&mt('Domain').': '.$tdom.'
'.&mt('Server'). ': '.$home; @@ -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(''."\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.'

'); - } - } + $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'; + } + return $output; +} + sub role_status { my ($rolekey,$then,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_; my @pwhere = (); @@ -889,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}); @@ -910,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 = ''. ''. ''. @@ -986,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; @@ -1016,13 +1030,11 @@ sub allcourses_row { my ($dcdom,$rowtype) = @_; my $output = ''. ' '."\n"; return $output; } @@ -1037,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); 500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

 '.&mt('User Role').''.&mt('Extent'). ''.&mt('Start').''.&mt('End').'
'; - 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 .= '