[LON-CAPA-cvs] cvs: loncom /interface loncreateuser.pm selfenroll.pm

raeburn raeburn@source.lon-capa.org
Mon, 09 Feb 2009 04:11:11 -0000


raeburn		Mon Feb  9 04:11:11 2009 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm selfenroll.pm 
  Log:
  - Store enrollment request record in requestor's own selfenrollrequests.db (as well as in corresponding db file for the course).
  - Modify record in requestor's selfenrollrequests.db when CC approves or rejects enrollment request.
  
  
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.279 loncom/interface/loncreateuser.pm:1.280
--- loncom/interface/loncreateuser.pm:1.279	Sun Feb  8 20:01:54 2009
+++ loncom/interface/loncreateuser.pm	Mon Feb  9 04:11:11 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.279 2009/02/08 20:01:54 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.280 2009/02/09 04:11:11 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4172,7 +4172,8 @@
     my $hostname = &Apache::lonnet::hostname($chome);
     my $protocol = $Apache::lonnet::protocol{$chome};
     $protocol = 'http' if ($protocol ne 'https');
-    my (@existing,@missingreq,@invalidusers,@limitexceeded,@enrolled,@enrollerrors,);
+    my (@existing,@missingreq,@invalidusers,@limitexceeded,@enrolled,
+        @enrollerrors,@warn_approves,@warn_rejects);
     my $now = time;
     my $sender = $env{'user.name'}.':'.$env{'user.domain'};
     my $approvedmsg = [{
@@ -4225,6 +4226,19 @@
                     $stucounts->{'selfenrolled'} ++;
                     &Apache::selfenroll::send_notification($uname.':'.$udom,$approvedmsg,$cid,
                                                $coursedesc,$now,'enroller',$sender);
+                    my %userrequest = (
+                        $cdom.'_'.$cnum => {
+                           timestamp   => $now,
+                           section     => $usec,
+                           adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
+                           status      => 'approved',
+                       }
+                    );
+                    my $userresult = 
+                        &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
+                    if ($userresult ne 'ok') {
+                        push(@warn_approves,$uname.':'.$udom);
+                    }
                 } else {
                     push(@enrollerrors,$uname.':'.$udom);
                 }
@@ -4238,6 +4252,19 @@
         foreach my $user (@rejections) {
             &Apache::selfenroll::send_notification($user,$rejectedmsg,$cid,
                                                    $coursedesc,$now,'enroller',$sender);
+            my ($uname,$udom) = split(/:/,$user);
+            my %userrequest = (
+                $cdom.'_'.$cnum => {
+                    timestamp   => $now,
+                    adjudicator => $env{'user.name'}.':'.$env{'user.domain'}, 
+                    status      => 'rejected',
+                }
+            );
+            my $userresult = 
+                &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
+            if ($userresult ne 'ok') {
+                push(@warn_rejects,$user);
+            }
         }
     }
     if (@changes) {
@@ -4306,6 +4333,20 @@
         }
         $r->print('</ul></p>');
     }
+    if (@warn_approves) {
+        $r->print('<p>'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'<ul>');
+        foreach my $user (@warn_approves) {
+            $r->print('<li>'.$user.'</li>');
+        }
+        $r->print('</ul></p>');
+    }
+    if (@warn_rejects) {
+        $r->print('<p>'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'<ul>');
+        foreach my $user (@warn_rejects) {
+            $r->print('<li>'.$user.'</li>');
+        }
+        $r->print('</ul></p>');
+    }
     return;
 }
 
Index: loncom/interface/selfenroll.pm
diff -u loncom/interface/selfenroll.pm:1.15 loncom/interface/selfenroll.pm:1.16
--- loncom/interface/selfenroll.pm:1.15	Thu Feb  5 12:27:21 2009
+++ loncom/interface/selfenroll.pm	Mon Feb  9 04:11:11 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Allow users to self-enroll in a course
 #
-# $Id: selfenroll.pm,v 1.15 2009/02/05 12:27:21 raeburn Exp $
+# $Id: selfenroll.pm,v 1.16 2009/02/09 04:11:11 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -550,16 +550,31 @@
                          );
         my $putresult = &Apache::lonnet::put($namespace,\%selfenroll,$cdom,$cnum);
         if ($putresult eq 'ok') {
+            my %userenroll = (
+                               $cdom.'_'.$cnum =>  {
+                                                      timestamp => $now,
+                                                      section   => $usec,
+                                                      status    => 'request', 
+                                                   });
+            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('A message will be sent to your LON-CAPA account when the course coordinator takes action on your request.').'<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);
+                $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 />';
             }
+  
             if ($selfenroll_notifylist) {
                 my $fullname = &Apache::loncommon::plainname($uname,$udom);
                 my %courseinfo = &Apache::lonnet::coursedescription($cdom.'_'.$cnum);
@@ -589,13 +604,14 @@
         $rawsubj = 'Self-enrollment requests processed';
         push(@rawmsg,{
                       mt => 'Enrollment requests in the following course: [_1] have been processed.',
-                      args => [$coursedesc],
+                      args => ["\n$coursedesc\n"],
                      });
     } elsif ($context eq 'enroller') {
         $rawsubj = 'Enrollment request';
         push(@rawmsg,{
                       mt  => 'Your request for enrollment in the following course: [_1], requested on [_2], has been reviewed by a Course Coordinator.',
-                      args => [$coursedesc,$timestamp],
+                      args => ["\n$coursedesc\n","$timestamp\n"],
+
                      });
         if (ref($textstr) eq 'ARRAY') {
             push(@rawmsg,@{$textstr});
@@ -604,10 +620,11 @@
         $rawsubj = 'Self-enrollment request';
         push(@rawmsg,{
                       mt  => 'Enrollment in the following course: [_1] was requested by [_2] on [_3].',
-                      args => [$coursedesc,$textstr,$timestamp],
+                      args => ["\n$coursedesc\n",$textstr,$timestamp],
                      },
                      {
-                      mt =>'As Course Coordinator, use Main Menu -> Manage Couse Users -> "Enrollment Requests" to display a list of pending enrollment requests which you can either approve or reject.'
+                      mt =>'As Course Coordinator, use: [_1]Main Menu -> Manage Couse Users -> Enrollment Requests[_1] to display a list of pending enrollment requests,[_1] which you can either approve or reject.',
+                      args => ["\n"],
                      });
     }
     my @to_notify = split(/,/,$notifylist);