9cb21861514df76b30d13df3e0eb10ace6d0ec86
chinhli
  Sat Jun 15 13:31:38 2013 -0700
ToDo 11002 Jonathan's CRAZ category hack STOOPED.
diff --git src/hg/hgUserSuggestion/hgUserSuggestion.c src/hg/hgUserSuggestion/hgUserSuggestion.c
index 3f64b67..58e2c98 100644
--- src/hg/hgUserSuggestion/hgUserSuggestion.c
+++ src/hg/hgUserSuggestion/hgUserSuggestion.c
@@ -122,30 +122,48 @@
 if (!*(domain = ++c)) return 0;
 do
     {
     if (*c == '.')
         {
         if (c == domain || *(c - 1) == '.') return 0;
         count++;
         }
     if (*c <= ' ' || *c >= 127) return 0;
     if (strchr(rfc822_specials, *c)) return 0;
     } while (*++c);
 
 return (count >= 1);
 }
 
+boolean validateCategory(char *category)
+/* Validate the Category from the request */
+{
+const char *cat[5];
+cat[0] = "Tracks";
+cat[1] = "Genome Assemblies";
+cat[2] = "Browser Tools";
+cat[3] = "Command-line Utilities";
+cat[4] = "Others";
+
+int i;
+for(i=0;i<5;i++)
+{
+    if (strcmp(cat[i], category)==0) return TRUE;
+}
+return FALSE;
+}
+
 
 /* javascript functions */
 void printMainForm()
 /* Create the main suggestion form */
 {
 hPrintf(
     "     <FORM ACTION=\"../cgi-bin/hgUserSuggestion?do.suggestSendMail=1\" METHOD=\"POST\" ENCTYPE=\"multipart/form-data\" NAME=\"mainForm\" onLoad=\"document.forms.mainForm.name.focus()\">\n");
 hPrintf(
     "<H2>User Suggestion Form</H2>\n"
     "<P>If you have ideas about how we can improve the value of the Genome Browser to your research, "
     "we'd like to hear from you. Please provide a concise description below. "
     "A copy of the suggestion will be sent to your email address along with a reference number. "
     "You may follow up on the status of your request at any time by <a href=\"../contacts.html#followup\">contacting us</a> and quoting the reference number.</P>");
 hPrintf("<P>Please note: this form is not the proper place to submit questions regarding browser use or bug reports. Use the links on our <a href=\"../contacts.html\">contact page</a> instead.</P>");
 hPrintf("<HR><BR>"); 
@@ -323,30 +341,42 @@
     "<a href=\"../contacts.html#followup\">contacting us</a> and quoting your reference number:<BR><BR>%s<BR><BR>"
     "A copy of this information has also been sent to you at %s.<BR></p>",
      refID, userAddr); 
 hPrintf(
     "<p><a href=\"hgUserSuggestion\">Click here if you wish to make additional suggestions.</a></p>");
 hPrintf(
     "<p>"
     "<B>Your suggestion summary:</B><BR>"
     "%s<BR>"
     "<B>Your suggestion details:</B><BR>"
     "<pre>%s</pre>"
     "</p>",
     summary, details);
 } 
 
+void printInvalidCategory(char *invalidCategory)
+/* display suggestion confirm page */
+{
+hPrintf(
+    "<h2>Invalid Category.</h2>");
+hPrintf(
+    "<p>"
+    "The category \"%s\" is invalid. Please correct it and "
+    "<a href=\"javascript: history.go(-1)\">submit</a> again.</p>",
+    invalidCategory);
+}
+
 void printInvalidEmailAddr(char *invalidEmailAddr)
 /* display suggestion confirm page */
 {
 hPrintf(
     "<h2>Invalid email address format.</h2>");
 hPrintf(
     "<p>"
     "The email address \"%s\" is invalid. Please correct it and "
     "<a href=\"javascript: history.go(-1)\">submit</a> again.</p>",
     invalidEmailAddr);
 }
 
 void sendSuggestionBack(char *sName, char *sEmail, char *sCategory, char *sSummary, char *sDetails, char *suggestID)
 /* send back the suggestion */
 {
@@ -402,30 +432,38 @@
 {
 /* parameters from hg.cong */
 char *filter=filterKeyword();
 
 /* values from cart */
 char *sName=cartUsualString(cart,"suggestName","");
 char *sEmail=cartUsualString(cart,"suggestEmail","");
 char *sCategory=cartUsualString(cart,"suggestCategory","");
 char *sSummary=cartUsualString(cart,"suggestSummary","");
 char *sDetails=cartUsualString(cart,"suggestDetails","");
 
 char suggestID[512];
 safef(suggestID, sizeof(suggestID),"%s %s", sEmail, now());
 char subject[512];
 safef(subject, sizeof(subject),"%s %s", filter, suggestID);
+
+/* reject suggestion if category is invalid */
+if (!validateCategory(sCategory))
+{
+    printInvalidCategory(sCategory);
+    return;  
+} 
+
 /* Send back suggestion only with valid user email address */
 if (spc_email_isvalid(sEmail) != 0)
 {
     /* send back the suggestion */
     sendSuggestionBack(sName, sEmail, sCategory, sSummary, sDetails, suggestID);
     /* send confirmation mail to user */
     sendConfirmMail(sEmail,suggestID, sSummary, sDetails);
     /* display confirmation page */
     printSuggestionConfirmed(sSummary, suggestID, sEmail, mailReturnAddr(), sDetails);
 } else {
     /* save all field value in cart */
      printInvalidEmailAddr(sEmail);
 }
 cartRemove(cart, "do.suggestSendMail");
 }