version 1.1, 2008/03/08 04:26:12
|
version 1.7, 2008/07/08 01:55:52
|
Line 66 sub handler {
|
Line 66 sub handler {
|
return OK; |
return OK; |
} |
} |
my ($cdom,$cnum,$canenroll,$selfenroll_types,$selfenroll_registered, |
my ($cdom,$cnum,$canenroll,$selfenroll_types,$selfenroll_registered, |
$cancreate,$knownuser,$selfenroll_access_start,$selfenroll_access_end, |
@cancreate,$knownuser,$selfenroll_access_start,$selfenroll_access_end, |
$selfenroll_section,%curr_role,%coursehash); |
$selfenroll_section,%curr_role,%coursehash); |
my $now = time; |
my $now = time; |
%coursehash = &Apache::lonnet::coursedescription($cid); |
%coursehash = &Apache::lonnet::coursedescription($cid); |
Line 92 sub handler {
|
Line 92 sub handler {
|
foreach my $key (keys(%env)) { |
foreach my $key (keys(%env)) { |
if ($key =~ m-^user\.role\.st\./$cdom/$cnum/?(\w*)$-) { |
if ($key =~ m-^user\.role\.st\./$cdom/$cnum/?(\w*)$-) { |
my $sec = $1; |
my $sec = $1; |
if ($sec eq '') { |
|
$sec = &mt('none'); |
|
} |
|
my ($start,$end) = split(/\./,$env{$key}); |
my ($start,$end) = split(/\./,$env{$key}); |
my $status = 'active'; |
my $status = 'active'; |
if (($end) && ($end<=$now)) { |
if (($end) && ($end<=$now)) { |
Line 106 sub handler {
|
Line 103 sub handler {
|
if ($status eq 'active' || $status eq 'future') { |
if ($status eq 'active' || $status eq 'future') { |
$curr_role{'status'} = $status; |
$curr_role{'status'} = $status; |
$curr_role{'section'} = $sec; |
$curr_role{'section'} = $sec; |
|
if ($curr_role{'section'} eq '') { |
|
$curr_role{'section'} = &mt('none'); |
|
} |
$curr_role{'start'} = &Apache::lonlocal::locallocaltime($start); |
$curr_role{'start'} = &Apache::lonlocal::locallocaltime($start); |
$curr_role{'role'} = 'st./'.$cdom.'/'.$cnum; |
$curr_role{'role'} = 'st./'.$cdom.'/'.$cnum; |
if ($sec ne '') { |
if ($sec ne '') { |
Line 122 sub handler {
|
Line 122 sub handler {
|
$r->print(&Apache::loncommon::end_page()); |
$r->print(&Apache::loncommon::end_page()); |
return OK; |
return OK; |
} |
} |
$cancreate = &can_create($cdom); |
@cancreate = &can_create($cdom); |
my ($login_path,$firsturl,$create_path,$sso_url,$missing_formitem); |
my ($login_path,$firsturl,$create_path,$sso_url,$missing_formitem); |
$login_path = '/adm/login'; |
$login_path = '/adm/login'; |
$firsturl= '/adm/selfenroll?cid='.$cid; |
$firsturl= '/adm/selfenroll?cid='.$cid; |
Line 140 sub handler {
|
Line 140 sub handler {
|
&process_self_enroll($r,$cdom,$cnum,$selfenroll_types,$selfenroll_registered, |
&process_self_enroll($r,$cdom,$cnum,$selfenroll_types,$selfenroll_registered, |
$selfenroll_access_start,$selfenroll_access_end, |
$selfenroll_access_start,$selfenroll_access_end, |
$selfenroll_section,$now); |
$selfenroll_section,$now); |
} elsif ($cancreate) { |
} elsif (@cancreate > 0) { |
$r->print(<<END); |
$r->print(<<END); |
<script type="text/javascript"> |
<script type="text/javascript"> |
function setPath(formaction,item,arg) { |
function setPath(formaction,item,arg) { |
Line 167 function getIndexByName(item) {
|
Line 167 function getIndexByName(item) {
|
</script> |
</script> |
END |
END |
$r->print(&mt('You need to be logged into LON-CAPA to self-enroll in a course.').'<ul><li>'.&mt('If you have an account in LON-CAPA, [_1]log-in[_2].','<a href="javascript:setPath('."'$login_path','firsturl','$firsturl'".')">','</a>').'</li>'); |
$r->print(&mt('You need to be logged into LON-CAPA to self-enroll in a course.').'<ul><li>'.&mt('If you have an account in LON-CAPA, [_1]log-in[_2].','<a href="javascript:setPath('."'$login_path','firsturl','$firsturl'".')">','</a>').'</li>'); |
if ($cancreate eq 'any') { |
if (@cancreate > 1) { |
$r->print('<li>'.&mt('Otherwise [_1]create an account[_2].','<a href="javascript:setPath('."'$create_path','courseid','$cid'".')">','</a>')); |
$r->print('<li>'.&mt('Otherwise:').'<br />'); |
} elsif ($cancreate eq 'login') { |
my $count = 0; |
$r->print('<li>'.&mt('Otherwise, if you have an institutional login, [_1]create an account[_2].','<a href="javascript:setPath('."'$create_path','courseid','$cid'".')">','</a>')); |
foreach my $type ('sso','login','email') { |
} elsif ($cancreate eq 'email') { |
if (($count > 0) && ($count <@cancreate)) { |
$r->print('<li>'.&mt('Otherwise, you will use an e-mail address to [_1]create an account[_2].','<a href="javascript:setPath('."'$create_path','courseid','$cid'".')">','</a>')); |
$r->print(' , '.&mt('or').'<br />'); |
} elsif ($cancreate eq 'sso') { |
} |
$r->print('<li>'.&mt("Otherwise, use your institution's [_1]single sign on page[_2] to log-in, then create an account.",'<a href="javascript:setPath('."'$sso_url','firsturl','$firsturl'".')">','</a>')); |
if (grep(/^$type$/,@cancreate)) { |
|
if ($type eq 'sso') { |
|
$r->print(' '.&mt("if you have an institutional log-in, use your institution's [_1]single sign on page[_2] to log-in, then create an account",'<a href="javascript:setPath('."'$sso_url','firsturl','$firsturl'".')">','</a>')); |
|
} elsif ($type eq 'login') { |
|
$r->print(' '.&mt('if you have an institutional login, [_1]create an account[_2]','<a href="javascript:setPath('."'$create_path','courseid','$cid'".')">','</a>')); |
|
} elsif ($type eq 'email') { |
|
$r->print(' '.&mt('you can use an e-mail address to [_1]create an account[_2]','<a href="javascript:setPath('."'$create_path','courseid','$cid'".')">','</a>')); |
|
} |
|
$count ++; |
|
} |
|
} |
|
$r->print('.<br />'); |
|
} else { |
|
if ($cancreate[0] eq 'login') { |
|
$r->print('<li>'.&mt('Otherwise, if you have an institutional login, [_1]create an account[_2].','<a href="javascript:setPath('."'$create_path','courseid','$cid'".')">','</a>')); |
|
} elsif ($cancreate[0] eq 'email') { |
|
$r->print('<li>'.&mt('Otherwise, you will use an e-mail address to [_1]create an account[_2].','<a href="javascript:setPath('."'$create_path','courseid','$cid'".')">','</a>')); |
|
} elsif ($cancreate[0] eq 'sso') { |
|
$r->print('<li>'.&mt("Otherwise, use your institution's [_1]single sign on page[_2] to log-in, then create an account.",'<a href="javascript:setPath('."'$sso_url','firsturl','$firsturl'".')">','</a>')); |
|
} |
} |
} |
if ($selfenroll_types eq '*') { |
if ($selfenroll_types eq '*') { |
$r->print('<br />'.&mt('You will have an opportunity to self enroll in the course once the account has been created.').'</li></ul>'); |
$r->print('<br />'.&mt('You will have an opportunity to self enroll in the course once the account has been created.').'</li></ul>'); |
Line 221 sub user_is_known {
|
Line 240 sub user_is_known {
|
|
|
sub can_create { |
sub can_create { |
my ($cdom) = @_; |
my ($cdom) = @_; |
my $cancreate = ''; |
my @cancreate; |
my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$cdom); |
my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$cdom); |
if (ref($domconfig{'usercreation'}) eq 'HASH') { |
if (ref($domconfig{'usercreation'}) eq 'HASH') { |
if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') { |
if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') { |
if ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne 'none') { |
if ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne 'none') { |
$cancreate = $domconfig{'usercreation'}{'cancreate'}{'selfcreate'}; |
if (ref($domconfig{'usercreation'}{'cancreate'}{'selfcreate'}) eq 'ARRAY') { |
|
@cancreate = @{$domconfig{'usercreation'}{'cancreate'}{'selfcreate'}}; |
|
} else { |
|
if (($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne 'none') && |
|
($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne '')) { |
|
@cancreate = ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'}); |
|
} |
|
} |
} |
} |
} |
} |
} |
} |
if ($cancreate eq 'none') { |
return @cancreate; |
$cancreate = ''; |
|
} |
|
return $cancreate; |
|
} |
} |
|
|
sub has_role { |
sub has_role { |
Line 257 sub process_self_enroll {
|
Line 280 sub process_self_enroll {
|
my %userhash = &Apache::lonnet::userenvironment($udom,$uname,@info); |
my %userhash = &Apache::lonnet::userenvironment($udom,$uname,@info); |
my ($enrolltypes,$longtypes,$alldoms) = |
my ($enrolltypes,$longtypes,$alldoms) = |
&get_selfenroll_filters($selfenroll_types,$udom); |
&get_selfenroll_filters($selfenroll_types,$udom); |
my @inststatuses = &unescape(split(/:/,$userhash{'inststatus'})); |
my @inststatuses; |
if (@inststatuses == 0) { |
if ($userhash{'inststatus'} eq '') { |
push(@inststatuses,'other'); |
push(@inststatuses,'other'); |
|
} else { |
|
my @esc_statuses = split(/:/,$userhash{'inststatus'}); |
|
@inststatuses = map { &unescape($_); } (@esc_statuses); |
} |
} |
my $selfenroll = 0; |
my $selfenroll = 0; |
if ($alldoms) { |
if ($alldoms) { |
Line 287 sub process_self_enroll {
|
Line 313 sub process_self_enroll {
|
my ($registered,$instsec,$message) = &check_registered($cdom,$cnum); |
my ($registered,$instsec,$message) = &check_registered($cdom,$cnum); |
$usec = $instsec; |
$usec = $instsec; |
if (!$registered) { |
if (!$registered) { |
$r->print(&mt('Self-enrollment is restricted to officially registered students.').'<br />'); |
$r->print(&mt('Self-enrollment is restricted to students officially registered for this course.').'<br />'); |
if ($message) { |
if ($message) { |
$r->print($message); |
$r->print($message); |
} else { |
} else { |
Line 298 sub process_self_enroll {
|
Line 324 sub process_self_enroll {
|
} |
} |
my $enrollresult = |
my $enrollresult = |
&Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef, |
&Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef, |
undef,undef,$usec,$selfenroll_access_end,$selfenroll_access_start, 'manual',undef,$cdom.'_'.$cnum,$selfenroll); |
undef,undef,$usec,$selfenroll_access_end,$selfenroll_access_start, |
|
'manual',undef,$cdom.'_'.$cnum,$selfenroll); |
if ($enrollresult eq 'ok') { |
if ($enrollresult eq 'ok') { |
my (%userroles,%newrole,%newgroups); |
my (%userroles,%newrole,%newgroups); |
my $role = 'st'; |
my $role = 'st'; |
Line 312 sub process_self_enroll {
|
Line 339 sub process_self_enroll {
|
$area); |
$area); |
&Apache::lonnet::set_userprivs(\%userroles,\%newrole,%newgroups); |
&Apache::lonnet::set_userprivs(\%userroles,\%newrole,%newgroups); |
$userroles{'user.role.'.$spec} = $selfenroll_access_start.'.'.$selfenroll_access_end; |
$userroles{'user.role.'.$spec} = $selfenroll_access_start.'.'.$selfenroll_access_end; |
&Apache::lonnet::appenv(%userroles); |
&Apache::lonnet::appenv(\%userroles,[$role]); |
if ($selfenroll_access_end && $selfenroll_access_end <= $now) { |
if ($selfenroll_access_end && $selfenroll_access_end <= $now) { |
$r->print(&mt('The end date for access to this course for users who self-enroll has passed.').'<br />'.&mt('Consequently, although a new role was created for you in the course, it is an inactive role which does not provide access to the course.')); |
$r->print(&mt('The end date for access to this course for users who self-enroll has passed.').'<br />'.&mt('Consequently, although a new role was created for you in the course, it is an inactive role which does not provide access to the course.')); |
} else { |
} else { |
Line 408 sub print_selfenroll_types {
|
Line 435 sub print_selfenroll_types {
|
} |
} |
} |
} |
} else { |
} else { |
$output = &mt('Self-enrollment in this course is only available to users in the following domains (with the following status): ').'<ul>'; |
$output = &mt('Self-enrollment in this course is only available to users in the following domains (with the following status):').' <ul>'; |
foreach my $selfdom (sort(keys(%{$longtypes}))) { |
foreach my $selfdom (sort(keys(%{$longtypes}))) { |
if (ref($longtypes->{$selfdom}) eq 'ARRAY') { |
if (ref($longtypes->{$selfdom}) eq 'ARRAY') { |
$output .= '<li>'.$selfdom.': '.join(', ',@{$longtypes->{$selfdom}}).'</li>'; |
$output .= '<li>'.$selfdom.': '.join(', ',@{$longtypes->{$selfdom}}).'</li>'; |
Line 417 sub print_selfenroll_types {
|
Line 444 sub print_selfenroll_types {
|
$output .= '</ul>'; |
$output .= '</ul>'; |
} |
} |
} else { |
} else { |
$output = &mt('Self-enrollment is not currently available in this course'); |
$output = &mt('Self-enrollment is not currently available for this course.'); |
} |
} |
} |
} |
return $output; |
return $output; |