#include #include "error.h" #include "datafile.h" #include "config.h" #include "cdbslib.h" #include "loadfile.h" #include "query_task.h" #include "cdbserror.h" #define OUTPUT 1 #define ERRMSG 2 #define TOPLINK 3 #define TXTLINK 4 #define TASKURL 5 /* QRYOUT_HTML -- Produce html output for the query task * * i: tab table descriptor */ void qryout_html (char *templat, table *tab) { FILE *fp; char *var; int html, title, icol, irow, iop; char params[SZ_LIST+1]; char *option, *value, *errbuf; static char *nbsp = " "; static char *omit = "v|text|html"; static char *varlist = "output|errmsg|toplink|txtlink|taskurl"; /* Get task parameters */ html = yorn (get_option("HTML")); title = yorn(get_option("title")); /* Open the html template file */ fp = fopen (templat, "r"); if (fp == NULL) cdbs_error (NOTOPEN, "%s", templat); /* Print the html response header if called as a cgi script */ if (html == YES) printf ("Content-type: text/html\n\n"); while ((var = html_template (fp)) != NULL) { switch (strmatch (var, varlist)) { case OUTPUT: /* Print output in html table format */ printf (" \n"); /* Print the title line */ if (title == YES) { for (icol = 0; icol < ncol_table(tab); icol ++) printf (" \n", get_tab_colname (tab, icol)); } /* Print the cells in the table */ for (irow = 0; irow < nrow_table(tab); irow ++) { printf (" \n"); for (icol = 0; icol < ncol_table(tab); icol ++) { value = get_tab_cell_bynum (tab, icol, irow); if (value[0] == EOS) value = nbsp; printf (" \n", value); } printf (" \n"); } printf ("
%s
%s
"); break; case ERRMSG: /* Print any error messages stored in the error buffer */ errbuf = cgi_errbuf (); if (errbuf[0] != EOS) { printf ("

Error Messages

\n"); printf ("
\n%s
", errbuf); } break; case TOPLINK: /* Print an anchor that will generate the top level form */ printf ("", QUERYURL); break; case TXTLINK: /* Print an anchor that will produce ascii output */ printf (""); break; case TASKURL: /* Print the url of this task */ printf (QUERYURL); break; } } fclose (fp); }