--- loncom/interface/selfenroll.pm 2008/07/14 10:25:25 1.11 +++ loncom/interface/selfenroll.pm 2014/03/31 02:31:05 1.28 @@ -1,7 +1,7 @@ # The LearningOnline Network # Allow users to self-enroll in a course # -# $Id: selfenroll.pm,v 1.11 2008/07/14 10:25:25 raeburn Exp $ +# $Id: selfenroll.pm,v 1.28 2014/03/31 02:31:05 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -34,6 +34,8 @@ use Apache::lonnet; use Apache::loncommon; use Apache::lonlocal; use Apache::createaccount; +use Apache::loncoursequeueadmin; +use Apache::lonuserutils; use LONCAPA qw(:DEFAULT :match); sub handler { @@ -51,47 +53,78 @@ sub handler { } &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'}); - if ($coursechk ne 'ok') { - &page_header($r,$cid); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['courseid']); + my $js = &Apache::createaccount::catreturn_js(); + + my $courseid = Apache::lonnet::is_course($env{'form.courseid'}); + + unless ($courseid) { + &page_header($r,$env{'form.courseid'},$js); $r->print('

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

'. ''. &mt('Invalid domain or course number').''); - $r->print(&Apache::loncommon::end_page()); + &page_footer($r); return OK; } my $now = time; - my $js; if ($env{'form.phase'} eq 'login') { - $js = &Apache::createaccount::javascript_setforms($now); + $js .= "\n".&Apache::createaccount::javascript_setforms($now); } - &page_header($r,$cid,$js); + 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 ($cdom,$cnum,$desc,$canenroll,$selfenroll_types,$selfenroll_registered, - @cancreate,$knownuser,$selfenroll_access_start,$selfenroll_access_end, - $selfenroll_section,$selfenroll_future,%curr_role,%coursehash,$cdomdesc); - %coursehash = &Apache::lonnet::coursedescription($cid); - $cdom = $coursehash{'domain'}; - $cnum = $coursehash{'num'}; - $desc = $coursehash{'description'}; + 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,$crstype); $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'}; + $crstype = $coursehash{'internal.type'}; + if ($crstype eq '') { + $crstype = 'Course'; + } + 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 > 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)) { 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); + } } } } @@ -100,6 +133,14 @@ sub handler { $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 '*') { @@ -167,13 +208,14 @@ 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 '') { @@ -184,51 +226,47 @@ sub handler { if (keys(%curr_role)) { $r->print('

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

'. ''.&has_role(%curr_role).''); - $r->print(&Apache::loncommon::end_page()); + &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,$crstype,$lonhost); } 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,$cid, + $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.''). - &Apache::loncommon::end_page()); + $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) { - if (formaction != '') { - 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('LON-CAPA account required').'

'. - &mt('You need to be logged into LON-CAPA to self-enroll in a course.').'