// // DotNetNuke - http://www.dotnetnuke.com // Copyright (c) 2002-2005 // by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca ) // // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated // documentation files (the "Software"), to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and // to permit persons to whom the Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all copies or substantial portions // of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // using DotNetNuke; using DotNetNuke.Services.Localization; using System.Collections.Generic; using DotNetNuke.Common.Utilities; using DotNetNuke.Common; using System.Web.UI.WebControls; namespace DotNetNuke.Modules.Survey { public partial class EditSurvey : DotNetNuke.Entities.Modules.PortalModuleBase { protected System.Web.UI.WebControls.Label Label5; private int SurveyId = -1; private void Page_Load(object sender, System.EventArgs e) { // get parameter if (!(Request.QueryString["SurveyId"] == null)) { SurveyId = int.Parse(Request.QueryString["SurveyId"]); } else { SurveyId = Null.NullInteger; } if ((Page.IsPostBack == false)) { cmdDelete.Attributes.Add("onClick", ("javascript:return confirm(\'" + (Localization.GetString("DeleteItem") + "\');"))); if (!Null.IsNull(SurveyId)) { SurveyInfo objSurvey = SurveyController.GetSurvey(SurveyId, ModuleId); if (!(objSurvey == null)) { txtQuestion.Text = objSurvey.Question; cboOptionType.Items.FindByValue(objSurvey.OptionType).Selected = true; if (!Null.IsNull(objSurvey.ViewOrder)) { txtViewOrder.Text = objSurvey.ViewOrder.ToString(); } List arrSurveyOptions = SurveyOptionController.GetSurveyOptions(SurveyId); SurveyOptionInfo objSurveyOption; int intIndex; for (intIndex = 0; (intIndex <= (arrSurveyOptions.Count - 1)); intIndex++) { objSurveyOption = ((SurveyOptionInfo)(arrSurveyOptions[intIndex])); objSurveyOption.OptionName = FormatSurveyOption(objSurveyOption.OptionName, objSurveyOption.IsCorrect); arrSurveyOptions[intIndex] = objSurveyOption; } lstOptions.DataSource = arrSurveyOptions; lstOptions.DataBind(); ctlAudit.CreatedByUser = objSurvey.CreatedByUser.ToString(); ctlAudit.CreatedDate = objSurvey.CreatedDate.ToShortDateString(); } else { // security violation attempt to access item not related to this Module Response.Redirect(Globals.NavigateURL()); } } else { // new item cmdDelete.Visible = false; ctlAudit.Visible = false; } } } protected void Update_Click(object sender, System.EventArgs e) { SurveyInfo objSurvey = new SurveyInfo(); objSurvey.SurveyId = SurveyId; objSurvey.ModuleId = ModuleId; objSurvey.Question = txtQuestion.Text; if ((txtViewOrder.Text != "")) { objSurvey.ViewOrder = int.Parse(txtViewOrder.Text); } else { objSurvey.ViewOrder = Null.NullInteger; } objSurvey.OptionType = cboOptionType.SelectedItem.Value; objSurvey.CreatedByUser = UserId; if (Null.IsNull(SurveyId)) { SurveyId = SurveyController.AddSurvey(objSurvey); } else { SurveyController.UpdateSurvey(objSurvey); } int intOption; for (intOption = 0; (intOption <= (lstOptions.Items.Count - 1)); intOption++) { SurveyOptionInfo objSurveyOption = new SurveyOptionInfo(); objSurveyOption.SurveyOptionId = int.Parse(lstOptions.Items[intOption].Value); objSurveyOption.SurveyId = SurveyId; objSurveyOption.OptionName = lstOptions.Items[intOption].Text; objSurveyOption.ViewOrder = intOption; objSurveyOption.Votes = 0; objSurveyOption.IsCorrect = false; if ((objSurveyOption.OptionName == FormatSurveyOption(objSurveyOption.OptionName, true))) { objSurveyOption.OptionName = FormatSurveyOption(objSurveyOption.OptionName, false); objSurveyOption.IsCorrect = true; } if (Null.IsNull(objSurveyOption.SurveyOptionId)) { SurveyOptionController.AddSurveyOption(objSurveyOption); } else { SurveyOptionController.UpdateSurveyOption(objSurveyOption); } } // Redirect back to the portal Response.Redirect(Globals.NavigateURL()); } protected void Delete_Click(object sender, System.EventArgs e) { if (!Null.IsNull(SurveyId)) { SurveyInfo objSurvey = new SurveyInfo(); objSurvey.SurveyId = SurveyId; objSurvey.ModuleId = ModuleId; SurveyController.DeleteSurvey(objSurvey); } // Redirect back to the portal Response.Redirect(Globals.NavigateURL()); } protected void cmdCancel_Click(object sender, System.EventArgs e) { // Redirect back to the portal Response.Redirect(Globals.NavigateURL()); } protected void cmdAddOption_Click(object sender, System.EventArgs e) { if ((txtOption.Text != "")) { bool blnIsUnique = true; int intItem; for (intItem = 0; (intItem <= (lstOptions.Items.Count - 1)); intItem++) { if ((lstOptions.Items[intItem].Text.ToLower() == txtOption.Text.ToLower())) { blnIsUnique = false; } } if (blnIsUnique) { string strOption = FormatSurveyOption(txtOption.Text, chkCorrect.Checked); lstOptions.Items.Add(new ListItem(strOption, "-1")); chkCorrect.Checked = false; } else { DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("OptionExists", this.LocalResourceFile), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.YellowWarning); } txtOption.Text = ""; } } protected void cmdDeleteOption_Click(object sender, System.Web.UI.ImageClickEventArgs e) { SurveyOptionInfo objSurveyOptionInfo = new SurveyOptionInfo(); if ((lstOptions.SelectedIndex != -1)) { if ((int.Parse(lstOptions.SelectedItem.Value) != -1)) { objSurveyOptionInfo.SurveyOptionId = int.Parse(lstOptions.SelectedItem.Value); SurveyOptionController.DeleteSurveyOption(objSurveyOptionInfo); } lstOptions.Items.RemoveAt(lstOptions.SelectedIndex); } } protected void cmdUp_Click(object sender, System.Web.UI.ImageClickEventArgs e) { if ((lstOptions.SelectedIndex > 0)) { // save int intSelectedIndex = lstOptions.SelectedIndex; ListItem objListItem = lstOptions.Items[lstOptions.SelectedIndex]; // remove lstOptions.Items.Remove(objListItem); // move up lstOptions.Items.Insert((intSelectedIndex - 1), objListItem); } } protected void cmdDown_Click(object sender, System.Web.UI.ImageClickEventArgs e) { if ((lstOptions.SelectedIndex < (lstOptions.Items.Count - 1))) { // save int intSelectedIndex = lstOptions.SelectedIndex; ListItem objListItem = lstOptions.Items[lstOptions.SelectedIndex]; // remove lstOptions.Items.Remove(objListItem); // move up lstOptions.Items.Insert((intSelectedIndex + 1), objListItem); } } private string FormatSurveyOption(string OptionName, bool IsCorrect) { if (IsCorrect) { if (((OptionName.StartsWith(">") == true) && (OptionName.EndsWith("<") == true))) { return OptionName; } else { return (">" + OptionName + "<"); } } else if (((OptionName.StartsWith(">") == true) && (OptionName.EndsWith("<") == true))) { return OptionName.Substring(1, (OptionName.Length - 2)); } else { return OptionName; } } } }