--- loncom/auth/lonroles.pm 2006/05/30 12:45:24 1.149
+++ loncom/auth/lonroles.pm 2006/06/26 21:41:09 1.160
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.149 2006/05/30 12:45:24 www Exp $
+# $Id: lonroles.pm,v 1.160 2006/06/26 21:41:09 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -39,8 +39,8 @@ use Apache::loncommon;
use Apache::lonhtmlcommon;
use Apache::lonannounce;
use Apache::lonlocal;
+use Apache::lonpageflip();
use GDBM_File;
-use lib '/home/httpd/lib/perl/';
use LONCAPA;
@@ -77,6 +77,21 @@ ENDREDIR
return;
}
+sub error_page {
+ my ($r,$error,$dest)=@_;
+ &Apache::loncommon::content_type($r,'text/html');
+ &Apache::loncommon::no_cache($r);
+ $r->send_http_header;
+ return OK if $r->header_only;
+ $r->print(&Apache::loncommon::start_page('Problems during Course Initialization').
+ ''.
+ '
'.&mt('The following problems occurred:').
+ $error.
+ '
'.&mt('Continue').''.
+ &Apache::loncommon::end_page());
+}
+
sub handler {
my $r = shift;
@@ -134,8 +149,10 @@ sub handler {
# store role if recent_role list being kept
if ($env{'environment.recentroles'}) {
+ my %frozen_roles =
+ &Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
&Apache::lonhtmlcommon::store_recent('roles',
- $trolecode,' ');
+ $trolecode,' ',$frozen_roles{$trolecode});
}
@@ -232,9 +249,9 @@ ENDENTERKEY
'request.course.sec' => $csec,
'request.course.groups' => $cgrps);
my $tadv=0;
- my $msg=&mt('Entering course ...');
if (($cnum) && ($role ne 'ca') && ($role ne 'aa')) {
+ my $msg;
my ($furl,$ferr)=
&Apache::lonuserstate::readmap($cdom.'/'.$cnum);
if (($env{'form.orgurl'}) &&
@@ -242,52 +259,68 @@ ENDENTERKEY
my $dest=$env{'form.orgurl'};
if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
&Apache::lonnet::appenv('request.role.adv'=>$tadv);
- $r->internal_redirect($dest);
+ if (($ferr) && ($tadv)) {
+ &error_page($r,$ferr,$dest);
+ } else {
+ $r->internal_redirect($dest);
+ }
return OK;
} else {
- unless ($env{'request.course.id'}) {
+ my $type = 'Course/Group';
+ if (!$env{'request.course.id'}) {
+ $type = &Apache::loncommon::course_type();
&Apache::lonnet::appenv(
"request.course.id" => $cdom.'_'.$cnum);
$furl='/adm/roles?tryagain=1';
$msg=
- ''.
- &mt('Could not initialize course at this time.').
- '
'.&mt('Please try again.').'
'.$ferr;
+ ''.
+ &mt('Could not initialize '.lc($type).' at this time.').
+ '
'.&mt('Please try again.').'
'.$ferr;
}
if (&Apache::lonnet::allowed('adv') eq 'F') { $tadv=1; }
&Apache::lonnet::appenv('request.role.adv'=>$tadv);
- # Check to see if the user is a CC entering a course
- # for the first time
- my (undef, undef, $role, $courseid) = split(/\./, $envkey);
- if (substr($courseid, 0, 1) eq '/') {
- $courseid = substr($courseid, 1);
- }
- $courseid =~ s/\//_/;
- if ($role eq 'cc' && $env{'course.' . $courseid .
- '.course.helper.not.run'}) {
- $furl = "/adm/helper/course.initialization.helper";
- # Send the user to the course they selected
- } elsif ($env{'request.course.id'}) {
- if (&Apache::lonnet::allowed('whn',
- $env{'request.course.id'})
- || &Apache::lonnet::allowed('whn',
- $env{'request.course.id'}.'/'
- .$env{'request.course.sec'})
- ) {
- my $startpage = &courseloadpage($courseid);
- unless ($startpage eq 'firstres') {
- $msg = &mt('Entering course ....');
- &redirect_user($r,&mt('New in course'),
- '/adm/whatsnew?refpage=start',$msg,
- $env{'environment.remotenavmap'});
- return OK;
- }
- }
+ if (($ferr) && ($tadv)) {
+ &error_page($r,$ferr,$furl);
+ } else {
+ # Check to see if the user is a CC entering a course
+ # for the first time
+ my (undef, undef, $role, $courseid) = split(/\./, $envkey);
+ if (substr($courseid, 0, 1) eq '/') {
+ $courseid = substr($courseid, 1);
+ }
+ $courseid =~ s/\//_/;
+ if ($role eq 'cc' && $env{'course.' . $courseid .
+ '.course.helper.not.run'}) {
+ $furl = "/adm/helper/course.initialization.helper";
+ # Send the user to the course they selected
+ } elsif ($env{'request.course.id'}) {
+ if (&Apache::lonnet::allowed('whn',
+ $env{'request.course.id'})
+ || &Apache::lonnet::allowed('whn',
+ $env{'request.course.id'}.'/'
+ .$env{'request.course.sec'})
+ ) {
+ my $startpage = &courseloadpage($courseid);
+ unless ($startpage eq 'firstres') {
+ $msg = &mt('Entering '.lc($type).' ....');
+ &redirect_user($r,&mt('New in course'),
+ '/adm/whatsnew?refpage=start',$msg,
+ $env{'environment.remotenavmap'});
+ return OK;
+ }
+ }
+ }
+# Are we allowed to look at the first resource?
+ if (!&Apache::lonnet::allowed('bre',$furl)) {
+# Guess not ...
+ $furl=&Apache::lonpageflip::first_accessible_resource();
+ }
+ $msg = &mt('Entering '.lc($type).' ...');
+ &redirect_user($r,&mt('Entering '.$type),
+ $furl,$msg,
+ $env{'environment.remotenavmap'});
}
- &redirect_user($r,&mt('Entering Course'),
- $furl,$msg,
- $env{'environment.remotenavmap'});
return OK;
}
}
@@ -329,7 +362,7 @@ ENDENTERKEY
my $start_page=&Apache::loncommon::start_page('User Roles');
my $standby=&mt('Role selected. Please stand by.');
$standby=~s/\n/\\n/g;
- my $helptag=''.&Apache::loncommon::help_open_menu('','General Intro','General_Intro','User Roles',1,undef,undef,undef,undef,,&mt("Click here for help")).' |
';
+ my $helptag=''.&Apache::loncommon::help_open_menu('','General Intro','General_Intro','',1,undef,undef,undef,undef,,&mt("Click here for help")).' |
';
$r->print(<
@@ -389,26 +422,16 @@ ENDHEADER
} else {
if ($env{'user.error.msg'}) {
$r->print(
- ''.
- &mt('You need to choose another user role or enter a specific course for this function').'
');
+ ''.
+ &mt('You need to choose another user role or enter a specific course for this function').'
');
}
}
# -------------------------------------------------------- Choice or no choice?
if ($nochoose) {
- if ($advanced) {
- $r->print("".&mt('Assigned User Roles')."
\n");
- } else {
- $r->print("".&mt('Sorry ...')."
\n".
- &mt('This resource might be part of'));
- if ($env{'request.course.id'}) {
- $r->print(&mt(' another'));
- } else {
- $r->print(&mt(' a certain'));
- }
- $r->print(&mt(' course.').
- &Apache::loncommon::end_page());
- return OK;
- }
+ $r->print("".&mt('Sorry ...')."
\n".
+ &mt('This action is currently not authorized.').
+ &Apache::loncommon::end_page());
+ return OK;
} else {
if ($advanced) {
$r->print(&mt("Your home server is ").
@@ -493,10 +516,8 @@ ENDHEADER
if ($tremark) { $tremark.='
'; }
$tremark.=&mt('Defined by ').$rauthor.
&mt(' at ').$rdomain.'.';
- $trole=$rrole;
- } else {
- $trole=Apache::lonnet::plaintext($role);
- }
+ }
+ $trole=Apache::lonnet::plaintext($role);
my $ttype;
my $twhere;
my ($tdom,$trest,$tsection)=
@@ -540,8 +561,9 @@ ENDHEADER
$tremark.=&Apache::lonhtmlcommon::authorbombs('/res/'.$tdom.'/'.$env{'user.name'}.'/');
$sortkey=$role;
} elsif ($trest) {
- $ttype='Course';
my $tcourseid=$tdom.'_'.$trest;
+ $ttype = &Apache::loncommon::course_type($tcourseid);
+ $trole = &Apache::lonnet::plaintext($role,$ttype);
if ($env{'course.'.$tcourseid.'.description'}) {
$twhere=$env{'course.'.$tcourseid.'.description'};
$sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
@@ -559,16 +581,18 @@ ENDHEADER
' '.
&Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$trest,$tdom,$tfont).
'';
+ $ttype = $newhash{'type'};
+ $trole = &Apache::lonnet::plaintext($role,$ttype);
} else {
$twhere=&mt('Currently not available');
$env{'course.'.$tcourseid.'.description'}=$twhere;
$sortkey=$role."\0".$tdom."\0".$twhere."\0".$envkey;
+ $ttype = 'Unavailable';
}
}
if ($tsection) {
$twhere.='
'.&mt('Section/Group').': '.$tsection;
}
-
if ($role ne 'st') { $twhere.="
".&mt('Domain').":".$tdom; }
} elsif ($tdom) {
$ttype='Domain';
@@ -579,8 +603,7 @@ ENDHEADER
$twhere=&mt('system wide');
$sortkey=$role.$twhere;
}
-
- $roletext.=&build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$ttype,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver);
+ $roletext.=&build_roletext($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver);
$roletext{$envkey}=$roletext;
if (!$sortkey) {$sortkey=$twhere."\0".$envkey;}
$sortrole{$sortkey}=$envkey;
@@ -610,14 +633,14 @@ ENDHEADER
# More than one possible role
# ----------------------------------------------------------------------- Table
unless (($advanced) || ($nochoose)) {
- $r->print("".&mt('Select a Course to Enter')."
\n");
+ $r->print("".&mt('Select a Course/Group 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','System') {
+ foreach my $type ('Domain','Construction Space','Course','Group','Unavailable','System') {
my $haverole=0;
foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
@@ -656,7 +679,7 @@ ENDHEADER
$r->print(&coursepick_jscript());
$r->print(&Apache::loncommon::coursebrowser_javascript());
}
- foreach my $type ('Construction Space','Domain','Course','System') {
+ foreach my $type ('Construction Space','Domain','Course','Group','Unavailable','System') {
my $output;
foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
if ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/) {
@@ -718,10 +741,11 @@ ENDHEADER
$ttype='Construction Space';
$twhere='User: '.$trest.', Domain: '.$tdom;
} else {
- $ttype='Course';
+ $ttype=
+ &Apache::loncommon::course_type($tdom.'_'.$trest);
$twhere=$env{'course.'.$tdom.'_'.$trest.'.description'};
if ($tsec) {
- $twhere.=' (Section/Group: '.$tsec.')';
+ $twhere.=' (Section: '.$tsec.')';
}
}
} elsif ($tdom) {
@@ -791,7 +815,7 @@ sub role_status {
}
sub build_roletext {
- my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$ttype,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver) = @_;
+ my ($trolecode,$tdom,$trest,$tstatus,$tryagain,$advanced,$tremark,$tbg,$tfont,$trole,$twhere,$tpstart,$tpend,$nochoose,$button,$switchserver) = @_;
my $roletext='';
my $is_dc=($trolecode =~ m/^dc\./);
my $rowspan=($is_dc) ? ''
@@ -876,9 +900,11 @@ sub check_fordc {
}
sub courselink {
- my ($dcdom,$rowtype) = @_;
+ my ($dcdom,$rowtype,$selecttype) = @_;
my $courseform=&Apache::loncommon::selectcourse_link
- ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.$dcdom,$dcdom);
+ ('rolechoice','dccourse'.$rowtype.'_'.$dcdom,
+ 'dcdomain'.$rowtype.'_'.$dcdom,'coursedesc'.$rowtype.'_'.
+ $dcdom,$dcdom,undef,$selecttype);
my $hiddenitems = ''.
''.
''.
@@ -957,8 +983,8 @@ sub display_cc_role {
if ($rolekey =~ m-^user\.role.cc\./(\w+)/(\w+)$-) {
my $tcourseid = $1.'_'.$2;
my $trolecode = 'cc./'.$1.'/'.$2;
- my $trole = Apache::lonnet::plaintext('cc');
my $twhere;
+ my $ttype;
my $tbg='#77FF77';
my $tfont='#003300';
my %newhash=&Apache::lonnet::coursedescription($tcourseid);
@@ -967,27 +993,31 @@ sub display_cc_role {
' '.
&Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$2,$1,$tfont).
'';
+ $ttype = $newhash{'type'};
} else {
$twhere=&mt('Currently not available');
$env{'course.'.$tcourseid.'.description'}=$twhere;
}
+ my $trole = &Apache::lonnet::plaintext('cc',$ttype);
$twhere.="
".&mt('Domain').":".$1;
- $roletext = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$tfont,$trole,&mt('Course'),$twhere,'','','',1,'');
+ $roletext = &build_roletext($trolecode,$1,$2,'is',$tryagain,$advanced,'',$tbg,$tfont,$trole,$twhere,'','','',1,'');
}
}
- return $roletext;
+ return ($roletext);
}
sub allcourses_row {
my ($dcdom,$rowtype) = @_;
- my $ccrole = Apache::lonnet::plaintext('cc');
- my $selectlink = &courselink($dcdom,$rowtype);
my $output = '
'.
- ''.
- ''.$ccrole.''.
- ' '.$selectlink.''.
- ' from '.&mt('Domain').' '.$dcdom.
- ' |
|
'."\n";
+ ' ';
+ foreach my $type ('Course','Group') {
+ my $selectlink = &courselink($dcdom,$rowtype,$type);
+ my $ccrole = &Apache::lonnet::plaintext('cc',$type);
+ $output.= ''.$ccrole.''.
+ ' '.$selectlink.''.
+ ' from '.&mt('Domain').' '.$dcdom.' ';
+ }
+ $output .= ' | |
'."\n";
return $output;
}
@@ -1001,17 +1031,11 @@ 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,'','',$dcdom,$env{'user.name'});
my %ccrole = ();
&Apache::lonnet::standard_roleprivs(\%ccrole,$role,$dcdom,$spec,$pickedcourse,$area);
- my ($author,$adv)= &Apache::lonnet::set_userprivs(\$userroles,\%ccrole);
- my @newprivs = split/\n/,$userroles;
- my %newccroles = ();
- foreach (@newprivs) {
- my ($key,$val) = split/=/,$_;
- $newccroles{$key} = $val;
- }
- &Apache::lonnet::appenv(%newccroles);
+ my ($author,$adv)= &Apache::lonnet::set_userprivs(\%userroles,\%ccrole);
+ &Apache::lonnet::appenv(%userroles);
&Apache::lonnet::log($env{'user.domain'},
$env{'user.name'},
$env{'user.home'},