Esempio n. 1
0
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        if (!CMSContext.CurrentUser.IsAuthorizedPerUIElement("CMS.Content", "Properties.Workflow"))
        {
            RedirectToCMSDeskUIElementAccessDenied("CMS.Content", "Properties.Workflow");
        }

        // Redirect to page 'New culture version' in split mode. It must be before setting EditedDocument.
        if ((Node == null) && displaySplitMode)
        {
            URLHelper.Redirect("~/CMSModules/Content/CMSDesk/New/NewCultureVersion.aspx" + URLHelper.Url.Query);
        }
        // Set edited document
        EditedDocument = Node;

        gridSteps.WhereCondition = "StepWorkflowID = @StepWorkflowID";

        // Hide custom steps if license doesn't allow them or check automatically publish changes
        if (!WorkflowInfoProvider.IsCustomStepAllowed())
        {
            gridSteps.WhereCondition = SqlHelperClass.AddWhereCondition(gridSteps.WhereCondition, "((StepName = 'edit') OR (StepName = 'published') OR (StepName = 'archived'))");
        }
        // Hide custom steps (without actual step) if functionality 'Automatically publish changes' is allowed
        else if ((WorkflowInfo != null) && WorkflowInfo.WorkflowAutoPublishChanges)
        {
            gridSteps.WhereCondition = SqlHelperClass.AddWhereCondition(gridSteps.WhereCondition, "(StepName = 'edit') OR (StepName = 'published') OR (StepName = 'archived')");
            // Get current step info
            WorkflowStepInfo currentStep = WorkflowManager.GetStepInfo(Node);

            if (currentStep != null)
            {
                string currentStepName = currentStep.StepName.ToLower();

                if ((currentStepName != "edit") && (currentStepName != "published") && (currentStepName != "archived"))
                {
                    gridSteps.WhereCondition = SqlHelperClass.AddWhereCondition(gridSteps.WhereCondition, "(StepName = '" + SqlHelperClass.GetSafeQueryString(currentStep.StepName, false) + "')", "OR");
                }
            }
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Reloads the page data.
    /// </summary>
    protected void ReloadData()
    {
        string where = string.Format("StepType IN ({0}, {1}, {2})", (int)WorkflowStepTypeEnum.DocumentEdit, (int)WorkflowStepTypeEnum.DocumentPublished, (int)WorkflowStepTypeEnum.DocumentArchived);
        // Hide custom steps if license doesn't allow them or check automatically publish changes
        if (!WorkflowInfoProvider.IsCustomStepAllowed())
        {
            gridSteps.WhereCondition = SqlHelper.AddWhereCondition(gridSteps.WhereCondition, where);
        }
        // Hide custom steps (without actual step) if functionality 'Automatically publish changes' is allowed
        else if ((WorkflowInfo != null) && WorkflowInfo.WorkflowAutoPublishChanges)
        {
            gridSteps.WhereCondition = SqlHelper.AddWhereCondition(gridSteps.WhereCondition, where);
            // Get current step info
            WorkflowStepInfo currentStep = WorkflowManager.GetStepInfo(Node);

            if (currentStep != null)
            {
                if (!currentStep.StepIsDefault)
                {
                    gridSteps.WhereCondition = SqlHelper.AddWhereCondition(gridSteps.WhereCondition, "(StepName = '" + SqlHelper.EscapeQuotes(currentStep.StepName) + "')", "OR");
                }
            }
        }

        // Do not display steps without order - advanced workflow steps
        gridSteps.WhereCondition = SqlHelper.AddWhereCondition(gridSteps.WhereCondition, "StepOrder IS NOT NULL");


        // Prepare the query parameters
        QueryDataParameters parameters = new QueryDataParameters();

        parameters.Add("@DocumentID", 0);

        // Prepare the steps query parameters
        QueryDataParameters stepsParameters = new QueryDataParameters();

        stepsParameters.Add("@StepWorkflowID", 0);

        if (Node != null)
        {
            // Check read permissions
            if (MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(Node, NodePermissionsEnum.Read) == AuthorizationResultEnum.Denied)
            {
                RedirectToAccessDenied(String.Format(GetString("cmsdesk.notauthorizedtoreaddocument"), HTMLHelper.HTMLEncode(Node.GetDocumentName())));
            }

            // Prepare parameters
            parameters.Add("@DocumentID", Node.DocumentID);
            currentStepId = ValidationHelper.GetInteger(Node.GetValue("DocumentWorkflowStepID"), 0);

            if (WorkflowInfo != null)
            {
                plcBasic.Visible    = WorkflowInfo.IsBasic;
                plcAdvanced.Visible = !plcBasic.Visible;
                if (plcAdvanced.Visible)
                {
                    ucDesigner.WorkflowID     = WorkflowInfo.WorkflowID;
                    ucDesigner.SelectedStepID = currentStepId;
                }
                else
                {
                    stepsParameters.Add("@StepWorkflowID", WorkflowInfo.WorkflowID);
                }

                // Initialize grids
                gridHistory.OnExternalDataBound += gridHistory_OnExternalDataBound;
                gridSteps.OnExternalDataBound   += gridSteps_OnExternalDataBound;
                gridHistory.ZeroRowsText         = GetString("workflowproperties.nohistoryyet");
            }
        }
        else
        {
            pnlWorkflow.Visible = false;
        }

        // Initialize query parameters of grids
        gridSteps.QueryParameters   = stepsParameters;
        gridHistory.QueryParameters = parameters;

        SetupForm();
        gridHistory.ReloadData();
        if (plcBasic.Visible)
        {
            gridSteps.ReloadData();
        }
    }
Esempio n. 3
0
    public void ReloadMenu()
    {
        newLink     = (Action == "newlink");
        newDocument = ((Action == "new") || newLink || Action == "newvariant");
        newCulture  = (Action == "newculture");

        if (Action == "newvariant")
        {
            ShowSpellCheck = false;
        }

        MenuItem newItem = null;

        // Create the edit menu
        menuElem.Items.Clear();

        mMenuItems = 0;

        // Save button
        MenuItem saveItem = null;

        if (mShowSave)
        {
            saveItem                   = new MenuItem();
            saveItem.ToolTip           = GetString("EditMenu.Save");
            saveItem.JavascriptCommand = FunctionsPrefix + "SaveDocument(" + NodeID + ");";
            saveItem.ImageAltText      = saveItem.ToolTip;
            saveItem.Text              = GetString("general.save");
            saveItem.Image             = GetImageUrl("CMSModules/CMS_Content/EditMenu/save.png");
            saveItem.MouseOverImage    = saveItem.Image;
            saveItem.MouseOverCssClass = "MenuItemEdit";
            saveItem.CssClass          = "MenuItemEdit";
            menuElem.Items.Add(saveItem);
            mMenuItems += 1;
        }

        mWorkflowInfo = "";

        mAllowEdit = true;
        mAllowSave = true;
        bool showDelete = false;

        if (!newDocument)
        {
            if (Node != null && !newCulture)
            {
                bool authorized = true;

                // If the perrmisions should be checked
                if (CheckPermissions)
                {
                    // Check read permissions
                    if (CMSContext.CurrentUser.IsAuthorizedPerDocument(Node, NodePermissionsEnum.Read) == AuthorizationResultEnum.Denied)
                    {
                        RedirectToAccessDenied(String.Format(GetString("cmsdesk.notauthorizedtoreaddocument"), Node.NodeAliasPath));
                    }
                    // Check modify permissions
                    else if (CMSContext.CurrentUser.IsAuthorizedPerDocument(Node, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Denied)
                    {
                        mAllowSave    = false;
                        mWorkflowInfo = String.Format(GetString("cmsdesk.notauthorizedtoeditdocument"), Node.NodeAliasPath);
                        authorized    = false;
                    }
                }

                // If authorized
                if (authorized)
                {
                    WorkflowInfo wi = WorkflowMan.GetNodeWorkflow(Node);
                    // If workflow not null, process the workflow information to display the items
                    if (wi != null)
                    {
                        // Get current step info, do not update document
                        WorkflowStepInfo si = null;
                        if (Node.IsPublished && (Node.DocumentCheckedOutVersionHistoryID <= 0))
                        {
                            si = WorkflowStepInfoProvider.GetWorkflowStepInfo("published", wi.WorkflowID);
                        }
                        else
                        {
                            si = WorkflowMan.GetStepInfo(Node, false) ??
                                 WorkflowMan.GetFirstWorkflowStep(Node, wi);
                        }

                        bool allowApproval      = true;
                        bool canApprove         = true;
                        bool autoPublishChanges = wi.WorkflowAutoPublishChanges;

                        // If license does not allow custom steps, can approve check is useless
                        if (WorkflowInfoProvider.IsCustomStepAllowed())
                        {
                            canApprove = WorkflowMan.CanUserApprove(Node, CMSContext.CurrentUser);
                        }

                        string stepName = si.StepName.ToLower();
                        if (!(canApprove || (stepName == "edit") || (stepName == "published") || (stepName == "archived")))
                        {
                            mAllowSave = false;
                        }

                        bool useCheckInCheckOut = wi.UseCheckInCheckOut(CMSContext.CurrentSiteName);

                        // Check-in, Check-out
                        if (useCheckInCheckOut)
                        {
                            if (!Node.IsCheckedOut)
                            {
                                mAllowSave = false;
                                mAllowEdit = false;

                                // If not checked out, add the check-out button
                                if (mShowCheckOut && (canApprove || (stepName == "edit") || (stepName == "published") || (stepName == "archived")))
                                {
                                    newItem                   = new MenuItem();
                                    newItem.ToolTip           = GetString("EditMenu.CheckOut");
                                    newItem.JavascriptCommand = FunctionsPrefix + "CheckOut(" + NodeID + ");";
                                    newItem.ImageAltText      = newItem.ToolTip;
                                    newItem.Text              = GetString("EditMenu.IconCheckOut");
                                    newItem.Image             = GetImageUrl("CMSModules/CMS_Content/EditMenu/checkout.png");
                                    newItem.MouseOverImage    = newItem.Image;
                                    newItem.MouseOverCssClass = "MenuItemEdit";
                                    newItem.CssClass          = "MenuItemEdit";
                                    menuElem.Items.Add(newItem);
                                    mMenuItems += 1;
                                }
                                // Set workflow info
                                // If not checked out, add the check-out information
                                if (canApprove || (stepName == "edit") || (stepName == "published") || (stepName == "archived"))
                                {
                                    mWorkflowInfo += GetString("EditContent.DocumentCheckedIn");
                                }
                            }
                        }
                        if (Node.IsCheckedOut)
                        {
                            // If checked out by current user, add the check-in button
                            int checkedOutBy = Node.DocumentCheckedOutByUserID;
                            if (checkedOutBy == CMSContext.CurrentUser.UserID)
                            {
                                if (mShowUndoCheckOut)
                                {
                                    newItem                   = new MenuItem();
                                    newItem.ToolTip           = GetString("EditMenu.UndoCheckout");
                                    newItem.JavascriptCommand = FunctionsPrefix + "UndoCheckOut(" + NodeID + ");";
                                    newItem.ImageAltText      = newItem.ToolTip;
                                    newItem.Text              = GetString("EditMenu.IconUndoCheckout");
                                    newItem.Image             = GetImageUrl("CMSModules/CMS_Content/EditMenu/undocheckout.png");
                                    newItem.MouseOverImage    = newItem.Image;
                                    newItem.MouseOverCssClass = "MenuItemEdit";
                                    newItem.CssClass          = "MenuItemEdit";
                                    menuElem.Items.Add(newItem);
                                    mMenuItems += 1;
                                }

                                if (mShowCheckIn)
                                {
                                    newItem                   = new MenuItem();
                                    newItem.ToolTip           = GetString("EditMenu.CheckIn");
                                    newItem.JavascriptCommand = FunctionsPrefix + "CheckIn(" + NodeID + ");";
                                    newItem.ImageAltText      = newItem.ToolTip;
                                    newItem.Text              = GetString("EditMenu.IconCheckIn");
                                    newItem.Image             = GetImageUrl("CMSModules/CMS_Content/EditMenu/checkin.png");
                                    newItem.MouseOverImage    = newItem.Image;
                                    newItem.MouseOverCssClass = "MenuItemEdit";
                                    newItem.CssClass          = "MenuItemEdit";
                                    menuElem.Items.Add(newItem);
                                    mMenuItems += 1;
                                }

                                // Set workflow info
                                mWorkflowInfo += GetString("EditContent.DocumentCheckedOut");
                            }
                            else
                            {
                                mAllowSave = false;
                                mAllowEdit = false;

                                string userName = UserInfoProvider.GetUserNameById(checkedOutBy);
                                // Set workflow info
                                mWorkflowInfo += String.Format(GetString("EditContent.DocumentCheckedOutByAnother"), userName);
                            }
                            allowApproval = false;
                        }

                        // Document approval
                        if (allowApproval)
                        {
                            MenuItem approveItem = null;

                            switch (stepName)
                            {
                            case "edit":
                                // When edit step and not allowed 'auto publish changes', display submit to approval
                                if (mShowSubmitToApproval && !autoPublishChanges)
                                {
                                    approveItem                   = new MenuItem();
                                    approveItem.ToolTip           = GetString("EditMenu.SubmitToApproval");
                                    approveItem.JavascriptCommand = FunctionsPrefix + "Approve(" + NodeID + ");";
                                    approveItem.ImageAltText      = approveItem.ToolTip;
                                    approveItem.Text              = GetString("EditMenu.IconSubmitToApproval");
                                    approveItem.Image             = GetImageUrl("CMSModules/CMS_Content/EditMenu/approve.png");
                                    approveItem.MouseOverImage    = approveItem.Image;
                                    approveItem.MouseOverCssClass = "MenuItemEdit";
                                    approveItem.CssClass          = "MenuItemEdit";
                                    menuElem.Items.Add(approveItem);
                                    mMenuItems += 1;
                                }
                                break;

                            case "published":
                            case "archived":
                                // No workflow options in these steps
                                break;

                            default:
                                // If the user is authorized to perform the step, display the approve and reject buttons
                                if (canApprove)
                                {
                                    if (mShowApprove && !autoPublishChanges)
                                    {
                                        approveItem                   = new MenuItem();
                                        approveItem.ToolTip           = GetString("EditMenu.Approve");
                                        approveItem.JavascriptCommand = FunctionsPrefix + "Approve(" + NodeID + ");";
                                        approveItem.ImageAltText      = approveItem.ToolTip;
                                        approveItem.Text              = GetString("general.approve");
                                        approveItem.Image             = GetImageUrl("CMSModules/CMS_Content/EditMenu/approve.png");
                                        approveItem.MouseOverImage    = approveItem.Image;
                                        approveItem.MouseOverCssClass = "MenuItemEdit";
                                        approveItem.CssClass          = "MenuItemEdit";
                                        menuElem.Items.Add(approveItem);
                                        mMenuItems += 1;
                                    }

                                    if (mShowReject && !autoPublishChanges)
                                    {
                                        newItem                   = new MenuItem();
                                        newItem.ToolTip           = GetString("EditMenu.Reject");
                                        newItem.JavascriptCommand = FunctionsPrefix + "Reject(" + NodeID + ");";
                                        newItem.ImageAltText      = newItem.ToolTip;
                                        newItem.Text              = GetString("general.reject");
                                        newItem.Image             = GetImageUrl("CMSModules/CMS_Content/EditMenu/reject.png");
                                        newItem.MouseOverImage    = newItem.Image;
                                        newItem.MouseOverCssClass = "MenuItemEdit";
                                        newItem.CssClass          = "MenuItemEdit";
                                        menuElem.Items.Add(newItem);
                                        mMenuItems += 1;
                                    }
                                }
                                break;
                            }

                            if (approveItem != null)
                            {
                                // Get next step info
                                WorkflowStepInfo nsi = WorkflowMan.GetNextStepInfo(Node);
                                if (nsi.StepName.ToLower() == "published")
                                {
                                    approveItem.ToolTip = GetString("EditMenu.Publish");
                                    approveItem.Text    = GetString("EditMenu.IconPublish");
                                }
                            }

                            // Set workflow info
                            if (!(canApprove || (stepName == "edit") || (stepName == "published") || (stepName == "archived")))
                            {
                                if (!string.IsNullOrEmpty(mWorkflowInfo))
                                {
                                    mWorkflowInfo += "<br />";
                                }
                                mWorkflowInfo += GetString("EditContent.NotAuthorizedToApprove");
                            }
                            if (!string.IsNullOrEmpty(mWorkflowInfo))
                            {
                                mWorkflowInfo += "<br />";
                            }
                            // If workflow isn't auto publish or step name isn't 'published' or 'check-in/check-out' is allowed then show current step name
                            if (!wi.WorkflowAutoPublishChanges || (stepName != "published") || useCheckInCheckOut)
                            {
                                mWorkflowInfo += String.Format(GetString("EditContent.CurrentStepInfo"), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(si.StepDisplayName)));
                            }
                        }
                    }
                }

                if (mShowProperties)
                {
                    newItem                   = new MenuItem();
                    newItem.ToolTip           = GetString("EditMenu.Properties");
                    newItem.JavascriptCommand = FunctionsPrefix + "Properties(" + NodeID + ");";
                    newItem.ImageAltText      = newItem.ToolTip;
                    newItem.Text              = GetString("EditMenu.IconProperties");
                    newItem.Image             = GetImageUrl("CMSModules/CMS_Content/EditMenu/properties.png");
                    newItem.MouseOverImage    = newItem.Image;
                    newItem.MouseOverCssClass = "MenuItemEdit";
                    newItem.CssClass          = "MenuItemEdit";
                    menuElem.Items.Add(newItem);
                    mMenuItems += 1;
                }

                if (mShowDelete)
                {
                    showDelete = true;
                }
            }

            // If not allowed to save, disable the save item
            if (!mAllowSave && mShowSave && (saveItem != null))
            {
                saveItem.JavascriptCommand = "";
                saveItem.MouseOverCssClass = "MenuItemEditDisabled";
                saveItem.CssClass          = "MenuItemEditDisabled";
                saveItem.Image             = GetImageUrl("CMSModules/CMS_Content/EditMenu/savedisabled.png");
                saveItem.MouseOverImage    = saveItem.Image;
            }
        }
        else if (mAllowSave && mShowCreateAnother)
        {
            newItem                   = new MenuItem();
            newItem.ToolTip           = GetString("EditMenu.SaveAndAnother");
            newItem.JavascriptCommand = FunctionsPrefix + "SaveDocument(" + NodeID + ", true);";
            newItem.ImageAltText      = newItem.ToolTip;
            newItem.Text              = GetString("editmenu.iconsaveandanother");
            newItem.Image             = GetImageUrl("CMSModules/CMS_Content/EditMenu/saveandanother.png");
            newItem.MouseOverImage    = newItem.Image;
            newItem.MouseOverCssClass = "MenuItemEdit";
            newItem.CssClass          = "MenuItemEdit";
            menuElem.Items.Add(newItem);
            mMenuItems += 1;
        }

        if (mAllowSave && mShowSave && mShowSpellCheck && !newLink)
        {
            newItem                   = new MenuItem();
            newItem.ToolTip           = GetString("EditMenu.SpellCheck");
            newItem.JavascriptCommand = FunctionsPrefix + "SpellCheck(spellURL);";
            newItem.ImageAltText      = newItem.ToolTip;
            newItem.Text              = GetString("EditMenu.IconSpellCheck");
            newItem.Image             = GetImageUrl("CMSModules/CMS_Content/EditMenu/spellcheck.png");
            newItem.MouseOverImage    = newItem.Image;
            newItem.MouseOverCssClass = "MenuItemEdit";
            newItem.CssClass          = "MenuItemEdit";
            menuElem.Items.Add(newItem);
            mMenuItems += 1;
        }

        if (showDelete)
        {
            newItem                   = new MenuItem();
            newItem.ToolTip           = GetString("EditMenu.Delete");
            newItem.JavascriptCommand = FunctionsPrefix + "Delete(" + NodeID + ");";
            newItem.ImageAltText      = newItem.ToolTip;
            newItem.Text              = GetString("general.delete");
            newItem.Image             = GetImageUrl("CMSModules/CMS_Content/EditMenu/delete.png");
            newItem.MouseOverImage    = newItem.Image;
            newItem.MouseOverCssClass = "MenuItemEdit";
            newItem.CssClass          = "MenuItemEdit";
            menuElem.Items.Add(newItem);
            mMenuItems += 1;
        }
    }
    protected void libraryMenuElem_OnReloadData(object sender, EventArgs e)
    {
        string[] parameters = ValidationHelper.GetString(libraryMenuElem.Parameter, string.Empty).Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
        if (parameters.Length == 2)
        {
            // Parse identifier and document culture from library parameter
            int    nodeId      = ValidationHelper.GetInteger(parameters[0], 0);
            string cultureCode = ValidationHelper.GetString(parameters[1], string.Empty);

            // Get document using based on node identifier and culture
            TreeNode node = DocumentHelper.GetDocument(nodeId, cultureCode, TreeProvider);

            bool contextMenuVisible    = false;
            bool localizeVisible       = false;
            bool editVisible           = false;
            bool uploadVisible         = false;
            bool copyVisible           = false;
            bool deleteVisible         = false;
            bool openVisible           = false;
            bool propertiesVisible     = false;
            bool permissionsVisible    = false;
            bool versionHistoryVisible = false;

            bool checkOutVisible         = false;
            bool checkInVisible          = false;
            bool undoCheckoutVisible     = false;
            bool submitToApprovalVisible = false;
            bool rejectVisible           = false;
            bool archiveVisible          = false;

            if ((node != null) && (CMSContext.CurrentUser.IsAuthorizedPerDocument(node, NodePermissionsEnum.Read) == AuthorizationResultEnum.Allowed))
            {
                // Get original node (in case of linked documents)
                TreeNode originalNode = TreeProvider.GetOriginalNode(node);

                string documentType           = ValidationHelper.GetString(node.GetValue("DocumentType"), string.Empty);
                string siteName               = CMSContext.CurrentSiteName;
                string currentDocumentCulture = CMSContext.CurrentDocumentCulture.CultureCode;

                if (CMSContext.CurrentSiteID != originalNode.NodeSiteID)
                {
                    SiteInfo si = SiteInfoProvider.GetSiteInfo(originalNode.NodeSiteID);
                    siteName = si.SiteName;
                }

                // Get permissions
                const bool authorizedToRead              = true;
                bool       authorizedToDelete            = (CMSContext.CurrentUser.IsAuthorizedPerDocument(node, NodePermissionsEnum.Delete) == AuthorizationResultEnum.Allowed);
                bool       authorizedToModify            = (CMSContext.CurrentUser.IsAuthorizedPerDocument(node, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Allowed);
                bool       authorizedCultureToModify     = (CMSContext.CurrentUser.IsAuthorizedPerDocument(node, NodePermissionsEnum.Modify, false) == AuthorizationResultEnum.Allowed) && TreeSecurityProvider.HasUserCultureAllowed(NodePermissionsEnum.Modify, currentDocumentCulture, CMSContext.CurrentUser, siteName);
                bool       authorizedToModifyPermissions = (CMSContext.CurrentUser.IsAuthorizedPerDocument(node, NodePermissionsEnum.ModifyPermissions) == AuthorizationResultEnum.Allowed);
                bool       authorizedToCreate            = CMSContext.CurrentUser.IsAuthorizedToCreateNewDocument(node.NodeParentID, node.NodeClassName);
                bool       allowEditByCurrentUser        = false;

                // Hide menu when user has no 'Read' permissions on document
                libraryMenuElem.Visible = authorizedToRead;

                // First evaluation of control's visibility
                bool differentCulture = (string.Compare(node.DocumentCulture, currentDocumentCulture, StringComparison.InvariantCultureIgnoreCase) != 0);
                localizeVisible       = differentCulture && authorizedToCreate && authorizedCultureToModify;
                uploadVisible         = authorizedToModify;
                copyVisible           = authorizedToCreate && authorizedToModify;
                deleteVisible         = authorizedToDelete;
                openVisible           = authorizedToRead;
                propertiesVisible     = authorizedToModify;
                permissionsVisible    = authorizedToModifyPermissions;
                versionHistoryVisible = authorizedToModify;
                editVisible           = authorizedToModify && CMSContext.IsWebDAVEnabled(CMSContext.CurrentSiteName) && RequestHelper.IsWindowsAuthentication() && WebDAVSettings.IsExtensionAllowedForEditMode(documentType, CMSContext.CurrentSiteName);

                // Get workflow object
                WorkflowInfo wi = WorkflowManager.GetNodeWorkflow(node);

                if ((wi != null) && authorizedToModify)
                {
                    bool autoPublishChanges = wi.WorkflowAutoPublishChanges;
                    // Get current step info, do not update document
                    WorkflowStepInfo si = WorkflowManager.GetStepInfo(node, false) ?? WorkflowManager.GetFirstWorkflowStep(node, wi);

                    bool canApprove = true;

                    // If license does not allow custom steps, 'can approve' check is meaningless
                    if (WorkflowInfoProvider.IsCustomStepAllowed())
                    {
                        canApprove = WorkflowManager.CanUserApprove(node, CMSContext.CurrentUser);
                    }

                    // Get name of current workflow step
                    string stepName             = si.StepName.ToLower();
                    bool   useCheckinCheckout   = wi.UseCheckInCheckOut(CMSContext.CurrentSiteName);
                    int    nodeCheckedOutByUser = node.DocumentCheckedOutByUserID;
                    bool   nodeIsCheckedOut     = (nodeCheckedOutByUser != 0);
                    bool   allowEdit            = canApprove || (stepName == "edit") || (stepName == "published") || (stepName == "archived");

                    // If document is checked in
                    if (nodeIsCheckedOut)
                    {
                        // If checked out by current user, add the check-in button and undo checkout button
                        if (nodeCheckedOutByUser == CMSContext.CurrentUser.UserID)
                        {
                            undoCheckoutVisible    = true;
                            checkInVisible         = true;
                            allowEditByCurrentUser = allowEdit;
                        }
                    }
                    else
                    {
                        // Hide check-out menu item if user can't apporve or document is in specific step
                        if (allowEdit)
                        {
                            // If site uses check-out / check-in
                            if (useCheckinCheckout)
                            {
                                checkOutVisible = true;
                            }
                            else
                            {
                                allowEditByCurrentUser = true;
                            }
                        }
                    }

                    rejectVisible           = canApprove && !nodeIsCheckedOut && (stepName != "edit") && (stepName != "published") && (stepName != "archived") && !autoPublishChanges;
                    submitToApprovalVisible = (canApprove || ((stepName == "edit") && authorizedToRead)) && !nodeIsCheckedOut && (stepName != "published") && (stepName != "archived") && !autoPublishChanges;
                    archiveVisible          = canApprove && !nodeIsCheckedOut && (stepName == "published");
                }
                else
                {
                    allowEditByCurrentUser = true;
                }

                // Check whether the document is not checked out by another user
                editVisible   &= allowEditByCurrentUser;
                uploadVisible &= allowEditByCurrentUser;

                string parameterScript = "GetContextMenuParameter('" + libraryMenuElem.MenuID + "')";

                // Initialize edit menu item
                Guid attachmentGuid = ValidationHelper.GetGuid(node.GetValue("FileAttachment"), Guid.Empty);

                // If attachment field doesn't allow empty value and the value is empty
                if ((FieldInfo != null) && !FieldInfo.AllowEmpty && (attachmentGuid == Guid.Empty))
                {
                    submitToApprovalVisible = false;
                    archiveVisible          = false;
                    checkInVisible          = false;
                }

                // Get attachment
                AttachmentInfo ai = DocumentHelper.GetAttachment(attachmentGuid, TreeProvider, siteName, false);

                Panel previousPanel = null;
                Panel currentPanel  = pnlEdit;

                if (editVisible)
                {
                    if (ai != null)
                    {
                        // Load WebDAV edit control and initialize it
                        WebDAVEditControl editAttachment = Page.LoadControl("~/CMSModules/WebDAV/Controls/AttachmentWebDAVEditControl.ascx") as WebDAVEditControl;

                        if (editAttachment != null)
                        {
                            editAttachment.ID                  = "editAttachment";
                            editAttachment.NodeAliasPath       = node.NodeAliasPath;
                            editAttachment.NodeCultureCode     = node.DocumentCulture;
                            editAttachment.AttachmentFieldName = "FileAttachment";
                            editAttachment.FileName            = ai.AttachmentName;
                            editAttachment.IsLiveSite          = IsLiveSite;
                            editAttachment.UseImageButton      = true;
                            editAttachment.LabelText           = GetString("general.edit");
                            editAttachment.CssClass            = "Icon";
                            editAttachment.LabelCssClass       = "Name";
                            editAttachment.RefreshScript       = JavaScriptPrefix + "PerformAction(" + parameterScript + ", 'WebDAVRefresh');";
                            // Set Group ID for live site
                            editAttachment.GroupID = IsLiveSite ? node.GetIntegerValue("NodeGroupID") : 0;
                            editAttachment.ReloadData(true);

                            pnlEditPadding.Controls.Add(editAttachment);
                            pnlEditPadding.CssClass = editAttachment.EnabledResult ? "ItemPadding" : "ItemPaddingDisabled";
                        }
                    }
                    else
                    {
                        editVisible = false;
                        openVisible = false;
                    }
                }

                previousPanel = currentPanel;
                currentPanel  = pnlUpload;

                // Initialize upload menu item
                if (authorizedToModify)
                {
                    string uploaderImg  = "<img class=\"UploaderImage\" src=\"" + GetImageUrl("Design/Controls/ContextMenu/DocumentLibrary/Upload.png", IsLiveSite) + "\" alt=\"" + GetString("general.update") + "\" />";
                    string uploaderText = "<span class=\"UploaderText\">" + GetString("general.update") + "</span>";

                    StringBuilder uploaderInnerHtml = new StringBuilder();

                    bool isRTL = (IsLiveSite && CultureHelper.IsPreferredCultureRTL()) || (!IsLiveSite && CultureHelper.IsUICultureRTL());
                    if (isRTL)
                    {
                        uploaderInnerHtml.Append(uploaderText);
                        uploaderInnerHtml.Append(uploaderImg);
                    }
                    else
                    {
                        uploaderInnerHtml.Append(uploaderImg);
                        uploaderInnerHtml.Append(uploaderText);
                    }

                    // Initialize direct file uploader
                    updateAttachment.InnerDivHtml             = uploaderInnerHtml.ToString();
                    updateAttachment.InnerDivClass            = "LibraryContextUploader";
                    updateAttachment.DocumentID               = node.DocumentID;
                    updateAttachment.ParentElemID             = ClientID;
                    updateAttachment.SourceType               = MediaSourceEnum.Attachment;
                    updateAttachment.AttachmentGUIDColumnName = "FileAttachment";
                    updateAttachment.DisplayInline            = true;
                    updateAttachment.IsLiveSite               = IsLiveSite;

                    // Set allowed extensions
                    if ((FieldInfo != null) && ValidationHelper.GetString(FieldInfo.Settings["extensions"], "") == "custom")
                    {
                        // Load allowed extensions
                        updateAttachment.AllowedExtensions = ValidationHelper.GetString(FieldInfo.Settings["allowed_extensions"], "");
                    }
                    else
                    {
                        // Use site settings
                        updateAttachment.AllowedExtensions = SettingsKeyProvider.GetStringValue(siteName + ".CMSUploadExtensions");
                    }

                    updateAttachment.ReloadData();
                    SetupPanelClasses(currentPanel, previousPanel);
                }

                previousPanel = currentPanel;
                currentPanel  = pnlLocalize;

                // Initialize localize menu item
                if (localizeVisible)
                {
                    lblLocalize.RefreshText();
                    imgLocalize.AlternateText = lblLocalize.Text;
                    imgLocalize.ImageUrl      = GetImageUrl("Design/Controls/ContextMenu/DocumentLibrary/Localize.png", IsLiveSite);
                    pnlLocalize.Attributes.Add("onclick", JavaScriptPrefix + "PerformAction(" + parameterScript + ", 'Localize');");
                    SetupPanelClasses(currentPanel, previousPanel);
                }

                previousPanel = null;
                currentPanel  = pnlCopy;

                // Initialize copy menu item
                if (copyVisible)
                {
                    lblCopy.RefreshText();
                    imgCopy.ImageUrl = GetImageUrl("Design/Controls/ContextMenu/DocumentLibrary/Copy.png", IsLiveSite);
                    pnlCopy.Attributes.Add("onclick", JavaScriptPrefix + "PerformAction(" + parameterScript + ",'Copy');");
                    SetupPanelClasses(currentPanel, previousPanel);
                }

                previousPanel = currentPanel;
                currentPanel  = pnlDelete;

                // Initialize delete menu item
                if (deleteVisible)
                {
                    lblDelete.RefreshText();
                    imgDelete.ImageUrl = GetImageUrl("Design/Controls/ContextMenu/DocumentLibrary/Delete.png", IsLiveSite);
                    pnlDelete.Attributes.Add("onclick", JavaScriptPrefix + "PerformAction(" + parameterScript + ", 'Delete');");
                    SetupPanelClasses(currentPanel, previousPanel);
                }

                previousPanel = currentPanel;
                currentPanel  = pnlOpen;

                // Initialize open menu item
                if (openVisible)
                {
                    lblOpen.RefreshText();
                    imgOpen.ImageUrl = GetImageUrl("Design/Controls/ContextMenu/DocumentLibrary/Open.png", IsLiveSite);
                    if (ai != null)
                    {
                        // Get document URL
                        string attachmentUrl = CMSContext.ResolveUIUrl(AttachmentURLProvider.GetPermanentAttachmentUrl(node.NodeGUID, node.NodeAlias));
                        if (authorizedToModify)
                        {
                            attachmentUrl = URLHelper.AddParameterToUrl(attachmentUrl, "latestfordocid", ValidationHelper.GetString(node.DocumentID, string.Empty));
                            attachmentUrl = URLHelper.AddParameterToUrl(attachmentUrl, "hash", ValidationHelper.GetHashString("d" + node.DocumentID));
                        }
                        attachmentUrl = URLHelper.UpdateParameterInUrl(attachmentUrl, "chset", Guid.NewGuid().ToString());

                        if (!string.IsNullOrEmpty(attachmentUrl))
                        {
                            pnlOpen.Attributes.Add("onclick", "location.href = " + ScriptHelper.GetString(attachmentUrl) + ";");
                        }
                    }
                    SetupPanelClasses(currentPanel, previousPanel);
                }

                previousPanel = null;
                currentPanel  = pnlProperties;

                // Initialize properties menu item
                lblProperties.RefreshText();
                imgProperties.ImageUrl = GetImageUrl("Design/Controls/ContextMenu/DocumentLibrary/Properties.png", IsLiveSite);
                pnlProperties.Attributes.Add("onclick", JavaScriptPrefix + "PerformAction(" + parameterScript + ", 'Properties');");
                SetupPanelClasses(currentPanel, previousPanel);

                previousPanel = currentPanel;
                currentPanel  = pnlPermissions;

                // Initialize permissions menu item
                lblPermissions.RefreshText();
                imgPermissions.ImageUrl = GetImageUrl("Design/Controls/ContextMenu/DocumentLibrary/Permissions.png", IsLiveSite);
                pnlPermissions.Attributes.Add("onclick", JavaScriptPrefix + "PerformAction(" + parameterScript + ", 'Permissions');");
                SetupPanelClasses(currentPanel, previousPanel);

                previousPanel = currentPanel;
                currentPanel  = pnlVersionHistory;

                // Initialize version history menu item
                lblVersionHistory.RefreshText();
                imgVersionHistory.ImageUrl = GetImageUrl("Design/Controls/ContextMenu/DocumentLibrary/VersionHistory.png", IsLiveSite);
                pnlVersionHistory.Attributes.Add("onclick", JavaScriptPrefix + "PerformAction(" + parameterScript + ", 'VersionHistory');");
                SetupPanelClasses(currentPanel, previousPanel);

                previousPanel = null;
                currentPanel  = pnlCheckOut;

                // Initialize checkout menu item
                if (checkOutVisible)
                {
                    lblCheckOut.RefreshText();
                    imgCheckOut.ImageUrl = GetImageUrl("Design/Controls/ContextMenu/DocumentLibrary/CheckOut.png", IsLiveSite);
                    pnlCheckOut.Attributes.Add("onclick", JavaScriptPrefix + "PerformAction(" + parameterScript + ", 'CheckOut');");
                    SetupPanelClasses(currentPanel, previousPanel);
                }

                previousPanel = currentPanel;
                currentPanel  = pnlCheckIn;

                // Initialize checkin menu item
                if (checkInVisible)
                {
                    lblCheckIn.RefreshText();
                    imgCheckIn.ImageUrl = GetImageUrl("Design/Controls/ContextMenu/DocumentLibrary/CheckIn.png", IsLiveSite);
                    pnlCheckIn.Attributes.Add("onclick", JavaScriptPrefix + "PerformAction(" + parameterScript + ", 'CheckIn');");
                    SetupPanelClasses(currentPanel, previousPanel);
                }

                previousPanel = currentPanel;
                currentPanel  = pnlUndoCheckout;

                // Initialize undo checkout menu item
                if (undoCheckoutVisible)
                {
                    lblUndoCheckout.RefreshText();
                    imgUndoCheckout.ImageUrl = GetImageUrl("Design/Controls/ContextMenu/DocumentLibrary/UndoCheckout.png", IsLiveSite);
                    pnlUndoCheckout.Attributes.Add("onclick", JavaScriptPrefix + "PerformAction(" + parameterScript + ", 'UndoCheckout');");
                    SetupPanelClasses(currentPanel, previousPanel);
                }

                previousPanel = currentPanel;
                currentPanel  = pnlSubmitToApproval;

                // Initialize submit to approval / publish menu item
                if (submitToApprovalVisible)
                {
                    if (wi != null)
                    {
                        // Get next step info
                        WorkflowStepInfo nsi = WorkflowManager.GetNextStepInfo(node);
                        if (nsi.StepName.ToLower() == "published")
                        {
                            // Set 'Publish' label
                            lblSubmitToApproval.ResourceString = "general.publish";
                        }
                    }

                    lblSubmitToApproval.RefreshText();
                    imgSubmitToApproval.ImageUrl = GetImageUrl("Design/Controls/ContextMenu/DocumentLibrary/SubmitToApproval.png", IsLiveSite);
                    pnlSubmitToApproval.Attributes.Add("onclick", JavaScriptPrefix + "PerformAction(" + parameterScript + ", 'SubmitToApproval');");
                    SetupPanelClasses(currentPanel, previousPanel);
                }

                previousPanel = currentPanel;
                currentPanel  = pnlReject;

                // Initialize reject menu item
                if (rejectVisible)
                {
                    lblReject.RefreshText();
                    imgReject.ImageUrl = GetImageUrl("Design/Controls/ContextMenu/DocumentLibrary/Reject.png", IsLiveSite);
                    pnlReject.Attributes.Add("onclick", JavaScriptPrefix + "PerformAction(" + parameterScript + ", 'Reject');");
                    SetupPanelClasses(currentPanel, previousPanel);
                }

                previousPanel = currentPanel;
                currentPanel  = pnlArchive;

                // Initialize archive menu item
                if (archiveVisible)
                {
                    lblArchive.RefreshText();
                    imgArchive.ImageUrl = GetImageUrl("Design/Controls/ContextMenu/DocumentLibrary/Archive.png", IsLiveSite);
                    pnlArchive.Attributes.Add("onclick", JavaScriptPrefix + "PerformAction(" + parameterScript + ", 'Archive');");
                    SetupPanelClasses(currentPanel, previousPanel);
                }

                // Set up visibility of menu items
                pnlLocalize.Visible       = localizeVisible;
                pnlUpload.Visible         = uploadVisible;
                pnlDelete.Visible         = deleteVisible;
                pnlCopy.Visible           = copyVisible;
                pnlOpen.Visible           = openVisible;
                pnlProperties.Visible     = propertiesVisible;
                pnlPermissions.Visible    = permissionsVisible;
                pnlVersionHistory.Visible = versionHistoryVisible;
                pnlEdit.Visible           = editVisible;

                pnlCheckOut.Visible         = checkOutVisible;
                pnlCheckIn.Visible          = checkInVisible;
                pnlUndoCheckout.Visible     = undoCheckoutVisible;
                pnlSubmitToApproval.Visible = submitToApprovalVisible;
                pnlReject.Visible           = rejectVisible;
                pnlArchive.Visible          = archiveVisible;

                // Set up visibility of whole menu
                contextMenuVisible = true;
            }

            // Set up visibility of separators
            bool firstGroupVisible  = editVisible || uploadVisible || localizeVisible;
            bool secondGroupVisible = copyVisible || deleteVisible || openVisible;
            bool thirdGroupVisible  = propertiesVisible || permissionsVisible || versionHistoryVisible;
            bool fourthGroupVisible = checkOutVisible || checkInVisible || undoCheckoutVisible || submitToApprovalVisible || rejectVisible || archiveVisible;

            pnlSep1.Visible = firstGroupVisible && secondGroupVisible;
            pnlSep2.Visible = secondGroupVisible && thirdGroupVisible;
            pnlSep3.Visible = thirdGroupVisible && fourthGroupVisible;

            // Setup 'No action available' menu item
            pnlNoAction.Visible = !contextMenuVisible;
            lblNoAction.RefreshText();
        }
    }