--- loncom/auth/lonroles.pm 2012/07/21 21:09:03 1.269
+++ loncom/auth/lonroles.pm 2013/01/01 03:45:50 1.269.2.6
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.269 2012/07/21 21:09:03 raeburn Exp $
+# $Id: lonroles.pm,v 1.269.2.6 2013/01/01 03:45:50 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -138,6 +138,7 @@ use Apache::lonlocal;
use Apache::lonpageflip();
use Apache::lonnavdisplay();
use Apache::loncoursequeueadmin;
+use Apache::longroup;
use GDBM_File;
use LONCAPA qw(:DEFAULT :match);
use HTML::Entities;
@@ -149,6 +150,7 @@ sub redirect_user {
&Apache::loncommon::content_type($r,'text/html');
&Apache::loncommon::no_cache($r);
$r->send_http_header;
+ my $swinfo=&Apache::lonmenu::rawconfig();
# Breadcrumbs
my $brcrum = [{'href' => $url,
@@ -163,6 +165,11 @@ sub redirect_user {
$url=~s/ /\%20/g;
$r->print(<
+//
+
$msg
$end_page
ENDREDIR
@@ -211,9 +218,17 @@ sub handler {
$update = $then;
}
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
+
+# -------------------------------------------------- Check if setting hot list
+ my $hotlist;
+ if ($env{'form.action'} eq 'verify_and_change_rolespref') {
+ $hotlist = &Apache::lonpreferences::verify_and_change_rolespref($r);
+ }
+
# -------------------------------------------------------- Check for new roles
my $updateresult;
- if ($env{'form.doupdate'}) {
+ if ($env{'form.state'} eq 'doupdate') {
my $show_course=&Apache::loncommon::show_course();
my $checkingtxt;
if ($show_course) {
@@ -221,16 +236,22 @@ sub handler {
} else {
$checkingtxt = &mt('Checking for new roles ...');
}
- $updateresult = ''.$checkingtxt.' ';
+ $updateresult = $checkingtxt;
$updateresult .= &update_session_roles();
&Apache::lonnet::appenv({'user.update.time' => $now});
$update = $now;
+ &Apache::loncoursequeueadmin::reqauthor_check();
+ }
+
+# -------------------------------------------------- Check for author requests
+ my $reqauthor;
+ if ($env{'form.state'} eq 'requestauthor') {
+ $reqauthor = &Apache::loncoursequeueadmin::process_reqauthor(\$update);
}
my $envkey;
my %dcroles = ();
my $numdc = &check_fordc(\%dcroles,$update,$then);
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
my $loncaparev = $Apache::lonnet::perlvar{'lonVersion'};
# ================================================================== Roles Init
@@ -277,8 +298,10 @@ sub handler {
if (my ($ccrole,$domain,$coursenum) =
($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
if ($dcroles{$domain}) {
- &Apache::lonnet::check_adhoc_privs($domain,$coursenum,
- $update,$refresh,$now,$ccrole);
+ if (&Apache::lonnet::check_adhoc_privs($domain,$coursenum,
+ $update,$refresh,$now,$ccrole)) {
+ &Apache::lonnet::appenv({"environment.internal.$domain.$coursenum.$ccrole.adhoc" => time});
+ }
}
last;
}
@@ -501,6 +524,12 @@ ENDENTERKEY
my $msg;
my ($furl,$ferr)=
&Apache::lonuserstate::readmap($cdom.'/'.$cnum);
+ unless (($ferr) || ($env{'form.switchrole'}) ||
+ ($env{"environment.internal.$cdom.$cnum.$role.adhoc"})) {
+ &Apache::lonnet::put('nohist_crslastlogin',
+ {$env{'user.name'}.':'.$env{'user.domain'}.
+ ':'.$csec.':'.$role => $now},$cdom,$cnum);
+ }
if (($env{'form.orgurl'}) &&
($env{'form.orgurl'}!~/^\/adm\/flip/)) {
my $dest=$env{'form.orgurl'};
@@ -557,11 +586,52 @@ 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'};
- if ($env{'form.destsymb'} ne '') {
- my $esc_symb = &HTML::Entities::encode($env{'form.destsymb'},'"<>&');
- $dest .= '?symb='.$esc_symb;
+ my ($dest,$destsymb,$checkenc);
+ $dest = $env{'form.destinationurl'};
+ $destsymb = $env{'form.destsymb'};
+ if ($dest ne '') {
+ if ($env{'form.switchrole'}) {
+ if ($destsymb ne '') {
+ if ($destsymb !~ m{^/enc/}) {
+ unless ($env{'request.role.adv'}) {
+ $checkenc = 1;
+ }
+ }
+ }
+ if ($dest =~ m{^/enc/}) {
+ if ($env{'request.role.adv'}) {
+ $dest = &Apache::lonenc::unencrypted($dest);
+ if ($destsymb eq '') {
+ ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]*)/);
+ $destsymb = &unescape($destsymb);
+ }
+ }
+ } else {
+ if ($destsymb eq '') {
+ ($destsymb) = ($dest =~ /(?:\?|\&)symb=([^\&]+)/);
+ $destsymb = &unescape($destsymb);
+ }
+ unless ($env{'request.role.adv'}) {
+ $checkenc = 1;
+ }
+ }
+ if (($checkenc) && ($destsymb ne '')) {
+ my ($encstate,$unencsymb,$res);
+ my $unencsymb = &Apache::lonnet::symbclean($destsymb);
+ (undef,undef,$res) = &Apache::lonnet::decode_symb($unencsymb);
+ &Apache::lonnet::symbverify($unencsymb,$res,\$encstate);
+ if ($encstate) {
+ if (($dest ne '') && ($dest !~ m{^/enc/})) {
+ $dest=&Apache::lonenc::encrypted($dest);
+ }
+ }
+ }
+ }
+ unless (($dest =~ m{^/enc/}) || ($dest =~ /(\?|\&)symb=.+___\d+___.+/)) {
+ if (($destsymb ne '') && ($destsymb !~ m{^/enc/})) {
+ my $esc_symb = &escape($destsymb);
+ $dest .= '?symb='.$esc_symb;
+ }
}
&redirect_user($r, &mt('Entering [_1]',
$env{'course.'.$courseid.'.description'}),
@@ -647,15 +717,20 @@ ENDENTERKEY
$recent = &mt('Recent Courses');
}
my $brcrum =[{href=>"/adm/roles",text=>$crumbtext}];
+
+ my %roles_in_env;
+ my $showcount = &roles_from_env(\%roles_in_env,$update);
+
my $swinfo=&Apache::lonmenu::rawconfig();
my $start_page=&Apache::loncommon::start_page($pagetitle,undef,{bread_crumbs=>$brcrum});
+ my $funcs = &get_roles_functions($showcount);
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 be 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(<
+$funcs
$noscript
@@ -678,10 +753,17 @@ function enterrole (thisform,rolecode,bu
}
}
-function setToUpdate(thisform) {
- thisform.doupdate.value='1';
- thisform.selectrole.value='';
- thisform.submit();
+function rolesView (caller) {
+ if ((caller == 'showall') || (caller == 'noshowall')) {
+ document.rolechoice.display.value = caller;
+ } else {
+ if ((caller == 'doupdate') || (caller == 'requestauthor') ||
+ (caller == 'queued')) {
+ document.rolechoice.state.value = caller;
+ }
+ }
+ document.rolechoice.selectrole.value='';
+ document.rolechoice.submit();
}
// ]]>
@@ -750,55 +832,43 @@ ENDHEADER
&Apache::loncommon::end_page());
return OK;
} else {
- $r->print($updateresult);
+ if ($updateresult || $reqauthor || $hotlist) {
+ my $showresult = '';
+ if ($updateresult) {
+ $showresult .= &Apache::lonhtmlcommon::confirm_success($updateresult);
+ }
+ if ($reqauthor) {
+ $showresult .= &Apache::lonhtmlcommon::confirm_success($reqauthor);
+ }
+ if ($hotlist) {
+ $showresult .= $hotlist;
+ }
+ $showresult .= '
';
+ $r->print($showresult);
+ } elsif ($env{'form.state'} eq 'queued') {
+ $r->print(&get_queued());
+ }
if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
$fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
}
+ my $display = ($env{'form.display'} =~ /^(showall)$/);
$r->print('
';
}
} elsif ($currrole_expired) {
- $msg .= '';
+ $msg .= '
';
if (&Apache::loncommon::show_course()) {
$msg .= &mt('Your role in the current course has expired.');
} else {
$msg .= &mt('Your current role has expired.');
}
- $msg .= ' '.&mt('However you can continue to use this role until you logout, click the "Re-Select" button, or your session has been idle for more than 24 hours.').'
';
+ $msg .= ' '.&mt('However you can continue to use this role until you logout, click the "Re-Select" button, or your session has been idle for more than 24 hours.').'';
+ }
+ &Apache::lonnet::set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles);
+ my ($curr_is_adv,$curr_role_adv,$curr_author,$curr_role_author);
+ $curr_author = $env{'user.author'};
+ if (($env{'request.role'} =~/^au/) || ($env{'request.role'} =~/^ca/) ||
+ ($env{'request.role'} =~/^aa/)) {
+ $curr_role_author=1;
+ }
+ $curr_is_adv = $env{'user.adv'};
+ $curr_role_adv = $env{'request.role.adv'};
+ if (keys(%userroles) > 0) {
+ foreach my $role (@changed_roles) {
+ unless(grep(/^\Q$role\E$/,@rolecodes)) {
+ push(@rolecodes,$role);
+ }
+ }
+ unless(grep(/^\Qcm\E$/,@rolecodes)) {
+ push(@rolecodes,'cm');
+ }
+ &Apache::lonnet::appenv(\%userroles,\@rolecodes);
+ }
+ my %newenv;
+ if (&Apache::lonnet::is_advanced_user($env{'user.domain'},$env{'user.name'})) {
+ unless ($curr_is_adv) {
+ $newenv{'user.adv'} = 1;
+ }
+ } elsif ($curr_is_adv && !$curr_role_adv) {
+ &Apache::lonnet::delenv('user.adv');
+ }
+ my %authorroleshash =
+ &Apache::lonnet::get_my_roles('','','userroles',['active'],['au','ca','aa']);
+ if (keys(%authorroleshash)) {
+ unless ($curr_author) {
+ $newenv{'user.author'} = 1;
+ }
+ } elsif ($curr_author && !$curr_role_author) {
+ &Apache::lonnet::delenv('user.author');
+ }
+ if ($env{'request.course.id'}) {
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my (@activecrsgroups,$crsgroupschanged);
+ if ($env{'request.course.groups'}) {
+ @activecrsgroups = split(/:/,$env{'request.course.groups'});
+ foreach my $item (keys(%deletedroles)) {
+ if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
+ if (grep(/^\Q$1\E$/,@activecrsgroups)) {
+ $crsgroupschanged = 1;
+ last;
+ }
+ }
+ }
+ }
+ unless ($crsgroupschanged) {
+ foreach my $item (keys(%newgroup)) {
+ if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
+ if ($newgroup{$item} eq 'active') {
+ $crsgroupschanged = 1;
+ last;
+ }
+ }
+ }
+ }
+ if ((ref($changed_groups{$env{'request.course.id'}}) eq 'HASH') ||
+ (ref($groupchange{"/$cdom/$cnum"}) eq 'HASH') ||
+ ($crsgroupschanged)) {
+ my %grouproles = &Apache::lonnet::get_my_roles('','','userroles',
+ ['active'],['gr'],[$cdom],1);
+ my @activegroups;
+ foreach my $item (keys(%grouproles)) {
+ next unless($item =~ /^\Q$cnum\E:\Q$cdom\E/);
+ my $group;
+ my ($crsn,$crsd,$role,$remainder) = split(/:/,$item,4);
+ if ($remainder =~ /:/) {
+ (my $other,$group) = ($remainder =~ /^([\w:]+):([^:]+)$/);
+ } else {
+ $group = $remainder;
+ }
+ if ($group ne '') {
+ push(@activegroups,$group);
+ }
+ }
+ $newenv{'request.course.groups'} = join(':',@activegroups);
+ }
+ }
+ if (keys(%newenv)) {
+ &Apache::lonnet::appenv(\%newenv);
}
if (!@changed_roles || !(keys(%changed_groups))) {
my ($rolesmsg,$groupsmsg);
@@ -2204,7 +2391,7 @@ sub update_session_roles {
}
$msg .= '';
} else {
- $msg = ' '.$rolesmsg.' ';
+ $msg = ' '.$rolesmsg.' ';
}
return $msg;
}
@@ -2213,11 +2400,42 @@ sub update_session_roles {
if (@changed_roles > 0) {
if (keys(%newgroup) > 0) {
my $groupmsg;
+ my (%curr_groups,%groupdescs,$currcrs);
foreach my $item (sort(keys(%newgroup))) {
if (&is_active_course($item,$refresh,$update,\%roleshash)) {
- $groupmsg .= ''.
- &mt('[_1] with status: [_2].',
- $item,$newgroup{$item}).' ';
+ if ($item =~ m{^gr\./($match_domain/$match_courseid)/(\w+)$}) {
+ my ($cdom,$cnum) = split(/\//,$1);
+ my $group = $2;
+ if ($currcrs ne $cdom.'_'.$cnum) {
+ if ($currcrs) {
+ $groupmsg .= '';
+ }
+ $groupmsg .= ' '.
+ $env{'course.'.$cdom.'_'.$cnum.'.description'}.' ';
+ }
+ my ($cdom,$cnum) = split(/\//,$1);
+ my $group = $2;
+ my $groupdesc;
+ unless (ref($curr_groups{$cdom.'_'.$cnum}) eq 'HASH') {
+ %{$curr_groups{$cdom.'_'.$cnum}} =
+ &Apache::longroup::coursegroups($cdom,$cnum);
+ }
+ unless ((ref($groupdescs{$cdom.'_'.$cnum}) eq 'HASH') &&
+ ($groupdescs{$cdom.'_'.$cnum}{$group})) {
+
+ my %groupinfo =
+ &Apache::longroup::get_group_settings($curr_groups{$cdom.'_'.$cnum}{$group});
+ $groupdescs{$cdom.'_'.$cnum}{$group} =
+ &unescape($groupinfo{'description'});
+ }
+ $groupdesc = $groupdescs{$cdom.'_'.$cnum}{$group};
+ $groupmsg .= ''.
+ &mt('[_1] with status: [_2].',
+ ''.$groupdesc.' ',$newgroup{$item}).' ';
+ }
+ }
+ if ($groupmsg) {
+ $groupmsg .= ' ';
}
}
if ($groupmsg) {
@@ -2230,9 +2448,10 @@ sub update_session_roles {
$changemsg .= ''.&mt('New roles').
'';
foreach my $item (sort(keys(%newrole))) {
+ my $desc = &role_desc($item,$update,$refresh,$now);
$changemsg .= ''.
&mt('[_1] with status: [_2].',
- $item,$newrole{$item}).' ';
+ $desc,$newrole{$item}).' ';
}
$changemsg .= '';
}
@@ -2241,7 +2460,8 @@ sub update_session_roles {
&mt('Custom roles with privilege changes').
'';
foreach my $item (sort(keys(%customprivchg))) {
- $changemsg .= ''.$item.' ';
+ my $desc = &role_desc($item,$update,$refresh,$now);
+ $changemsg .= ''.$desc.' ';
}
$changemsg .= ' ';
}
@@ -2250,8 +2470,9 @@ sub update_session_roles {
&mt('Existing roles with status changes').''.
'';
foreach my $item (sort(keys(%rolechange))) {
+ my $desc = &role_desc($item,$update,$refresh,$now);
$changemsg .= ''.
- &mt('[_1] status now: [_2].',$item,
+ &mt('[_1] status now: [_2].',$desc,
$rolechange{$item}).' ';
}
$changemsg .= ' ';
@@ -2261,7 +2482,8 @@ sub update_session_roles {
&mt('Existing roles now expired').''.
'';
foreach my $item (sort(keys(%deletedroles))) {
- $changemsg .= ''.$item.' ';
+ my $desc = &role_desc($item,$update,$refresh,$now);
+ $changemsg .= ''.$desc.' ';
}
$changemsg .= ' ';
}
@@ -2293,10 +2515,22 @@ sub update_session_roles {
&mt('Existing course/community groups with status changes').''.
'';
foreach my $crs (sort(keys(%groupchange))) {
+ my $cid = $crs;
+ $cid=~s{^/}{};
+ $cid=~s{/}{_};
+ my $crsdesc = $env{'course.'.$cid.'.description'};
+ my $cdom = $env{'course.'.$cid.'.domain'};
+ my $cnum = $env{'course.'.$cid.'.num'};
+ my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
+ my %groupdesc;
if (ref($groupchange{$crs}) eq 'HASH') {
- $groupchgmsg .= ''.&mt('Course/Community: [_1]',''.$crs.' ');
+ $groupchgmsg .= ''.&mt('Course/Community: [_1]',''.$crsdesc.' ');
foreach my $group (sort(keys(%{$groupchange{$crs}}))) {
- $groupchgmsg .= ''.&mt('Group: [_1] status now: [_2].',''.$group.' ',$groupchange{$crs}{$group}).' ';
+ unless ($groupdesc{$group}) {
+ my %groupinfo = &Apache::longroup::get_group_settings($curr_groups{$group});
+ $groupdesc{$group} = &unescape($groupinfo{'description'});
+ }
+ $groupchgmsg .= ''.&mt('Group: [_1] status now: [_2].',''.$groupdesc{$group}.' ',$groupchange{$crs}{$group}).' ';
}
$groupchgmsg .= ' ';
}
@@ -2312,94 +2546,61 @@ sub update_session_roles {
if ($changemsg) {
$msg .= '';
}
- &Apache::lonnet::set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles);
- my ($curr_is_adv,$curr_role_adv,$curr_author,$curr_role_author);
- $curr_author = $env{'user.author'};
- if (($env{'request.role'} =~/^au/) || ($env{'request.role'} =~/^ca/) ||
- ($env{'request.role'} =~/^aa/)) {
- $curr_role_author=1;
- }
- $curr_is_adv = $env{'user.adv'};
- $curr_role_adv = $env{'request.role.adv'};
- if (keys(%userroles) > 0) {
- foreach my $role (@changed_roles) {
- unless(grep(/^\Q$role\E$/,@rolecodes)) {
- push(@rolecodes,$role);
- }
- }
- unless(grep(/^\Qcm\E$/,@rolecodes)) {
- push(@rolecodes,'cm');
- }
- &Apache::lonnet::appenv(\%userroles,\@rolecodes);
- }
- my %newenv;
- if (&Apache::lonnet::is_advanced_user($env{'user.domain'},$env{'user.name'})) {
- unless ($curr_is_adv) {
- $newenv{'user.adv'} = 1;
- }
- } elsif ($curr_is_adv && !$curr_role_adv) {
- &Apache::lonnet::delenv('user.adv');
- }
- my %authorroleshash =
- &Apache::lonnet::get_my_roles('','','userroles',['active'],['au','ca','aa']);
- if (keys(%authorroleshash)) {
- unless ($curr_author) {
- $newenv{'user.author'} = 1;
- }
- } elsif ($curr_author && !$curr_role_author) {
- &Apache::lonnet::delenv('user.author');
- }
- if ($env{'request.course.id'}) {
- my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
- my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
- my (@activecrsgroups,$crsgroupschanged);
- if ($env{'request.course.groups'}) {
- @activecrsgroups = split(/:/,$env{'request.course.groups'});
- foreach my $item (keys(%deletedroles)) {
- if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
- if (grep(/^\Q$1\E$/,@activecrsgroups)) {
- $crsgroupschanged = 1;
- last;
- }
- }
+ return $msg;
+}
+
+sub role_desc {
+ my ($item,$update,$refresh,$now) = @_;
+ my ($where,$trolecode,$role,$tstatus,$tend,$tstart,$twhere,
+ $trole,$tremark);
+ &Apache::lonnet::role_status('user.role.'.$item,$update,$refresh, $now,\$role,\$where, \$trolecode,
+ \$tstatus,\$tstart,\$tend);
+ if ($role =~ /^cr\//) {
+ my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$role);
+ $tremark = &mt('Customrole defined by [_1].',$rauthor.':'.$rdomain);
+ }
+ $trole=Apache::lonnet::plaintext($role);
+ my ($tdom,$trest,$tsection)=
+ split(/\//,Apache::lonnet::declutter($where));
+ if (($role eq 'ca') || ($role eq 'aa')) {
+ my $home = &Apache::lonnet::homeserver($trest,$tdom);
+ $home = &Apache::lonnet::hostname($home);
+ $twhere=&mt('User').': '.$trest.' '.&mt('Domain').
+ ': '.$tdom.' '.&mt('Server').': '.$home;
+ } elsif ($role eq 'au') {
+ my $home = &Apache::lonnet::homeserver
+ ($env{'user.name'},$env{'user.domain'});
+ $home = &Apache::lonnet::hostname($home);
+ $twhere=&mt('Domain').': '.$tdom.' '.&mt('Server').
+ ': '.$home;
+ } elsif ($trest) {
+ my $tcourseid=$tdom.'_'.$trest;
+ my $crstype = &Apache::loncommon::course_type($tcourseid);
+ $trole = &Apache::lonnet::plaintext($role,$crstype,$tcourseid);
+ if ($env{'course.'.$tcourseid.'.description'}) {
+ $twhere=$env{'course.'.$tcourseid.'.description'};
+ } else {
+ my %newhash=&Apache::lonnet::coursedescription($tcourseid);
+ if (%newhash) {
+ $twhere=$newhash{'description'};
+ } else {
+ $twhere=&mt('Currently not available');
}
}
- unless ($crsgroupschanged) {
- foreach my $item (keys(%newgroup)) {
- if ($item =~ m{^gr\./\Q$cdom\E/\Q$cnum\E/(\w+)$}) {
- if ($newgroup{$item} eq 'active') {
- $crsgroupschanged = 1;
- last;
- }
- }
- }
+ if ($tsection) {
+ $twhere.= ' '.&mt('Section').': '.$tsection;
}
- if ((ref($changed_groups{$env{'request.course.id'}}) eq 'HASH') ||
- (ref($groupchange{"/$cdom/$cnum"}) eq 'HASH') ||
- ($crsgroupschanged)) {
- my %grouproles = &Apache::lonnet::get_my_roles('','','userroles',
- ['active'],['gr'],[$cdom],1);
- my @activegroups;
- foreach my $item (keys(%grouproles)) {
- next unless($item =~ /^\Q$cnum\E:\Q$cdom\E/);
- my $group;
- my ($crsn,$crsd,$role,$remainder) = split(/:/,$item,4);
- if ($remainder =~ /:/) {
- (my $other,$group) = ($remainder =~ /^([\w:]+):([^:]+)$/);
- } else {
- $group = $remainder;
- }
- if ($group ne '') {
- push(@activegroups,$group);
- }
- }
- $newenv{'request.course.groups'} = join(':',@activegroups);
+ if ($role ne 'st') {
+ $twhere.= ' '.&mt('Domain').': '.$tdom;
}
+ } elsif ($tdom) {
+ $twhere = &mt('Domain').': '.$tdom;
}
- if (keys(%newenv)) {
- &Apache::lonnet::appenv(\%newenv);
+ my $output = "$trole -- $twhere";
+ if ($tremark) {
+ $output .= ' '.$tremark;
}
- return $msg;
+ return $output;
}
sub curr_role_status {
@@ -2461,6 +2662,130 @@ sub is_active_course {
return $is_active;
}
+sub get_roles_functions {
+ my ($rolescount) = @_;
+ my @links;
+ push(@links,["javascript:rolesView('doupdate');",'start-here-22x22',&mt('Check for changes')]);
+ if ($env{'environment.canrequest.author'}) {
+ unless (&Apache::loncoursequeueadmin::is_active_author()) {
+ push(@links,["javascript:rolesView('requestauthor');",'list-add-22x22',&mt('Request author role')]);
+ }
+ }
+ if (($rolescount > 3) || ($env{'environment.recentroles'})) {
+ push(@links,['/adm/preferences?action=changerolespref&returnurl=/adm/roles','role_hotlist-22x22',&mt('Hotlist')]);
+ }
+ if (&Apache::lonmenu::check_for_rcrs()) {
+ push(@links,['/adm/requestcourse','rcrs-22x22',&mt('Request course')]);
+ }
+ if ($env{'form.state'} eq 'queued') {
+ push(@links,["javascript:rolesView('noqueued');",'selfenrl-queue-22x22',&mt('Hide queued')]);
+ } else {
+ push(@links,["javascript:rolesView('queued');",'selfenrl-queue-22x22',&mt('Show queued')]);
+ }
+ if ($env{'user.adv'}) {
+ if ($env{'form.display'} eq 'showall') {
+ push(@links,["javascript:rolesView('noshowall');",'edit-redo-22x22',&mt('Exclude expired roles')]);
+ } else {
+ push(@links,["javascript:rolesView('showall');",'edit-undo-22x22',&mt('Include expired roles')]);
+ }
+ }
+ my $funcs = &Apache::lonhtmlcommon::start_funclist();
+ foreach my $link (@links) {
+ $funcs .= &Apache::lonhtmlcommon::add_item_funclist(
+ '');
+ }
+ $funcs .= &Apache::lonhtmlcommon::end_funclist();
+ return &Apache::loncommon::head_subbox($funcs);
+}
+
+sub get_queued {
+ my ($output,%reqcrs);
+ my ($types,$typenames) = &Apache::loncommon::course_types();
+ my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
+ $env{'user.name'},'^status:');
+ foreach my $key (keys(%statusinfo)) {
+ next unless (($statusinfo{$key} eq 'approval') || ($statusinfo{$key} eq 'pending'));
+ (undef,my($cdom,$cnum)) = split(':',$key);
+ my $requestkey = $cdom.'_'.$cnum;
+ if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
+ my %history = &Apache::lonnet::restore($requestkey,'courserequests',
+ $env{'user.domain'},$env{'user.name'});
+ next if ((exists($history{'status'})) && ($history{'status'} eq 'created'));
+ my $reqtime = $history{'reqtime'};
+ my $lastupdate = $history{'timestamp'};
+ my $showtype = $history{'crstype'};
+ if (defined($typenames->{$history{'crstype'}})) {
+ $showtype = $typenames->{$history{'crstype'}};
+ }
+ my $description;
+ if (ref($history{'details'}) eq 'HASH') {
+ $description = $history{details}{'cdescr'};
+ }
+ @{$reqcrs{$reqtime}} = ($description,$showtype);
+ }
+ }
+ my @sortedtimes = sort {$a <=> $b} (keys(%reqcrs));
+ if (@sortedtimes > 0) {
+ $output .= ''.&mt('Course/Community requests').' '.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ '
'.&mt('Date requested').' '.
+ ''.&mt('Course title').' '.
+ ''.&mt('Course type').' ';
+ &Apache::loncommon::end_data_table_header_row();
+ foreach my $reqtime (@sortedtimes) {
+ next unless (ref($reqcrs{$reqtime}) eq 'ARRAY');
+ $output .= &Apache::loncommon::start_data_table_row().
+ ''.&Apache::lonlocal::locallocaltime($reqtime).' '.
+ ''.join(' ',@{$reqcrs{$reqtime}}).' '.
+ &Apache::loncommon::end_data_table_row();
+ }
+ $output .= &Apache::loncommon::end_data_table().
+ ' ';
+ }
+ my $queuedselfenroll = &Apache::loncoursequeueadmin::queued_selfenrollment(1);
+ if ($queuedselfenroll) {
+ $output .= ''.&mt('Enrollment requests').' '.
+ $queuedselfenroll.'
';
+ }
+ if ($env{'environment.canrequest.author'}) {
+ unless (&Apache::loncoursequeueadmin::is_active_author()) {
+ my $requestauthor;
+ my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});
+ if (($status eq 'approval') || ($status eq 'approved')) {
+ $output .= ''.&mt('Author role request').' ';
+ if ($status eq 'approval') {
+ $output .= &mt('A request for authoring space submitted on [_1] is awaiting approval',
+ &Apache::lonlocal::locallocaltime($timestamp));
+ } elsif ($status eq 'approved') {
+ my %roleshash =
+ &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
+ ['active'],['au'],[$env{'user.domain'}]);
+ if (keys(%roleshash)) {
+ $output .= ''.
+ &mt('Your request for an author role has been approved.').' '.
+ &mt('Use the "Check for changes" link to update your list of roles.').
+ ' ';
+ }
+ }
+ $output .= '
';
+ }
+ }
+ }
+ unless ($output) {
+ if ($env{'environment.canrequest.author'} || $env{'environment.canrequest.official'} ||
+ $env{'environment.canrequest.unofficial'} || $env{'environment.canrequest.community'}) {
+ $output = &mt('No requests for courses, communities or authoring currently queued');
+ } else {
+ $output = &mt('No enrollment requests currently queued awaiting approval');
+ }
+ }
+ return '
'.&mt('Queued requests').' '.
+ $output.' ';
+}
+
1;
__END__