'.
- &mt('No course was found matching your choice of institutional course category.');
- if ($code_chk ne '') {
- $message .= ' '.$code_chk;
- }
- $message .= '
';
- }
+ if ($checkedcode) {
+ if ($codechk eq 'valid') {
+ $message = '
'.
- &mt('No course was found matching your choice of institutional course category.');
- }
- unless ($code_chk eq 'ok') {
+ &mt('No course was found matching your choice of institutional course category.');
+ if ($codechk ne '') {
+ $message .= ' '.$codechk;
+ }
+ $message .= '
'."\n";
return $output;
}
@@ -1629,13 +1888,11 @@ sub clone_form {
&Apache::loncommon::selectcourse_link($formname,'clonecrs','clonedom','','','',$type);
my %lt = &clone_text();
my $output .=
- &Apache::lonhtmlcommon::start_pick_box().
&Apache::lonhtmlcommon::row_title($lt{'cid'}).''.&Apache::lonhtmlcommon::row_closure(1).''.
- $cloneform.''.&Apache::lonhtmlcommon::row_closure().
+ $cloneform.''.&Apache::lonhtmlcommon::row_closure(1).
&Apache::lonhtmlcommon::row_title($lt{'dsh'}).' '.
''.
- &Apache::lonhtmlcommon::row_closure(1).
- &Apache::lonhtmlcommon::end_pick_box();
+ &Apache::lonhtmlcommon::row_closure(1);
return $output;
}
@@ -1749,17 +2005,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 +2080,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";
@@ -1835,8 +2123,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'};
}
}
@@ -1902,17 +2193,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'};
@@ -1958,18 +2241,19 @@ sub print_request_outcome {
accessend => $accessend,
personnel => \%personnel,
};
- my @inststatuses;
+ my (@inststatuses,$storeresult,$creationresult);
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 {
$output = &mt('Unrecognized course type: [_1]',$crstype);
}
+ $storeresult = 'notpermitted';
} else {
my ($disposition,$message,$reqstatus);
my %reqhash = (
@@ -1986,7 +2270,7 @@ sub print_request_outcome {
$disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
$dom,$crstype,$limit,\$message);
} elsif ($val eq 'validate') {
- my $inststatuslist;
+ my ($inststatuslist,$validationchk,$validation);
if (@inststatuses > 0) {
$inststatuslist = join(',',@inststatuses);
}
@@ -1994,23 +2278,20 @@ sub print_request_outcome {
if (@instsections > 0) {
$instseclist = join(',',@instsections);
}
- my $validation =
- &Apache::lonnet::auto_validate_instcode('',$dom,$instcode,
- $env{'user.name'}.':'.$env{'user.domain'},$inststatuslist,
- $instseclist);
- if ($validation eq 'valid') {
- $disposition = 'process';
- } elsif ($validation eq 'rejected') {
- $disposition = 'rejected';
- } elsif ($validation eq 'pending') {
- $disposition = 'pending';
- } elsif ($disposition eq 'approval') {
- $disposition = 'approval';
- } elsif ($disposition =~ /^error(.*)$/) {
+ $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 = 'approval';
+ $disposition = $validation;
}
} else {
$disposition = 'approval';
@@ -2023,6 +2304,7 @@ sub print_request_outcome {
if ($message) {
$output .= '
'.$message.'
';
}
+ $storeresult = 'rejected';
} elsif ($disposition eq 'process') {
my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg,%longroles);
@@ -2040,15 +2322,18 @@ sub print_request_outcome {
if ($result eq 'created') {
$disposition = 'created';
$reqstatus = 'created';
- $output = &mt('Your course request has been processed and the course has been created.').
- ' '.
- &mt('You will need to logout and log-in again to be able to select a role in the course.');
+ my $role_result = &update_requestors_roles($dom,$cnum,$crstype,$details,
+ \%longroles);
+ $output = '
'.&mt('Your course request has been processed and the course has been created.').
+ ' '.$role_result.'
';
+ $creationresult = 'created';
} else {
$output = ''.
&mt('An error occurred when processing your course request.').
' '.
&mt('You may want to review the request details and submit the request again.').
'';
+ $creationresult = 'error';
}
} else {
my $requestid = $cnum.'_'.$disposition;
@@ -2066,9 +2351,10 @@ sub print_request_outcome {
$env{'user.domain'},$env{'user.name'});
if ($userreqhash{$statuskey} ne '') {
$modified = 1;
- my %queuehash = &Apache::lonnet::get_dom('courserequestqueue',
- [$cnum.'_approval',
- $cnum.'_pending'],$dom);
+ 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;
@@ -2089,7 +2375,7 @@ sub print_request_outcome {
}
}
}
- my ($storeresult,$statusresult);
+ my ($statusresult);
if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
$storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
'courserequests');
@@ -2097,7 +2383,7 @@ sub print_request_outcome {
my %status = (
'status:'.$dom.':'.$cnum => $reqstatus,
);
- $statusresult = &Apache::lonnet::put('courserequests',\%status);
+ $statusresult = &Apache::lonnet::put('courserequests',\%status);
}
} else {
$storeresult = 'error: invalid requestkey format';
@@ -2106,7 +2392,7 @@ sub print_request_outcome {
$output .= ''.&mt('An error occurred saving a record of the details of your request: [_1].',$storeresult).' ';
&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).' ';
+ $output .= ''.&mt('An error occurred saving a record of the status of your request: [_1].',$statusresult).' ';
&Apache::lonnet::logthis("Error saving course request status for $requestkey (for $env{'user.name'}:$env{'user.domain'}) - $statusresult");
}
if ($modified && $queued && $storeresult eq 'ok') {
@@ -2114,8 +2400,119 @@ sub print_request_outcome {
¬ification_information($disposition,$req_notifylist,$cnum,$now);
}
if ($validationerror ne '') {
- $output .= ''.&mt('An error occurred validating your request with institutional data sources: {_1].',$validationerror).'';
+ $output .= ''.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'';
+ }
+ }
+ if ($creationresult ne '') {
+ return ($creationresult,$output);
+ } else {
+ return ($storeresult,$output);
+ }
+}
+
+sub update_requestors_roles {
+ my ($dom,$cnum,$crstype,$details,$longroles) = @_;
+ my $now = time;
+ my ($active,$future,$numactive,$numfuture,$output);
+ my $owner = $env{'user.name'}.':'.$env{'user.domain'};
+ if (ref($details) eq 'HASH') {
+ if (ref($details->{'personnel'}) eq 'HASH') {
+ if (ref($details->{'personnel'}{$owner}) eq 'HASH') {
+ my @roles;
+ if (ref($details->{'personnel'}{$owner}{'roles'}) eq 'ARRAY') {
+ @roles = sort(@{$details->{'personnel'}{$owner}{'roles'}});
+ unless (grep(/^cc$/,@roles)) {
+ push(@roles,'cc');
+ }
+ } else {
+ @roles = ('cc');
+ }
+ foreach my $role (@roles) {
+ my $start = $now;
+ my $end = '0';
+ if ($role eq 'st') {
+ if ($details->{'accessstart'} ne '') {
+ $start = $details->{'accessstart'};
+ }
+ if ($details->{'accessend'} ne '') {
+ $end = $details->{'accessend'};
+ }
+ }
+ my @usecs;
+ if ($role ne 'cc') {
+ if (ref($details->{'personnel'}{$owner}{$role}{'usec'}) eq 'ARRAY') {
+ @usecs = @{$details->{'personnel'}{$owner}{$role}{'usec'}};
+ }
+ }
+ if ($role eq 'st') {
+ if (@usecs > 1) {
+ my $firstsec = $usecs[0];
+ @usecs = ($firstsec);
+ }
+ }
+ if (@usecs == 0) {
+ push(@usecs,'');
+ }
+ foreach my $usec (@usecs) {
+ my (%userroles,%newrole,%newgroups,$spec,$area);
+ my $area = '/'.$dom.'/'.$cnum;
+ my $spec = $role.'.'.$area;
+ if ($usec ne '') {
+ $spec .= '/'.$usec;
+ $area .= '/'.$usec;
+ }
+ if ($role =~ /^cr\//) {
+ &Apache::lonnet::custom_roleprivs(\%newrole,$role,$dom,
+ $cnum,$spec,$area);
+ } else {
+ &Apache::lonnet::standard_roleprivs(\%newrole,$role,$dom,
+ $spec,$cnum,$area);
+ }
+ &Apache::lonnet::set_userprivs(\%userroles,\%newrole,
+ \%newgroups);
+ $userroles{'user.role.'.$spec} = $start.'.'.$end;
+ &Apache::lonnet::appenv(\%userroles,[$role,'cm']);
+ if (($end == 0) || ($end > $now)) {
+ my $showrole = $role;
+ if ($role =~ /^cr\//) {
+ $showrole = &Apache::lonnet::plaintext($role,$crstype);
+ } elsif (ref($longroles) eq 'HASH') {
+ if ($longroles->{$role} ne '') {
+ $showrole = $longroles->{$role};
+ }
+ }
+ if ($start <= $now) {
+ $active .= '
'.$showrole;
+ if ($usec ne '') {
+ $future .= ' - '.&mt('section:').' '.$usec;
+ }
+ $future .= '
';
+ $numfuture ++;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ if ($active) {
+ if ($numactive == 1) {
+ $output = &mt('Use the following link to enter the course:');
+ } else {
+ $output = &mt('Use the following links to your new roles to enter the course:');
}
+ $output .= '
'.$active.'
';
+ }
+ if ($future) {
+ $output .= &mt('The following course [quant,_1,role] will become available for selection from your [_2]roles page[_3], once the default student access start date - [_4] - has been reached:',$numfuture,'','',&Apache::lonlocal::locallocaltime($details->{'accessstart'})).
+ '
'.$future.'
';
}
return $output;
}
@@ -2161,7 +2558,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'},
@@ -2174,7 +2571,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 {
@@ -2227,11 +2624,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_');
}
@@ -2274,11 +2677,14 @@ sub check_autolimit {
}
sub retrieve_settings {
- my ($dom,$cnum) = @_;
- my ($result,%reqinfo) = &get_request_settings($dom,$cnum);
+ my ($dom,$cnum,$udom,$uname) = @_;
+ if ($udom eq '' || $uname eq '') {
+ $udom = $env{'user.domain'};
+ $uname = $env{'user.name'};
+ }
+ my ($result,%reqinfo) = &get_request_settings($dom,$cnum,$udom,$uname);
if ($result eq 'ok') {
- if (($env{'user.name'} eq $reqinfo{'owner'}) &&
- ($env{'user.domain'} eq $reqinfo{'domain'})) {
+ if (($udom eq $reqinfo{'domain'}) && ($uname eq $reqinfo{'owner'})) {
$env{'form.chome'} = $reqinfo{'coursehome'};
$env{'form.cdescr'} = $reqinfo{'cdescr'};
$env{'form.crstype'} = $reqinfo{'crstype'};
@@ -2301,17 +2707,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);
}
@@ -2319,15 +2726,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);
+ }
}
}
}
@@ -2353,7 +2764,7 @@ sub retrieve_settings {
if (grep(/^\Q$sec\E/,@currsec)) {
$env{'form.person_'.$i.'_sec'} = $sec;
} else {
- push (@newsecs,$sec);
+ push(@newsecs,$sec);
}
}
}
@@ -2375,12 +2786,11 @@ sub retrieve_settings {
}
sub get_request_settings {
- my ($dom,$cnum) = @_;
+ my ($dom,$cnum,$udom,$uname) = @_;
my $requestkey = $dom.'_'.$cnum;
my ($result,%reqinfo);
if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
- my %history = &Apache::lonnet::restore($requestkey,'courserequests',
- $env{'user.domain'},$env{'user.name'});
+ my %history = &Apache::lonnet::restore($requestkey,'courserequests',$udom,$uname);
my $disposition = $history{'disposition'};
if (($disposition eq 'approval') || ($disposition eq 'pending')) {
if (ref($history{'details'}) eq 'HASH') {
@@ -2399,26 +2809,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};
}
}
}