--- loncom/auth/lonroles.pm 2011/02/24 23:29:10 1.260
+++ loncom/auth/lonroles.pm 2012/09/25 22:51:43 1.269.2.3
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.260 2011/02/24 23:29:10 raeburn Exp $
+# $Id: lonroles.pm,v 1.269.2.3 2012/09/25 22:51:43 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -149,6 +149,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 +164,11 @@ sub redirect_user {
$url=~s/ /\%20/g;
$r->print(<
+//
+
$msg
$end_page
ENDREDIR
@@ -211,9 +217,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 +235,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
@@ -266,6 +286,7 @@ sub handler {
"request.course.fn" => '',
"request.course.uri" => '',
"request.course.sec" => '',
+ "request.course.tied" => '',
"request.role" => 'cm',
"request.role.adv" => $env{'user.adv'},
"request.role.domain" => $env{'user.domain'}});
@@ -276,8 +297,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;
}
@@ -500,6 +523,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'};
@@ -519,7 +548,8 @@ ENDENTERKEY
if ($dest =~ m{^/adm/coursedocs\?folderpath}) {
if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
- &update_content_constraints($cdom,$cnum,$chome,$cdom.'_'.$cnum);
+ &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,
+ $cdom.'_'.$cnum);
}
}
$r->internal_redirect($dest);
@@ -555,11 +585,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'}),
@@ -601,10 +672,9 @@ ENDENTERKEY
if ($role =~ /^(au|ca|aa)$/) {
my $redirect_url = '/priv/';
if ($role eq 'au') {
- $redirect_url.=$env{'user.name'};
+ $redirect_url.=$env{'user.domain'}.'/'.$env{'user.name'};
} else {
- $where =~ /\/(.*)$/;
- $redirect_url .= $1;
+ $redirect_url .= $where;
}
$redirect_url .= '/';
&redirect_user($r,&mt('Entering Construction Space'),
@@ -646,15 +716,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
@@ -677,10 +752,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();
}
// ]]>
@@ -749,55 +831,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.').'';
}
if (!@changed_roles || !(keys(%changed_groups))) {
- $msg .= '';
+ my ($rolesmsg,$groupsmsg);
if (!@changed_roles) {
- $msg .= '';
if (&Apache::loncommon::show_course()) {
- $msg .= &mt('No new courses or communities');
+ $rolesmsg = &mt('No new courses or communities');
} else {
- $msg .= &mt('No role changes');
+ $rolesmsg = &mt('No role changes');
}
- $msg .= ' ';
}
if ($hasgroups && !(keys(%changed_groups)) && !(grep(/gr/,@changed_roles))) {
- $msg .= ''.&mt('No changes in course/community groups').' ';
+ $groupsmsg = &mt('No changes in course/community groups');
}
- $msg .= ' ';
if (!@changed_roles && !(keys(%changed_groups))) {
+ if (($msg ne '') || ($groupsmsg ne '')) {
+ $msg .= '';
+ if ($rolesmsg) {
+ $msg .= ''.$rolesmsg.' ';
+ }
+ if ($groupsmsg) {
+ $msg .= ''.$groupsmsg.' ';
+ }
+ $msg .= ' ';
+ } else {
+ $msg = ' '.$rolesmsg.' ';
+ }
return $msg;
}
}
@@ -2280,7 +2346,7 @@ sub update_session_roles {
}
if (keys(%deletedroles) > 0) {
$changemsg .= ''.
- &mt('Existing roles deleted').' '.
+ &mt('Existing roles now expired').''.
'';
foreach my $item (sort(keys(%deletedroles))) {
$changemsg .= ''.$item.' ';
@@ -2483,6 +2549,131 @@ sub is_active_course {
return $is_active;
}
+sub get_roles_functions {
+ my ($rolescount) = @_;
+ my @links;
+ 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')]);
+ }
+ }
+ 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 (&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 (($rolescount > 3) || ($env{'environment.recentroles'})) {
+ push(@links,['/adm/preferences?action=changerolespref&returnurl=/adm/roles','role_hotlist-22x22',&mt('Hotlist')]);
+ }
+
+ 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__