Example #1
0
        /// <summary>
        /// The is input verified.
        /// </summary>
        /// <returns>
        /// Return if input is verified.
        /// </returns>
        protected bool IsInputVerified()
        {
            if (ObjectExtensions.ToType <int>(this.PollGroupListDropDown.SelectedIndex) <= 0)
            {
                if (this.Question.Text.Trim().Length == 0)
                {
                    YafContext.Current.AddLoadMessage(this.GetText("POLLEDIT", "NEED_QUESTION"));
                    return(false);
                }

                this.Question.Text = HtmlHelper.StripHtml(this.Question.Text);

                int notNullcount =
                    (from RepeaterItem ri in this.ChoiceRepeater.Items
                     select((TextBox)ri.FindControl("PollChoice")).Text.Trim()).Count(
                        value => !string.IsNullOrEmpty(value));

                if (notNullcount < 2)
                {
                    YafContext.Current.AddLoadMessage(this.GetText("POLLEDIT", "NEED_CHOICES"));
                    return(false);
                }

                int dateVerified;
                if (!int.TryParse(this.PollExpire.Text.Trim(), out dateVerified) && StringExtensions.IsSet(this.PollExpire.Text.Trim()))
                {
                    YafContext.Current.AddLoadMessage(this.GetText("POLLEDIT", "EXPIRE_BAD"));
                    return(false);
                }

                // Set default value
                if (StringExtensions.IsNotSet(this.PollExpire.Text.Trim()) && this.IsClosedBoundCheckBox.Checked)
                {
                    this.PollExpire.Text = "1";
                }
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// The init poll ui.
        /// </summary>
        /// <param name="pollID">
        /// The poll ID.
        /// </param>
        private void InitPollUI(int?pollID)
        {
            // we should get the schema anyway
            this._choices = LegacyDb.poll_stats(pollID);
            this._choices.Columns.Add("ChoiceOrderID", typeof(int));

            // First existing values alway 1!
            int existingRowsCount    = 1;
            int allExistingRowsCount = this._choices.Rows.Count;

            // we edit existing poll
            if (this._choices.Rows.Count > 0)
            {
                if ((ObjectExtensions.ToType <int>(this._choices.Rows[0]["UserID"]) != this.PageContext.PageUserID) &&
                    (!this.PageContext.IsAdmin) && (!this.PageContext.ForumModeratorAccess))
                {
                    YafBuildLink.RedirectInfoPage(InfoMessage.Invalid);
                }

                this.IsBoundCheckBox.Checked              = ObjectExtensions.ToType <bool>(this._choices.Rows[0]["IsBound"]);
                this.IsClosedBoundCheckBox.Checked        = ObjectExtensions.ToType <bool>(this._choices.Rows[0]["IsClosedBound"]);
                this.AllowMultipleChoicesCheckBox.Checked = ObjectExtensions.ToType <bool>(this._choices.Rows[0]["AllowMultipleChoices"]);
                this.AllowSkipVoteCheckBox.Checked        = ObjectExtensions.ToType <bool>(this._choices.Rows[0]["AllowSkipVote"]);
                this.ShowVotersCheckBox.Checked           = ObjectExtensions.ToType <bool>(this._choices.Rows[0]["ShowVoters"]);
                this.Question.Text           = this._choices.Rows[0]["Question"].ToString();
                this.QuestionObjectPath.Text = this._choices.Rows[0]["QuestionObjectPath"].ToString();

                if (this._choices.Rows[0]["Closes"] != DBNull.Value)
                {
                    TimeSpan closing = (DateTime)this._choices.Rows[0]["Closes"] - DateTime.UtcNow;

                    this.PollExpire.Text = ObjectExtensions.ToType <int>((closing.TotalDays + 1)).ToString();
                }
                else
                {
                    this.PollExpire.Text = null;
                }

                foreach (DataRow choiceRow in this._choices.Rows)
                {
                    choiceRow["ChoiceOrderID"] = existingRowsCount;

                    existingRowsCount++;
                }
            }
            else
            {
                // A new topic is created
                // below check currently if works for topics only, but will do as some things are not enabled
                if (!this.CanCreatePoll())
                {
                    YafBuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
                }

                // Get isBound value using page variables. They are initialized here.
                int pgidt = 0;

                // If a topic poll is edited or new topic created
                if (this._topicId > 0 && this._topicInfo != null)
                {
                    // topicid should not be null here
                    if (!this._topicInfo["PollID"].IsNullOrEmptyDBField())
                    {
                        pgidt = (int)this._topicInfo["PollID"];

                        DataTable pollGroupData = LegacyDb.pollgroup_stats(pgidt);

                        this.IsBoundCheckBox.Checked = Convert.ToBoolean(pollGroupData.Rows[0]["IsBound"]);
                        //// this.IsClosedBoundCheckBox.Checked = Convert.ToBoolean(DB.pollgroup_stats(pgidt).Rows[0]["IsClosedBound"]);
                    }
                }
                else if (this._forumId > 0 && (!(this._topicId > 0) || (!(this._editTopicId > 0))))
                {
                    // forumid should not be null here
                    pgidt = (int)LegacyDb.forum_list(this.PageContext.PageBoardID, this._forumId).Rows[0]["PollGroupID"];
                }
                else if (this._categoryId > 0)
                {
                    // categoryid should not be null here
                    pgidt =
                        this.GetRepository <Category>()
                        .Listread(this.PageContext.PageUserID, this._categoryId)
                        .GetFirstRowColumnAsValue <int>("PollGroupID", 0);
                }

                if (pgidt > 0)
                {
                    if (LegacyDb.pollgroup_stats(pgidt).Rows[0]["IsBound"].ToType <int>() == 2)
                    {
                        this.IsBoundCheckBox.Checked = true;
                    }

                    if (LegacyDb.pollgroup_stats(pgidt).Rows[0]["IsClosedBound"].ToType <int>() == 4)
                    {
                        this.IsClosedBoundCheckBox.Checked = true;
                    }
                }

                // clear the fields...
                this.PollExpire.Text = string.Empty;
                this.Question.Text   = string.Empty;
            }

            // we add dummy rows to data table to fill in repeater empty fields
            int dummyRowsCount = this.Get <YafBoardSettings>().AllowedPollChoiceNumber - allExistingRowsCount - 1;

            for (int i = 0; i <= dummyRowsCount; i++)
            {
                DataRow drow = this._choices.NewRow();
                drow["ChoiceOrderID"] = existingRowsCount + i;
                this._choices.Rows.Add(drow);
            }

            // Bind choices repeater
            this.ChoiceRepeater.DataSource = this._choices;
            this.ChoiceRepeater.DataBind();
            this.ChoiceRepeater.Visible = true;

            // Show controls
            this.SavePoll.Visible                = true;
            this.Cancel.Visible                  = true;
            this.PollRow1.Visible                = true;
            this.PollRowExpire.Visible           = true;
            this.IsClosedBound.Visible           =
                this.IsBound.Visible             = this.Get <YafBoardSettings>().AllowUsersHidePollResults || PageContext.IsAdmin || PageContext.IsForumModerator;
            this.tr_AllowMultipleChoices.Visible = this.Get <YafBoardSettings>().AllowMultipleChoices || PageContext.IsAdmin ||
                                                   PageContext.ForumModeratorAccess;
            this.tr_ShowVoters.Visible    = true;
            this.tr_AllowSkipVote.Visible = false;
        }
Example #3
0
        /// <summary>
        /// The get poll id.
        /// </summary>
        /// <returns>
        /// Returns the Poll Id
        /// </returns>
        private bool?GetPollID()
        {
            if (int.TryParse(this.PollExpire.Text.Trim(), out this._daysPollExpire))
            {
                this._datePollExpire = DateTime.UtcNow.AddDays(this._daysPollExpire);
            }

            // we are just using existing poll
            if (this.PollId != null)
            {
                string questionPath = this.QuestionObjectPath.Text.Trim();
                string questionMime = string.Empty;

                if (StringExtensions.IsSet(questionPath))
                {
                    long length;
                    questionMime = ImageHelper.GetImageParameters(new Uri(questionPath), out length);
                    if (StringExtensions.IsNotSet(questionMime))
                    {
                        YafContext.Current.AddLoadMessage(this.GetTextFormatted("POLLIMAGE_INVALID", questionPath));
                        return(false);
                    }

                    if (length > this.Get <YafBoardSettings>().PollImageMaxFileSize * 1024)
                    {
                        YafContext.Current.AddLoadMessage(
                            this.GetTextFormatted(
                                "POLLIMAGE_TOOBIG",
                                length / 1024,
                                this.Get <YafBoardSettings>().PollImageMaxFileSize,
                                questionPath));
                        return(false);
                    }
                }

                LegacyDb.poll_update(
                    this.PollId,
                    this.Question.Text,
                    this._datePollExpire,
                    this.IsBoundCheckBox.Checked,
                    this.IsClosedBoundCheckBox.Checked,
                    this.AllowMultipleChoicesCheckBox.Checked,
                    this.ShowVotersCheckBox.Checked,
                    this.AllowSkipVoteCheckBox.Checked,
                    questionPath,
                    questionMime);

                foreach (RepeaterItem ri in this.ChoiceRepeater.Items)
                {
                    string choice = ((TextBox)ri.FindControl("PollChoice")).Text.Trim();
                    string chid   = ((HiddenField)ri.FindControl("PollChoiceID")).Value;

                    string choiceObjectPath = ((TextBox)ri.FindControl("ObjectPath")).Text.Trim();

                    string choiceImageMime = string.Empty;

                    // update choice
                    if (StringExtensions.IsSet(choiceObjectPath))
                    {
                        long length;
                        choiceImageMime = ImageHelper.GetImageParameters(new Uri(choiceObjectPath), out length);
                        if (StringExtensions.IsNotSet(choiceImageMime))
                        {
                            YafContext.Current.AddLoadMessage(
                                this.GetTextFormatted("POLLIMAGE_INVALID", choiceObjectPath.Trim()));
                            return(false);
                        }

                        if (length > this.Get <YafBoardSettings>().PollImageMaxFileSize * 1024)
                        {
                            YafContext.Current.AddLoadMessage(
                                this.GetTextFormatted(
                                    "POLLIMAGE_TOOBIG",
                                    length / 1024,
                                    this.Get <YafBoardSettings>().PollImageMaxFileSize,
                                    choiceObjectPath));
                            return(false);
                        }
                    }

                    if (string.IsNullOrEmpty(chid) && !string.IsNullOrEmpty(choice))
                    {
                        // add choice
                        LegacyDb.choice_add(this.PollId, choice, choiceObjectPath, choiceImageMime);
                    }
                    else if (!string.IsNullOrEmpty(chid) && !string.IsNullOrEmpty(choice))
                    {
                        LegacyDb.choice_update(chid, choice, choiceObjectPath, choiceImageMime);
                    }
                    else if (!string.IsNullOrEmpty(chid) && string.IsNullOrEmpty(choice))
                    {
                        // remove choice
                        LegacyDb.choice_delete(chid);
                    }
                }

                return(true);
            }
            else
            {
                // User wishes to create a poll
                // The value was selected, we attach an existing poll
                if (ObjectExtensions.ToType <int>(this.PollGroupListDropDown.SelectedIndex) > 0)
                {
                    int result = LegacyDb.pollgroup_attach(
                        ObjectExtensions.ToType <int>(this.PollGroupListDropDown.SelectedValue),
                        this._topicId,
                        this._forumId,
                        this._categoryId,
                        this._boardId);

                    if (result == 1)
                    {
                        this.PageContext.AddLoadMessage(this.GetText("POLLEDIT", "POLLGROUP_ATTACHED"));
                    }

                    return(true);
                }

                string questionPath = this.QuestionObjectPath.Text.Trim();
                string questionMime = string.Empty;

                if (StringExtensions.IsSet(questionPath))
                {
                    long length;
                    questionMime = ImageHelper.GetImageParameters(new Uri(questionPath), out length);
                    if (StringExtensions.IsNotSet(questionMime))
                    {
                        YafContext.Current.AddLoadMessage(
                            this.GetTextFormatted("POLLIMAGE_INVALID", this.QuestionObjectPath.Text.Trim()));
                        return(false);
                    }

                    if (length > this.Get <YafBoardSettings>().PollImageMaxFileSize * 1024)
                    {
                        YafContext.Current.AddLoadMessage(
                            this.GetTextFormatted(
                                "POLLIMAGE_TOOBIG",
                                length / 1024,
                                this.Get <YafBoardSettings>().PollImageMaxFileSize,
                                questionPath));
                    }
                }

                var pollSaveList = new List <PollSaveList>();

                var rawChoices = new string[3, this.ChoiceRepeater.Items.Count];
                int j          = 0;

                foreach (RepeaterItem ri in this.ChoiceRepeater.Items)
                {
                    string choiceObjectPath = ((TextBox)ri.FindControl("ObjectPath")).Text.Trim();

                    string choiceObjectMime = string.Empty;

                    if (StringExtensions.IsSet(choiceObjectPath))
                    {
                        long length;
                        choiceObjectMime = ImageHelper.GetImageParameters(new Uri(choiceObjectPath), out length);
                        if (StringExtensions.IsNotSet(choiceObjectMime))
                        {
                            YafContext.Current.AddLoadMessage(
                                this.GetTextFormatted("POLLIMAGE_INVALID", choiceObjectPath.Trim()));
                            return(false);
                        }

                        if (length > this.Get <YafBoardSettings>().PollImageMaxFileSize * 1024)
                        {
                            YafContext.Current.AddLoadMessage(
                                this.GetTextFormatted(
                                    "POLLIMAGE_TOOBIG",
                                    length / 1024,
                                    this.Get <YafBoardSettings>().PollImageMaxFileSize,
                                    choiceObjectPath));
                            return(false);
                        }
                    }

                    rawChoices[0, j] = HtmlHelper.StripHtml(((TextBox)ri.FindControl("PollChoice")).Text.Trim());
                    rawChoices[1, j] = choiceObjectPath;
                    rawChoices[2, j] = choiceObjectMime;
                    j++;
                }

                int?realTopic = this._topicId;

                if (this._topicId == null)
                {
                    realTopic = this._editTopicId;
                }

                if (this._datePollExpire == null && StringExtensions.IsSet(this.PollExpire.Text.Trim()))
                {
                    this._datePollExpire = DateTime.UtcNow.AddDays(ObjectExtensions.ToType <int>(this.PollExpire.Text.Trim()));
                }

                pollSaveList.Add(
                    new PollSaveList(
                        this.Question.Text,
                        rawChoices,
                        this._datePollExpire,
                        this.PageContext.PageUserID,
                        realTopic,
                        this._forumId,
                        this._categoryId,
                        this._boardId,
                        questionPath,
                        questionMime,
                        this.IsBoundCheckBox.Checked,
                        this.IsClosedBoundCheckBox.Checked,
                        this.AllowMultipleChoicesCheckBox.Checked,
                        this.ShowVotersCheckBox.Checked,
                        this.AllowSkipVoteCheckBox.Checked));
                LegacyDb.poll_save(pollSaveList);
                return(true);
            }

            return(false); // A poll was not created for this topic.
        }