--- loncom/interface/selfenroll.pm 2008/06/30 17:04:11 1.6
+++ loncom/interface/selfenroll.pm 2008/07/11 13:43:53 1.9
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Allow users to self-enroll in a course
#
-# $Id: selfenroll.pm,v 1.6 2008/06/30 17:04:11 raeburn Exp $
+# $Id: selfenroll.pm,v 1.9 2008/07/11 13:43:53 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -61,13 +61,14 @@ sub handler {
text=>"Self-enroll"});
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enroll in course'));
if ($coursechk ne 'ok') {
- $r->print(&mt('Invalid domain or course number'));
+ $r->print('
'.&mt('Self-enrollment error').'
'.
+ ''.&mt('Invalid domain or course number').'');
$r->print(&Apache::loncommon::end_page());
return OK;
}
my ($cdom,$cnum,$canenroll,$selfenroll_types,$selfenroll_registered,
@cancreate,$knownuser,$selfenroll_access_start,$selfenroll_access_end,
- $selfenroll_section,%curr_role,%coursehash);
+ $selfenroll_section,$selfenroll_future,%curr_role,%coursehash,$cdomdesc);
my $now = time;
%coursehash = &Apache::lonnet::coursedescription($cid);
$cdom = $coursehash{'domain'};
@@ -80,21 +81,59 @@ sub handler {
if ($selfenroll_types ne '') {
my $start = $coursehash{'internal.selfenroll_start_date'};
my $end = $coursehash{'internal.selfenroll_end_date'};
- if (($start > 0 && $start < $now) && ($end > 0 && $end > $now)) {
+ if (($start > 0 && $start < $now) && (($end == 0) || ($end > 0 && $end > $now))) {
$canenroll = 1;
+ } elsif (($end == 0) || ($end > 0 && $end > $now)) {
+ if ($start > $now) {
+ $selfenroll_future = &Apache::lonlocal::locallocaltime($start);
+ }
}
}
+ $knownuser = &user_is_known();
if (!$canenroll) {
- $r->print(&mt('Self-enrollment is not currently available for this course.').'
');
+ $r->print(''.&mt('Self-enrollment unavailable').'
'.
+ &mt('Self-enrollment is not currently available for this course.').
+ '
');
+ if ($selfenroll_types ne '') {
+ if ($selfenroll_future ne '') {
+ if ($selfenroll_types eq '*') {
+ $r->print(&mt('Self-enrollment will become available starting [_1], and will be available to all LON-CAPA users.',$selfenroll_future).'
');
+ } else {
+ my ($enrolltypes,$longtypes,$alldoms);
+ if ($knownuser) {
+ &get_selfenroll_filters($selfenroll_types,$env{'user.domain'});
+ my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
+ if (ref($enrolltypes) eq 'HASH') {
+ if (ref($enrolltypes->{$env{'user.domain'}}) eq 'ARRAY') {
+ if (grep(/^any$/,@{$enrolltypes->{$env{'user.domain'}}})) {
+ $r->print(&mt('Self-enrollment will become available starting [_1], and will be available to all LON-CAPA users at your institution ([_2]).',
+ $selfenroll_future,$domdesc).'
');
+
+ } else {
+ if (&user_can_selfenroll($env{'user.domain'},
+ $env{'user.name'},
+ $enrolltypes->{$env{'user.domain'}})) {
+ $r->print(&mt('Self-enrollment will become available starting [_1]; please enroll at that time.',$selfenroll_future));
+ } else {
+ $r->print(&mt('Although self-enrollment will become available starting [_1], you are ineligible for enrollment.',$selfenroll_future).'
');
+ $r->print(&print_selfenroll_types($longtypes,$env{'user.domain'}));
+ }
+ }
+ }
+ }
+ } else {
+ $r->print(&mt('Self-enrollment will become available starting [_1].',
+ $selfenroll_future).'
');
+ $r->print(&print_selfenroll_types($longtypes));
+ }
+ }
+ }
+ }
}
- $knownuser = &user_is_known();
if ($knownuser) {
foreach my $key (keys(%env)) {
if ($key =~ m-^user\.role\.st\./$cdom/$cnum/?(\w*)$-) {
my $sec = $1;
- if ($sec eq '') {
- $sec = &mt('none');
- }
my ($start,$end) = split(/\./,$env{$key});
my $status = 'active';
if (($end) && ($end<=$now)) {
@@ -106,6 +145,9 @@ sub handler {
if ($status eq 'active' || $status eq 'future') {
$curr_role{'status'} = $status;
$curr_role{'section'} = $sec;
+ if ($curr_role{'section'} eq '') {
+ $curr_role{'section'} = &mt('none');
+ }
$curr_role{'start'} = &Apache::lonlocal::locallocaltime($start);
$curr_role{'role'} = 'st./'.$cdom.'/'.$cnum;
if ($sec ne '') {
@@ -134,7 +176,9 @@ sub handler {
my $missing_formitem = &mt('The link to the requested page could not be followed.')."\\n".&mt('The placeholder for the courseID is absent.');
if ($knownuser) {
if (keys(%curr_role)) {
- $r->print(&has_role(%curr_role));
+ $r->print(''.&mt('Self-enrollment unavailable').'
'.
+ ''.&has_role(%curr_role).'');
+ $r->print(&Apache::loncommon::end_page());
return OK;
}
&process_self_enroll($r,$cdom,$cnum,$selfenroll_types,$selfenroll_registered,
@@ -166,7 +210,8 @@ function getIndexByName(item) {
}
END
- $r->print(&mt('You need to be logged into LON-CAPA to self-enroll in a course.').'- '.&mt('If you have an account in LON-CAPA, [_1]log-in[_2].','','').'
');
+ $r->print(''.&mt('LON-CAPA account required').'
'.
+ &mt('You need to be logged into LON-CAPA to self-enroll in a course.').'- '.&mt('If you have an account in LON-CAPA, [_1]log-in[_2].','','').'
');
if (@cancreate > 1) {
$r->print('- '.&mt('Otherwise:').'
');
my $count = 0;
@@ -196,20 +241,24 @@ END
}
}
if ($selfenroll_types eq '*') {
- $r->print('
'.&mt('You will have an opportunity to self enroll in the course once the account has been created.').'
');
+ $r->print('
'.&mt('You will be able to self enroll in this course once the account has been created.').'
');
} else {
$r->print('');
my ($enrolltypes,$longtypes,$alldoms) =
- &get_selfenroll_filters($selfenroll_types,$cdom);
- $r->print(&print_selfenroll_types($longtypes,$cdom));
+ &get_selfenroll_filters($selfenroll_types);
+ $r->print(&print_selfenroll_types($longtypes));
}
} else {
- $r->print(&mt('You must [_1]log-in[_2] to LON-CAPA with an existing account to be able to enroll in this course, as account creation is not permitted when self-enrolling.','',''));
+ my $cdomdesc = &Apache::lonnet::domain($cdom,'description');
+ $r->print(''.&mt('LON-CAPA account required').'
');
+ $r->print(&mt('You must [_1]log-in[_2] to LON-CAPA with an existing account to be able to enroll in this course, as account creation at this institution ([_3]) is not permitted when self-enrolling.','','',$cdomdesc));
if ($selfenroll_types ne '*') {
my ($enrolltypes,$longtypes,$alldoms) =
&get_selfenroll_filters($selfenroll_types);
- $r->print('
'.&print_selfenroll_types($longtypes));
+ $r->print('
'.&print_selfenroll_types($longtypes));
}
+ my $displayurl = &escape($firsturl);
+ $r->print(&mt('Submit a request to the LON-CAPA [_1]helpdesk[_2] for [_3] if you require assistance.','','',$cdomdesc));
}
$r->print('';
@@ -409,10 +475,27 @@ sub get_selfenroll_filters {
my ($othertitle,$usertypes,$types) =
&Apache::loncommon::sorted_inst_types($selfdom);
if (ref($usertypes) eq 'HASH') {
- $usertypes->{'any'} = &mt('any');
- $usertypes->{'other'} = &mt('other');
- @{$enrolltypes{$selfdom}} = @types;
- @{$longtypes{$selfdom}} = map {$usertypes->{$_}} @types;
+ my $anytype = 1;
+ foreach my $key (keys(%{$usertypes})) {
+ if (!grep(/^\Q$key\E$/,@types)) {
+ $anytype = 0;
+ last;
+ }
+ }
+ if ($anytype) {
+ if (!(grep(/^other$/,@types))) {
+ $anytype = 0;
+ }
+ }
+ $usertypes->{'any'} = &mt('Any users');
+ $usertypes->{'other'} = &mt('Others');
+ if ($anytype) {
+ @{$enrolltypes{$selfdom}} = ('any');
+ } else {
+ @{$enrolltypes{$selfdom}} = @types;
+ }
+ @{$longtypes{$selfdom}} =
+ map {$usertypes->{$_}} @{$enrolltypes{$selfdom}}
}
}
}
@@ -424,25 +507,27 @@ sub print_selfenroll_types {
my ($longtypes,$domain) = @_;
my $output;
if (ref($longtypes) eq 'HASH') {
- if (keys(%{$longtypes}) > 0) {
- if ($domain ne '') {
- if (ref($longtypes->{$domain}) eq 'ARRAY') {
- if (grep(/^any$/,@{$longtypes->{$domain}})) {
- $output = &mt('Self-enrollment in this course is only available to users in domain "[_1]".',$domain);
- } else {
- my $status_str = join(', ',@{$longtypes->{$domain}});
- $output = &mt('Self-enrollment in this course is only available to users in domain "[_1]" who have the following status: "[_2]".',$domain,$status_str);
- }
+ if ($domain ne '') {
+ my $domdesc = &Apache::lonnet::domain($domain,'description');
+ if (ref($longtypes->{$domain}) eq 'ARRAY') {
+ if (grep(/^any$/,@{$longtypes->{$domain}})) {
+ $output = &mt('Self-enrollment in this course is available to any user affiliated with [_1].',$domdesc);
+ } else {
+ my $status_str = join(', ',@{$longtypes->{$domain}});
+ $output = &mt('Self-enrollment in this course is only available to users affiliated with [_1] who have the following status: "[_2]".',$domdesc,$status_str);
}
} else {
- $output = &mt('Self-enrollment in this course is only available to users in the following domains (with the following status):').' ';
- foreach my $selfdom (sort(keys(%{$longtypes}))) {
- if (ref($longtypes->{$selfdom}) eq 'ARRAY') {
- $output .= '- '.$selfdom.': '.join(', ',@{$longtypes->{$selfdom}}).'
';
- }
+ $output = &mt('Self-enrollment is not currently available for this course for users affiliated with [_1].',$domdesc);
+ }
+ } elsif (keys(%{$longtypes}) > 0) {
+ $output = &mt('Self-enrollment in this course is only available to users affiliated with the following institutions, and who have the required status:').' ';
+ foreach my $selfdom (sort(keys(%{$longtypes}))) {
+ my $selfdomdesc = &Apache::lonnet::domain($selfdom,'description');
+ if (ref($longtypes->{$selfdom}) eq 'ARRAY') {
+ $output .= '- '.$selfdomdesc.': '.join(', ',@{$longtypes->{$selfdom}}).'
';
}
- $output .= '
';
}
+ $output .= '
';
} else {
$output = &mt('Self-enrollment is not currently available for this course.');
}