--- loncom/interface/selfenroll.pm 2008/07/14 08:32:36 1.10
+++ loncom/interface/selfenroll.pm 2008/07/30 16:25:35 1.14
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Allow users to self-enroll in a course
#
-# $Id: selfenroll.pm,v 1.10 2008/07/14 08:32:36 raeburn Exp $
+# $Id: selfenroll.pm,v 1.14 2008/07/30 16:25:35 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -51,34 +51,34 @@ 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'});
+ &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') {
- &page_header($r,$cid);
+ &page_header($r,$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_types = $coursehash{'internal.selfenroll_types'};
$selfenroll_registered = $coursehash{'internal.selfenroll_registered'};
$selfenroll_section = $coursehash{'internal.selfenroll_section'};
@@ -167,24 +167,25 @@ 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,
@@ -194,41 +195,36 @@ sub handler {
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.').'- '.&mt('If you have an account in LON-CAPA, [_1]log-in[_2].','','').'
');
+ &mt('You need to be logged into LON-CAPA to self-enroll in a course.').'- '.&mt('If you have an account in LON-CAPA, [_1]log-in[_2].','','').'
');
if (@cancreate > 1) {
$r->print('- '.&mt('Otherwise:').'
');
my $count = 0;
@@ -238,11 +234,11 @@ END
}
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",'',''));
+ $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",'',''));
} elsif ($type eq 'login') {
- $r->print(' '.&mt('if you have an institutional login, [_1]create an account[_2]','',''));
+ $r->print(' '.&mt('if you have an institutional login, [_1]create an account[_2]','',''));
} elsif ($type eq 'email') {
- $r->print(' '.&mt('you can use an e-mail address to [_1]create an account[_2]','',''));
+ $r->print(' '.&mt('you can use an e-mail address to [_1]create an account[_2]','',''));
}
$count ++;
}
@@ -250,11 +246,11 @@ END
$r->print('.
');
} else {
if ($cancreate[0] eq 'login') {
- $r->print(' - '.&mt('Otherwise, if you have an institutional login, [_1]create an account[_2].','',''));
+ $r->print('
- '.&mt('Otherwise, if you have an institutional login, [_1]create an account[_2].','',''));
} elsif ($cancreate[0] eq 'email') {
- $r->print('
- '.&mt('Otherwise, you will use an e-mail address to [_1]create an account[_2].','',''));
+ $r->print('
- '.&mt('Otherwise, you will use an e-mail address to [_1]create an account[_2].','',''));
} elsif ($cancreate[0] eq 'sso') {
- $r->print('
- '.&mt("Otherwise, use your institution's [_1]single sign on page[_2] to log-in, then create an account.",'',''));
+ $r->print('
- '.&mt("Otherwise, use your institution's [_1]single sign on page[_2] to log-in, then create an account.",'',''));
}
}
if ($selfenroll_types eq '*') {
@@ -277,34 +273,41 @@ END
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".
- &Apache::loncommon::end_page());
+ &Apache::lonhtmlcommon::echo_form_input(['backto','courseid','context','phase'])."\n".
+ ''."\n");
+ &page_footer($r);
return OK;
}
sub page_header {
- my ($r,$cid,$js) = @_;
+ 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::lonhtmlcommon::add_breadcrumb
- ({href=>"/adm/selfenroll?cid=$cid",
- text=>"Self-enroll"});
+ &Apache::createaccount::selfenroll_crumbs($r,$courseid,$desc);
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enroll in course'));
return;
}
+sub page_footer {
+ my ($r) = @_;
+ $r->print(''.&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;
@@ -449,14 +452,12 @@ sub process_self_enroll {
sub user_can_selfenroll {
my ($udom,$uname,$domenrolltypes) = @_;
my $selfenroll = 0;
- my @info = ['inststatus'];
- my %userhash = &Apache::lonnet::userenvironment($udom,$uname,@info);
+ my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'inststatus');
my @inststatuses;
if ($userhash{'inststatus'} eq '') {
push(@inststatuses,'other');
} else {
- my @esc_statuses = split(/:/,$userhash{'inststatus'});
- @inststatuses = map { &unescape($_); } (@esc_statuses);
+ @inststatuses = split(':',$userhash{'inststatus'});
}
foreach my $type (@inststatuses) {
if (ref($domenrolltypes) eq 'ARRAY') {
@@ -504,12 +505,13 @@ 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') {
my $anytype = 1;
foreach my $key (keys(%{$usertypes})) {
- if (!grep(/^\Q$key\E$/,@types)) {
+ if (!grep(/^\Q$key\E$/,@unesc_types)) {
$anytype = 0;
last;
}
@@ -521,13 +523,16 @@ sub get_selfenroll_filters {
}
$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->{$_}} @{$enrolltypes{$selfdom}}
+ map {$usertypes->{$_}} @showtypes;
}
}
}
@@ -552,14 +557,14 @@ sub print_selfenroll_types {
$output = &mt('Self-enrollment is not currently available for this course for users affiliated with [_1].',$domdesc);
}
} elsif (keys(%{$longtypes}) > 0) {
- $output = &mt('Self-enrollment in this course is only available to users affiliated with the following institutions, and who have the required status:').'
';
+ $output = &mt('Self-enrollment in this course is only available to users affiliated with the following institutions, and who have the required status:').' '."\n";
foreach my $selfdom (sort(keys(%{$longtypes}))) {
my $selfdomdesc = &Apache::lonnet::domain($selfdom,'description');
if (ref($longtypes->{$selfdom}) eq 'ARRAY') {
- $output .= '- '.$selfdomdesc.': '.join(', ',@{$longtypes->{$selfdom}}).'
';
+ $output .= '- '.$selfdomdesc.': '.join(', ',@{$longtypes->{$selfdom}}).'
'."\n";
}
}
- $output .= '
';
+ $output .= '
'."\n";
} else {
$output = &mt('Self-enrollment is not currently available for this course.');
}