Exemple #1
0
    /// <summary>
    /// Validates the form. If validation succeeds returns true, otherwise returns false.
    /// </summary>
    private bool Validate()
    {
        DateTime from = ValidationHelper.GetDateTime(form.GetFieldValue("MVTestOpenFrom"), DateTimeHelper.ZERO_TIME);
        DateTime to   = ValidationHelper.GetDateTime(form.GetFieldValue("MVTestOpenTo"), DateTimeHelper.ZERO_TIME);

        if (!DateTimeHelper.IsValidFromTo(from, to))
        {
            ShowError(GetString("om.wrongtimeinterval"));
            return(false);
        }

        MVTestInfo info = new MVTestInfo
        {
            MVTestEnabled  = (bool)form.GetFieldValue("MVTestEnabled"),
            MVTestSiteID   = CurrentSite.SiteID,
            MVTestID       = ((MVTestInfo)form.EditedObject).MVTestID,
            MVTestOpenFrom = from,
            MVTestOpenTo   = to,
            MVTestCulture  = (string)form.GetFieldValue("MVTestCulture"),
            MVTestPage     = String.IsNullOrEmpty(QueryHelper.GetString("AliasPath", null)) ? form.GetFieldValue("MVTestPage").ToString() : QueryHelper.GetString("AliasPath", null)
        };

        MVTestInfo conflictingTest = MVTestInfoProvider.GetConflicting(info).FirstOrDefault();

        if (conflictingTest != null)
        {
            ShowError(String.Format(GetString("om.twotestsonepageerror"), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(conflictingTest.MVTestDisplayName)), info.MVTestPage));
            return(false);
        }

        return(true);
    }
Exemple #2
0
    /// <summary>
    /// Handles Unigrid's OnExternalDataBound event.
    /// </summary>
    protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        case "mvteststatus":
        {
            int        testID   = ValidationHelper.GetInteger(parameter, 0);
            MVTestInfo testInfo = MVTestInfoProvider.GetMVTestInfo(testID);
            return(GetFormattedStatus(testInfo));
        }

        case "maxconversions":
        {
            DataRowView drv         = (DataRowView)parameter;
            string      conversions = ValidationHelper.GetString(drv["MVTestMaxConversions"], "");
            if (!String.IsNullOrEmpty(conversions))
            {
                string type = ValidationHelper.GetString(drv["MVTestTargetConversionType"], "").ToLowerCSafe();
                return(conversions + " (" + GetString("om.conversion." + type) + ")");
            }
            return(string.Empty);
        }
        }
        return(parameter);
    }
Exemple #3
0
    /// <summary>
    /// Handles Unigrid's OnExternalDataBound event.
    /// </summary>
    protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        case "mvteststatus":
            int        testID   = ValidationHelper.GetInteger(parameter, 0);
            MVTestInfo testInfo = MVTestInfoProvider.GetMVTestInfo(testID);
            if (testInfo != null)
            {
                if (!testInfo.MVTestEnabled)
                {
                    return("<span class=\"StatusDisabled\">" + GetString("general.disabled") + "</span>");
                }
                else
                {
                    MVTestStatusEnum statusOut = MVTestStatusEnum.Disabled;
                    string           status    = string.Empty;
                    if (MVTestInfoProvider.MVTestIsRunning(testInfo, out statusOut))
                    {
                        status = "<span class=\"StatusEnabled\">" + GetString("mvtest.status." + MVTestInfoProvider.GetMVTestStatus(testInfo)) + "</span>";
                    }
                    else
                    {
                        status = GetString("mvtest.status." + MVTestInfoProvider.GetMVTestStatus(testInfo));
                    }

                    return(status);
                }
            }

            return(string.Empty);
        }
        return(parameter);
    }
Exemple #4
0
 /// <summary>
 /// Displays status information (running/disabled/none) about given MV test.
 /// </summary>
 private void ShowStatusInfo(MVTestInfo info)
 {
     if ((info != null) && (info.MVTestSiteID != 0))
     {
         var status = MVTestInfoProvider.GetMVTestStatus(info);
         ShowInformation(GetString("general.status") + ": " + FormattedStatusText(status));
     }
 }
    /// <summary>
    // Processes the form - saves the data.
    /// </summary>
    private void Process()
    {
        if (CheckPermissions("CMS.MVTest", PERMISSION_MANAGE))
        {
            // Validate the form
            if (Validate())
            {
                // Ensure the info object
                if (MvtestObj == null)
                {
                    MvtestObj = new MVTestInfo();
                    MvtestObj.MVTestSiteID = siteId;
                    MvtestObj.MVTestPage   = AliasPath;
                }

                // Initialize object
                String newCodeName = txtMVTestCodeName.Text.Trim();
                MvtestObj.MVTestDisplayName    = txtMVTestDisplayName.Text.Trim();
                MvtestObj.MVTestDescription    = txtMVTestDescription.Text;
                MvtestObj.OriginalCulture      = MvtestObj.MVTestCulture;
                MvtestObj.MVTestCulture        = ucCultureSelector.Value.ToString();
                MvtestObj.MVTestMaxConversions = ValidationHelper.GetInteger(txtMVTestMaxConversions.Text, 0);
                MvtestObj.MVTestOpenFrom       = dtpMVTestOpenFrom.SelectedDateTime;
                MvtestObj.MVTestOpenTo         = dtpMVTestOpenTo.SelectedDateTime;
                MvtestObj.MVTestEnabled        = chkMVTestEnabled.Checked;

                // Name has changed. Change analytics statistics data for existing object
                if ((MvtestObj.MVTestID != 0) && (MvtestObj.MVTestName != newCodeName))
                {
                    MVTestInfoProvider.RenameMVTestStatistics(MvtestObj.MVTestName, newCodeName, CMSContext.CurrentSiteID);
                }
                MvtestObj.MVTestName = newCodeName;

                if (radTotal.Checked)
                {
                    MvtestObj.MVTestTargetConversionType = MVTTargetConversionTypeEnum.Total;
                }
                else if (radAnyVariant.Checked)
                {
                    MvtestObj.MVTestTargetConversionType = MVTTargetConversionTypeEnum.AnyCombination;
                }

                if (ShowAliasPath)
                {
                    MvtestObj.MVTestPage = ucPath.Value.ToString().Trim();
                }

                // Save object data to database
                MVTestInfoProvider.SetMVTestInfo(MvtestObj);

                ItemID = MvtestObj.MVTestID;
                RaiseOnSaved();

                // Set the info message
                ShowChangesSaved();
            }
        }
    }
    /// <summary>
    /// Sets the current combination as default
    /// </summary>
    void btnUseCombination_Click(object sender, EventArgs e)
    {
        if ((CMSContext.CurrentPageInfo != null))
        {
            // Keep current page template insatnce
            PageInfo pi = CMSContext.CurrentPageInfo;

            // Set the selected combination (from cookie by default)
            MVTestInfo mvTestInfo = MVTestInfoProvider.GetRunningTest(CMSContext.CurrentAliasPath, CMSContext.CurrentSiteID, CMSContext.CurrentDocumentCulture.CultureCode);
            // Get combination from cookies
            string combinationName = CookieHelper.GetValue(cookieTestName);
            // Get combination info
            MVTCombinationInfo currentCombination = MVTCombinationInfoProvider.GetMVTCombinationInfo(pi.DocumentPageTemplateID, combinationName);
            // Get default combination info
            MVTCombinationInfo defaultCombination = MVTCombinationInfoProvider.GetDefaultCombinationInfo(pi.DocumentPageTemplateID);

            // Check whether default and current combination exists
            if ((currentCombination != null) && (defaultCombination != null))
            {
                // Do not save default combination
                if (currentCombination.MVTCombinationID != defaultCombination.MVTCombinationID)
                {
                    // Copy the combination custom name
                    defaultCombination.MVTCombinationCustomName = currentCombination.MVTCombinationCustomName;
                    defaultCombination.Update();

                    // Tree provider instance
                    TreeProvider tp = new TreeProvider(currentUser);

                    // Documents - use the Preview view mode to ensure that only chosen variant will be rendered (Design mode renders all web part/zone variants and does not combine the instance with the variants)
                    PageTemplateInstance instance = MVTestInfoProvider.CombineWithMVT(pi, pi.PageTemplateInfo.TemplateInstance, currentCombination.MVTCombinationID, ViewModeEnum.Preview);
                    CMSPortalManager.SaveTemplateChanges(pi, pi.PageTemplateInfo, instance, WidgetZoneTypeEnum.None, ViewModeEnum.Design, tp);

                    // Widgets - use the Preview view mode to ensure that only chosen variant will be rendered (Edit mode renders all widget variants and does not combine the instance with the variants)
                    instance = MVTestInfoProvider.CombineWithMVT(pi, pi.DocumentTemplateInstance, currentCombination.MVTCombinationID, ViewModeEnum.Preview);
                    CMSPortalManager.SaveTemplateChanges(pi, pi.PageTemplateInfo, instance, WidgetZoneTypeEnum.Editor, ViewModeEnum.Edit, tp);
                }

                // Remove all variants
                InfoDataSet <MVTVariantInfo> variants = MVTVariantInfoProvider.GetMVTVariants("MVTVariantPageTemplateID = " + pi.DocumentPageTemplateID, null);
                if (!DataHelper.DataSourceIsEmpty(variants))
                {
                    foreach (MVTVariantInfo info in variants)
                    {
                        MVTVariantInfoProvider.DeleteMVTVariantInfo(info);
                    }
                }

                // Clear cached template info
                pi.PageTemplateInfo.Update();

                // Redirect to the same page to update the current view
                URLHelper.Redirect(URLHelper.CurrentURL);
            }
        }
    }
Exemple #7
0
    /// <summary>
    /// Gets formatted status string.
    /// </summary>
    private FormattedText GetFormattedStatus(MVTestInfo testInfo)
    {
        if (testInfo == null)
        {
            throw new ArgumentNullException("testInfo");
        }

        if (!testInfo.MVTestEnabled)
        {
            return(new FormattedText(GetString("general.disabled")).ColorRed());
        }

        var status = new FormattedText(GetString("mvtest.status." + MVTestInfoProvider.GetMVTestStatus(testInfo)));

        if (MVTestInfoProvider.MVTestIsRunning(testInfo))
        {
            status.ColorGreen();
        }
        return(status);
    }
    /// <summary>
    /// Init event handler.
    /// </summary>
    protected override void OnInit(EventArgs e)
    {
        combinationSelector.UniSelector.UseUniSelectorAutocomplete = false;
        currentUser = MembershipContext.AuthenticatedUser;

        // Set the selected combination (from cookie by default)
        MVTestInfo mvTestInfo = MVTestInfoProvider.GetRunningTest(DocumentContext.CurrentAliasPath, SiteContext.CurrentSiteID, DocumentContext.CurrentDocumentCulture.CultureCode);

        // Get the cookie name
        if (mvTestInfo != null)
        {
            // Get a cookie name for the mvt test
            cookieTestName = CookieName.GetMVTCookieName(mvTestInfo.MVTestName);
        }
        else
        {
            // Get a template cookie name (used just in CMSDesk when no test is running)
            cookieTestName = CookieName.GetNoMVTCookieName(DocumentContext.CurrentDocument.GetUsedPageTemplateId());
        }

        // Move cookies expiration to next 30 days
        HttpCookie cookieMVTTest = CookieHelper.GetExistingCookie(cookieTestName);

        if (cookieMVTTest != null)
        {
            CookieHelper.SetValue(cookieMVTTest.Name, cookieMVTTest.Value, cookieMVTTest.Path, DateTime.Now.AddDays(30), false);
        }

        base.OnInit(e);

        viewMode = PortalContext.ViewMode;

        // Check permissions
        if ((currentUser == null) ||
            (!currentUser.IsAuthorizedPerResource("CMS.Design", "Design") && PortalContext.IsDesignMode(viewMode)) ||
            (!currentUser.IsAuthorizedPerResource("CMS.MVTest", "Read")))
        {
            stopProcessing = true;
        }
    }
    /// <summary>
    /// Init event handler.
    /// </summary>
    protected override void OnInit(EventArgs e)
    {
        currentUser = CMSContext.CurrentUser;

        // Set the selected combination (from cookie by default)
        MVTestInfo mvTestInfo = MVTestInfoProvider.GetRunningTest(CMSContext.CurrentAliasPath, CMSContext.CurrentSiteID, CMSContext.CurrentDocumentCulture.CultureCode);

        // Get the cookie name
        if (mvTestInfo != null)
        {
            // Get a cookie name for the mvt test
            cookieTestName = "CMSMVT" + mvTestInfo.MVTestName.ToLower();
        }
        else
        {
            // Get a template cookie name (used just in CMSDesk when no test is running)
            cookieTestName = "CMSNoTestMVT" + CMSContext.CurrentDocument.DocumentPageTemplateID;
        }

        // Move cookies expiration to next 30 days
        HttpCookie cookieMVTTest = CookieHelper.GetExistingCookie(cookieTestName);

        if (cookieMVTTest != null)
        {
            CookieHelper.SetValue(cookieMVTTest.Name, cookieMVTTest.Value, cookieMVTTest.Path, DateTime.Now.AddDays(30), false);
        }

        base.OnInit(e);

        viewMode = CMSContext.ViewMode;

        // Check permissions
        if ((currentUser == null) ||
            (!currentUser.IsAuthorizedPerResource("CMS.Design", "Design") && ((viewMode == ViewModeEnum.Design) || (viewMode == ViewModeEnum.DesignDisabled))) ||
            (!currentUser.IsAuthorizedPerResource("CMS.MVTest", "Read")))
        {
            stopProcessing = true;
        }
    }
Exemple #10
0
    protected void Page_Load(object sender, EventArgs e)
    {
        CurrentUserInfo cui = CMSContext.CurrentUser;

        // Check UI Permissions
        if ((cui == null) || (!cui.IsAuthorizedPerUIElement("CMS.Content", "OnlineMarketing.MVTests")))
        {
            RedirectToCMSDeskUIElementAccessDenied("CMS.Content", "OnlineMarketing.MVTests");
        }

        reportHeader.ActionPerformed += HeaderActions_ActionPerformed;

        if (DataHelper.GetNotEmpty(URLHelper.GetCurrentDomain(), "") != "")
        {
            LicenseHelper.CheckFeatureAndRedirect(URLHelper.GetCurrentDomain(), FeatureEnum.MVTesting);
        }

        // Set disabled module info
        ucDisabledModule.SettingsKeys = "CMSAnalyticsEnabled;CMSMVTEnabled";
        ucDisabledModule.InfoTexts.Add(GetString("WebAnalytics.Disabled") + "</br>");
        ucDisabledModule.InfoTexts.Add(GetString("mvt.disabled"));
        ucDisabledModule.ParentPanel = pnlWarning;

        // Register actions
        ComponentEvents.RequestEvents.RegisterForEvent(ComponentEvents.SAVE, (s, args) => { Save(); });

        ucDisplayReport = this.LoadUserControl("~/CMSModules/Reporting/Controls/DisplayReport.ascx") as IDisplayReport;
        pnlContent.Controls.Add((Control)ucDisplayReport);

        CurrentMaster.PanelContent.CssClass = "";
        UIHelper.AllowUpdateProgress        = false;

        // MVTest Info
        int        mvTestID = QueryHelper.GetInteger("mvTestID", 0);
        MVTestInfo mvInfo   = MVTestInfoProvider.GetMVTestInfo(mvTestID);

        if (mvInfo == null)
        {
            return;
        }

        // Load combination by current template ID and culture
        if (pnlCombination.Visible)
        {
            int nodeID = QueryHelper.GetInteger("NodeID", 0);

            // Create condition for current template combinations
            TreeProvider tree = new TreeProvider(cui);
            TreeNode     node = tree.SelectSingleNode(nodeID, cui.PreferredCultureCode);

            if (node != null)
            {
                usCombination.DocumentID     = node.DocumentID;
                usCombination.PageTemplateID = node.GetUsedPageTemplateId();
            }

            usCombination.ReloadData(true);
        }

        testName = mvInfo.MVTestName;

        ucGraphType.ProcessChartSelectors(false);

        // Enables/disables radio buttons (based on UI elements)
        CurrentUserInfo ui = CMSContext.CurrentUser;

        if (!RequestHelper.IsPostBack())
        {
            if (!ui.IsGlobalAdministrator)
            {
                rbCount.Enabled        = ui.IsAuthorizedPerUIElement("cms.WebAnalytics", "MVTestConversionCount");
                rbRate.Enabled         = ui.IsAuthorizedPerUIElement("cms.WebAnalytics", "MVTestConversionRate");
                rbValue.Enabled        = ui.IsAuthorizedPerUIElement("cms.WebAnalytics", "MVTestConversionValue");
                rbCombinations.Enabled = ui.IsAuthorizedPerUIElement("cms.WebAnalytics", "ConversionsByCombination");

                bool checkedButton = false;

                // Check first enabled button
                foreach (Control ctrl in pnlRadioButtons.Controls)
                {
                    RadioButton rb = ctrl as RadioButton;
                    if (rb != null)
                    {
                        if (rb.Enabled)
                        {
                            rb.Checked    = true;
                            checkedButton = true;
                            break;
                        }
                    }
                }

                // No report avaible -> redirect to access denied
                if (!checkedButton)
                {
                    RedirectToAccessDenied(GetString("mvtest.noreportavaible"));
                }
            }
            else
            {
                // Admin check first radio button
                rbCount.Checked = true;
            }
        }
    }
Exemple #11
0
    /// <summary>
    /// Displays the report
    /// </summary>
    /// <param name="reload">If true dirplay reload control is reloaded</param>
    private void DisplayReport(bool reload)
    {
        ucGraphType.ProcessChartSelectors(false);

        // Prepare report parameters
        DataTable dtp = new DataTable();

        dtp.Columns.Add("FromDate", typeof(DateTime));
        dtp.Columns.Add("ToDate", typeof(DateTime));
        dtp.Columns.Add("CodeName", typeof(string));
        dtp.Columns.Add("MVTestName", typeof(string));
        dtp.Columns.Add("ConversionName", typeof(string));
        dtp.Columns.Add("CombinationName", typeof(string));

        object[] parameters = new object[6];

        parameters[0] = ucGraphType.From;
        parameters[1] = ucGraphType.To;
        parameters[2] = "";
        parameters[3] = ValidationHelper.GetString(ucMVTests.Value, String.Empty);

        // Conversion
        String conversion = ValidationHelper.GetString(ucConversions.Value, String.Empty);
        if (conversion == ucConversions.AllRecordValue)
        {
            conversion = String.Empty;
        }

        parameters[4] = ValidationHelper.GetString(conversion, String.Empty);

        // Combination
        String combination = ValidationHelper.GetString(usCombination.Value, String.Empty);
        if (combination == usCombination.AllRecordValue)
        {
            combination = String.Empty;
        }

        parameters[5] = ValidationHelper.GetString(combination, String.Empty);

        dtp.Rows.Add(parameters);
        dtp.AcceptChanges();

        string reportName = ucGraphType.GetReportName(QueryHelper.GetString("reportCodeName", String.Empty));

        // Hide show selectors by report name
        if (reportName.Contains("mvtestconversionsbycombinations"))
        {
            pnlConversion.Visible = false;
        }
        else
        {
            pnlCultures.Visible = false;
            pnlCombination.Visible = false;
        }

        // Load conversion by mvt code name
        if (pnlConversion.Visible)
        {
            ucConversions.MVTestName = ValidationHelper.GetString(ucMVTests.Value, String.Empty);
            ucConversions.PostbackOnDropDownChange = true;
            ucConversions.ReloadData(true);
        }

        // Load combination by mvt name
        if (pnlCombination.Visible)
        {
            string name = ValidationHelper.GetString(ucMVTests.Value, String.Empty);
            if ((name != String.Empty) && (name != ucMVTests.AllRecordValue))
            {
                string cultureWhere = String.Empty;
                MVTestInfo mvt = MVTestInfoProvider.GetMVTestInfo(name, CMSContext.CurrentSiteName);
                if (mvt != null)
                {
                    string culture = ValidationHelper.GetString(usCulture.Value, String.Empty);
                    if ((culture != String.Empty) && (culture != usCulture.AllRecordValue))
                    {
                        cultureWhere = " AND DocumentCulture = '" + culture.Replace("'", "''") + "'";
                    }

                    string where = "MVTCombinationPageTemplateID IN ( SELECT DocumentPageTemplateID FROM View_CMS_Tree_Joined WHERE NodeSiteID = " + CMSContext.CurrentSiteID + @"
                            AND NodeAliasPath ='" + mvt.MVTestPage + "'" + cultureWhere + ")";

                    usCombination.WhereCondition = SqlHelperClass.AddWhereCondition(usCombination.WhereCondition, where);
                    usCombination.ReloadData(true);
                }
            }
        }

        // Set report
        ucDisplayReport.ReportName = reportName;

        if (!ucDisplayReport.IsReportLoaded())
        {
            lblErrorConversions.Visible = true;
            lblErrorConversions.Text = String.Format(GetString("Analytics_Report.ReportDoesnotExist"), reportName);
        }
        else
        {
            ucDisplayReport.LoadFormParameters = false;
            ucDisplayReport.DisplayFilter = false;
            ucDisplayReport.ReportParameters = dtp.Rows[0];
            ucDisplayReport.GraphImageWidth = 100;
            ucDisplayReport.IgnoreWasInit = true;
            ucDisplayReport.UseExternalReload = true;
            ucDisplayReport.UseProgressIndicator = true;

            // Reload data only if parameter is set
            if (reload)
            {
                ucDisplayReport.ReloadData(true);
            }
        }
    }
    /// <summary>
    /// Validates the form. If validation succeeds returns true, otherwise returns false.
    /// </summary>
    private bool Validate()
    {
        string codename = txtMVTestCodeName.Text.Trim();

        // Validate required fields
        string errorMessage = new Validator()
            .NotEmpty(txtMVTestDisplayName.Text.Trim(), rfvMVTestDisplayName.ErrorMessage)
            .NotEmpty(codename, rfvMVTestCodeName.ErrorMessage)
            .IsCodeName(codename, GetString("general.invalidcodename")).Result;

        // Prepare the properties required for validation (codename + siteID)
        MVTestInfo tempMvtTest = new MVTestInfo();
        tempMvtTest.MVTestName = codename;
        tempMvtTest.MVTestSiteID = siteId;
        if (MvtestObj != null)
        {
            tempMvtTest.MVTestID = MvtestObj.MVTestID;
        }

        // Check the uniqueness of the codename
        if (!tempMvtTest.CheckUniqueCodeName())
        {
            errorMessage = GetString("general.codenameexists");
        }

        if (!dtpMVTestOpenFrom.IsValidRange() || !dtpMVTestOpenTo.IsValidRange())
        {
            errorMessage = GetString("general.errorinvaliddatetimerange");
        }

        if ((dtpMVTestOpenFrom.SelectedDateTime != DateTimeHelper.ZERO_TIME)
            && (dtpMVTestOpenTo.SelectedDateTime != DateTimeHelper.ZERO_TIME)
            && (dtpMVTestOpenFrom.SelectedDateTime > dtpMVTestOpenTo.SelectedDateTime))
        {
            errorMessage = GetString("om.wrongtimeinterval");
        }

        string currentConversions = txtMVTestConversions.Text.Trim();
        string maxConversions = txtMVTestMaxConversions.Text.Trim();
        if (!String.IsNullOrEmpty(currentConversions) && (String.IsNullOrEmpty(errorMessage)))
        {
            errorMessage = new Validator().IsInteger(currentConversions, GetString("om.currentconversionrequiresinteger")).IsPositiveNumber(currentConversions, GetString("om.currentconversionrequiresinteger")).Result;
        }

        if (!String.IsNullOrEmpty(maxConversions) && (String.IsNullOrEmpty(errorMessage)))
        {
            errorMessage = new Validator().IsInteger(maxConversions, GetString("om.targetconversionrequiresinteger")).IsPositiveNumber(maxConversions, GetString("om.targetconversionrequiresinteger")).Result;
        }

        if (string.IsNullOrEmpty(ucPath.Value.ToString().Trim()) && (AliasPath == String.Empty))
        {
            errorMessage = GetString("mvtest.pagerequired");
        }

        // Test if there is no enabled test for same page
        if (chkMVTestEnabled.Checked && TestToValidate())
        {
            QueryDataParameters parameters = null;
            string testPage = ((AliasPath != String.Empty) && !ShowAliasPath) ? AliasPath : ucPath.Value.ToString();
            string where = MVTestInfoProvider.GetRunningCondition(MVTestID, testPage, siteId, ucCultureSelector.Value.ToString(), dtpMVTestOpenFrom.SelectedDateTime, dtpMVTestOpenTo.SelectedDateTime, out parameters);
            DataSet ds = MVTestInfoProvider.GetMVTests(where, null, parameters);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                errorMessage = GetString("om.twotestsonepageerror");
            }
        }

        // Set the error message
        if (!String.IsNullOrEmpty(errorMessage))
        {
            ShowError(errorMessage);
            return false;
        }

        return true;
    }
    /// <summary>
    /// Validates the form. If validation succeeds returns true, otherwise returns false.
    /// </summary>
    private bool Validate()
    {
        string codename = txtMVTestCodeName.Text.Trim();

        // Validate required fields
        string errorMessage = new Validator()
                              .NotEmpty(txtMVTestDisplayName.Text.Trim(), rfvMVTestDisplayName.ErrorMessage)
                              .NotEmpty(codename, rfvMVTestCodeName.ErrorMessage)
                              .IsCodeName(codename, GetString("general.invalidcodename")).Result;

        // Prepare the properties required for validation (codename + siteID)
        MVTestInfo tempMvtTest = new MVTestInfo();

        tempMvtTest.MVTestName   = codename;
        tempMvtTest.MVTestSiteID = siteId;
        if (MvtestObj != null)
        {
            tempMvtTest.MVTestID = MvtestObj.MVTestID;
        }

        // Check the uniqueness of the codename
        if (!tempMvtTest.CheckUniqueCodeName())
        {
            errorMessage = GetString("general.codenameexists");
        }

        if (!dtpMVTestOpenFrom.IsValidRange() || !dtpMVTestOpenTo.IsValidRange())
        {
            errorMessage = GetString("general.errorinvaliddatetimerange");
        }

        if ((dtpMVTestOpenFrom.SelectedDateTime != DateTimeHelper.ZERO_TIME) &&
            (dtpMVTestOpenTo.SelectedDateTime != DateTimeHelper.ZERO_TIME) &&
            (dtpMVTestOpenFrom.SelectedDateTime > dtpMVTestOpenTo.SelectedDateTime))
        {
            errorMessage = GetString("om.wrongtimeinterval");
        }

        string currentConversions = txtMVTestConversions.Text.Trim();
        string maxConversions     = txtMVTestMaxConversions.Text.Trim();

        if (!String.IsNullOrEmpty(currentConversions) && (String.IsNullOrEmpty(errorMessage)))
        {
            errorMessage = new Validator().IsInteger(currentConversions, GetString("om.currentconversionrequiresinteger")).IsPositiveNumber(currentConversions, GetString("om.currentconversionrequiresinteger")).Result;
        }

        if (!String.IsNullOrEmpty(maxConversions) && (String.IsNullOrEmpty(errorMessage)))
        {
            errorMessage = new Validator().IsInteger(maxConversions, GetString("om.targetconversionrequiresinteger")).IsPositiveNumber(maxConversions, GetString("om.targetconversionrequiresinteger")).Result;
        }


        if (string.IsNullOrEmpty(ucPath.Value.ToString().Trim()) && (AliasPath == String.Empty))
        {
            errorMessage = GetString("mvtest.pagerequired");
        }

        // Test if there is no enabled test for same page
        if (chkMVTestEnabled.Checked && TestToValidate())
        {
            QueryDataParameters parameters = null;
            string testPage = ((AliasPath != String.Empty) && !ShowAliasPath) ? AliasPath : ucPath.Value.ToString();
            string where = MVTestInfoProvider.GetRunningCondition(MVTestID, testPage, siteId, ucCultureSelector.Value.ToString(), dtpMVTestOpenFrom.SelectedDateTime, dtpMVTestOpenTo.SelectedDateTime, out parameters);
            DataSet ds = MVTestInfoProvider.GetMVTests(where, null, parameters);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                errorMessage = GetString("om.twotestsonepageerror");
            }
        }

        // Set the error message
        if (!String.IsNullOrEmpty(errorMessage))
        {
            ShowError(errorMessage);
            return(false);
        }

        return(true);
    }
 /// <summary>
 /// Displays status information (running/disabled/none) about given MV test.
 /// </summary>
 private void ShowStatusInfo(MVTestInfo info)
 {
     if ((info != null) && (info.MVTestSiteID != 0))
     {
         var status = MVTestInfoProvider.GetMVTestStatus(info);
         ShowInformation(GetString("general.status") + ": " + FormattedStatusText(status));
     }
 }
    /// <summary>
    /// Gets formatted status string.
    /// </summary>
    private FormattedText GetFormattedStatus(MVTestInfo testInfo)
    {
        if (testInfo == null)
        {
            throw new ArgumentNullException("testInfo");
        }

        if (!testInfo.MVTestEnabled)
        {
            return new FormattedText(GetString("general.disabled")).ColorRed();
        }

        var status = new FormattedText(GetString("mvtest.status." + MVTestInfoProvider.GetMVTestStatus(testInfo)));
        if (MVTestInfoProvider.MVTestIsRunning(testInfo))
        {
            status.ColorGreen();
        }
        return status;
    }
Exemple #16
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check UI Permissions
        if ((CMSContext.CurrentUser == null) || (!CMSContext.CurrentUser.IsAuthorizedPerUIElement("CMS.Content", "OnlineMarketing.MVTests")))
        {
            RedirectToCMSDeskUIElementAccessDenied("CMS.Content", "OnlineMarketing.MVTests");
        }

        if (DataHelper.GetNotEmpty(URLHelper.GetCurrentDomain(), "") != "")
        {
            LicenseHelper.CheckFeatureAndRedirect(URLHelper.GetCurrentDomain(), FeatureEnum.MVTesting);
        }

        // Check features and display warning
        String siteName = CMSContext.CurrentSiteName;

        if (!AnalyticsHelper.AnalyticsEnabled(siteName))
        {
            this.pnlWarning.Visible = true;
            this.lblWAWarning.Text  = GetString("WebAnalytics.Disabled") + "<br/>";
        }

        if (!MVTestInfoProvider.MVTestingEnabled(siteName))
        {
            this.pnlWarning.Visible = true;
            this.lblMVWarning.Text  = GetString("mvt.disabled");
        }

        ucDisplayReport = LoadControl("~/CMSModules/Reporting/Controls/DisplayReport.ascx") as IDisplayReport;
        pnlContent.Controls.Add((Control)ucDisplayReport);

        CurrentMaster.PanelContent.CssClass = "";
        UIHelper.AllowUpdateProgress        = false;

        // MVTest Info
        int        mvTestID = QueryHelper.GetInteger("mvTestID", 0);
        MVTestInfo mvInfo   = MVTestInfoProvider.GetMVTestInfo(mvTestID);

        if (mvInfo == null)
        {
            return;
        }

        // Load combination by current template ID and culture
        if (pnlCombination.Visible)
        {
            int nodeID = QueryHelper.GetInteger("NodeID", 0);

            CurrentUserInfo cui = CMSContext.CurrentUser;

            // Create condition for current template combinations
            TreeProvider tree = new TreeProvider(cui);
            TreeNode     node = tree.SelectSingleNode(nodeID, cui.PreferredCultureCode);

            if (node != null)
            {
                usCombination.DocumentID     = node.DocumentID;
                usCombination.PageTemplateID = node.DocumentPageTemplateID;
            }

            usCombination.ReloadData(true);
        }

        testName = mvInfo.MVTestName;

        // Text for menu
        mSave       = GetString("general.save");
        mPrint      = GetString("Analytics_Report.Print");
        mDeleteData = GetString("Analytics_Report.ManageData");

        // Images for menu buttons
        imgSave.ImageUrl       = GetImageUrl("CMSModules/CMS_Content/EditMenu/save_small.png");
        imgPrint.ImageUrl      = GetImageUrl("General/printSmall.png");
        imgManageData.ImageUrl = GetImageUrl("CMSModules/CMS_Reporting/managedataSmall.png");

        // Check 'ManageData' permission
        if (CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.WebAnalytics", "ManageData"))
        {
            this.lnkDeleteData.OnClientClick = "modalDialog('" +
                                               ResolveUrl("~/CMSModules/Reporting/WebAnalytics/Analytics_ManageData.aspx") +
                                               "?statcodename=mvtconversion;" + testName + ";%', 'AnalyticsManageData', " + AnalyticsHelper.MANAGE_WINDOW_WIDTH + ", " + AnalyticsHelper.MANAGE_WINDOW_HEIGHT + "); return false; ";
            this.lnkDeleteData.Visible = true;
        }

        ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "myModalDialog",
                                               ScriptHelper.GetScript("function myModalDialog(url, name, width, height) { " +
                                                                      "win = window; " +
                                                                      "var dHeight = height; var dWidth = width; " +
                                                                      "if (( document.all )&&(navigator.appName != 'Opera')) { " +
                                                                      "try { win = wopener.window; } catch (e) {} " +
                                                                      "if ( parseInt(navigator.appVersion.substr(22, 1)) < 7 ) { dWidth += 4; dHeight += 58; }; " +
                                                                      "dialog = win.showModalDialog(url, this, 'dialogWidth:' + dWidth + 'px;dialogHeight:' + dHeight + 'px;resizable:yes;scroll:yes'); " +
                                                                      "} else { " +
                                                                      "oWindow = win.open(url, name, 'height=' + dHeight + ',width=' + dWidth + ',toolbar=no,directories=no,menubar=no,modal=yes,dependent=yes,resizable=yes,scroll=yes,scrollbars=yes'); oWindow.opener = this; oWindow.focus(); } } "));

        ucGraphType.ProcessChartSelectors(false);

        // Enables/disables radio buttons (based on UI elements)
        CurrentUserInfo ui = CMSContext.CurrentUser;

        if (!RequestHelper.IsPostBack())
        {
            if (!ui.IsGlobalAdministrator)
            {
                rbCount.Enabled        = ui.IsAuthorizedPerUIElement("cms.WebAnalytics", "MVTestConversionCount");
                rbRate.Enabled         = ui.IsAuthorizedPerUIElement("cms.WebAnalytics", "MVTestConversionRate");
                rbValue.Enabled        = ui.IsAuthorizedPerUIElement("cms.WebAnalytics", "MVTestConversionValue");
                rbCombinations.Enabled = ui.IsAuthorizedPerUIElement("cms.WebAnalytics", "ConversionsByCombination");

                bool checkedButton = false;

                // Check first enabled button
                foreach (Control ctrl in pnlRadioButtons.Controls)
                {
                    RadioButton rb = ctrl as RadioButton;
                    if (rb != null)
                    {
                        if (rb.Enabled)
                        {
                            rb.Checked    = true;
                            checkedButton = true;
                            break;
                        }
                    }
                }

                // No report avaible -> redirect to access denied
                if (!checkedButton)
                {
                    RedirectToAccessDenied(GetString("mvtest.noreportavaible"));
                }
            }
            else
            {
                // Admin check first radio button
                rbCount.Checked = true;
            }
        }
    }
    /// <summary>
    /// Validates the form. If validation succeeds returns true, otherwise returns false.
    /// </summary>
    private bool Validate()
    {
        DateTime from = ValidationHelper.GetDateTime(form.GetFieldValue("MVTestOpenFrom"), DateTimeHelper.ZERO_TIME);
        DateTime to = ValidationHelper.GetDateTime(form.GetFieldValue("MVTestOpenTo"), DateTimeHelper.ZERO_TIME);

        if (!DateTimeHelper.IsValidFromTo(from, to))
        {
            ShowError(GetString("om.wrongtimeinterval"));
            return false;
        }

        MVTestInfo info = new MVTestInfo
        {
            MVTestEnabled = (bool)form.GetFieldValue("MVTestEnabled"),
            MVTestSiteID = CurrentSite.SiteID,
            MVTestID = ((MVTestInfo)form.EditedObject).MVTestID,
            MVTestOpenFrom = from,
            MVTestOpenTo = to,
            MVTestCulture = (string)form.GetFieldValue("MVTestCulture"),
            MVTestPage = String.IsNullOrEmpty(QueryHelper.GetString("AliasPath", null)) ? form.GetFieldValue("MVTestPage").ToString() : QueryHelper.GetString("AliasPath", null)
        };

        MVTestInfo conflictingTest = MVTestInfoProvider.GetConflicting(info).FirstOrDefault();
        if (conflictingTest != null)
        {
            ShowError(String.Format(GetString("om.twotestsonepageerror"), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(conflictingTest.MVTestDisplayName)), info.MVTestPage));
            return false;
        }

        return true;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        var cui = MembershipContext.AuthenticatedUser;

        reportHeader.ActionPerformed += HeaderActions_ActionPerformed;

        if (DataHelper.GetNotEmpty(RequestContext.CurrentDomain, "") != "")
        {
            LicenseHelper.CheckFeatureAndRedirect(RequestContext.CurrentDomain, FeatureEnum.MVTesting);
        }

        // Set disabled module info
        ucDisabledModule.SettingsKeys = "CMSAnalyticsEnabled;CMSMVTEnabled";
        ucDisabledModule.ParentPanel  = pnlWarning;

        // Register actions
        ComponentEvents.RequestEvents.RegisterForEvent(ComponentEvents.SAVE, (s, args) => Save());

        mUcDisplayReport = (IDisplayReport)LoadUserControl("~/CMSModules/Reporting/Controls/DisplayReport.ascx");
        pnlContent.Controls.Add((Control)mUcDisplayReport);

        CurrentMaster.PanelContent.CssClass = String.Empty;
        UIHelper.AllowUpdateProgress        = false;

        // MVTest Info
        int        mvTestID = QueryHelper.GetInteger("objectID", 0);
        MVTestInfo mvInfo   = MVTestInfoProvider.GetMVTestInfo(mvTestID);

        if (mvInfo == null)
        {
            return;
        }

        // Load combination by current template ID and culture
        int nodeID = QueryHelper.GetInteger("NodeID", 0);

        if (nodeID > 0)
        {
            // Create condition for current template combinations
            TreeProvider tree = new TreeProvider(cui);
            TreeNode     node = tree.SelectSingleNode(nodeID, LocalizationContext.PreferredCultureCode);

            if (node != null)
            {
                usCombination.DocumentID     = node.DocumentID;
                usCombination.PageTemplateID = node.GetUsedPageTemplateId();
            }
        }
        else
        {
            rbCombinations.Visible = false;
        }

        usCombination.ReloadData(true);

        mTestName = mvInfo.MVTestName;

        ucGraphType.ProcessChartSelectors(false);

        // Enables/disables radio buttons (based on UI elements)
        var ui = MembershipContext.AuthenticatedUser;

        if (!RequestHelper.IsPostBack())
        {
            if (!ui.IsGlobalAdministrator)
            {
                bool checkedButton = false;

                // Check first enabled button
                foreach (Control ctrl in pnlRadioButtons.Controls)
                {
                    CMSRadioButton rb = ctrl as CMSRadioButton;
                    if (rb != null)
                    {
                        if (rb.Enabled)
                        {
                            rb.Checked    = true;
                            checkedButton = true;
                            break;
                        }
                    }
                }

                // No report avaible -> redirect to access denied
                if (!checkedButton)
                {
                    RedirectToAccessDenied(GetString("mvtest.noreportavaible"));
                }
            }
            else
            {
                // Admin check first radio button
                rbCount.Checked = true;
            }
        }
    }
    /// <summary>
    // Processes the form - saves the data.
    /// </summary>
    private void Process()
    {
        if (CheckPermissions("CMS.MVTest", PERMISSION_MANAGE))
        {
            // Validate the form
            if (Validate())
            {
                // Ensure the info object
                if (MvtestObj == null)
                {
                    MvtestObj = new MVTestInfo();
                    MvtestObj.MVTestSiteID = siteId;
                    MvtestObj.MVTestPage = AliasPath;
                }

                // Initialize object
                String newCodeName = txtMVTestCodeName.Text.Trim();
                MvtestObj.MVTestDisplayName = txtMVTestDisplayName.Text.Trim();
                MvtestObj.MVTestDescription = txtMVTestDescription.Text;
                MvtestObj.OriginalCulture = MvtestObj.MVTestCulture;
                MvtestObj.MVTestCulture = ucCultureSelector.Value.ToString();
                MvtestObj.MVTestMaxConversions = ValidationHelper.GetInteger(txtMVTestMaxConversions.Text, 0);
                MvtestObj.MVTestOpenFrom = dtpMVTestOpenFrom.SelectedDateTime;
                MvtestObj.MVTestOpenTo = dtpMVTestOpenTo.SelectedDateTime;
                MvtestObj.MVTestEnabled = chkMVTestEnabled.Checked;

                // Name has changed. Change analytics statistics data for existing object
                if ((MvtestObj.MVTestID != 0) && (MvtestObj.MVTestName != newCodeName))
                {
                    MVTestInfoProvider.RenameMVTestStatistics(MvtestObj.MVTestName, newCodeName, CMSContext.CurrentSiteID);
                }
                MvtestObj.MVTestName = newCodeName;

                if (radTotal.Checked)
                {
                    MvtestObj.MVTestTargetConversionType = MVTTargetConversionTypeEnum.Total;
                }
                else if (radAnyVariant.Checked)
                {
                    MvtestObj.MVTestTargetConversionType = MVTTargetConversionTypeEnum.AnyCombination;
                }

                if (ShowAliasPath)
                {
                    MvtestObj.MVTestPage = ucPath.Value.ToString().Trim();
                }

                // Save object data to database
                MVTestInfoProvider.SetMVTestInfo(MvtestObj);

                ItemID = MvtestObj.MVTestID;
                RaiseOnSaved();

                // Set the info message
                ShowChangesSaved();
            }
        }
    }