[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface selfenroll.pm
raeburn
raeburn at source.lon-capa.org
Sat Apr 5 09:17:16 EDT 2014
raeburn Sat Apr 5 13:17:16 2014 EDT
Modified files: (Branch: version_2_11_X)
/loncom/interface selfenroll.pm
Log:
- For 2.11
- Backport 1.28, 1.29, 1.30
-------------- next part --------------
Index: loncom/interface/selfenroll.pm
diff -u loncom/interface/selfenroll.pm:1.27.2.1 loncom/interface/selfenroll.pm:1.27.2.2
--- loncom/interface/selfenroll.pm:1.27.2.1 Fri May 25 03:04:59 2012
+++ loncom/interface/selfenroll.pm Sat Apr 5 13:17:16 2014
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Allow users to self-enroll in a course
#
-# $Id: selfenroll.pm,v 1.27.2.1 2012/05/25 03:04:59 raeburn Exp $
+# $Id: selfenroll.pm,v 1.27.2.2 2014/04/05 13:17:16 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -35,6 +35,7 @@
use Apache::lonlocal;
use Apache::createaccount;
use Apache::loncoursequeueadmin;
+use Apache::lonuserutils;
use LONCAPA qw(:DEFAULT :match);
sub handler {
@@ -83,7 +84,7 @@
$knownuser,$selfenroll_access_start,$selfenroll_access_end,
$selfenroll_section,$selfenroll_future,%curr_role,$cdomdesc,
$selfenroll_approval,$selfenroll_limit,$selfenroll_cap,
- $selfenroll_notifylist,$owner);
+ $selfenroll_notifylist,$owner,$crstype);
$selfenroll_types = $coursehash{'internal.selfenroll_types'};
$selfenroll_registered = $coursehash{'internal.selfenroll_registered'};
$selfenroll_section = $coursehash{'internal.selfenroll_section'};
@@ -94,6 +95,10 @@
$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'};
@@ -227,7 +232,7 @@
&process_self_enroll($r,$cdom,$cnum,$selfenroll_types,$selfenroll_registered,
$selfenroll_access_start,$selfenroll_access_end,
$selfenroll_section,$now,$selfenroll_approval,
- $selfenroll_notifylist,$owner);
+ $selfenroll_notifylist,$owner,$crstype,$lonhost,$handle);
} elsif ($env{'form.phase'} eq 'login') {
my $submit_text = &mt('Log in');
$r->print('<h3>'.&mt('Log-in to LON-CAPA').'</h3>');
@@ -406,7 +411,7 @@
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) = @_;
+ $now,$selfenroll_approval,$selfenroll_notifylist,$owner,$crstype,$lonhost,$handle) = @_;
my $udom = $env{'user.domain'};
my $uname = $env{'user.name'};
my $selfenroll = 0;
@@ -437,7 +442,8 @@
my ($registered,$instsec,$message) = &check_registered($cdom,$cnum);
$usec = $instsec;
if (!$registered) {
- $r->print('<h3>'.&mt('Self-enrollment unavailable').'</h3>'.&mt('Self-enrollment is restricted to students officially registered for this course.').'<br />');
+ $r->print('<h3>'.&mt('Self-enrollment unavailable').'</h3>'.
+ &mt('Self-enrollment is restricted to students officially registered for this course.').'<br />');
if ($message) {
$r->print($message);
} else {
@@ -449,7 +455,8 @@
if ($selfenroll_approval) {
my $outcome =
&store_selfenroll_request($udom,$uname,$usec,$cdom,$cnum,
- $selfenroll_notifylist,$owner);
+ $selfenroll_notifylist,$owner,
+ $selfenroll_approval,$crstype,$lonhost,$handle);
$r->print($outcome);
} else {
my $enrollresult =
@@ -527,56 +534,118 @@
}
sub store_selfenroll_request {
- my ($udom,$uname,$usec,$cdom,$cnum,$selfenroll_notifylist,$owner) = @_;
+ my ($udom,$uname,$usec,$cdom,$cnum,$selfenroll_notifylist,$owner,
+ $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.').'<br />'.&mt('Your earlier request is in a queue awaiting action by a Course Coordinator.').
+ $output = &mt('A self-enrollment request already exists for you for this course.').'<br />'.
+ &mt('Your earlier request is in a queue awaiting action by a Course Coordinator.').
'<br /><br />'.&Apache::loncoursequeueadmin::queued_selfenrollment();
} else {
my %selfenroll = (
$uname.':'.$udom => $now.':'.$usec,
);
my $putresult = &Apache::lonnet::put($namespace,\%selfenroll,$cdom,$cnum);
+ my $status = 'request';
+ if ($selfenroll_approval eq '2') {
+ $status = 'pending';
+ }
if ($putresult eq 'ok') {
my %userenroll = (
$cdom.'_'.$cnum => {
timestamp => $now,
section => $usec,
- status => 'request',
+ status => $status,
});
+ my $token;
+ if ($status eq 'pending') {
+ $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);
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.').'<br />'.
- &mt('A message will be sent to your LON-CAPA account when the course coordinator takes action on your request.').'<br />'.
- &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
- 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).'<br />';
- }
- if ($warning) {
- $output .= '<span class="LC_warning">'.$warning.'</span><br />';
- }
-
- $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);
+ $output = &mt('Your request for self-enrollment has been recorded.').'<br />';
+ 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, at 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 .= '<form name="selfenrollvalidation" action="'.$url.'" method="post">'."\n";
+ foreach my $field (@fields) {
+ if ($postvalues{$field}) {
+ $output .= '<input type="hidden" name="'.$field.'" value="'.$postvalues{$field}.'" />'."\n";
+ }
+ }
+ if ($buttontext eq '') {
+ $buttontext = &mt('Complete my enrollment');
+ }
+ my $protocol = $Apache::lonnet::protocol{$lonhost};
+ $protocol = 'http' if ($protocol ne 'https');
+ my $enroller = $protocol.'://'.&Apache::lonnet::hostname($lonhost).'/cgi-bin/enrollqueued.pl';
+ $output .= '<input type="hidden" name="enroller" value="'.$enroller.'" />'."\n".
+ '<input type="submit" name="validate" value="'.$buttontext.'" />'."\n".
+ '</form>'."\n";
+ } else {
+ $status = 'request';
+ }
+ }
+ } else {
+ $status = 'request';
+ }
+ }
+ if ($status eq 'request') {
+ $output .= &mt('A message will be sent to your LON-CAPA account when the course coordinator takes action on your request.').'<br />'.
+ &mt('To access your LON-CAPA message, go to the Main Menu and click on "Send and Receive Messages".').'<br />';
+ 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).'<br />';
+ }
+ if ($warning) {
+ $output .= '<span class="LC_warning">'.$warning.'</span><br />';
+ }
+ $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 = '<span class="LC_error">'.&mt('An error occurred when recording your request.').'</span>';
More information about the LON-CAPA-cvs
mailing list