예제 #1
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Visible)
            {
                return;
            }

            if (!IsPostBack)
            {
                SaveButton.OnClientClick = String.Format("RunCommand('ChangeTemplate', {0}.value);", TemplateListControl.ClientID);
                BindDropDownList();
            }

            if (Request.QueryString["TemplateId"] != null)
            {
                // Check permissions, only cms manager can change template
                if (!Page.User.Identity.IsAuthenticated || !SecurityManager.CheckPermission(new string[] { CmsRoles.ManagerRole }))
                {
                    this.Visible = false;
                    return;
                }

                TemplateListControl.SelectedValue = Request.QueryString["TemplateId"];
            }

            using (IDataReader reader = PageVersion.GetVersionById(VersionId))
            {
                if (reader.Read())
                {
                    TemplateListControl.SelectedValue = ((int)reader["TemplateId"]).ToString();
                    TemplateListControl.Visible       = true;
                    //statusId = (int)reader["statusId"];
                }
            }
        }
예제 #2
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();
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Visible)
            {
                return;
            }

            #region Visible Approve/Deny
            using (IDataReader reader = PageVersion.GetVersionById(CMSContext.Current.VersionId))
            {
                if (reader.Read())
                {
                    TopToolbar.Items[0].Visible = (WorkflowStatus.GetNext((int)reader["StatusId"]) != -1) && (CMSContext.Current.PageStatusAccess.ContainsKey(WorkflowStatus.GetNext((int)reader["StatusId"])));

                    if ((int)reader["StatusId"] == WorkflowStatus.DraftId)
                    {
                        TopToolbar.Items[0].Visible = true;
                    }

                    TopToolbar.Items[1].Visible = (WorkflowStatus.GetPrevious((int)reader["StatusId"]) != -1) && (CMSContext.Current.PageStatusAccess.ContainsKey(WorkflowStatus.GetNext((int)reader["StatusId"])));
                    if (WorkflowStatus.GetNext((int)reader["StatusId"]) == -1 && CMSContext.Current.PageStatusAccess.ContainsKey((int)reader["StatusId"]))
                    {
                        TopToolbar.Items[1].Visible = true;
                    }
                }
                else
                {
                    TopToolbar.Items[0].Visible = false;
                    TopToolbar.Items[1].Visible = false;
                }

                reader.Close();
            }

            if (!TopToolbar.Items[0].Visible && !TopToolbar.Items[1].Visible)
            {
                TopToolbar.Items[2].Visible = false;
            }

            #endregion
        }
예제 #4
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, "");
                    }
                }
            }
        }
예제 #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;
            }
        }
예제 #6
0
        /// <summary>
        /// Fills the context.
        /// </summary>
        private void FillContext()
        {
            // Reset the DesignMode since we could have saved it in a cookie and logged out since then
            if (CMSContext.Current.IsDesignMode && !CanEdit)
            {
                CMSContext.Current.IsDesignMode = false;
            }

            //SHOW  REQUESTED VERSION
            if (!String.IsNullOrEmpty(Request.QueryString["VersionId"]) && Page.User.Identity.IsAuthenticated)
            {
                bool versionExist = (int.Parse(Request.QueryString["VersionId"]) > 0);

                //Work with exist. version
                if (versionExist)
                {
                    int versionLangId = 1;
                    CMSContext.Current.VersionId = int.Parse(Request.QueryString["VersionId"]);

                    using (IDataReader reader = PageVersion.GetVersionById(CMSContext.Current.VersionId))
                    {
                        if (reader.Read())
                        {
                            CMSContext.Current.TemplateId = (int)reader["TemplateId"];
                            versionLangId = (int)reader["LangId"];
                        }

                        reader.Close();
                    }
                    //set CurrentCulture to version Culture
                    using (IDataReader lang = Language.LoadLanguage(versionLangId))
                    {
                        if (lang.Read())
                        {
                            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(lang["LangName"].ToString());
                            Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(lang["LangName"].ToString());
                        }

                        lang.Close();
                    }
                }
                //Work with temp version
                else
                {
                    CMSContext.Current.VersionId    = int.Parse(Request.QueryString["VersionId"]);
                    CMSContext.Current.IsDesignMode = true;
                    if (Request.QueryString["TemplateId"] != null)
                    {
                        CMSContext.Current.TemplateId = int.Parse(Request.QueryString["TemplateId"]);
                    }
                    else
                    {
                        CMSContext.Current.TemplateId = int.Parse(GlobalVariable.GetVariable("default_template", CMSContext.Current.SiteId).ToString());
                    }
                }
            }

            //SHOW PUBLISHED VERSION
            else
            {
                LoadPublishedVersionContext(!CMSContext.Current.IsDesignMode);
            }

            // If we are opening page in design mode, make sure we can actually edit the version
            if (CMSContext.Current.IsDesignMode && CMSContext.Current.VersionId != -2 && !PageHelper.HasLanguageVersion(CMSContext.Current.PageId, LanguageId, CMSContext.Current.VersionId))
            {
                // simply switch design mode off
                CMSContext.Current.IsDesignMode = false;
            }

            // Check current mode and set if toolbar and toolbox is visible
            if (CanEdit)
            {
                // Redirect to version list page, only for users who have appropriate permissions
                if (CMSContext.Current.VersionId == -1)
                {
                    if (CMSContext.Current.IsDesignMode)
                    {
                        LoadPublishedVersionContext(true);
                        _CommandValue.Value = CMSContext.Current.PageId.ToString() + "," + LanguageId.ToString();
                        RunCommand("AddVersion");
                    }
                    //Response.Redirect("~/Structure/Base/Controls/VersionList.aspx?PageId=" + CMSContext.Current.PageId + "&LanguageId=" + LanguageId);
                }

                // Check if any specific tab was clicked
                if (Request.QueryString["tab"] != null && !this.IsPostBack)
                {
                    if (Request.QueryString["tab"] == "design")
                    {
                        CMSContext.Current.IsDesignMode = true;
                        RunCommand("Edit");
                    }
                    else if (Request.QueryString["tab"] == "public")
                    {
                        CMSContext.Current.IsDesignMode = false;
                        RunCommand("Cancel");
                    }
                }
            }
            else
            {
                // Display default language page and show friendly error saying specified language page is not available
                if (CMSContext.Current.VersionId == -1)
                {
                    //Response.Cookies.Clear();
                    if (Response.Cookies["MediachaseCMSCurrentCulture"] != null)
                    {
                        Response.Cookies["MediachaseCMSCurrentCulture"].Expires = DateTime.Now.AddDays(-10);
                    }

                    if (!String.IsNullOrEmpty(Request.QueryString["_mode"]) && Request.QueryString["_mode"] == "edit")
                    {
                        // can not use "FormsAuthentication.LoginUrl" because it will return full path including ApplicationName, which might be incorrect for a current CMS Site context
                        Response.Redirect(String.Format("{0}?ReturnUrl={1}", ResolveUrl("~/login.aspx"), HttpUtility.UrlEncode(CMSContext.Current.CurrentUrl)));
                    }

                    //throw new HttpException(404, String.Empty);
                }
                else if (!String.IsNullOrEmpty(Request.QueryString["_mode"]) && Request.QueryString["_mode"] == "edit")
                {
                    // can not use "FormsAuthentication.LoginUrl" because it will return full path including ApplicationName, which might be incorrect for a current CMS Site context
                    Response.Redirect(String.Format("{0}?ReturnUrl={1}", ResolveUrl("~/login.aspx"), HttpUtility.UrlEncode(CMSContext.Current.CurrentUrl)));
                }


                HideDesignUI();
                CMSContext.Current.IsDesignMode = false;
            }

//            if (!CMSContext.Current.IsDesignMode)
//                HideDesignUI();

            // Initialize current PageDocument
            if (CMSContext.Current.IsDesignMode)
            {
                PageDocument.Current = PageDocument.Open(CMSContext.Current.VersionId, OpenMode.Design, UserUID);
            }
            else
            {
                PageDocument.Current = PageDocument.Open(CMSContext.Current.VersionId, OpenMode.View, UserUID);
            }
        }
예제 #7
0
        /// <summary>
        /// Binds the info.
        /// </summary>
        private void BindInfo()
        {
            #region InfoAboutVersion
            bool   canEdit       = false;
            string _comment      = string.Empty;
            string _commentValue = string.Empty;
            using (IDataReader reader = PageVersion.GetVersionById(CMSContext.Current.VersionId))
            {
                if (reader.Read())
                {
                    using (IDataReader readerState = Workflow.PageStateGetById((int)reader["StateId"]))
                    {
                        if (readerState.Read())
                        {
                            //if (canEdit) _comment = _comment + "<b>Состояние:</b> " + (string)readerState["FriendlyName"];
                            if (canEdit)
                            {
                                if ((int)reader["StateId"] == 1)
                                {
                                    _comment = _comment + "<b> <span align='right' style='color:blue'>" + (string)readerState["FriendlyName"] + "</span> </b>";
                                }
                                else
                                {
                                    _comment = _comment + "<b> <span align='right' style='color:red'>" + (string)readerState["FriendlyName"] + "</span> </b>";
                                }
                            }
                        }

                        readerState.Close();
                    }

                    /*
                     * using (IDataReader readerStatus = WorkflowStatus.LoadById((int)reader["StatusId"]))
                     * {
                     *  //if ((int)reader["StatusId"] == -1)
                     *  //{
                     *  //    secHeader.AddText("&nbsp Документ - Черновик &nbsp");
                     *  //}
                     *  if (readerStatus.Read())
                     *  {
                     *      //_comment = _comment + "<br> <b>Статус:</b> " + (string)readerStatus["FriendlyName"];
                     *      //secHeader.AddText("&nbsp Документ - " + (string)readerStatus["FriendlyName"] + "&nbsp");
                     *  }
                     * }
                     * */
                    if (!(reader["EditorUID"] is DBNull))
                    {
                        _comment = _comment + "<b>Edited by </b> <span style='color: blue'>" + CommonHelper.GetUserName((Guid)reader["EditorUID"]) + "</span> on " + ((DateTime)reader["Edited"]).ToString("f");
                    }

                    if (!(reader["Comment"] is System.DBNull) && canEdit)
                    {
                        if (((string)reader["Comment"]).Length > 0)
                        {
                            _comment      = _comment + "<b>Comments:</b><br>";
                            _commentValue = _commentValue + (string)reader["Comment"];// +"<br>";
                        }
                    }
                }

                reader.Close();
            }
            lblComment.Text      = _comment;
            lblCommentValue.Text = _commentValue;
            #endregion

            //ddText.Visible = canEdit;
            if (canEdit)
            {
                ddText.Attributes.Add("display", "inline");
            }
            else
            {
                ddText.Attributes.Add("display", "none");
            }
        }
예제 #8
0
        /// <summary>
        /// Handles the BeginRequest event of the context control.
        ///
        /// It will execute the following actions:
        ///
        ///     1. Determine which site this request belongs to.
        ///     2. Check if request is for the template.aspx and if it is redirect to the homepage instead.
        ///     3. Determine if it is a folder request or not and if it is detect the default page and redirect.
        ///     4. Restore settings from user cookies.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication app     = (HttpApplication)sender;
            HttpContext     context = app.Context;

            // Process only aspx pages and directories
            if (!(context.Request.Url.ToString().ToLower().IndexOf(".aspx") > 0) &&
                !context.Request.Url.ToString().EndsWith("/"))
            {
                // If page name does not contain ".", then assume it is a folder and try to process the request
                if (context.Request.Url.Segments[context.Request.Url.Segments.Length - 1].ToString().Contains("."))
                {
                    return;
                }
            }

            CMSContext ctx = CMSContext.Create(context);

            // Determine SiteId
            SiteDto.SiteRow row = FindSiteFromUrl(ctx);

            // throw does not exist error
            if (row == null)
            {
                //throw new HttpException(404, "Site does not exist");
                Write(null, null, "StoreClosed.htm");
            }

            ctx.SiteId = row.SiteId;

            string appPath = ctx.Context.Request.ApplicationPath;

            if (appPath == "/")
            {
                appPath = String.Empty;
            }

            string outline  = context.Request.RawUrl;
            int    folderId = -1;

            if (ctx.AppPath.Length != 1)
            {
                outline = outline.Substring(ctx.AppPath.Length);
            }

            // Check if the request is for the template.aspx
            if (outline.Equals("/template.aspx", StringComparison.OrdinalIgnoreCase))
            {
                ctx.Redirect(CMSContext.Current.ResolveUrl("~"));
            }

            // If empty, we assume it is the site root that we are requesting
            if (String.IsNullOrEmpty(outline))
            {
                outline = "/";
            }

            // Is it a folder?
            if (outline.EndsWith("/") || !outline.Contains("."))
            {
                using (IDataReader reader = FileTreeItem.GetItemByOutlineAll(outline, CMSContext.Current.SiteId))
                {
                    if (reader.Read())
                    {
                        folderId = (int)reader["PageId"];
                    }

                    reader.Close();
                }
                if (folderId != -1)
                {
                    //try to find default page for folder
                    using (IDataReader reader = FileTreeItem.GetFolderDefaultPage(folderId))
                    {
                        if (reader.Read())
                        {
                            string urlPage = String.Empty;
                            if (context.Request.QueryString.Count > 0)
                            {
                                urlPage = reader.GetString(2) + "?" + context.Request.QueryString;
                            }
                            else
                            {
                                urlPage = reader.GetString(2);
                            }

                            // Add the relative path
                            if (urlPage.StartsWith("/"))
                            {
                                urlPage = "~" + urlPage;
                            }

                            // Redirect
                            ctx.Redirect(CMSContext.Current.ResolveUrl(urlPage));
                        }
                        else
                        {
                            reader.Close();
                            throw new HttpException(204, "Default page for folder not found");
                        }

                        reader.Close();
                    }
                }
            }

            // TODO: remove hard coded cookie names and put it into CMS configuration instead
            HttpCookie cookie;

            //CHECK ToolBar/ToolBox visible
            if (context.Request.Cookies[_toolBarVisibleCookieString] != null)
            {
                cookie = (HttpCookie)context.Request.Cookies[_toolBarVisibleCookieString];
                CMSContext.Current.ToolBarVisible = Convert.ToBoolean(cookie.Value);
            }
            //CHECK ToolBox
            if (context.Request.Cookies[_toolBoxVisibleCookieString] != null)
            {
                cookie = (HttpCookie)context.Request.Cookies[_toolBoxVisibleCookieString];
                CMSContext.Current.ToolBoxVisible = Convert.ToBoolean(cookie.Value);
            }

            //CHECK IsDesignMode
            CMSContext.Current.IsDesignMode = CommonHelper.CheckDesignMode(context);

            //CHECK CULTURE
            string currentCulture = string.Empty;

            //CHECK HIDDEN FIELDS
            if (!String.IsNullOrEmpty(context.Request.Form[_currentCultureRequestString]))
            {
                currentCulture = context.Request.Form[_currentCultureRequestString].Trim();
            }
            else if (!String.IsNullOrEmpty(context.Request.QueryString[_currentCultureRequestString]))
            {
                currentCulture = context.Request.QueryString[_currentCultureRequestString].Trim();
            }

            //CHECK QUERYSTRING
            if (!String.IsNullOrEmpty(context.Request.QueryString[_languageQueryString]))
            {
                currentCulture = context.Request.QueryString[_languageQueryString];
            }
            //CHECK VERSION LANGUAGE
            if (!String.IsNullOrEmpty(context.Request.QueryString[_versionIdQueryString]))
            {
                int LangId    = -1;
                int versionId = int.Parse(context.Request.QueryString[_versionIdQueryString]);
                //get version language id
                using (IDataReader reader = PageVersion.GetVersionById(versionId))
                {
                    if (reader.Read())
                    {
                        LangId = (int)reader["LangId"];
                    }

                    reader.Close();
                }

                //get language name
                using (IDataReader lang = Language.LoadLanguage(LangId))
                {
                    if (lang.Read())
                    {
                        currentCulture = CultureInfo.CreateSpecificCulture(lang["LangName"].ToString()).Name;
                    }

                    lang.Close();
                }
            }

            if (currentCulture != string.Empty)
            {
                Thread.CurrentThread.CurrentCulture   = new CultureInfo(currentCulture);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(currentCulture);
            }
            else
            {
                //CHECK COOKIES
                if (context.Request.Cookies[_currentCultureCookieString] != null)
                {
                    cookie = (HttpCookie)context.Request.Cookies[_currentCultureCookieString];
                    Thread.CurrentThread.CurrentCulture   = new CultureInfo(cookie.Value);
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo(cookie.Value);
                }
                else
                {
                    // culture should be set to the one specified in the web.config file
                    //Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
                }
            }

            if (!String.IsNullOrEmpty(currentCulture))
            {
                //ConfigurationManager.AppSettings["HtmlEditorControl"];
                cookie         = new HttpCookie(_currentCultureCookieString);
                cookie.Expires = DateTime.Now.AddMonths(1);
                cookie.Value   = Thread.CurrentThread.CurrentCulture.Name;
                context.Response.Cookies.Add(cookie);
            }
        }