'.
+ &close_popup_form());
} elsif ($action eq 'log') {
$r->print(&coursereq_log('View request log',$jscript,$loaditems).$crumb);
}
@@ -741,8 +937,194 @@ END
return;
}
+sub enrollment_lcsec_js {
+ my %alerts = §ion_check_alerts();
+ my $secname = $alerts{'badsec'};
+ my $secnone = $alerts{'reserved'};
+ my $output = '
+function validateEnrollSections(formname,nextstate) {
+ var badsectotal = 0;
+ var reservedtotal = 0;
+ var secTest = "";
+';
+ for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
+ $output .= "
+ var selSec = 0;
+ for (var j=0; j "You need to change one or more LON-CAPA section names - none is a reserved word in the system, and may not be used.",
+ badsec => 'You need to change one or more LON-CAPA section names - names may only contain letters or numbers.',
+ separate => 'Separate multiple sections with a comma.'
+ );
+ return %lt;
+}
+
+sub section_check_javascript {
+ return <<"END";
+function validsection(field,mult) {
+ var str = field.value;
+ var badsec=0;
+ var reserved=0;
+ if (window.RegExp) {
+ var badsecnum=0;
+ var reservednum=0;
+ var pattern=/[^a-zA-Z0-9]/;
+ str = str.replace(/(^\\s*)|(\\s*\$)/gi,"");
+ str = str.replace(/[ ]{2,}/gi," ");
+ if (mult == '1') {
+ var sections = new Array();
+ sections = str.split(/\\s*[\\s,;:]\\s*/);
+ var i;
+ for (i=0; i 0) {
+ return 'badsec';
+ }
+ if (reservednum > 0) {
+ return 'reserved';
+ }
+ }
+ return;
+}
+END
+}
+
+sub close_popup_form {
+ my $close= &mt('Close Window');
+ return << "END";
+
+
+
+END
+}
+
+sub get_instcode {
+ my ($dom) = @_;
+ my ($instcode,$numtitles);
+ my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
+ &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
+ \%cat_order,\@code_order);
+ $numtitles = scalar(@codetitles);
+ if (@code_order > 0) {
+ my $message;
+ foreach my $item (@code_order) {
+ $instcode .= $env{'form.instcode_'.$item};
+ }
+ }
+ return ($instcode,$numtitles);
+}
+
sub print_request_form {
- my ($r,$action,$state,$page,$states,$dom) = @_;
+ my ($r,$action,$state,$page,$states,$dom,$newinstcode,$codechk,$checkedcode,
+ $invalidcrosslist) = @_;
my $formname = 'requestcrs';
my ($next,$prev,$message,$output,$codepicker,$crstype);
$prev = $states->{$action}[$page-1];
@@ -753,44 +1135,28 @@ sub print_request_form {
);
$crstype = $env{'form.crstype'};
$r->print('
');
- my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk);
+ my (@codetitles,%cat_titles,%cat_order,@code_order,$instcode,$code_chk,
+ @disallowed);
if ($crstype eq 'official') {
if ($env{'form.instcode'} ne '') {
$instcode = $env{'form.instcode'};
+ } elsif ($newinstcode ne '') {
+ $instcode = $newinstcode;
}
- }
- if ($prev eq 'codepick') {
- if ($crstype eq 'official') {
- &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
- \%cat_order,\@code_order);
- }
- if (@code_order > 0) {
- my $message;
- if ($instcode eq '') {
- foreach my $item (@code_order) {
- $instcode .= $env{'form.instcode_'.$item};
- }
- $r->print(''."\n");
- }
- if ($instcode ne '') {
- $code_chk = &Apache::lonnet::auto_validate_instcode('',$dom,$instcode);
- if ($code_chk eq 'valid') {
- $message = '
'.
- &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 +1184,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 +1194,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 +1280,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 +1695,23 @@ 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 ($env{'form.sec_'.$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 +1820,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 +1926,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,14 +2105,25 @@ sub print_review {
'
'.&mt('None').'
';
for (my $i=0; $i<$env{'form.persontotal'}; $i++) {
if ($env{'form.person_'.$i.'_uname'} ne '') {
- my @allsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
+ if (ref($disallowed) eq 'ARRAY') {
+ next if (grep(/^$i$/,@{$disallowed}));
+ }
+ my @officialsecs = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
+ my @allsecs;
+ foreach my $sec (@officialsecs) {
+ next unless ($sec =~ /\w/);
+ next if ($sec =~ /\W/);
+ next if ($sec eq 'none');
+ push(@allsecs,$sec);
+ }
my $newsec = $env{'form.person_'.$i.'_newsec'};
$newsec =~ s/^\s+//;
$newsec =~s/\s+$//;
- my @newsecs = split(/[\s,;]+/,$newsec);
+ my @newsecs = split(/\s*[\s,;:]\s*/,$newsec);
foreach my $sec (@newsecs) {
+ next unless ($sec =~ /\w/);
next if ($sec =~ /\W/);
- next if ($newsec eq 'none');
+ next if ($sec eq 'none');
if ($sec ne '') {
unless (grep(/^\Q$sec\E$/,@allsecs)) {
push(@allsecs,$sec);
@@ -1549,18 +2140,30 @@ sub print_review {
if ($env{'form.person_'.$i.'_role'} eq 'cc') {
$showsec = &mt('None');
}
+ my $role = $env{'form.person_'.$i.'_role'};
$personnel_values .=
'
');
}
@@ -1927,20 +2554,27 @@ sub print_request_outcome {
@{$personnel{$uname.':'.$udom}{$role}{'usec'}} = ();
} else {
my @currsec = &Apache::loncommon::get_env_multiple('form.person_'.$i.'_sec');
+ my @allsecs;
+ foreach my $sec (@currsec) {
+ next unless ($sec =~ /\w/);
+ next if ($sec =~ /\W/);
+ next if ($sec eq 'none');
+ push(@allsecs,$sec);
+ }
my $newsec = $env{'form.person_'.$i.'_newsec'};
$newsec =~ s/^\s+//;
$newsec =~s/\s+$//;
my @newsecs = split(/[\s,;]+/,$newsec);
foreach my $sec (@newsecs) {
next if ($sec =~ /\W/);
- next if ($newsec eq 'none');
+ next if ($sec eq 'none');
if ($sec ne '') {
- unless (grep(/^\Q$sec\E$/,@currsec)) {
- push(@currsec,$sec);
+ unless (grep(/^\Q$sec\E$/,@allsecs)) {
+ push(@allsecs,$sec);
}
}
}
- @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @currsec;
+ @{$personnel{$uname.':'.$udom}{$role}{'usec'}} = @allsecs;
}
}
} else {
@@ -2007,7 +2641,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 +2653,7 @@ sub print_request_outcome {
} else {
$output = &mt('Unrecognized course type: [_1]',$crstype);
}
+ $storeresult = 'notpermitted';
} else {
my ($disposition,$message,$reqstatus);
my %reqhash = (
@@ -2069,6 +2704,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 +2722,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 +2751,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 +2775,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 +2783,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 +2792,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 +2803,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 +3077,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 +3186,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') {