8c6b14ddbd81e82fcc40a2b909fabea1d3a83096
max
  Thu Sep 13 16:07:27 2012 -0700
added optional (chrom,start,end)-column matching to itemDetailsHtmlTable code
diff --git src/hg/hgc/hgc.c src/hg/hgc/hgc.c
index 4ad4c82..0cee2ab 100644
--- src/hg/hgc/hgc.c
+++ src/hg/hgc/hgc.c
@@ -874,40 +874,65 @@
 {
 int i;
 struct dyString *s = newDyString(256), *d = NULL;
 
 dyStringAppend(s, orig);
 for (i=0; i<subCount; ++i)
     {
     d = dyStringSub(s->string, in[i], out[i]);
     dyStringFree(&s);
     s = d;
     d = NULL;
     }
 return s;
 }
 
+bool columnExists(struct sqlConnection *conn, char *tableName, char *column)
+/* checks if column exists in table */
+{
+    char query[1024];
+    safef(query, 1024, "SHOW COLUMNS FROM `%s` LIKE '%s'", tableName, column);
+    char buf[1024];
+    char *ret = sqlQuickQuery(conn, query, buf, 1024);
+    return (ret!=NULL);
+}
+
 void printItemDetailsHtml(struct trackDb *tdb, char *itemName)
 /* if track has an itemDetailsHtml, retrieve and print the HTML */
 {
 char *tableName = trackDbSetting(tdb, "itemDetailsHtmlTable");
 if (tableName != NULL)
     {
     struct sqlConnection *conn = hAllocConn(database);
-    struct itemDetailsHtml *html, *htmls
-        = sqlQueryObjs(conn, (sqlLoadFunc)itemDetailsHtmlLoad, sqlQueryMulti,
+    struct itemDetailsHtml *html, *htmls;
+    if (columnExists(conn, tableName, "chrom"))
+        htmls = sqlQueryObjs(conn, (sqlLoadFunc)itemDetailsHtmlLoad, sqlQueryMulti,
                        "select name, html from %s where name = '%s'", tableName, itemName);
+    else 
+        {
+        char *chrom = cgiString("c");
+        int start   = cgiInt("o");
+        int end     = cgiInt("t");
+
+        htmls = sqlQueryObjs(conn, (sqlLoadFunc)itemDetailsHtmlLoad, sqlQueryMulti,
+                       "select name, html from %s where \
+                       name = '%s' and \
+                       chrom = '%s' and \
+                       start = '%d' and \
+                       end = '%d'", tableName, itemName, chrom, start, end);
+        }
+
     for (html = htmls; html != NULL; html = html->next)
         printf("<br>\n%s\n", html->html);
     itemDetailsHtmlFreeList(&htmls);
     hFreeConn(&conn);
     }
 }
 
 char *getIdInUrl(struct trackDb *tdb, char *itemName)
 /* If we have an idInUrlSql tag, look up itemName in that, else just
  * return itemName. */
 {
 char *sql = trackDbSetting(tdb, "idInUrlSql");
 char *id = itemName;
 if (sql != NULL)
     {