[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface selfenroll.pm

raeburn raeburn at source.lon-capa.org
Sun Apr 6 10:24:41 EDT 2014


raeburn		Sun Apr  6 14:24:41 2014 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/interface	selfenroll.pm 
  Log:
  - For 2.11
    - Backport 1.31.
  
  
-------------- next part --------------
Index: loncom/interface/selfenroll.pm
diff -u loncom/interface/selfenroll.pm:1.27.2.2 loncom/interface/selfenroll.pm:1.27.2.3
--- loncom/interface/selfenroll.pm:1.27.2.2	Sat Apr  5 13:17:16 2014
+++ loncom/interface/selfenroll.pm	Sun Apr  6 14:24:40 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Allow users to self-enroll in a course
 #
-# $Id: selfenroll.pm,v 1.27.2.2 2014/04/05 13:17:16 raeburn Exp $
+# $Id: selfenroll.pm,v 1.27.2.3 2014/04/06 14:24:40 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -542,9 +542,22 @@
     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.').
-                  '<br /><br />'.&Apache::loncoursequeueadmin::queued_selfenrollment();
+        my $status;
+        $output = &mt('A self-enrollment request already exists for you for this course.').'<br />';
+        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.').
+                       '<br /><br />'.&Apache::loncoursequeueadmin::queued_selfenrollment();
+        }
     } else {
         my %selfenroll = (
                             $uname.':'.$udom => $now.':'.$usec,
@@ -575,51 +588,11 @@
             }
             $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';
-                        } 
-                    }
+                my ($statusupdate,$pendingform) = &pending_selfenrollment_form($cdom,$cnum,$crstype,$token,$lonhost);
+                if ($statusupdate eq 'request') {
+                    $status = $statusupdate;
                 } else {
-                    $status = 'request';
+                    $output .= $pendingform;
                 }
             }
             if ($status eq 'request') {
@@ -655,6 +628,59 @@
     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, 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="hidden" name="token" value="'.$token.'" />'."\n".
+                           '<input type="submit" name="validate" value="'.$buttontext.'" />'."\n".
+                           '</form>'."\n";
+                $status = 'pending';
+            } else {
+                $status = 'request';
+            }
+        }
+    } else {
+        $status = 'request';
+    }
+    return ($status,$output);
+}
+
 sub jump_to_role {
     my ($role) = @_;
     my $output = <<"END";


More information about the LON-CAPA-cvs mailing list