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

raeburn raeburn@source.lon-capa.org
Tue, 18 Aug 2009 20:06:51 -0000


raeburn		Tue Aug 18 20:06:51 2009 EDT

  Modified files:              
    /loncom/interface	lonrequestcourse.pm 
  Log:
  - lonrequestcourse.pm uses lonnet::auto_validate_instcode() to check if request should be 
  processed:
    - result (ultimately from localenroll.pm) will be one of: valid, pending, approval or 
      error.
  
  
Index: loncom/interface/lonrequestcourse.pm
diff -u loncom/interface/lonrequestcourse.pm:1.16 loncom/interface/lonrequestcourse.pm:1.17
--- loncom/interface/lonrequestcourse.pm:1.16	Tue Aug 18 01:41:37 2009
+++ loncom/interface/lonrequestcourse.pm	Tue Aug 18 20:06:51 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Request a course
 #
-# $Id: lonrequestcourse.pm,v 1.16 2009/08/18 01:41:37 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.17 2009/08/18 20:06:51 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -775,7 +775,7 @@
             }
             if ($instcode ne '') {
                 $code_chk = &Apache::lonnet::auto_validate_instcode('',$dom,$instcode);
-                if ($code_chk eq 'ok') {
+                if ($code_chk eq 'valid') {
                     $message = '<div class="LC_info">'.
                                &mt('The chosen course category [_1] is valid.','<b>'.
                                $instcode.'</b>').'</div>';
@@ -1808,6 +1808,7 @@
     }
     $now = time;
     $crstype = $env{'form.crstype'};
+    my @instsections;
     if ($crstype eq 'official') {
         if (&Apache::lonnet::auto_run('',$dom)) {
             ($enrollstart,$enrollend)=&dates_from_form('enrollstart','enrollend');
@@ -1815,7 +1816,11 @@
         for (my $i=0; $i<$env{'form.sectotal'}; $i++) {
             if ($env{'form.sec_'.$i}) {
                 if ($env{'form.secnum_'.$i} ne '') {
-                    $sections{$i}{'inst'} = $env{'form.secnum_'.$i};
+                    my $sec = $env{'form.secnum_'.$i};
+                    $sections{$i}{'inst'} = $sec;
+                    if (($sec ne '') && (!grep(/^\Q$sec\E$/,@instsections))) {
+                        push(@instsections,$sec);
+                    }
                     $sections{$i}{'loncapa'} = $env{'form.loncapasec_'.$i};
                 }
             }
@@ -1973,6 +1978,7 @@
                         details   => $details,
                       );
         my $requestkey = $dom.'_'.$cnum;
+        my $validationerror;
         if ($val eq 'autolimit=') {
             $disposition = 'process';
         } elsif ($val =~ /^autolimit=(\d+)$/) {
@@ -1980,9 +1986,32 @@
             $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
                                             $dom,$crstype,$limit,\$message);
         } elsif ($val eq 'validate') {
-            $disposition =
-                &Apache::lonnet::auto_courserequest_validation($dom,$details,
-                                                              \@inststatuses,\$message);
+            my $inststatuslist;
+            if (@inststatuses > 0) {
+                $inststatuslist = join(',',@inststatuses);
+            }
+            my $instseclist;
+            if (@instsections > 0) {
+                $instseclist = join(',',@instsections);
+            }
+            my $validation = 
+                &Apache::lonnet::auto_validate_instcode('',$dom,$instcode,
+                    $env{'user.name'}.':'.$env{'user.domain'},$inststatuslist,
+                    $instseclist);
+            if ($validation eq 'valid') {
+                $disposition = 'process';
+            } elsif ($validation eq 'rejected') {
+                $disposition = 'rejected';
+            } elsif ($validation eq 'pending') {
+                $disposition = 'pending';
+            } elsif ($disposition eq 'approval') {
+                $disposition = 'approval';
+            } elsif ($disposition =~ /^error(.*)$/) {
+                $disposition = 'approval';
+                $validationerror = $1;
+            } else {
+                $disposition = 'approval';  
+            }
         } else {
             $disposition = 'approval';
         }
@@ -2035,13 +2064,13 @@
             my $statuskey = 'status:'.$dom.':'.$cnum;
             my %userreqhash = &Apache::lonnet::get('courserequests',[$statuskey],
                                                    $env{'user.domain'},$env{'user.name'});
-            if (exists($userreqhash{$statuskey})) {
+            if ($userreqhash{$statuskey} ne '') {
                 $modified = 1;
                 my %queuehash = &Apache::lonnet::get_dom('courserequestqueue',
                                                          [$cnum.'_approval',
                                                           $cnum.'_pending'],$dom);
-                if ((exists($queuehash{$cnum.'_approval'})) || 
-                    (exists($queuehash{$cnum.'_pending'}))) {
+                if (($queuehash{$cnum.'_approval'} ne '') || 
+                    ($queuehash{$cnum.'_pending'} ne '')) {
                     $queued = 1;
                 }
             }
@@ -2084,6 +2113,9 @@
             $output .= '<p>'.&mt('Your course request has been updated').'</p>'.
                        &notification_information($disposition,$req_notifylist,$cnum,$now);
         }
+        if ($validationerror ne '') {
+            $output .= '<span class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: {_1].',$validationerror).'</p>';
+        }
     }
     return $output;
 }
@@ -2111,12 +2143,16 @@
             my $sender = $env{'user.name'}.':'.$env{'user.domain'};
             &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,"$fullname ($env{'user.name'}:$env{'user.domain'})",$cnum,$env{'form.cdescr'},$now,'coursereq',$sender);
         }
-    } else {
+    } elsif ($disposition eq 'pending') {
         $output .= '<div class="LC_info">'.
 &mt('Your request has been placed in a queue pending administrative action.').'<br />'.
 &mt("Usually this means that your institution's information systems do not list you among the instructional personnel for this course.").'<br />'.
 &mt('The list of instructional personnel for the course will be automatically checked daily, and once you are listed the request will be processed.').
                    '</div>';
+    } else {
+        $output .= '<div class="LC_warning">'.
+                   &mt('Your request status is: [_1].',$disposition). 
+                   '</div>'
     }
     return $output;
 }