public UserFeedbackSubmittedData[] FetchAllUserFeedbackSubmittedData() { List <UserFeedbackSubmittedData> ret = new List <UserFeedbackSubmittedData>(); string sql = "select dateTimeSubmitted, Name, EmailAddress, Location, TextAreaQuestion, TextAreaValue, ReferringUrl "; sql += " from userfeedbacksubmitteddata order by dateTimeSubmitted "; DataSet ds = RunSelectQuery(sql); if (hasRows(ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { UserFeedbackSubmittedData d = new UserFeedbackSubmittedData(); d.dateTimeSubmitted = Convert.ToDateTime(dr["dateTimeSubmitted"]); d.Name = dr["Name"].ToString(); d.EmailAddress = dr["EmailAddress"].ToString(); d.Location = dr["Location"].ToString(); d.TextAreaQuestion = dr["TextAreaQuestion"].ToString(); d.TextAreaValue = dr["TextAreaValue"].ToString(); d.ReferringUrl = dr["ReferringUrl"].ToString(); ret.Add(d); } // foreach } return(ret.ToArray()); }
public bool saveUserFeedbackSubmittedData(UserFeedbackSubmittedData submittedData) { string sql = "insert into userfeedbacksubmitteddata (dateTimeSubmitted, Name, EmailAddress, Location, TextAreaQuestion, TextAreaValue, ReferringUrl ) VALUES ("; sql += "NOW(), "; sql += "'" + dbEncode(submittedData.Name) + "', "; sql += "'" + dbEncode(submittedData.EmailAddress) + "', "; sql += "'" + dbEncode(submittedData.Location) + "', "; sql += "'" + dbEncode(submittedData.TextAreaQuestion) + "', "; sql += "'" + dbEncode(submittedData.TextAreaValue) + "', "; sql += "'" + dbEncode(submittedData.ReferringUrl) + "' "; sql += ");"; int newId = this.RunInsertQuery(sql); if (newId > -1) { return(true); } return(false); }
} // RenderView private bool sendAdministratorNotification(UserFeedbackFormInfo formInfo, UserFeedbackSubmittedData submittedData) { if (formInfo.EmailAddressesToNotify.Trim() == "") { return(true); } string smtpServer = CmsConfig.getConfigValue("smtpServer", "smtp.hatfieldgroup.com"); string toAddress = formInfo.EmailAddressesToNotify; string[] toArray = toAddress.Split(new char[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries); string fromAddress = submittedData.EmailAddress; string subject = CmsContext.currentPage.Title; string host = CmsConfig.getConfigValue("SiteName", ""); if (HttpContext.Current != null && HttpContext.Current.Request != null) { host = HttpContext.Current.Request.Url.Host; } string body = "The following feedback was sent from the " + host + " website" + Environment.NewLine + Environment.NewLine; body += "Date: " + DateTime.Now.ToString("MMM dd yyyy hh:mm tt") + Environment.NewLine; body += "From: " + submittedData.Name + " (" + submittedData.EmailAddress + ")" + Environment.NewLine; body += "Location: " + submittedData.Location + Environment.NewLine; body += "Referencing Location: " + submittedData.ReferringUrl + Environment.NewLine + Environment.NewLine; body += submittedData.TextAreaQuestion + ":" + Environment.NewLine + Environment.NewLine; body += submittedData.TextAreaValue; try { // SmtpMail.SmtpServer = smtpServer; Hatfield.Web.Portal.Net.SmtpDirect.SmtpServerHostName = smtpServer; MailMessage msg = new MailMessage(); msg.From = new MailAddress(fromAddress); foreach (string to in toArray) { msg.To.Add(to); } msg.IsBodyHtml = false; msg.Subject = subject; msg.Body = body; bool b = Hatfield.Web.Portal.Net.SmtpDirect.Send(msg); if (!b) { return(true); } } catch (Exception ex) { Console.Write(ex.Message); } return(false); }
public override void RenderInViewMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList) { UserFeedbackDb db = new UserFeedbackDb(); UserFeedbackFormInfo formInfo = db.getUserFeedbackFormInfo(page, identifier, langToRenderFor, true); string ControlId = "UserFeedbackInfo_" + page.ID.ToString() + "_" + identifier.ToString() + "_" + langToRenderFor.shortCode + "_"; string _errorMessage = ""; string action = PageUtils.getFromForm(ControlId + "Action", ""); UserFeedbackSubmittedData submittedData = new UserFeedbackSubmittedData(); bool formValuesLoadedFromSession = false; if (action.Trim().ToLower() == "send") { // -- get the spam question index int spamQuestionIndex = (PageUtils.getFromForm(ControlId + "spamQuestionIndex", SpamTestQuestion.GetRandomQuestionIndex())); if (spamQuestionIndex >= SpamTestQuestion.Questions.Length || spamQuestionIndex < 0) { spamQuestionIndex = SpamTestQuestion.GetRandomQuestionIndex(); } SpamTestQuestion questionToAnswer = SpamTestQuestion.Questions[spamQuestionIndex]; string spamQuestionAnswer = (PageUtils.getFromForm(ControlId + "spamQuestionAnswer", "")); submittedData.Name = (PageUtils.getFromForm(ControlId + "Name", "")); submittedData.Name = submittedData.Name.Trim(); submittedData.EmailAddress = PageUtils.getFromForm(ControlId + "Email", ""); submittedData.EmailAddress = submittedData.EmailAddress.Trim(); submittedData.Location = PageUtils.getFromForm(ControlId + "Location", ""); submittedData.Location = submittedData.Location.Trim(); submittedData.TextAreaValue = PageUtils.getFromForm(ControlId + "Comments", ""); submittedData.TextAreaValue = submittedData.TextAreaValue.Trim(); submittedData.ReferringUrl = PageUtils.getFromForm(ControlId + "Referer", ""); // -- validate user submitted values if (questionToAnswer.Answer != spamQuestionAnswer) { _errorMessage = "Your answer to the math question was incorrect. Please try again."; } else if (submittedData.Name == "") { _errorMessage = getErrorEnterNameText(langToRenderFor); } else if (submittedData.EmailAddress == "") { _errorMessage = getErrorEnterEmailText(langToRenderFor); } else if (!PageUtils.isValidEmailAddress(submittedData.EmailAddress)) { _errorMessage = getErrorEnterValidEmailText(langToRenderFor); } else if (submittedData.TextAreaValue == "") { _errorMessage = getErrorEnterTextAreaQuestionText(langToRenderFor) + formInfo.TextAreaQuestion; } else { // -- save the submitted value submittedData.dateTimeSubmitted = DateTime.Now; submittedData.TextAreaQuestion = formInfo.TextAreaQuestion; if (db.saveUserFeedbackSubmittedData(submittedData)) { // -- success // save submitted values to the current session if (HttpContext.Current != null && HttpContext.Current.Session != null) { System.Web.SessionState.HttpSessionState session = System.Web.HttpContext.Current.Session; session[ControlId + "Name"] = submittedData.Name; session[ControlId + "Email"] = submittedData.EmailAddress; session[ControlId + "Location"] = submittedData.Location; } // send notification email message sendAdministratorNotification(formInfo, submittedData); // output the Thankyou message writer.Write("<p><strong>" + formInfo.ThankyouMessage + "</strong></p>"); return; } else { _errorMessage = getErrorSavingText(langToRenderFor); } } } // if save posted values else { // -- get previously submitted values from the current session if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Session != null) { System.Web.SessionState.HttpSessionState session = System.Web.HttpContext.Current.Session; if (session[ControlId + "Name"] != null) { submittedData.Name = session[ControlId + "Name"].ToString(); formValuesLoadedFromSession = true; } if (session[ControlId + "Email"] != null) { submittedData.EmailAddress = session[ControlId + "Email"].ToString(); formValuesLoadedFromSession = true; } if (session[ControlId + "Location"] != null) { submittedData.Location = session[ControlId + "Location"].ToString(); formValuesLoadedFromSession = true; } } } StringBuilder html = new StringBuilder(); if (_errorMessage != "") { html.Append("<p class=\"FormErrorMessage\">" + _errorMessage + "</p>"); } string formId = "UserFeedback"; html.Append(page.getFormStartHtml(formId)); html.Append("<em>" + getCompleteAllText(langToRenderFor) + "</em> "); if (formValuesLoadedFromSession) { html.Append(getValuesPreloadedText(langToRenderFor)); } html.Append("<table>"); html.Append("<tr>"); html.Append("<td valign=\"top\">" + getNameText(langToRenderFor) + ":"); html.Append("</td>"); html.Append("<td valign=\"top\">"); html.Append(PageUtils.getInputTextHtml(ControlId + "Name", ControlId + "Name", submittedData.Name, formInfo.FormFieldDisplayWidth, 255)); html.Append("</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td valign=\"top\">" + getEmailText(langToRenderFor) + ":"); html.Append("</td>"); html.Append("<td valign=\"top\">"); html.Append(PageUtils.getInputTextHtml(ControlId + "Email", ControlId + "Email", submittedData.EmailAddress, formInfo.FormFieldDisplayWidth, 255)); html.Append("</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td valign=\"top\">" + getLocationText(langToRenderFor) + ":"); html.Append("</td>"); html.Append("<td valign=\"top\">"); html.Append(PageUtils.getInputTextHtml(ControlId + "Location", ControlId + "Location", submittedData.Location, formInfo.FormFieldDisplayWidth, 255)); html.Append("</td>"); html.Append("</tr>"); html.Append("<tr>"); html.Append("<td valign=\"top\">"); html.Append(formInfo.TextAreaQuestion); html.Append("</td>"); html.Append("<td valign=\"top\">"); html.Append(PageUtils.getTextAreaHtml(ControlId + "Comments", ControlId + "Comments", "", formInfo.FormFieldDisplayWidth, 7)); html.Append("</td>"); html.Append("</tr>"); // -- spam stop question int qIndex = SpamTestQuestion.GetRandomQuestionIndex(); SpamTestQuestion spamQuestion = SpamTestQuestion.Questions[qIndex]; html.Append("<tr>"); html.Append("<td valign=\"top\">"); html.Append(spamQuestion.Question); html.Append("</td>"); html.Append("<td valign=\"top\">"); html.Append(PageUtils.getInputTextHtml(ControlId + "spamQuestionAnswer", ControlId + "spamQuestionAnswer", "", 5, 255)); html.Append("</td>"); html.Append("</tr>"); html.Append("</table>"); html.Append(PageUtils.getHiddenInputHtml(ControlId + "spamQuestionIndex", qIndex.ToString())); html.Append(PageUtils.getHiddenInputHtml(ControlId + "Action", "send")); html.Append(PageUtils.getHiddenInputHtml(ControlId + "Referer", PageUtils.getFromForm("r", "(unknown)"))); html.Append("<input type=\"submit\" value=\"" + getSubmitButtonText(langToRenderFor) + "\">"); html.Append(page.getFormCloseHtml(formId)); writer.Write(html.ToString()); } // RenderView