Beispiel #1
0
    /// <summary>
    /// Sets SkinId to all controls in logon form.
    /// </summary>
    private void SetSkinID(string skinId)
    {
        if (skinId != "")
        {
            Login1.SkinID = skinId;

            LocalizedLabel lbl = (LocalizedLabel)Login1.FindControl("lblUserName");
            if (lbl != null)
            {
                lbl.SkinID = skinId;
            }
            lbl = (LocalizedLabel)Login1.FindControl("lblPassword");
            if (lbl != null)
            {
                lbl.SkinID = skinId;
            }

            TextBox txt = (TextBox)Login1.FindControl("UserName");
            if (txt != null)
            {
                txt.SkinID = skinId;
            }
            txt = (TextBox)Login1.FindControl("Password");
            if (txt != null)
            {
                txt.SkinID = skinId;
            }

            LocalizedCheckBox chk = (LocalizedCheckBox)Login1.FindControl("chkRememberMe");
            if (chk != null)
            {
                chk.SkinID = skinId;
            }

            LocalizedButton btn = (LocalizedButton)Login1.FindControl("LoginButton");
            if (btn != null)
            {
                btn.SkinID = skinId;
            }
        }
    }
Beispiel #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        SetBrowserClass();
        AddNoCacheTag();

        // Ensure the refresh script
        bool   sameWindow       = (FormStateHelper.PreservePostbackValuesOnLogin && (FormStateHelper.GetSavedState() != null));
        string defaultCondition = "((top.frames['cmsheader'] != null) || (top.frames['propheader'] != null))";

        if (sameWindow)
        {
            ScriptHelper.RegisterStartupScript(this, typeof(string), "TopWindow", ScriptHelper.GetScript("if (((document.body.clientWidth < 510) || (document.body.clientHeight < 300)) && " + defaultCondition + ") { var loginUrl = top.window.location.href.replace(/\\/\\(\\w\\([^\\)]+\\)\\)/g, ''); if (loginUrl.indexOf('restorepost=0') < 0) { if (loginUrl.indexOf('?') >= 0) { loginUrl = loginUrl + '&restorepost=0'; } else { loginUrl = loginUrl + '?restorepost=0'; } } top.window.location.replace(loginUrl); }"));
        }
        else
        {
            ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "TopWindow", ScriptHelper.GetScript("if " + defaultCondition + " { top.window.location.replace(top.window.location.href.replace(/\\/\\(\\w\\([^\\)]+\\)\\)/g, '')); }"));
        }

        // Enable caps lock check
        if (ValidationHelper.GetBoolean(SettingsHelper.AppSettings["CMSUseCapsLockNotification"], true))
        {
            RegisterCAPSLOCKScript();
            TextBox txtPassword = (TextBox)Login1.FindControl("Password");
            if (txtPassword != null)
            {
                txtPassword.Attributes.Add("onkeypress", "CheckCapsLock(event)");
            }
        }

        // Site manager prefix
        string smPrefix = IsSiteManager ? "SM/" : null;

        // Initialize help
        CMSAdminControls_UI_PageElements_Help ucHelp = (CMSAdminControls_UI_PageElements_Help)Login1.FindControl("ucHelp");

        ucHelp.Tooltip   = GetString("logon.helptooltip");
        ucHelp.IconUrl   = GetImageUrl("Others/LogonForm/" + smPrefix + "HelpButton.png");
        ucHelp.TopicName = "LogonTroubleshooting";

        LocalizedLabel lblItem = (LocalizedLabel)Login1.FindControl("lblUserName");

        if (lblItem != null)
        {
            lblItem.Text = "{$LogonForm.UserName$}";
        }
        lblItem = (LocalizedLabel)Login1.FindControl("lblPassword");
        if (lblItem != null)
        {
            lblItem.Text = "{$LogonForm.Password$}";
        }

        // Display culture link due to value of the key stored in the web.config file
        bool showCultureSelector = ValidationHelper.GetBoolean(SettingsHelper.AppSettings["CMSShowLogonCultureSelector"], true);

        if (showCultureSelector)
        {
            ImageButton lnkLanguage = (ImageButton)Login1.FindControl("lnkLanguage");
            if (lnkLanguage != null)
            {
                lnkLanguage.Visible = true;

                // Ensure language selection panel functionality
                HtmlGenericControl pnlLanguage = (HtmlGenericControl)Login1.FindControl("pnlLanguage");
                if (pnlLanguage != null)
                {
                    lnkLanguage.ImageUrl      = GetImageUrl("Others/LogonForm/" + smPrefix + "LanguageButton.png");
                    lnkLanguage.AlternateText = GetString("LogonForm.SelectLanguage");
                    lnkLanguage.ToolTip       = GetString("LogonForm.SelectLanguage");

                    this.ltlScript.Text = ScriptHelper.GetScript("function ShowLanguage(id){var panel=document.getElementById(id);if(panel!=null){panel.style.display=(panel.style.display == 'block')?'none':'block';}}");
                    lnkLanguage.Attributes.Add("onclick", "ShowLanguage('" + pnlLanguage.ClientID + "'); return false;");
                }
            }
        }

        // Set up forgotten password link
        if (ShowForgottenPassword)
        {
            ImageButton lnkPassword = (ImageButton)Login1.FindControl("lnkPassword");
            if (lnkPassword != null)
            {
                lnkPassword.Visible       = true;
                lnkPassword.ImageUrl      = GetImageUrl("Others/LogonForm/" + smPrefix + "ForgottenPassword.png");
                lnkPassword.AlternateText = GetString("LogonForm.ForgottenPassword");
                lnkPassword.ToolTip       = GetString("LogonForm.ForgottenPassword");
                lnkPassword.Click        += new ImageClickEventHandler(lnkPassword_Click);
            }
        }

        LocalizedCheckBox chkItem = (LocalizedCheckBox)Login1.FindControl("chkRememberMe");

        if (chkItem != null)
        {
            chkItem.Text = "{$LogonForm.RememberMe$}";
        }

        LocalizedButton btnItem = (LocalizedButton)Login1.FindControl("LoginButton");

        if (btnItem != null)
        {
            btnItem.Text   = "{$LogonForm.LogOnButton$}";
            btnItem.Click += new EventHandler(btnItem_Click);
        }

        RequiredFieldValidator rfvUserName = (RequiredFieldValidator)Login1.FindControl("rfvUserNameRequired");

        if (rfvUserName != null)
        {
            rfvUserName.ToolTip      = GetString("LogonForm.NameRequired");
            rfvUserName.ErrorMessage = GetString("LogonForm.NameRequired");
        }

        // Load UI cultures for the dropdown list
        if (!RequestHelper.IsPostBack())
        {
            LoadCultures();
        }

        Label lblVersion = (Label)this.FindControl("lblVersion");

        if (lblVersion != null)
        {
            // Show version only if right key is inserted
            string versionKey = QueryHelper.GetString("versionkey", string.Empty);
            if (EncryptionHelper.VerifyVersionRSA(versionKey))
            {
                lblVersion.Text = ResHelper.GetString("Footer.Version") + "&nbsp;" + CMSContext.GetFriendlySystemVersion(true);
            }
        }

        Login1.LoggingIn  += new LoginCancelEventHandler(Login1_LoggingIn);
        Login1.LoggedIn   += new EventHandler(Login1_LoggedIn);
        Login1.LoginError += new EventHandler(Login1_LoginError);

        if (!RequestHelper.IsPostBack())
        {
            Login1.UserName = QueryHelper.GetString("username", String.Empty);
        }

        // Ensure username textbox focus
        TextBox txtUserName = (TextBox)Login1.FindControl("UserName");

        if (txtUserName != null)
        {
            ScriptHelper.RegisterStartupScript(this, GetType(), "SetFocus", ScriptHelper.GetScript("var txt=document.getElementById('" + txtUserName.ClientID + "');if(txt!=null){txt.focus();}"));
        }

        // Ensure different class for Site Manager
        if (IsSiteManager)
        {
            pnlMainContainer.CssClass += " SM";
        }

        if (QueryHelper.GetBoolean("forgottenpassword", false))
        {
            SetForgottenPasswordMode();
        }
    }
Beispiel #3
0
    /// <summary>
    /// Creates poll answer section.
    /// </summary>
    /// <param name="reload">Indicates postback</param>
    /// <param name="hasVoted">Indicates if user has voted</param>
    protected void CreateAnswerSection(bool reload, bool hasVoted)
    {
        pnlAnswer.Controls.Clear();

        if (pi != null)
        {
            // Get poll's answers
            DataSet ds = Answers;
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                int count = 0;
                int maxCount = 0;
                long sumCount = 0;

                // Sum answer counts and get highest
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    if (ValidationHelper.GetBoolean(row["AnswerEnabled"], true))
                    {
                        count = ValidationHelper.GetInteger(row["AnswerCount"], 0);
                        sumCount += count;
                        if (count > maxCount)
                        {
                            maxCount = count;
                        }
                    }
                }

                LocalizedCheckBox chkItem = null;
                LocalizedRadioButton radItem = null;
                LocalizedLabel lblItem = null;
                int index = 0;
                bool enabled = false;

                pnlAnswer.Controls.Add(new LiteralControl("<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">"));

                // Create the answers
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    enabled = ValidationHelper.GetBoolean(row["AnswerEnabled"], true);
                    if (enabled)
                    {
                        pnlAnswer.Controls.Add(new LiteralControl("<tr><td class=\"PollAnswer\" colspan=\"2\">"));

                        if (((reload) && (this.ShowResultsAfterVote)) || (!hasPermission && !this.HideWhenNotAuthorized)
                            || (!isOpened && !this.HideWhenNotOpened) || (this.CheckVoted && PollInfoProvider.HasVoted(pi.PollID)))
                        {
                            // Add label
                            lblItem = new LocalizedLabel();
                            lblItem.ID = "lbl" + ValidationHelper.GetInteger(row["AnswerID"], 0);
                            lblItem.EnableViewState = false;
                            lblItem.Text = HTMLHelper.HTMLEncode(ValidationHelper.GetString(row["AnswerText"], ""));
                            lblItem.CssClass = "PollAnswerText";

                            pnlAnswer.Controls.Add(lblItem);
                        }
                        else
                        {
                            if (pi.PollAllowMultipleAnswers)
                            {
                                // Add checkboxes for multiple answers
                                chkItem = new LocalizedCheckBox();
                                chkItem.ID = "chk" + ValidationHelper.GetInteger(row["AnswerID"], 0);
                                chkItem.AutoPostBack = false;
                                chkItem.Text = HTMLHelper.HTMLEncode(ValidationHelper.GetString(row["AnswerText"], ""));
                                chkItem.Checked = false;
                                chkItem.CssClass = "PollAnswerCheck";

                                pnlAnswer.Controls.Add(chkItem);
                            }
                            else
                            {
                                // Add radiobuttons
                                radItem = new LocalizedRadioButton();
                                radItem.ID = "rad" + ValidationHelper.GetInteger(row["AnswerID"], 0);
                                radItem.AutoPostBack = false;
                                radItem.GroupName = pi.PollCodeName + "Group";
                                radItem.Text = HTMLHelper.HTMLEncode(ValidationHelper.GetString(row["AnswerText"], ""));
                                radItem.Checked = false;
                                radItem.CssClass = "PollAnswerRadio";

                                pnlAnswer.Controls.Add(radItem);
                            }
                        }

                        pnlAnswer.Controls.Add(new LiteralControl("</td></tr>"));

                        if (this.ShowGraph || (hasVoted || reload) && this.ShowResultsAfterVote)
                        {
                            // Create graph under the answer
                            CreateGraph(maxCount, ValidationHelper.GetInteger(row["AnswerCount"], 0), sumCount, index);
                        }

                        index++;
                    }
                }

                pnlAnswer.Controls.Add(new LiteralControl("</table>"));
            }
        }
    }
Beispiel #4
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (StopProcessing)
        {
            rqValue.Visible = false;
            // Do not process
        }
        else
        {
            // Set failure text
            if (FailureText != "")
            {
                Login1.FailureText = ResHelper.LocalizeString(FailureText);
            }
            else
            {
                Login1.FailureText = GetString("Login_FailureText");
            }

            // Set strings
            lnkPasswdRetrieval.Text = GetString("LogonForm.lnkPasswordRetrieval");
            lblPasswdRetrieval.Text = GetString("LogonForm.lblPasswordRetrieval");
            btnPasswdRetrieval.Text = GetString("LogonForm.btnPasswordRetrieval");
            rqValue.ErrorMessage    = GetString("LogonForm.rqValue");
            rqValue.ValidationGroup = ClientID + "_PasswordRetrieval";

            // Set logon strings
            LocalizedLabel lblItem = (LocalizedLabel)Login1.FindControl("lblUserName");
            if (lblItem != null)
            {
                lblItem.Text = "{$LogonForm.UserName$}";
            }
            lblItem = (LocalizedLabel)Login1.FindControl("lblPassword");
            if (lblItem != null)
            {
                lblItem.Text = "{$LogonForm.Password$}";
            }
            LocalizedCheckBox chkItem = (LocalizedCheckBox)Login1.FindControl("chkRememberMe");
            if (chkItem != null)
            {
                chkItem.Text = "{$LogonForm.RememberMe$}";
            }
            LocalizedButton btnItem = (LocalizedButton)Login1.FindControl("LoginButton");
            if (btnItem != null)
            {
                btnItem.Text            = "{$LogonForm.LogOnButton$}";
                btnItem.ValidationGroup = ClientID + "_Logon";
            }

            RequiredFieldValidator rfv = (RequiredFieldValidator)Login1.FindControl("rfvUserNameRequired");
            if (rfv != null)
            {
                rfv.ValidationGroup = ClientID + "_Logon";
                rfv.ToolTip         = GetString("LogonForm.NameRequired");
            }

            CMSTextBox txtUserName = (CMSTextBox)Login1.FindControl("UserName");
            if (txtUserName != null)
            {
                txtUserName.EnableAutoComplete = SecurityHelper.IsAutoCompleteEnabledForLogin(CMSContext.CurrentSiteName);
            }

            lnkPasswdRetrieval.Visible = AllowPasswordRetrieval;

            Login1.LoggedIn   += new EventHandler(Login1_LoggedIn);
            Login1.LoggingIn  += new LoginCancelEventHandler(Login1_LoggingIn);
            Login1.LoginError += new EventHandler(Login1_LoginError);

            btnPasswdRetrieval.Click          += new EventHandler(btnPasswdRetrieval_Click);
            btnPasswdRetrieval.ValidationGroup = ClientID + "_PasswordRetrieval";

            if (!RequestHelper.IsPostBack())
            {
                Login1.UserName = ValidationHelper.GetString(Request.QueryString["username"], "");
                // Set SkinID properties
                if (!StandAlone && (PageCycle < PageCycleEnum.Initialized) && (ValidationHelper.GetString(Page.StyleSheetTheme, "") == ""))
                {
                    SetSkinID(SkinID);
                }
            }

            if (!AllowPasswordRetrieval)
            {
                pnlPasswdRetrieval.Visible = false;
            }

            // Register script to update logon error message
            LocalizedLabel failureLit = Login1.FindControl("FailureText") as LocalizedLabel;
            if (failureLit != null)
            {
                StringBuilder sbScript = new StringBuilder();
                sbScript.Append(@"
function UpdateLabel_", ClientID, @"(content, context) {
    var lbl = document.getElementById(context);
    if(lbl)
    {       
        lbl.innerHTML = content;
        lbl.className = ""InfoLabel"";
    }
}");
                ScriptHelper.RegisterClientScriptBlock(this, GetType(), "InvalidLogonAttempts_" + ClientID, sbScript.ToString(), true);
            }
        }
    }
Beispiel #5
0
    /// <summary>
    /// On btnVote click event handler.
    /// </summary>
    protected void btnVote_OnClick(object sender, EventArgs e)
    {
        // Check banned ip
        if (!BannedIPInfoProvider.IsAllowed(CMSContext.CurrentSiteName, BanControlEnum.AllNonComplete))
        {
            lblInfo.CssClass = "ErrorMessage";
            lblInfo.Text     = GetString("General.BannedIP");
            return;
        }

        if (pi != null)
        {
            // Indicates whether user voted or not
            bool voted = false;

            // Indicates wheter all forms of all open-ended answers can be saved
            bool       formsAreValid   = true;
            List <int> selectedAnswers = new List <int>();

            // List of poll answers (in case of multiple answers) for activity logging
            StringBuilder pollAnswerIDs = new StringBuilder();

            // Check if user has already voted
            if ((CheckVoted) && (PollInfoProvider.HasVoted(pi.PollID)))
            {
                errMessage = GetString("Polls.UserHasVoted");
                voted      = true;
            }
            else if (isOpened)
            {
                // Get poll answers
                DataSet ds = Answers;
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    DataRowCollection rows = ds.Tables[0].Rows;

                    LocalizedCheckBox    chkItem = null;
                    LocalizedRadioButton radItem = null;
                    bool           selected      = false;
                    PollAnswerInfo pai           = null;
                    BizForm        bizItem       = null;

                    foreach (DataRow row in rows)
                    {
                        pai = new PollAnswerInfo(row);

                        if ((pai != null) && (pai.AnswerEnabled))
                        {
                            selected = false;

                            // Find specific controls and update pollanswerinfo if controls are checked
                            if (pi.PollAllowMultipleAnswers)
                            {
                                // Find checkbox
                                chkItem = (LocalizedCheckBox)pnlAnswer.FindControl("chk" + pai.AnswerID);

                                if (chkItem != null)
                                {
                                    selected = chkItem.Checked;
                                }
                            }
                            else
                            {
                                // Find radiobutton
                                radItem = (LocalizedRadioButton)pnlAnswer.FindControl("rad" + pai.AnswerID);

                                if (radItem != null)
                                {
                                    selected = radItem.Checked;
                                }
                            }

                            if ((selected) && (pai.AnswerCount < Int32.MaxValue))
                            {
                                bool canBeSaved = false;
                                bizItem = (BizForm)pnlAnswer.FindControl("frm" + pai.AnswerID);

                                if (bizItem == null)
                                {
                                    canBeSaved = true;
                                }
                                else if (bizItem.BasicForm != null)
                                {
                                    // Validate form data
                                    canBeSaved = bizItem.BasicForm.ValidateData();
                                }

                                if (canBeSaved)
                                {
                                    selectedAnswers.Add(pai.AnswerID);
                                }
                                else
                                {
                                    formsAreValid = false;
                                }
                            }
                        }
                    }

                    if (formsAreValid)
                    {
                        if (selectedAnswers.Count > 0)
                        {
                            foreach (int aid in selectedAnswers)
                            {
                                // Set the vote
                                PollAnswerInfoProvider.Vote(aid);
                                // Save the bizform data
                                bizItem = (BizForm)pnlAnswer.FindControl("frm" + aid);
                                if (bizItem != null)
                                {
                                    if (bizItem.BasicForm != null)
                                    {
                                        bizItem.BasicForm.SaveData(null, false);
                                    }
                                }

                                // Save all selected answers (for activity logging)
                                pollAnswerIDs.Append(aid);
                                pollAnswerIDs.Append(ActivityLogProvider.POLL_ANSWER_SEPARATOR);
                            }
                            voted = true;
                        }
                        else
                        {
                            // Set error message if no answer selected
                            lblInfo.CssClass = "ErrorMessage";
                            lblInfo.Text     = GetString("Polls.DidNotVoted");
                        }
                    }

                    if (voted)
                    {
                        LogActivity(pi, pollAnswerIDs.ToString());
                    }

                    if ((CheckVoted) && (voted))
                    {
                        // Create cookie about user's voting
                        PollInfoProvider.SetVoted(pi.PollID);
                    }
                }
            }

            if (voted)
            {
                // Clear cache if it's used
                Answers = null;
                // Reload poll control
                ReloadData(true);

                if (OnAfterVoted != null)
                {
                    OnAfterVoted(this, EventArgs.Empty);
                }
            }
        }
    }
Beispiel #6
0
    /// <summary>
    /// Creates poll answer section.
    /// </summary>
    /// <param name="reload">Indicates postback</param>
    /// <param name="hasVoted">Indicates if user has voted</param>
    protected void CreateAnswerSection(bool reload, bool hasVoted)
    {
        pnlAnswer.Controls.Clear();

        if (pi != null)
        {
            // Get poll's answers
            DataSet ds = Answers;
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                int  count        = 0;
                int  maxCount     = 0;
                long sumCount     = 0;
                bool hideSomeForm = false;

                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    // Sum answer counts and get highest
                    if (ValidationHelper.GetBoolean(row["AnswerEnabled"], true))
                    {
                        count     = ValidationHelper.GetInteger(row["AnswerCount"], 0);
                        sumCount += count;
                        if (count > maxCount)
                        {
                            maxCount = count;
                        }
                    }

                    // Check if any open-ended answer form should be hidden
                    if (ValidationHelper.GetBoolean(row["AnswerHideForm"], false))
                    {
                        hideSomeForm = true;
                    }
                }

                LocalizedCheckBox    chkItem = null;
                LocalizedRadioButton radItem = null;
                LocalizedLabel       lblItem = null;
                BizForm viewBiz  = null;
                string  formName = null;
                int     index    = 0;
                bool    enabled  = false;

                bool bizFormsAvailable = ModuleEntry.IsModuleLoaded(ModuleEntry.BIZFORM) && ResourceSiteInfoProvider.IsResourceOnSite(ModuleEntry.BIZFORM, CMSContext.CurrentSiteName);

                pnlAnswer.Controls.Add(new LiteralControl("<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">"));

                // Create the answers
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    enabled = ValidationHelper.GetBoolean(row["AnswerEnabled"], true);
                    if (enabled)
                    {
                        pnlAnswer.Controls.Add(new LiteralControl("<tr><td class=\"PollAnswer\" colspan=\"2\">"));

                        if (((reload) && (ShowResultsAfterVote)) || (!hasPermission && !HideWhenNotAuthorized) ||
                            (!isOpened && !HideWhenNotOpened) || (CheckVoted && PollInfoProvider.HasVoted(pi.PollID)))
                        {
                            // Add label
                            lblItem    = new LocalizedLabel();
                            lblItem.ID = "lbl" + ValidationHelper.GetInteger(row["AnswerID"], 0);
                            lblItem.EnableViewState = false;
                            lblItem.Text            = HTMLHelper.HTMLEncode(ValidationHelper.GetString(row["AnswerText"], string.Empty));
                            lblItem.CssClass        = "PollAnswerText";

                            pnlAnswer.Controls.Add(lblItem);
                        }
                        else
                        {
                            if (pi.PollAllowMultipleAnswers)
                            {
                                // Add checkboxes for multiple answers
                                chkItem              = new LocalizedCheckBox();
                                chkItem.ID           = "chk" + ValidationHelper.GetInteger(row["AnswerID"], 0);
                                chkItem.AutoPostBack = false;
                                chkItem.Text         = HTMLHelper.HTMLEncode(ValidationHelper.GetString(row["AnswerText"], string.Empty));
                                chkItem.Checked      = false;
                                chkItem.CssClass     = "PollAnswerCheck";

                                if (hideSomeForm)
                                {
                                    chkItem.AutoPostBack    = true;
                                    chkItem.CheckedChanged += AnswerSelectionChanged;
                                }
                                pnlAnswer.Controls.Add(chkItem);
                            }
                            else
                            {
                                // Add radiobuttons
                                radItem              = new LocalizedRadioButton();
                                radItem.ID           = "rad" + ValidationHelper.GetInteger(row["AnswerID"], 0);
                                radItem.AutoPostBack = false;
                                radItem.GroupName    = pi.PollCodeName + "Group";
                                radItem.Text         = HTMLHelper.HTMLEncode(ValidationHelper.GetString(row["AnswerText"], string.Empty));
                                radItem.Checked      = false;
                                radItem.CssClass     = "PollAnswerRadio";

                                if (hideSomeForm)
                                {
                                    radItem.AutoPostBack    = true;
                                    radItem.CheckedChanged += AnswerSelectionChanged;
                                }

                                pnlAnswer.Controls.Add(radItem);
                            }

                            formName = ValidationHelper.GetString(row["AnswerForm"], string.Empty);

                            if (!string.IsNullOrEmpty(formName) && bizFormsAvailable)
                            {
                                // Add forms for open ended answers
                                viewBiz          = new BizForm();
                                viewBiz.FormName = formName;
                                viewBiz.SiteName = CMSContext.CurrentSiteName;
                                viewBiz.AlternativeFormFullName = ValidationHelper.GetString(row["AnswerAlternativeForm"], string.Empty);
                                viewBiz.ID                 = "frm" + ValidationHelper.GetInteger(row["AnswerID"], 0);
                                viewBiz.IsLiveSite         = IsLiveSite;
                                viewBiz.OnAfterDataLoad   += Form_AfterDataLoad;
                                viewBiz.CssClass           = "PollAnswerForm";
                                viewBiz.Visible            = !ValidationHelper.GetBoolean(row["AnswerHideForm"], false);
                                viewBiz.FormClearAfterSave = true;
                                viewBiz.FormRedirectToUrl  = String.Empty;
                                viewBiz.FormDisplayText    = String.Empty;
                                pnlAnswer.Controls.Add(viewBiz);
                            }
                        }

                        pnlAnswer.Controls.Add(new LiteralControl("</td></tr>"));

                        if (ShowGraph || (hasVoted || reload) && ShowResultsAfterVote)
                        {
                            // Create graph under the answer
                            CreateGraph(maxCount, ValidationHelper.GetInteger(row["AnswerCount"], 0), sumCount, index);
                        }

                        index++;
                    }
                }

                pnlAnswer.Controls.Add(new LiteralControl("</table>"));
            }
        }
    }
Beispiel #7
0
    /// <summary>
    /// Creates poll answer section.
    /// </summary>
    /// <param name="reload">Indicates postback</param>
    /// <param name="hasVoted">Indicates if user has voted</param>
    protected void CreateAnswerSection(bool reload, bool hasVoted)
    {
        pnlAnswer.Controls.Clear();

        if (pi != null)
        {
            // Get poll's answers
            DataSet ds = Answers;
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                int  count    = 0;
                int  maxCount = 0;
                long sumCount = 0;

                // Sum answer counts and get highest
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    if (ValidationHelper.GetBoolean(row["AnswerEnabled"], true))
                    {
                        count     = ValidationHelper.GetInteger(row["AnswerCount"], 0);
                        sumCount += count;
                        if (count > maxCount)
                        {
                            maxCount = count;
                        }
                    }
                }

                LocalizedCheckBox    chkItem = null;
                LocalizedRadioButton radItem = null;
                LocalizedLabel       lblItem = null;
                int  index   = 0;
                bool enabled = false;

                pnlAnswer.Controls.Add(new LiteralControl("<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">"));

                // Create the answers
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    enabled = ValidationHelper.GetBoolean(row["AnswerEnabled"], true);
                    if (enabled)
                    {
                        pnlAnswer.Controls.Add(new LiteralControl("<tr><td class=\"PollAnswer\" colspan=\"2\">"));

                        if (((reload) && (this.ShowResultsAfterVote)) || (!hasPermission && !this.HideWhenNotAuthorized) ||
                            (!isOpened && !this.HideWhenNotOpened) || (this.CheckVoted && PollInfoProvider.HasVoted(pi.PollID)))
                        {
                            // Add label
                            lblItem    = new LocalizedLabel();
                            lblItem.ID = "lbl" + ValidationHelper.GetInteger(row["AnswerID"], 0);
                            lblItem.EnableViewState = false;
                            lblItem.Text            = HTMLHelper.HTMLEncode(ValidationHelper.GetString(row["AnswerText"], ""));
                            lblItem.CssClass        = "PollAnswerText";

                            pnlAnswer.Controls.Add(lblItem);
                        }
                        else
                        {
                            if (pi.PollAllowMultipleAnswers)
                            {
                                // Add checkboxes for multiple answers
                                chkItem              = new LocalizedCheckBox();
                                chkItem.ID           = "chk" + ValidationHelper.GetInteger(row["AnswerID"], 0);
                                chkItem.AutoPostBack = false;
                                chkItem.Text         = HTMLHelper.HTMLEncode(ValidationHelper.GetString(row["AnswerText"], ""));
                                chkItem.Checked      = false;
                                chkItem.CssClass     = "PollAnswerCheck";

                                pnlAnswer.Controls.Add(chkItem);
                            }
                            else
                            {
                                // Add radiobuttons
                                radItem              = new LocalizedRadioButton();
                                radItem.ID           = "rad" + ValidationHelper.GetInteger(row["AnswerID"], 0);
                                radItem.AutoPostBack = false;
                                radItem.GroupName    = pi.PollCodeName + "Group";
                                radItem.Text         = HTMLHelper.HTMLEncode(ValidationHelper.GetString(row["AnswerText"], ""));
                                radItem.Checked      = false;
                                radItem.CssClass     = "PollAnswerRadio";

                                pnlAnswer.Controls.Add(radItem);
                            }
                        }

                        pnlAnswer.Controls.Add(new LiteralControl("</td></tr>"));

                        if (this.ShowGraph || (hasVoted || reload) && this.ShowResultsAfterVote)
                        {
                            // Create graph under the answer
                            CreateGraph(maxCount, ValidationHelper.GetInteger(row["AnswerCount"], 0), sumCount, index);
                        }

                        index++;
                    }
                }

                pnlAnswer.Controls.Add(new LiteralControl("</table>"));
            }
        }
    }
    /// <summary>
    /// Creates poll answer section.
    /// </summary>
    /// <param name="reload">Indicates postback</param>
    /// <param name="hasVoted">Indicates if user has voted</param>
    protected void CreateAnswerSection(bool reload, bool hasVoted)
    {
        pnlAnswer.Controls.Clear();

        if (pi != null)
        {
            // Get poll's answers
            DataSet ds = Answers;
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                int count = 0;
                int maxCount = 0;
                long sumCount = 0;
                bool hideSomeForm = false;

                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    // Sum answer counts and get highest
                    if (ValidationHelper.GetBoolean(row["AnswerEnabled"], true))
                    {
                        count = ValidationHelper.GetInteger(row["AnswerCount"], 0);
                        sumCount += count;
                        if (count > maxCount)
                        {
                            maxCount = count;
                        }
                    }

                    // Check if any open-ended answer form should be hidden
                    if (ValidationHelper.GetBoolean(row["AnswerHideForm"], false))
                    {
                        hideSomeForm = true;
                    }
                }

                LocalizedCheckBox chkItem = null;
                LocalizedRadioButton radItem = null;
                LocalizedLabel lblItem = null;
                BizForm viewBiz = null;
                string formName = null;
                int index = 0;
                bool enabled = false;

                bool bizFormsAvailable = ModuleEntry.IsModuleLoaded(ModuleEntry.BIZFORM) && ResourceSiteInfoProvider.IsResourceOnSite(ModuleEntry.BIZFORM, CMSContext.CurrentSiteName);

                pnlAnswer.Controls.Add(new LiteralControl("<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">"));

                // Create the answers
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    enabled = ValidationHelper.GetBoolean(row["AnswerEnabled"], true);
                    if (enabled)
                    {
                        pnlAnswer.Controls.Add(new LiteralControl("<tr><td class=\"PollAnswer\" colspan=\"2\">"));

                        if (((reload) && (ShowResultsAfterVote)) || (!hasPermission && !HideWhenNotAuthorized)
                            || (!isOpened && !HideWhenNotOpened) || (CheckVoted && PollInfoProvider.HasVoted(pi.PollID)))
                        {
                            // Add label
                            lblItem = new LocalizedLabel();
                            lblItem.ID = "lbl" + ValidationHelper.GetInteger(row["AnswerID"], 0);
                            lblItem.EnableViewState = false;
                            lblItem.Text = HTMLHelper.HTMLEncode(ValidationHelper.GetString(row["AnswerText"], string.Empty));
                            lblItem.CssClass = "PollAnswerText";

                            pnlAnswer.Controls.Add(lblItem);
                        }
                        else
                        {
                            if (pi.PollAllowMultipleAnswers)
                            {
                                // Add checkboxes for multiple answers
                                chkItem = new LocalizedCheckBox();
                                chkItem.ID = "chk" + ValidationHelper.GetInteger(row["AnswerID"], 0);
                                chkItem.AutoPostBack = false;
                                chkItem.Text = HTMLHelper.HTMLEncode(ValidationHelper.GetString(row["AnswerText"], string.Empty));
                                chkItem.Checked = false;
                                chkItem.CssClass = "PollAnswerCheck";

                                if (hideSomeForm)
                                {
                                    chkItem.AutoPostBack = true;
                                    chkItem.CheckedChanged += AnswerSelectionChanged;
                                }
                                pnlAnswer.Controls.Add(chkItem);
                            }
                            else
                            {
                                // Add radiobuttons
                                radItem = new LocalizedRadioButton();
                                radItem.ID = "rad" + ValidationHelper.GetInteger(row["AnswerID"], 0);
                                radItem.AutoPostBack = false;
                                radItem.GroupName = pi.PollCodeName + "Group";
                                radItem.Text = HTMLHelper.HTMLEncode(ValidationHelper.GetString(row["AnswerText"], string.Empty));
                                radItem.Checked = false;
                                radItem.CssClass = "PollAnswerRadio";

                                if (hideSomeForm)
                                {
                                    radItem.AutoPostBack = true;
                                    radItem.CheckedChanged += AnswerSelectionChanged;
                                }

                                pnlAnswer.Controls.Add(radItem);
                            }

                            formName = ValidationHelper.GetString(row["AnswerForm"], string.Empty);

                            if (!string.IsNullOrEmpty(formName) && bizFormsAvailable)
                            {
                                // Add forms for open ended answers
                                viewBiz = new BizForm();
                                viewBiz.FormName = formName;
                                viewBiz.SiteName = CMSContext.CurrentSiteName;
                                viewBiz.AlternativeFormFullName = ValidationHelper.GetString(row["AnswerAlternativeForm"], string.Empty);
                                viewBiz.ID = "frm" + ValidationHelper.GetInteger(row["AnswerID"], 0);
                                viewBiz.IsLiveSite = IsLiveSite;
                                viewBiz.OnAfterDataLoad += Form_AfterDataLoad;
                                viewBiz.CssClass = "PollAnswerForm";
                                viewBiz.Visible = !ValidationHelper.GetBoolean(row["AnswerHideForm"], false);
                                viewBiz.FormClearAfterSave = true;
                                viewBiz.FormRedirectToUrl = String.Empty;
                                viewBiz.FormDisplayText = String.Empty;
                                pnlAnswer.Controls.Add(viewBiz);
                            }
                        }

                        pnlAnswer.Controls.Add(new LiteralControl("</td></tr>"));

                        if (ShowGraph || (hasVoted || reload) && ShowResultsAfterVote)
                        {
                            // Create graph under the answer
                            CreateGraph(maxCount, ValidationHelper.GetInteger(row["AnswerCount"], 0), sumCount, index);
                        }

                        index++;
                    }
                }

                pnlAnswer.Controls.Add(new LiteralControl("</table>"));
            }
        }
    }
Beispiel #9
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (this.StopProcessing)
        {
            this.rqValue.Visible = false;
            // Do not process
        }
        else
        {
            // Set failure text
            if (this.FailureText != "")
            {
                Login1.FailureText = ResHelper.LocalizeString(this.FailureText);
            }
            else
            {
                Login1.FailureText = GetString("Login_FailureText");
            }

            // Set strings
            lnkPasswdRetrieval.Text = GetString("LogonForm.lnkPasswordRetrieval");
            lblPasswdRetrieval.Text = GetString("LogonForm.lblPasswordRetrieval");
            btnPasswdRetrieval.Text = GetString("LogonForm.btnPasswordRetrieval");
            rqValue.ErrorMessage    = GetString("LogonForm.rqValue");
            rqValue.ValidationGroup = ClientID + "_PasswordRetrieval";

            // Set logon strings
            LocalizedLabel lblItem = (LocalizedLabel)Login1.FindControl("lblUserName");
            if (lblItem != null)
            {
                lblItem.Text = "{$LogonForm.UserName$}";
            }
            lblItem = (LocalizedLabel)Login1.FindControl("lblPassword");
            if (lblItem != null)
            {
                lblItem.Text = "{$LogonForm.Password$}";
            }
            LocalizedCheckBox chkItem = (LocalizedCheckBox)Login1.FindControl("chkRememberMe");
            if (chkItem != null)
            {
                chkItem.Text = "{$LogonForm.RememberMe$}";
            }
            LocalizedButton btnItem = (LocalizedButton)Login1.FindControl("LoginButton");
            if (btnItem != null)
            {
                btnItem.Text            = "{$LogonForm.LogOnButton$}";
                btnItem.ValidationGroup = ClientID + "_Logon";
            }

            RequiredFieldValidator rfv = (RequiredFieldValidator)Login1.FindControl("rfvUserNameRequired");
            if (rfv != null)
            {
                rfv.ValidationGroup = ClientID + "_Logon";
                rfv.ToolTip         = GetString("LogonForm.NameRequired");
            }

            this.lnkPasswdRetrieval.Visible = this.AllowPasswordRetrieval;

            Login1.LoggedIn  += new EventHandler(Login1_LoggedIn);
            Login1.LoggingIn += new LoginCancelEventHandler(Login1_LoggingIn);

            btnPasswdRetrieval.Click          += new EventHandler(btnPasswdRetrieval_Click);
            btnPasswdRetrieval.ValidationGroup = ClientID + "_PasswordRetrieval";

            if (!RequestHelper.IsPostBack())
            {
                Login1.UserName = ValidationHelper.GetString(Request.QueryString["username"], "");
                // Set SkinID properties
                if (!this.StandAlone && (this.PageCycle < PageCycleEnum.Initialized) && (ValidationHelper.GetString(this.Page.StyleSheetTheme, "") == ""))
                {
                    SetSkinID(this.SkinID);
                }
            }

            if (!this.AllowPasswordRetrieval)
            {
                pnlPasswdRetrieval.Visible = false;
            }
        }
    }