b3d64986be797cc7f4e48ee7d6f1004e3005031b
braney
  Tue May 20 16:24:22 2014 -0700
fix a couple problems found in code review, add some comments, andrearrange the code a little

diff --git src/hg/hgHubConnect/hgHubConnect.c src/hg/hgHubConnect/hgHubConnect.c
index 4e28b57..2b54555 100644
--- src/hg/hgHubConnect/hgHubConnect.c
+++ src/hg/hgHubConnect/hgHubConnect.c
@@ -226,35 +226,31 @@
     else
 	{
 	// give people a chance to clear the error 
 	ourCellStart();
 	printf(
 	"<input name=\"hubClearButton\""
 	    "onClick=\"document.resetHubForm.elements['hubUrl'].value='%s';"
 		"document.resetHubForm.submit();return true;\" "
 		"class=\"hubField\" type=\"button\" value=\"check hub\">\n"
 		, hub->hubUrl);
 	ourCellEnd();
 	}
     if (hub->trackHub != NULL)
 	{
 	if (hub->trackHub->descriptionUrl != NULL)
-	    {
-	    printf("<A href=%s>\n", hub->trackHub->descriptionUrl);
-	    ourPrintCell(hub->trackHub->shortLabel);
-	    puts("</A>");
-	    }
+	    ourPrintCellLink(hub->trackHub->shortLabel, hub->trackHub->descriptionUrl);
 	else
 	    ourPrintCell(hub->trackHub->shortLabel);
 	}
     else
 	ourPrintCell("");
 
     if (!isEmpty(hub->errorMessage))
 	printf("<TD><span class=\"hubError\">ERROR: %s </span>"
 	    "<a href=\"../goldenPath/help/hgTrackHubHelp.html#Debug\">Debug</a></TD>\n", 
 	    hub->errorMessage);
     else if (hub->trackHub != NULL)
 	ourPrintCell(hub->trackHub->longLabel);
     else
 	ourPrintCell("");
 
@@ -310,69 +306,70 @@
 
 return urlSearchHash;
 }
 
 static struct hash *outputPublicTable(struct sqlConnection *conn, char *publicTable, char *statusTable)
 /* Put up the list of public hubs and other controls for the page. */
 {
 char *trixFile = cfgOptionEnvDefault("HUBSEARCHTRIXFILE", "hubSearchTrixFile", "/gbdb/hubs/public.ix");
 char *hubSearchTerms = cartOptionalString(cart, hgHubSearchTerms);
 boolean haveTrixFile = fileExists(trixFile);
 struct hash *urlSearchHash = NULL;
 
 if (haveTrixFile && !isEmpty(hubSearchTerms))
     urlSearchHash = getUrlSearchHash(trixFile, hubSearchTerms);
 
-addPublicHubsToHubStatus(conn, publicTable, statusTable);
-
-struct hash *publicHash = NULL;
-char query[512];
-bool hasDescription = sqlColumnExists(conn, publicTable, "descriptionUrl");
-
-if (hasDescription)
-    sqlSafef(query, sizeof(query), "select p.hubUrl,p.shortLabel,p.longLabel,p.dbList,s.errorMessage,s.id,p.descriptionUrl from %s p,%s s where p.hubUrl = s.hubUrl", 
-	  publicTable, statusTable); 
-else
-    sqlSafef(query, sizeof(query), "select p.hubUrl,p.shortLabel,p.longLabel,p.dbList,s.errorMessage,s.id from %s p,%s s where p.hubUrl = s.hubUrl", 
-	 publicTable, statusTable); 
-
-struct sqlResult *sr = sqlGetResult(conn, query);
-char **row;
-int count = 0;
-
+// if we have search terms, put out the line telling the user so
 if (!isEmpty(hubSearchTerms))
     {
     printf("<BR>List restricted by search terms : %s\n", hubSearchTerms);
     puts("<input name=\"hubDeleteSearchButton\""
 	"onClick="
 	"\" document.searchHubForm.elements['hubSearchTerms'].value=\'\';"
 	"document.searchHubForm.submit();return true;\" "
 	"class=\"hubField\" type=\"button\" value=\"Delete Search Terms\">\n");
     printf("<BR>\n");
     }
 
+// if we have a trix file, draw the search box
 if (haveTrixFile)
     {
     puts("<input name=\"hubSearchTerms\" id=\"hubSearchTerms\" class=\"hubField\""
 	"type=\"text\" size=\"65\"> \n"
     "<input name=\"hubSearchButton\""
 	"onClick="
 	"\" document.searchHubForm.elements['hubSearchTerms'].value=hubSearchTerms.value;"
 	    "document.searchHubForm.submit();return true;\" "
 	    "class=\"hubField\" type=\"button\" value=\"Search Public Hubs\">\n");
     }
 
+// make sure all the public hubs are in the hubStatus table.
+addPublicHubsToHubStatus(conn, publicTable, statusTable);
+
+struct hash *publicHash = NULL;
+char query[512];
+bool hasDescription = sqlColumnExists(conn, publicTable, "descriptionUrl");
+if (hasDescription)
+    sqlSafef(query, sizeof(query), "select p.hubUrl,p.shortLabel,p.longLabel,p.dbList,s.errorMessage,s.id,p.descriptionUrl from %s p,%s s where p.hubUrl = s.hubUrl", 
+	  publicTable, statusTable); 
+else
+    sqlSafef(query, sizeof(query), "select p.hubUrl,p.shortLabel,p.longLabel,p.dbList,s.errorMessage,s.id from %s p,%s s where p.hubUrl = s.hubUrl", 
+	 publicTable, statusTable); 
+
+struct sqlResult *sr = sqlGetResult(conn, query);
+char **row;
+int count = 0;
 boolean gotAnyRows = FALSE;
 while ((row = sqlNextRow(sr)) != NULL)
     {
     ++count;
     char *url = row[0], *shortLabel = row[1], *longLabel = row[2], 
     	  *dbList = row[3], *errorMessage = row[4], *descriptionUrl = row[6];
     int id = atoi(row[5]);
 
     if ((urlSearchHash != NULL) && (hashLookup(urlSearchHash, url) == NULL))
 	continue;
 
     if (gotAnyRows)
 	webPrintLinkTableNewRow();
     else
 	{
@@ -408,35 +405,31 @@
 	{
 	// give user a chance to clear the error
 	ourCellStart();
 	printf(
 	"<input name=\"hubClearButton\""
 	    "onClick=\"document.resetHubForm.elements['hubUrl'].value='%s';"
 		"document.resetHubForm.submit();return true;\" "
 		"class=\"hubField\" type=\"button\" value=\"check hub\">"
 		, url);
 	ourCellEnd();
 	}
     else
 	errAbort("cannot get id for hub with url %s\n", url);
 
     if (hasDescription && !isEmpty(descriptionUrl))
-	{
-	printf("<A HREF=\"%s\">\n", descriptionUrl);
 	ourPrintCellLink(shortLabel, descriptionUrl);
-	puts("</A>");
-	}
     else
 	ourPrintCell(shortLabel);
     if (isEmpty(errorMessage))
 	ourPrintCell(longLabel);
     else
 	printf("<TD><span class=\"hubError\">ERROR: %s </span>"
 	    "<a href=\"../goldenPath/help/hgTrackHubHelp.html#Debug\">Debug</a></TD>", 
 	    errorMessage);
 
     printGenomeList(slNameListFromComma(dbList), count); // Leaking a bit of memory
     ourPrintCell(url);
 
     hashStore(publicHash, url);
     }
 sqlFreeResult(&sr);