--- loncom/interface/selfenroll.pm 2014/03/31 02:31:05 1.28
+++ loncom/interface/selfenroll.pm 2016/07/24 14:35:00 1.33
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Allow users to self-enroll in a course
#
-# $Id: selfenroll.pm,v 1.28 2014/03/31 02:31:05 raeburn Exp $
+# $Id: selfenroll.pm,v 1.33 2016/07/24 14:35:00 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -221,7 +221,8 @@ sub handler {
if ($sso_url eq '') {
$sso_url = $login_path;
}
- $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.');
+ &js_escape(\$missing_formitem);
if ($knownuser) {
if (keys(%curr_role)) {
$r->print('
'.&mt('Self-enrollment unavailable').'
'.
@@ -232,7 +233,7 @@ sub handler {
&process_self_enroll($r,$cdom,$cnum,$selfenroll_types,$selfenroll_registered,
$selfenroll_access_start,$selfenroll_access_end,
$selfenroll_section,$now,$selfenroll_approval,
- $selfenroll_notifylist,$owner,$crstype,$lonhost);
+ $selfenroll_notifylist,$owner,$crstype,$lonhost,$handle);
} elsif ($env{'form.phase'} eq 'login') {
my $submit_text = &mt('Log in');
$r->print(''.&mt('Log-in to LON-CAPA').'
');
@@ -410,7 +411,7 @@ sub has_role {
sub process_self_enroll {
my ($r,$cdom,$cnum,$selfenroll_types,$selfenroll_registered,
$selfenroll_access_start,$selfenroll_access_end,$selfenroll_section,
- $now,$selfenroll_approval,$selfenroll_notifylist,$owner,$crstype,$lonhost) = @_;
+ $now,$selfenroll_approval,$selfenroll_notifylist,$owner,$crstype,$lonhost,$handle) = @_;
my $udom = $env{'user.domain'};
my $uname = $env{'user.name'};
my $selfenroll = 0;
@@ -437,8 +438,10 @@ sub process_self_enroll {
if ($selfenroll_section eq 'none') {
$usec = '';
}
+ my $instcid;
if ($selfenroll_registered) {
- my ($registered,$instsec,$message) = &check_registered($cdom,$cnum);
+ my ($registered,$instsec,$message);
+ my ($registered,$instsec,$instcid,$message) = &check_registered($cdom,$cnum);
$usec = $instsec;
if (!$registered) {
$r->print(''.&mt('Self-enrollment unavailable').'
'.
@@ -455,13 +458,13 @@ sub process_self_enroll {
my $outcome =
&store_selfenroll_request($udom,$uname,$usec,$cdom,$cnum,
$selfenroll_notifylist,$owner,
- $selfenroll_approval,$crstype,$lonhost);
+ $selfenroll_approval,$crstype,$lonhost,$handle);
$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);
+ 'selfenroll',undef,$cdom.'_'.$cnum,$selfenroll,'selfenroll','',$instcid);
if ($enrollresult eq 'ok') {
my (%userroles,%newrole,%newgroups);
my $role = 'st';
@@ -534,16 +537,29 @@ sub user_can_selfenroll {
sub store_selfenroll_request {
my ($udom,$uname,$usec,$cdom,$cnum,$selfenroll_notifylist,$owner,
- $selfenroll_approval,$crstype,$lonhost) = @_;
+ $selfenroll_approval,$crstype,$lonhost,$handle) = @_;
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();
+ my $status;
+ $output = &mt('A self-enrollment request already exists for you for this course.').'
';
+ my %info = &Apache::lonnet::get($namespace,[$cdom.'_'.$cnum],$udom,$uname);
+ if (ref($info{$cdom.'_'.$cnum}) eq 'HASH') {
+ $status = $info{$cdom.'_'.$cnum}{'status'};
+ }
+ if ($status eq 'pending') {
+ my $token = $info{$cdom.'_'.$cnum}{'token'};
+ my ($statusupdate,$pendingform) = &pending_selfenrollment_form($cdom,$cnum,$crstype,$token,$lonhost);
+ if ($statusupdate eq 'pending') {
+ $output .= $pendingform;
+ }
+ } else {
+ $output .= &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,
@@ -562,8 +578,10 @@ sub store_selfenroll_request {
});
my $token;
if ($status eq 'pending') {
- $token = &Apache::lonnet::tmpput(\%selfenroll,$lonhost);;
+ $token = &Apache::lonnet::tmpput(\%selfenroll,$lonhost);
$userenroll{$cdom.'_'.$cnum}{'token'} = $token;
+ $userenroll{$cdom.'_'.$cnum}{'lonhost'} = $lonhost;
+ $userenroll{$cdom.'_'.$cnum}{'handle'} = $handle;
}
my $warning;
my $userresult = &Apache::lonnet::put($namespace,\%userenroll,$udom,$uname);
@@ -572,43 +590,11 @@ sub store_selfenroll_request {
}
$output = &mt('Your request for self-enrollment has been recorded.').'
';
if ($status eq 'pending') {
- my $coursetype = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype);
- my %postvalues = (
- 'username' => $env{'user.name'},
- 'domain' => $env{'user.domain'},
- 'course' => $cdom.'_'.$cnum,
- 'coursetype' => $coursetype,
- 'token' => $token,
- );
- my %domconfig = &Apache::lonnet::get_dom('configuration',['selfenrollment'],$cdom);
- if (ref($domconfig{'selfenrollment'}) eq 'HASH') {
- my ($url,$buttontext,$code,@fields);
- if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
- my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum,{ 'one_time' => 1});
- $postvalues{'uniquecode'} = $courseinfo{'internal.uniquecode'};
- $url = $domconfig{'selfenrollment'}{'validation'}{'url'};
- if (ref($domconfig{'selfenrollment'}{'validation'}{'fields'}) eq 'ARRAY') {
- @fields = @{$domconfig{'selfenrollment'}{'validation'}{'fields'}};
- }
- $buttontext = $domconfig{'selfenrollment'}{'validation'}{'button'};
-
- $output .= $domconfig{'selfenrollment'}{'validation'}{'markup'};
- if (($url =~ m{^(https?\://|/)}) && (@fields > 0)) {
- $output .= ''."\n";
- }
+ my ($statusupdate,$pendingform) = &pending_selfenrollment_form($cdom,$cnum,$crstype,$token,$lonhost);
+ if ($statusupdate eq 'request') {
+ $status = $statusupdate;
} else {
- $status eq 'request';
+ $output .= $pendingform;
}
}
if ($status eq 'request') {
@@ -644,6 +630,59 @@ sub store_selfenroll_request {
return $output;
}
+sub pending_selfenrollment_form {
+ my ($cdom,$cnum,$crstype,$token,$lonhost) = @_;
+ my ($status,$output);
+ my $coursetype = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype);
+ my %postvalues = (
+ 'username' => $env{'user.name'},
+ 'domain' => $env{'user.domain'},
+ 'course' => $cdom.'_'.$cnum,
+ 'coursetype' => $coursetype,
+ );
+ my %domconfig = &Apache::lonnet::get_dom('configuration',['selfenrollment'],$cdom);
+
+ if (ref($domconfig{'selfenrollment'}) eq 'HASH') {
+ my ($url,$buttontext,$code,@fields);
+ if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
+ my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum,{ 'one_time' => 1});
+ $postvalues{'uniquecode'} = $courseinfo{'internal.uniquecode'};
+ $postvalues{'description'} = $courseinfo{'description'};
+ $url = $domconfig{'selfenrollment'}{'validation'}{'url'};
+ if (ref($domconfig{'selfenrollment'}{'validation'}{'fields'}) eq 'ARRAY') {
+ @fields = @{$domconfig{'selfenrollment'}{'validation'}{'fields'}};
+ }
+ $buttontext = $domconfig{'selfenrollment'}{'validation'}{'button'};
+
+ $output .= $domconfig{'selfenrollment'}{'validation'}{'markup'};
+ if (($url =~ m{^(https?\://|/)}) && (@fields > 0)) {
+ $output .= ''."\n";
+ $status = 'pending';
+ } else {
+ $status = 'request';
+ }
+ }
+ } else {
+ $status = 'request';
+ }
+ return ($status,$output);
+}
+
sub jump_to_role {
my ($role) = @_;
my $output = <<"END";
@@ -748,7 +787,7 @@ sub print_selfenroll_types {
sub check_registered {
my ($cdom,$cnum) = @_;
- my ($registered,$instsec,$message);
+ my ($registered,$instsec,$instcid,$message);
my %settings = &Apache::lonnet::get('environment',['internal.coursecode',
'internal.sectionnums',
'internal.crosslistings'],$cdom,$cnum);
@@ -768,6 +807,7 @@ sub check_registered {
if (defined($enrolled{$env{'user.name'}})) {
$registered = 1;
$instsec = $LC_code{$class};
+ $instcid = $class;
last;
}
}
@@ -780,7 +820,7 @@ sub check_registered {
} else {
$message = &mt('As no institutional course sections are currently associated with this course, your registration status is undetermined.');
}
- return ($registered,$instsec,$message);
+ return ($registered,$instsec,$instcid,$message);
}
1;