--- loncom/interface/loncoursequeueadmin.pm 2012/08/14 15:45:06 1.30
+++ loncom/interface/loncoursequeueadmin.pm 2013/01/04 01:56:35 1.34
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Utilities to administer domain course requests and course self-enroll requests
#
-# $Id: loncoursequeueadmin.pm,v 1.30 2012/08/14 15:45:06 raeburn Exp $
+# $Id: loncoursequeueadmin.pm,v 1.34 2013/01/04 01:56:35 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -70,6 +70,14 @@ described at http://www.lon-capa.org.
=item process_official_reqs()
+=item is_active_author()
+
+=item author_prompt()
+
+=item reqauthor_check()
+
+=item process_reqauthor()
+
=back
=cut
@@ -101,7 +109,7 @@ sub send_selfserve_notification {
} elsif ($context eq 'domainmanagers') {
$rawsubj = 'Course/Community requests reviewed';
push(@rawmsg,{
- mt => 'Course/Community creation requests in the following domain: [_1] have been reviewed.',
+ mt => 'Course/Community creation requests in the following domain: "[_1]" have been reviewed.',
args => ["\n$contextdesc"],
});
if (ref($textstr) eq 'ARRAY') {
@@ -110,7 +118,7 @@ sub send_selfserve_notification {
} elsif ($context eq 'authormanagers') {
$rawsubj = 'Authoring space requests reviewed';
push(@rawmsg,{
- mt => 'Authoring requests in the following domain: [_1] have been reviewed.',
+ mt => 'Authoring requests in the following domain: "[_1]" have been reviewed.',
args => ["\n$contextdesc"],
});
if (ref($textstr) eq 'ARRAY') {
@@ -170,14 +178,14 @@ sub send_selfserve_notification {
},
{
mt =>'[_1]As Domain Coordinator, use: [_2]Main Menu -> Course and community creation -> Approve or reject requests[_3]to display a list of pending requests, which you can either approve or reject.',
- args => ["\n","\n\n ","\n\n"],
+ args => ["\n","\n\n","\n\n"],
});
} elsif ($context eq 'selfenrollreq') {
$rawsubj = 'Self-enrollment request';
if ($crstype eq 'community') {
- $msgtxt = 'Enrollment in the following community: [_1] was requested by [_2] on [_3].'
+ $msgtxt = 'Enrollment in the following community: [_1]was requested by [_2] on [_3].'
} else {
- $msgtxt = 'Enrollment in the following course: [_1] was requested by [_2] on [_3].'
+ $msgtxt = 'Enrollment in the following course: [_1]was requested by [_2] on [_3].'
}
push(@rawmsg,{
mt => $msgtxt,
@@ -196,7 +204,7 @@ sub send_selfserve_notification {
});
} elsif ($context eq 'authorreq') {
$rawsubj = 'Authoring space request to review';
- $msgtxt = 'Assignment of an author role in the [_1] domain[_2] was requested by [_3] on [_4].';
+ $msgtxt = 'Assignment of an author role in the [_1] domain[_2]was requested by [_3] on [_4].';
push(@rawmsg,{
mt => $msgtxt,
args => [$contextdesc,"\n",$textstr,$timestamp],
@@ -528,12 +536,12 @@ sub update_request_queue {
$firsturl);
my $count=0;
while (my @course = &Apache::loncommon::get_env_multiple('form.'.$count.'radioreq')) {
- if (@course[0] =~ /^\d+:.*/) {
- push(@approvals,@course[0]);
- } elsif (@course[0] =~ /^later:.*/) {
+ if ($course[0] =~ /^\d+:.*/) {
+ push(@approvals,$course[0]);
+ } elsif ($course[0] =~ /^later:.*/) {
#decide later
} else {
- push(@rejections,@course[0]);
+ push(@rejections,$course[0]);
}
$count+=1;
}
@@ -1462,7 +1470,7 @@ sub get_processtype {
} else {
my %alltasks;
if (($isadv) && ($settings{'_LC_adv'} ne '')) {
- $val = $settings{$crstype}{'_LC_adv'};
+ $val = $settings{'_LC_adv'};
@{$inststatuses} = ('_LC_adv_');
} else {
if ($userenv{'inststatus'} ne '') {
@@ -1548,7 +1556,7 @@ sub queued_selfenrollment {
}
if (keys(%reqs_by_date)) {
unless ($notitle) {
- $output .= ''.&mt('Enrollment requests pending Course Coordinator approval').'
';
+ $output .= '
'.&mt('Enrollment requests pending Course Coordinator approval').'
';
}
$output .= &Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_header_row().
@@ -1781,6 +1789,142 @@ sub process_official_reqs {
}
}
return $output;
+}
+
+sub is_active_author {
+ if ($env{'user.role.au./'.$env{'user.domain'}.'/'} =~ /^(\d*)\.(\d*)$/) {
+ if ((!$1 || $1 < time) &&
+ (!$2 || $2 > time)) {
+ return 1;
+ }
+ }
+}
+
+sub author_prompt {
+ my ($is_active_author,$offer_author);
+ if ($env{'environment.canrequest.author'}) {
+ unless (&is_active_author()) {
+ unless (&reqauthor_check() =~ /^approval:\d+$/) {
+ $offer_author = 1;
+ }
+ }
+ }
+ return $offer_author;
+}
+
+sub reqauthor_check {
+ my $queued = $env{'environment.requestauthorqueued'};
+ my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
+ $env{'user.domain'},$env{'user.name'});
+ my $reqstatus = $reqauthor{'author_status'};
+ if (($reqstatus eq '' && $queued ne '') ||
+ ($env{'environment.requestauthorqueued'} !~ /^\Q$reqstatus\E/)) {
+ if (ref($reqauthor{'author'}) eq 'HASH') {
+ $queued = $reqstatus.':'.$reqauthor{'author'}{'timestamp'};
+ } else {
+ undef($queued);
+ }
+ &Apache::lonnet::appenv({'environment.requestauthorqueued' => $queued});
+ }
+ return $queued;
+}
+
+sub process_reqauthor {
+ my ($dispositionref,$updateref) = @_;
+ if (&is_active_author()) {
+ return ''.
+ &mt('An authoring space has already been assigned to you.').'
'.
+ &mt('Please select the Author role from your [_1]roles page[_2].','',
+ '').'';
+ }
+ unless ($env{'environment.canrequest.author'}) {
+ return ''.
+ &mt('You do not currently have rights to request an authoring space.').'
'.
+ &mt('Please contact the [_1]helpdesk[_2].','',
+ '').'';
+ }
+ my $queued = &reqauthor_check();
+ if ($queued =~ /^approval:(\d+)$/) {
+ my $timestamp = $1;
+ return ''.
+ &mt('A request for authoring space submitted on [_1] is awaiting approval',
+ &Apache::lonlocal::locallocaltime($timestamp)).
+ '';
+ } elsif ($queued =~ /^approved:(\d+)$/) {
+ my $timestamp = $1;
+ my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
+ ['active'],['au'],[$env{'user.domain'}]);
+ if (keys(%roleshash) > 0) {
+ return ''.
+ &mt('A request for authoring space submitted on [_1] has been approved.',
+ &Apache::lonlocal::locallocaltime($timestamp)).
+ '';
+ }
+ }
+ my ($output,@inststatuses,%domconfig);
+ %domconfig = &Apache::lonnet::get_dom('configuration',['requestauthor'],
+ $env{'user.domain'});
+ my $val = &get_processtype('requestauthor',$env{'user.name'},$env{'user.domain'},
+ $env{'user.adv'},$env{'user.domain'},undef,
+ \@inststatuses,\%domconfig);
+ my $now = time;
+ if ($val eq 'automatic') {
+ my $start = $now-1;
+ if (&Apache::lonnet::assignrole($env{'user.domain'},$env{'user.name'},'/'.$env{'user.domain'}.'/',
+ 'au',undef,$start,undef,undef,'requestauthor') eq 'ok') {
+ $output = ''.
+ &mt('Access to authoring space has been activated').'
';
+ &Apache::lonroles::update_session_roles();
+ &Apache::lonnet::appenv({'user.update.time' => $now});
+ if (ref($updateref)) {
+ $$updateref = $now;
+ }
+ if (ref($dispositionref)) {
+ $$dispositionref = 'created';
+ }
+ } else {
+ $output = ''.
+ &mt('An error occurred while activating your access to authoring space');
+ }
+ } elsif ($val eq 'approval') {
+ my $domconfiguser = &Apache::lonnet::get_domainconfiguser($env{'user.domain'});
+ if (&Apache::lonnet::put('requestauthorqueue',{ $env{'user.name'}.'_'.$val => $now },
+ $env{'user.domain'},$domconfiguser) eq 'ok') {
+ my %userrequest = (
+ author => {
+ timestamp => $now,
+ status => $val,
+ },
+ author_status => $val,
+ );
+ my $req_notifylist;
+ if (ref($domconfig{'requestauthor'}) eq 'HASH') {
+ if (ref($domconfig{'requestauthor'}{'notify'}) eq 'HASH') {
+ my $req_notifylist = $domconfig{'requestauthor'}{'notify'}{'approval'};
+ if ($req_notifylist) {
+ my $fullname = &Apache::loncommon::plainname($env{'user.name'},
+ $env{'user.domain'});
+ my $sender = $env{'user.name'}.':'.$env{'user.domain'};
+ my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
+ &send_selfserve_notification($req_notifylist,
+ "$fullname ($env{'user.name'}:$env{'user.domain'})",
+ undef,$domdesc,$now,'authorreq',$sender);
+ }
+ }
+ }
+ my $userresult =
+ &Apache::lonnet::put('requestauthor',\%userrequest,$env{'user.domain'},$env{'user.name'});
+ $output = ''.
+ &mt('Your request for authoring space has been submitted for approval.').
+ '';
+ &Apache::lonnet::appenv({'environment.requestauthorqueued' => $val.':'.$now});
+ } else {
+ $output = ''.
+ &mt('An error occurred saving your request for authoring space.').
+ '';
+ }
+ }
+ return $output;
}
1;