version 1.14, 2008/07/30 16:25:35
|
version 1.25.2.1, 2010/01/18 15:58:25
|
Line 34 use Apache::lonnet;
|
Line 34 use Apache::lonnet;
|
use Apache::loncommon; |
use Apache::loncommon; |
use Apache::lonlocal; |
use Apache::lonlocal; |
use Apache::createaccount; |
use Apache::createaccount; |
|
use Apache::loncoursequeueadmin; |
use LONCAPA qw(:DEFAULT :match); |
use LONCAPA qw(:DEFAULT :match); |
|
|
sub handler { |
sub handler { |
Line 78 sub handler {
|
Line 79 sub handler {
|
} |
} |
my ($canenroll,$selfenroll_types,$selfenroll_registered,@cancreate, |
my ($canenroll,$selfenroll_types,$selfenroll_registered,@cancreate, |
$knownuser,$selfenroll_access_start,$selfenroll_access_end, |
$knownuser,$selfenroll_access_start,$selfenroll_access_end, |
$selfenroll_section,$selfenroll_future,%curr_role,$cdomdesc); |
$selfenroll_section,$selfenroll_future,%curr_role,$cdomdesc, |
|
$selfenroll_approval,$selfenroll_limit,$selfenroll_cap, |
|
$selfenroll_notifylist,$owner); |
$selfenroll_types = $coursehash{'internal.selfenroll_types'}; |
$selfenroll_types = $coursehash{'internal.selfenroll_types'}; |
$selfenroll_registered = $coursehash{'internal.selfenroll_registered'}; |
$selfenroll_registered = $coursehash{'internal.selfenroll_registered'}; |
$selfenroll_section = $coursehash{'internal.selfenroll_section'}; |
$selfenroll_section = $coursehash{'internal.selfenroll_section'}; |
$selfenroll_access_start = $coursehash{'internal.selfenroll_start_access'}; |
$selfenroll_access_start = $coursehash{'internal.selfenroll_start_access'}; |
$selfenroll_access_end = $coursehash{'internal.selfenroll_end_access'}; |
$selfenroll_access_end = $coursehash{'internal.selfenroll_end_access'}; |
|
$selfenroll_limit = $coursehash{'internal.selfenroll_limit'}; |
|
$selfenroll_cap = $coursehash{'internal.selfenroll_cap'}; |
|
$selfenroll_approval = $coursehash{'internal.selfenroll_approval'}; |
|
$selfenroll_notifylist = $coursehash{'internal.selfenroll_notifylist'}; |
|
$owner = $coursehash{'internal.courseowner'}; |
|
my $nospace; |
if ($selfenroll_types ne '') { |
if ($selfenroll_types ne '') { |
my $start = $coursehash{'internal.selfenroll_start_date'}; |
my $start = $coursehash{'internal.selfenroll_start_date'}; |
my $end = $coursehash{'internal.selfenroll_end_date'}; |
my $end = $coursehash{'internal.selfenroll_end_date'}; |
if (($start > 0 && $start < $now) && (($end == 0) || ($end > 0 && $end > $now))) { |
if (($start > 0 && $start < $now) && (($end == 0) || ($end > 0 && $end > $now))) { |
$canenroll = 1; |
if (($selfenroll_limit eq 'allstudents') || |
|
($selfenroll_limit eq 'selfenroll')) { |
|
$nospace = |
|
&enrollment_limit_check($selfenroll_limit,$selfenroll_cap, |
|
$cdom,$cnum); |
|
if (!$nospace) { |
|
$canenroll = 1; |
|
} |
|
} else { |
|
$canenroll = 1; |
|
} |
} elsif (($end == 0) || ($end > 0 && $end > $now)) { |
} elsif (($end == 0) || ($end > 0 && $end > $now)) { |
if ($start > $now) { |
if ($start > $now) { |
$selfenroll_future = &Apache::lonlocal::locallocaltime($start); |
if (($selfenroll_limit eq 'allstudents') || |
|
($selfenroll_limit eq 'selfenroll')) { |
|
$nospace = |
|
&enrollment_limit_check($selfenroll_limit,$cdom,$cnum); |
|
} |
|
if (!$nospace) { |
|
$selfenroll_future = &Apache::lonlocal::locallocaltime($start); |
|
} |
} |
} |
} |
} |
} |
} |
Line 100 sub handler {
|
Line 126 sub handler {
|
$r->print('<h3>'.&mt('Self-enrollment unavailable').'</h3><span class="LC_warning">'. |
$r->print('<h3>'.&mt('Self-enrollment unavailable').'</h3><span class="LC_warning">'. |
&mt('Self-enrollment is not currently available for this course.'). |
&mt('Self-enrollment is not currently available for this course.'). |
'</span><br /><br />'); |
'</span><br /><br />'); |
|
if ($nospace) { |
|
if ($selfenroll_limit eq 'allstudents') { |
|
$r->print(&mt('The enrollment limit of [quant,_1,student] has been reached.',$selfenroll_cap)); |
|
} else { |
|
$r->print(&mt('The enrollment limit of [quant,_1,self-enrolled student] has been reached.',$selfenroll_cap)); |
|
|
|
} |
|
} |
if ($selfenroll_types ne '') { |
if ($selfenroll_types ne '') { |
if ($selfenroll_future ne '') { |
if ($selfenroll_future ne '') { |
if ($selfenroll_types eq '*') { |
if ($selfenroll_types eq '*') { |
Line 190 sub handler {
|
Line 224 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,$selfenroll_approval, |
|
$selfenroll_notifylist,$owner); |
} elsif ($env{'form.phase'} eq 'login') { |
} elsif ($env{'form.phase'} eq 'login') { |
my $submit_text = &mt('Log in'); |
my $submit_text = &mt('Log in'); |
$r->print('<h3>'.&mt('Log-in to LON-CAPA').'</h3>'); |
$r->print('<h3>'.&mt('Log-in to LON-CAPA').'</h3>'); |
Line 282 END
|
Line 317 END
|
return OK; |
return OK; |
} |
} |
|
|
|
sub enrollment_limit_check { |
|
my ($selfenroll_limit,$selfenroll_cap,$cdom,$cnum) = @_; |
|
my $nospace = 0; |
|
my (%idx,%stucount); |
|
my $classlist = &Apache::loncoursedata::get_classlist($cdom,$cnum); |
|
$idx{'type'} = &Apache::loncoursedata::CL_TYPE(); |
|
$idx{'status'} = &Apache::loncoursedata::CL_STATUS(); |
|
while (my ($student,$data) = each(%$classlist)) { |
|
if (($data->[$idx{'status'}] eq 'Active') || |
|
($data->[$idx{'status'}] eq 'Future')) { |
|
if ($data->[$idx{'type'}] eq 'selfenroll') { |
|
$stucount{'selfenroll'} ++; |
|
} |
|
$stucount{'allstudents'} ++; |
|
} |
|
} |
|
if ($stucount{$selfenroll_limit} >= $selfenroll_cap) { |
|
$nospace = 1; |
|
} |
|
return $nospace; |
|
} |
|
|
sub page_header { |
sub page_header { |
my ($r,$courseid,$js,$desc) = @_; |
my ($r,$courseid,$js,$desc) = @_; |
my $start_page = |
my $start_page = |
Line 348 sub has_role {
|
Line 405 sub has_role {
|
my $output; |
my $output; |
if ($curr_role{'status'} eq 'active') { |
if ($curr_role{'status'} eq 'active') { |
my $rolelink = &jump_to_role($curr_role{'role'}); |
my $rolelink = &jump_to_role($curr_role{'role'}); |
$output = &mt('You already have an active student role (section: "[_1]") in this course.',$curr_role{'section'}).'<br>'.$rolelink; |
$output = &mt('You already have an active student role (section: "[_1]") in this course.',$curr_role{'section'}).'<br />'.$rolelink; |
} elsif ($curr_role{'status'} eq 'future') { |
} elsif ($curr_role{'status'} eq 'future') { |
$output = &mt('You have a student role (section: "[_1]") in this course which will become active [_2].',$curr_role{'section'},$curr_role{'start'}); |
$output = &mt('You have a student role (section: "[_1]") in this course which will become active [_2].',$curr_role{'section'},$curr_role{'start'}); |
} |
} |
Line 357 sub has_role {
|
Line 414 sub has_role {
|
|
|
sub process_self_enroll { |
sub process_self_enroll { |
my ($r,$cdom,$cnum,$selfenroll_types,$selfenroll_registered, |
my ($r,$cdom,$cnum,$selfenroll_types,$selfenroll_registered, |
$selfenroll_access_start,$selfenroll_access_end,$selfenroll_section,$now) = @_; |
$selfenroll_access_start,$selfenroll_access_end,$selfenroll_section, |
|
$now,$selfenroll_approval,$selfenroll_notifylist,$owner) = @_; |
my $udom = $env{'user.domain'}; |
my $udom = $env{'user.domain'}; |
my $uname = $env{'user.name'}; |
my $uname = $env{'user.name'}; |
my $selfenroll = 0; |
my $selfenroll = 0; |
Line 397 sub process_self_enroll {
|
Line 455 sub process_self_enroll {
|
return; |
return; |
} |
} |
} |
} |
my $enrollresult = |
if ($selfenroll_approval) { |
&Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef, |
my $outcome = |
undef,undef,$usec,$selfenroll_access_end,$selfenroll_access_start, |
&store_selfenroll_request($udom,$uname,$usec,$cdom,$cnum, |
'manual',undef,$cdom.'_'.$cnum,$selfenroll); |
$selfenroll_notifylist,$owner); |
if ($enrollresult eq 'ok') { |
$r->print($outcome); |
my (%userroles,%newrole,%newgroups); |
} else { |
my $role = 'st'; |
my $enrollresult = |
my $area = '/'.$cdom.'/'.$cnum; |
&Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef, |
my $spec = $role.'.'.$area; |
undef,undef,$usec,$selfenroll_access_end,$selfenroll_access_start, |
if ($usec ne '') { |
'selfenroll',undef,$cdom.'_'.$cnum,$selfenroll); |
$spec .= '/'.$usec; |
if ($enrollresult eq 'ok') { |
$area .= '/'.$usec; |
my (%userroles,%newrole,%newgroups); |
} |
my $role = 'st'; |
&Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum, |
my $area = '/'.$cdom.'/'.$cnum; |
$area); |
my $spec = $role.'.'.$area; |
&Apache::lonnet::set_userprivs(\%userroles,\%newrole,%newgroups); |
if ($usec ne '') { |
$userroles{'user.role.'.$spec} = $selfenroll_access_start.'.'.$selfenroll_access_end; |
$spec .= '/'.$usec; |
&Apache::lonnet::appenv(\%userroles,[$role,'cm']); |
$area .= '/'.$usec; |
$r->print('<h3>'.&mt('Enrollment process complete').'</h3>'); |
} |
if ($selfenroll_access_end && $selfenroll_access_end <= $now) { |
&Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum, |
$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.')); |
$area); |
} else { |
&Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups); |
$r->print(&mt('Self-enrollment in this course was successful.').'<br />'); |
$userroles{'user.role.'.$spec} = $selfenroll_access_start.'.'.$selfenroll_access_end; |
my $showstart = &Apache::lonlocal::locallocaltime($selfenroll_access_start); |
&Apache::lonnet::appenv(\%userroles,[$role,'cm']); |
my $showend = &Apache::lonlocal::locallocaltime($selfenroll_access_end); |
$r->print('<h3>'.&mt('Enrollment process complete').'</h3>'); |
if ($selfenroll_access_start && $selfenroll_access_start >$now) { |
if ($selfenroll_access_end && $selfenroll_access_end <= $now) { |
$r->print(&mt('The start date for access to this course for users who self-enroll has yet to be reached.').'<br />'.&mt('Consequently, although a new role was created for you in the course, you will not be able to select this role until [_1].',$showstart)); |
$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 { |
my $newrole = 'st./'.$cdom.'/'.$cnum; |
$r->print(&mt('Self-enrollment in this course was successful.').'<br />'); |
if ($usec ne '') { |
my $showstart = &Apache::lonlocal::locallocaltime($selfenroll_access_start); |
$newrole .= '/'.$usec; |
my $showend = &Apache::lonlocal::locallocaltime($selfenroll_access_end); |
|
if ($selfenroll_access_start && $selfenroll_access_start >$now) { |
|
$r->print(&mt('The start date for access to this course for users who self-enroll has yet to be reached.').'<br />'.&mt('Consequently, although a new role was created for you in the course, you will not be able to select this role until [_1].',$showstart)); |
|
} else { |
|
my $newrole = 'st./'.$cdom.'/'.$cnum; |
|
if ($usec ne '') { |
|
$newrole .= '/'.$usec; |
|
} |
|
my $rolelink = &jump_to_role($newrole); |
|
$r->print(&mt('Your new role is available immediately, and will provide access to the course until [_1].',$showend).'<br /><br />'."\n". |
|
$rolelink); |
} |
} |
my $rolelink = &jump_to_role($newrole); |
|
$r->print(&mt('Your new role is available immediately, and will provide access to the course until [_1].',$showend).'<br /><br />'."\n". |
|
$rolelink); |
|
} |
} |
} |
} else { |
} else { |
$r->print('<h3>'.&mt('Enrollment incomplete').'</h3>'. |
$r->print('<h3>'.&mt('Enrollment incomplete').'</h3>'. |
&mt('Self-enrollment in this course failed.')); |
&mt('Self-enrollment in this course failed.')); |
if ($enrollresult ne '') { |
if ($enrollresult ne '') { |
$r->print('<span class="LC_error">'.$enrollresult.'</span>'); |
$r->print('<span class="LC_error">'.$enrollresult.'</span>'); |
} |
} |
} |
} |
} |
} else { |
} else { |
Line 470 sub user_can_selfenroll {
|
Line 535 sub user_can_selfenroll {
|
return $selfenroll; |
return $selfenroll; |
} |
} |
|
|
|
sub store_selfenroll_request { |
|
my ($udom,$uname,$usec,$cdom,$cnum,$selfenroll_notifylist,$owner) = @_; |
|
my $namespace = 'selfenrollrequests'; |
|
my $output; |
|
my $now = time; |
|
my %existing = |
|
&Apache::lonnet::get($namespace,[$uname.':'.$udom],$cdom,$cnum); |
|
if ($existing{$uname.':'.$udom}) { |
|
$output = &mt('A self-enrollment request already exists for you for this course.').'<br />'.&mt('Your earlier request is in a queue awaiting action by a Course Coordinator.'). |
|
'<br /><br />'.&Apache::loncoursequeueadmin::queued_selfenrollment(); |
|
} else { |
|
my %selfenroll = ( |
|
$uname.':'.$udom => $now.':'.$usec, |
|
); |
|
my $putresult = &Apache::lonnet::put($namespace,\%selfenroll,$cdom,$cnum); |
|
if ($putresult eq 'ok') { |
|
my %userenroll = ( |
|
$cdom.'_'.$cnum => { |
|
timestamp => $now, |
|
section => $usec, |
|
status => 'request', |
|
}); |
|
my $warning; |
|
my $userresult = &Apache::lonnet::put($namespace,\%userenroll,$udom,$uname); |
|
if ($userresult ne 'ok') { |
|
$warning = &mt('An error occurred saving a personal record of your request.'); |
|
} |
|
$output = &mt('Your request for self-enrollment has been recorded.').'<br />'. |
|
&mt('A message will be sent to your LON-CAPA account when the course coordinator takes action on your request.').'<br />'. |
|
&mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".'); |
|
my %emails = &Apache::loncommon::getemails($uname,$udom); |
|
if (($emails{'permanentemail'} ne '') || ($emails{'notification'} ne '')) { |
|
my $address = $emails{'permanentemail'}; |
|
if ($address eq '') { |
|
$address = $emails{'notification'}; |
|
} |
|
$output.= &mt('An e-mail will also be sent to: [_1] when this occurs.',$address).'<br />'; |
|
} |
|
if ($warning) { |
|
$output .= '<span class="LC_warning">'.$warning.'</span><br />'; |
|
} |
|
|
|
$output .= '<br />'.&Apache::loncoursequeueadmin::queued_selfenrollment(); |
|
|
|
if ($selfenroll_notifylist) { |
|
my $fullname = &Apache::loncommon::plainname($uname,$udom); |
|
my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum); |
|
my $coursedesc = $courseinfo{'description'}; |
|
&Apache::loncoursequeueadmin::send_selfserve_notification( |
|
$selfenroll_notifylist,$fullname,$cdom.'_'.$cnum, |
|
$coursedesc,$now,'selfenrollreq',$owner); |
|
} |
|
} else { |
|
$output = '<span class="LC_error">'.&mt('An error occurred when recording your request.').'</span>'; |
|
|
|
} |
|
} |
|
return $output; |
|
} |
|
|
sub jump_to_role { |
sub jump_to_role { |
my ($role) = @_; |
my ($role) = @_; |
my $output = <<"END"; |
my $output = <<"END"; |