--- loncom/auth/lonroles.pm 2007/11/09 20:56:34 1.181
+++ loncom/auth/lonroles.pm 2008/03/10 23:47:24 1.185
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.181 2007/11/09 20:56:34 albertel Exp $
+# $Id: lonroles.pm,v 1.185 2008/03/10 23:47:24 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -110,6 +110,12 @@ sub handler {
$env{'form.'.$env{'form.newrole'}}=1;
}
if ($env{'request.course.id'}) {
+ # Check if user is CC trying to select a course role
+ if ($env{'form.switchrole'}) {
+ if (!defined($env{'user.role.'.$env{'form.switchrole'}})) {
+ &adhoc_course_role($then);
+ }
+ }
my %temp=('logout_'.$env{'request.course.id'} => time);
&Apache::lonnet::put('email_status',\%temp);
&Apache::lonnet::delenv('user.state.'.$env{'request.course.id'});
@@ -121,14 +127,37 @@ sub handler {
"request.role" => 'cm',
"request.role.adv" => $env{'user.adv'},
"request.role.domain" => $env{'user.domain'});
-
-# Check if user is a DC trying to enter a course and needs privs to be created
+# Check if user is a DC trying to enter a course or author space and needs privs to be created
if ($numdc > 0) {
foreach my $envkey (keys %env) {
+# Is this an ad-hoc CC-role?
if (my ($domain,$coursenum) =
($envkey =~ m-^form\.cc\./($match_domain)/($match_courseid)$-)) {
if ($dcroles{$domain}) {
- &check_privs($domain,$coursenum,$then,$now);
+ &check_privs($domain,$coursenum,$then,$now,'cc');
+ }
+ last;
+ }
+# Is this a recent ad-hoc CA-role?
+ if (my ($domain,$user) =
+ ($envkey =~ m-^form\.ca\./($match_domain)/($match_username)$-)) {
+ if (($dcroles{$domain}) && (&is_author_homeserver($user,$domain))) {
+ &check_privs($domain,$user,$then,$now,'ca');
+ } else {
+ delete($env{$envkey});
+ }
+ last;
+ }
+# Is this a new ad-hoc CA-role?
+ if (my ($domain) =
+ ($envkey =~ m-^form\.adhocca\./($match_domain)$-)) {
+ if ($dcroles{$domain}) {
+ my $user=$env{'form.adhoccauname.'.$domain};
+ if (!$user) { $user=$env{'form.adhoccaunamerecent.'.$domain} };
+ if (($user) && ($user=~/$match_username/) && (&is_author_homeserver($user,$domain))) {
+ &check_privs($domain,$user,$then,$now,'ca');
+ $env{'form.ca./'.$domain.'/'.$user}=1;
+ }
}
last;
}
@@ -295,6 +324,14 @@ ENDENTERKEY
$furl = "/adm/helper/course.initialization.helper";
# Send the user to the course they selected
} elsif ($env{'request.course.id'}) {
+ if ($env{'form.destinationurl'}) {
+ my $dest = $env{'form.destinationurl'};
+ &redirect_user($r,&mt('Entering [_1]',
+ $env{'course.'.$courseid.'.description'}),
+ $dest,$msg,
+ $env{'environment.remotenavmap'});
+ return OK;
+ }
if (&Apache::lonnet::allowed('whn',
$env{'request.course.id'})
|| &Apache::lonnet::allowed('whn',
@@ -365,7 +402,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 $noscript=''.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'
'.&mt('As this is not the case, most functionality in the system will ba unavailable.').'
';
+ my $noscript=''.&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.').'
'.&mt('As this is not the case, most functionality in the system will be unavailable.').'
';
$r->print(< 0) {
unless ($_ =~/^error\:/) {
@@ -697,7 +735,8 @@ ENDHEADER
$output.=$roletext{$sortrole{$which}};
if ($sortrole{$which} =~ m-dc\./($match_domain)/-) {
if ($dcroles{$1}) {
- $output .= &allcourses_row($1,'');
+ $output .= &allcourses_row($1,'').
+ &allcoauthors_row($1,'');
}
}
}
@@ -881,17 +920,31 @@ sub build_roletext {
return $roletext;
}
+sub is_author_homeserver {
+ my ($uname,$udom)=@_;
+ my $home = &Apache::lonnet::homeserver($uname,$udom);
+ my @ids=&Apache::lonnet::current_machine_ids();
+ foreach my $id (@ids) {
+ if ($id eq $home) {
+ if (-e "/home/".$uname."/public_html") {
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
+
sub check_privs {
- my ($cdom,$cnum,$then,$now) = @_;
- my $cckey = 'user.role.cc./'.$cdom.'/'.$cnum;
+ my ($cdom,$cnum,$then,$now,$checkrole) = @_;
+ my $cckey = 'user.role.'.$checkrole.'./'.$cdom.'/'.$cnum;
if ($env{$cckey}) {
my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend,$tfont);
&role_status($cckey,$then,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend);
unless (($tstatus eq 'is') || ($tstatus eq 'will_not')) {
- &set_privileges($cdom,$cnum);
+ &set_privileges($cdom,$cnum,$checkrole);
}
} else {
- &set_privileges($cdom,$cnum);
+ &set_privileges($cdom,$cnum,$checkrole);
}
}
@@ -916,6 +969,69 @@ sub check_fordc {
return $numdc;
}
+sub adhoc_course_role {
+ my ($then) = @_;
+ my ($cdom,$cnum);
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ if (&check_forcc($cdom,$cnum,$then)) {
+ my $setprivs;
+ if (!defined($env{'user.role.'.$env{'form.selectrole'}})) {
+ $setprivs = 1;
+ } else {
+ my ($start,$end) = split(/\./,$env{'user.role.'.$env{'form.selectrole'}});
+ if (($start && ($start>$then || $start == -1)) ||
+ ($end && $end<$then)) {
+ $setprivs = 1;
+ }
+ }
+ if ($setprivs) {
+ if ($env{'form.switchrole'} =~ m-^(in|ta|ep|ad|st|cr)([\w/]*)\./\Q$cdom\E/\Q$cnum\E(/?\w*)$-) {
+ my $role = $1;
+ my $custom_role = $2;
+ my $usec = $3;
+ if ($role eq 'cr') {
+ if ($custom_role =~ m-^$match_domain/$match_courseid/\w+$-) {
+ $role .= $custom_role;
+ } else {
+ return;
+ }
+ }
+ my (%userroles,%newrole,%newgroups);
+ my $area = '/'.$cdom.'/'.$cnum;
+ my $spec = $role.'.'.$area;
+ if ($usec ne '') {
+ $spec .= '/'.$usec;
+ $area .= '/'.$usec;
+ }
+ &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum,$area);
+ &Apache::lonnet::set_userprivs(\%userroles,\%newrole,%newgroups);
+ my $adhocstart = $then-1;
+ $userroles{'user.role.'.$spec} = $adhocstart.'.';
+ &Apache::lonnet::appenv(%userroles);
+ }
+ }
+ }
+ return;
+}
+
+sub check_forcc {
+ my ($cdom,$cnum,$then) = @_;
+ my $is_cc;
+ if ($cdom ne '' && $cnum ne '') {
+ if (&Apache::lonnet::is_course($cdom,$cnum)) {
+ my $envkey = 'user.role.cc./'.$cdom.'/'.$cnum;
+ if (defined($env{$envkey})) {
+ $is_cc = 1;
+ my ($tstart,$tend)=split(/\./,$env{$envkey});
+ if ($tstart && $tstart>$then) { $is_cc = 0; }
+ if ($tend && $tend <$then) { $is_cc = 0; }
+ }
+ }
+ }
+ return $is_cc;
+}
+
sub courselink {
my ($dcdom,$rowtype,$selecttype) = @_;
my $courseform=&Apache::loncommon::selectcourse_link
@@ -930,6 +1046,10 @@ sub courselink {
}
sub coursepick_jscript {
+ my %lt = &Apache::lonlocal::texthash(
+ plsu => "Please use the 'Select Course' link to open a separate pick course window where you may select the course you wish to enter.",
+ youc => 'You can only use this screen to select courses in the current domain.',
+ );
my $verify_script = <<"END";