Пример #1
0
        void ProcessApproveCommand(string[] items)
        {
            for (int i = 0; i < items.Length; i++)
            {
                string[] keys = EcfListView.GetPrimaryKeyIdStringItems(items[i]);
                if (keys != null)
                {
                    int versionId = Int32.Parse(keys[0]);

                    using (IDataReader reader = PageVersion.GetVersionById(versionId))
                    {
                        if (reader.Read())
                        {
                            int templateId = (int)reader["TemplateId"];
                            int statusId   = (int)reader["StatusId"];
                            int stateId    = (int)reader["StateId"];
                            int langId     = (int)reader["LangId"];

                            int newStatus = WorkflowAccess.GetNextStatusId(statusId);

                            if (newStatus > 0)
                            {
                                PageVersion.UpdatePageVersion(versionId, templateId, langId, statusId, newStatus, ProfileContext.Current.UserId, 1, "");
                            }
                            //PageVersion.UpdatePageVersion(CMSContext.Current.VersionId, templateId, langId, statusId, WorkflowAccess.GetMaxStatus(Roles.GetRolesForUser(), WorkflowStatus.GetLast(statusId)), (Guid)Membership.GetUser(Page.User.Identity.Name).ProviderUserKey, 1, string.Empty);

                            // if we publish version
                            if (newStatus == WorkflowStatus.GetLast(statusId))
                            {
                                //find old publishd and put to archive
                                using (IDataReader reader2 = PageVersion.GetVersionByStatusId((int)reader["PageId"], newStatus))
                                {
                                    while (reader2.Read())
                                    {
                                        if ((int)reader2["LangId"] == langId)
                                        {
                                            if (versionId != (int)reader2["VersionId"])
                                            {
                                                PageVersion.UpdatePageVersion((int)reader2["VersionId"], (int)reader2["TemplateId"], (int)reader2["LangId"], (int)reader2["StatusId"], WorkflowStatus.GetArcStatus((int)reader2["StatusId"]), ProfileContext.Current.UserId, 2, "sent to archieve");
                                            }
                                        }
                                    }
                                    reader2.Close();
                                }
                            }
                        }
                        reader.Close();
                    }
                }
            }
        }
Пример #2
0
        void ProcessRejectCommand(string[] items)
        {
            for (int i = 0; i < items.Length; i++)
            {
                string[] keys = EcfListView.GetPrimaryKeyIdStringItems(items[i]);
                if (keys != null)
                {
                    int versionId = Int32.Parse(keys[0]);

                    // delete selected version
                    int templateId = -1;
                    int statusId   = -1;
                    using (IDataReader reader = PageVersion.GetVersionById(versionId))
                    {
                        if (reader.Read())
                        {
                            if (reader["TemplateId"] != DBNull.Value)
                            {
                                templateId = (int)reader["TemplateId"];
                            }
                            if (reader["StatusId"] != DBNull.Value)
                            {
                                statusId = (int)reader["StatusId"];
                            }
                        }
                        reader.Close();
                    }

                    int newStatus = -1;
                    newStatus = WorkflowAccess.GetPrevStatusId(statusId);
                    if (newStatus > 0)
                    {
                        PageVersion.UpdatePageVersion(versionId, templateId, CMSContext.Current.LanguageId,
                                                      statusId, newStatus, ProfileContext.Current.UserId, 2, "");
                    }
                }
            }
        }
Пример #3
0
    /// <summary>
    /// Creates the menu.
    /// </summary>
    /// <param name="langName">Name of the lang.</param>
    /// <param name="langId">The lang id.</param>
    private void CreateMenu(string langName, int langId)
    {
        //create menu
        TableCell cellMenu = new TableCell();

        cellMenu.Style.Add("border-left", "solid 1px silver");
        cellMenu.Style.Add("width", "12px");
        System.Web.UI.WebControls.Menu menuLang = new System.Web.UI.WebControls.Menu();
        //set style
        menuLang.StaticMenuItemStyle.CssClass = menuPattern.StaticMenuItemStyle.CssClass;
        menuLang.DynamicMenuStyle.CssClass    = menuPattern.DynamicMenuStyle.CssClass;
        //set templates
        menuLang.DynamicItemTemplate = menuPattern.DynamicItemTemplate;
        //disable default popup image
        menuLang.StaticEnableDefaultPopOutImage = false;
        //set orientation
        menuLang.Orientation = Orientation.Horizontal;
        System.Web.UI.WebControls.MenuItem root = new System.Web.UI.WebControls.MenuItem();
        root.Selectable = false;
        menuLang.Items.Add(root);


        //add other version
        //get archive status id
        int archiveStatusId = WorkflowStatus.GetArcStatus(0);
        //get allowed statusId
        ArrayList allowedStatusId = WorkflowAccess.LoadListByRoleId(ProfileContext.Current.User.ProviderUserKey.ToString());

        using (IDataReader reader = PageVersion.GetVersionByLangId(PageId, langId))
        {
            while (reader.Read())
            {
                int    statusId   = (int)reader["StatusId"];
                string statusName = string.Empty;
                using (IDataReader status = WorkflowStatus.LoadById(statusId))
                {
                    if (status.Read())
                    {
                        if (statusId != archiveStatusId && allowedStatusId.Contains(statusId))
                        {
                            statusName = status["FriendlyName"].ToString();
                        }
                    }

                    status.Close();
                }

                //add user draft
                Guid UserKey  = (Guid)ProfileContext.Current.User.ProviderUserKey;
                Guid OwnerKey = new Guid(reader["EditorUID"].ToString());
                if (statusId == WorkflowStatus.DraftId && UserKey == OwnerKey)
                {
                    statusName = "draft";
                }
                if (statusName != string.Empty)
                {
                    System.Web.UI.WebControls.MenuItem newItem = new System.Web.UI.WebControls.MenuItem();
                    newItem.Text = "Version #" + reader["VersionId"] + "(" + statusName + ")";


                    NameValueCollection vals = new NameValueCollection();
                    vals.Add("lang", langName);
                    vals.Add("VersionId", reader["VersionId"].ToString());
                    newItem.NavigateUrl = CommonHelper.FormatQueryString(CMSContext.Current.CurrentUrl, vals);

                    /*
                     * newItem.NavigateUrl = "~" + PageOutline + "?VersionId=" + reader["VersionId"].ToString() +
                     *                    "&UserId=" + Membership.GetUser().ProviderUserKey.ToString() +
                     *                    "&lang=" + langName;
                     * */
                    root.ChildItems.Add(newItem);
                }
            }

            reader.Close();
        }


        if (root.ChildItems.Count > 0)
        {
            //add menu to cell
            cellMenu.Controls.Add(menuLang);
            //add cell to row
            trLanguageMenu.Cells.Add(cellMenu);
        }
    }
Пример #4
0
        /// <summary>
        /// Creates the menu.
        /// </summary>
        /// <param name="langId">The lang id.</param>
        private void CreateMenu(int langId)
        {
            //create menu
            TableCell cellMenu = new TableCell();

            //cellMenu.Style.Add("border-left", "solid 1px silver");
            cellMenu.Style.Add("width", "12px");
            System.Web.UI.WebControls.Menu menuLang = new System.Web.UI.WebControls.Menu();
            //set style
            menuLang.StaticMenuItemStyle.CssClass = menuPattern.StaticMenuItemStyle.CssClass;
            menuLang.DynamicMenuStyle.CssClass    = menuPattern.DynamicMenuStyle.CssClass;
            //set templates
            //menuLang.StaticItemTemplate = menuPattern.StaticItemTemplate;
            menuLang.DynamicItemTemplate = menuPattern.DynamicItemTemplate;
            //disable default popup image
            menuLang.StaticEnableDefaultPopOutImage = false;
            //set orientation
            menuLang.Orientation = Orientation.Horizontal;
            System.Web.UI.WebControls.MenuItem root = new System.Web.UI.WebControls.MenuItem();
            root.Selectable = false;
            menuLang.Items.Add(root);

            //add other version
            //get archive status id
            int archiveStatusId = WorkflowStatus.GetArcStatus(0);
            //get allowed statusId
            ArrayList allowedStatusId = WorkflowAccess.LoadListByRoleId(Membership.GetUser().ProviderUserKey.ToString());

            using (IDataReader reader = PageVersion.GetVersionByLangId(PageId, langId))
            {
                while (reader.Read())
                {
                    int    statusId   = (int)reader["StatusId"];
                    string statusName = string.Empty;
                    using (IDataReader status = WorkflowStatus.LoadById(statusId))
                    {
                        if (status.Read())
                        {
                            if (statusId != archiveStatusId && allowedStatusId.Contains(statusId))
                            {
                                statusName = status["FriendlyName"].ToString();
                            }
                        }
                        status.Close();
                    }

                    //add user draft
                    Guid UserKey  = (Guid)Membership.GetUser().ProviderUserKey;
                    Guid OwnerKey = new Guid(reader["EditorUID"].ToString());
                    if (statusId == WorkflowStatus.DraftId && UserKey == OwnerKey)
                    {
                        statusName = "draft";
                    }
                    //TODO: for refactoring
                    if (statusName != string.Empty)
                    {
                        System.Web.UI.WebControls.MenuItem newItem = new System.Web.UI.WebControls.MenuItem();
                        newItem.Text        = "Version #" + reader["VersionId"] + "(" + statusName + ")";
                        newItem.Target      = "_blank";
                        newItem.NavigateUrl = "http://" + Mediachase.Cms.GlobalVariable.GetVariable("url", SiteId) + PageOutline + "?VersionId=" + reader["VersionId"].ToString() +
                                              "&UserId=" + Membership.GetUser().ProviderUserKey.ToString();
                        root.ChildItems.Add(newItem);
                    }
                }
                reader.Close();
            }


            if (root.ChildItems.Count > 0)
            {
                //add menu to cell
                cellMenu.Controls.Add(menuLang);
            }

            //add cell to row
            trLanguageMenu.Cells.Add(cellMenu);
        }
Пример #5
0
        /// <summary>
        /// Runs the command.
        /// </summary>
        /// <param name="commandName">Name of the command.</param>
        private void RunCommand(string commandName)
        {
            FileSystemResourceProvider prov = (FileSystemResourceProvider)ResourceHandler.ResourceHandler.ResourceProvider;
            {
                //EXIT FROM DESIGN-MODE
                if (commandName == "Cancel")
                {
                    // delete temp pagedocument
                    DeleteFromTemp();
                    this.ViewState.Clear();

                    CMSContext.Current.IsDesignMode = false;

                    //back to prev page
                    if (Request.QueryString["PrevVersionId"] != null)
                    {
                        NameValueCollection vals = new NameValueCollection();

                        if (Int32.Parse(Request.QueryString["PrevVersionId"]) > 0)
                        {
                            vals.Add("VersionId", Request.QueryString["PrevVersionId"]);
                        }
                        else
                        {
                            vals.Add("VersionId", "");
                        }

                        string url = CommonHelper.FormatQueryString(CMSContext.Current.CurrentUrl, vals);

                        Response.Redirect(url);
                        //Response.Redirect("~" + CMSContext.Current.Outline + "?VersionId=" + Request.QueryString["PrevVersionId"]);
                    }
                    else
                    {
                        Response.Redirect(Request.RawUrl, true);
                    }
                }

                //ENTER DESIGN-MODE
                if (commandName == "Edit")
                {
                    //GA: delete temp pagedocument
                    DeleteFromTemp();

                    // Check if we have access to the current version, if not, the new version for a current language will
                    // need to be created for "edit" command
                    if (!PageHelper.HasLanguageVersion(CMSContext.Current.PageId, LanguageId, CMSContext.Current.VersionId))
                    {
                        // add new version
                        _CommandValue.Value = String.Format("{0},{1}", CMSContext.Current.PageId, LanguageId);
                        RunCommand("AddVersion");
                    }

                    //back to prev page
                    if (Request.QueryString["PrevVersionId"] != null)
                    {
                        NameValueCollection vals = new NameValueCollection();
                        vals.Add("PrevVersionId", Request.QueryString["PrevVersionId"]);
                        string url = CommonHelper.FormatQueryString(CMSContext.Current.CurrentUrl, vals);
                        Response.Redirect(url);
                        //Response.Redirect("~" + CMSContext.Current.Outline + "?VersionId=" + Request.QueryString["PrevVersionId"]);
                    }
                    else
                    {
                        Response.Redirect(Request.RawUrl, true);
                    }
                }

                //SAVE AS DRAFT
                if (commandName == "SaveDraft")
                {
                    if (CMSContext.Current.VersionId == -2)
                    {
                        CMSContext.Current.VersionId       = PageVersion.AddDraft(CMSContext.Current.PageId, CMSContext.Current.TemplateId, LanguageId, (Guid)ProfileContext.Current.User.ProviderUserKey);
                        PageDocument.Current.PageVersionId = CMSContext.Current.VersionId;
                        //copy resources
                        DirectoryInfo resDir = new DirectoryInfo(MapPath("~/" + prov.Archive + "/" + ProfileContext.Current.User.UserName + "/"));
                        CommonHelper.CopyDirectory(resDir.FullName, MapPath("~/" + prov.Archive + "/" + CMSContext.Current.VersionId.ToString() + "/"));
                        if (resDir.Exists)
                        {
                            resDir.Delete(true);
                        }
                    }
                    PageDocument.Current.IsModified = true;

                    using (IDataReader reader = PageVersion.GetVersionById(CMSContext.Current.VersionId))
                    {
                        if (reader.Read())
                        {
                            int  verId      = -1;
                            bool addVersion = false;
                            using (IDataReader r = PageVersion.GetVersionById(CMSContext.Current.VersionId))
                            {
                                if (r.Read())
                                {
                                    addVersion = (int)r["StatusId"] != -1;
                                    if (!addVersion)
                                    {
                                        verId = CMSContext.Current.VersionId;
                                        PageVersion.UpdatePageVersion(verId, (int)r["TemplateId"], (int)r["LangId"], -1, WorkflowStatus.DraftId, (Guid)ProfileContext.Current.User.ProviderUserKey, 1, string.Empty);
                                    }
                                }

                                r.Close();
                            }

                            if (addVersion)
                            {
                                verId = PageVersion.AddPageVersion((int)reader["PageId"], (int)reader["TemplateId"], (int)reader["LangId"], (Guid)ProfileContext.Current.User.ProviderUserKey, 1, string.Empty);
                                using (IDataReader reader2 = PageVersion.GetVersionById(verId))
                                {
                                    if (reader2.Read())
                                    {
                                        PageVersion.UpdatePageVersion(verId, (int)reader2["TemplateId"], (int)reader2["LangId"], (int)reader2["StatusId"], WorkflowStatus.DraftId, (Guid)ProfileContext.Current.User.ProviderUserKey, 1, string.Empty);
                                    }

                                    reader2.Close();
                                }

                                //copy resources
                                //todo: feature suspended, reimplement in the future
                                //CommonHelper.CopyDirectory(MapPath("~/" + prov.Archive + "/" + CMSContext.Current.VersionId.ToString() + "/"), MapPath("~/" + prov.Archive + "/" + verId.ToString() + "/"));

                                CMSContext.Current.VersionId = verId;
                            }
                        }

                        reader.Close();
                    }
                    //SAVE DRAFT TO PERSIST STORAGE
                    PageDocument.Current.Save(CMSContext.Current.VersionId, SaveMode.PersistentStorage, Guid.Empty);
                    PageDocument.Current.ResetModified();

                    //delete from temporary storage
                    DeleteFromTemp();
                    this.ViewState.Clear();

                    //SWITCH TO VIEW MODE
                    EnableViewMode();

                    RedirectToNewPage();
                }

                //PUBLISH
                if (commandName == "Publish")
                {
                    bool firstVersion = false;
                    if (CMSContext.Current.VersionId == -2)
                    {
                        firstVersion = true;
                        CMSContext.Current.VersionId       = PageVersion.AddDraft(CMSContext.Current.PageId, CMSContext.Current.TemplateId, LanguageId, (Guid)ProfileContext.Current.User.ProviderUserKey);
                        PageDocument.Current.PageVersionId = CMSContext.Current.VersionId;
                        //copy resources
                        DirectoryInfo resDir = new DirectoryInfo(MapPath("~/" + prov.Archive + "/" + ProfileContext.Current.User.UserName + "/"));
                        CommonHelper.CopyDirectory(resDir.FullName, MapPath("~/" + prov.Archive + "/" + CMSContext.Current.VersionId.ToString() + "/"));
                        if (resDir.Exists)
                        {
                            resDir.Delete(true);
                        }
                    }
                    using (IDataReader reader = PageVersion.GetVersionById(CMSContext.Current.VersionId))
                    {
                        if (reader.Read())
                        {
                            int langId = (int)reader["LangId"];
                            if (WorkflowStatus.GetNext((int)reader["StatusId"]) != -1 || (int)reader["StatusId"] == -1)
                            {
                                PageVersion.UpdatePageVersion(CMSContext.Current.VersionId, (int)reader["TemplateId"], (int)reader["LangId"], (int)reader["StatusId"], WorkflowAccess.GetMaxStatus(Roles.GetRolesForUser(), WorkflowStatus.GetLast((int)reader["StatusId"])), (Guid)ProfileContext.Current.User.ProviderUserKey, 1, string.Empty);
                            }

                            // if we publish version
                            if (WorkflowStatus.GetLast((int)reader["StatusId"]) == WorkflowAccess.GetMaxStatus(Roles.GetRolesForUser(), WorkflowStatus.GetLast((int)reader["StatusId"])))
                            {
                                //find old published and put to archive
                                using (IDataReader reader2 = PageVersion.GetVersionByStatusId((int)reader["PageId"], WorkflowStatus.GetLast((int)reader["StatusId"])))
                                {
                                    while (reader2.Read())
                                    {
                                        if ((int)reader2["LangId"] == langId)
                                        {
                                            if (CMSContext.Current.VersionId != (int)reader2["VersionId"])
                                            {
                                                PageVersion.UpdatePageVersion((int)reader2["VersionId"], (int)reader2["TemplateId"], (int)reader2["LangId"], (int)reader2["StatusId"], WorkflowStatus.GetArcStatus((int)reader2["StatusId"]), (Guid)ProfileContext.Current.User.ProviderUserKey, 2, "sent to archieve");
                                            }
                                        }
                                    }

                                    reader2.Close();
                                }
                            }
                        }
                        reader.Close();
                    }

                    //SAVE TO PERSIST STORAGE
                    PageDocument.Current.Save(CMSContext.Current.VersionId, SaveMode.PersistentStorage, Guid.Empty);
                    PageDocument.Current.ResetModified();

                    //delete from temporary storage
                    DeleteFromTemp();
                    this.ViewState.Clear();

                    //SWITCH TO VIEW MODE
                    EnableViewMode();

                    // replace VersionId in query string with a new id
                    string url = Request.RawUrl;
                    if (firstVersion)
                    {
                        // if the page has just been created and is being published, need to remove "VersionId=-2" from the queryString to load published version
                        NameValueCollection vals = new NameValueCollection();
                        vals.Add("VersionId", String.Empty);
                        url = CommonHelper.FormatQueryString(url, vals);
                    }
                    Response.Redirect(url, true);
                }

                if (commandName == "Approve")
                {
                    using (IDataReader reader = PageVersion.GetVersionById(CMSContext.Current.VersionId))
                    {
                        if (reader.Read())
                        {
                            PageVersion.UpdatePageVersion(CMSContext.Current.VersionId, (int)reader["TemplateId"], (int)reader["LangId"], (int)reader["StatusId"], WorkflowAccess.GetMaxStatus(Roles.GetRolesForUser(), WorkflowStatus.GetLast((int)reader["StatusId"])), (Guid)ProfileContext.Current.User.ProviderUserKey, 1, /*ddText.TextValue*/ "");
                            int langId = (int)reader["langId"];

                            // if we publish version
                            if (WorkflowStatus.GetLast((int)reader["StatusId"]) == WorkflowAccess.GetMaxStatus(Roles.GetRolesForUser(), WorkflowStatus.GetLast((int)reader["StatusId"])))
                            {
                                //find old publishd and put to archive
                                using (IDataReader reader2 = PageVersion.GetVersionByStatusId((int)reader["PageId"], WorkflowStatus.GetLast((int)reader["StatusId"])))
                                {
                                    while (reader2.Read())
                                    {
                                        if (langId == (int)reader2["LangId"])
                                        {
                                            if (CMSContext.Current.VersionId != (int)reader2["VersionId"])
                                            {
                                                PageVersion.UpdatePageVersion((int)reader2["VersionId"], (int)reader2["TemplateId"], (int)reader2["LangId"], (int)reader2["StatusId"], WorkflowStatus.GetArcStatus((int)reader2["StatusId"]), (Guid)ProfileContext.Current.User.ProviderUserKey, 1, "Archieved");
                                            }
                                        }
                                    }

                                    reader2.Close();
                                }
                            }
                            //PageVersion.DeletePageVersion(CMSContext.Current.VersionId);
                            //PageVersion.AddPageVerion((int)reader["PageId"], (int)reader["TemplateId"], (int)reader["LangId"], (Guid)Membership.GetUser(Page.User.Identity.Name).ProviderUserKey, 1, ddText.TextValue);
                        }

                        reader.Close();
                    }

                    Response.Redirect(Request.RawUrl, true);
                    //RedirectToNewPage();
                }

                if (commandName == "Deny")
                {
                    using (IDataReader reader = PageVersion.GetVersionById(CMSContext.Current.VersionId))
                    {
                        if (reader.Read())
                        {
                            PageVersion.UpdatePageVersion(CMSContext.Current.VersionId, (int)reader["TemplateId"], (int)reader["LangId"], (int)reader["StatusId"], WorkflowStatus.GetPrevious((int)reader["StatusId"]), (Guid)ProfileContext.Current.User.ProviderUserKey, 2, /*ddText.TextValue*/ "");
                            //PageVersion.AddPageVerion((int)reader["PageId"], (int)reader["TemplateId"], (int)reader["LangId"], (Guid)Membership.GetUser(Page.User.Identity.Name).ProviderUserKey, 1, ddText.TextValue);
                        }

                        reader.Close();
                    }
                    string url = Page.Request.Url.ToString();

                    if (!url.Contains("VersionId"))
                    {
                        NameValueCollection vals = new NameValueCollection();
                        vals.Add("VersionId", CMSContext.Current.VersionId.ToString());
                        url = CommonHelper.FormatQueryString(url, vals);
                        Response.Redirect(url);
                    }
                }

                if (commandName == "ChangeTemplate")
                {
                    // Clear cache
                    CmsCache.Clear();

                    CMSContext mcContext = CMSContext.Current;
                    using (IDataReader reader = PageVersion.GetVersionById(CMSContext.Current.VersionId))
                    {
                        if (reader.Read())
                        {
                            int pageTemplateId;

                            if (Int32.TryParse(_CommandValue.Value, out pageTemplateId))
                            {
                                PageVersion.UpdatePageVersion(CMSContext.Current.VersionId, int.Parse(_CommandValue.Value), this.LanguageId, (int)reader["StatusId"], (int)reader["StatusId"], (Guid)ProfileContext.Current.User.ProviderUserKey, 1, string.Empty);
                            }
                        }

                        reader.Close();
                    }

                    if (mcContext.VersionId == -2)
                    {
                        NameValueCollection vals = new NameValueCollection();
                        vals.Add("TemplateId", _CommandValue.Value);
                        string url = CommonHelper.FormatQueryString(Request.RawUrl, vals);
                        Response.Redirect(url, true);
                    }
                    else
                    {
                        Response.Redirect(Request.RawUrl, true);
                    }
                }

                if (commandName == "AddVersion")
                {
                    string separator      = ",";
                    int    pageId         = int.Parse(_CommandValue.Value.Split(separator.ToCharArray())[0]);
                    int    langId         = int.Parse(_CommandValue.Value.Split(separator.ToCharArray())[1]);
                    string currentCulture = "en-us";
                    using (IDataReader reader = Language.LoadLanguage(langId))
                    {
                        if (reader.Read())
                        {
                            currentCulture = (string)reader["LangName"];
                        }

                        reader.Close();
                    }

                    NameValueCollection vals = new NameValueCollection();
                    vals.Add("lang", currentCulture);
                    vals.Add("VersionId", "-2");
                    vals.Add("PrevVersionId", CMSContext.Current.VersionId.ToString());
                    string url = CommonHelper.FormatQueryString(CMSContext.Current.CurrentUrl, vals);
                    Response.Redirect(url);
                }
                return;
            }
        }