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

raeburn raeburn@source.lon-capa.org
Thu, 20 Aug 2009 21:15:37 -0000


raeburn		Thu Aug 20 21:15:37 2009 EDT

  Modified files:              
    /loncom/interface	lonrequestcourse.pm 
  Log:
  - Change mechanism for choosing domain to default to on course request main menu.
  - Missing punctuation.
  - Use approval instead of approve for name of option, for consistency with
    request processing.
  - entries in reqcrsotherdom are in the form $dom:$value (where $value is approval, validate, autolimit etc.) not simply $dom.  
  
  
Index: loncom/interface/lonrequestcourse.pm
diff -u loncom/interface/lonrequestcourse.pm:1.18 loncom/interface/lonrequestcourse.pm:1.19
--- loncom/interface/lonrequestcourse.pm:1.18	Wed Aug 19 20:12:04 2009
+++ loncom/interface/lonrequestcourse.pm	Thu Aug 20 21:15:37 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Request a course
 #
-# $Id: lonrequestcourse.pm,v 1.18 2009/08/19 20:12:04 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.19 2009/08/20 21:15:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -429,6 +429,8 @@
     my ($dom,$can_request) = @_;
     my $canreq = 0;
     my ($types,$typename) = &course_types();
+    my @options = ('approval','validate','autolimit');
+    my $optregex = join('|',@options);
     if ((ref($can_request) eq 'HASH') && (ref($types) eq 'ARRAY')) {
         foreach my $type (@{$types}) {
             if (&Apache::lonnet::usertools_access($env{'user.name'},
@@ -444,7 +446,7 @@
                 if (@curr > 0) {
                     $canreq ++;
                     unless ($dom eq $env{'user.domain'}) {
-                        if (grep(/^\Q$dom\E$/,@curr)) {
+                        if (grep(/^\Q$dom\E:($optregex)(=?\d*)$/,@curr)) {
                             $can_request->{$type} = 1;
                         }
                     }
@@ -1749,17 +1751,47 @@
 
 sub get_course_dom {
     my $codedom = &Apache::lonnet::default_login_domain();
+    if ($env{'form.showdom'} ne '') {
+        if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
+            return $env{'form.showdom'};
+        }
+    }
     if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne 'public')) {
+        my ($types,$typename) = &course_types();
+        if (ref($types) eq 'ARRAY') {
+            foreach my $type (@{$types}) {
+                if (&Apache::lonnet::usertools_access($env{'user.name'},
+                                                      $env{'user.domain'},$type,
+                                                      undef,'requestcourses')) {
+                    return $env{'user.domain'};
+                }
+            }
+            my @possible_doms;
+            foreach my $type (@{$types}) {
+                my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
+                if ($dom_str ne '') {
+                    my @domains = split(',',$dom_str);
+                    foreach my $entry (@domains) {
+                        my ($extdom,$extopt) = split(':',$entry);
+                        if ($extdom eq $env{'request.role.domain'}) {
+                            return $extdom;
+                        } 
+                        unless(grep(/^\Q$extdom\E$/,@possible_doms)) {
+                            push(@possible_doms,$extdom);
+                        }
+                    }
+                }
+            }
+            if (@possible_doms) {
+                @possible_doms = sort(@possible_doms);
+                return $possible_doms[0];
+            }
+        }
         $codedom = $env{'user.domain'};
         if ($env{'request.role.domain'} ne '') {
             $codedom = $env{'request.role.domain'};
         }
     }
-    if ($env{'form.showdom'} ne '') {
-        if (&Apache::lonnet::domain($env{'form.showdom'}) ne '') {
-            $codedom = $env{'form.showdom'};
-        }
-    }
     return $codedom;
 }
 
@@ -1962,9 +1994,9 @@
     my $val = &get_processtype($dom,$crstype,\@inststatuses,\%domconfig);
     if ($val eq '') {
         if ($crstype eq 'official') {
-            $output = &mt('You are not permitted to request creation of official courses');
+            $output = &mt('You are not permitted to request creation of official courses.');
         } elsif ($crstype eq 'unofficial') {
-            $output = &mt('You are not permitted to request creation of unofficial courses');
+            $output = &mt('You are not permitted to request creation of unofficial courses.');
         } elsif ($crstype eq 'community') {
             $output = &mt('You are not permitted to request creation of communities');
         } else {
@@ -2114,7 +2146,7 @@
                        &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>';
+            $output .= '<span class="LC_warning">'.&mt('An error occurred validating your request with institutional data sources: [_1].',$validationerror).'</p>';
         }
     }
     return $output;
@@ -2161,7 +2193,7 @@
     my ($dom,$crstype,$inststatuses,$domconfig) = @_;
     return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
     my (%userenv,%settings,$val);
-    my @options = ('autolimit','validate','approve');
+    my @options = ('autolimit','validate','approval');
     if ($dom eq $env{'user.domain'}) {
         %userenv = 
             &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'},
@@ -2227,11 +2259,17 @@
     } else {
         %userenv = &Apache::lonnet::userenvironment($env{'user.domain'},
                       $env{'user.name'},'reqcrsotherdom.'.$env{'form.crstype'});
-        if ($userenv{'reqcrsotherdom'}) {
-            my @doms = split(',',$userenv{'reqcrsotherdom'});
-            my $optregex = join('|',@options); 
-            if (grep(/^\Q$dom\E:($optregex=?\d*)/,@doms)) {
-                $val = $1;
+        if ($userenv{'reqcrsotherdom.'.$crstype}) {
+            my @doms = split(',',$userenv{'reqcrsotherdom.'.$crstype});
+            my $optregex = join('|',@options);
+            foreach my $item (@doms) {
+                my ($extdom,$extopt) = split(':',$item);
+                if ($extdom eq $dom) {  
+                    if ($extopt =~ /^($optregex)(=?\d*)$/) {
+                        $val = $1.$2;
+                    }
+                    last;
+                }
             }
             @{$inststatuses} = ('_external_');
         }