--- loncom/interface/selfenroll.pm 2008/07/10 00:19:56 1.8 +++ loncom/interface/selfenroll.pm 2010/01/18 15:58:25 1.25.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network # Allow users to self-enroll in a course # -# $Id: selfenroll.pm,v 1.8 2008/07/10 00:19:56 raeburn Exp $ +# $Id: selfenroll.pm,v 1.25.2.1 2010/01/18 15:58:25 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -33,6 +33,8 @@ use Apache::Constants qw(:common); use Apache::lonnet; use Apache::loncommon; use Apache::lonlocal; +use Apache::createaccount; +use Apache::loncoursequeueadmin; use LONCAPA qw(:DEFAULT :match); sub handler { @@ -44,50 +46,130 @@ sub handler { } my $handle = &Apache::lonnet::check_for_valid_session($r); my $lonidsdir=$r->dir_config('lonIDsDir'); + my $lonhost = $r->dir_config('lonHostID'); if ($handle ne '') { &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle); } &Apache::lonacc::get_posted_cgi($r); &Apache::lonlocal::get_language_handle($r); - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cid']); - my ($coursechk,$cid) = &validate_course_id($env{'form.cid'}); - my $start_page = - &Apache::loncommon::start_page('Self-enroll in a LON-CAPA course','', - {'no_inline_link' => 1,}); - $r->print($start_page); - &Apache::lonhtmlcommon::clear_breadcrumbs(); - &Apache::lonhtmlcommon::add_breadcrumb - ({href=>"/adm/selfenroll?cid=$cid", - text=>"Self-enroll"}); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enroll in course')); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['courseid']); + my $js = &Apache::createaccount::catreturn_js(); + my ($coursechk,$courseid) = &validate_course_id($env{'form.courseid'}); if ($coursechk ne 'ok') { - $r->print(&mt('Invalid domain or course number')); - $r->print(&Apache::loncommon::end_page()); + &page_header($r,$courseid,$js); + $r->print('

'.&mt('Self-enrollment error').'

'. + ''. + &mt('Invalid domain or course number').''); + &page_footer($r); return OK; } - my ($cdom,$cnum,$canenroll,$selfenroll_types,$selfenroll_registered, - @cancreate,$knownuser,$selfenroll_access_start,$selfenroll_access_end, - $selfenroll_section,%curr_role,%coursehash); my $now = time; - %coursehash = &Apache::lonnet::coursedescription($cid); - $cdom = $coursehash{'domain'}; - $cnum = $coursehash{'num'}; + if ($env{'form.phase'} eq 'login') { + $js .= "\n".&Apache::createaccount::javascript_setforms($now); + } + my %coursehash = &Apache::lonnet::coursedescription($courseid); + my $cdom = $coursehash{'domain'}; + my $cnum = $coursehash{'num'}; + my $desc = $coursehash{'description'}; + &page_header($r,$courseid,$js,$desc); + my $include = $r->dir_config('lonIncludes'); + if ($env{'form.phase'} eq 'login') { + my $jsh=Apache::File->new($include."/londes.js"); + $r->print(<$jsh>); + } + my ($canenroll,$selfenroll_types,$selfenroll_registered,@cancreate, + $knownuser,$selfenroll_access_start,$selfenroll_access_end, + $selfenroll_section,$selfenroll_future,%curr_role,$cdomdesc, + $selfenroll_approval,$selfenroll_limit,$selfenroll_cap, + $selfenroll_notifylist,$owner); $selfenroll_types = $coursehash{'internal.selfenroll_types'}; $selfenroll_registered = $coursehash{'internal.selfenroll_registered'}; $selfenroll_section = $coursehash{'internal.selfenroll_section'}; $selfenroll_access_start = $coursehash{'internal.selfenroll_start_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 '') { my $start = $coursehash{'internal.selfenroll_start_date'}; my $end = $coursehash{'internal.selfenroll_end_date'}; - if (($start > 0 && $start < $now) && ($end > 0 && $end > $now)) { - $canenroll = 1; + if (($start > 0 && $start < $now) && (($end == 0) || ($end > 0 && $end > $now))) { + 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)) { + if ($start > $now) { + 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); + } + } } } + $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 ($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_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*)$-) { @@ -119,54 +201,65 @@ sub handler { if (keys(%curr_role)) { $r->print(&has_role(%curr_role)); } - $r->print(&Apache::loncommon::end_page()); + &page_footer($r); return OK; } @cancreate = &can_create($cdom); - my ($login_path,$firsturl,$create_path,$sso_url,$missing_formitem); + my ($form,$login_path,$firsturl,$create_path,$sso_url,$missing_formitem); + $form = 'logmein'; $login_path = '/adm/login'; - $firsturl= '/adm/selfenroll?cid='.$cid; + $firsturl= '/adm/selfenroll?courseid='.$courseid; $create_path = '/adm/createaccount'; $sso_url = $r->dir_config('lonSSOReloginServer'); if ($sso_url eq '') { $sso_url = $login_path; } - my $missing_formitem = &mt('The link to the requested page could not be followed.')."\\n".&mt('The placeholder for the courseID is absent.'); + $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).''); + &page_footer($r); return OK; } &process_self_enroll($r,$cdom,$cnum,$selfenroll_types,$selfenroll_registered, $selfenroll_access_start,$selfenroll_access_end, - $selfenroll_section,$now); + $selfenroll_section,$now,$selfenroll_approval, + $selfenroll_notifylist,$owner); + } elsif ($env{'form.phase'} eq 'login') { + my $submit_text = &mt('Log in'); + $r->print('

'.&mt('Log-in to LON-CAPA').'

'); + my $udom = &Apache::lonnet::default_login_domain(); + $r->print(&Apache::createaccount::login_box($now,$lonhost,$courseid, + $submit_text,$udom,'selfenroll')); + $r->print(&mt('You will be able to self-enroll in the course you selected ([_1]) after you have successfully logged in.',''.$desc.'')); + &page_footer($r); + return OK; } elsif (@cancreate > 0) { $r->print(< -function setPath(formaction,item,arg) { - document.forms.logmein.action = formaction; - var itemid = getIndexByName("setting"); - if (itemid > -1) { - document.logmein.elements[itemid].name = item; - document.logmein.elements[itemid].value = arg; - document.logmein.submit(); - } else { - alert("$missing_formitem"); +function setPath(formname,formaction,item,arg) { + var formidx = getFormByName(formname); + if (formidx > -1) { + if (formaction != '') { + document.forms[formidx].action = formaction; + } + var itemid = getIndexByName(formidx,'setting'); + if (itemid > -1) { + document.forms[formidx].elements[itemid].name = item; + document.forms[formidx].elements[itemid].value = arg; + document.forms[formidx].submit(); + } else { + alert("$missing_formitem"); + } } return; } -function getIndexByName(item) { - for (var i=0;i END - $r->print(&mt('You need to be logged into LON-CAPA to self-enroll in a course.').''); } 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('
'."\n". + $r->print("\n".''."\n". + ''."\n". ''."\n". - '
'."\n". - &Apache::loncommon::end_page()); + &Apache::lonhtmlcommon::echo_form_input(['backto','courseid','context','phase'])."\n". + ''."\n"); + &page_footer($r); 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 { + my ($r,$courseid,$js,$desc) = @_; + my $start_page = + &Apache::loncommon::start_page('Self-enroll in a LON-CAPA course',$js, + {'no_inline_link' => 1,}); + $r->print($start_page); + &Apache::lonhtmlcommon::clear_breadcrumbs(); + &Apache::createaccount::selfenroll_crumbs($r,$courseid,$desc); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enroll in course')); + return; +} + +sub page_footer { + my ($r) = @_; + $r->print('
'."\n". + &Apache::lonhtmlcommon::echo_form_input(['backto','courseid','phase','context']). + '
'.&Apache::loncommon::end_page()); + return; +} + sub validate_course_id { - my ($cid) = @_; - my ($cdom,$cnum) = ($env{'form.cid'} =~ /^($match_domain)_($match_courseid)$/); + my ($courseid) = @_; + my ($cdom,$cnum) = ($env{'form.courseid'} =~ /^($match_domain)_($match_courseid)$/); if ($cdom ne '' && $cnum ne '') { if (&Apache::lonnet::is_course($cdom,$cnum)) { - return ('ok',$cid); + return ('ok',$courseid); } } return; @@ -264,42 +405,34 @@ sub has_role { my $output; if ($curr_role{'status'} eq 'active') { my $rolelink = &jump_to_role($curr_role{'role'}); - $output = &mt('You currently have an active role (section: "[_1]") in this course.',$curr_role{'section'}).' '.$rolelink; + $output = &mt('You already have an active student role (section: "[_1]") in this course.',$curr_role{'section'}).'
'.$rolelink; } elsif ($curr_role{'status'} eq 'future') { - $output = &mt('You have a 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'}); } return $output; } sub process_self_enroll { 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 $uname = $env{'user.name'}; - my @info = ['inststatus']; - my %userhash = &Apache::lonnet::userenvironment($udom,$uname,@info); - my ($enrolltypes,$longtypes,$alldoms) = - &get_selfenroll_filters($selfenroll_types,$udom); - my @inststatuses; - if ($userhash{'inststatus'} eq '') { - push(@inststatuses,'other'); - } else { - my @esc_statuses = split(/:/,$userhash{'inststatus'}); - @inststatuses = map { &unescape($_); } (@esc_statuses); - } my $selfenroll = 0; - if ($alldoms) { + my ($enrolltypes,$longtypes,$alldoms); + if ($selfenroll_types eq '*') { $selfenroll = 1; - } elsif (ref($enrolltypes) eq 'HASH') { - if (ref($enrolltypes->{$udom}) eq 'ARRAY') { - if (grep(/^any$/,@{$enrolltypes->{$udom}})) { - $selfenroll = 1; - } else { - foreach my $type (@inststatuses) { - if (grep(/^\Q$type\E$/,@{$enrolltypes->{$udom}})) { - $selfenroll = 1; - last; - } + } else { + ($enrolltypes,$longtypes,$alldoms) = + &get_selfenroll_filters($selfenroll_types,$udom); + if ($alldoms) { + $selfenroll = 1; + } elsif (ref($enrolltypes) eq 'HASH') { + if (ref($enrolltypes->{$udom}) eq 'ARRAY') { + if (grep(/^any$/,@{$enrolltypes->{$udom}})) { + $selfenroll = 1; + } else { + $selfenroll = &user_can_selfenroll($udom,$uname,$enrolltypes->{$udom}); } } } @@ -313,7 +446,7 @@ sub process_self_enroll { my ($registered,$instsec,$message) = &check_registered($cdom,$cnum); $usec = $instsec; if (!$registered) { - $r->print(&mt('Self-enrollment is restricted to students officially registered for this course.').'
'); + $r->print('

'.&mt('Self-enrollment unavailable').'

'.&mt('Self-enrollment is restricted to students officially registered for this course.').'
'); if ($message) { $r->print($message); } else { @@ -322,55 +455,146 @@ sub process_self_enroll { return; } } - my $enrollresult = - &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef, - undef,undef,$usec,$selfenroll_access_end,$selfenroll_access_start, - 'manual',undef,$cdom.'_'.$cnum,$selfenroll); - if ($enrollresult eq 'ok') { - my (%userroles,%newrole,%newgroups); - my $role = 'st'; - my $area = '/'.$cdom.'/'.$cnum; - my $spec = $role.'.'.$area; - if ($usec ne '') { - $spec .= '/'.$usec; - $area .= '/'.$usec; - } - &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum, - $area); - &Apache::lonnet::set_userprivs(\%userroles,\%newrole,%newgroups); - $userroles{'user.role.'.$spec} = $selfenroll_access_start.'.'.$selfenroll_access_end; - &Apache::lonnet::appenv(\%userroles,[$role,'cm']); - 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.').'
'.&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 { - $r->print(&mt('Self-enrollment in this course was successful.').'
'); - my $showstart = &Apache::lonlocal::locallocaltime($selfenroll_access_start); - 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.').'
'.&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)); + if ($selfenroll_approval) { + my $outcome = + &store_selfenroll_request($udom,$uname,$usec,$cdom,$cnum, + $selfenroll_notifylist,$owner); + $r->print($outcome); + } else { + my $enrollresult = + &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef, + undef,undef,$usec,$selfenroll_access_end,$selfenroll_access_start, + 'selfenroll',undef,$cdom.'_'.$cnum,$selfenroll); + if ($enrollresult eq 'ok') { + my (%userroles,%newrole,%newgroups); + my $role = 'st'; + my $area = '/'.$cdom.'/'.$cnum; + my $spec = $role.'.'.$area; + if ($usec ne '') { + $spec .= '/'.$usec; + $area .= '/'.$usec; + } + &Apache::lonnet::standard_roleprivs(\%newrole,$role,$cdom,$spec,$cnum, + $area); + &Apache::lonnet::set_userprivs(\%userroles,\%newrole,\%newgroups); + $userroles{'user.role.'.$spec} = $selfenroll_access_start.'.'.$selfenroll_access_end; + &Apache::lonnet::appenv(\%userroles,[$role,'cm']); + $r->print('

'.&mt('Enrollment process complete').'

'); + 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.').'
'.&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 { - my $newrole = 'st./'.$cdom.'/'.$cnum; - if ($usec ne '') { - $newrole .= '/'.$usec; + $r->print(&mt('Self-enrollment in this course was successful.').'
'); + my $showstart = &Apache::lonlocal::locallocaltime($selfenroll_access_start); + 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.').'
'.&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).'

'."\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).'

'."\n". - $rolelink); } - } - } else { - $r->print(&mt('Self-enrollment in this course failed.')); - if ($enrollresult ne '') { - $r->print(''.$enrollresult.''); + } else { + $r->print('

'.&mt('Enrollment incomplete').'

'. + &mt('Self-enrollment in this course failed.')); + if ($enrollresult ne '') { + $r->print(''.$enrollresult.''); + } } } } else { - $r->print(&mt('You are not permitted to enroll yourself in this course.').'
'); + $r->print('

'.&mt('Self-enrollment unavailable').'

'. + &mt('You are not permitted to enroll yourself in this course.').'
'); $r->print(&print_selfenroll_types($longtypes)); } return; } +sub user_can_selfenroll { + my ($udom,$uname,$domenrolltypes) = @_; + my $selfenroll = 0; + my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'inststatus'); + my @inststatuses; + if ($userhash{'inststatus'} eq '') { + push(@inststatuses,'other'); + } else { + @inststatuses = split(':',$userhash{'inststatus'}); + } + foreach my $type (@inststatuses) { + if (ref($domenrolltypes) eq 'ARRAY') { + if (grep(/^\Q$type\E$/,@{$domenrolltypes})) { + $selfenroll = 1; + last; + } + } + } + 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.').'
'.&mt('Your earlier request is in a queue awaiting action by a Course Coordinator.'). + '

'.&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.').'
'. + &mt('A message will be sent to your LON-CAPA account when the course coordinator takes action on your request.').'
'. + &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).'
'; + } + if ($warning) { + $output .= ''.$warning.'
'; + } + + $output .= '
'.&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 = ''.&mt('An error occurred when recording your request.').''; + + } + } + return $output; +} + sub jump_to_role { my ($role) = @_; my $output = <<"END"; @@ -383,7 +607,7 @@ function SelectRole() { END $output .= ''."\n". &mt('Enter course now').''."\n". - '
'."\n". + ''."\n". ''."\n". ''."\n". '
'; @@ -406,13 +630,34 @@ sub get_selfenroll_filters { if ($selfdom =~ /^$match_domain$/) { if (&Apache::lonnet::domain($selfdom) ne '') { my @types = split(/,/,$type_str); + my @unesc_types = map { &unescape($_); } @types; 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$/,@unesc_types)) { + $anytype = 0; + last; + } + } + if ($anytype) { + if (!(grep(/^other$/,@types))) { + $anytype = 0; + } + } + $usertypes->{'any'} = &mt('Any users'); + $usertypes->{'other'} = &mt('Others'); + my @showtypes; + if ($anytype) { + @{$enrolltypes{$selfdom}} = ('any'); + @showtypes = ('any'); + } else { + @{$enrolltypes{$selfdom}} = @types; + @showtypes = @unesc_types; + } + @{$longtypes{$selfdom}} = + map {$usertypes->{$_}} @showtypes; } } } @@ -424,25 +669,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):').' '."\n"; } else { $output = &mt('Self-enrollment is not currently available for this course.'); }