private void CreateSurveyItems(List <SurveysInfo> surveys) { foreach (SurveysInfo survey in surveys) { List <SurveyOptionsInfo> surveyOptions = SurveyOptionsController.GetAll(survey.SurveyID); switch (survey.OptionType) { case QuestionType.RadioButtons: SurveyRadioButtons surveyRadioButtons = (SurveyRadioButtons)LoadControl(string.Format("{0}Controls/SurveyRadioButtons.ascx", ControlPath)); surveyRadioButtons.ID = string.Format("SurveyRadiobutton_{0}", survey.SurveyID); surveyRadioButtons.Label = survey.Question; surveyRadioButtons.RepeatDirection = survey.RepeatDirection; surveyRadioButtons.RepeatColumns = (((survey.RepeatColumns == null) || (survey.RepeatColumns <= 1)) ? 1 : survey.RepeatColumns.Value); surveyRadioButtons.EditUrl = EditUrl("SurveyID", survey.SurveyID.ToString()); surveyRadioButtons.IsEditable = IsEditable; surveyRadioButtons.ErrorMessage = string.Format(Localization.GetString("RadioButtonRequired.ErrorMessage", LocalResourceFile), survey.Question); surveyRadioButtons.ValidationGroup = string.Format("Survey_{0}_ValidationGroup", ModuleId); surveyRadioButtons.DataSource = surveyOptions; surveyRadioButtons.DataTextField = "OptionName"; surveyRadioButtons.DataValueField = "SurveyOptionID"; surveyRadioButtons.DataBind(); SurveyPlaceHolder.Controls.Add(surveyRadioButtons); break; case QuestionType.CheckBoxes: SurveyCheckBoxes surveyCheckBoxes = (SurveyCheckBoxes)LoadControl(string.Format("{0}Controls/SurveyCheckBoxes.ascx", ControlPath)); surveyCheckBoxes.ID = string.Format("SurveyCheckbox_{0}", survey.SurveyID); surveyCheckBoxes.Label = survey.Question; surveyCheckBoxes.RepeatDirection = survey.RepeatDirection; surveyCheckBoxes.RepeatColumns = (((survey.RepeatColumns == null) || (survey.RepeatColumns <= 1)) ? 1 : survey.RepeatColumns.Value); surveyCheckBoxes.EditUrl = EditUrl("SurveyID", survey.SurveyID.ToString()); surveyCheckBoxes.IsEditable = IsEditable; surveyCheckBoxes.ErrorMessage = string.Format(Localization.GetString("CheckBoxRequired.ErrorMessage", LocalResourceFile), survey.Question); surveyCheckBoxes.ValidationGroup = string.Format("Survey_{0}_ValidationGroup", ModuleId); surveyCheckBoxes.DataSource = surveyOptions; surveyCheckBoxes.DataTextField = "OptionName"; surveyCheckBoxes.DataValueField = "SurveyOptionID"; surveyCheckBoxes.DataBind(); SurveyPlaceHolder.Controls.Add(surveyCheckBoxes); break; case QuestionType.Text: SurveyText surveyTextBox = (SurveyText)LoadControl(string.Format("{0}Controls/SurveyText.ascx", ControlPath)); surveyTextBox.ID = string.Format("SurveyTextBox_{0}", survey.SurveyID); surveyTextBox.Label = survey.Question; surveyTextBox.NumberOfRows = (((survey.NumberOfRows.HasValue) && (survey.NumberOfRows.Value > 1)) ? survey.NumberOfRows.Value : 1); surveyTextBox.EditUrl = EditUrl("SurveyID", survey.SurveyID.ToString()); surveyTextBox.IsEditable = IsEditable; surveyTextBox.ErrorMessage = string.Format(Localization.GetString("TextBoxRequired.ErrorMessage", LocalResourceFile), survey.Question); surveyTextBox.ValidationGroup = string.Format("Survey_{0}_ValidationGroup", ModuleId); surveyTextBox.SurveyOptionID = surveyOptions[0].SurveyOptionID; SurveyPlaceHolder.Controls.Add(surveyTextBox); break; default: break; } } if (PrivacyConfirmation) { // This is DNN 9.2.2 code... string privacyUrl = Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "Privacy"); string termsUrl = Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "Terms"); // For DNN 9.3.0 use this code then... //string privacyUrl = (PortalSettings.PrivacyTabId == Null.NullInteger ? Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "Privacy") : Globals.NavigateURL(PortalSettings.PrivacyTabId)); //string termsUrl = (PortalSettings.TermsTabId == Null.NullInteger ? Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "Terms") : Globals.NavigateURL(PortalSettings.TermsTabId)); PrivacyConfirmationCheckBox privacyConfirmation = (PrivacyConfirmationCheckBox)LoadControl(string.Format("{0}Controls/PrivacyConfirmationCheckBox.ascx", ControlPath)); privacyConfirmation.ID = string.Format("PrivacyConfirmationCheckBox_{0}", ModuleId); privacyConfirmation.Label = string.Format(Localization.GetString("PrivacyConfirmation.Text", LocalResourceFile), privacyUrl, termsUrl); privacyConfirmation.ErrorMessage = Localization.GetString("PrivacyConfirmation.ErrorMessage", LocalResourceFile); privacyConfirmation.ValidationGroup = string.Format("Survey_{0}_ValidationGroup", ModuleId); SurveyPlaceHolder.Controls.Add(privacyConfirmation); } if ((UseCaptcha == UseCaptcha.Always) || ((UseCaptcha == UseCaptcha.UnauthorizedUsersOnly) && (UserId < 1))) { CaptchaControl captcha = new CaptchaControl(); captcha.ID = string.Format("Captcha_{0}", ModuleId); captcha.Text = Localization.GetString("Captcha.Text", LocalResourceFile); captcha.CaptchaLength = 8; captcha.ErrorMessage = Localization.GetString("Captcha.ErrorMessage", LocalResourceFile); captcha.CaptchaChars = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789"; captcha.ErrorStyle.CssClass = "dnnFormMessage dnnFormError"; SurveyPlaceHolder.Controls.Add(captcha); } }
protected void SubmitSurveyButton_Click(object sender, EventArgs e) { // First, check CAPTCHA CaptchaControl captcha = (CaptchaControl)FindControl(string.Format("Captcha_{0}", ModuleId)); if (((captcha != null) && (captcha.IsValid)) || (captcha == null)) { // Then validate page... Page.Validate(string.Format("Survey_{0}_ValidationGroup", ModuleId)); if (Page.IsValid) { if (ContactByFaxOnlyCheckBox.Checked) { // if someone activates this checkbox send him home :-) Response.Redirect("http://localhost/"); } List <SurveysInfo> surveys = SurveysController.GetAll(ModuleId); List <SurveyResultsInfo> surveyResults = new List <SurveyResultsInfo>(); Guid resultUserID = Guid.NewGuid(); foreach (SurveysInfo survey in surveys) { SurveyResultsInfo surveyResult; switch (survey.OptionType) { case QuestionType.RadioButtons: SurveyRadioButtons surveyRadioButtons = (SurveyRadioButtons)FindControl(string.Format("SurveyRadiobutton_{0}", survey.SurveyID)); surveyResult = new SurveyResultsInfo(); surveyResult.SurveyOptionID = Convert.ToInt32(surveyRadioButtons.SelectedValue); surveyResult.UserID = (UserId < 1 ? (int?)null : UserId); surveyResult.IPAddress = Request.ServerVariables["REMOTE_ADDR"]; surveyResult.IsCorrect = SurveyOptionsController.GetAll(survey.SurveyID).Find(x => x.SurveyOptionID == surveyResult.SurveyOptionID).IsCorrect; surveyResult.ResultUserID = resultUserID; surveyResults.Add(surveyResult); break; case QuestionType.CheckBoxes: SurveyCheckBoxes surveyCheckBoxes = (SurveyCheckBoxes)FindControl(string.Format("SurveyCheckbox_{0}", survey.SurveyID)); foreach (int surveyOptionID in surveyCheckBoxes.SelectedItems) { surveyResult = new SurveyResultsInfo(); surveyResult.SurveyOptionID = surveyOptionID; surveyResult.UserID = (UserId < 1 ? (int?)null : UserId); surveyResult.IPAddress = Request.ServerVariables["REMOTE_ADDR"]; surveyResult.IsCorrect = SurveyOptionsController.GetAll(survey.SurveyID).Find(x => x.SurveyOptionID == surveyResult.SurveyOptionID).IsCorrect; surveyResult.ResultUserID = resultUserID; surveyResults.Add(surveyResult); } break; case QuestionType.Text: SurveyText surveyTextBox = (SurveyText)FindControl(string.Format("SurveyTextBox_{0}", survey.SurveyID)); surveyResult = new SurveyResultsInfo(); surveyResult.SurveyOptionID = surveyTextBox.SurveyOptionID; surveyResult.UserID = (UserId < 1 ? (int?)null : UserId); surveyResult.IPAddress = Request.ServerVariables["REMOTE_ADDR"]; surveyResult.TextAnswer = PortalSecurity.InputFilter(surveyTextBox.Text, PortalSecurity.FilterFlag.MultiLine | PortalSecurity.FilterFlag.NoAngleBrackets | PortalSecurity.FilterFlag.NoMarkup | PortalSecurity.FilterFlag.NoScripting | PortalSecurity.FilterFlag.NoSQL); surveyResult.IsCorrect = true; surveyResult.ResultUserID = resultUserID; surveyResults.Add(surveyResult); break; default: break; } } if (PortalSecurity.IsInRole("Administrators")) { // This is just to force the SQL Script SurveyResults_Add to add the result if the user is an administrator SurveyResultsController.Add(surveyResults, false); } else { SurveyResultsController.Add(surveyResults, AuthorizedUsersOnly); } HttpCookie cookie = new HttpCookie(_cookie); cookie.Value = "True"; cookie.Expires = (SurveyClosingDate == DateTime.MinValue ? DateTime.MaxValue : SurveyClosingDate.AddDays(1)); Response.AppendCookie(cookie); SubmitSurveyButton.Visible = false; if (SurveyType == SurveyType.Survey) { SurveyPlaceHolder.Visible = false; if (HasViewResultsPermission) { Response.Redirect(EditUrl("SurveyResults"), false); } else { SurveyMessageLabel.Text = Localization.GetString("HasVoted.Text", LocalResourceFile); SurveyMessageLabel.CssClass = "dnnFormMessage dnnFormSuccess"; SurveyMessageLabel.Visible = true; } } else { SurveyMessageLabel.Text = Localization.GetString("QuizResults.Text", LocalResourceFile); SurveyMessageLabel.CssClass = "dnnFormMessage dnnFormSuccess"; SurveyMessageLabel.Visible = true; SurveyPlaceHolder.Controls.Clear(); DisplayQuizResults(surveys, surveyResults); } } } }