version 1.12.2.10, 2010/12/05 21:57:33
|
version 1.19, 2010/02/21 23:38:51
|
Line 1
|
Line 1
|
# The LearningOnline Network |
# 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$ |
# $Id$ |
# |
# |
Line 35 Apache::loncoursequeueadmin.pm
|
Line 35 Apache::loncoursequeueadmin.pm
|
|
|
Utilities used by domain coordinators to administer queued course creation requests, |
Utilities used by domain coordinators to administer queued course creation requests, |
and by course coordinators for queued self-enrollment requests, and by general |
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 |
This is part of the LearningOnline Network with CAPA project |
described at http://www.lon-capa.org. |
described at http://www.lon-capa.org. |
Line 55 described at http://www.lon-capa.org.
|
Line 55 described at http://www.lon-capa.org.
|
=item course_creation() |
=item course_creation() |
|
|
=item build_batchcreatehash() |
=item build_batchcreatehash() |
|
|
=item can_clone_course() |
=item can_clone_course() |
|
|
|
=item get_processtype() |
|
|
=item queued_selfenrollment() |
=item queued_selfenrollment() |
|
|
=back |
=back |
Line 72 use Apache::loncommon;
|
Line 74 use Apache::loncommon;
|
use Apache::lonmsg; |
use Apache::lonmsg; |
use Apache::lonlocal; |
use Apache::lonlocal; |
use Apache::lonuserutils; |
use Apache::lonuserutils; |
use LONCAPA; |
use LONCAPA qw(:DEFAULT :match); |
|
|
sub send_selfserve_notification { |
sub send_selfserve_notification { |
my ($notifylist,$textstr,$cid,$contextdesc,$timestamp,$context,$sender, |
my ($notifylist,$textstr,$cid,$contextdesc,$timestamp,$context,$sender, |
Line 373 sub update_request_queue {
|
Line 375 sub update_request_queue {
|
$stucounts,$idx,$classlist,%requesthash,$cid,$hostname,$protocol, |
$stucounts,$idx,$classlist,%requesthash,$cid,$hostname,$protocol, |
$domdesc,$now,$sender,$approvedmsg,$rejectedmsg,$beneficiary, |
$domdesc,$now,$sender,$approvedmsg,$rejectedmsg,$beneficiary, |
@existing,@missingreq,@invalidusers,@limitexceeded,@completed, |
@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, |
@rejections,@rejectionerrors,@nopermissions,%courseroles, |
%communityroles,%domdefs,%approvalmsg,%rejectionmsg,$crstype, |
%communityroles,%domdefs,%approvalmsg,%rejectionmsg,$crstype); |
@warn_coursereqs); |
|
@approvals = &Apache::loncommon::get_env_multiple('form.approvereq'); |
@approvals = &Apache::loncommon::get_env_multiple('form.approvereq'); |
@rejections = &Apache::loncommon::get_env_multiple('form.rejectreq'); |
@rejections = &Apache::loncommon::get_env_multiple('form.rejectreq'); |
$now = time; |
$now = time; |
Line 459 sub update_request_queue {
|
Line 460 sub update_request_queue {
|
} |
} |
|
|
} |
} |
my %allnums = &Apache::loncommon::get_faculty_cnums(); |
|
foreach my $item (sort {$a <=> $b} @approvals) { |
foreach my $item (sort {$a <=> $b} @approvals) { |
if ($context eq 'course') { |
if ($context eq 'course') { |
my ($num,$uname,$udom,$usec) = split(/:/,$item); |
my ($num,$uname,$udom,$usec) = split(/:/,$item); |
my $uhome = &Apache::lonnet::homeserver($uname,$udom); |
my $uhome = &Apache::lonnet::homeserver($uname,$udom); |
if ($uhome ne 'no_host') { |
if ($uhome ne 'no_host') { |
if (exists($requesthash{$uname.':'.$udom})) { |
if (exists($requesthash{$uname.':'.$udom})) { |
if ($cdom ne '' && ref($allnums{$cdom} eq 'HASH') { |
|
my ($addothers,@others); |
|
foreach my $key (%{$allnums{$cdom}}) { |
|
if ($key eq $cnum) { |
|
$addothers = 1; |
|
} else { |
|
push(@others,$key); |
|
} |
|
} |
|
if ($addothers) { |
|
foreach my $crs (@others) { |
|
my $enresult = |
|
&enable_additional_roles($cdom,$crs,$udom,$uname, |
|
$access_end,$access_start); |
|
} |
|
} |
|
} |
|
if (exists($classlist->{$uname.':'.$udom})) { |
if (exists($classlist->{$uname.':'.$udom})) { |
if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') { |
if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') { |
if (($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Active') || |
if (($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Active') || |
Line 528 sub update_request_queue {
|
Line 511 sub update_request_queue {
|
&Apache::lonnet::put($namespace,\%userrequest,$udom,$uname); |
&Apache::lonnet::put($namespace,\%userrequest,$udom,$uname); |
if ($userresult ne 'ok') { |
if ($userresult ne 'ok') { |
push(@warn_approves,$uname.':'.$udom); |
push(@warn_approves,$uname.':'.$udom); |
} elsif (ref($allnums{$udom}) eq 'HASH') { |
|
my %changehash = ( |
|
'reqcrsotherdom.unofficial' => $udom.'test:autolimit=', |
|
); |
|
my $reqresult = &Apache::lonnet::put('environment',\%changehash, |
|
$udom,$uname); |
|
if ($reqresult ne 'ok') { |
|
push(@warn_coursereqs,$uname.':'.$udom); |
|
} |
|
} |
} |
} else { |
} else { |
push(@processing_errors,$uname.':'.$udom); |
push(@processing_errors,$uname.':'.$udom); |
Line 590 sub update_request_queue {
|
Line 564 sub update_request_queue {
|
$approvedmsg = $approvalmsg{'course'}; |
$approvedmsg = $approvalmsg{'course'}; |
} |
} |
push(@completed,$cnum); |
push(@completed,$cnum); |
|
|
|
unless (&Apache::lonnet::del_dom($namespace,[$cnum.'_approval'],$cdom) eq 'ok') { |
|
push(@warn_dels,$cnum); |
|
} |
&send_selfserve_notification($ownername.':'.$ownerdom,$approvedmsg, |
&send_selfserve_notification($ownername.':'.$ownerdom,$approvedmsg, |
$cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype); |
$cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype); |
my %reqhash = ( |
my %reqhash = ( |
Line 704 sub update_request_queue {
|
Line 682 sub update_request_queue {
|
} else { |
} else { |
push(@warn_rejects,$cnum); |
push(@warn_rejects,$cnum); |
} |
} |
|
unless (&Apache::lonnet::del_dom($namespace,[$cnum.'_approval'],$cdom) eq 'ok') { |
|
push(@warn_dels,$cnum); |
|
} |
} else { |
} else { |
push(@warn_rejects,$cnum); |
push(@warn_rejects,$cnum); |
} |
} |
Line 921 sub update_request_queue {
|
Line 902 sub update_request_queue {
|
$output .= '</ul></p>'; |
$output .= '</ul></p>'; |
} |
} |
} |
} |
if (@warn_coursereqs) { |
if (@warn_dels) { |
$output .= '<p>'..&mt("For the following users, an error occurred when setting rights to request creation of Concept Test courses:").'<ul>'; |
$output .= '<p>'.&mt("For the following course/community requests an error occurred when removing requests for the following from the pending queue:").'<ul>'; |
foreach my $user (@warn_coursereqs) { |
foreach my $cnum (@warn_dels) { |
$output .= '<li>'.$user.'</li>'; |
my $showcourse; |
} |
if (ref($requesthash{$cnum.'_approval'})) { |
$output .= '</ul></p>'; |
$showcourse = $requesthash{$cnum.'_approval'}{'description'}; |
} |
} else { |
return $output; |
$showcourse = $cnum; |
} |
|
|
|
sub enable_additional_roles { |
|
my ($cdom,$cnum,$udom,$uname,$access_end,$access_start) = @_; |
|
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; |
|
} |
} |
|
$output .= '<li>'.$showcourse.'</li>'; |
} |
} |
|
$output .= '</ul></p>'; |
} |
} |
return |
return $output; |
&Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$access_end,$access_start,'selfenroll',undef,$cdom.'_'.$cnum,1); |
|
} |
} |
|
|
sub get_student_counts { |
sub get_student_counts { |
Line 988 sub course_creation {
|
Line 960 sub course_creation {
|
} |
} |
my %reqdetails = &build_batchcreatehash($dom,$context,$details,$owneremail,$domdefs); |
my %reqdetails = &build_batchcreatehash($dom,$context,$details,$owneremail,$domdefs); |
my $cid = &LONCAPA::batchcreatecourse::build_course($dom,$cnum,'requestcourses', |
my $cid = &LONCAPA::batchcreatecourse::build_course($dom,$cnum,'requestcourses', |
\%reqdetails,$longroles,$logmsg,$newusermsg,$addresult, |
\%reqdetails,$longroles,\$logmsg,\$newusermsg,\$addresult, |
$enrollcount,$output,$keysmsg,$ownerdom,$ownername,$cnum,$crstype); |
\$enrollcount,\$output,\$keysmsg,$ownerdom,$ownername,$cnum,$crstype); |
if ($cid eq "/$dom/$cnum") { |
if ($cid eq "/$dom/$cnum") { |
$result = 'created'; |
$result = 'created'; |
} else { |
} else { |
Line 1001 sub course_creation {
|
Line 973 sub course_creation {
|
sub build_batchcreatehash { |
sub build_batchcreatehash { |
my ($dom,$context,$details,$owneremail,$domdefs) = @_; |
my ($dom,$context,$details,$owneremail,$domdefs) = @_; |
my %batchhash; |
my %batchhash; |
my @items = qw{owner domain coursehome clonecrs clonedom cloneroster datemode dateshift enrollstart enrollend accessstart accessend sections crosslists users}; |
my @items = qw{owner domain coursehome clonecrs clonedom datemode dateshift enrollstart enrollend accessstart accessend sections crosslists users}; |
if ($dom =~ /^\w+citest$/) { |
|
push(@items,'firstres'); |
|
} |
|
if ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH')) { |
if ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH')) { |
my $emailenc = &escape($owneremail); |
my $emailenc = &escape($owneremail); |
my $owner = $details->{'owner'}.':'.$details->{'domain'}; |
my $owner = $details->{'owner'}.':'.$details->{'domain'}; |
Line 1091 sub can_clone_course {
|
Line 1060 sub can_clone_course {
|
} |
} |
unless ($canclone) { |
unless ($canclone) { |
if (&Apache::lonnet::is_course_owner($clonedom,$clonecrs,$uname,$udom)) { |
if (&Apache::lonnet::is_course_owner($clonedom,$clonecrs,$uname,$udom)) { |
$canclone = 1; |
$can_clone = 1; |
} |
} |
} |
} |
} |
} |
return $canclone; |
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 { |
sub queued_selfenrollment { |
my ($notitle) = @_; |
my ($notitle) = @_; |
my $output; |
my $output; |
Line 1144 sub queued_selfenrollment {
|
Line 1204 sub queued_selfenrollment {
|
return $output; |
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 = '<span class="LC_warning">'.$output.'</span><br />'; |
|
} |
|
&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 = '<span class="LC_warning">'.$output.'</span><br />'; |
|
} |
|
&Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult"); |
|
} |
|
return ($storeresult,$output); |
|
} |
|
|
1; |
1; |