Пример #1
0
    /// <summary>
    /// Creates new AB variant if AB test filled in.
    /// </summary>
    /// <param name="newDocument">Newly created document</param>
    /// <returns>True if new variant is successfully created or if AB test is not defined.</returns>
    private bool CreateABVariant(TreeNode newDocument)
    {
        // If ABTest selected - create new variant
        int abTestID = ValidationHelper.GetInteger(ucABTestSelector.Value, 0);

        if (abTestID <= 0)
        {
            return(true);
        }

        // If no test found, handle it as no test was specified
        ABTestInfo abTest = ABTestInfoProvider.GetABTestInfo(abTestID);

        if (abTest == null)
        {
            return(true);
        }

        string        defaultCodeName = TextHelper.LimitLength(ValidationHelper.GetCodeName(newDocument.NodeAlias), 45, String.Empty);
        string        codeName        = defaultCodeName;
        ABVariantInfo info            = ABVariantInfoProvider.GetABVariantInfo(codeName, abTest.ABTestName, SiteContext.CurrentSiteName);

        // Find non existing variant code name
        int index = 0;

        while (info != null)
        {
            index++;
            codeName = defaultCodeName + "-" + index;
            info     = ABVariantInfoProvider.GetABVariantInfo(codeName, abTest.ABTestName, SiteContext.CurrentSiteName);
        }

        // Save AB Variant
        ABVariantInfo variantInfo = new ABVariantInfo();

        variantInfo.ABVariantTestID      = abTestID;
        variantInfo.ABVariantPath        = newDocument.NodeAliasPath;
        variantInfo.ABVariantName        = codeName;
        variantInfo.ABVariantDisplayName = newDocument.NodeAlias;
        variantInfo.ABVariantSiteID      = SiteContext.CurrentSiteID;

        try
        {
            ABVariantInfoProvider.SetABVariantInfo(variantInfo);
        }
        catch (InfoObjectException ex)
        {
            newDocument.Delete(true, true);
            ShowError(ex.Message);
            return(false);
        }
        return(true);
    }
Пример #2
0
    /// <summary>
    /// Handles Unigrid's OnExternalDataBound event.
    /// </summary>
    protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLower())
        {
        case "abteststatus":
            int        testID   = ValidationHelper.GetInteger(parameter, 0);
            ABTestInfo testInfo = ABTestInfoProvider.GetABTestInfo(testID);
            if (testInfo != null)
            {
                if (!testInfo.ABTestEnabled)
                {
                    return("<span class=\"StatusDisabled\">" + GetString("general.disabled") + "</span>");
                }
                else
                {
                    string status = string.Empty;

                    if (ABTestInfoProvider.ABTestIsRunning(testInfo))
                    {
                        // Display disabled information
                        if (!webAnalyticsEnabled)
                        {
                            return(GetString("abtesting.statusNone"));
                        }

                        if (!ABTestInfoProvider.ContainsVariants(testInfo))
                        {
                            // Display warning when the test does not contain any variant
                            return("<img src=\"" + GetImageUrl("Design/Controls/UniGrid/Actions/Warning.png") + "\" alt=\"" + GetString("abtest.novariants") + "\" title=\""
                                   + GetString("abtest.novariants") + "\" />&nbsp;&nbsp;"
                                   + GetString("abtesting.status" + ABTestStatusEnum.None));
                        }

                        status += "<span class=\"StatusEnabled\">" + GetString("abtesting.status" + ABTestInfoProvider.GetABTestStatus(testInfo)) + "</span>";
                    }
                    else
                    {
                        status += GetString("abtesting.status" + ABTestInfoProvider.GetABTestStatus(testInfo));
                    }

                    return(status);
                }
            }

            return(string.Empty);
        }

        return(parameter);
    }
Пример #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int abTestId = QueryHelper.GetInteger("abTestId", 0);
        int nodeID   = QueryHelper.GetInteger("nodeid", 0);

        ABTestInfo abTest = ABTestInfoProvider.GetABTestInfo(abTestId);

        if (abTest != null)
        {
            // Prepare the tabs
            string[,] tabs = new string[3, 4];
            tabs[0, 0]     = GetString("general.general");
            tabs[0, 1]     = "SetHelpTopic('helpTopic', 'abtest_general');";
            tabs[0, 2]     = "Tab_General.aspx?abTestId=" + abTestId + "&nodeid=" + nodeID;

            tabs[1, 0] = GetString("abtesting.variant.list");
            tabs[1, 1] = "SetHelpTopic('helpTopic', 'abtest_variants');";
            tabs[1, 2] = ResolveUrl("~/CMSModules/OnlineMarketing/Pages/Content/ABTesting/ABVariant/List.aspx?abTestId=" + abTestId + "&nodeid=" + nodeID);

            tabs[2, 0] = GetString("general.reports");
            tabs[2, 1] = "SetHelpTopic('helpTopic', 'abtest_reports');";
            tabs[2, 2] = "abtestreports.aspx?abtestid=" + abTestId;

            // Prepare the breadcrumbs
            string[,] breadcrumbs = new string[2, 3];
            breadcrumbs[0, 0]     = GetString("abtesting.abtest.list");
            breadcrumbs[0, 1]     = "~/CMSModules/OnlineMarketing/Pages/Content/ABTesting/ABTest/List.aspx?nodeid=" + nodeID;
            breadcrumbs[0, 2]     = "_parent";
            breadcrumbs[1, 0]     = HTMLHelper.HTMLEncode(abTest.ABTestDisplayName.ToString());

            // Set the tabs
            ICMSMasterPage master = CurrentMaster;
            master.Tabs.Tabs      = tabs;
            master.Tabs.UrlTarget = "content";

            // Set the title
            PageTitle title = CurrentMaster.Title;
            title.Breadcrumbs   = breadcrumbs;
            title.HelpTopicName = "abtest_general";
            title.HelpName      = "helpTopic";
        }
    }
Пример #4
0
    /// <summary>
    /// Handles Unigrid's OnExternalDataBound event.
    /// </summary>
    protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        string param = parameter.ToString();

        switch (sourceName.ToLowerCSafe())
        {
        case "status":
        {
            ABTestStatusEnum status;
            if (Enum.TryParse(param, out status))
            {
                return(ABTestStatusEvaluator.GetFormattedStatus(status));
            }
            break;
        }

        case "page":
            return(new HyperLink
            {
                NavigateUrl = DocumentURLProvider.GetUrl(param),
                Text = HTMLHelper.HTMLEncode(param),
                Target = "_blank"
            });

        case "visitors":
        case "conversions":
        {
            string statisticsCodeName = (sourceName.ToLowerCSafe() == "visitors" ? "abvisitfirst" : "absessionconversionfirst");

            ABTestInfo abTestInfo = ABTestInfoProvider.GetABTestInfo(param, SiteContext.CurrentSiteName);
            if (abTestInfo != null)
            {
                return(ValidationHelper.GetInteger(HitsInfoProvider.GetAllHitsInfo(SiteContext.CurrentSiteID, HitsIntervalEnum.Year, statisticsCodeName + ";" + abTestInfo.ABTestName + ";%", "SUM(HitsCount)", abTestInfo.ABTestCulture).Tables[0].Rows[0][0], 0));
            }

            return(0);
        }
        }

        return(null);
    }
Пример #5
0
    /// <summary>
    /// Validates the form. If validation succeeds returns true, otherwise returns false.
    /// </summary>
    private bool Validate()
    {
        // Validate required fields
        string errorMessage = new Validator()
                              .NotEmpty(txtABVariantDisplayName.Text.Trim(), rfvABVariantDisplayName.ErrorMessage)
                              .NotEmpty(txtABVariantName.Text.Trim(), rfvABVariantName.ErrorMessage)
                              .IsCodeName(txtABVariantName.Text.Trim(), GetString("general.invalidcodename")).Result;

        string abTestName = string.Empty;
        string siteName   = CMSContext.CurrentSiteName;

        // Get AB test info object
        ABTestInfo abti = ABTestInfoProvider.GetABTestInfo(TestID);

        if (abti != null)
        {
            abTestName = abti.ABTestName;
        }

        // Test unique codename
        ABVariantInfo info = ABVariantInfoProvider.GetABVariantInfo(txtABVariantName.Text.Trim(), abTestName, siteName);

        if ((info != null) && ((VariantObj == null) || (info.ABVariantID != VariantObj.ABVariantID)))
        {
            errorMessage = GetString("general.codenameexists");
        }

        if (String.IsNullOrEmpty(ucPath.Value.ToString()))
        {
            errorMessage = GetString("abtesting.entertestpage");
        }

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

        return(true);
    }
Пример #6
0
    /// <summary>
    /// Creates document.
    /// </summary>
    /// <param name="createAnother">If false user will be redirected to created document</param>
    public int Save(bool createAnother)
    {
        // Validate input data
        string message = new Validator().NotEmpty(txtDocumentName.Text.Trim(), GetString("om.enterdocumentname")).Result;

        if (message == String.Empty)
        {
            if (node != null)
            {
                // Select parent node
                TreeNode parent = tree.SelectSingleNode(CMSContext.CurrentSiteName, ucPath.Value.ToString(), TreeProvider.ALL_CULTURES, false, null, false);
                if (parent != null)
                {
                    // Check security
                    if (!CMSContext.CurrentUser.IsAuthorizedToCreateNewDocument(parent.NodeID, node.NodeClassName))
                    {
                        RedirectToAccessDenied(GetString("cmsdesk.notauthorizedtocreatedocument"));
                        return(0);
                    }
                    TreeNode newNode = ProcessAction(node, parent, "copynode", false, true, true);

                    if (newNode != null)
                    {
                        newNode.SetValue("DocumentMenuItemHideInNavigation", !chkShowInNavigation.Checked);
                        newNode.SetValue("DocumentShowInSiteMap", chkShowInSiteMap.Checked);
                        newNode.SetValue("DocumentSearchExcluded", chkExcludeFromSearch.Checked);
                        // Limit length to 100 characters
                        string nodeAlias = TextHelper.LimitLength(txtDocumentName.Text.Trim(), 100, String.Empty);
                        newNode.NodeAlias    = nodeAlias;
                        newNode.DocumentName = nodeAlias;

                        // Update menu item name
                        newNode.SetDocumentNameSource(nodeAlias);

                        newNode.Update();

                        // If ABTest selected - create new variant
                        int abTestID = ValidationHelper.GetInteger(ucABTestSelector.Value, 0);
                        if (abTestID != 0)
                        {
                            ABTestInfo abTest = ABTestInfoProvider.GetABTestInfo(abTestID);
                            if (abTest != null)
                            {
                                string        defaultCodeName = TextHelper.LimitLength(ValidationHelper.GetCodeName(newNode.GetDocumentName()), 45, String.Empty);
                                string        codeName        = defaultCodeName;
                                ABVariantInfo info            = ABVariantInfoProvider.GetABVariantInfo(codeName, abTest.ABTestName, CMSContext.CurrentSiteName);

                                // Find non existing variant code name
                                int index = 0;
                                while (info != null)
                                {
                                    index++;
                                    codeName = defaultCodeName + "-" + index;
                                    info     = ABVariantInfoProvider.GetABVariantInfo(codeName, abTest.ABTestName, CMSContext.CurrentSiteName);
                                }

                                // Save AB Variant
                                ABVariantInfo variantInfo = new ABVariantInfo();
                                variantInfo.ABVariantTestID      = abTestID;
                                variantInfo.ABVariantPath        = newNode.NodeAliasPath;
                                variantInfo.ABVariantName        = codeName;
                                variantInfo.ABVariantDisplayName = newNode.GetDocumentName();
                                variantInfo.ABVariantSiteID      = CMSContext.CurrentSiteID;

                                ABVariantInfoProvider.SetABVariantInfo(variantInfo);
                            }
                        }

                        // Get the page mode
                        if (CMSContext.ViewMode != ViewModeEnum.EditLive)
                        {
                            CMSContext.ViewMode = ViewModeEnum.EditForm;
                        }

                        txtDocumentName.Text = String.Empty;
                        return(newNode.NodeID);
                    }
                }
                else
                {
                    message = GetString("om.pathdoesnotexists");
                }
            }
        }

        if (message != String.Empty)
        {
            lblError.Visible = true;
            lblError.Text    = message;
        }
        return(0);
    }
Пример #7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ucDisplayReport = this.LoadUserControl("~/CMSModules/Reporting/Controls/DisplayReport.ascx") as IDisplayReport;
        reportHeader.ActionPerformed += HeaderActions_ActionPerformed;
        pnlContent.Controls.Add((Control)ucDisplayReport);

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

        CurrentMaster.PanelContent.CssClass = "";

        UIHelper.AllowUpdateProgress = false;

        // ABTest Info
        int        abTestID = QueryHelper.GetInteger("abtestid", 0);
        ABTestInfo abInfo   = ABTestInfoProvider.GetABTestInfo(abTestID);

        if (abInfo == null)
        {
            return;
        }

        siteName = CMSContext.CurrentSiteName;
        testName = abInfo.ABTestName;

        // Variants condition
        ucSelectVariation.WhereCondition = "ABVariantTestID  IN ( SELECT ABTestID FROM OM_ABTest WHERE ABTestName = N'" + testName + "')";
        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", "ABTest.ConversionsCount");
                rbRate.Enabled        = ui.IsAuthorizedPerUIElement("cms.WebAnalytics", "ABTest.ConversionsRate");
                rbValue.Enabled       = ui.IsAuthorizedPerUIElement("cms.WebAnalytics", "ABTest.ConversionsValue");
                rbSourcePages.Enabled = ui.IsAuthorizedPerUIElement("cms.WebAnalytics", "ABTest.ConversionsSourcePages");
                rbVariants.Enabled    = ui.IsAuthorizedPerUIElement("cms.WebAnalytics", "ABTest.ConversionsByVariations");

                bool checkedButton = false;

                // Check first enabled button
                foreach (Control ctrl in pnlRadios.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("abtest.noreportavaible"));
                }
            }
            else
            {
                // Admin check first radio button
                rbCount.Checked = true;
            }
        }
    }
Пример #8
0
    /// <summary>
    /// Validates the form. If validation succeeds returns true, otherwise returns false.
    /// </summary>
    private bool Validate()
    {
        string codename = this.txtABTestName.Text.Trim();

        // Validate required fields
        string errorMessage = new Validator()
                              .NotEmpty(txtABTestDisplayName.Text.Trim(), this.rfvABTestDisplayName.ErrorMessage)
                              .NotEmpty(codename, this.rfvABTestName.ErrorMessage)
                              .IsCodeName(codename, GetString("general.invalidcodename")).Result;

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

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

        string maxConversions = txtABTestMaxConversions.Text.Trim();

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

        // Check the uniqueness of the codename
        ABTestInfo info = ABTestInfoProvider.GetABTestInfo(txtABTestName.Text.Trim(), CMSContext.CurrentSiteName);

        if ((info != null) && ((this.AbTestObj == null) || (info.ABTestID != this.AbTestObj.ABTestID)))
        {
            errorMessage = GetString("general.codenameexists");
        }

        if (String.IsNullOrEmpty(ucPath.Value.ToString()) && (AliasPath == String.Empty))
        {
            errorMessage = GetString("abtesting.enteroriginalpage");
        }

        // Test if there is no enabled test for same page
        if (chkABTestEnabled.Checked && TestToValidate())
        {
            QueryDataParameters parameters = null;
            string testPage = ((AliasPath != String.Empty) && !ShowAliasPath) ? AliasPath : ucPath.Value.ToString();
            string where = ABTestInfoProvider.GetRunningCondition(ABTestID, testPage, CMSContext.CurrentSiteID, ucCultureSelector.Value.ToString(), dtpABTestOpenFrom.SelectedDateTime, dtpABTestOpenTo.SelectedDateTime, out parameters);
            DataSet ds = ABTestInfoProvider.GetABTests(where, null, -1, null, parameters);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                errorMessage = GetString("om.twotestsonepageerror");
            }
        }

        // Set the error message
        if (!String.IsNullOrEmpty(errorMessage))
        {
            this.lblError.Text = errorMessage;
            return(false);
        }

        return(true);
    }
Пример #9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ucDisplayReport = LoadControl("~/CMSModules/Reporting/Controls/DisplayReport.ascx") as IDisplayReport;
        pnlContent.Controls.Add((Control)ucDisplayReport);

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

        // ABTest Info
        int        abTestID = QueryHelper.GetInteger("abtestid", 0);
        ABTestInfo abInfo   = ABTestInfoProvider.GetABTestInfo(abTestID);

        if (abInfo == null)
        {
            return;
        }

        String siteName = CMSContext.CurrentSiteName;

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

        if (!ABTestInfoProvider.ABTestingEnabled(siteName))
        {
            this.pnlWarning.Visible = true;
            this.lblABWarning.Text  = GetString("abtesting.disabled");
        }

        testName = abInfo.ABTestName;

        // Variants condition
        ucSelectVariation.WhereCondition = "ABVariantTestID  IN ( SELECT ABTestID FROM OM_ABTest WHERE ABTestName = N'" + testName + "')";

        // 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=abconversion;" + 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", "ABTest.ConversionsCount");
                rbRate.Enabled        = ui.IsAuthorizedPerUIElement("cms.WebAnalytics", "ABTest.ConversionsRate");
                rbValue.Enabled       = ui.IsAuthorizedPerUIElement("cms.WebAnalytics", "ABTest.ConversionsValue");
                rbSourcePages.Enabled = ui.IsAuthorizedPerUIElement("cms.WebAnalytics", "ABTest.ConversionsSourcePages");
                rbVariants.Enabled    = ui.IsAuthorizedPerUIElement("cms.WebAnalytics", "ABTest.ConversionsByVariations");

                bool checkedButton = false;

                // Check first enabled button
                foreach (Control ctrl in pnlRadios.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("abtest.noreportavaible"));
                }
            }
            else
            {
                // Admin check first radio button
                rbCount.Checked = true;
            }
        }
    }