24295958e3a35c027cf4727e43823283d80ae697
larrym
  Tue Apr 3 12:48:49 2012 -0700
replace use of SUPPORT_EURONODE with geoMirrorEnabled()
diff --git src/hg/lib/web.c src/hg/lib/web.c
index fd3cbb1..6b4c66d 100644
--- src/hg/lib/web.c
+++ src/hg/lib/web.c
@@ -14,30 +14,31 @@
 #include "dbDb.h"
 #include "hgColors.h"
 #include "hubConnect.h"
 #include "search.h"
 #ifndef GBROWSE
 #include "axtInfo.h"
 #include "wikiLink.h"
 #include "googleAnalytics.h"
 #include "jsHelper.h"
 #endif /* GBROWSE */
 #include "errabort.h"  // FIXME tmp hack to try to find source of popWarnHandler underflows in browse
 /* phoneHome business */
 #include <utime.h>
 #include <htmlPage.h>
 #include <signal.h>
+#include "geoMirror.h"
 /* phoneHome business */
 
 
 /* flag that tell if the CGI header has already been outputed */
 boolean webHeadAlreadyOutputed = FALSE;
 /* flag that tell if text CGI header hsa been outputed */
 boolean webInTextMode = FALSE;
 static char *dbCgiName = "db";
 static char *orgCgiName = "org";
 static char *cladeCgiName = "clade";
 static char *extraStyle = NULL;
 
 /* global: a cart for use in error handlers. */
 static struct cart *errCart = NULL;
 
@@ -374,80 +375,74 @@
             printf("<TD><A HREF='../goldenPath/help/hgSessionHelp.html'");
         else if (endsWith(scriptName, "pbGateway"))
             printf("<TD><A HREF='../goldenPath/help/pbTracksHelpFiles/pbTracksHelp.shtml'");
         else if (endsWith(scriptName, "hgVisiGene"))
             printf("<TD><A HREF='../goldenPath/help/hgTracksHelp.html#VisiGeneHelp'");
         else
             printf("<TD><A HREF='../goldenPath/help/hgTracksHelp.html'");
         printf(" class='topbar'>Help</A></TD>\n");
         }
     }
     printf("<TD style='width:95%%'>&nbsp;</TD></TR></TABLE>\n"); // last column squeezes other columns left
     puts("</TD></TR>\n");
 
 #endif
 
-#ifdef SUPPORT_EURONODE
-
-if (endsWith(scriptName, "hgGateway"))  // DEBUG
+if (endsWith(scriptName, "hgGateway") && geoMirrorEnabled())
     {
+    // Show an opt-out alert if user is on a host to which user has been automatically redirected (just once, right after they have been redirected)
     char *source = cgiOptionalString("source");
-    if (source)
+    char *redirect = cgiOptionalString("redirect");
+    if (source != NULL && redirect != NULL && sameString(redirect, "auto"))
 	{
 	char *domain = cgiServerName();
 	char *port = cgiServerPort();
-	char *uri = cgiRequestUri();
-	    //   /cgi-bin/test.cgi?x=15&y=youdog
-	int newUriSize = strlen(uri)+1024;
-	char *newUri = needMem(newUriSize);
+        // We don't bother maintaining stuff in request URI, because it may contain items like hgsid and other host specific values
+        int newUriSize = 2048;
+	char *newUri = needMem(2048);
 	// TODO what about https?
-	safef(newUri, newUriSize, "http://%s:%s%s", source, port, uri);
-	char *zTerm = rStringIn("&source=", newUri);
-	if (zTerm)
-	    *zTerm = 0;
+	safef(newUri, newUriSize, "http://%s:%s/cgi-bin/hgGateway?redirect=manual&source=%s", source, port, domain);
 
 	//empty TD disappears
 	/*
 	printf("<TR><TD COLSPAN=3 id='redirectTd' onclick=\"javascript:document.getElementById('redirectTd').innerHTML='';\">"
 	    "<center>"
 	    "You've been redirected to your nearest mirror - %s<br>"
 	    "<a href=\"%s\">Take me back to %s</a>"
 	    "</center>"
 	    "</TD></TR>\n"
 	    , domain, newUri, source );
 	    "<h3 style=\"background-color: #2636d1; text-align: center; color:#E0F0F0; margin-top:0px;\">"
 	*/
 
 	printf("<TR><TD COLSPAN=3 id='redirectTd' onclick=\"javascript:document.getElementById('redirectTd').innerHTML='';\">"
 	    "<div style=\"margin: 10px 25%%; border-style:solid; border-width:thin; border-color:#97D897;\">"
 	    "<h3 style=\"background-color: #97D897; text-align: left; margin-top:0px; margin-bottom:0px;\">"
 	    "<img style=\"float:left; margin-top:4px; margin-left:3px; margin-right:4px;\" src=\"http://uswest.ensembl.org/i/info_blue_13.png\">"
 	    "You've been redirected to your nearest mirror - %s"
 	    "<img title=\"Hide hint panel\" alt=\"Hide hint panel\" style=\"float:right; margin-top:3px; margin-right:3px\" src=\"http://uswest.ensembl.org/i/close.gif\">"
 	    "</h3> "
 	    "<ul style=\"margin:5px;\">"
 	    "<li>Take me back to <a href=\"%s\">%s</a>"
 	    "</li>"
 	    "</ul>"
 	    "</div>"
 	    "</TD></TR>\n"
 	    , domain, newUri, source );
 	}
     }
 
-#endif
-
 if(!skipSectionHeader)
 /* this HTML must be in calling code if skipSectionHeader is TRUE */
     {
     puts(        // TODO: Replace nested tables with CSS (difficulty is that tables are closed elsewhere)
          "<!-- +++++++++++++++++++++ CONTENT TABLES +++++++++++++++++++ -->" "\n"
          "<TR><TD COLSPAN=3>\n"
          "      <!--outer table is for border purposes-->\n"
          "      <TABLE WIDTH='100%' BGCOLOR='#" HG_COL_BORDER "' BORDER='0' CELLSPACING='0' CELLPADDING='1'><TR><TD>\n"
          "    <TABLE BGCOLOR='#" HG_COL_INSIDE "' WIDTH='100%'  BORDER='0' CELLSPACING='0' CELLPADDING='0'><TR><TD>\n"
          "     <div class='subheadingBar'><div class='windowSize' id='sectTtl'>"
          );
     htmlTextOut(textOutBuf);
 
     puts(
          "     </div></div>\n"