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

raeburn raeburn@source.lon-capa.org
Sun, 25 Oct 2009 15:53:25 -0000


raeburn		Sun Oct 25 15:53:25 2009 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm 
  Log:
  - DC configuration of log-in page redirect for multi-domain server case.
     - &dom_servers() returns hash of key => value pairs,
         where key is lonHostID and value is hostname
       - each hostname is included exactly once for any servers belonging 
         to domains associated with the primary library server for the 
         domain being configured. 
  
  
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.116 loncom/interface/domainprefs.pm:1.117
--- loncom/interface/domainprefs.pm:1.116	Fri Oct 23 16:14:43 2009
+++ loncom/interface/domainprefs.pm	Sun Oct 25 15:53:25 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.116 2009/10/23 16:14:43 bisitz Exp $
+# $Id: domainprefs.pm,v 1.117 2009/10/25 15:53:25 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -320,7 +320,7 @@
                             }],
                  },
     );
-    my %servers = &Apache::lonnet::get_servers($dom);
+    my %servers = &dom_servers($dom);
     if (keys(%servers) > 1) {
         $prefs{'login'}  = { text   => 'Log-in page options',
                              help   => 'Domain_Configuration_Login_Page',
@@ -617,7 +617,7 @@
     my $itemcount = 1;
 
     if ($position eq 'top') {
-        my %servers = &Apache::lonnet::get_servers($dom);
+        my %servers = &dom_servers($dom);
         my $choice = $choices{'disallowlogin'};
         $css_class = ' class="LC_odd_row"';
         $datatable .= '<tr'.$css_class.'><td>'.$choices{'disallowlogin'}.'</td>'.
@@ -3163,7 +3163,7 @@
                                          \%loginhash);
     }
 
-    my %servers = &Apache::lonnet::get_servers($dom);
+    my %servers = &dom_servers($dom);
     if (keys(%servers) > 1) {
         foreach my $lonhost (keys(%servers)) {
             next if ($env{'form.'.$lonhost.'_serverurl'} eq $curr_loginvia{$lonhost});
@@ -5666,4 +5666,37 @@
     return;
 }
 
+sub dom_servers {
+    my ($dom) = @_;
+    my (%uniqservers,%servers);
+    my $primaryserver = &Apache::lonnet::hostname(&Apache::lonnet::domain($dom,'primary'));
+    my @machinedoms = &Apache::lonnet::machine_domains($primaryserver);
+    foreach my $mdom (@machinedoms) {
+        my %currservers = %servers;
+        my %server = &Apache::lonnet::get_servers($mdom);
+        %servers = (%currservers,%server);
+    }
+    my %by_hostname;
+    foreach my $id (keys(%servers)) {
+        push(@{$by_hostname{$servers{$id}}},$id);
+    }
+    foreach my $hostname (sort(keys(%by_hostname))) {
+        if (@{$by_hostname{$hostname}} > 1) {
+            my $match = 0;
+            foreach my $id (@{$by_hostname{$hostname}}) {
+                if (&Apache::lonnet::host_domain($id) eq $dom) {
+                    $uniqservers{$id} = $hostname;
+                    $match = 1;
+                }
+            }
+            unless ($match) {
+                $uniqservers{$by_hostname{$hostname}[0]} = $hostname;
+            }
+        } else {
+            $uniqservers{$by_hostname{$hostname}[0]} = $hostname;
+        }
+    }
+    return %uniqservers;
+}
+
 1;