--- loncom/interface/loncoursequeueadmin.pm 2009/08/16 19:16:16 1.2 +++ loncom/interface/loncoursequeueadmin.pm 2009/08/20 20:43:08 1.5 @@ -1,7 +1,7 @@ # The LearningOnline Network # Utilities to administer domain course requests and course self-enroll requests # -# $Id: loncoursequeueadmin.pm,v 1.2 2009/08/16 19:16:16 raeburn Exp $ +# $Id: loncoursequeueadmin.pm,v 1.5 2009/08/20 20:43:08 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -77,13 +77,13 @@ sub send_selfserve_notification { $rawsubj = 'Self-enrollment requests processed'; push(@rawmsg,{ mt => 'Enrollment requests in the following course: [_1]have been processed.', - args => ["\n $contextdesc\n"], + args => ["\n $contextdesc"], }); } elsif ($context eq 'domainmanagers') { $rawsubj = 'Course requests reviewed'; push(@rawmsg,{ mt => 'Course creation requests in the following domain: [_1]have been reviewed.', - args => ["\n $contextdesc\n"], + args => ["\n $contextdesc"], }); if (ref($textstr) eq 'ARRAY') { push(@rawmsg,@{$textstr}); @@ -345,7 +345,8 @@ sub update_request_queue { $domdesc,$now,$sender,$approvedmsg,$rejectedmsg,$beneficiary, @existing,@missingreq,@invalidusers,@limitexceeded,@completed, @processing_errors,@warn_approves,@warn_rejects,@approvals, - @rejections,%courseroles,%communityroles,%domdefs); + @rejections,@rejectionerrors,@nopermissions,%courseroles, + %communityroles,%domdefs); @approvals = &Apache::loncommon::get_env_multiple('form.approvereq'); @rejections = &Apache::loncommon::get_env_multiple('form.rejectreq'); $now = time; @@ -482,8 +483,22 @@ sub update_request_queue { if ($crstype eq 'community') { $longroles = \%communityroles; } - if (&Apache::lonnet::usertools_access($ownername,$ownerdom,$crstype, - undef,'requestcourses')) { + my $cancreate; + if ($cdom eq $ownerdom) { + if (&Apache::lonnet::usertools_access($ownername,$ownerdom,$crstype, + undef,'requestcourses')) { + $cancreate = 1; + } + } else { + my %userenv = &Apache::lonnet::userenvironment($ownerdom,$ownername,'reqcrsotherdom.'.$crstype); + if ($userenv{'reqcrsotherdom.'.$crstype}) { + my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype}); + if (grep(/^\Q$cdom\E:/,@doms)) { + $cancreate = 1; + } + } + } + if ($cancreate) { my $requestkey = $cdom.'_'.$cnum; my %history = &Apache::lonnet::restore($requestkey,'courserequests', @@ -531,7 +546,7 @@ sub update_request_queue { push(@processing_errors,$cnum); } } else { - push(@processing_errors,$cnum); + push(@nopermissions,$cnum); } } else { push(@existing,$cnum); @@ -546,8 +561,9 @@ sub update_request_queue { @changes = map {$_.'_approval'} (@changes); } if (@rejections) { - foreach my $user (@rejections) { + foreach my $item (@rejections) { if ($context eq 'course') { + my $user = $item; &send_selfserve_notification($user,$rejectedmsg,$cid,$coursedesc, $now,$beneficiary,$sender); my ($uname,$udom) = split(/:/,$user); @@ -564,8 +580,10 @@ sub update_request_queue { push(@warn_rejects,$user); } } else { - if (ref($requesthash{$user.'_approval'}) eq 'HASH') { - if (&Apache::lonnet::homeserver($user,$cdom) eq 'no_host') { + my $cnum = $item; + if (ref($requesthash{$cnum.'_approval'}) eq 'HASH') { + if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') { + my $requestkey = $cdom.'_'.$cnum; my $ownername = $requesthash{$cnum.'_approval'}{'ownername'}; my $ownerdom = $requesthash{$cnum.'_approval'}{'ownerdom'}; my $coursedesc = $requesthash{$cnum.'_approval'}{'description'}; @@ -573,7 +591,7 @@ sub update_request_queue { $cid,$coursedesc,$now,$beneficiary, $sender); my %history = - &Apache::lonnet::restore($cdom.'_'.$cnum,'courserequests', + &Apache::lonnet::restore($requestkey,'courserequests', $ownerdom,$ownername); if ((ref($history{'details'}) eq 'HASH') && ($history{'disposition'} eq 'approval')) { @@ -586,12 +604,29 @@ sub update_request_queue { adjudicator => $env{'user.name'}.':'.$env{'user.domain'}, ); my $userresult = - &Apache::lonnet::store_userdata($namespace,\%reqhash,$ownerdom,$ownername); - if ($userresult ne 'ok') { - push(@warn_rejects,$user); + &Apache::lonnet::store_userdata(\%reqhash,$requestkey, + 'courserequests',$ownerdom,$ownername); + if ($userresult eq 'ok') { + my %status = ( + 'status:'.$cdom.':'.$cnum => 'rejected' + ); + my $statusresult = + &Apache::lonnet::put('courserequests',\%status, + $ownerdom,$ownername); + if ($statusresult ne 'ok') { + push(@warn_rejects,$cnum); + } + } else { + push(@warn_rejects,$cnum); } + } else { + push(@warn_rejects,$cnum); } + } else { + push(@existing,$cnum); } + } else { + push(@rejectionerrors,$cnum); } } } @@ -729,6 +764,19 @@ sub update_request_queue { $output .= '
'; } } + if (@nopermissions) { + $output .= ''.&mt('The following course creation requests could not be processed because the course owner does hot have rights to create this type of course:').'
'.&mt('The following enrollment requests could not be processed because an error occurred:').'
'.&mt('The following course creation request rejections could not be fully processed because an error occurred:').'
'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'