--- loncom/interface/lonrequestcourse.pm	2009/08/20 21:15:37	1.19
+++ loncom/interface/lonrequestcourse.pm	2009/08/22 21:08:39	1.23
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Request a course
 #
-# $Id: lonrequestcourse.pm,v 1.19 2009/08/20 21:15:37 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.23 2009/08/22 21:08:39 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -116,13 +116,11 @@ use LONCAPA qw(:DEFAULT :match);
 
 sub handler {
     my ($r) = @_;
+    &Apache::loncommon::content_type($r,'text/html');
+    $r->send_http_header;
     if ($r->header_only) {
-        &Apache::loncommon::content_type($r,'text/html');
-        $r->send_http_header;
         return OK;
     }
-    &Apache::loncommon::content_type($r,'text/html');
-    $r->send_http_header;
 
     &Apache::lonhtmlcommon::clear_breadcrumbs();
     my $dom = &get_course_dom();
@@ -159,9 +157,10 @@ sub handler {
     $states{'view'} = ['pick_request','details','cancel','removal'];
     $states{'log'} = ['filter','display'];
     $states{'new'} = ['courseinfo','enrollment','personnel','review','process'];
+
     if (($action eq 'new') && ($env{'form.crstype'} eq 'official')) {
         unless ($env{'form.state'} eq 'crstype') {
-            unshift (@{$states{'new'}},'codepick');
+            unshift(@{$states{'new'}},'codepick');
         }
     }
 
@@ -793,7 +792,7 @@ sub print_request_form {
                 $message = '<div class="LC_warning">'.
                            &mt('No course was found matching your choice of institutional course category.');
             }
-            unless ($code_chk eq 'ok') {
+            unless ($code_chk eq 'valid') {
                 $prev = 'crstype';
             }
             $r->print($message);
@@ -811,12 +810,19 @@ sub print_request_form {
                 $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box().$codepicker.
                           &Apache::lonhtmlcommon::end_pick_box().'</div>');
             } else {
+                $next = $states->{$action}[$page+2];
                 $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
             }
         } else {
+            if ($crstype eq 'official') {
+                $next = $states->{$action}[$page+2];
+            }
             $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
         }
     } elsif ($prev eq 'codepick') {
+        if ($env{'form.instcode'} eq '') {
+            $prev = $states->{$action}[$page-2];
+        }
         $r->print(&courseinfo_form($dom,$formname,$crstype,$next));
     } elsif ($state eq 'enrollment') {
         if ($crstype eq 'official') {
@@ -1867,8 +1873,8 @@ sub print_request_outcome {
                         }
                     }
                 }
-                $xlistinfo .= $env{'form.crosslist_'.$i.'_instsec'};
-                $crosslistings{$i}{'inst'} = $xlistinfo;
+                $crosslistings{$i}{'instcode'} = $xlistinfo;
+                $crosslistings{$i}{'instsec'} = $env{'form.crosslist_'.$i.'_instsec'}; 
                 $crosslistings{$i}{'loncapa'} = $env{'form.crosslist_'.$i.'_lcsec'};
             }
         }
@@ -2018,7 +2024,7 @@ sub print_request_outcome {
             $disposition = &check_autolimit($env{'user.name'},$env{'user.domain'},
                                             $dom,$crstype,$limit,\$message);
         } elsif ($val eq 'validate') {
-            my $inststatuslist;
+            my ($inststatuslist,$validationchk,$validation);
             if (@inststatuses > 0) {
                 $inststatuslist = join(',',@inststatuses);
             }
@@ -2026,23 +2032,20 @@ sub print_request_outcome {
             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(.*)$/) {
+            $validationchk = 
+                &Apache::lonnet::auto_courserequest_validation($dom,
+                    $env{'user.name'}.':'.$env{'user.domain'},$crstype,
+                    $inststatuslist,$instcode,$instseclist);
+            if ($validationchk =~ /:/) {
+                ($validation,$message) = split(':',$validationchk);
+            } else {
+                $validation = $validationchk;
+            }
+            if ($validation =~ /^error(.*)$/) {
                 $disposition = 'approval';
                 $validationerror = $1;
             } else {
-                $disposition = 'approval';  
+                $disposition = $validation;
             }
         } else {
             $disposition = 'approval';
@@ -2206,7 +2209,7 @@ sub get_processtype {
             if (ref($domconfig->{'requestcourses'}) eq 'HASH') {
                 %settings = %{$domconfig->{'requestcourses'}};
                 if (ref($settings{$crstype}) eq 'HASH') {
-                    if (($env{'user.adv'}) && (exists($settings{$crstype}{'_LC_adv'}))) {
+                    if (($env{'user.adv'}) && ($settings{$crstype}{'_LC_adv'} ne '')) {
                         $val = $settings{$crstype}{'_LC_adv'};
                         @{$inststatuses} = ('_LC_adv_');
                     } else {
@@ -2365,7 +2368,7 @@ sub retrieve_settings {
                         my %crscode = (
                                         $i => $reqinfo{'crosslistings'}{$i}{'instcode'},
                                       );
-                        &extract_instcode($dom,'crosslist',\%crscode,$1,$xlistsec);
+                        &extract_instcode($dom,'crosslist',\%crscode,$i,$xlistsec);
                     }
                 }
             }
@@ -2391,7 +2394,7 @@ sub retrieve_settings {
                                                 if (grep(/^\Q$sec\E/,@currsec)) {
                                                     $env{'form.person_'.$i.'_sec'} = $sec;
                                                 } else {
-                                                    push (@newsecs,$sec);
+                                                    push(@newsecs,$sec);
                                                 }
                                             }
                                         }