/// <summary>
    /// Header action handler.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="e">Event args</param>
    private void HeaderActions_ActionPerformed(object sender, CommandEventArgs e)
    {
        switch (e.CommandName.ToLowerCSafe())
        {
        case "btnreset_click":     // Reset all answer counts
            // Check 'Manage' permission
            PollInfo pi      = PollInfoProvider.GetPollInfo(AnswerList.PollId);
            int      groupId = 0;

            if (pi != null)
            {
                groupId = pi.PollGroupID;
            }

            // Check permissions
            CheckPermissions(groupId, CMSAdminControl.PERMISSION_MANAGE);

            if (pollId > 0)
            {
                PollAnswerInfoProvider.ResetAnswers(pollId);
                AnswerList.ReloadData();
            }
            break;
        }
    }
Exemple #2
0
 public void map(PollInfo oParam, DataRow tempdr)
 {
     oParam.SysNo     = Util.TrimIntNull(tempdr["SysNo"]);
     oParam.PollName  = Util.TrimNull(tempdr["PollName"]);
     oParam.PollCount = Util.TrimIntNull(tempdr["PollCount"]);
     oParam.Status    = Util.TrimIntNull(tempdr["Status"]);
 }
Exemple #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get the poll ID
        int      pollId = QueryHelper.GetInteger("pollId", 0);
        PollInfo pi     = PollInfoProvider.GetPollInfo(pollId);

        // Check global and site read permmision
        this.CheckPollsReadPermission(pi.PollSiteID);

        if (!RequestHelper.IsPostBack())
        {
            InitalizeMenu(pi);
        }

        // Initialize the page title
        string[,] breadcrumbs = new string[2, 3];
        breadcrumbs[0, 0]     = GetString("Polls_Edit.itemlistlink");
        breadcrumbs[0, 1]     = "~/CMSModules/Polls/Tools/Polls_List.aspx?siteid=" + QueryHelper.GetInteger("siteid", 0);
        breadcrumbs[0, 2]     = "_parent";
        breadcrumbs[1, 0]     = (pi != null ? pi.PollDisplayName : String.Empty);
        breadcrumbs[1, 1]     = "";
        breadcrumbs[1, 2]     = "";

        this.CurrentMaster.Title.TitleText     = GetString("Polls_Edit.headercaption");
        this.CurrentMaster.Title.TitleImage    = GetImageUrl("Objects/Polls_Poll/object.png");
        this.CurrentMaster.Title.Breadcrumbs   = breadcrumbs;
        this.CurrentMaster.Title.HelpTopicName = "general_tab4";
        this.CurrentMaster.Title.HelpName      = "helpTopic";
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get poll id from querystring
        pollId       = QueryHelper.GetInteger("pollId", 0);
        pi           = PollInfoProvider.GetPollInfo(pollId);
        EditedObject = pi;

        // Check global and site read permmision
        CheckPollsReadPermission(pi.PollSiteID);

        if (CheckPollsModifyPermission(pi.PollSiteID, false))
        {
            HeaderAction newItem = new HeaderAction();
            newItem.Text        = GetString("Polls_Answer_List.NewItemCaption");
            newItem.RedirectUrl = ResolveUrl("Polls_Answer_Edit.aspx?pollId=" + pollId);
            CurrentMaster.HeaderActions.AddAction(newItem);

            HeaderAction reset = new HeaderAction();
            reset.Text          = GetString("Polls_Answer_List.ResetButton");
            reset.OnClientClick = "return confirm(" + ScriptHelper.GetString(GetString("Polls_Answer_List.ResetConfirmation")) + ");";
            reset.CommandName   = "btnReset_Click";
            CurrentMaster.HeaderActions.AddAction(reset);
            CurrentMaster.HeaderActions.ActionPerformed += HeaderActions_ActionPerformed;

            AnswerList.AllowEdit = true;
        }

        AnswerList.OnEdit    += new EventHandler(AnswerList_OnEdit);
        AnswerList.PollId     = pollId;
        AnswerList.IsLiveSite = false;
        AnswerList.AllowEdit  = CheckPollsModifyPermission(pi.PollSiteID, false);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get poll id from querystring
        pollId = QueryHelper.GetInteger("pollId", 0);
        pi = PollInfoProvider.GetPollInfo(pollId);
        EditedObject = pi;

        // Check global and site read permmision
        CheckPollsReadPermission(pi.PollSiteID);

        if (CheckPollsModifyPermission(pi.PollSiteID, false))
        {
            HeaderAction newItem = new HeaderAction();
            newItem.Text = GetString("Polls_Answer_List.NewItemCaption");
            newItem.RedirectUrl = ResolveUrl("Polls_Answer_Edit.aspx?pollId=" + pollId);
            CurrentMaster.HeaderActions.AddAction(newItem);

            HeaderAction reset = new HeaderAction();
            reset.Text = GetString("Polls_Answer_List.ResetButton");
            reset.OnClientClick = "return confirm(" + ScriptHelper.GetString(GetString("Polls_Answer_List.ResetConfirmation")) + ");";
            reset.CommandName = "btnReset_Click";
            CurrentMaster.HeaderActions.AddAction(reset);
            CurrentMaster.HeaderActions.ActionPerformed += HeaderActions_ActionPerformed;

            AnswerList.AllowEdit = true;
        }

        AnswerList.OnEdit += new EventHandler(AnswerList_OnEdit);
        AnswerList.PollId = pollId;
        AnswerList.IsLiveSite = false;
        AnswerList.AllowEdit = CheckPollsModifyPermission(pi.PollSiteID, false);
    }
Exemple #6
0
 public PollInfo Get(int pollID, int userID)
 {
     try
     {
         var authUserID = MyVoteAuthentication.GetCurrentUserID().Value;
         var criteria   = new PollSubmissionCriteria(pollID, authUserID);
         var submission = this.PollSubmissionFactory.Fetch(criteria);
         var result     = new PollInfo
         {
             PollID           = submission.PollID,
             PollDescription  = submission.PollDescription,
             MaxAnswers       = submission.PollMaxAnswers,
             MinAnswers       = submission.PollMinAnswers,
             Comment          = submission.Comment,
             PollQuestion     = submission.PollQuestion,
             PollSubmissionID = submission.PollSubmissionID,
             SubmissionDate   = submission.SubmissionDate,
             UserID           = submission.UserID,
             PollOptions      = submission.Responses.Select(_ => new Models.PollResponseOption
             {
                 IsOptionSelected = _.IsOptionSelected,
                 OptionPosition   = _.OptionPosition,
                 OptionText       = _.OptionText,
                 PollOptionID     = _.PollOptionID,
                 PollResponseID   = _.PollResponseID
             }).ToList()
         };
         return(result);
     }
     catch (Exception ex)
     {
         throw ex.ToHttpResponseException(Request);
     }
 }
Exemple #7
0
        public int Add(PollInfo poll)
        {
            string pollSql            = "INSERT INTO " + Config.ForumTablePrefix + "POLLS (DisplayText,TopicId) VALUES (@Question,@TopicId); SELECT SCOPE_IDENTITY();";
            List <SqlParameter> parms = new List <SqlParameter>
            {
                new SqlParameter("@TopicId", SqlDbType.Int)
                {
                    Value = poll.TopicId
                },
                new SqlParameter("@Question", SqlDbType.NVarChar)
                {
                    Value = poll.DisplayText
                }
            };

            int pollid = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnString, CommandType.Text, pollSql, parms.ToArray()));

            StringBuilder choices = new StringBuilder();

            foreach (var choice in poll.Choices)
            {
                choices.AppendFormat("INSERT INTO {0}POLLANSWERS (PollID,DisplayText,SortOrder) VALUES (@PollId,'{1}',{2});", Config.ForumTablePrefix, choice.DisplayText, choice.Order);
            }
            if (poll.Choices.Count > 0)
            {
                SqlHelper.ExecuteNonQuery(SqlHelper.ConnString, CommandType.Text, choices.ToString(), new SqlParameter("@PollId", SqlDbType.Int)
                {
                    Value = pollid
                });
            }

            return(pollid);
        }
Exemple #8
0
        public void Page_Load(object sender, EventArgs e)
        {
            _apiUrl        = HttpUtility.UrlDecode(Request.QueryString["apiUrl"]);
            _siteId        = Convert.ToInt32(Request.QueryString["siteId"]);
            _channelId     = Convert.ToInt32(Request.QueryString["channelId"]);
            _contentId     = Convert.ToInt32(Request.QueryString["contentId"]);
            _returnUrl     = HttpUtility.UrlDecode(Request.QueryString["returnUrl"]);
            _pollInfo      = Main.PollDao.GetPollInfo(_siteId, _channelId, _contentId);
            _fieldInfoList = Main.FieldDao.GetFieldInfoList(_siteId, _channelId, _contentId, false);

            if (!Main.AdminApi.IsSiteAuthorized(_siteId))
            {
                Response.Write("<h1>未授权访问</h1>");
                Response.End();
                return;
            }

            if (IsPostBack)
            {
                return;
            }

            foreach (var fieldInfo in _fieldInfoList)
            {
                LtlFieldNames.Text += $@"<th scope=""col"">{fieldInfo.DisplayName}</th>";
            }

            var totalCount = Main.LogDao.GetCount(_pollInfo.Id);
            var logs       = Main.LogDao.GetPollLogInfoList(_pollInfo.Id, totalCount, 30, 0);

            RptLogs.DataSource     = logs;
            RptLogs.ItemDataBound += RptLogs_ItemDataBound;
            RptLogs.DataBind();
        }
Exemple #9
0
        public PollInfo Load(int sysno)
        {
            string  sql = "select * from poll where sysno = " + sysno;
            DataSet ds  = SqlHelper.ExecuteDataSet(sql);

            if (!Util.HasMoreRow(ds))
            {
                return(null);
            }
            PollInfo oPoll = new PollInfo();

            map(oPoll, ds.Tables[0].Rows[0]);

            string  sqlItem = "select * from poll_item where pollsysno = " + sysno + " order by ItemName";
            DataSet dsItem  = SqlHelper.ExecuteDataSet(sqlItem);

            if (Util.HasMoreRow(dsItem))
            {
                foreach (DataRow dr in dsItem.Tables[0].Rows)
                {
                    PollItemInfo oPollItem = new PollItemInfo();
                    map(oPollItem, dr);
                    oPoll.itemHash.Add(oPollItem.SysNo, oPollItem);
                }
            }
            return(oPoll);
        }
Exemple #10
0
        public void Delete(PollInfo pollInfo, LogInfo logInfo)
        {
            _repository.Delete(logInfo.Id);

            pollInfo.TotalCount -= 1;
            PollManager.Repository.Update(pollInfo);
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        poll = PollInfoProvider.GetPollInfo(ItemID);
        if ((ItemID > 0) && !IsLiveSite)
        {
            EditedObject = poll;
        }

        if (poll != null)
        {
            groupId = poll.PollGroupID;
        }

        // Roles control settings
        addRoles.PollID         = ItemID;
        addRoles.IsLiveSite     = IsLiveSite;
        addRoles.Changed       += addRoles_Changed;
        addRoles.GroupID        = groupId;
        addRoles.ShowSiteFilter = false;

        if (!RequestHelper.IsPostBack() && (poll != null) && !IsLiveSite)
        {
            ReloadData();
        }
        else
        {
            if (radOnlyRoles.Checked)
            {
                addRoles.CurrentSelector.Enabled = true;
                int    currentSiteID = 0;
                string roles         = string.Empty;

                // Get current site ID using CMSContext
                if (SiteContext.CurrentSite != null)
                {
                    currentSiteID = SiteContext.CurrentSiteID;
                }

                DataSet ds = PollInfoProvider.GetPollRoles(ItemID, null, null, -1, "CMS_Role.SiteID, CMS_Role.RoleID");
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        // Include roles associated to current site only
                        if ((ValidationHelper.GetInteger(row["SiteID"], 0) == currentSiteID))
                        {
                            // Insert an item to the listbox
                            roles += ValidationHelper.GetString(row["RoleID"], null) + ";";
                        }
                    }
                }

                addRoles.CurrentValues = roles;
            }
            else
            {
                addRoles.CurrentSelector.Enabled = false;
            }
        }
    }
Exemple #12
0
        public void Page_Load(object sender, EventArgs e)
        {
            _apiUrl    = HttpUtility.UrlDecode(Request.QueryString["apiUrl"]);
            _siteId    = Convert.ToInt32(Request.QueryString["siteId"]);
            _channelId = Convert.ToInt32(Request.QueryString["channelId"]);
            _contentId = Convert.ToInt32(Request.QueryString["contentId"]);
            _returnUrl = HttpUtility.UrlDecode(Request.QueryString["returnUrl"]);
            _pollInfo  = Main.PollDao.GetPollInfo(_siteId, _channelId, _contentId);

            if (!Main.AdminApi.IsSiteAuthorized(_siteId))
            {
                Response.Write("<h1>未授权访问</h1>");
                Response.End();
                return;
            }

            if (IsPostBack)
            {
                return;
            }

            var items = Main.ItemDao.GetItemInfoList(_pollInfo.Id, out _totalCount);

            RptItems.DataSource     = items;
            RptItems.ItemDataBound += RptItems_ItemDataBound;
            RptItems.DataBind();
        }
Exemple #13
0
        public PollInfo GetPollInfo(int id)
        {
            PollInfo pollInfo = null;

            string sqlString = $@"SELECT {nameof(PollInfo.Id)}, 
            {nameof(PollInfo.PublishmentSystemId)}, 
            {nameof(PollInfo.ChannelId)}, 
            {nameof(PollInfo.ContentId)}, 
            {nameof(PollInfo.IsImage)}, 
            {nameof(PollInfo.IsUrl)}, 
            {nameof(PollInfo.IsResult)}, 
            {nameof(PollInfo.IsTimeout)}, 
            {nameof(PollInfo.TimeToStart)}, 
            {nameof(PollInfo.TimeToEnd)}, 
            {nameof(PollInfo.IsCheckbox)},
            {nameof(PollInfo.CheckboxMin)},
            {nameof(PollInfo.CheckboxMax)}, 
            {nameof(PollInfo.IsProfile)}
            FROM {TableName} WHERE {nameof(PollInfo.Id)} = {id}";

            using (var rdr = _helper.ExecuteReader(_connectionString, sqlString))
            {
                if (rdr.Read())
                {
                    pollInfo = GetPollInfo(rdr);
                }
                rdr.Close();
            }

            return(pollInfo);
        }
    /// <summary>
    /// Reloads control with new data.
    /// </summary>
    public override void ReloadData()
    {
        this.ClearForm();
        pollObj = pollObj ?? PollInfoProvider.GetPollInfo(this.ItemID);

        if (pollObj == null)
        {
            return;
        }

        txtCodeName.Text = pollObj.PollCodeName;
        txtDisplayName.Text = pollObj.PollDisplayName;
        txtTitle.Text = pollObj.PollTitle;
        txtQuestion.Text = pollObj.PollQuestion;

        if (pollObj.PollOpenFrom != DataHelper.DATETIME_NOT_SELECTED)
        {
            dtPickerOpenFrom.SelectedDateTime = pollObj.PollOpenFrom;
        }

        if (pollObj.PollOpenTo != DataHelper.DATETIME_NOT_SELECTED)
        {
            dtPickerOpenTo.SelectedDateTime = pollObj.PollOpenTo;
        }

        txtResponseMessage.Text = pollObj.PollResponseMessage;
        chkAllowMultipleAnswers.Checked = pollObj.PollAllowMultipleAnswers;

        if (ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(this.SiteID))
        {
            plcOnline.Visible = true;
            chkLogActivity.Checked = pollObj.PollLogActivity;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get PollID and GroupID from querystring
        int pollId  = QueryHelper.GetInteger("pollid", 0);
        int groupId = QueryHelper.GetInteger("groupid", 0);

        PollInfo pi = PollInfoProvider.GetPollInfo(pollId);

        EditedObject = pi;

        if ((pi != null) && (pi.PollGroupID == groupId))
        {
            PollView.PollCodeName         = pi.PollCodeName;
            PollView.PollSiteID           = pi.PollSiteID;
            PollView.PollGroupID          = pi.PollGroupID;
            PollView.CountType            = CountTypeEnum.Percentage;
            PollView.ShowGraph            = true;
            PollView.ShowResultsAfterVote = true;
            // Check permissions during voting if user hasn't got 'Manage' permission
            PollView.CheckPermissions      = (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.groups", CMSAdminControl.PERMISSION_MANAGE));
            PollView.CheckVoted            = false;
            PollView.HideWhenNotAuthorized = false;
            PollView.CheckOpen             = false;
        }
    }
Exemple #16
0
    /// <summary>
    /// Gets and bulk updates polls. Called when the "Get and bulk update polls" button is pressed.
    /// Expects the CreatePoll method to be run first.
    /// </summary>
    private bool GetAndBulkUpdatePolls()
    {
        // Prepare the parameters
        string where = "PollCodeName LIKE N'MyNewPoll%'";

        // Get the data
        DataSet polls = PollInfoProvider.GetPolls(where, null);

        if (!DataHelper.DataSourceIsEmpty(polls))
        {
            // Loop through the individual items
            foreach (DataRow pollDr in polls.Tables[0].Rows)
            {
                // Create object from DataRow
                PollInfo modifyPoll = new PollInfo(pollDr);

                // Update the properties
                modifyPoll.PollDisplayName = modifyPoll.PollDisplayName.ToUpper();

                // Save the changes
                PollInfoProvider.SetPollInfo(modifyPoll);
            }

            return(true);
        }

        return(false);
    }
    /// <summary>
    /// Displays controls in dependence on properties.
    /// </summary>
    public override void ReloadData(bool forceReload)
    {
        base.ReloadData(forceReload);

        // Setup button
        imgNewPoll.ImageUrl       = GetImageUrl("Objects/Polls_Poll/add.png");
        imgNewPoll.AlternateText  = GetString("polls_new.newitemcaption");
        btnNewPoll.ResourceString = "Polls_List.NewItemCaption";

        // Setup breadcrumbs
        btnBreadCrumbs.ResourceString = "Polls_Edit.itemlistlink";

        // Setup panels
        pnlPollsHeaderLinks.Visible       = false;
        pnlPollsHeaderBreadCrumbs.Visible = false;
        pnlList.Visible    = false;
        pnlEdit.Visible    = false;
        pnlPollNew.Visible = false;

        // Display appropriate poll controls
        switch (SelectedControl)
        {
        case "new":
        {
            pnlPollsHeaderBreadCrumbs.Visible = true;
            pnlPollNew.Visible = true;
            PollNew.ReloadData();
            lblPoll.ResourceString = "polls_new.newitemcaption";
            break;
        }

        case "edit":
        {
            pnlPollsHeaderBreadCrumbs.Visible = true;
            pnlEdit.Visible = true;
            PollEdit.ReloadData(true);
            PollInfo pi = PollInfoProvider.GetPollInfo(this.ItemID);
            if (pi != null)
            {
                lblPoll.ResourceString = null;
                lblPoll.Text           = HTMLHelper.HTMLEncode(pi.PollDisplayName);
            }
            break;
        }

        case "list":
        default:
        {
            if (!dataLoaded || forceReload)
            {
                pnlPollsHeaderLinks.Visible = true;
                pnlList.Visible             = true;
                PollsList.GroupId           = GroupID;
                PollsList.ReloadData();
                dataLoaded = true;
            }
            break;
        }
        }
    }
Exemple #18
0
    /// <summary>
    /// Reloads control with new data.
    /// </summary>
    public override void ReloadData()
    {
        this.ClearForm();
        pollObj = pollObj ?? PollInfoProvider.GetPollInfo(this.ItemID);

        if (pollObj == null)
        {
            return;
        }

        txtCodeName.Text    = pollObj.PollCodeName;
        txtDisplayName.Text = pollObj.PollDisplayName;
        txtTitle.Text       = pollObj.PollTitle;
        txtQuestion.Text    = pollObj.PollQuestion;

        if (pollObj.PollOpenFrom != DataHelper.DATETIME_NOT_SELECTED)
        {
            dtPickerOpenFrom.SelectedDateTime = pollObj.PollOpenFrom;
        }

        if (pollObj.PollOpenTo != DataHelper.DATETIME_NOT_SELECTED)
        {
            dtPickerOpenTo.SelectedDateTime = pollObj.PollOpenTo;
        }

        txtResponseMessage.Text         = pollObj.PollResponseMessage;
        chkAllowMultipleAnswers.Checked = pollObj.PollAllowMultipleAnswers;

        if (ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(this.SiteID))
        {
            plcOnline.Visible      = true;
            chkLogActivity.Checked = pollObj.PollLogActivity;
        }
    }
Exemple #19
0
        public IHttpActionResult Add()
        {
            try
            {
                var request = Context.AuthenticatedRequest;

                var siteId = request.GetQueryInt("siteId");
                if (!request.IsAdminLoggin ||
                    !request.AdminPermissions.HasSitePermissions(siteId, PollUtils.PluginId))
                {
                    return(Unauthorized());
                }

                var pollInfo = new PollInfo
                {
                    SiteId      = siteId,
                    Title       = request.GetPostString("title"),
                    Description = request.GetPostString("description")
                };

                PollManager.Repository.Insert(pollInfo);

                return(Ok(new
                {
                    Value = PollManager.GetPollInfoList(siteId, 0)
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #20
0
    /// <summary>
    /// Gets and updates answer. Called when the "Get and update answer" button is pressed.
    /// Expects the CreateAnswer method to be run first.
    /// </summary>
    private bool GetAndUpdateAnswer()
    {
        // Get the answer
        PollInfo updatePoll = PollInfoProvider.GetPollInfo("MyNewPoll", SiteContext.CurrentSiteID);

        if (updatePoll != null)
        {
            DataSet answers = PollAnswerInfoProvider.GetAnswers(updatePoll.PollID, 1, null);

            if (!DataHelper.DataSourceIsEmpty(answers))
            {
                PollAnswerInfo updateAnswer = new PollAnswerInfo(answers.Tables[0].Rows[0]);

                // Update the properties
                updateAnswer.AnswerText = updateAnswer.AnswerText.ToLower();

                // Save the changes
                PollAnswerInfoProvider.SetPollAnswerInfo(updateAnswer);

                return(true);
            }
        }

        return(false);
    }
Exemple #21
0
    /// <summary>
    /// Initializes edit menu.
    /// </summary>
    protected void InitalizeMenu(PollInfo pi)
    {
        int pollId = 0;
        if (pi != null)
        {
            pollId = pi.PollID;
        }

        string[,] tabs = new string[5, 4];
        tabs[0, 0] = GetString("general.general");
        tabs[0, 1] = "SetHelpTopic('helpTopic', 'general_tab4');";
        tabs[0, 2] = "Polls_General.aspx?pollId=" + pollId;
        tabs[1, 0] = GetString("Polls_Edit.Answers");
        tabs[1, 1] = "SetHelpTopic('helpTopic', 'answer_list');";
        tabs[1, 2] = "Polls_Answer_List.aspx?pollId=" + pollId;
        tabs[2, 0] = GetString("general.security");
        tabs[2, 1] = "SetHelpTopic('helpTopic', 'security3');";
        tabs[2, 2] = "Polls_Security.aspx?pollId=" + pollId;

        int i = 3;
        if ((pi != null) && (pi.PollSiteID == 0))
        {
            tabs[i, 0] = GetString("general.sites");
            tabs[i, 1] = "SetHelpTopic('helpTopic', 'sites');";
            tabs[i, 2] = "Polls_Sites.aspx?pollId=" + pollId;
            i++;
        }

        tabs[i, 0] = GetString("general.view");
        tabs[i, 1] = "SetHelpTopic('helpTopic', 'view');";
        tabs[i, 2] = "Polls_View.aspx?pollId=" + pollId;

        this.CurrentMaster.Tabs.Tabs = tabs;
        this.CurrentMaster.Tabs.UrlTarget = "pollContent";
    }
Exemple #22
0
    /// <summary>
    /// Logs activity
    /// </summary>
    /// <param name="pollId">Poll</param>
    /// <param name="answers">Answers</param>
    private void LogActivity(PollInfo pi, string answers)
    {
        string siteName = CMSContext.CurrentSiteName;

        if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) || !IsLiveSite || (pi == null) || !pi.PollLogActivity || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser) ||
            !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) || !ActivitySettingsHelper.PollVotingEnabled(siteName))
        {
            return;
        }

        TreeNode currentDoc = CMSContext.CurrentDocument;
        var      data       = new ActivityData()
        {
            ContactID = ModuleCommands.OnlineMarketingGetCurrentContactID(),
            SiteID    = CMSContext.CurrentSiteID,
            Type      = PredefinedActivityType.POLL_VOTING,
            TitleData = pi.PollQuestion,
            ItemID    = pi.PollID,
            URL       = URLHelper.CurrentRelativePath,
            NodeID    = (currentDoc != null ? currentDoc.NodeID : 0),
            Culture   = (currentDoc != null ? currentDoc.DocumentCulture : null),
            Value     = answers,
            Campaign  = CMSContext.Campaign
        };

        ActivityLogProvider.LogActivity(data);
    }
Exemple #23
0
    /// <summary>
    /// Gets and bulk updates answers. Called when the "Get and bulk update answers" button is pressed.
    /// Expects the CreateAnswer method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateAnswers()
    {
        PollInfo updatePoll = PollInfoProvider.GetPollInfo("MyNewPoll", SiteContext.CurrentSiteID);

        if (updatePoll != null)
        {
            // Get the data
            DataSet answers = PollAnswerInfoProvider.GetAnswers(updatePoll.PollID);
            if (!DataHelper.DataSourceIsEmpty(answers))
            {
                // Loop through the individual items
                foreach (DataRow answerDr in answers.Tables[0].Rows)
                {
                    // Create object from DataRow
                    PollAnswerInfo modifyAnswer = new PollAnswerInfo(answerDr);

                    // Update the properties
                    modifyAnswer.AnswerText = modifyAnswer.AnswerText.ToUpper();

                    // Save the changes
                    PollAnswerInfoProvider.SetPollAnswerInfo(modifyAnswer);
                }

                return(true);
            }
        }

        return(false);
    }
Exemple #24
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void UniGrid_OnAction(string actionName, object actionArgument)
    {
        if (actionName == "edit")
        {
            SelectedItemID = Convert.ToInt32(actionArgument);
            RaiseOnEdit();
        }
        else if (actionName == "delete")
        {
            PollInfo pi = PollInfoProvider.GetPollInfo(Convert.ToInt32(actionArgument));
            if (pi != null)
            {
                if ((pi.PollSiteID > 0) && !CheckPermissions("cms.polls", PERMISSION_MODIFY) ||
                    (pi.PollSiteID <= 0) && !CheckPermissions("cms.polls", PERMISSION_GLOBALMODIFY))
                {
                    return;
                }

                // Delete PollInfo object from database with it's dependences
                PollInfoProvider.DeletePollInfo(Convert.ToInt32(actionArgument));
            }

            ReloadData();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get PollID from querystring
        int pollId = QueryHelper.GetInteger("pollid", 0);

        // Get poll object
        PollInfo pi = PollInfoProvider.GetPollInfo(pollId);

        EditedObject = pi;

        // Check global and site read permmision
        CheckPollsReadPermission(pi.PollSiteID);

        if (pi != null)
        {
            // Check permissions during voting if user hasn't got 'Modify' permission
            var  user            = MembershipContext.AuthenticatedUser;
            bool checkPermission =
                (pi.PollSiteID > 0) && !user.IsAuthorizedPerResource("cms.polls", CMSAdminControl.PERMISSION_MODIFY) ||
                (pi.PollSiteID <= 0) && !user.IsAuthorizedPerResource("cms.polls", CMSAdminControl.PERMISSION_GLOBALMODIFY);

            pollElem.PollCodeName         = pi.PollCodeName;
            pollElem.PollSiteID           = pi.PollSiteID;
            pollElem.PollGroupID          = pi.PollGroupID;
            pollElem.CountType            = CountTypeEnum.Percentage;
            pollElem.ShowGraph            = true;
            pollElem.ShowResultsAfterVote = true;
            // Check permissions during voting if user hasn't got 'Modify' permission
            pollElem.CheckPermissions      = checkPermission;
            pollElem.CheckVoted            = false;
            pollElem.HideWhenNotAuthorized = false;
            pollElem.CheckOpen             = false;
            pollElem.IsLiveSite            = false;
        }
    }
Exemple #26
0
        async void SetText()
        {
            UkName.Text = Settings.MobileSettings.main_name;
            if (!string.IsNullOrWhiteSpace(Settings.Person.companyPhone))
            {
                LabelPhone.Text = "+" + Settings.Person.companyPhone.Replace("+", "");
            }
            else
            {
                IconViewLogin.IsVisible = false;
                LabelPhone.IsVisible    = false;
            }
            LabelTitle.Text = _announcementInfo.Header;
            LabelDate.Text  = _announcementInfo.Created;
            LabelText.Text  = _announcementInfo.Text;
            FrameBtnQuest.BackgroundColor = (Color)Application.Current.Resources["MainColor"];
            int announcementInfoAdditionalServiceId = _announcementInfo.AdditionalServiceId;

            if (announcementInfoAdditionalServiceId != -1)
            {
                _additional = Settings.GetAdditionalService(announcementInfoAdditionalServiceId);
                byte[] imageByte = await _server.GetPhotoAdditional(announcementInfoAdditionalServiceId.ToString());

                if (imageByte != null)
                {
                    Stream stream = new MemoryStream(imageByte);
                    ImageAdd.Source    = ImageSource.FromStream(() => { return(stream); });
                    ImageAdd.IsVisible = true;

                    var openAdditional = new TapGestureRecognizer();
                    openAdditional.Tapped += async(s, e) =>
                    {
                        await Navigation.PushAsync(new AdditionalOnePage(_additional));
                    };
                    ImageAdd.GestureRecognizers.Add(openAdditional);
                }
            }

            if (_announcementInfo.QuestionGroupID != -1)
            {
                _polls = Settings.GetPollInfo(_announcementInfo.QuestionGroupID);
                FrameBtnQuest.IsVisible = true;
            }

            Color hexColor = (Color)Application.Current.Resources["MainColor"];

            IconViewLogin.SetAppThemeColor(IconView.ForegroundProperty, hexColor, Color.White);

            Pancake.SetAppThemeColor(PancakeView.BorderColorProperty, hexColor, Color.Transparent);
            PancakeViewIcon.SetAppThemeColor(PancakeView.BorderColorProperty, hexColor, Color.Transparent); if (Device.RuntimePlatform == Device.iOS)
            {
                if (AppInfo.PackageName == "rom.best.saburovo" || AppInfo.PackageName == "sys_rom.ru.tsg_saburovo")
                {
                    PancakeViewIcon.Padding = new Thickness(0);
                }
            }
            //LabelTech.SetAppThemeColor(Label.TextColorProperty, hexColor, Color.Black);
            //IconViewTech.SetAppThemeColor(IconView.ForegroundProperty, hexColor, Color.Black);
        }
Exemple #27
0
 public Task <ActionResult> PollAsync(
     [Remainder,
      Description(
          "The content of the poll. Format is `question;option1[;option2;option3;option4;option5]`. You do not need to provide the brackets.")]
     string poll)
 => PollInfo.TryParse(poll, out var pollInfo)
         ? Ok(pollInfo)
         : BadRequest(pollInfo.Validation.InvalidationReason);
 /// <summary>
 /// Logs activity for the given <paramref name="poll"/>.
 /// </summary>
 /// <param name="poll">Reference to poll the activity is logged for</param>
 /// <param name="selectedAnswers">Collection containing the IDs of selected answers within the <paramref name="poll"/></param>
 private void LogActivity(PollInfo poll, IEnumerable <int> selectedAnswers)
 {
     if (PortalContext.ViewMode.IsLiveSite() && IsLiveSite && poll.PollLogActivity)
     {
         var activityInitializer = new PollVotingActivityInitializer(poll, selectedAnswers, DocumentContext.CurrentDocument);
         Service.Resolve <IActivityLogService>().Log(activityInitializer, CMSHttpContext.Current.Request);
     }
 }
Exemple #29
0
 /// <summary>
 /// Logs activity
 /// </summary>
 /// <param name="pi">Poll</param>
 /// <param name="answers">Answers</param>
 private void LogActivity(PollInfo pi, string answers)
 {
     if ((CMSContext.ViewMode == ViewModeEnum.LiveSite) && IsLiveSite)
     {
         Activity activity = new ActivityPollVoting(pi, CMSContext.CurrentDocument, answers, CMSContext.ActivityEnvironmentVariables);
         activity.Log();
     }
 }
Exemple #30
0
 /// <summary>
 /// Logs activity
 /// </summary>
 /// <param name="pi">Poll</param>
 /// <param name="answers">Answers</param>
 private void LogActivity(PollInfo pi, string answers)
 {
     if (PortalContext.ViewMode.IsLiveSite() && IsLiveSite)
     {
         Activity activity = new ActivityPollVoting(pi, DocumentContext.CurrentDocument, answers, AnalyticsContext.ActivityEnvironmentVariables);
         activity.Log();
     }
 }
Exemple #31
0
        public bool Update(PollInfo pollInfo)
        {
            var updated = _repository.Update(pollInfo);

            PollManager.UpdateCache(pollInfo);

            return(updated);
        }
Exemple #32
0
        public void Update(PollInfo poll)
        {
            string pollSql            = "UPDATE " + Config.ForumTablePrefix + "POLLS SET DisplayText=@Question WHERE PollId=@PollId;";
            List <SqlParameter> parms = new List <SqlParameter>
            {
                new SqlParameter("@PollId", SqlDbType.Int)
                {
                    Value = poll.Id
                },
                new SqlParameter("@Question", SqlDbType.NVarChar)
                {
                    Value = poll.DisplayText
                }
            };

            SqlHelper.ExecuteNonQuery(SqlHelper.ConnString, CommandType.Text, pollSql, parms.ToArray());
            if (poll.Choices == null)
            {
                return;
            }
            var choices            = GetPollChoices(poll.Id).ToArray();
            int currentchoicecount = choices.Length;
            int newchoicecount     = poll.Choices.Count;

            for (int ch = 0; ch < choices.Count(); ch++)
            {
                if (ch < newchoicecount)
                {
                    choices[ch].DisplayText = poll.Choices[ch].DisplayText;
                    choices[ch].Order       = poll.Choices[ch].Order;
                    UpdateChoice(choices[ch]);
                }
                else
                {
                    break;
                }
            }
            if (newchoicecount > currentchoicecount)
            {
                for (int i = currentchoicecount; i < newchoicecount; i++)
                {
                    PollChoiceInfo choice = new PollChoiceInfo
                    {
                        DisplayText = poll.Choices[i].DisplayText,
                        PollId      = poll.Id,
                        Order       = poll.Choices[i].Order
                    };
                    AddChoice(choice);
                }
            }
            else if (newchoicecount < currentchoicecount)
            {
                for (int i = newchoicecount; i < currentchoicecount; i++)
                {
                    DeleteChoice(choices[i].Id);
                }
            }
        }
Exemple #33
0
        /// <summary>
        /// 根据投票信息更新数据库中的记录
        /// </summary>
        /// <param name="tid">主题id</param>
        /// <param name="selitemidlist">选择的投票项id列表</param>
        /// <param name="username">用户名</param>
        /// <returns>如果执行成功则返回0, 非法提交返回负值</returns>
        public static int UpdatePoll(int tid, string selitemidlist, string username)
        {
            if (Utils.StrIsNullOrEmpty(username))
            {
                return(-1);
            }

            string[] selitemid = Utils.SplitString(selitemidlist, ",");
            foreach (string optionid in selitemid)
            {
                // 如果id结果集合中出现非数字类型字符则认为是非法
                if (Utils.StrToInt(optionid, -1) == -1)
                {
                    return(-1);
                }
            }

            PollInfo pollinfo = Discuz.Data.Polls.GetPollInfo(tid);

            if (pollinfo.Pollid < 1)
            {
                return(-3);
            }

            if (Utils.StrIsNullOrEmpty(pollinfo.Voternames))
            {
                pollinfo.Voternames = username;
            }
            else
            {
                pollinfo.Voternames = pollinfo.Voternames + "\r\n" + username;
            }

            Discuz.Data.Polls.UpdatePoll(pollinfo);
            List <PollOptionInfo> pollOptionInfoList = Discuz.Data.Polls.GetPollOptionInfoCollection(pollinfo.Tid);

            foreach (string optionid in selitemid)
            {
                foreach (PollOptionInfo polloptioninfo in pollOptionInfoList)
                {
                    if (optionid == polloptioninfo.Polloptionid.ToString())
                    {
                        if (Utils.StrIsNullOrEmpty(polloptioninfo.Voternames))
                        {
                            polloptioninfo.Voternames = username;
                        }
                        else
                        {
                            polloptioninfo.Voternames = polloptioninfo.Voternames + "\r\n" + username;
                        }

                        polloptioninfo.Votes += 1;
                        DatabaseProvider.GetInstance().UpdatePollOption(polloptioninfo);
                    }
                }
            }
            return(0);
        }
Exemple #34
0
    /// <summary>
    /// Reloads form data.
    /// </summary>
    public override void ReloadData()
    {
        this.ClearForm();

        if (poll == null)
        {
            // Get poll object and set group ID
            poll = PollInfoProvider.GetPollInfo(this.ItemID);
        }

        if (poll != null)
        {
            groupId = poll.PollGroupID;
            // Reload role list
            ReloadRolesList();

            switch (poll.PollAccess)
            {
                // If access is enabled for all users
                case SecurityAccessEnum.AllUsers:
                    UncheckAllRadio();
                    radAllUsers.Checked = true;
                    DisableRoleSelector();
                    break;

                // If access is enabled for authenticated users only
                case SecurityAccessEnum.AuthenticatedUsers:
                    UncheckAllRadio();
                    radOnlyUsers.Checked = true;
                    DisableRoleSelector();
                    break;

                // If access is enabled for group members only
                case SecurityAccessEnum.GroupMembers:
                    UncheckAllRadio();
                    radGroupMembers.Checked = true;
                    DisableRoleSelector();
                    break;

                // Access is enabled for users in authorized roles only
                case SecurityAccessEnum.AuthorizedRoles:
                    UncheckAllRadio();
                    radOnlyRoles.Checked = true;
                    btnRemoveRole.Enabled = true;
                    lstRoles.Enabled = true;
                    break;
            }
        }
        else
        {
            DisableRoleSelector();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get poll id from querystring
        pollId = QueryHelper.GetInteger("pollId", 0);
        pi = PollInfoProvider.GetPollInfo(pollId);
        EditedObject = pi;

        // Check global and site read permmision
        CheckPollsReadPermission(pi.PollSiteID);

        if (CheckPollsModifyPermission(pi.PollSiteID, false))
        {
            string[,] actions = new string[2, 7];

            // New item link
            actions[0, 0] = HeaderActions.TYPE_HYPERLINK;
            actions[0, 1] = GetString("Polls_Answer_List.NewItemCaption");
            actions[0, 2] = null;
            actions[0, 3] = ResolveUrl("Polls_Answer_Edit.aspx?pollId=" + pollId.ToString());
            actions[0, 4] = null;
            actions[0, 5] = GetImageUrl("Objects/Polls_PollAnswer/add.png");

            // Reset answer button
            actions[1, 0] = HeaderActions.TYPE_LINKBUTTON;
            actions[1, 1] = GetString("Polls_Answer_List.ResetButton");
            actions[1, 2] = "return confirm(" + ScriptHelper.GetString(GetString("Polls_Answer_List.ResetConfirmation")) + ");";
            actions[1, 3] = null;
            actions[1, 4] = null;
            actions[1, 5] = GetImageUrl("CMSModules/CMS_Polls/resetanswers.png");
            actions[1, 6] = "btnReset_Click";

            CurrentMaster.HeaderActions.Actions = actions;
            CurrentMaster.HeaderActions.ActionPerformed += new CommandEventHandler(HeaderActions_ActionPerformed);

            AnswerList.AllowEdit = true;
        }

        AnswerList.OnEdit += new EventHandler(AnswerList_OnEdit);
        AnswerList.PollId = pollId;
        AnswerList.IsLiveSite = false;
        AnswerList.AllowEdit = CheckPollsModifyPermission(pi.PollSiteID, false);
    }
Exemple #36
0
    /// <summary>
    /// Gets and bulk updates polls. Called when the "Get and bulk update polls" button is pressed.
    /// Expects the CreatePoll method to be run first.
    /// </summary>
    private bool GetAndBulkUpdatePolls()
    {
        // Prepare the parameters
        string where = "PollCodeName LIKE N'MyNewPoll%'";

        // Get the data
        DataSet polls = PollInfoProvider.GetPolls(where, null);

        if (!DataHelper.DataSourceIsEmpty(polls))
        {
            // Loop through the individual items
            foreach (DataRow pollDr in polls.Tables[0].Rows)
            {
                // Create object from DataRow
                PollInfo modifyPoll = new PollInfo(pollDr);

                // Update the properties
                modifyPoll.PollDisplayName = modifyPoll.PollDisplayName.ToUpper();

                // Save the changes
                PollInfoProvider.SetPollInfo(modifyPoll);
            }

            return true;
        }

        return false;
    }
Exemple #37
0
    /// <summary>
    /// Creates poll. Called when the "Create poll" button is pressed.
    /// </summary>
    private bool CreatePoll()
    {
        // Create new poll object
        PollInfo newPoll = new PollInfo();

        // Set the properties
        newPoll.PollDisplayName = "My new poll";
        newPoll.PollCodeName = "MyNewPoll";
        newPoll.PollTitle = "My title";
        newPoll.PollQuestion = "My question";
        newPoll.PollResponseMessage = "My response message.";
        newPoll.PollAllowMultipleAnswers = false;
        newPoll.PollAccess = 0;

        // Save the poll
        PollInfoProvider.SetPollInfo(newPoll);

        return true;
    }
		public void UpdatePoll(PollInfo objPoll)
		{
			dataProvider.UpdatePoll(objPoll.PollId, objPoll.TopicId, objPoll.UserId, objPoll.Question, objPoll.PollType, objPoll.CreatedOnDate);
			//Caching.ClearPollCache(ojbPoll.Topic);
		}
Exemple #39
0
    protected void Page_Load(object sender, EventArgs e)
    {
        poll = PollInfoProvider.GetPollInfo(this.ItemID);
        if ((this.ItemID > 0) && !IsLiveSite)
        {
            EditedObject = poll;
        }

        if (poll != null)
        {
            groupId = poll.PollGroupID;
        }

        // Roles control settings
        addRoles.PollID = this.ItemID;
        addRoles.IsLiveSite = this.IsLiveSite;
        addRoles.Changed += addRoles_Changed;
        addRoles.GroupID = groupId;
        addRoles.ShowSiteFilter = false;

        if (!RequestHelper.IsPostBack() && (poll != null) && !IsLiveSite)
        {
            ReloadData();
        }
        else
        {
            if (radOnlyRoles.Checked)
            {
                addRoles.CurrentSelector.Enabled = true;
                int currentSiteID = 0;
                string roles = string.Empty;

                // Get current site ID using CMSContext
                if (CMSContext.CurrentSite != null)
                {
                    currentSiteID = CMSContext.CurrentSiteID;
                }

                DataSet ds = PollInfoProvider.GetPollRoles(this.ItemID, null, null, -1, "CMS_Role.SiteID, CMS_Role.RoleID");
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        // Include roles associated to current site only
                        if ((ValidationHelper.GetInteger(row["SiteID"], 0) == currentSiteID))
                        {
                            // Insert an item to the listbox
                            roles += ValidationHelper.GetString(row["RoleID"], null) + ";";
                        }
                    }
                }

                addRoles.CurrentValues = roles;
            }
            else
            {
                addRoles.CurrentSelector.Enabled = false;
            }
        }
    }
Exemple #40
0
    /// <summary>
    /// Logs activity
    /// </summary>
    /// <param name="pollId">Poll</param>
    /// <param name="answers">Answers</param>
    private void LogActivity(PollInfo pi, string answers)
    {
        string siteName = CMSContext.CurrentSiteName;
        if ((CMSContext.ViewMode != ViewModeEnum.LiveSite) || !IsLiveSite || (pi == null) || !pi.PollLogActivity || !ActivitySettingsHelper.ActivitiesEnabledForThisUser(CMSContext.CurrentUser)
            || !ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) || !ActivitySettingsHelper.PollVotingEnabled(siteName))
        {
            return;
        }

        TreeNode currentDoc = CMSContext.CurrentDocument;
        var data = new ActivityData()
        {
            ContactID = ModuleCommands.OnlineMarketingGetCurrentContactID(),
            SiteID = CMSContext.CurrentSiteID,
            Type = PredefinedActivityType.POLL_VOTING,
            TitleData = pi.PollQuestion,
            ItemID = pi.PollID,
            URL = URLHelper.CurrentRelativePath,
            NodeID = (currentDoc != null ? currentDoc.NodeID : 0),
            Culture = (currentDoc != null ? currentDoc.DocumentCulture : null),
            Value = answers,
            Campaign = CMSContext.Campaign
        };
        ActivityLogProvider.LogActivity(data);
    }
Exemple #41
0
    /// <summary>
    /// Loads data.
    /// </summary>
    public void ReloadData(bool forceReload)
    {
        if (!this.StopProcessing)
        {
            this.SetContext();

            lblInfo.Text = string.Empty;
            lblInfo.Visible = false;

            if (pi == null)
            {
                pi = PollInfoProvider.GetPollInfo(this.PollCodeName, this.PollSiteID, this.PollGroupID);
                hasPermission = HasPermission();
                isOpened = IsOpened();
            }

            // Show poll if current user has permission or if poll should be displayed even if user is not authorized
            // and if poll is opened or if poll should be opened even if it is not opened
            // ... and show group poll if it is poll of current group
            bool showPoll = (pi != null) && (hasPermission || !this.HideWhenNotAuthorized) && (isOpened || !this.HideWhenNotOpened);
            // Show site poll only if it is poll of current site
            if (showPoll && (pi.PollSiteID > 0) && (pi.PollSiteID != CMSContext.CurrentSiteID))
            {
                showPoll = false;
            }

            // Show global poll only if it is allowed for current site
            if (showPoll && (pi.PollSiteID == 0))
            {
                showPoll = SettingsKeyProvider.GetBoolValue(CMSContext.CurrentSiteName + ".CMSPollsAllowGlobal");
            }

            if (showPoll)
            {
                this.Visible = true;

                // Load title
                lblTitle.Text = HTMLHelper.HTMLEncode(pi.PollTitle);
                // Load question
                lblQuestion.Text = HTMLHelper.HTMLEncode(pi.PollQuestion);

                if ((!forceReload) || ((forceReload) && (this.ShowResultsAfterVote)))
                {
                    // Add answer section
                    CreateAnswerSection(forceReload, this.CheckVoted && PollInfoProvider.HasVoted(pi.PollID));
                }
                else
                {
                    // Hide answer panel
                    pnlAnswer.Visible = false;
                }

                if ((forceReload) && (isOpened))
                {
                    // Hide footer with vote button
                    pnlFooter.Visible = false;

                    // Add poll response after voting
                    if ((errMessage != null) && (errMessage.Trim() != ""))
                    {
                        // Display message if error occurs
                        lblInfo.Text = errMessage;
                        lblInfo.CssClass = "ErrorMessage";
                    }
                    else
                    {
                        // Display poll response message
                        lblResult.Text = HTMLHelper.HTMLEncode(pi.PollResponseMessage);
                    }
                }
                else if (isOpened)
                {
                    if (hasPermission && !(this.CheckVoted && (PollInfoProvider.HasVoted(pi.PollID))))
                    {
                        // Display footer wiht vote button
                        pnlFooter.Visible = true;
                        btnVote.Text = this.ButtonText;
                    }
                    else
                    {
                        pnlFooter.Visible = false;
                    }
                }
                else
                {
                    pnlFooter.Visible = false;
                    lblInfo.Text = GetString("Polls.Closed");
                }
            }
            else
            {
                this.Visible = false;
            }

            this.ReleaseContext();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Required field validator error messages initialization
        rfvCodeName.ErrorMessage = GetString("general.requirescodename");
        rfvDisplayName.ErrorMessage = GetString("general.requiresdisplayname");
        rfvQuestion.ErrorMessage = GetString("Polls_New.QuestionError");
        rfvMaxLength.ErrorMessage = GetString("general.errortexttoolong");
        rfvMaxLengthResponse.ErrorMessage = GetString("general.errortexttoolong");

        // Set caption of the panels
        pnlGeneral.GroupingText = GetString("general.general");
        pnlAdvanced.GroupingText = GetString("general.advancedsettings");

        // Set if it is live site
        txtDisplayName.IsLiveSite = txtTitle.IsLiveSite = txtQuestion.IsLiveSite = txtResponseMessage.IsLiveSite = IsLiveSite;

        if (!RequestHelper.IsPostBack())
        {
            // Show possible license limitation error relayed from new poll page
            string error = QueryHelper.GetText("error", null);
            if (!string.IsNullOrEmpty(error))
            {
                ShowError(error);
            }
        }

        if (pollObj == null)
        {
            pollObj = PollInfoProvider.GetPollInfo(ItemID);
            if ((ItemID > 0) && !IsLiveSite)
            {
                EditedObject = pollObj;
            }
        }

        if (pollObj != null)
        {
            // Fill editing form
            if (!RequestHelper.IsPostBack() && !IsLiveSite)
            {
                ReloadData();
            }
        }

        btnOk.Enabled = Enabled;
    }
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if ((SiteID > 0) && !CheckPermissions("cms.polls", PERMISSION_MODIFY))
        {
            return;
        }
        if ((SiteID <= 0) && !CheckPermissions("cms.polls", PERMISSION_GLOBALMODIFY))
        {
            return;
        }

        // Get trimmed inputs
        string codeName = txtCodeName.Text.Trim();
        string displayName = txtDisplayName.Text.Trim();
        string question = txtQuestion.Text.Trim();

        // Validate the fields
        string errorMessage = new Validator()
            .NotEmpty(codeName, rfvCodeName.ErrorMessage)
            .NotEmpty(displayName, rfvDisplayName.ErrorMessage)
            .NotEmpty(question, rfvQuestion.ErrorMessage)
            .Result;

        if (!ValidationHelper.IsCodeName(codeName))
        {
            errorMessage = GetString("General.ErrorCodeNameInIdentifierFormat");
        }
        else
        {
            // From/to date validation
            if (!dtPickerOpenFrom.IsValidRange() || !dtPickerOpenTo.IsValidRange())
            {
                errorMessage = GetString("general.errorinvaliddatetimerange");
            }

            if (string.IsNullOrEmpty(errorMessage) &&
                (!ValidationHelper.IsIntervalValid(dtPickerOpenFrom.SelectedDateTime, dtPickerOpenTo.SelectedDateTime, true)))
            {
                errorMessage = GetString("General.DateOverlaps");
            }
        }

        if (!string.IsNullOrEmpty(errorMessage))
        {
            // Error message - validation
            ShowError(errorMessage);
            return;
        }

        // Check uniqueness
        PollInfo secondPoll = null;
        if (SiteID <= 0)
        {
            // Try to find poll in global polls (leading period denotes global poll)
            secondPoll = PollInfoProvider.GetPollInfo("." + codeName, 0);
        }
        else
        {
            // Try to find poll in site polls
            secondPoll = PollInfoProvider.GetPollInfo(codeName, SiteID, GroupID);
        }
        if (secondPoll != null && (secondPoll.PollID != ItemID))
        {
            // Error message - Code name already exist
            ShowError(GetString("polls.codenameexists"));
            return;
        }

        pollObj = pollObj ?? PollInfoProvider.GetPollInfo(ItemID);
        if (pollObj == null)
        {
            // Error message - Poll does not exist
            ShowError(GetString("polls.pollnotexist"));
            return;
        }

        if (pollObj.PollSiteID != SiteID)
        {
            throw new Exception("[PollProperties.ascx]: Wrong poll object received since SiteID parameter wasn't provided.");
        }

        // Store the fields
        pollObj.PollCodeName = codeName;
        pollObj.PollDisplayName = displayName;
        pollObj.PollTitle = txtTitle.Text.Trim();
        pollObj.PollQuestion = question;
        pollObj.PollOpenFrom = dtPickerOpenFrom.SelectedDateTime;
        pollObj.PollOpenTo = dtPickerOpenTo.SelectedDateTime;
        pollObj.PollResponseMessage = txtResponseMessage.Text.Trim();
        pollObj.PollAllowMultipleAnswers = chkAllowMultipleAnswers.Checked;

        if (plcOnline.Visible)
        {
            pollObj.PollLogActivity = chkLogActivity.Checked;
        }
        // Save the data
        try
        {
            PollInfoProvider.SetPollInfo(pollObj);
        }
        catch (Exception ex)
        {
            ShowError(GetString("general.saveerror"), ex.Message, null);
            return;
        }

        ShowChangesSaved();

        // Raise on saved event
        RaiseOnSaved();
    }
 /// <summary>
 /// Logs activity
 /// </summary>
 /// <param name="pi">Poll</param>
 /// <param name="answers">Answers</param>
 private void LogActivity(PollInfo pi, string answers)
 {
     if (PortalContext.ViewMode.IsLiveSite() && IsLiveSite)
     {
         Activity activity = new ActivityPollVoting(pi, DocumentContext.CurrentDocument, answers, AnalyticsContext.ActivityEnvironmentVariables);
         activity.Log();
     }
 }
 /// <summary>
 /// Logs activity
 /// </summary>
 /// <param name="pi">Poll</param>
 /// <param name="answers">Answers</param>
 private void LogActivity(PollInfo pi, string answers)
 {
     if ((CMSContext.ViewMode == ViewModeEnum.LiveSite) && IsLiveSite)
     {
         Activity activity = new ActivityPollVoting(pi, CMSContext.CurrentDocument, answers, CMSContext.ActivityEnvironmentVariables);
         activity.Log();
     }
 }
		public int AddPoll(PollInfo objPoll)
		{
			return dataProvider.AddPoll(objPoll.TopicId, objPoll.UserId, objPoll.Question, objPoll.PollType, objPoll.CreatedOnDate);
			//Caching.ClearPollCache(objPoll.TopicId);
		}
    protected void Page_Load(object sender, EventArgs e)
    {
        // Hide code name editing in simple mode
        if (DisplayMode == ControlDisplayModeEnum.Simple)
        {
            plcCodeName.Visible = false;
        }

        // Required field validator error messages initialization
        rfvCodeName.ErrorMessage = GetString("general.requirescodename");
        rfvDisplayName.ErrorMessage = GetString("general.requiresdisplayname");
        rfvQuestion.ErrorMessage = GetString("Polls_New.QuestionError");
        rfvMaxLength.ErrorMessage = GetString("general.errortexttoolong");
        rfvMaxLengthResponse.ErrorMessage = GetString("general.errortexttoolong");

        // Set if it is live site
        txtDisplayName.IsLiveSite = txtTitle.IsLiveSite = txtQuestion.IsLiveSite = txtResponseMessage.IsLiveSite = this.IsLiveSite;

        if (!RequestHelper.IsPostBack())
        {
            // Show possible license limitation error relayed from new poll page
            string error = QueryHelper.GetText("error", null);
            if (!string.IsNullOrEmpty(error))
            {
                lblError.Text = error;
                lblError.Visible = true;
            }
        }

        if (pollObj == null)
        {
            pollObj = PollInfoProvider.GetPollInfo(this.ItemID);
            if ((this.ItemID > 0) && !IsLiveSite)
            {
                EditedObject = pollObj;
            }
        }

        if (pollObj != null)
        {
            // Fill editing form
            if (!RequestHelper.IsPostBack() && !IsLiveSite)
            {
                ReloadData();
            }
        }
    }
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (CreateGlobal)
        {
            if (!CheckPermissions("cms.polls", PERMISSION_GLOBALMODIFY))
            {
                return;
            }
        }
        else
        {
            if (!CheckPermissions("cms.polls", PERMISSION_MODIFY))
            {
                return;
            }
        }

        // Generate code name in simple mode
        string codeName = txtCodeName.Text.Trim();
        if (DisplayMode == ControlDisplayModeEnum.Simple)
        {
            codeName = ValidationHelper.GetCodeName(txtDisplayName.Text.Trim(), null, null);
        }

        // Perform validation
        string errorMessage = new Validator().NotEmpty(codeName, rfvCodeName.ErrorMessage)
            .NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage).NotEmpty(txtQuestion.Text.Trim(), rfvQuestion.ErrorMessage).Result;

        // Check CodeName for identifier format
        if (!ValidationHelper.IsCodeName(codeName))
        {
            errorMessage = GetString("General.ErrorCodeNameInIdentifierFormat");
        }

        if (string.IsNullOrEmpty(errorMessage))
        {
            bool isnew = false;

            // Create new
            PollInfo pollObj = new PollInfo();
            pollObj.PollAllowMultipleAnswers = false;
            pollObj.PollAccess = SecurityAccessEnum.AllUsers;

            // Check if codename already exists on a group or is a global
            PollInfo pi = null;
            if (CreateGlobal)
            {
                pi = PollInfoProvider.GetPollInfo("." + codeName, 0);
                if ((pi != null) && (pi.PollSiteID <= 0))
                {
                    errorMessage = GetString("polls.codenameexists");
                }
            }
            else
            {
                pi = PollInfoProvider.GetPollInfo(codeName, SiteID, GroupID);
                if ((pi != null) && (pi.PollSiteID > 0))
                {
                    errorMessage = GetString("polls.codenameexists");
                }
            }

            if (string.IsNullOrEmpty(errorMessage))
            {
                // Set the fields
                pollObj.PollCodeName = codeName;
                pollObj.PollDisplayName = txtDisplayName.Text.Trim();
                pollObj.PollTitle = txtTitle.Text.Trim();
                pollObj.PollQuestion = txtQuestion.Text.Trim();
                pollObj.PollLogActivity = true;
                if (GroupID > 0)
                {
                    if (SiteID <= 0)
                    {
                        ShowError(GetString("polls.nositeid"));
                        return;
                    }

                    pollObj.PollGroupID = GroupID;
                    pollObj.PollSiteID = SiteID;
                }
                else
                {
                    // Assigned poll to particular site if it is not global poll
                    if (!CreateGlobal)
                    {
                        if (!PollInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Polls, VersionActionEnum.Insert))
                        {
                            LicenseError = GetString("LicenseVersion.Polls");
                        }
                        else
                        {
                            pollObj.PollSiteID = SiteID;
                        }
                    }
                }

                // Save the object
                PollInfoProvider.SetPollInfo(pollObj);
                ItemID = pollObj.PollID;
                isnew = true;

                // Add global poll to current site
                if ((CMSContext.CurrentSite != null) && CreateGlobal)
                {
                    if (PollInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Polls, VersionActionEnum.Insert))
                    {
                        if ((pollObj.PollGroupID == 0) && (pollObj.PollSiteID == 0))
                        {
                            // Bind only global polls to current site
                            PollInfoProvider.AddPollToSite(pollObj.PollID, CMSContext.CurrentSiteID);
                        }
                    }
                    else
                    {
                        LicenseError = GetString("LicenseVersion.Polls");
                    }
                }

                // Redirect to edit mode
                if ((isnew) && (!error))
                {
                    RaiseOnSaved();
                }
            }
            else
            {
                // Error message - code name already exists
                ShowError(GetString("polls.codenameexists"));
            }
        }

        if (!string.IsNullOrEmpty(errorMessage))
        {
            // Error message - validation
            ShowError(errorMessage);
        }
    }
    void pollResult()
    {
        if (Object.Equals(Request.Form["voteItem_" + id], null) || Object.Equals(Request.Form["voteItem_" + id], ""))
        {
            Response.Redirect("Vote.aspx?action=vote&id=" + id);
            Response.End();
        }
        else
        {
            string[] pollArray = Request.Form["voteItem_" + id].ToString().Split(new Char[] { ',' });
            string vote = "";
            PollInfo pi = Poll.GetPollByID(int.Parse(id));
            DataTable poll = this.PollsDataTable(pi.Items.ToString(), pi.Num.ToString());
            for (int i = 0; i < poll.Rows.Count; i++)
            {
                bool count = false;

                for (int j = 0; j < pollArray.Length; j++)
                {
                    if (i == int.Parse(pollArray[j]))
                    {
                        count = true;
                        break;
                    }
                }
                vote += (count ? int.Parse(poll.Rows[i]["itemVote"].ToString()) + 1 : int.Parse(poll.Rows[i]["itemVote"].ToString())).ToString() + "|";
            }
            PollInfo p = new PollInfo();
            p.PollID = int.Parse(id);
            p.Num = vote.Substring(0,vote.Length-1);
            Poll.UpdatePollNum(p);

            Response.Cookies["Vote" + id].Expires = DateTime.Now.AddDays(1);
            Response.Cookies["Vote" + id].Value = "True";
        }
    }