'.&mt('Requests for official courses queued pending validation').'
'.
+ '
'.&mt('Requests are validated against institutional data to confirm that the requestor is an instructor of record.').' '.
+ &mt('Validation is attempted when the request is submitted.').' '.&mt('If unvalidated, the request will be held in a queue.').' '.&mt('Validation of pending requests is automatically repeated daily.').'
';
+ } else {
+ $output .= '
'.&mt('Course/Community requests queued pending approval by a Domain Coordinator').'
';
+ if ($context eq 'course') {
+ $output .= &mt('There are currently no enrollment requests awaiting approval.');
+ } elsif ($context eq 'pending') {
+ $output .= &mt('There are currently no requests for official courses awaiting validation.');
+ } elsif ($context eq 'domain') {
+ $output .= &mt('There are currently no course or community requests awaiting approval.');
+ }
+ $output .= '
'.&mt('Any course/community requests which are successfully validated will be created immediately.').' '.&mt('Unvalidated requests will be listed for manual approval/rejection.').'
';
+ if ($context eq 'course') {
+ $output .= &mt('There are currently no enrollment requests awaiting approval.');
+ } elsif ($context eq 'pending') {
+ $output .= &mt('There are currently no requests for official courses awaiting validation.');
+ } else {
+ $output .= &mt('There are currently no course or community requests awaiting approval.');
+ }
+ $output .= '
'."\n";
+ }
+ $output .= &Apache::loncommon::start_data_table_row()."\n".
+ $row.
+ &Apache::loncommon::end_data_table_row()."\n";
+ $count ++;
}
}
- $output .= &Apache::loncommon::end_data_table().
- '';
- } else {
- if ($context eq 'course') {
- $output .= &mt('There are currently no enrollment requests.');
- } else {
- $output .= &mt('There are currently no course or community requests awaiting approval.');
- }
}
+ $output .= &Apache::loncommon::end_data_table();
return $output;
}
sub update_request_queue {
my ($context,$cdom,$cnum,$coursedesc) = @_;
my ($output,$access_start,$access_end,$limit,$cap,$notifylist,$namespace,
- $stucounts,$idx,$classlist,%requesthash,$cid,$hostname,$protocol,
- $domdesc,$now,$sender,$approvedmsg,$rejectedmsg,$beneficiary,
+ $stucounts,$idx,$classlist,%requesthash,$cid,$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);
- @approvals = &Apache::loncommon::get_env_multiple('form.approvereq');
- @rejections = &Apache::loncommon::get_env_multiple('form.rejectreq');
+ %communityroles,%domdefs,%approvalmsg,%rejectionmsg,$crstype,$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:.*/) {
+ #decide later
+ } else {
+ push(@rejections,@course[0]);
+ }
+ $count+=1;
+ }
+
+
$now = time;
$sender = $env{'user.name'}.':'.$env{'user.domain'};
if ($context eq 'course') {
@@ -386,10 +483,7 @@ sub update_request_queue {
$beneficiary = 'enroller';
$cid = $env{'request.course.id'};
$crstype = lc(&Apache::loncommon::course_type());
- my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
- $hostname = &Apache::lonnet::hostname($chome);
- $protocol = $Apache::lonnet::protocol{$chome};
- $protocol = 'http' if ($protocol ne 'https');
+ $firsturl = &course_portal_url($cnum,$cdom);
%requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
$access_start = $env{'course.'.$cid.'.internal.selfenroll_start_access'};
$access_end = $env{'course.'.$cid.'.internal.selfenroll_end_access'};
@@ -401,8 +495,8 @@ sub update_request_queue {
mt => 'Your request for enrollment has been approved.',
},
{
- mt => 'Visit [_1], to log-in and access the course',
- args => [$protocol.'://'.$hostname],
+ mt => 'Visit [_1] to log-in and access the course',
+ args => [$firsturl],
}];
$rejectedmsg = [{
mt => 'Your request for enrollment has not been approved.',
@@ -411,11 +505,11 @@ sub update_request_queue {
$domdesc = &Apache::lonnet::domain($cdom);
$namespace = 'courserequestqueue';
$beneficiary = 'courserequestor';
- %requesthash = &Apache::lonnet::dump_dom($namespace,$cdom,'_approval');
- my $chome = &Apache::lonnet::domain($cdom,'primary');
- $hostname = &Apache::lonnet::hostname($chome);
- $protocol = $Apache::lonnet::protocol{$chome};
- $protocol = 'http' if ($protocol ne 'https');
+ $queue = 'approval';
+ if ($env{'form.queue'} eq 'pending') {
+ $queue = 'pending';
+ }
+ %requesthash = &Apache::lonnet::dump_dom($namespace,$cdom,'_'.$queue);
my %domconfig = &Apache::lonnet::get_dom('configuration',['requestcourses'],$cdom);
if (ref($domconfig{'requestcourses'}) eq 'HASH') {
if (ref($domconfig{'requestcourses'}{'notify'}) eq 'HASH') {
@@ -427,8 +521,8 @@ sub update_request_queue {
mt => 'Your course request has been approved.',
},
{
- mt => 'Visit [_1], to log-in and access the course',
- args => [$protocol.'://'.$hostname],
+ mt => 'Visit [_1] to log-in and access the course',
+ args => [],
}];
$rejectionmsg{'course'} =
[{
@@ -440,8 +534,8 @@ sub update_request_queue {
mt => 'Your community request has been approved.',
},
{
- mt => 'Visit [_1], to log-in and access the community',
- args => [$protocol.'://'.$hostname],
+ mt => 'Visit [_1] to log-in and access the community',
+ args => [],
}];
$rejectionmsg{'community'} =
@@ -459,30 +553,12 @@ sub update_request_queue {
}
}
- my %allnums = &Apache::loncommon::get_faculty_cnums();
foreach my $item (sort {$a <=> $b} @approvals) {
if ($context eq 'course') {
my ($num,$uname,$udom,$usec) = split(/:/,$item);
my $uhome = &Apache::lonnet::homeserver($uname,$udom);
if ($uhome ne 'no_host') {
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 (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
if (($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Active') ||
@@ -515,7 +591,8 @@ sub update_request_queue {
$stucounts->{'allstudents'} ++;
$stucounts->{'selfenrolled'} ++;
&send_selfserve_notification($uname.':'.$udom,$approvedmsg,
- $cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype);
+ $cid,$coursedesc,$now,$beneficiary,$sender,
+ undef,undef,$crstype);
my %userrequest = (
$cdom.'_'.$cnum => {
timestamp => $now,
@@ -528,15 +605,6 @@ sub update_request_queue {
&Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
if ($userresult ne 'ok') {
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 {
push(@processing_errors,$uname.':'.$udom);
@@ -547,12 +615,12 @@ sub update_request_queue {
}
} else {
my ($num,$cnum) = split(':',$item);
- if (ref($requesthash{$cnum.'_approval'}) eq 'HASH') {
+ if (ref($requesthash{$cnum.'_'.$queue}) eq 'HASH') {
if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
- my $ownername = $requesthash{$cnum.'_approval'}{'ownername'};
- my $ownerdom = $requesthash{$cnum.'_approval'}{'ownerdom'};
- $crstype = $requesthash{$cnum.'_approval'}{'crstype'};
- my $coursedesc = $requesthash{$cnum.'_approval'}{'description'};
+ my $ownername = $requesthash{$cnum.'_'.$queue}{'ownername'};
+ my $ownerdom = $requesthash{$cnum.'_'.$queue}{'ownerdom'};
+ $crstype = $requesthash{$cnum.'_'.$queue}{'crstype'};
+ my $coursedesc = $requesthash{$cnum.'_'.$queue}{'description'};
my $longroles = \%courseroles;
if ($crstype eq 'community') {
$longroles = \%communityroles;
@@ -578,7 +646,7 @@ sub update_request_queue {
&Apache::lonnet::restore($requestkey,'courserequests',
$ownerdom,$ownername);
if ((ref($history{'details'}) eq 'HASH') &&
- ($history{'disposition'} eq 'approval')) {
+ ($history{'disposition'} eq $queue)) {
my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg);
my $result = &course_creation($cdom,$cnum,$context,$history{'details'},\$logmsg,
\$newusermsg,\$addresult,\$enrollcount,
@@ -589,9 +657,20 @@ sub update_request_queue {
} else {
$approvedmsg = $approvalmsg{'course'};
}
+ my $firsturl = &course_portal_url($cnum,$cdom);
+ if (ref($approvedmsg) eq 'ARRAY') {
+ if (ref($approvedmsg->[1]) eq 'HASH') {
+ $approvedmsg->[1]->{'args'} = [$firsturl];
+ }
+ }
push(@completed,$cnum);
- &send_selfserve_notification($ownername.':'.$ownerdom,$approvedmsg,
- $cid,$coursedesc,$now,$beneficiary,$sender,undef,undef,$crstype);
+
+ unless (&Apache::lonnet::del_dom($namespace,[$cnum.'_'.$queue],$cdom) eq 'ok') {
+ push(@warn_dels,$cnum);
+ }
+ &send_selfserve_notification($ownername.':'.$ownerdom,
+ $approvedmsg,$cid,$coursedesc,$now,
+ $beneficiary,$sender,undef,undef,$crstype);
my %reqhash = (
reqtime => $history{'reqtime'},
crstype => $history{'crstype'},
@@ -637,14 +716,15 @@ sub update_request_queue {
}
my @changes = (@completed,@rejections);
if ($context eq 'domain') {
- @changes = map {$_.'_approval'} (@changes);
+ @changes = map {$_.'_'.$queue} (@changes);
}
if (@rejections) {
foreach my $item (@rejections) {
if ($context eq 'course') {
my $user = $item;
&send_selfserve_notification($user,$rejectedmsg,$cid,$coursedesc,
- $now,$beneficiary,$sender,undef,undef,$crstype);
+ $now,$beneficiary,$sender,undef,undef,
+ $crstype);
my ($uname,$udom) = split(/:/,$user);
my %userrequest = (
$cdom.'_'.$cnum => {
@@ -660,13 +740,13 @@ sub update_request_queue {
}
} else {
my $cnum = $item;
- if (ref($requesthash{$cnum.'_approval'}) eq 'HASH') {
+ if (ref($requesthash{$cnum.'_'.$queue}) 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'};
- $crstype = $requesthash{$cnum.'_approval'}{'crstype'};
+ my $ownername = $requesthash{$cnum.'_'.$queue}{'ownername'};
+ my $ownerdom = $requesthash{$cnum.'_'.$queue}{'ownerdom'};
+ my $coursedesc = $requesthash{$cnum.'_'.$queue}{'description'};
+ $crstype = $requesthash{$cnum.'_'.$queue}{'crstype'};
if ($crstype eq 'community') {
$rejectedmsg = $rejectionmsg{'community'};
} else {
@@ -679,7 +759,7 @@ sub update_request_queue {
&Apache::lonnet::restore($requestkey,'courserequests',
$ownerdom,$ownername);
if ((ref($history{'details'}) eq 'HASH') &&
- ($history{'disposition'} eq 'approval')) {
+ ($history{'disposition'} eq $queue)) {
my %reqhash = (
reqtime => $history{'reqtime'},
crstype => $history{'crstype'},
@@ -704,6 +784,9 @@ sub update_request_queue {
} else {
push(@warn_rejects,$cnum);
}
+ unless (&Apache::lonnet::del_dom($namespace,[$cnum.'_'.$queue],$cdom) eq 'ok') {
+ push(@warn_dels,$cnum);
+ }
} else {
push(@warn_rejects,$cnum);
}
@@ -764,8 +847,8 @@ sub update_request_queue {
$output .= '
'.&mt('The following courses/communities were created:').'
';
foreach my $cnum (@completed) {
my $showcourse;
- if (ref($requesthash{$cnum.'_approval'})) {
- $showcourse = $requesthash{$cnum.'_approval'}{'description'};
+ if (ref($requesthash{$cnum.'_'.$queue})) {
+ $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
} else {
$showcourse = $cnum;
}
@@ -780,8 +863,8 @@ sub update_request_queue {
$output .= '
'.&mt('The following requests were rejected:').'
';
foreach my $cnum (@rejections) {
my $showcourse;
- if (ref($requesthash{$cnum.'_approval'})) {
- $showcourse = $requesthash{$cnum.'_approval'}{'description'};
+ if (ref($requesthash{$cnum.'_'.$queue})) {
+ $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
} else {
$showcourse = $cnum;
}
@@ -857,8 +940,8 @@ sub update_request_queue {
$output .= '
'.&mt('The following course/community creation requests could not be processed because the owner does not have rights to create this type of course:').'
';
foreach my $cnum (@nopermissions) {
my $showcourse;
- if (ref($requesthash{$cnum.'_approval'})) {
- $showcourse = $requesthash{$cnum.'_approval'}{'description'};
+ if (ref($requesthash{$cnum.'_'.$queue})) {
+ $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
} else {
$showcourse = $cnum;
}
@@ -877,8 +960,8 @@ sub update_request_queue {
$output .= '
'.&mt('The following course/community creation requests could not be processed because an error occurred:').'
';
foreach my $cnum (@processing_errors) {
my $showcourse;
- if (ref($requesthash{$cnum.'_approval'})) {
- $showcourse = $requesthash{$cnum.'_approval'}{'description'};
+ if (ref($requesthash{$cnum.'_'.$queue})) {
+ $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
} else {
$showcourse = $cnum;
}
@@ -891,8 +974,8 @@ sub update_request_queue {
$output .= '
'.&mt('The following course/community creation request rejections could not be fully processed because an error occurred:').'
';
foreach my $cnum (@rejectionerrors) {
my $showcourse;
- if (ref($requesthash{$cnum.'_approval'})) {
- $showcourse = $requesthash{$cnum.'_approval'}{'description'};
+ if (ref($requesthash{$cnum.'_'.$queue})) {
+ $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
} else {
$showcourse = $cnum;
}
@@ -911,8 +994,8 @@ sub update_request_queue {
$output .= '
'.&mt("For the following course/community requests an error occurred when updating the requestor's own requests record:").'
';
foreach my $cnum (@warn_approves,@warn_rejects) {
my $showcourse;
- if (ref($requesthash{$cnum.'_approval'})) {
- $showcourse = $requesthash{$cnum.'_approval'}{'description'};
+ if (ref($requesthash{$cnum.'_'.$queue})) {
+ $showcourse = $requesthash{$cnum.'_'.$queue}{'description'};
} else {
$showcourse = $cnum;
}
@@ -921,29 +1004,36 @@ 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:").'
';
}
return $output;
}
-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;
- }
- }
+sub course_portal_url {
+ my ($cnum,$cdom) = @_;
+ my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
+ my $hostname = &Apache::lonnet::hostname($chome);
+ my $protocol = $Apache::lonnet::protocol{$chome};
+ $protocol = 'http' if ($protocol ne 'https');
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
+ my $firsturl;
+ if ($domdefaults{'portal_def'}) {
+ $firsturl = $domdefaults{'portal_def'};
+ } else {
+ $firsturl = $protocol.'://'.$hostname;
}
- return
- &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$access_end,$access_start,'selfenroll',undef,$cdom.'_'.$cnum,1);
+ return $firsturl;
}
sub get_student_counts {
@@ -1001,10 +1091,7 @@ sub course_creation {
sub build_batchcreatehash {
my ($dom,$context,$details,$owneremail,$domdefs) = @_;
my %batchhash;
- my @items = qw{owner domain coursehome clonecrs clonedom cloneroster datemode dateshift enrollstart enrollend accessstart accessend sections crosslists users};
- if ($dom =~ /^\w+citest$/) {
- push(@items,'firstres');
- }
+ my @items = qw{owner domain coursehome clonecrs clonedom datemode dateshift enrollstart enrollend accessstart accessend sections crosslists users};
if ((ref($details) eq 'HASH') && (ref($domdefs) eq 'HASH')) {
my $emailenc = &escape($owneremail);
my $owner = $details->{'owner'}.':'.$details->{'domain'};
@@ -1098,6 +1185,97 @@ sub can_clone_course {
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;
@@ -1143,5 +1321,210 @@ sub queued_selfenrollment {
}
return $output;
}
+
+sub update_coursereq_status {
+ my ($reqhash,$dom,$cnum,$reqstatus,$context,$udom,$uname) = @_;
+ my ($storeresult,$statusresult,$output);
+ my $requestkey = $dom.'_'.$cnum;
+ if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
+ $storeresult = &Apache::lonnet::store_userdata($reqhash,$requestkey,
+ 'courserequests',$udom,$uname);
+ if ($storeresult eq 'ok') {
+ my %status = (
+ 'status:'.$dom.':'.$cnum => $reqstatus,
+ );
+ $statusresult = &Apache::lonnet::put('courserequests',\%status,$udom,$uname);
+ }
+ } 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 $uname:$udom - $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 $uname:$udom) - $statusresult");
+ }
+ return ($storeresult,$output);
+}
+
+sub process_official_reqs {
+ my ($context,$dom,$dcname,$dcdom) = @_;
+ my $reqsnamespace = 'courserequestqueue';
+ my %requesthash =
+ &Apache::lonnet::dump_dom($reqsnamespace,$dom,'_pending');
+ my (%newcids,%longroles,%stillpending);
+ my @courseroles = ('cc','in','ta','ep','ad','st');
+ foreach my $role (@courseroles) {
+ $longroles{$role}=&Apache::lonnet::plaintext($role);
+ }
+ my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
+ my ($output,$linefeed);
+ if ($context eq 'auto') {
+ $linefeed = "\n";
+ } else {
+ $linefeed = ' '."\n";
+ }
+ foreach my $key (keys(%requesthash)) {
+ my ($cnum,$status) = split('_',$key);
+ next if (&Apache::lonnet::homeserver($cnum,$dom) ne 'no_host');
+ if (ref($requesthash{$key}) eq 'HASH') {
+ my $ownername = $requesthash{$key}{'ownername'};
+ my $ownerdom = $requesthash{$key}{'ownerdom'};
+ next if (&Apache::lonnet::homeserver($ownername,$ownerdom) eq 'no_host');
+ my $inststatus;
+ my %userenv =
+ &Apache::lonnet::get('environment',['inststatus'],
+ $ownerdom,$ownername);
+ my ($tmp) = keys(%userenv);
+ if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
+ $inststatus = $userenv{'inststatus'};
+ } else {
+ undef(%userenv);
+ }
+ my $reqkey = $dom.'_'.$cnum;
+ my %history = &Apache::lonnet::restore($reqkey,'courserequests',
+ $ownerdom,$ownername);
+ if (ref($history{'details'}) eq 'HASH') {
+ my $instcode = $history{'details'}{'instcode'};
+ my $crstype = $history{'details'}{'crstype'};
+ my $reqtime = $history{'details'}{'reqtime'};
+ my $cdescr = $history{'details'}{'cdescr'};
+ my @currsec;
+ my $sections = $history{'details'}{'sections'};
+ if (ref($sections) eq 'HASH') {
+ foreach my $i (sort(keys(%{$sections}))) {
+ if (ref($sections->{$i}) eq 'HASH') {
+ my $sec = $sections->{$i}{'inst'};
+ if (!grep(/^\Q$sec\E$/,@currsec)) {
+ push(@currsec,$sec);
+ }
+ }
+ }
+ }
+ my $instseclist = join(',',@currsec);
+ my ($validationchk,$disposition,$reqstatus,$message,
+ $validation,$validationerror);
+ $validationchk =
+ &Apache::lonnet::auto_courserequest_validation($dom,
+ $ownername.':'.$ownerdom,$crstype,$inststatus,
+ $instcode,$instseclist);
+ if ($validationchk =~ /:/) {
+ ($validation,$message) = split(':',$validationchk);
+ } else {
+ $validation = $validationchk;
+ }
+ if ($validation =~ /^error(.*)$/) {
+ $disposition = 'approval';
+ $validationerror = $1;
+ } else {
+ $disposition = $validation;
+ }
+ $reqstatus = $disposition;
+ if ($disposition eq 'process') {
+ my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg);
+ my $result = &course_creation($dom,$cnum,'domain',$history{'details'},\$logmsg,\$newusermsg,\$addresult,\$enrollcount,\$response,\$keysmsg,\%domdefs,\%longroles);
+ if ($result eq 'created') {
+ $disposition = 'created';
+ $reqstatus = 'created';
+ my $cid = $dom.'_'.$cnum;
+ push(@{$newcids{$instcode}},$cid);
+ if ($dcname && $dcdom) {
+ my $firsturl = &course_portal_url($cnum,$dom);
+ my $beneficiary = 'pendingrequestor';
+ my $now = time;
+ my $owner = $ownername.':'.$ownerdom;
+ my $approvedmsg =
+ [{
+ mt => 'Your requested course: [_1], (queued pending validation) has now been created.',
+ args => [$cdescr],
+ },
+ {
+ mt => 'Visit [_1] to log-in and access the course.',
+ args => [$firsturl],
+ },
+ {
+ mt => 'If currently logged-in to LON-CAPA, log-out and log-in again to select your new course role.'
+ }];
+ my $sender = $dcname.':'.$dcdom;
+ &send_selfserve_notification($owner,$approvedmsg,
+ $cid,$cdescr,$now,
+ $beneficiary,$sender,
+ undef,undef,$crstype);
+ }
+ }
+ } elsif ($disposition eq 'rejected') {
+ $output .= &mt('Queued course request for [_1] submitted by [_2] with status [_3] rejected when validating.',$instcode,$ownername.':'.$ownerdom,$inststatus).$linefeed;
+ } elsif ($disposition eq 'approval') {
+ $output .= &mt('Queued course request for [_1] submitted by [_2] with status [_3] switched to "approval by DC" because of validation error: [_4].',$instcode,$ownername.':'.$ownerdom,$inststatus,$validationerror).$linefeed;
+
+ my $requestid = $cnum.'_'.$disposition;
+ my $request = {
+ $requestid => {
+ timestamp => $reqtime,
+ crstype => $crstype,
+ ownername => $ownername,
+ ownerdom => $ownerdom,
+ description => $cdescr,
+ },
+ };
+ my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,$dom);
+ unless ($putresult eq 'ok') {
+ $output .= &mt("An error occurred saving the modified course request for [_1] submitted by [_2] in the domain's courserequestqueue.db.",$instcode,$ownername.':'.$ownerdom).$linefeed;
+ }
+ } elsif ($disposition eq 'pending') {
+ my $instcode = $requesthash{$key}{'instcode'};
+ my $description = $requesthash{$key}{'description'};
+ my $timestamp = $requesthash{$key}{'timestamp'};
+ my $entry = $cnum.':'.$ownername.':'.$ownerdom.':'.
+ $instcode.':'.$description;
+ if (ref($stillpending{$timestamp}) eq 'ARRAY') {
+ push(@{$stillpending{$timestamp}},$entry);
+ } else {
+ $stillpending{$timestamp} = [$entry];
+ }
+ }
+ unless ($disposition eq 'pending') {
+ my ($statusresult,$output) =
+ &update_coursereq_status(\%requesthash,$dom,$cnum,
+ $reqstatus,'domain',$ownerdom,
+ $ownername);
+ unless (&Apache::lonnet::del_dom($reqsnamespace,[$cnum.'_pending'],$dom) eq 'ok') {
+ $output .= &mt('An error occurred when removing the request for [_1] submitted by [_2] from the pending queue.',$instcode,$ownername.':'.$ownerdom).$linefeed;
+ }
+ }
+ }
+ }
+ }
+ foreach my $key (sort(keys(%newcids))) {
+ if (ref($newcids{$key}) eq 'ARRAY') {
+ $output .= "created course from queued request: $key - ".join(', ',@{$newcids{$key}}).$linefeed;
+ my $newcourse = &LONCAPA::escape($key.':'.$newcids{$key});
+ }
+ }
+ unless ($context eq 'auto') {
+ if (keys(%stillpending) > 0) {
+ $output .= '
'."\n".
+ ''."\n".
+ ''.
+ '
'.&mt('For the following requests, the requestor could [_1]not[_2] be validated as official course personnel, so the request remains in the pending queue.','','').' '.&mt('Requests may be left in the queue, or you can manually approve or reject them.').'