--- loncom/interface/loncoursequeueadmin.pm 2010/01/18 15:54:23 1.12.2.7
+++ loncom/interface/loncoursequeueadmin.pm 2010/02/22 09:47:56 1.20
@@ -1,7 +1,7 @@
# The LearningOnline Network
-# Utilities to administer domain course requests and course self-enroll requests
+# Utilities to administer domain course requests and course self-enroll requests
#
-# $Id: loncoursequeueadmin.pm,v 1.12.2.7 2010/01/18 15:54:23 raeburn Exp $
+# $Id: loncoursequeueadmin.pm,v 1.20 2010/02/22 09:47:56 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -35,7 +35,7 @@ Apache::loncoursequeueadmin.pm
Utilities used by domain coordinators to administer queued course creation requests,
and by course coordinators for queued self-enrollment requests, and by general
-users to display their queued self-enrollment requests.
+users to display their queued self-enrollment requests.
This is part of the LearningOnline Network with CAPA project
described at http://www.lon-capa.org.
@@ -55,9 +55,11 @@ described at http://www.lon-capa.org.
=item course_creation()
=item build_batchcreatehash()
-
+
=item can_clone_course()
+=item get_processtype()
+
=item queued_selfenrollment()
=back
@@ -72,7 +74,7 @@ use Apache::loncommon;
use Apache::lonmsg;
use Apache::lonlocal;
use Apache::lonuserutils;
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
sub send_selfserve_notification {
my ($notifylist,$textstr,$cid,$contextdesc,$timestamp,$context,$sender,
@@ -373,10 +375,9 @@ sub update_request_queue {
$stucounts,$idx,$classlist,%requesthash,$cid,$hostname,$protocol,
$domdesc,$now,$sender,$approvedmsg,$rejectedmsg,$beneficiary,
@existing,@missingreq,@invalidusers,@limitexceeded,@completed,
- @processing_errors,@warn_approves,@warn_rejects,@approvals,
+ @processing_errors,@warn_approves,@warn_rejects,@approvals,@warn_dels,
@rejections,@rejectionerrors,@nopermissions,%courseroles,
- %communityroles,%domdefs,%approvalmsg,%rejectionmsg,$crstype,
- @warn_coursereqs);
+ %communityroles,%domdefs,%approvalmsg,%rejectionmsg,$crstype);
@approvals = &Apache::loncommon::get_env_multiple('form.approvereq');
@rejections = &Apache::loncommon::get_env_multiple('form.rejectreq');
$now = time;
@@ -465,10 +466,6 @@ sub update_request_queue {
my $uhome = &Apache::lonnet::homeserver($uname,$udom);
if ($uhome ne 'no_host') {
if (exists($requesthash{$uname.':'.$udom})) {
- if ($cdom eq 'gci' && $cnum eq '9615072b469884921gcil1') {
- my $enresult = &enable_gci_submission($udom,$uname,
- $access_end,$access_start);
- }
if (exists($classlist->{$uname.':'.$udom})) {
if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
if (($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Active') ||
@@ -514,15 +511,6 @@ sub update_request_queue {
&Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
if ($userresult ne 'ok') {
push(@warn_approves,$uname.':'.$udom);
- } elsif ($udom eq 'gci') {
- my %changehash = (
- 'reqcrsotherdom.unofficial' => 'gcitest:autolimit=',
- );
- my $reqresult = &Apache::lonnet::put('environment',\%changehash,
- $udom,$uname);
- if ($reqresult ne 'ok') {
- push(@warn_coursereqs,$uname.':'.$udom);
- }
}
} else {
push(@processing_errors,$uname.':'.$udom);
@@ -576,6 +564,10 @@ sub update_request_queue {
$approvedmsg = $approvalmsg{'course'};
}
push(@completed,$cnum);
+
+ unless (&Apache::lonnet::del_dom($namespace,[$cnum.'_approval'],$cdom) eq 'ok') {
+ push(@warn_dels,$cnum);
+ }
&send_selfserve_notification($ownername.':'.$ownerdom,$approvedmsg,
$cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype);
my %reqhash = (
@@ -690,6 +682,9 @@ sub update_request_queue {
} else {
push(@warn_rejects,$cnum);
}
+ unless (&Apache::lonnet::del_dom($namespace,[$cnum.'_approval'],$cdom) eq 'ok') {
+ push(@warn_dels,$cnum);
+ }
} else {
push(@warn_rejects,$cnum);
}
@@ -907,31 +902,20 @@ sub update_request_queue {
$output .= '
';
}
}
- if (@warn_coursereqs) {
- $output .= ''..&mt("For the following users, an error occurred when setting rights to request creation of Concept Test courses:").'
';
- foreach my $user (@warn_coursereqs) {
- $output .= '- '.$user.'
';
- }
- $output .= '
';
- }
- return $output;
-}
-
-sub enable_gci_submission {
- my ($udom,$uname,$access_end,$access_start) = @_;
- my $cdom = 'gci';
- my $cnum = '1H96711d710194bfegcil1';
- my ($stucounts,$idx,$classlist) = &get_student_counts($cdom,$cnum);
- if (exists($classlist->{$uname.':'.$udom})) {
- if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
- if (($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Active') ||
- ($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Future')) {
- return;
+ if (@warn_dels) {
+ $output .= ''.&mt("For the following course/community requests an error occurred when removing requests for the following from the pending queue:").'
';
+ foreach my $cnum (@warn_dels) {
+ my $showcourse;
+ if (ref($requesthash{$cnum.'_approval'})) {
+ $showcourse = $requesthash{$cnum.'_approval'}{'description'};
+ } else {
+ $showcourse = $cnum;
}
+ $output .= '- '.$showcourse.'
';
}
+ $output .= '
';
}
- return
- &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$access_end,$access_start,'selfenroll',undef,$cdom.'_'.$cnum,1);
+ return $output;
}
sub get_student_counts {
@@ -990,11 +974,8 @@ sub build_batchcreatehash {
my ($dom,$context,$details,$owneremail,$domdefs) = @_;
my %batchhash;
my @items = qw{owner domain coursehome clonecrs clonedom datemode dateshift enrollstart enrollend accessstart accessend sections crosslists users};
- if ($dom eq 'gcitest') {
- push(@items,'firstres');
- }
if ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH')) {
- my $emailenc = &Apache::lonnet::escape($owneremail);
+ my $emailenc = &escape($owneremail);
my $owner = $details->{'owner'}.':'.$details->{'domain'};
foreach my $item (@items) {
$batchhash{$item} = $details->{$item};
@@ -1077,10 +1058,106 @@ sub can_clone_course {
$canclone = 1;
}
}
+ unless ($canclone) {
+ if (&Apache::lonnet::is_course_owner($clonedom,$clonecrs,$uname,$udom)) {
+ $canclone = 1;
+ }
+ }
}
return $canclone;
}
+sub get_processtype {
+ my ($uname,$udom,$isadv,$dom,$crstype,$inststatuses,$domconfig) = @_;
+ return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
+ if ($uname eq '' || $udom eq '') {
+ $uname = $env{'user.name'};
+ $udom = $env{'user.domain'};
+ $isadv = $env{'user.adv'};
+ }
+ my (%userenv,%settings,$val);
+ my @options = ('autolimit','validate','approval');
+ if ($dom eq $udom) {
+ %userenv =
+ &Apache::lonnet::userenvironment($udom,$uname,'requestcourses.'.$crstype,'inststatus');
+ if ($userenv{'requestcourses.'.$crstype}) {
+ $val = $userenv{'requestcourses.'.$crstype};
+ @{$inststatuses} = ('_custom_');
+ } else {
+ my ($task,%alltasks);
+ if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
+ %settings = %{$domconfig->{'requestcourses'}};
+ if (ref($settings{$crstype}) eq 'HASH') {
+ if (($isadv) && ($settings{$crstype}{'_LC_adv'} ne '')) {
+ $val = $settings{$crstype}{'_LC_adv'};
+ @{$inststatuses} = ('_LC_adv_');
+ } else {
+ if ($userenv{'inststatus'} ne '') {
+ @{$inststatuses} = split(',',$userenv{'inststatus'});
+ } else {
+ @{$inststatuses} = ('default');
+ }
+ foreach my $status (@{$inststatuses}) {
+ if (exists($settings{$crstype}{$status})) {
+ my $value = $settings{$crstype}{$status};
+ next unless ($value);
+ unless (exists($alltasks{$value})) {
+ if (ref($alltasks{$value}) eq 'ARRAY') {
+ unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
+ push(@{$alltasks{$value}},$status);
+ }
+ } else {
+ @{$alltasks{$value}} = ($status);
+ }
+ }
+ }
+ }
+ my $maxlimit = 0;
+
+ foreach my $key (sort(keys(%alltasks))) {
+ if ($key =~ /^autolimit=(\d*)$/) {
+ if ($1 eq '') {
+ $val ='autolimit=';
+ last;
+ } elsif ($1 > $maxlimit) {
+ $maxlimit = $1;
+ }
+ }
+ }
+ if ($maxlimit) {
+ $val = 'autolimit='.$maxlimit;
+ } else {
+ foreach my $option (@options) {
+ if ($alltasks{$option}) {
+ $val = $option;
+ last;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ } else {
+ %userenv = &Apache::lonnet::userenvironment($udom,$uname,'reqcrsotherdom.'.$crstype);
+ if ($userenv{'reqcrsotherdom.'.$crstype}) {
+ my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
+ my $optregex = join('|',@options);
+ foreach my $item (@doms) {
+ my ($extdom,$extopt) = split(':',$item);
+ if ($extdom eq $dom) {
+ if ($extopt =~ /^($optregex)(=?\d*)$/) {
+ $val = $1.$2;
+ }
+ last;
+ }
+ }
+ @{$inststatuses} = ('_external_');
+ }
+ }
+ return $val;
+}
+
sub queued_selfenrollment {
my ($notitle) = @_;
my $output;
@@ -1127,4 +1204,40 @@ sub queued_selfenrollment {
return $output;
}
+sub update_coursereq_status {
+ my ($reqhash,$dom,$cnum,$reqstatus,$context) = @_;
+ my ($storeresult,$statusresult,$output);
+ my $requestkey = $dom.'_'.$cnum;
+ if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
+ $storeresult = &Apache::lonnet::store_userdata($reqhash,$requestkey,
+ 'courserequests');
+ if ($storeresult eq 'ok') {
+ my %status = (
+ 'status:'.$dom.':'.$cnum => $reqstatus,
+ );
+ $statusresult = &Apache::lonnet::put('courserequests',\%status);
+ }
+ } else {
+ $storeresult = 'error: invalid requestkey format';
+ }
+ if ($storeresult ne 'ok') {
+ $output = &mt('An error occurred saving a record of the details of your request: [_1].',$storeresult);
+ if ($context eq 'domain') {
+ $output .= "\n";
+ } else {
+ $output = ''.$output.'
';
+ }
+ &Apache::lonnet::logthis("Error saving course request - $requestkey for $env{'user.name'}:$env{'user.domain'} - $storeresult");
+ } elsif ($statusresult ne 'ok') {
+ $output = &mt('An error occurred saving a record of the status of your request: [_1].',$statusresult);
+ if ($context eq 'domain') {
+ $output .= "\n";
+ } else {
+ $output = ''.$output.'
';
+ }
+ &Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
+ }
+ return ($storeresult,$output);
+}
+
1;