protected void btnSave_Click(object sender, EventArgs e)
        {
            if (rbEditorSelection.SelectedIndex == 0)
            {
                Html_Text.Text = FCKeditor1.Value;
            }
            else
            {
                FCKeditor1.Value = Html_Text.Text;
            }

            SqlServer sqlServer = new SqlServer(Util.SqlConnectionString());
            sqlServer.JMD_MOD_HTML_SAVE(hdnPageModID.Value, string.Empty,
                Server.HtmlEncode(Html_Text.Text).Replace("'", "'"));
            lblMessage.Text = "Successfully saved the content";
        }
        private void SavePage()
        {
            try
            {
                int returnNumber = -1;
                int sortNumber = 0;
                int childPageNumber = -1;
                string pageModID = "0";
                string pageName = txtPageName.Text.Replace("'", "''");
                string pageCaption = txtPageCaption.Text.Replace("'", "''");
                string metaTitle = txtMetaTitle.Text.Replace("'", "''");
                string metaDesc = txtMetaDescription.Text.Replace("'", "''");
                string metaKey = txtMetaKeywords.Text.Replace("'", "''");

                CMSBL cmsBL = new CMSBL();

                if (lblTitle.Text == "Add Page")
                {
                    bool duplicatePage = cmsBL.DuplicatePageName(hdnSiteID.Value, pageName);

                    if (duplicatePage)
                    {
                        lblMessage.Text = "Duplicate Page Name";
                        lblMessage.ForeColor = System.Drawing.Color.Red;
                        return;
                    }
                }

                SqlServer sqlServer = new SqlServer(Util.SqlConnectionString()); ;

                string isPublished = "";
                if (rbYes.Checked)
                    isPublished = "1";
                else if (rbNo.Checked)
                    isPublished = "0";

                //sortNumber = cmsBL.GetDuplicatePageSort(hdnSiteID.Value, hdnPageID.Value, ddlSortNumber.SelectedValue);

                if (sortNumber == 0)
                {
                    childPageNumber = cmsBL.JMD_PAGE_SAVE(hdnChildPageID.Value, hdnSiteName.Value, pageName, pageCaption,
                    metaTitle, metaDesc, metaKey, "",
                    isPublished, "0", "0", "Admin", "Admin", "Admin", "Admin", "Admin", "Admin", "0", "0", "0", "1");

                    if (lblTitle.Text == "Update Page")
                    {
                        DataSet dsPageMod = new DataSet();
                        dsPageMod = sqlServer.JMD_LOAD_MODS(hdnSiteName.Value, pageName);
                        if (dsPageMod.Tables[0].Rows.Count > 0)
                        {
                            DataRow[] dr = dsPageMod.Tables[0].Select("PAGE_NAME='" + pageName + "'");
                            if (dr.Length > 0)
                                pageModID = dr[0]["PAGE_MOD_ID"].ToString();
                        }

                        returnNumber = cmsBL.UpdateTreeview(hdnSiteID.Value, hdnPageID.Value, childPageNumber.ToString(), ddlSortNumber.SelectedValue, _userName);
                    }
                    else
                    {
                        returnNumber = cmsBL.CreateTreeview(hdnSiteID.Value, hdnPageID.Value, childPageNumber.ToString(), ddlSortNumber.SelectedValue, _userName);
                    }

                    sqlServer.JMD_PAGE_MOD_SAVE(pageModID, hdnSiteName.Value, pageName, "7",
                    "Mod_" + pageName, "7", "1", "0", "Admin;Guests;Registered;",
                    "Admin;", "Admin;", "Admin;", "Admin;", "0");

                    if (lblTitle.Text == "Add Page")
                    {
                        lblMessage.Text = "Successfully added the new Page.";
                    }
                    else
                    {
                        lblMessage.Text = "Successfully updated the Page.";
                    }
                    lblMessage.ForeColor = System.Drawing.Color.Green;

                }
                else
                {
                    lblMessage.Text = "Sort Number already exist.";
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = "Page Not Updated.";
                lblMessage.ForeColor = System.Drawing.Color.Red;
            }
        }
        protected void btnManagePage_Click(object sender, EventArgs e)
        {
            try
            {
                string pageModID = "0";
                SqlServer sqlServer = new SqlServer(Util.SqlConnectionString()); ;
                DataSet dsPageMod = new DataSet();

                int rowNumber = 0;
                rowNumber = GetSelectedRow();
                if (rowNumber >= 0)
                {
                    string pageID = dgPages.Items[rowNumber].Cells[0].Text;
                    string pageName = dgPages.Items[rowNumber].Cells[1].Text;

                    dsPageMod = sqlServer.JMD_LOAD_MODS(lblSiteName.Text, pageName);
                    if (dsPageMod.Tables[0].Rows.Count > 0)
                    {
                        DataRow[] dr = dsPageMod.Tables[0].Select("ID='" + pageID + "'");
                        if (dr.Length > 0)
                            pageModID = dr[0]["PAGE_MOD_ID"].ToString();
                        //pageModID = dsPageMod.Tables[0].Rows[0]["PAGE_MOD_ID"].ToString();
                    }
                    Response.Redirect("../CMS/HTMLEdit.aspx?PageModId=" + pageModID + "&PageName=" + pageName + "&companyName=" + lblCompanyName.Text +
                        "&siteName=" + lblSiteName.Text + "&outlineName=" + lblOutlineName.Text + "&siteID=" + hdnSiteID.Value + "&pageID=" + hdnPageID.Value);
                }

            }
            catch (Exception ex)
            {

            }
        }
        public void CheckPageAuth(string SqlConnectionString, string Site_Url,
            string Page_Name)
        {
            //IPrincipal p = HttpContext.Current.User;
            IPrincipal p = HttpContext.Current.User;

            if (p.IsInRole("Admin"))
            {
                isAdmin = true;
                pageView = true;
                pageAdd = true;
                pageEdit = true;
                pageDelete = true;
                pageMove = true;
                pageAddModules = true;
            }
            else
            {
                SqlServer sqlServer = new SqlServer(SqlConnectionString);
                DataTable dt = sqlServer.JMD_PAGE_AUTH(Site_Url, Page_Name);
                if (dt.Rows.Count > 0)
                {
                    //string[] roles = authTicket.UserData.Split(new char[] { ';' });
                    string[] ViewRoles = dt.Rows[0]["VIEW_ROLES"].ToString().Split(new char[] { ';' });
                    string[] AddRoles = dt.Rows[0]["ADD_ROLES"].ToString().Split(new char[] { ';' });
                    string[] EditRoles = dt.Rows[0]["EDIT_ROLES"].ToString().Split(new char[] { ';' });
                    string[] MoveRoles = dt.Rows[0]["MOVE_ROLES"].ToString().Split(new char[] { ';' });
                    string[] DeleteRoles = dt.Rows[0]["DELETE_ROLES"].ToString().Split(new char[] { ';' });
                    string[] AddModuleRoles = dt.Rows[0]["ADD_MODULE_ROLES"].ToString().Split(new char[] { ';' });
                    foreach (string Role in ViewRoles)
                    {
                        if ((p.IsInRole(Role) && (string.Compare(Role.Trim(), string.Empty) != 0)) ||
                            (String.Compare(Role, "Guests", true) == 0))
                        {
                            pageView = true;
                            break;
                        }
                        else if ((p.Identity.IsAuthenticated) && (String.Compare(Role, "Registered", true) == 0))
                        {
                            pageView = true;
                            break;
                        }
                    }
                    foreach (string Role in AddRoles)
                    {
                        if (p.IsInRole(Role) && (string.Compare(Role.Trim(), string.Empty) != 0))
                        {
                            pageAdd = true;
                            break;
                        }
                        else if ((p.Identity.IsAuthenticated) && (String.Compare(Role, "Registered", true) == 0))
                        {
                            pageAdd = true;
                            break;
                        }
                    }

                    foreach (string Role in EditRoles)
                    {
                        if (p.IsInRole(Role) && (string.Compare(Role.Trim(), string.Empty) != 0))
                        {
                            pageEdit = true;
                            break;
                        }
                        else if ((p.Identity.IsAuthenticated) && (String.Compare(Role, "Registered", true) == 0))
                        {
                            pageEdit = true;
                            break;
                        }
                    }
                    foreach (string Role in DeleteRoles)
                    {
                        if (p.IsInRole(Role) && (string.Compare(Role.Trim(), string.Empty) != 0))
                        {
                            pageDelete = true;
                            break;
                        }

                        else if ((p.Identity.IsAuthenticated) && (String.Compare(Role, "Registered", true) == 0))
                        {
                            pageDelete = true;
                            break;
                        }
                    }
                    foreach (string Role in MoveRoles)
                    {
                        if (p.IsInRole(Role) && (string.Compare(Role.Trim(), string.Empty) != 0))
                        {
                            pageMove = true;
                            break;
                        }

                        else if ((p.Identity.IsAuthenticated) && (String.Compare(Role, "Registered", true) == 0))
                        {
                            pageMove = true;
                            break;
                        }
                    }
                    foreach (string Role in AddModuleRoles)
                    {
                        if (p.IsInRole(Role) && (string.Compare(Role.Trim(), string.Empty) != 0))
                        {
                            pageAddModules = true;
                            break;
                        }
                        else if ((p.Identity.IsAuthenticated) && (String.Compare(Role, "Registered", true) == 0))
                        {
                            pageAddModules = true;
                            break;
                        }
                    }
                }
                dt.Dispose();
                sqlServer = null;
            }
        }
        private void SavePage()
        {
            try
            {
                int returnNumber = -1;
                int childPageNumber = -1;
                string pageModID = "0";
                string pageName = txtPageName.Text.Replace("'", "''");
                string pageCaption = txtPageCaption.Text.Replace("'", "''");
                string metaTitle = txtMetaTitle.Text.Replace("'", "''");
                string metaDesc = txtMetaDescription.Text.Replace("'", "''");
                string metaKey = txtMetaKeywords.Text.Replace("'", "''");

                CMSBL cmsBL = new CMSBL();
                if (lblTitle.Text == "Add Page")
                {
                    bool duplicatePage = cmsBL.DuplicatePageName(hdnSiteID.Value, pageName);

                    if (duplicatePage)
                    {
                        lblMessage.Text = "Duplicate Page Name";
                        lblMessage.ForeColor = System.Drawing.Color.Red;
                        return;
                    }
                }

                SqlServer sqlServer = new SqlServer(Util.SqlConnectionString());

                childPageNumber = cmsBL.JMD_PAGE_SAVE(hdnChildPageID.Value, hdnSiteName.Value, pageName, pageCaption,
                metaTitle, metaDesc, metaKey, "",
                "1", "0", "0", "Admin", "Admin", "Admin", "Admin", "Admin", "Admin", "0", "0", "0", "1");

                if (lblTitle.Text == "Update Page")
                {
                    DataSet dsPageMod = new DataSet();
                    dsPageMod = sqlServer.JMD_LOAD_MODS(hdnSiteName.Value, pageName);
                    if (dsPageMod.Tables[0].Rows.Count > 0)
                    {
                        DataRow[] dr = dsPageMod.Tables[0].Select("PAGE_NAME='" + pageName + "'");
                        if (dr.Length > 0)
                            pageModID = dr[0]["PAGE_MOD_ID"].ToString();
                    }
                }

                sqlServer.JMD_PAGE_MOD_SAVE(pageModID, hdnSiteName.Value, pageName, "7",
                    "Mod_" + pageName, "7", "1", "0", "Admin;Guests;Registered;",
                    "Admin;", "Admin;", "Admin;", "Admin;", "0");

                lblMessage.Text = "Page Updated Successfully";
                lblMessage.ForeColor = System.Drawing.Color.Green;

            }
            catch (Exception ex)
            {
                lblMessage.Text = "Page Not Updated";
                lblMessage.ForeColor = System.Drawing.Color.Red;
            }
        }
        private void LoadContentDetails()
        {
            FCKeditor1.ID = "FCKeditor1";
            FCKeditor1.UseBROnCarriageReturn = true;
            FCKeditor1.FormatSource = false;

            Html_Text.ID = "Html_Text";
            /*string PageParams = Util.PageParams(Request.QueryString["Pg"].ToString());
            string PageModId = string.Empty;
            if (string.Compare(PageParams, String.Empty) != 0)
            {
                string[] ParamParts = PageParams.Split(new char[] { ',' });
                PageModId = ParamParts[0].Split(new char[] { '=' })[1].ToString();
            }*/

            hdnPageModID.Value = Request.QueryString["PageModId"].ToString();
            hdnPageName.Value = Request.QueryString["PageName"].ToString();

            SqlServer sqlServer = new SqlServer(Util.SqlConnectionString());
            DataTable dt;
            dt = sqlServer.JMD_MOD_HTML_Select(hdnPageModID.Value);

            if (dt.Rows.Count > 0)
            {
                //Literal1.Text = String.Format("<Div id=\"{0}\">", DivMod[0].ToString());
                Html_Text.Text += Server.HtmlDecode(dt.Rows[0]["HTML_TEXT"].ToString().Replace("&#39;", "'"));
                //Literal1.Text += "</Div>";
                FCKeditor1.Value = Server.HtmlDecode(dt.Rows[0]["HTML_TEXT"].ToString().Replace("&#39;", "'"));
            }
            dt.Dispose();
            sqlServer = null;
        }