'.
- &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 'valid') {
+ &mt('No course was found matching your choice of institutional course category.');
+ if ($codechk ne '') {
+ $message .= ' '.$codechk;
+ }
+ $message .= '
';
$prev = 'crstype';
}
$r->print($message);
@@ -818,7 +1016,7 @@ sub print_request_form {
$r->print(&courseinfo_form($dom,$formname,$crstype,$next));
}
} elsif ($prev eq 'codepick') {
- if ($env{'form.instcode'} eq '') {
+ if ($instcode eq '') {
$prev = $states->{$action}[$page-2];
}
$r->print(&courseinfo_form($dom,$formname,$crstype,$next));
@@ -828,10 +1026,84 @@ sub print_request_form {
\%cat_order,\@code_order);
}
$r->print(&print_enrollment_menu($formname,$instcode,$dom,\@codetitles,
- \%cat_titles,\%cat_order,\@code_order));
+ \%cat_titles,\%cat_order,\@code_order,
+ $invalidcrosslist));
} elsif ($state eq 'personnel') {
- $r->print(&print_personnel_menu($dom,$formname,$crstype));
+ $r->print(&print_personnel_menu($dom,$formname,$crstype,$invalidcrosslist));
} elsif ($state eq 'review') {
+ my (%alerts,%rulematch,%inst_results,%curr_rules,%got_rules,%disallowmsg);
+ my $now = time;
+ for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
+ my $personname = $env{'form.person_'.$i.'_uname'};
+ my $persondom = $env{'form.person_'.$i.'_dom'};
+ if (($personname =~ /^$match_username$/) &&
+ ($persondom =~ /^$match_domain$/)) {
+ if (&Apache::lonnet::domain($persondom)) {
+ my $personhome =
+ &Apache::lonnet::homeserver($personname,$persondom);
+ if ($personhome eq 'no_host') {
+ if ($persondom ne $dom) {
+ my $skipuser = 1;
+ if ($env{'user.role.dc./'.$persondom.'/'}) {
+ my ($start,$end) = split('.',$env{'user.role.dc./'.$persondom.'/'});
+ if (((!$start) || ($start < $now)) &&
+ ((!$end) || ($end > $now))) {
+ $skipuser = 0;
+ }
+ }
+ if ($skipuser) {
+ push(@disallowed,$i);
+ $disallowmsg{$i} = &mt('[_1] was excluded because new users need be from the course domain',''.$personname.':'.$persondom.'');
+ next;
+ }
+ }
+ if (&get_cancreate_status($persondom,$personname,$dom)) {
+ my ($allowed,$msg) =
+ &check_newuser_rules($persondom,$personname,
+ \%alerts,\%rulematch,\%inst_results,
+ \%curr_rules,\%got_rules);
+ if ($allowed) {
+ if (ref($inst_results{$personname.':'.$persondom}) eq 'HASH') {
+ if ($inst_results{$personname.':'.$persondom}{'lastname'} ne '') {
+ $env{'form.person_'.$i.'_lastname'} = $inst_results{$personname.':'.$persondom}{'lastname'};
+ }
+ if ($inst_results{$personname.':'.$persondom}{'firstname'} ne '') {
+ $env{'form.person_'.$i.'_firstname'} = $inst_results{$personname.':'.$persondom}{'firstname'};
+ }
+ if ($inst_results{$personname.':'.$persondom}{'permanentemail'} ne '') {
+ $env{'form.person_'.$i.'_emailaddr'} = $inst_results{$personname.':'.$persondom}{'permanentemail'};
+ }
+ }
+ } else {
+ push(@disallowed,$i);
+ $disallowmsg{$i} = &mt('[_1] was excluded because the username violated format rules for the domain',''.$personname.':'.$persondom.'');
+ }
+ } else {
+ push(@disallowed,$i);
+ $disallowmsg{$i} = &mt('[_1] was excluded because you may not request new users in the domain',''.$personname.':'.$persondom.'');
+ }
+ } else {
+ my %userenv =
+ &Apache::lonnet::userenvironment($persondom,$personname,'lastname','firstname','permanentemail');
+ if ($env{'form.person_'.$i.'_lastname'} eq '') {
+ $env{'form.person_'.$i.'_lastname'} = $userenv{'lastname'};
+ }
+ if ($env{'form.person_'.$i.'_firstname'} eq '') {
+ $env{'form.person_'.$i.'_firstname'} = $userenv{'firstname'};
+ }
+ if ($env{'form.person_'.$i.'_emailaddr'} eq '') {
+ $env{'form.person_'.$i.'_emailaddr'} = $userenv{'permanentemail'};
+ }
+ }
+ } elsif ($personname ne '') {
+ push(@disallowed,$i);
+ $disallowmsg{$i} = &mt('[_1] was excluded because the domain is invalid',''.$personname.':'.$persondom.'');
+ }
+ } elsif ($personname ne '') {
+ push(@disallowed,$i);
+ $disallowmsg{$i} = &mt('[_1] was excluded because the username or domain is invalid.',''.$personname.':'.$persondom.'');
+ }
+ }
my $cnum;
if ($env{'form.origcnum'} =~ /^($match_courseid)$/) {
$cnum = $env{'form.origcnum'};
@@ -840,9 +1112,8 @@ sub print_request_form {
}
&Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
\%cat_order,\@code_order);
- $r->print('
'.&mt('Review the details of the course request before submission.').'
'."\n".
@@ -1135,6 +1522,21 @@ sub print_personnel_menu {
return $output;
}
+sub current_lc_sections {
+ my @currsecs;
+ if ($env{'form.sectotal'}) {
+ for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
+ if (defined($env{'form.loncapasec_'.$i})) {
+ my $lcsec = $env{'form.loncapasec_'.$i};
+ unless (grep(/^\Q$lcsec\E$/,@currsecs)) {
+ push(@currsecs,$lcsec);
+ }
+ }
+ }
+ }
+ return @currsecs;
+}
+
sub print_request_status {
my ($dom) = @_;
my %statusinfo = &Apache::lonnet::dump('courserequests',$env{'user.domain'},
@@ -1243,8 +1645,7 @@ sub print_request_status {
$output .= '
'.&mt('You have no matching course requests awaiting approval by a Domain Coordinator or held in a queue pending administrative action at your institution.').'
';
}
$output .= '
-
-';
+ ';
return $output;
}
@@ -1350,13 +1751,17 @@ sub print_request_logs {
}
sub print_review {
- my ($formname,$dom,$codetitles,$cat_titles,$cat_order,$code_order) = @_;
+ my ($dom,$codetitles,$cat_titles,$cat_order,$code_order,$uname,$udom,
+ $disallowed,$disallowmsg) = @_;
my ($types,$typename) = &course_types();
my ($owner,$ownername,$owneremail);
- $owner = $env{'user.name'}.':'.$env{'user.domain'};
- $ownername = &Apache::loncommon::plainname($env{'user.name'},
- $env{'user.domain'},'first');
- my %emails = &Apache::loncommon::getemails();
+ if ($uname eq '' || $udom eq '') {
+ $uname = $env{'user.name'};
+ $udom = $env{'user.domain'};
+ }
+ $owner = $uname.':'.$udom;
+ $ownername = &Apache::loncommon::plainname($uname,$udom,'first');
+ my %emails = &Apache::loncommon::getemails($uname,$udom);
foreach my $email ('permanentemail','critnotification','notification') {
$owneremail = $emails{$email};
last if ($owneremail ne '');
@@ -1525,6 +1930,9 @@ sub print_review {
'
'.&mt('None').'
';
for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
if ($env{'form.person_'.$i.'_uname'} ne '') {
+ if (ref($disallowed) eq 'ARRAY') {
+ next if (grep(/^$i$/,@{$disallowed}));
+ }
my @allsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
my $newsec = $env{'form.person_'.$i.'_newsec'};
$newsec =~ s/^\s+//;
@@ -1549,18 +1957,30 @@ sub print_review {
if ($env{'form.person_'.$i.'_role'} eq 'cc') {
$showsec = &mt('None');
}
+ my $role = $env{'form.person_'.$i.'_role'};
$personnel_values .=
'
'."\n";
+ &clone_form($dom,$formname,$crstype).
+ &Apache::lonhtmlcommon::end_pick_box().''."\n";
return $output;
}
@@ -1651,13 +2080,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;
}
@@ -2007,7 +2433,7 @@ 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') {
@@ -2019,6 +2445,7 @@ sub print_request_outcome {
} else {
$output = &mt('Unrecognized course type: [_1]',$crstype);
}
+ $storeresult = 'notpermitted';
} else {
my ($disposition,$message,$reqstatus);
my %reqhash = (
@@ -2069,6 +2496,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);
@@ -2086,15 +2514,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;
@@ -2112,9 +2543,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;
@@ -2135,7 +2567,7 @@ sub print_request_outcome {
}
}
}
- my ($storeresult,$statusresult);
+ my ($statusresult);
if ($requestkey =~ /^($match_domain)_($match_courseid)$/) {
$storeresult = &Apache::lonnet::store_userdata(\%reqhash,$requestkey,
'courserequests');
@@ -2143,7 +2575,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';
@@ -2152,7 +2584,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') {
@@ -2163,6 +2595,117 @@ sub print_request_outcome {
$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;
}
@@ -2326,11 +2869,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'};
@@ -2432,12 +2978,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') {