'.
@@ -1749,17 +1771,47 @@ sub coursecode_form {
sub get_course_dom {
my $codedom = &Apache::lonnet::default_login_domain();
+ if ($env{'form.showdom'} ne '') {
+ if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
+ return $env{'form.showdom'};
+ }
+ }
if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
+ my ($types,$typename) = &course_types();
+ if (ref($types) eq 'ARRAY') {
+ foreach my $type (@{$types}) {
+ if (&Apache::lonnet::usertools_access($env{'user.name'},
+ $env{'user.domain'},$type,
+ undef,'requestcourses')) {
+ return $env{'user.domain'};
+ }
+ }
+ my @possible_doms;
+ foreach my $type (@{$types}) {
+ my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
+ if ($dom_str ne '') {
+ my @domains = split(',',$dom_str);
+ foreach my $entry (@domains) {
+ my ($extdom,$extopt) = split(':',$entry);
+ if ($extdom eq $env{'request.role.domain'}) {
+ return $extdom;
+ }
+ unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
+ push(@possible_doms,$extdom);
+ }
+ }
+ }
+ }
+ if (@possible_doms) {
+ @possible_doms = sort(@possible_doms);
+ return $possible_doms[0];
+ }
+ }
$codedom = $env{'user.domain'};
if ($env{'request.role.domain'} ne '') {
$codedom = $env{'request.role.domain'};
}
}
- if ($env{'form.showdom'} ne '') {
- if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
- $codedom = $env{'form.showdom'};
- }
- }
return $codedom;
}
@@ -1794,6 +1846,8 @@ sub print_request_outcome {
my ($dom,$codetitles,$code_order) = @_;
my ($output,$cnum,$now,$req_notifylist,$crstype,$enrollstart,$enrollend,
%sections,%crosslistings,%personnel,@baduname,@missingdom,%domconfig,);
+ my $sectotal = $env{'form.sectotal'};
+ my $crosslisttotal = 0;
$cnum = $env{'form.cnum'};
unless ($cnum =~ /^$match_courseid$/) {
$output = &mt('Invalid LON-CAPA course number for the new course')."\n";
@@ -1808,6 +1862,7 @@ sub print_request_outcome {
}
$now = time;
$crstype = $env{'form.crstype'};
+ my @instsections;
if ($crstype eq 'official') {
if (&Apache::lonnet::auto_run('',$dom)) {
($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
@@ -1815,7 +1870,11 @@ sub print_request_outcome {
for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
if ($env{'form.sec_'.$i}) {
if ($env{'form.secnum_'.$i} ne '') {
- $sections{$i}{'inst'} = $env{'form.secnum_'.$i};
+ my $sec = $env{'form.secnum_'.$i};
+ $sections{$i}{'inst'} = $sec;
+ if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
+ push(@instsections,$sec);
+ }
$sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
}
}
@@ -1830,8 +1889,11 @@ sub print_request_outcome {
}
}
}
- $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'};
- $crosslistings{$i}{'inst'} = $xlistinfo;
+ $crosslistings{$i}{'instcode'} = $xlistinfo;
+ if ($xlistinfo ne '') {
+ $crosslisttotal ++;
+ }
+ $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'};
$crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
}
}
@@ -1897,17 +1959,9 @@ sub print_request_outcome {
if ($env{'form.autoadds'}) {
$autodrops = $env{'form.autoadds'};
}
- my $sectotal = 0;
- if ($env{'form.sectotal'}) {
- $sectotal = $env{'form.sectotal'};
- }
if ($env{'form.autoadds'}) {
$autodrops = $env{'form.autoadds'};
}
- my $crosslisttotal = 0;
- if ($env{'form.crosslisttotal'}) {
- $crosslisttotal = $env{'form.crosslisttotal'};
- }
my $instcode = '';
if (exists($env{'form.instcode'})) {
$instcode = $env{'form.instcode'};
@@ -1957,9 +2011,9 @@ sub print_request_outcome {
my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig);
if ($val eq '') {
if ($crstype eq 'official') {
- $output = &mt('You are not permitted to request creation of official courses');
+ $output = &mt('You are not permitted to request creation of official courses.');
} elsif ($crstype eq 'unofficial') {
- $output = &mt('You are not permitted to request creation of unofficial courses');
+ $output = &mt('You are not permitted to request creation of unofficial courses.');
} elsif ($crstype eq 'community') {
$output = &mt('You are not permitted to request creation of communities');
} else {
@@ -1973,6 +2027,7 @@ sub print_request_outcome {
details => $details,
);
my $requestkey = $dom.'_'.$cnum;
+ my $validationerror;
if ($val eq 'autolimit=') {
$disposition = 'process';
} elsif ($val =~ /^autolimit=(\d+)$/) {
@@ -1980,9 +2035,29 @@ sub print_request_outcome {
$disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
$dom,$crstype,$limit,\$message);
} elsif ($val eq 'validate') {
- $disposition =
- &Apache::lonnet::auto_courserequest_validation($dom,$details,
- \@inststatuses,\$message);
+ my ($inststatuslist,$validationchk,$validation);
+ if (@inststatuses > 0) {
+ $inststatuslist = join(',',@inststatuses);
+ }
+ my $instseclist;
+ if (@instsections > 0) {
+ $instseclist = join(',',@instsections);
+ }
+ $validationchk =
+ &Apache::lonnet::auto_courserequest_validation($dom,
+ $env{'user.name'}.':'.$env{'user.domain'},$crstype,
+ $inststatuslist,$instcode,$instseclist);
+ if ($validationchk =~ /:/) {
+ ($validation,$message) = split(':',$validationchk);
+ } else {
+ $validation = $validationchk;
+ }
+ if ($validation =~ /^error(.*)$/) {
+ $disposition = 'approval';
+ $validationerror = $1;
+ } else {
+ $disposition = $validation;
+ }
} else {
$disposition = 'approval';
}
@@ -2035,13 +2110,14 @@ sub print_request_outcome {
my $statuskey = 'status:'.$dom.':'.$cnum;
my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
$env{'user.domain'},$env{'user.name'});
- if (exists($userreqhash{$statuskey})) {
+ if ($userreqhash{$statuskey} ne '') {
$modified = 1;
- my %queuehash = &Apache::lonnet::get_dom('courserequestqueue',
- [$cnum.'_approval',
- $cnum.'_pending'],$dom);
- if ((exists($queuehash{$cnum.'_approval'})) ||
- (exists($queuehash{$cnum.'_pending'}))) {
+ my $uname = &Apache::lonnet::get_domainconfiguser($dom);
+ my %queuehash = &Apache::lonnet::get('courserequestqueue',
+ [$cnum.'_approval',
+ $cnum.'_pending'],$dom,$uname);
+ if (($queuehash{$cnum.'_approval'} ne '') ||
+ ($queuehash{$cnum.'_pending'} ne '')) {
$queued = 1;
}
}
@@ -2084,6 +2160,9 @@ sub print_request_outcome {
$output .= '
'.&mt('Your course request has been updated').'
'.
¬ification_information($disposition,$req_notifylist,$cnum,$now);
}
+ if ($validationerror ne '') {
+ $output .= ''.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'';
+ }
}
return $output;
}
@@ -2111,12 +2190,16 @@ sub notification_information {
my $sender = $env{'user.name'}.':'.$env{'user.domain'};
&Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
}
- } else {
+ } elsif ($disposition eq 'pending') {
$output .= '
'.
&mt('Your request has been placed in a queue pending administrative action.').' '.
&mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").' '.
&mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
'
';
+ } else {
+ $output .= '
'.
+ &mt('Your request status is: [_1].',$disposition).
+ '
'
}
return $output;
}
@@ -2125,7 +2208,7 @@ sub get_processtype {
my ($dom,$crstype,$inststatuses,$domconfig) = @_;
return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
my (%userenv,%settings,$val);
- my @options = ('autolimit','validate','approve');
+ my @options = ('autolimit','validate','approval');
if ($dom eq $env{'user.domain'}) {
%userenv =
&Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
@@ -2138,7 +2221,7 @@ sub get_processtype {
if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
%settings = %{$domconfig->{'requestcourses'}};
if (ref($settings{$crstype}) eq 'HASH') {
- if (($env{'user.adv'}) && (exists($settings{$crstype}{'_LC_adv'}))) {
+ if (($env{'user.adv'}) && ($settings{$crstype}{'_LC_adv'} ne '')) {
$val = $settings{$crstype}{'_LC_adv'};
@{$inststatuses} = ('_LC_adv_');
} else {
@@ -2191,11 +2274,17 @@ sub get_processtype {
} else {
%userenv = &Apache::lonnet::userenvironment($env{'user.domain'},
$env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'});
- if ($userenv{'reqcrsotherdom'}) {
- my @doms = split(',',$userenv{'reqcrsotherdom'});
- my $optregex = join('|',@options);
- if (grep(/^\Q$dom\E:($optregex=?\d*)/,@doms)) {
- $val = $1;
+ 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_');
}
@@ -2265,17 +2354,18 @@ sub retrieve_settings {
$env{'form.autoadds'} = $reqinfo{'autoadds'};
$env{'form.autdrops'} = $reqinfo{'autodrops'};
$env{'form.instcode'} = $reqinfo{'instcode'};
- my %crscode = (
- instcode => $reqinfo{'instcode'},
- );
- &extract_instcode($dom,'instcode',\%crscode);
+ my $crscode = {
+ $cnum => $reqinfo{'instcode'},
+ };
+ &extract_instcode($dom,'instcode',$crscode,$cnum);
}
my @currsec;
if (ref($reqinfo{'sections'}) eq 'HASH') {
foreach my $i (sort(keys(%{$reqinfo{'sections'}}))) {
if (ref($reqinfo{'sections'}{$i}) eq 'HASH') {
- my $sec = $reqinfo{'sections'}{$i}{'inst'};;
+ my $sec = $reqinfo{'sections'}{$i}{'inst'};
$env{'form.secnum_'.$i} = $sec;
+ $env{'form.sec_'.$i} = '1';
if (!grep(/^\Q$sec\E$/,@currsec)) {
push(@currsec,$sec);
}
@@ -2283,15 +2373,19 @@ sub retrieve_settings {
}
}
}
- if (ref($reqinfo{'crosslistings'}) eq 'HASH') {
- foreach my $i (sort(keys(%{$reqinfo{'crosslistings'}}))) {
- if (ref($reqinfo{'crosslistings'}{$i}) eq 'HASH') {
- $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslistings'}{$i}{'loncapa'};
- my $xlistsec = $reqinfo{'crosslistings'}{$i}{'instsec'};
- my %crscode = (
- $i => $reqinfo{'crosslistings'}{$i}{'instcode'},
- );
- &extract_instcode($dom,'crosslist',\%crscode,$1,$xlistsec);
+ if (ref($reqinfo{'crosslists'}) eq 'HASH') {
+ foreach my $i (sort(keys(%{$reqinfo{'crosslists'}}))) {
+ if (ref($reqinfo{'crosslists'}{$i}) eq 'HASH') {
+ $env{'form.crosslist_'.$i} = '1';
+ $env{'form.crosslist_'.$i.'_instsec'} = $reqinfo{'crosslists'}{$i}{'instsec'};
+ $env{'form.crosslist_'.$i.'_lcsec'} = $reqinfo{'crosslists'}{$i}{'loncapa'};
+ if ($reqinfo{'crosslists'}{$i}{'instcode'} ne '') {
+ my $key = $cnum.$i;
+ my $crscode = {
+ $key => $reqinfo{'crosslists'}{$i}{'instcode'},
+ };
+ &extract_instcode($dom,'crosslist',$crscode,$key,$i);
+ }
}
}
}
@@ -2317,7 +2411,7 @@ sub retrieve_settings {
if (grep(/^\Q$sec\E/,@currsec)) {
$env{'form.person_'.$i.'_sec'} = $sec;
} else {
- push (@newsecs,$sec);
+ push(@newsecs,$sec);
}
}
}
@@ -2363,26 +2457,19 @@ sub get_request_settings {
}
sub extract_instcode {
- my ($cdom,$element,$crscodehashref,$counter,$xlistsec) = @_;
+ my ($cdom,$element,$crscode,$crskey,$counter) = @_;
my (%codes,@codetitles,%cat_titles,%cat_order);
- if (ref($crscodehashref) eq 'HASH') {
- if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscodehashref,
- \%codes,\@codetitles,\%cat_titles,\%cat_order) eq 'ok') {
+ if (&Apache::lonnet::auto_instcode_format('requests',$cdom,$crscode,\%codes,
+ \@codetitles,\%cat_titles,
+ \%cat_order) eq 'ok') {
+ if (ref($codes{$crskey}) eq 'HASH') {
if (@codetitles > 0) {
my $sel = $element;
if ($element eq 'crosslist') {
$sel .= '_'.$counter;
}
- my $lastitem = pop(@codetitles);
foreach my $title (@codetitles) {
- if (ref($cat_order{$title}) eq 'ARRAY') {
- if (@{$cat_order{$title}} > 0) {
- $env{'form.'.$sel.'_'.$title} = $cat_order{$title}[0];
- }
- }
- }
- if ($element eq 'crosslist') {
- $env{'form.'.$sel.'_'.$lastitem} = $xlistsec;
+ $env{'form.'.$sel.'_'.$title} = $codes{$crskey}{$title};
}
}
}