--- loncom/interface/selfenroll.pm 2008/07/11 13:43:53 1.9 +++ loncom/interface/selfenroll.pm 2008/07/17 20:08:17 1.13 @@ -1,7 +1,7 @@ # The LearningOnline Network # Allow users to self-enroll in a course # -# $Id: selfenroll.pm,v 1.9 2008/07/11 13:43:53 raeburn Exp $ +# $Id: selfenroll.pm,v 1.13 2008/07/17 20:08:17 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -33,6 +33,7 @@ use Apache::Constants qw(:common); use Apache::lonnet; use Apache::loncommon; use Apache::lonlocal; +use Apache::createaccount; use LONCAPA qw(:DEFAULT :match); sub handler { @@ -44,35 +45,41 @@ 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 $desc; + my ($coursechk,$courseid) = &validate_course_id($env{'form.courseid'}); if ($coursechk ne 'ok') { + &page_header($r,$courseid,$js); $r->print('

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

'. - ''.&mt('Invalid domain or course number').''); - $r->print(&Apache::loncommon::end_page()); + ''. + &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,$selfenroll_future,%curr_role,%coursehash,$cdomdesc); 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_types = $coursehash{'internal.selfenroll_types'}; $selfenroll_registered = $coursehash{'internal.selfenroll_registered'}; $selfenroll_section = $coursehash{'internal.selfenroll_section'}; @@ -161,57 +168,64 @@ 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('

'.&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); + } 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('LON-CAPA account required').'

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