예제 #1
0
    /// <summary>
    /// Delete analytics data button click handler
    /// </summary>
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        // Check whether current user is authorized to manage analytics data
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.WebAnalytics", "ManageData"))
        {
            RedirectToCMSDeskAccessDenied("CMS.WebAnalytics", "ManageData");
        }

        string statCodeName = drpDeleteObjects.SelectedValue;

        DateTime fromDate = ucDeleteFrom.SelectedDateTime;
        DateTime toDate   = ucDeleteTo.SelectedDateTime;

        // Remove all data
        if (String.IsNullOrEmpty(statCodeName))
        {
            StatisticsInfoProvider.RemoveAnalyticsDataAsync(fromDate, toDate, CMSContext.CurrentSiteID, String.Empty);
        }
        // Remove data from specific report
        else
        {
            String where = String.Empty;

            // Stats for visitors needs special manipulation (it consist of two types
            // of statistics with different code names - new visitor and returning visitor)
            if (statCodeName.ToLowerCSafe() != HitLogProvider.VISITORS_FIRST)
            {
                // Ignore multilingual suffix (multilingual stats use the same data as "base" stats)
                if (statCodeName.ToLowerCSafe().EndsWithCSafe(MULTILINGUAL_SUFFIX))
                {
                    statCodeName = statCodeName.Remove(statCodeName.Length - MULTILINGUAL_SUFFIX.Length);
                }

                // Add where condition based on stat code name
                where = GenerateWhereCondition(statCodeName);

                // Recalculate/delete ordinary stats
                StatisticsInfoProvider.RemoveAnalyticsDataAsync(fromDate, toDate, CMSContext.CurrentSiteID, where);
            }
            else
            {
                where = "(StatisticsCode = '" + HitLogProvider.VISITORS_FIRST + "' OR StatisticsCode ='" + HitLogProvider.VISITORS_RETURNING + "')";
                StatisticsInfoProvider.RemoveAnalyticsDataAsync(fromDate, toDate, CMSContext.CurrentSiteID, where);
            }
        }

        // Disable controls
        EnableControls(false);
        ViewState["DeleterStarted"] = true;

        // Start refresh timer
        timeRefresh.Enabled = true;

        // Display info label and loading image
        ReloadInfoPanel();
    }
예제 #2
0
    public void btnDelete_Click(object sender, EventArgs e)
    {
        // Check 'ManageData' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.WebAnalytics", "ManageData"))
        {
            RedirectToCMSDeskAccessDenied("CMS.WebAnalytics", "ManageData");
        }

        if (statCodeName == String.Empty)
        {
            return;
        }

        DateTime fromDate = pickerFrom.SelectedDateTime;
        DateTime toDate   = pickerTo.SelectedDateTime;

        if (!pickerFrom.IsValidRange() || !pickerTo.IsValidRange())
        {
            lblError.Text    = GetString("general.errorinvaliddatetimerange");
            lblError.Visible = true;
            return;
        }

        if ((fromDate > toDate) && (toDate != DateTimeHelper.ZERO_TIME))
        {
            lblError.Visible = true;
            lblError.Text    = GetString("analt.invalidinterval");
            return;
        }

        String where = String.Empty;

        // Manage A/B test selector
        if ((statCodeName == "abtest") && (ucABTests != null))
        {
            string abTest = ValidationHelper.GetString(ucABTests.Value, String.Empty);
            if ((abTest == String.Empty) || (abTest == "pleaseselect"))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("abtest.pleaseselect");
                return;
            }

            String codeName = (abTest == ValidationHelper.GetString(ucABTests.GetValue("AllRecordValue"), String.Empty)) ? "'abconversion;%'" : "'abconversion;" + SqlHelperClass.GetSafeQueryString(abTest) + ";%'";
            where = "StatisticsCode LIKE " + codeName;
        }

        // Manage MVT test selector
        if ((statCodeName == "mvtest") && (ucMVTests != null))
        {
            string mvTest = ValidationHelper.GetString(ucMVTests.Value, String.Empty);
            if ((mvTest == String.Empty) || (mvTest == "pleaseselect"))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("mvtest.pleaseselect");
                return;
            }

            String codeName = (mvTest == ValidationHelper.GetString(ucMVTests.GetValue("AllRecordValue"), String.Empty)) ? "'mvtconversion;%'" : "'mvtconversion;" + SqlHelperClass.GetSafeQueryString(mvTest) + ";%'";
            where = "StatisticsCode LIKE " + codeName;
        }

        // Manage campaigns
        if (statCodeName == "campaigns")
        {
            string campaign = ValidationHelper.GetString(usCampaigns.Value, String.Empty);
            if ((campaign == String.Empty) || (campaign == "pleaseselect"))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("campaigns.pleaseselect");
                return;
            }

            if (campaign == usCampaigns.AllRecordValue)
            {
                where = "(StatisticsCode='campaign' OR StatisticsCode LIKE 'campconversion;%')";
            }
            else
            {
                where = " ((StatisticsCode='campaign' AND StatisticsObjectName ='" + SqlHelperClass.GetSafeQueryString(campaign) + "') OR StatisticsCode LIKE 'campconversion;" + SqlHelperClass.GetSafeQueryString(campaign) + "')";
            }
        }

        // Delete one campaign (set from url)
        if (statCodeName.StartsWith("singlecampaign"))
        {
            string[] arr = statCodeName.Split(';');
            if (arr.Length == 2)
            {
                String campaign = arr[1];
                where = "(StatisticsCode='campaign' AND StatisticsObjectName ='" + SqlHelperClass.GetSafeQueryString(campaign) + "') OR StatisticsCode LIKE 'campconversion;" + SqlHelperClass.GetSafeQueryString(campaign) + "'";
            }
        }

        // Ingore multilingual suffix (multilingual stats use the same data as "base" stats)
        if (statCodeName.ToLower().EndsWith(MULTILINGUAL_SUFFIX))
        {
            statCodeName = statCodeName.Remove(statCodeName.Length - MULTILINGUAL_SUFFIX.Length);
        }

        // Add where condition based on stat code name
        if (where == String.Empty)
        {
            where = "StatisticsCode LIKE '" + SqlHelperClass.GetSafeQueryString(statCodeName, false) + "'";
        }

        // In case of any error - (this page don't allow deleting all statistics)
        if (where == String.Empty)
        {
            return;
        }

        // Stats for visitors needs special manipulation (it consist of two types
        // of statistics with different code names - new visitor and returning visitor)
        if (statCodeName.ToLower() != HitLogProvider.VISITORS_FIRST)
        {
            StatisticsInfoProvider.RemoveAnalyticsDataAsync(fromDate, toDate, CMSContext.CurrentSiteID, where);
        }
        else
        {
            where = "(StatisticsCode = '" + HitLogProvider.VISITORS_FIRST + "' OR StatisticsCode ='" + HitLogProvider.VISITORS_RETURNING + "')";
            StatisticsInfoProvider.RemoveAnalyticsDataAsync(fromDate, toDate, CMSContext.CurrentSiteID, where);
        }

        // Manage async delete info
        timeRefresh.Enabled = true;
        EnableControls(false);
        ReloadInfoPanel();
        ViewState.Add("DeleterStarted", 1);
    }
    public void btnDelete_Click(object sender, EventArgs e)
    {
        // Check 'ManageData' permission
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.WebAnalytics", "ManageData"))
        {
            RedirectToAccessDenied("CMS.WebAnalytics", "ManageData");
        }

        if (statCodeName == String.Empty)
        {
            return;
        }

        DateTime fromDate = pickerFrom.SelectedDateTime;
        DateTime toDate   = pickerTo.SelectedDateTime;

        if (!pickerFrom.IsValidRange() || !pickerTo.IsValidRange())
        {
            ShowError(GetString("general.errorinvaliddatetimerange"));
            return;
        }

        if ((fromDate > toDate) && (toDate != DateTimeHelper.ZERO_TIME))
        {
            ShowError(GetString("analt.invalidinterval"));
            return;
        }

        String where = String.Empty;

        // Manage campaigns
        if (statCodeName == "campaigns")
        {
            string campaign = ValidationHelper.GetString(usCampaigns.Value, String.Empty);
            if (campaign == String.Empty)
            {
                ShowError(GetString("campaigns.pleaseselect"));
                return;
            }

            if (campaign == usCampaigns.AllRecordValue)
            {
                where = "(StatisticsCode='campaign' OR StatisticsCode LIKE 'campconversion;%')";
            }
            else
            {
                where = " ((StatisticsCode='campaign' AND StatisticsObjectName ='" + SqlHelper.EscapeQuotes(campaign) + "') OR StatisticsCode LIKE 'campconversion;" + SqlHelper.EscapeLikeText(SqlHelper.EscapeQuotes(campaign)) + "')";
            }
        }

        if ((statCodeName == "conversion") || statCodeName.StartsWithCSafe("singleconversion", true))
        {
            String defaultWhere = "(StatisticsCode='conversion' OR StatisticsCode LIKE 'campconversion;%' OR StatisticsCode LIKE 'abconversion;%' OR StatisticsCode LIKE 'mvtconversion;%')";
            if (!statCodeName.StartsWithCSafe("singleconversion", true))
            {
                string conversion = ValidationHelper.GetString(ucConversions.Value, String.Empty);
                if (conversion == String.Empty)
                {
                    ShowError(GetString("conversions.pleaseselect"));
                    return;
                }

                if (conversion == usCampaigns.AllRecordValue)
                {
                    where = defaultWhere;
                }
                else
                {
                    String saveConv = SqlHelper.EscapeQuotes(conversion);
                    where = String.Format("((StatisticsObjectName = '{0}') AND {1})", saveConv, defaultWhere);
                }
            }
            else
            {
                string[] arr = statCodeName.Split(';');
                if (arr.Length == 2)
                {
                    String saveConv = SqlHelper.EscapeQuotes(arr[1]);
                    where = String.Format("((StatisticsObjectName = '{0}') AND {1})", saveConv, defaultWhere);
                }
            }
        }

        // Delete one campaign (set from url)
        if (statCodeName.StartsWithCSafe("singlecampaign", true))
        {
            string[] arr = statCodeName.Split(';');
            if (arr.Length == 2)
            {
                String campaign = arr[1];
                where = "(StatisticsCode='campaign' AND StatisticsObjectName ='" + SqlHelper.EscapeQuotes(campaign) + "') OR StatisticsCode LIKE 'campconversion;" + SqlHelper.EscapeLikeText(SqlHelper.EscapeQuotes(campaign)) + "'";
            }
        }

        // Ingore multilingual suffix (multilingual stats use the same data as "base" stats)
        if (statCodeName.ToLowerCSafe().EndsWithCSafe(MULTILINGUAL_SUFFIX))
        {
            statCodeName = statCodeName.Remove(statCodeName.Length - MULTILINGUAL_SUFFIX.Length);
        }

        // Add where condition based on stat code name
        if (where == String.Empty)
        {
            where = "StatisticsCode LIKE '" + SqlHelper.EscapeLikeText(SqlHelper.EscapeQuotes(statCodeName)) + "'";
        }

        // In case of any error - (this page don't allow deleting all statistics)
        if (where == String.Empty)
        {
            return;
        }

        // Stats for visitors needs special manipulation (it consist of two types
        // of statistics with different code names - new visitor and returning visitor)
        if (statCodeName.ToLowerCSafe() != HitLogProvider.VISITORS_FIRST)
        {
            StatisticsInfoProvider.RemoveAnalyticsDataAsync(fromDate, toDate, SiteContext.CurrentSiteID, where);
        }
        else
        {
            where = "(StatisticsCode = '" + HitLogProvider.VISITORS_FIRST + "' OR StatisticsCode ='" + HitLogProvider.VISITORS_RETURNING + "')";
            StatisticsInfoProvider.RemoveAnalyticsDataAsync(fromDate, toDate, SiteContext.CurrentSiteID, where);
        }

        // Manage async delete info
        timeRefresh.Enabled = true;
        EnableControls(false);
        ReloadInfoPanel();
        ViewState.Add("DeleterStarted", 1);
    }