Beispiel #1
0
    /// <summary>
    /// Ensures dialog breadcrumbs
    /// </summary>
    /// <param name="node">Current node</param>
    private void EnsureBreadcrumbs(TreeNode node)
    {
        if (node == null)
        {
            return;
        }

        PageTitle.HideBreadcrumbs = false;

        // Loop thru all levels and generate breadcrumbs
        for (int i = node.NodeLevel; i >= 0; i--)
        {
            if (node == null)
            {
                continue;
            }

            PageBreadcrumbs.Items.Add(new BreadcrumbItem
            {
                Text          = node.GetDocumentName(),
                Index         = i,
                RedirectUrl   = "#",
                OnClientClick = "SelectItem(" + node.NodeID + "); return false;"
            });

            node = node.Parent;
        }

        // Add additional css class for correct design
        CurrentMaster.PanelHeader.CssClass += " SimpleHeader";
    }
Beispiel #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Display separator
        AbstractMasterPage mPage = CurrentMaster as AbstractMasterPage;

        if (mPage != null)
        {
            mPage.DisplaySeparatorPanel = true;
        }

        // Add the document name to the properties header title
        TreeNode node = DocumentManager.Node;

        if (node != null)
        {
            string nodeName = node.GetDocumentName();
            // Get name for root document
            if (node.IsRoot())
            {
                nodeName = SiteContext.CurrentSite.DisplayName;
            }

            PageTitle.TitleText += " \"" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(nodeName)) + "\"";
        }
    }
Beispiel #3
0
    /// <summary>
    /// Logs "insert" activity
    /// </summary>
    /// <param name="node">Node</param>
    private void LogInsertActivity(TreeNode node)
    {
        if ((node == null) || !LogActivity)
        {
            return;
        }
        Activity activity = new ActivityUserContributionInsert(node, node.GetDocumentName(), AnalyticsContext.ActivityEnvironmentVariables);

        activity.Log();
    }
Beispiel #4
0
    /// <summary>
    /// Logs "delete" activity
    /// </summary>
    /// <param name="node">Node to log the activity for</param>
    private void LogDeleteActivity(TreeNode node)
    {
        if ((node == null) || !LogActivity)
        {
            return;
        }

        Activity activity = new ActivityUserContributionDelete(node, node.GetDocumentName(), CMSContext.ActivityEnvironmentVariables);

        activity.Log();
    }
    /// <summary>
    /// Logs activity.
    /// </summary>
    /// <param name="bpsi">Blog subscription info</param>
    private void LogActivity(BlogPostSubscriptionInfo bpsi)
    {
        if ((bpsi != null) && (bpsi.SubscriptionPostDocumentID > 0))
        {
            TreeNode blogPost = DocumentHelper.GetDocument(bpsi.SubscriptionPostDocumentID, new TreeProvider());
            TreeNode blogNode = BlogHelper.GetParentBlog(bpsi.SubscriptionPostDocumentID, false);
            string   blogName = (blogNode != null) ? blogNode.GetDocumentName() : null;

            Activity activity = new ActivitySubscriptionBlogPost(blogName, blogNode, blogPost, bpsi, CMSContext.ActivityEnvironmentVariables);
            activity.Log();
        }
    }
    /// <summary>
    /// Initializes the master page elements.
    /// </summary>
    private void InitializeMasterPage()
    {
        HeaderActions hdrActions = CurrentMaster.HeaderActions;

        string url = "~/CMSModules/Ecommerce/Pages/Tools/Products/Product_New.aspx";

        url = URLHelper.AddParameterToUrl(url, "siteId", SiteContext.CurrentSiteID.ToString());
        url = URLHelper.AddParameterToUrl(url, "parentNodeId", NodeID.ToString());

        if (NodeID <= 0)
        {
            // Add "New product" action when tree is not visible (it has own 'New' action)
            if (!DisplayTreeInProducts)
            {
                hdrActions.ActionsList.Add(new HeaderAction
                {
                    Text        = GetString("com.sku.newsku"),
                    RedirectUrl = url
                });
            }
        }
        else
        {
            TreeNode currentNode = docList.Node;

            // Setup the link to the parent document
            if ((currentNode != null) && (currentNode.NodeClassName.ToLowerCSafe() != "cms.root") && (currentNode.NodeAliasPath.CompareToCSafe(ProductsStartingPath, true) != 0))
            {
                string actionUrl = ShowSections ? "javascript:SelectItem(" + currentNode.NodeParentID + ");" : "javascript:EditItem(" + currentNode.NodeParentID + ");";
                hdrActions.ActionsList.Add(new HeaderAction
                {
                    Text        = GetString("com.ParentSection"),
                    RedirectUrl = actionUrl,
                    ButtonStyle = ButtonStyle.Default
                });
            }

            // Display the "Edit section" action when section selected
            if ((currentNode != null) && (currentNode.NodeAliasPath != "/"))
            {
                hdrActions.ActionsList.Add(new HeaderAction
                {
                    Text          = GetString("com.productsection.editthis"),
                    RedirectUrl   = "#",
                    OnClientClick = "parent.SetMode('sectionedit'); return false;",
                    ButtonStyle   = ButtonStyle.Default
                });

                EnsureProductBreadcrumbs(PageBreadcrumbs, currentNode.GetDocumentName(), true);
            }
        }
    }
Beispiel #7
0
    /// <summary>
    /// Gets document name of specified node id.
    /// </summary>
    public static string GetDocumentName(object nodeIdent)
    {
        int nodeId = ValidationHelper.GetInteger(nodeIdent, 0);

        if (nodeId != 0)
        {
            TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
            TreeNode     node = tree.SelectSingleNode(nodeId, CMSContext.PreferredCultureCode);
            if (node != null)
            {
                return(node.GetDocumentName());
            }
        }
        return(String.Empty);
    }
    /// <summary>
    /// Creates or rebuild department content search index.
    /// </summary>
    /// <param name="departmentNode">Department node</param>
    private void CreateDepartmentContentSearchIndex(TreeNode departmentNode)
    {
        string codeName       = "default_department_" + departmentNode.NodeGUID;
        string departmentName = departmentNode.GetDocumentName();

        SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(codeName);

        if (sii == null)
        {
            // Create search index info
            sii           = new SearchIndexInfo();
            sii.IndexName = codeName;
            string suffix = " - Default";
            sii.IndexDisplayName      = TextHelper.LimitLength(departmentName, 200 - suffix.Length, "") + suffix;
            sii.IndexAnalyzerType     = SearchAnalyzerTypeEnum.StandardAnalyzer;
            sii.IndexType             = TreeNode.OBJECT_TYPE;
            sii.IndexIsCommunityGroup = false;
            sii.IndexProvider         = SearchIndexInfo.LUCENE_SEARCH_PROVIDER;

            // Create search index settings info
            SearchIndexSettingsInfo sisi = new SearchIndexSettingsInfo();
            sisi.ID         = Guid.NewGuid();
            sisi.Path       = departmentNode.NodeAliasPath + "/%";
            sisi.Type       = SearchIndexSettingsInfo.TYPE_ALLOWED;
            sisi.ClassNames = "";

            // Create settings item
            SearchIndexSettings sis = new SearchIndexSettings();

            // Update settings item
            sis.SetSearchIndexSettingsInfo(sisi);

            // Update xml value
            sii.IndexSettings = sis;
            SearchIndexInfoProvider.SetSearchIndexInfo(sii);

            // Assign to current website
            SearchIndexSiteInfoProvider.AddSearchIndexToSite(sii.IndexID, SiteContext.CurrentSiteID);
        }

        // Add current culture to search index
        CultureInfo ci = CultureInfoProvider.GetCultureInfo(departmentNode.DocumentCulture);

        SearchIndexCultureInfoProvider.AddSearchIndexCulture(sii.IndexID, ci.CultureID);

        // Rebuild search index
        SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, null, null, sii.IndexName, sii.IndexID);
    }
    /// <summary>
    /// Creates department media library.
    /// </summary>
    /// <param name="departmentNode">Department node</param>
    private void CreateDepartmentMediaLibrary(TreeNode departmentNode)
    {
        // Set general values
        string departmentName = departmentNode.GetDocumentName();
        string codeName       = "Department_" + departmentNode.NodeGUID;
        string suffix         = "";

        // Check if library with same name already exists
        MediaLibraryInfo mlInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo(codeName, CMSContext.CurrentSiteName);

        if (mlInfo != null)
        {
            return;
        }

        // Create new object (record) if needed
        mlInfo = new MediaLibraryInfo();

        suffix = " media library";
        mlInfo.LibraryDisplayName = TextHelper.LimitLength(departmentName, 200 - suffix.Length, "") + suffix;
        mlInfo.LibraryFolder      = departmentNode.NodeAlias;
        mlInfo.LibraryDescription = "Media library for " + departmentName + " department.";
        mlInfo.LibraryName        = codeName;
        mlInfo.LibrarySiteID      = CMSContext.CurrentSiteID;

        // Set security
        mlInfo.FileCreate   = SecurityAccessEnum.AuthorizedRoles;
        mlInfo.FileDelete   = SecurityAccessEnum.AuthorizedRoles;
        mlInfo.FileModify   = SecurityAccessEnum.AuthorizedRoles;
        mlInfo.FolderCreate = SecurityAccessEnum.AuthorizedRoles;
        mlInfo.FolderDelete = SecurityAccessEnum.AuthorizedRoles;
        mlInfo.FolderModify = SecurityAccessEnum.AuthorizedRoles;
        mlInfo.Access       = SecurityAccessEnum.AuthorizedRoles;

        try
        {
            MediaLibraryInfoProvider.SetMediaLibraryInfo(mlInfo);
        }
        catch
        {
            return;
        }

        // Create additional folders
        //MediaLibraryInfoProvider.CreateMediaLibraryFolder(CMSContext.CurrentSiteName, mlInfo.LibraryID, "Videos", false);
        //MediaLibraryInfoProvider.CreateMediaLibraryFolder(CMSContext.CurrentSiteName, mlInfo.LibraryID, "Other", false);
        //MediaLibraryInfoProvider.CreateMediaLibraryFolder(CMSContext.CurrentSiteName, mlInfo.LibraryID, "Photos & Images", false);
    }
    /// <summary>
    /// Creates forum search index.
    /// </summary>
    /// <param name="departmentNode">Department node</param>
    private void CreateDepartmentForumSearchIndex(TreeNode departmentNode)
    {
        string codeName       = "forums_department_" + departmentNode.NodeGUID;
        string departmentName = departmentNode.GetDocumentName();

        SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(codeName);

        if (sii == null)
        {
            // Create search index info
            sii           = new SearchIndexInfo();
            sii.IndexName = codeName;
            string suffix = " - Forums";
            sii.IndexDisplayName      = TextHelper.LimitLength(departmentName, 200 - suffix.Length, "") + suffix;
            sii.IndexAnalyzerType     = SearchAnalyzerTypeEnum.StandardAnalyzer;
            sii.IndexType             = PredefinedObjectType.FORUM;
            sii.IndexIsCommunityGroup = false;
            sii.IndexProvider         = SearchIndexInfo.LUCENE_SEARCH_PROVIDER;

            // Create search index settings info
            SearchIndexSettingsInfo sisi = new SearchIndexSettingsInfo();
            sisi.ID         = Guid.NewGuid();
            sisi.Type       = SearchIndexSettingsInfo.TYPE_ALLOWED;
            sisi.SiteName   = SiteContext.CurrentSiteName;
            sisi.ForumNames = "*_department_" + departmentNode.NodeGUID;

            // Create settings item
            SearchIndexSettings sis = new SearchIndexSettings();

            // Update settings item
            sis.SetSearchIndexSettingsInfo(sisi);

            // Update xml value
            sii.IndexSettings = sis;
            SearchIndexInfoProvider.SetSearchIndexInfo(sii);

            // Assign to current website and current culture
            SearchIndexSiteInfoProvider.AddSearchIndexToSite(sii.IndexID, SiteContext.CurrentSiteID);
            CultureInfo ci = CultureInfoProvider.GetCultureInfo(departmentNode.DocumentCulture);
            SearchIndexCultureInfoProvider.AddSearchIndexCulture(sii.IndexID, ci.CultureID);
        }
    }
Beispiel #11
0
    /// <summary>
    /// Ensures dialog breadcrumbs
    /// </summary>
    /// <param name="node">Current node</param>
    private void EnsureBreadcrumbs(TreeNode node)
    {
        if (node != null)
        {
            // Loop thru all levels and generate breadcrumbs
            int parentNodeId = 0;

            PageTitle.HideBreadcrumbs = false;

            for (int i = node.NodeLevel; i >= 0; i--)
            {
                if (node == null)
                {
                    // Document is not translated in the current culture -> get parent node from the default culture
                    TreeProvider treeProvider = new TreeProvider();
                    TreeNode     parentNode   = DocumentHelper.GetDocument(parentNodeId, CultureCode, true, treeProvider);
                    node = parentNode;
                }

                if (node != null)
                {
                    PageBreadcrumbs.Items.Add(new BreadcrumbItem
                    {
                        Text          = node.GetDocumentName(),
                        Index         = i,
                        RedirectUrl   = "#",
                        OnClientClick = "SelectItem(" + node.NodeID + "); return false;"
                    });

                    parentNodeId = node.NodeParentID;
                    node         = node.Parent;
                }
            }

            // Add additional css class for correct design
            CurrentMaster.PanelHeader.CssClass += " SimpleHeader";
        }
    }
    /// <summary>
    /// Creates department forum group.
    /// </summary>
    /// <param name="departmentNode">Department node</param>
    private void CreateDepartmentForumGroup(TreeNode departmentNode)
    {
        // Set general values
        string departmentName = departmentNode.GetDocumentName();
        string suffix         = "";


        #region "Create forum group"

        // Get forum group code name
        string groupCodeName = "Department_" + departmentNode.NodeGUID;

        // Check if forum group with given name already exists
        if (ForumGroupInfoProvider.GetForumGroupInfo(groupCodeName, SiteContext.CurrentSiteID) != null)
        {
            return;
        }

        // Create base URL for forums
        string baseUrl = DocumentURLProvider.GetUrl(departmentNode.NodeAliasPath + "/" + FORUM_DOCUMENT_ALIAS);

        ForumGroupInfo forumGroupObj = new ForumGroupInfo();
        forumGroupObj.GroupDescription = "Forum group for " + departmentName + " department.";
        suffix = " forum group";
        forumGroupObj.GroupDisplayName = TextHelper.LimitLength(departmentName, 200 - suffix.Length, "") + suffix;
        forumGroupObj.GroupName        = groupCodeName;
        forumGroupObj.GroupOrder       = 0;
        forumGroupObj.GroupEnableQuote = true;
        forumGroupObj.GroupSiteID      = SiteContext.CurrentSiteID;
        forumGroupObj.GroupBaseUrl     = baseUrl;

        // Additional settings
        forumGroupObj.GroupEnableCodeSnippet   = true;
        forumGroupObj.GroupEnableFontBold      = true;
        forumGroupObj.GroupEnableFontColor     = true;
        forumGroupObj.GroupEnableFontItalics   = true;
        forumGroupObj.GroupEnableFontStrike    = true;
        forumGroupObj.GroupEnableFontUnderline = true;
        forumGroupObj.GroupEnableQuote         = true;
        forumGroupObj.GroupEnableURL           = true;
        forumGroupObj.GroupEnableImage         = true;

        ForumGroupInfoProvider.SetForumGroupInfo(forumGroupObj);

        #endregion


        #region "Create forum"

        string codeName = "Default_department_" + departmentNode.NodeGUID;

        // Check if forum with given name already exists
        if (ForumInfoProvider.GetForumInfo(codeName, SiteContext.CurrentSite.SiteID) != null)
        {
            return;
        }

        ForumInfo forumObj = new ForumInfo();
        forumObj.ForumSiteID        = SiteContext.CurrentSiteID;
        forumObj.ForumIsLocked      = false;
        forumObj.ForumOpen          = true;
        forumObj.ForumDisplayEmails = false;
        forumObj.ForumDescription   = "Forum for " + departmentName + " department.";
        forumObj.ForumRequireEmail  = false;
        suffix = " forum";
        forumObj.ForumDisplayName     = TextHelper.LimitLength(departmentName, 200 - suffix.Length, "") + suffix;
        forumObj.ForumName            = codeName;
        forumObj.ForumGroupID         = forumGroupObj.GroupID;
        forumObj.ForumModerated       = false;
        forumObj.ForumAccess          = 40000;
        forumObj.ForumPosts           = 0;
        forumObj.ForumThreads         = 0;
        forumObj.ForumPostsAbsolute   = 0;
        forumObj.ForumThreadsAbsolute = 0;
        forumObj.ForumOrder           = 0;
        forumObj.ForumUseCAPTCHA      = false;
        forumObj.SetValue("ForumHTMLEditor", null);

        // Set security
        forumObj.AllowAccess       = SecurityAccessEnum.AuthorizedRoles;
        forumObj.AllowAttachFiles  = SecurityAccessEnum.AuthorizedRoles;
        forumObj.AllowMarkAsAnswer = SecurityAccessEnum.AuthorizedRoles;
        forumObj.AllowPost         = SecurityAccessEnum.AuthorizedRoles;
        forumObj.AllowReply        = SecurityAccessEnum.AuthorizedRoles;
        forumObj.AllowSubscribe    = SecurityAccessEnum.AuthorizedRoles;

        if (ForumInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Forums, ObjectActionEnum.Insert))
        {
            ForumInfoProvider.SetForumInfo(forumObj);
        }

        #endregion
    }
    /// <summary>
    /// Creates or rebuild department content search index.
    /// </summary>
    /// <param name="departmentNode">Department node</param>
    private void CreateDepartmentContentSearchIndex(TreeNode departmentNode)
    {
        string codeName = "default_department_" + departmentNode.NodeGUID;
        string departmentName = departmentNode.GetDocumentName();

        SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(codeName);
        if (sii == null)
        {
            // Create search index info
            sii = new SearchIndexInfo();
            sii.IndexName = codeName;
            string suffix = " - Default";
            sii.IndexDisplayName = TextHelper.LimitLength(departmentName, 200 - suffix.Length, "") + suffix;
            sii.IndexAnalyzerType = SearchAnalyzerTypeEnum.StandardAnalyzer;
            sii.IndexType = TreeNode.OBJECT_TYPE;
            sii.IndexIsCommunityGroup = false;

            // Create search index settings info
            SearchIndexSettingsInfo sisi = new SearchIndexSettingsInfo();
            sisi.ID = Guid.NewGuid();
            sisi.Path = departmentNode.NodeAliasPath + "/%";
            sisi.Type = SearchIndexSettingsInfo.TYPE_ALLOWED;
            sisi.ClassNames = "";

            // Create settings item
            SearchIndexSettings sis = new SearchIndexSettings();

            // Update settings item
            sis.SetSearchIndexSettingsInfo(sisi);

            // Update xml value
            sii.IndexSettings = sis;
            SearchIndexInfoProvider.SetSearchIndexInfo(sii);

            // Assign to current website
            SearchIndexSiteInfoProvider.AddSearchIndexToSite(sii.IndexID, SiteContext.CurrentSiteID);
        }

        // Add current culture to search index
        CultureInfo ci = CultureInfoProvider.GetCultureInfo(departmentNode.DocumentCulture);
        SearchIndexCultureInfoProvider.AddSearchIndexCulture(sii.IndexID, ci.CultureID);

        // Rebuild search index
        SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, null, null, sii.IndexName, sii.IndexID);
    }
Beispiel #14
0
    protected void gridDocs_OnAction(string actionName, object actionArgument)
    {
        switch (actionName.ToLowerCSafe())
        {
        case "delete":
            int deleteNodeId = ValidationHelper.GetInteger(actionArgument, 0);
            if (deleteNodeId > 0)
            {
                TreeNode deleteNode = DocumentManager.Tree.SelectSingleNode(deleteNodeId, TreeProvider.ALL_CULTURES);
                if ((deleteNode != null) && (Node != null))
                {
                    try
                    {
                        // Check user permissions
                        if (IsUserAuthorizedToDeleteDocument(deleteNode))
                        {
                            // Delete the document
                            DocumentHelper.DeleteDocument(deleteNode, DocumentManager.Tree);
                            ShowConfirmation(GetString("LinkedDocs.LinkDeleted"));

                            if ((deleteNode.NodeSiteID == Node.NodeSiteID) && (deleteNode.NodeID == NodeID))
                            {
                                // When deleting itself, select parent
                                ScriptHelper.RegisterStartupScript(this, typeof(string), "refreshScript", ScriptHelper.GetScript("SelectItem(" + deleteNode.NodeParentID + ", " + deleteNode.NodeParentID + ");"));
                            }
                            else
                            {
                                // When deleting from somewhere else, refresh tree
                                gridDocs.ReloadData();

                                ScriptHelper.RefreshTree(this, Node.NodeID, deleteNode.NodeParentID);
                            }
                        }
                        else
                        {
                            ShowError(String.Format(GetString("cmsdesk.notauthorizedtodeletedocument"), HTMLHelper.HTMLEncode(deleteNode.GetDocumentName())));
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowError(GetString("ContentRequest.DeleteFailed"), ex.Message);
                    }
                }
            }
            break;
        }
    }
Beispiel #15
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);
    }
Beispiel #16
0
    private void RemoveWorkflow(object parameter)
    {
        VersionManager verMan = VersionManager.GetInstance(Tree);
        TreeNode       node   = null;

        // Custom logging
        Tree.LogEvents         = false;
        Tree.AllowAsyncActions = false;
        CanceledString         = ResHelper.GetString("workflowdocuments.removingcanceled", currentCulture);
        try
        {
            // Begin log
            AddLog(ResHelper.GetString("content.preparingdocuments", currentCulture));

            string where = parameter as string;

            // Get the documents
            DataSet documents = GetDocumentsToProcess(where);

            if (!DataHelper.DataSourceIsEmpty(documents))
            {
                // Begin log
                AddLog(ResHelper.GetString("workflowdocuments.removingwf", currentCulture));

                foreach (DataTable classTable in documents.Tables)
                {
                    foreach (DataRow nodeRow in classTable.Rows)
                    {
                        // Get the current document
                        string className  = ValidationHelper.GetString(nodeRow["ClassName"], string.Empty);
                        string aliasPath  = ValidationHelper.GetString(nodeRow["NodeAliasPath"], string.Empty);
                        string docCulture = ValidationHelper.GetString(nodeRow["DocumentCulture"], string.Empty);
                        string siteName   = ValidationHelper.GetString(nodeRow["SiteName"], string.Empty);

                        // Get published version
                        node = Tree.SelectSingleNode(siteName, aliasPath, docCulture, false, className, false);
                        string encodedAliasPath = HTMLHelper.HTMLEncode(ValidationHelper.GetString(aliasPath, string.Empty) + " (" + node.GetValue("DocumentCulture") + ")");

                        // Destroy document history
                        verMan.DestroyDocumentHistory(node.DocumentID);

                        // Clear workflow
                        DocumentHelper.ClearWorkflowInformation(node);
                        node.Update();

                        // Add log record
                        AddLog(encodedAliasPath);

                        // Add record to eventlog
                        LogContext.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Content", "REMOVEDOCWORKFLOW", currentUser.UserID,
                                            currentUser.UserName, node.NodeID, node.GetDocumentName(),
                                            HTTPHelper.UserHostAddress, string.Format(GetString("workflowdocuments.removeworkflowsuccess"), encodedAliasPath),
                                            node.NodeSiteID, HTTPHelper.GetAbsoluteUri(), HTTPHelper.MachineName, HTTPHelper.GetUrlReferrer(), HTTPHelper.GetUserAgent());
                    }
                }
                CurrentInfo = GetString("workflowdocuments.removecomplete");
            }
            else
            {
                AddError(ResHelper.GetString("workflowdocuments.nodocumentstoclear", currentCulture));
            }
        }
        catch (ThreadAbortException ex)
        {
            string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty);
            if (state == CMSThread.ABORT_REASON_STOP)
            {
                // When canceled
                CurrentInfo = CanceledString;
            }
            else
            {
                int siteId = (node != null) ? node.NodeSiteID : CMSContext.CurrentSiteID;
                // Log error
                LogExceptionToEventLog("REMOVEDOCWORKFLOW", "workflowdocuments.removefailed", ex, siteId);
            }
        }
        catch (Exception ex)
        {
            int siteId = (node != null) ? node.NodeSiteID : CMSContext.CurrentSiteID;
            // Log error
            LogExceptionToEventLog("REMOVEDOCWORKFLOW", "workflowdocuments.removefailed", ex, siteId);
        }
    }
Beispiel #17
0
    /// <summary>
    /// Yes button click event handler.
    /// </summary>
    protected void btnYes_Click(object sender, EventArgs e)
    {
        if (IsBannedIP())
        {
            return;
        }

        // Prepare the where condition
        string where = "NodeID = " + NodeID;

        // Get the documents
        DataSet ds = null;

        if (chkAllCultures.Checked)
        {
            ds = TreeProvider.SelectNodes(SiteName, "/%", TreeProvider.ALL_CULTURES, true, null, where, null, -1, false);
        }
        else
        {
            ds = TreeProvider.SelectNodes(SiteName, "/%", CultureCode, false, null, where, null, -1, false);
        }

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            // Get node alias
            string nodeAlias = ValidationHelper.GetString(DataHelper.GetDataRowValue(ds.Tables[0].Rows[0], "NodeAlias"), string.Empty);
            // Get parent alias path
            string parentAliasPath = TreePathUtils.GetParentPath(ValidationHelper.GetString(DataHelper.GetDataRowValue(ds.Tables[0].Rows[0], "NodeAliasPath"), string.Empty));

            string   aliasPath = null;
            string   culture   = null;
            string   className = null;
            bool     hasUserDeletePermission = false;
            TreeNode treeNode = null;

            // Delete the documents
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                aliasPath = ValidationHelper.GetString(dr["NodeAliasPath"], string.Empty);
                culture   = ValidationHelper.GetString(dr["DocumentCulture"], string.Empty);
                className = ValidationHelper.GetString(dr["ClassName"], string.Empty);

                // Get the node
                treeNode = TreeProvider.SelectSingleNode(SiteName, aliasPath, culture, false, className, false);

                if (treeNode != null)
                {
                    // Check delete permissions
                    hasUserDeletePermission = !CheckPermissions || IsUserAuthorizedToDeleteDocument(treeNode, chkDestroy.Checked);

                    if (hasUserDeletePermission)
                    {
                        // Delete the document
                        try
                        {
                            LogDeleteActivity(treeNode);
                            DocumentHelper.DeleteDocument(treeNode, TreeProvider, chkAllCultures.Checked, chkDestroy.Checked, true);
                        }
                        catch (Exception ex)
                        {
                            EventLogProvider.LogEvent(EventType.ERROR, "Content", "DELETEDOC", EventLogProvider.GetExceptionLogMessage(ex), RequestContext.RawURL, MembershipContext.AuthenticatedUser.UserID, MembershipContext.AuthenticatedUser.UserName, treeNode.NodeID, treeNode.GetDocumentName(), RequestContext.UserHostAddress, SiteContext.CurrentSiteID);
                            AddAlert(GetString("ContentRequest.DeleteFailed") + ": " + ex.Message);
                            return;
                        }
                    }
                    // Access denied - not authorized to delete the document
                    else
                    {
                        AddAlert(String.Format(GetString("cmsdesk.notauthorizedtodeletedocument"), treeNode.NodeAliasPath));
                        return;
                    }
                }
                else
                {
                    AddAlert(GetString("ContentRequest.ErrorMissingSource"));
                    return;
                }
            }

            RaiseOnAfterDelete();

            string rawUrl = RequestContext.RawURL.TrimEnd(new char[] { '/' });
            if ((!string.IsNullOrEmpty(nodeAlias)) && (rawUrl.Substring(rawUrl.LastIndexOfCSafe('/')).Contains(nodeAlias)))
            {
                // Redirect to the parent url when current url belongs to deleted document
                URLHelper.Redirect(DocumentURLProvider.GetUrl(parentAliasPath));
            }
            else
            {
                // Redirect to current url
                URLHelper.Redirect(rawUrl);
            }
        }
        else
        {
            AddAlert(GetString("DeleteDocument.CultureNotExists"));
            return;
        }
    }
    private void RemoveWorkflow(object parameter)
    {
        VersionManager verMan = VersionManager.GetInstance(Tree);
        TreeNode       node   = null;

        // Custom logging
        Tree.LogEvents         = false;
        Tree.AllowAsyncActions = false;
        CanceledString         = GetString("workflowdocuments.removingcanceled", mCurrentCulture);
        try
        {
            // Begin log
            AddLog(GetString("content.preparingdocuments", mCurrentCulture));

            string where = parameter as string;

            // Get the documents
            DataSet documents = GetDocumentsToProcess(where);

            if (!DataHelper.DataSourceIsEmpty(documents))
            {
                // Begin log
                AddLog(GetString("workflowdocuments.removingwf", mCurrentCulture));

                foreach (DataTable classTable in documents.Tables)
                {
                    foreach (DataRow nodeRow in classTable.Rows)
                    {
                        // Get the current document
                        string className  = ValidationHelper.GetString(nodeRow["ClassName"], string.Empty);
                        string aliasPath  = ValidationHelper.GetString(nodeRow["NodeAliasPath"], string.Empty);
                        string docCulture = ValidationHelper.GetString(nodeRow["DocumentCulture"], string.Empty);
                        string siteName   = SiteInfoProvider.GetSiteName(nodeRow["NodeSiteID"].ToInteger(0));

                        // Get published version
                        node = Tree.SelectSingleNode(siteName, aliasPath, docCulture, false, className, false);
                        string encodedAliasPath = HTMLHelper.HTMLEncode(ValidationHelper.GetString(aliasPath, string.Empty) + " (" + node.GetValue("DocumentCulture") + ")");

                        // Destroy document history
                        verMan.DestroyDocumentHistory(node.DocumentID);

                        using (new CMSActionContext {
                            LogEvents = false
                        })
                        {
                            // Clear workflow
                            DocumentHelper.ClearWorkflowInformation(node);
                            node.Update();
                        }

                        // Add log record
                        AddLog(encodedAliasPath);

                        // Add record to eventlog
                        LogContext.LogEventToCurrent(EventType.INFORMATION, "Content", "REMOVEDOCWORKFLOW", string.Format(GetString("workflowdocuments.removeworkflowsuccess"), encodedAliasPath), RequestContext.RawURL, mCurrentUser.UserID, mCurrentUser.UserName, node.NodeID, node.GetDocumentName(), RequestContext.UserHostAddress, node.NodeSiteID, SystemContext.MachineName, RequestContext.URLReferrer, RequestContext.UserAgent, DateTime.Now);
                    }
                }
                CurrentInfo = GetString("workflowdocuments.removecomplete");
            }
            else
            {
                AddError(GetString("workflowdocuments.nodocumentstoclear", mCurrentCulture));
            }
        }
        catch (ThreadAbortException ex)
        {
            if (CMSThread.Stopped(ex))
            {
                // When canceled
                CurrentInfo = CanceledString;
            }
            else
            {
                int siteId = (node != null) ? node.NodeSiteID : SiteContext.CurrentSiteID;
                // Log error
                LogExceptionToEventLog("REMOVEDOCWORKFLOW", "workflowdocuments.removefailed", ex, siteId);
            }
        }
        catch (Exception ex)
        {
            int siteId = (node != null) ? node.NodeSiteID : SiteContext.CurrentSiteID;
            // Log error
            LogExceptionToEventLog("REMOVEDOCWORKFLOW", "workflowdocuments.removefailed", ex, siteId);
        }
    }
Beispiel #19
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Register script files
        ScriptHelper.RegisterCMS(this);
        ScriptHelper.RegisterScriptFile(this, "~/CMSModules/Content/CMSDesk/Operation.js");

        // Set current UI culture
        currentCulture = CultureHelper.PreferredUICultureCode;
        // Initialize current user
        currentUser = MembershipContext.AuthenticatedUser;
        // Initialize current site
        currentSite = SiteContext.CurrentSite;

        // Initialize events
        ctlAsync.OnFinished   += ctlAsync_OnFinished;
        ctlAsync.OnError      += ctlAsync_OnError;
        ctlAsync.OnRequestLog += ctlAsync_OnRequestLog;
        ctlAsync.OnCancel     += ctlAsync_OnCancel;

        if (!RequestHelper.IsCallback())
        {
            DataSet      allDocs = null;
            TreeProvider tree    = new TreeProvider(currentUser);
            btnCancel.Text = GetString("general.cancel");

            // Current Node ID to delete
            string parentAliasPath = string.Empty;
            if (Parameters != null)
            {
                parentAliasPath = ValidationHelper.GetString(Parameters["parentaliaspath"], string.Empty);
            }
            if (string.IsNullOrEmpty(parentAliasPath))
            {
                nodeIdsArr = QueryHelper.GetString("nodeid", string.Empty).Trim('|').Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string nodeId in nodeIdsArr)
                {
                    int id = ValidationHelper.GetInteger(nodeId, 0);
                    if (id != 0)
                    {
                        nodeIds.Add(id);
                    }
                }
            }
            else
            {
                string where = "ClassName <> 'CMS.Root'";
                if (!string.IsNullOrEmpty(WhereCondition))
                {
                    where = SqlHelper.AddWhereCondition(where, WhereCondition);
                }
                allDocs = tree.SelectNodes(currentSite.SiteName, parentAliasPath.TrimEnd(new[] { '/' }) + "/%",
                                           TreeProvider.ALL_CULTURES, true, ClassID > 0 ? DataClassInfoProvider.GetClassName(ClassID) : TreeProvider.ALL_CLASSNAMES, where,
                                           "DocumentName", TreeProvider.ALL_LEVELS, false, 0,
                                           TreeProvider.SELECTNODES_REQUIRED_COLUMNS + ",DocumentName,NodeParentID,NodeSiteID,NodeAliasPath,NodeSKUID");

                if (!DataHelper.DataSourceIsEmpty(allDocs))
                {
                    foreach (DataTable table in allDocs.Tables)
                    {
                        foreach (DataRow row in table.Rows)
                        {
                            nodeIds.Add(ValidationHelper.GetInteger(row["NodeID"], 0));
                        }
                    }
                }
            }

            // Setup page title text and image
            PageTitle.TitleText = GetString("Content.DeleteTitle");
            EnsureDocumentBreadcrumbs(PageBreadcrumbs, action: PageTitle.TitleText);

            btnCancel.Attributes.Add("onclick", ctlAsync.GetCancelScript(true) + "return false;");

            // Register the dialog script
            ScriptHelper.RegisterDialogScript(this);

            titleElemAsync.TitleText = GetString("ContentDelete.DeletingDocuments");
            // Set visibility of panels
            pnlContent.Visible = true;
            pnlLog.Visible     = false;

            bool isMultilingual = CultureSiteInfoProvider.IsSiteMultilingual(currentSite.SiteName);
            if (!isMultilingual)
            {
                // Set all cultures checkbox
                chkAllCultures.Checked = true;
                chkAllCultures.Visible = false;
            }

            if (nodeIds.Count > 0)
            {
                if (nodeIds.Count == 1)
                {
                    // Single document deletion
                    int      nodeId = ValidationHelper.GetInteger(nodeIds[0], 0);
                    TreeNode node   = null;

                    if (string.IsNullOrEmpty(parentAliasPath))
                    {
                        // Get any culture if current not found
                        node = tree.SelectSingleNode(nodeId, CultureCode) ?? tree.SelectSingleNode(nodeId, TreeProvider.ALL_CULTURES);
                    }
                    else
                    {
                        if (allDocs != null)
                        {
                            DataRow dr = allDocs.Tables[0].Rows[0];
                            node = TreeNode.New(ValidationHelper.GetString(dr["ClassName"], string.Empty), dr, tree);
                        }
                    }

                    if (node != null)
                    {
                        bool rootDeleteDisabled = false;

                        if (IsProductsMode)
                        {
                            string startingPath = SettingsKeyInfoProvider.GetStringValue(CurrentSiteName + ".CMSStoreProductsStartingPath");
                            if (node.NodeAliasPath.CompareToCSafe(startingPath) == 0)
                            {
                                string closeLink = "<a href=\"#\"><span style=\"cursor: pointer;\" " +
                                                   "onclick=\"SelectNode(" + node.NodeID + "); return false;\">" + GetString("general.back") +
                                                   "</span></a>";

                                ShowError(string.Format(GetString("com.productsection.deleteroot"), closeLink, ""));
                                pnlDelete.Visible  = false;
                                rootDeleteDisabled = true;
                            }
                        }

                        if (node.IsRoot() && isMultilingual)
                        {
                            // Hide 'Delete all cultures' checkbox
                            chkAllCultures.Visible = false;

                            if (!URLHelper.IsPostback())
                            {
                                // Check if there are any documents in another culture or current culture has some documents
                                pnlDeleteRoot.Visible = IsAnyDocumentInAnotherCulture(node) && (tree.SelectNodesCount(SiteContext.CurrentSiteName, "/%", LocalizationContext.PreferredCultureCode, false, null, null, null, TreeProvider.ALL_LEVELS, false) > 0);

                                if (pnlDeleteRoot.Visible)
                                {
                                    // Insert 'Delete current root' option if current root node is translated to current culture
                                    if (node.DocumentCulture == LocalizationContext.PreferredCultureCode)
                                    {
                                        rblRoot.Items.Add(new ListItem(GetString("rootdeletion.currentroot"), "current"));
                                    }

                                    rblRoot.Items.Add(new ListItem(GetString("rootdeletion.currentculture"), "allculturepages"));
                                    rblRoot.Items.Add(new ListItem(GetString("rootdeletion.allpages"), "allpages"));
                                }
                                else
                                {
                                    rblRoot.Items.Add(new ListItem(GetString("rootdeletion.allpages"), "allpages"));
                                }

                                if (rblRoot.SelectedIndex < 0)
                                {
                                    rblRoot.SelectedIndex = 0;
                                }
                            }
                        }

                        // Display warning for root node
                        if (!rootDeleteDisabled && node.IsRoot())
                        {
                            if (!currentUser.IsGlobalAdministrator)
                            {
                                pnlDelete.Visible = false;

                                ShowInformation(GetString("delete.rootonlyglobaladmin"));
                            }
                            else
                            {
                                if ((rblRoot.SelectedValue == "allpages") || !isMultilingual || ((rblRoot.SelectedValue == "allculturepages") && !IsAnyDocumentInAnotherCulture(node)))
                                {
                                    messagesPlaceholder.ShowWarning(GetString("Delete.RootWarning"));

                                    plcDeleteRoot.Visible = true;
                                }
                                else
                                {
                                    plcDeleteRoot.Visible = false;
                                }
                            }
                        }

                        hasChildren = node.NodeHasChildren;

                        bool authorizedToDeleteSKU = !node.HasSKU || IsUserAuthorizedToModifySKU(node);
                        if (!RequestHelper.IsPostBack())
                        {
                            bool authorizedToDeleteDocument = IsUserAuthorizedToDeleteDocument(node);
                            if (!authorizedToDeleteDocument || !authorizedToDeleteSKU)
                            {
                                pnlDelete.Visible = false;
                                RedirectToAccessDenied(String.Format(GetString("cmsdesk.notauthorizedtodeletedocument"), HTMLHelper.HTMLEncode(node.NodeAliasPath)));
                            }
                        }

                        if (node.IsLink)
                        {
                            PageTitle.TitleText    = GetString("Content.DeleteTitleLink") + " \"" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(node.GetDocumentName())) + "\"";
                            headQuestion.Text      = GetString("ContentDelete.QuestionLink");
                            chkAllCultures.Checked = true;
                            plcCheck.Visible       = false;
                        }
                        else
                        {
                            string nodeName = HTMLHelper.HTMLEncode(node.GetDocumentName());
                            // Get name for root document
                            if (node.NodeClassName.ToLowerCSafe() == "cms.root")
                            {
                                nodeName = HTMLHelper.HTMLEncode(currentSite.DisplayName);
                            }
                            PageTitle.TitleText = GetString("Content.DeleteTitle") + " \"" + HTMLHelper.HTMLEncode(ResHelper.LocalizeString(nodeName)) + "\"";

                            bool showSKUGroup = false;
                            if (NodeHasChildWithProduct(tree, node))
                            {
                                // Deleting product section
                                lblSKUActionInfo.Text = GetString("ContentDelete.SectionAssignedSKUInfo");
                                headDeleteSKU.Text    = GetString("ContentDelete.AssignedSKUs");

                                showSKUGroup = true;
                            }
                            else if (node.HasSKU && authorizedToDeleteSKU)
                            {
                                // Deleting product
                                if (!NodeSharesSKUWithOtherNode(tree, node))
                                {
                                    lblSKUActionInfo.Text = GetString("contentdelete.assignedskuinfo");
                                    headDeleteSKU.Text    = GetString("ContentDelete.AssignedSKU");

                                    showSKUGroup = true;
                                }
                            }

                            pnlDeleteSKU.Visible = showSKUGroup;
                            rblSKUAction.Visible = showSKUGroup;
                        }

                        // Show or hide checkbox
                        chkDestroy.Visible = CanDestroy(node);

                        cancelNodeId = IsMultipleAction ? node.NodeParentID : node.NodeID;

                        if (node.IsRoot())
                        {
                            // Change SEO panel if root is selected
                            pnlSeo.Visible = false;
                        }
                    }
                    else
                    {
                        if (!RequestHelper.IsPostBack())
                        {
                            URLHelper.Redirect(UIHelper.GetInformationUrl("editeddocument.notexists"));
                        }
                        else
                        {
                            // Hide everything
                            pnlContent.Visible = false;
                        }
                    }

                    headQuestion.Text       = GetString("ContentDelete.Question");
                    chkAllCultures.Text     = GetString("ContentDelete.AllCultures");
                    chkDestroy.Text         = GetString("ContentDelete.Destroy");
                    headDeleteDocument.Text = GetString("ContentDelete.Document");
                }
                else if (nodeIds.Count > 1)
                {
                    pnlDocList.Visible = true;
                    string where       = "NodeID IN (";
                    foreach (int nodeID in nodeIds)
                    {
                        where += nodeID + ",";
                    }

                    where = where.TrimEnd(',') + ")";
                    DataSet ds = allDocs ?? tree.SelectNodes(currentSite.SiteName, "/%", TreeProvider.ALL_CULTURES, true, null, where, "DocumentName", -1, false);

                    if (!DataHelper.DataSourceIsEmpty(ds))
                    {
                        string docList = null;

                        if (string.IsNullOrEmpty(parentAliasPath))
                        {
                            cancelNodeId = ValidationHelper.GetInteger(DataHelper.GetDataRowValue(ds.Tables[0].Rows[0], "NodeParentID"), 0);
                        }
                        else
                        {
                            cancelNodeId = TreePathUtils.GetNodeIdByAliasPath(currentSite.SiteName, parentAliasPath);
                        }

                        bool canDestroy  = true;
                        bool permissions = true;

                        foreach (DataTable table in ds.Tables)
                        {
                            foreach (DataRow dr in table.Rows)
                            {
                                bool   isLink = (dr["NodeLinkedNodeID"] != DBNull.Value);
                                string name   = (string)dr["DocumentName"];
                                docList += HTMLHelper.HTMLEncode(name);
                                if (isLink)
                                {
                                    docList += DocumentHelper.GetDocumentMarkImage(Page, DocumentMarkEnum.Link);
                                }
                                docList          += "<br />";
                                lblDocuments.Text = docList;

                                // Set visibility of checkboxes
                                TreeNode node = TreeNode.New(ValidationHelper.GetString(dr["ClassName"], string.Empty), dr);

                                if (!IsUserAuthorizedToDeleteDocument(node))
                                {
                                    permissions = false;
                                    AddError(String.Format(
                                                 GetString("cmsdesk.notauthorizedtodeletedocument"),
                                                 HTMLHelper.HTMLEncode(node.NodeAliasPath)), null);
                                }

                                // Can destroy if "can destroy all previous AND current"
                                canDestroy = CanDestroy(node) && canDestroy;

                                if (!hasChildren)
                                {
                                    hasChildren = node.NodeHasChildren;
                                }

                                if ((node.HasSKU && IsUserAuthorizedToModifySKU(node)) || NodeHasChildWithProduct(tree, node))
                                {
                                    pnlDeleteSKU.Visible = true;
                                    rblSKUAction.Visible = true;
                                }
                            }
                        }

                        pnlDelete.Visible  = permissions;
                        chkDestroy.Visible = canDestroy;
                    }
                    else
                    {
                        if (!RequestHelper.IsPostBack())
                        {
                            URLHelper.Redirect(UIHelper.GetInformationUrl("editeddocument.notexists"));
                        }
                        else
                        {
                            // Hide everything
                            pnlContent.Visible = false;
                        }
                    }

                    headQuestion.Text       = GetString("ContentDelete.QuestionMultiple");
                    PageTitle.TitleText     = GetString("Content.DeleteTitleMultiple");
                    chkAllCultures.Text     = GetString("ContentDelete.AllCulturesMultiple");
                    chkDestroy.Text         = GetString("ContentDelete.DestroyMultiple");
                    headDeleteDocument.Text = GetString("global.pages");
                    headDeleteSKU.Text      = GetString("ContentDelete.AssignedSKUs");
                    lblSKUActionInfo.Text   = GetString("ContentDelete.AssignedSKUsInfo");
                }

                // Init product actions
                if (!RequestHelper.IsPostBack())
                {
                    rblSKUAction.Items.Add(new ListItem(GetString("ContentDelete.SKU.deleteordisable"), "deleteordisable"));
                    rblSKUAction.Items.Add(new ListItem(GetString("ContentDelete.SKU.delete"), "delete"));
                    rblSKUAction.Items.Add(new ListItem(GetString("ContentDelete.SKU.disable"), "disable"));
                    rblSKUAction.Items.Add(new ListItem(GetString("ContentDelete.SKU.noaction"), "noaction"));

                    rblSKUAction.SelectedValue = "deleteordisable";
                }

                lblAltPath.AssociatedControlClientID = selAltPath.PathTextBox.ClientID;

                chkUseDeletedPath.CheckedChanged += chkUseDeletedPath_CheckedChanged;
                if (!RequestHelper.IsPostBack())
                {
                    selAltPath.Enabled     = false;
                    chkAltSubNodes.Enabled = false;
                    chkAltAliases.Enabled  = false;

                    // Set default path if is defined
                    selAltPath.Value = SettingsKeyInfoProvider.GetStringValue(CurrentSiteName + ".CMSDefaultDeletedNodePath");

                    if (!hasChildren)
                    {
                        chkAltSubNodes.Checked = false;
                        chkAltSubNodes.Enabled = false;
                    }
                }

                // If user has allowed cultures specified
                if (currentUser.UserHasAllowedCultures)
                {
                    // Get all site cultures
                    DataSet siteCultures            = CultureSiteInfoProvider.GetSiteCultures(currentSite.SiteName);
                    bool    denyAllCulturesDeletion = false;
                    // Check that user can edit all site cultures
                    foreach (DataRow culture in siteCultures.Tables[0].Rows)
                    {
                        string cultureCode = ValidationHelper.GetString(DataHelper.GetDataRowValue(culture, "CultureCode"), string.Empty);
                        if (!currentUser.IsCultureAllowed(cultureCode, currentSite.SiteName))
                        {
                            denyAllCulturesDeletion = true;
                        }
                    }
                    // If user can't edit all site cultures
                    if (denyAllCulturesDeletion)
                    {
                        // Hide all cultures selector
                        chkAllCultures.Visible = false;
                        chkAllCultures.Checked = false;
                    }
                }
                pnlDeleteDocument.Visible = chkAllCultures.Visible || chkDestroy.Visible;
            }
            else
            {
                // Hide everything
                pnlContent.Visible = false;
            }
        }
    }
    /// <summary>
    /// Ensures dialog breadcrumbs
    /// </summary>
    /// <param name="node">Current node</param>
    private void EnsureBreadcrumbs(TreeNode node)
    {
        if (node == null)
        {
            return;
        }

        PageTitle.HideBreadcrumbs = false;

        // Loop thru all levels and generate breadcrumbs
        for (int i = node.NodeLevel; i >= 0; i--)
        {
            if (node == null)
            {
                continue;
            }

            PageBreadcrumbs.Items.Add(new BreadcrumbItem
            {
                Text = node.GetDocumentName(),
                Index = i,
                RedirectUrl = "#",
                OnClientClick = "SelectItem(" + node.NodeID + "); return false;"
            });

            node = node.Parent;
        }

        // Add additional css class for correct design
        CurrentMaster.PanelHeader.CssClass += " SimpleHeader";
    }
    /// <summary>
    /// Creates department forum group.
    /// </summary>
    /// <param name="departmentNode">Department node</param>
    private void CreateDepartmentForumGroup(TreeNode departmentNode)
    {
        // Set general values
        string departmentName = departmentNode.GetDocumentName();
        string suffix = "";

        #region "Create forum group"

        // Get forum group code name
        string groupCodeName = "Department_" + departmentNode.NodeGUID;

        // Check if forum group with given name already exists
        if (ForumGroupInfoProvider.GetForumGroupInfo(groupCodeName, SiteContext.CurrentSiteID) != null)
        {
            return;
        }

        // Create base URL for forums
        string baseUrl = DocumentURLProvider.GetUrl(departmentNode.NodeAliasPath + "/" + FORUM_DOCUMENT_ALIAS);

        ForumGroupInfo forumGroupObj = new ForumGroupInfo();
        forumGroupObj.GroupDescription = "Forum group for " + departmentName + " department.";
        suffix = " forum group";
        forumGroupObj.GroupDisplayName = TextHelper.LimitLength(departmentName, 200 - suffix.Length, "") + suffix;
        forumGroupObj.GroupName = groupCodeName;
        forumGroupObj.GroupOrder = 0;
        forumGroupObj.GroupEnableQuote = true;
        forumGroupObj.GroupSiteID = SiteContext.CurrentSiteID;
        forumGroupObj.GroupBaseUrl = baseUrl;

        // Additional settings
        forumGroupObj.GroupEnableCodeSnippet = true;
        forumGroupObj.GroupEnableFontBold = true;
        forumGroupObj.GroupEnableFontColor = true;
        forumGroupObj.GroupEnableFontItalics = true;
        forumGroupObj.GroupEnableFontStrike = true;
        forumGroupObj.GroupEnableFontUnderline = true;
        forumGroupObj.GroupEnableQuote = true;
        forumGroupObj.GroupEnableURL = true;
        forumGroupObj.GroupEnableImage = true;

        ForumGroupInfoProvider.SetForumGroupInfo(forumGroupObj);

        #endregion

        #region "Create forum"

        string codeName = "Default_department_" + departmentNode.NodeGUID;

        // Check if forum with given name already exists
        if (ForumInfoProvider.GetForumInfo(codeName, SiteContext.CurrentSite.SiteID) != null)
        {
            return;
        }

        ForumInfo forumObj = new ForumInfo();
        forumObj.ForumSiteID = SiteContext.CurrentSiteID;
        forumObj.ForumIsLocked = false;
        forumObj.ForumOpen = true;
        forumObj.ForumDisplayEmails = false;
        forumObj.ForumDescription = "Forum for " + departmentName + " department.";
        forumObj.ForumRequireEmail = false;
        suffix = " forum";
        forumObj.ForumDisplayName = TextHelper.LimitLength(departmentName, 200 - suffix.Length, "") + suffix;
        forumObj.ForumName = codeName;
        forumObj.ForumGroupID = forumGroupObj.GroupID;
        forumObj.ForumModerated = false;
        forumObj.ForumAccess = 40000;
        forumObj.ForumPosts = 0;
        forumObj.ForumThreads = 0;
        forumObj.ForumPostsAbsolute = 0;
        forumObj.ForumThreadsAbsolute = 0;
        forumObj.ForumOrder = 0;
        forumObj.ForumUseCAPTCHA = false;
        forumObj.SetValue("ForumHTMLEditor", null);

        // Set security
        forumObj.AllowAccess = SecurityAccessEnum.AuthorizedRoles;
        forumObj.AllowAttachFiles = SecurityAccessEnum.AuthorizedRoles;
        forumObj.AllowMarkAsAnswer = SecurityAccessEnum.AuthorizedRoles;
        forumObj.AllowPost = SecurityAccessEnum.AuthorizedRoles;
        forumObj.AllowReply = SecurityAccessEnum.AuthorizedRoles;
        forumObj.AllowSubscribe = SecurityAccessEnum.AuthorizedRoles;

        if (ForumInfoProvider.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Forums, ObjectActionEnum.Insert))
        {
            ForumInfoProvider.SetForumInfo(forumObj);
        }

        #endregion
    }
    /// <summary>
    /// Deletes document(s).
    /// </summary>
    private void Delete(object parameter)
    {
        if (parameter == null || nodeIds.Count < 1)
        {
            return;
        }

        if (!LicenseHelper.LicenseVersionCheck(RequestContext.CurrentDomain, FeatureEnum.Documents, ObjectActionEnum.Edit))
        {
            AddError(GetString("cmsdesk.documentdeletelicenselimitations", currentCulture));
            return;
        }
        int refreshId = 0;

        TreeProvider tree = new TreeProvider(currentUser);

        tree.AllowAsyncActions = false;

        string[] parameters = ((string)parameter).Split(';');

        bool allLevelsSelected = ValidationHelper.GetBoolean(parameters[3], false);

        try
        {
            string siteName         = parameters[1];
            bool   isMultipleDelete = ValidationHelper.GetBoolean(parameters[2], false);

            // Prepare the where condition
            string where = new WhereCondition().WhereIn("NodeID", nodeIds).ToString(true);
            string columns = SqlHelper.MergeColumns(DocumentColumnLists.SELECTNODES_REQUIRED_COLUMNS, "NodeAliasPath, ClassName, DocumentCulture, NodeParentID");

            bool   combineWithDefaultCulture = false;
            string cultureCode = parameters[0];

            switch (parameters[4])
            {
            // Standard page deletion
            case "documentoptions":
                combineWithDefaultCulture = chkAllCultures.Checked;
                cultureCode = combineWithDefaultCulture ? TreeProvider.ALL_CULTURES : parameters[0];
                break;

            // Root page deletion
            case "rootoptions":
                cultureCode = rblRoot.SelectedValue == "allpages" ? TreeProvider.ALL_CULTURES : parameters[0];
                where       = rblRoot.SelectedValue == "allculturepages" ? String.Empty : where;
                break;
            }

            // Begin log
            AddLog(GetString("ContentDelete.DeletingDocuments", currentCulture));

            string orderBy = "NodeAliasPath DESC";
            if (cultureCode == TreeProvider.ALL_CULTURES)
            {
                // Default culture has to be selected on last position
                string defaultCulture = CultureHelper.GetDefaultCultureCode(siteName);
                orderBy += ", CASE WHEN DocumentCulture = '" + SqlHelper.EscapeQuotes(defaultCulture) + "' THEN 1 ELSE 0 END";
            }

            // Get the documents
            DataSet ds = tree.SelectNodes(siteName, "/%", cultureCode, combineWithDefaultCulture, null, where, orderBy, TreeProvider.ALL_LEVELS, false, 0, columns);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                // Delete the documents
                foreach (DataRow nodeRow in ds.Tables[0].Rows)
                {
                    // Get the current document
                    string className  = nodeRow["ClassName"].ToString();
                    string aliasPath  = nodeRow["NodeAliasPath"].ToString();
                    string docCulture = nodeRow["DocumentCulture"].ToString();
                    refreshId = ValidationHelper.GetInteger(nodeRow["NodeParentID"], 0);
                    if (refreshId == 0)
                    {
                        refreshId = ValidationHelper.GetInteger(nodeRow["NodeID"], 0);
                    }
                    TreeNode node = DocumentHelper.GetDocument(siteName, aliasPath, docCulture, false, className, null, null, TreeProvider.ALL_LEVELS, false, null, tree);

                    if (node == null)
                    {
                        AddLog(String.Format(GetString("ContentRequest.DocumentNoLongerExists", currentCulture), HTMLHelper.HTMLEncode(aliasPath)));
                        continue;
                    }

                    // Ensure current parent ID
                    int parentId = node.NodeParentID;

                    // Check if bound SKU can be deleted (if any)
                    bool authorizedToDeleteSKU = !node.HasSKU || IsUserAuthorizedToModifySKU(node);

                    // Check delete permissions
                    if (IsUserAuthorizedToDeleteDocument(node) && (CanDestroy(node) || !chkDestroy.Checked) && authorizedToDeleteSKU)
                    {
                        // Delete the document
                        if (parentId <= 0)
                        {
                            parentId = node.NodeID;
                        }

                        // Prepare settings for delete
                        var settings = new DeleteDocumentSettings(node, chkAllCultures.Checked, chkDestroy.Checked, tree);

                        // Delete document
                        refreshId = DocumentHelper.DeleteDocument(settings) || isMultipleDelete ? parentId : node.NodeID;
                    }
                    // Access denied - not authorized to delete the document
                    else
                    {
                        AddError(String.Format(GetString("cmsdesk.notauthorizedtodeletedocument", currentCulture), HTMLHelper.HTMLEncode(node.GetDocumentName())));
                    }
                }
            }
            else
            {
                AddError(GetString("DeleteDocument.CultureNotExists", currentCulture));
            }
        }
        catch (ThreadAbortException ex)
        {
            if (CMSThread.Stopped(ex))
            {
                // When canceled
                base.ShowError(GetString("DeleteDocument.DeletionCanceled", currentCulture));
            }
            else
            {
                // Log error
                LogExceptionToEventLog(ex);
            }
        }
        catch (Exception ex)
        {
            // Log error
            LogExceptionToEventLog(ex);
        }
        finally
        {
            if (String.IsNullOrEmpty(CurrentError))
            {
                // Overwrite refreshId variable if sub-levels are visible
                if (allLevelsSelected && Parameters.ContainsKey("refreshnodeid"))
                {
                    refreshId = ValidationHelper.GetInteger(Parameters["refreshnodeid"], 0);
                }

                // Refresh tree or page (on-site editing)
                if (!RequiresDialog)
                {
                    ctlAsyncLog.Parameter = "RefreshTree(" + refreshId + ", " + refreshId + "); \n" + "SelectNode(" + refreshId + ");";
                }
                else
                {
                    // Go to the root by default
                    string url = UrlResolver.ResolveUrl("~/");

                    // Update the refresh node id when set in the parent dialog
                    if (Parameters != null)
                    {
                        int refreshNodeId = ValidationHelper.GetInteger(Parameters["refreshnodeid"], 0);
                        if (refreshNodeId > 0)
                        {
                            refreshId = refreshNodeId;
                        }
                    }

                    // Try go to the parent document
                    if (refreshId > 0)
                    {
                        TreeProvider tp = new TreeProvider(MembershipContext.AuthenticatedUser);
                        TreeNode     tn = DocumentHelper.GetDocument(refreshId, TreeProvider.ALL_CULTURES, tp);
                        if (tn != null)
                        {
                            url = UrlResolver.ResolveUrl(DocumentURLProvider.GetUrl(tn));
                        }
                    }

                    ctlAsyncLog.Parameter = "window.refreshPageOnClose = true; window.reloadPageUrl = " + ScriptHelper.GetString(url) + "; CloseDialog();";
                }
            }
            else
            {
                ctlAsyncLog.Parameter = "RefreshTree(null, null);";
            }
        }
    }
Beispiel #23
0
    /// <summary>
    /// Initializes the control properties.
    /// </summary>
    public void SetupControl()
    {
        ltlIcons.Text = "";

        // Fill hashtable with info about all bookmark services
        FillHashTable();

        // Resolve path of images
        string imagesPath = ResolveUrl("~/CMSWebParts/SocialMedia/SocialBookmarking_files");

        // Get current document
        TreeNode node = DocumentContext.CurrentDocument;

        if (node != null)
        {
            // Get url of current document
            string liveUrl = RequestContext.CurrentURL;
            liveUrl = URLHelper.GetAbsoluteUrl(liveUrl);

            // Encode url
            liveUrl = Server.UrlEncode(liveUrl);

            // Prepare target
            string target = ShowInNewWindow ? "target=\"_blank\"" : "";

            string[] bookmarkInfo = new string[4];

            // Get all keys from hashtable
            object[] keys = new object[bookmarkServices.Count];
            bookmarkServices.Keys.CopyTo(keys, 0);
            StringBuilder sb = new StringBuilder();

            // Loop thru all items in hashtable
            for (int i = 0; i != keys.Length; i++)
            {
                // Get structure
                bookmarkInfo = (string[])bookmarkServices[keys[i]];
                string currentService = keys[i].ToString();
                if (bookmarkInfo.Length != 0)
                {
                    // If current service is enabled generate html code
                    if (ValidationHelper.GetBoolean(GetValue(currentService), false))
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append(Separator);
                        }
                        sb.Append("<a href=\"", bookmarkInfo[1], liveUrl, bookmarkInfo[2], Server.UrlEncode(node.GetDocumentName()), "\" title=\"", GetString("addtobook.addto"), " ", bookmarkInfo[0], "\" ", target, "><img src=\"", imagesPath, "/", currentService.ToLowerCSafe(), ".gif", "\" alt=\"", GetString("addtobook.addto"), " ", bookmarkInfo[0], "\" style=\"border-style:none;\" /></a>");
                    }
                }
            }


            // If at least one bookmarking service was checked show title
            if (sb.Length > 0)
            {
                if (!string.IsNullOrEmpty(TitleClass))
                {
                    sb.Insert(0, "<span class=\"" + TitleClass + "\">" + Title + "</span>");
                }
                else
                {
                    sb.Insert(0, Title);
                }

                // Wrap with span with class
                sb.Insert(0, "<span class=\"SocialBookmarking\">");
                sb.Append("</span>");
            }

            ltlIcons.Text = sb.ToString();
        }
    }
    /// <summary>
    /// Creates forum search index.
    /// </summary>
    /// <param name="departmentNode">Department node</param>
    private void CreateDepartmentForumSearchIndex(TreeNode departmentNode)
    {
        string codeName = "forums_department_" + departmentNode.NodeGUID;
        string departmentName = departmentNode.GetDocumentName();

        SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(codeName);
        if (sii == null)
        {
            // Create search index info
            sii = new SearchIndexInfo();
            sii.IndexName = codeName;
            string suffix = " - Forums";
            sii.IndexDisplayName = TextHelper.LimitLength(departmentName, 200 - suffix.Length, "") + suffix;
            sii.IndexAnalyzerType = SearchAnalyzerTypeEnum.StandardAnalyzer;
            sii.IndexType = PredefinedObjectType.FORUM;
            sii.IndexIsCommunityGroup = false;

            // Create search index settings info
            SearchIndexSettingsInfo sisi = new SearchIndexSettingsInfo();
            sisi.ID = Guid.NewGuid();
            sisi.Type = SearchIndexSettingsInfo.TYPE_ALLOWED;
            sisi.SiteName = SiteContext.CurrentSiteName;
            sisi.ForumNames = "*_department_" + departmentNode.NodeGUID;

            // Create settings item
            SearchIndexSettings sis = new SearchIndexSettings();

            // Update settings item
            sis.SetSearchIndexSettingsInfo(sisi);

            // Update xml value
            sii.IndexSettings = sis;
            SearchIndexInfoProvider.SetSearchIndexInfo(sii);

            // Assign to current website and current culture
            SearchIndexSiteInfoProvider.AddSearchIndexToSite(sii.IndexID, SiteContext.CurrentSiteID);
            CultureInfo ci = CultureInfoProvider.GetCultureInfo(departmentNode.DocumentCulture);
            SearchIndexCultureInfoProvider.AddSearchIndexCulture(sii.IndexID, ci.CultureID);
        }
    }
Beispiel #25
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Register the dialog script
        ScriptHelper.RegisterDialogScript(Page);

        DefaultSide                = QueryHelper.GetBoolean("defaultside", DefaultSide);
        AllowSwitchSides           = QueryHelper.GetBoolean("allowswitchsides", AllowSwitchSides);
        RelationshipName           = QueryHelper.GetString("relationshipname", RelationshipName);
        Config.ContentStartingPath = QueryHelper.GetString("startingpath", Config.ContentStartingPath);

        relNameSelector.IsLiveSite = false;
        btnSwitchSides.Visible     = AllowSwitchSides;
        btnOk.Visible = ShowButtons;

        // Initialize dialog scripts
        Config.EditorClientID = txtLeftNode.ClientID + ";" + hdnSelectedNodeId.ClientID;
        string url = CMSDialogHelper.GetDialogUrl(Config, IsLiveSite, false, null, false);

        btnLeftNode.OnClientClick = "modalDialog('" + url + "', 'contentselectnode', '90%', '85%'); return false;";

        Config.EditorClientID = txtRightNode.ClientID + ";" + hdnSelectedNodeId.ClientID;
        url = CMSDialogHelper.GetDialogUrl(Config, IsLiveSite, false, null, false);
        btnRightNode.OnClientClick = "modalDialog('" + url + "', 'contentselectnode', '90%', '85%'); return false;";

        if (TreeNode != null)
        {
            currentNodeId = TreeNode.NodeID;

            // Check modify permissions
            if (MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(TreeNode, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied)
            {
                Enabled = false;
                ShowInformation(String.Format(GetString("cmsdesk.notauthorizedtoeditdocument"), TreeNode.NodeAliasPath));
            }

            string nodeDocumentName = TreeNode.GetDocumentName();
            lblRightNode.Text = lblLeftNode.Text = HTMLHelper.HTMLEncode(nodeDocumentName);
        }
        else
        {
            Enabled = false;
        }

        // All relationship names for current site
        if (string.IsNullOrEmpty(RelationshipName))
        {
            relNameSelector.Visible = true;
            lblRelName.Visible      = false;
        }
        else
        {
            relationshipNameInfo = RelationshipNameInfoProvider.GetRelationshipNameInfo(RelationshipName);
            if (relationshipNameInfo != null)
            {
                lblRelName.Text = relationshipNameInfo.RelationshipDisplayName;
            }

            relNameSelector.Visible = false;
            lblRelName.Visible      = true;
        }

        // Register switching js
        if (btnSwitchSides.Enabled && btnSwitchSides.Visible)
        {
            RegisterScript();
        }

        if (!RequestHelper.IsPostBack())
        {
            hdnCurrentOnLeft.Value = !DefaultSide ? "true" : "false";
        }

        bool isLeftSide = ValidationHelper.GetBoolean(hdnCurrentOnLeft.Value, false);

        // Left side
        if (isLeftSide)
        {
            pnlLeftSelectedNode.AddCssClass("hidden");
            lblRightNode.AddCssClass("hidden");

            pnlRightSelectedNode.RemoveCssClass("hidden");
            lblLeftNode.RemoveCssClass("hidden");
        }
        // Right side
        else
        {
            lblLeftNode.AddCssClass("hidden");
            pnlRightSelectedNode.AddCssClass("hidden");

            pnlLeftSelectedNode.RemoveCssClass("hidden");
            lblRightNode.RemoveCssClass("hidden");
        }

        // Clear breadcrumbs suffix (we don't want it when creating new object)
        UIHelper.SetBreadcrumbsSuffix("");
    }
    /// <summary>
    /// Creates department media library.
    /// </summary>
    /// <param name="departmentNode">Department node</param>
    private void CreateDepartmentMediaLibrary(TreeNode departmentNode)
    {
        // Set general values
        string departmentName = departmentNode.GetDocumentName();
        string codeName = "Department_" + departmentNode.NodeGUID;
        string suffix = "";

        // Check if library with same name already exists
        MediaLibraryInfo mlInfo = MediaLibraryInfoProvider.GetMediaLibraryInfo(codeName, SiteContext.CurrentSiteName);
        if (mlInfo != null)
        {
            return;
        }

        // Create new object (record) if needed
        mlInfo = new MediaLibraryInfo();

        suffix = " media library";
        mlInfo.LibraryDisplayName = TextHelper.LimitLength(departmentName, 200 - suffix.Length, "") + suffix;
        mlInfo.LibraryFolder = departmentNode.NodeAlias;
        mlInfo.LibraryDescription = "Media library for " + departmentName + " department.";
        mlInfo.LibraryName = codeName;
        mlInfo.LibrarySiteID = SiteContext.CurrentSiteID;

        // Set security
        mlInfo.FileCreate = SecurityAccessEnum.AuthorizedRoles;
        mlInfo.FileDelete = SecurityAccessEnum.AuthorizedRoles;
        mlInfo.FileModify = SecurityAccessEnum.AuthorizedRoles;
        mlInfo.FolderCreate = SecurityAccessEnum.AuthorizedRoles;
        mlInfo.FolderDelete = SecurityAccessEnum.AuthorizedRoles;
        mlInfo.FolderModify = SecurityAccessEnum.AuthorizedRoles;
        mlInfo.Access = SecurityAccessEnum.AuthorizedRoles;

        try
        {
            MediaLibraryInfoProvider.SetMediaLibraryInfo(mlInfo);
        }
        catch
        {
            return;
        }

        // Create additional folders
        //MediaLibraryInfoProvider.CreateMediaLibraryFolder(SiteContext.CurrentSiteName, mlInfo.LibraryID, "Videos", false);
        //MediaLibraryInfoProvider.CreateMediaLibraryFolder(SiteContext.CurrentSiteName, mlInfo.LibraryID, "Other", false);
        //MediaLibraryInfoProvider.CreateMediaLibraryFolder(SiteContext.CurrentSiteName, mlInfo.LibraryID, "Photos & Images", false);
    }
    /// <summary>
    /// Process additional department tasks.
    /// </summary>
    public void ProcessDepartment(object sender, EventArgs e)
    {
        TreeNode editedNode = Form.EditedObject as TreeNode;

        // Get department template source document
        TreeNode sourceNode = DocumentHelper.GetDocument(SiteContext.CurrentSiteName, DepartmentTemplatePath, null, true, null, null, null, TreeProvider.ALL_LEVELS, false, null, TreeProvider);

        // Copy relevant template data to department document. Proceed only when creating a department, updating a department must not rewrite its data with template's data.
        if (Form.IsInsertMode && (sourceNode != null))
        {
            var excludeColumns = new []
            {
                "DocumentName",
                "NodeAlias",
                "DocumentTagGroupID",
                "DocumentStylesheetID",
                "DocumentPublishFrom",
                "DocumentPublishTo"
            };
            DocumentHelper.CopyNodeData(sourceNode, editedNode, new CopyNodeDataSettings(true, true, false, true, true, false, false, false, excludeColumns));
            DocumentHelper.UpdateDocument(editedNode, TreeProvider);
        }


        #region "Create department tag group"

        // Get tag group info
        TagGroupInfo tgi = TagGroupInfoProvider.GetTagGroupInfo(editedNode.DocumentTagGroupID);

        // If not exist, create new tag group and set it to document
        if (tgi == null)
        {
            // Populate tag group info fields
            tgi = new TagGroupInfo();
            tgi.TagGroupDisplayName = editedNode.GetDocumentName();
            tgi.TagGroupName        = editedNode.NodeGUID.ToString();
            tgi.TagGroupDescription = "";
            tgi.TagGroupSiteID      = SiteContext.CurrentSiteID;
            tgi.TagGroupIsAdHoc     = false;

            // Store tag group info to DB
            TagGroupInfoProvider.SetTagGroupInfo(tgi);

            // Update document Tag group ID
            editedNode.DocumentTagGroupID = tgi.TagGroupID;
            DocumentHelper.UpdateDocument(editedNode, TreeProvider);
        }

        #endregion


        if (!DataHelper.DataSourceIsEmpty(TemplateDocuments))
        {
            // List of selected documents
            string selectedDocs = ";" + Value + ";";

            // Get already created documents under edited document
            DataSet       dsExistingDocs = DocumentHelper.GetDocuments(SiteContext.CurrentSiteName, editedNode.NodeAliasPath + "/%", editedNode.DocumentCulture, true, null, null, null, 1, false, 0, "NodeAlias, " + DocumentColumnLists.SELECTNODES_REQUIRED_COLUMNS, null);
            StringBuilder sbExistDocs    = new StringBuilder();

            // Process existing documents to obtain list of aliases
            foreach (DataRow drExistDoc in dsExistingDocs.Tables[0].Rows)
            {
                sbExistDocs.Append(";");
                sbExistDocs.Append(drExistDoc["NodeAlias"].ToString().ToLowerCSafe());
            }
            sbExistDocs.Append(";");
            string existingDocs = sbExistDocs.ToString();

            // Set same ordering as for original template documents
            bool orgUseAutomaticOrdering = TreeProvider.UseAutomaticOrdering;
            TreeProvider.UseAutomaticOrdering = false;

            // Process template documents
            foreach (DataRow drDoc in TemplateDocuments.Tables[0].Rows)
            {
                if (DocumentHelper.IsDocumentTypeAllowed(editedNode, ValidationHelper.GetInteger(drDoc["NodeClassID"], 0)))
                {
                    string nodeAlias     = drDoc["NodeAlias"].ToString().ToLowerCSafe();
                    string contNodeAlias = ";" + nodeAlias + ";";

                    // Set marks
                    bool existing = existingDocs.Contains(contNodeAlias);
                    bool selected = selectedDocs.Contains(contNodeAlias);

                    int      nodeId     = ValidationHelper.GetInteger(drDoc["NodeID"], 0);
                    string   docCulture = ValidationHelper.GetString(drDoc["DocumentCulture"], "");
                    TreeNode srcNode    = DocumentHelper.GetDocument(nodeId, docCulture, editedNode.TreeProvider);

                    // Check if section exists
                    if (srcNode != null)
                    {
                        // Copy or remove marked document sections
                        if (selected)
                        {
                            if (!existing)
                            {
                                CopyDocumentSection(srcNode, editedNode, TreeProvider);
                            }
                        }
                        else
                        {
                            if (existing)
                            {
                                // Select node to delete
                                var aliasPath = editedNode.NodeAliasPath + "/" + nodeAlias;
                                var combineWithDefaultCulture = SettingsKeyInfoProvider.GetBoolValue(SiteContext.CurrentSiteName + ".CMSCombineWithDefaultCulture");

                                TreeProvider tree    = new TreeProvider(MembershipContext.AuthenticatedUser);
                                TreeNode     delNode = tree.SelectSingleNode(SiteContext.CurrentSiteName, aliasPath, LocalizationContext.PreferredCultureCode, combineWithDefaultCulture);

                                if (delNode != null)
                                {
                                    DeleteDocumentSection(delNode, TreeProvider);
                                }
                            }
                        }

                        // Process additional operations
                        if (selected && !existing)
                        {
                            switch (nodeAlias)
                            {
                            // Create department forum
                            case FORUM_DOCUMENT_ALIAS:
                                CreateDepartmentForumGroup(editedNode);
                                CreateDepartmentForumSearchIndex(editedNode);
                                break;

                            // Create media library
                            case MEDIA_DOCUMENT_ALIAS:
                                CreateDepartmentMediaLibrary(editedNode);
                                break;
                            }
                        }
                    }
                }
            }

            // Set previous ordering
            TreeProvider.UseAutomaticOrdering = orgUseAutomaticOrdering;
        }
        mDocumentSaved = true;
    }
    /// <summary>
    /// Ensures dialog breadcrumbs
    /// </summary>
    /// <param name="node">Current node</param>
    private void EnsureBreadcrumbs(TreeNode node)
    {
        if (node != null)
        {
            // Loop thru all levels and generate breadcrumbs
            int parentNodeId = 0;

            PageTitle.HideBreadcrumbs = false;

            for (int i = node.NodeLevel; i >= 0; i--)
            {
                if (node == null)
                {
                    // Document is not translated in the current culture -> get parent node from the default culture
                    TreeProvider treeProvider = new TreeProvider();
                    TreeNode parentNode = DocumentHelper.GetDocument(parentNodeId, CultureCode, true, treeProvider);
                    node = parentNode;
                }

                if (node != null)
                {
                    PageBreadcrumbs.Items.Add(new BreadcrumbItem
                    {
                        Text = node.GetDocumentName(),
                        Index = i,
                        RedirectUrl = "#",
                        OnClientClick = "SelectItem(" + node.NodeID + "); return false;"
                    });

                    parentNodeId = node.NodeParentID;
                    node = node.Parent;
                }
            }

            // Add additional css class for correct design
            CurrentMaster.PanelHeader.CssClass += " SimpleHeader";
        }
    }