コード例 #1
0
ファイル: View.ascx.cs プロジェクト: Jochumzen/DisplayPlugg
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                PluggId = Convert.ToInt32(((DotNetNuke.Framework.CDefault)this.Page).Title);
                CultureCode = (Page as DotNetNuke.Framework.PageBase).PageCulture.Name;
                BaseHandler bh = new BaseHandler();
                pc = new PluggContainer(CultureCode, PluggId);
                if (pc.ThePlugg.IsDeleted)
                    Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(Convert.ToInt32(Localization.GetString("TabPluggDeleted.Text", LocalResourceFile))));
                InCreationLanguage = (pc.ThePlugg.CreatedInCultureCode == CultureCode);
                IsAuthorized = ((this.UserId != -1 && pc.ThePlugg.WhoCanEdit == EWhoCanEdit.Anyone) || pc.ThePlugg.CreatedByUserId == this.UserId || (UserInfo.IsInRole("Administator")));
                Edit = !string.IsNullOrEmpty(Page.Request.QueryString["edit"]) ? Convert.ToInt16(Page.Request.QueryString["edit"]) : -1;
                Translate = !string.IsNullOrEmpty(Page.Request.QueryString["translate"]) ? Convert.ToInt16(Page.Request.QueryString["translate"]) : -1;
                Remove = !string.IsNullOrEmpty(Page.Request.QueryString["remove"]) ? Convert.ToInt16(Page.Request.QueryString["remove"]) : -1;
                DisplayInfo = !string.IsNullOrEmpty(Page.Request.QueryString["info"]) ? Convert.ToInt16(Page.Request.QueryString["info"]) : -1;

                #region hide/display controls
                hlDisplayInfo.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(TabId, "", "info=0");
                if(DisplayInfo == 0)
                {
                    pnlDisplayInfo.Visible = false;
                    pnlHideDisplayInfo.Visible = true;
                    hlHideDisplayInfo.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(TabId, "", "");
                }

                if (Remove > 0 && IsAuthorized)
                {
                    bh.DeleteComponent(pc, Remove);
                    Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(TabId, "", "edit=0"));
                }

                if (!InCreationLanguage && UserId > -1 && Translate == -1)
                {
                    pnlToCreationLanguage.Visible = true;
                    hlToCreationLanguage.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(TabId, "", "language=" + pc.ThePlugg.CreatedInCultureCode);
                    pnlTranslatePlugg.Visible = true;
                    hlTranslatePlugg.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(TabId, "", "translate=0");
                }

                if (InCreationLanguage && UserId > -1 && Edit == -1)
                {
                    pnlEditPlugg.Visible = true;
                    hlEditPlugg.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(TabId, "", "edit=0");
                }

                if (!InCreationLanguage && UserId > -1 && Translate > -1)
                {
                    pnlExitTranslateMode.Visible = true;
                    hlExitTranslateMode.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(TabId, "", "");
                }

                if (InCreationLanguage && UserId > -1 && Edit > -1)
                {
                    pnlExitEditMode.Visible = true;
                    hlExitEditMode.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(TabId, "", "");
                }
                #endregion

                pc.LoadComponents();
                phComponents.Controls.Clear();
                int controlOrder = 1;
                bool editOrTranslateMode = (Edit > -1 || Translate > -1) && UserId > -1;

                if (DisplayInfo == 0)
                {
                    DisplayPluggInfo ucDPI = (DisplayPluggInfo)this.LoadControl("/DesktopModules/DisplayPlugg/DisplayPluggInfo.ascx");
                    if (ucDPI != null)
                    {
                        ucDPI.LocalResourceFile = "/DesktopModules/DisplayPlugg/App_LocalResources/DisplayPluggInfo.ascx";
                        phComponents.Controls.Add(ucDPI);
                    }
                }

                if (editOrTranslateMode)
                {
                    string ComponentHead = "<hr /><h3>" + Localization.GetString("Subject", LocalResourceFile) + "</h3>";
                    phComponents.Controls.Add(new LiteralControl(ComponentHead));
                }
                LoadSubject(controlOrder);
                controlOrder++;

                if (editOrTranslateMode)
                {
                    string ComponentHead = "<hr /><h3>" + Localization.GetString("Title", LocalResourceFile) + "</h3>";
                    phComponents.Controls.Add(new LiteralControl(ComponentHead));
                    EditTitleAndDescription(controlOrder, ETextItemType.PluggTitle);
                    controlOrder++;

                    ComponentHead = "<hr /><h3>" + Localization.GetString("Description", LocalResourceFile) + "</h3>";
                    phComponents.Controls.Add(new LiteralControl(ComponentHead));
                    EditTitleAndDescription(controlOrder, ETextItemType.PluggDescription);
                    controlOrder++;
                }

                #region AddComponents
                int componentOrder = 1;
                foreach (PluggComponent c in pc.TheComponents)
                {
                    if (Edit == 0 && IsAuthorized)
                        Add_AddNewComponentControl(componentOrder);
                    if (editOrTranslateMode)
                    {
                        string ComponentHead = "<hr /><h3>" + Localization.GetString("Component", LocalResourceFile) + " " + c.ComponentOrder + ":  " + c.ComponentType + "</h3>";
                        phComponents.Controls.Add(new LiteralControl(ComponentHead));
                    }
                    switch (c.ComponentType)
                    {
                        case EComponentType.YouTube:
                            LoadYouTube(c, controlOrder);
                            break;
                        case EComponentType.Label:
                            LoadLabel(c, controlOrder);
                            break;
                        case EComponentType.RichRichText:
                            LoadRichRich(c, controlOrder);
                            break;
                        case EComponentType.RichText:
                            LoadRich(c, controlOrder);
                            break;
                        case EComponentType.Latex:
                            LoadLatex(c, controlOrder);
                            break;
                        default:
                            break;
                    }
                    HyperLink hl = new HyperLink();
                    if (Edit == 0 && IsAuthorized)
                    {
                        hl.Text = "Remove Component";
                        hl.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(TabId, "", "remove=" + componentOrder);
                        phComponents.Controls.Add(hl);
                    }
                    controlOrder++;
                    componentOrder++;
                }
                if (Edit == 0 && IsAuthorized)
                    Add_AddNewComponentControl(componentOrder);
                if (editOrTranslateMode)
                    phComponents.Controls.Add(new LiteralControl("<hr />"));

                #endregion
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
コード例 #2
0
ファイル: BaseHandler.cs プロジェクト: Jochumzen/PlugghestLib
        public void DeletePlugg(Plugg p)
        {
            // Todo: Don't delete Plugg if: It has comments or ratings or its included in a course.
            if (p == null)
            {
                throw new Exception("Cannot delete: Plugg not initialized");
            }

            //Delete Plugg page
            if (p.TabId != 0)
            {
                DNNHelper h = new DNNHelper();
                h.DeleteTab(p.TabId);
            }

            //Delete Plugg title and Plugg description
            rep.DeleteAllPhTextForItem(p.PluggId, ETextItemType.PluggTitle);
            rep.DeleteAllPhTextForItem(p.PluggId, ETextItemType.PluggDescription);

            //Delete all Pluggcomponents
            PluggContainer pc = new PluggContainer("en-us", p.PluggId);
            pc.LoadComponents();
            foreach (PluggComponent c in pc.TheComponents)
            {
                switch (c.ComponentType)
                {
                    case EComponentType.YouTube:
                        YouTube yt = GetYouTubeByComponentId(c.PluggComponentId);
                        if (yt!=null)
                            rep.DeleteYouTube(yt);
                        break;
                    case EComponentType.RichRichText:
                        rep.DeleteAllPhTextForItem(c.PluggComponentId, ETextItemType.PluggComponentRichRichText);
                        break;
                    case EComponentType.RichText:
                        rep.DeleteAllPhTextForItem(c.PluggComponentId, ETextItemType.PluggComponentRichText);
                        break;
                    case EComponentType.Label:
                        rep.DeleteAllPhTextForItem(c.PluggComponentId, ETextItemType.PluggComponentLabel);
                        break;
                    case EComponentType.Latex:
                        rep.DeleteAllLatexForItem(c.PluggComponentId, ELatexItemType.PluggComponentLatex);
                        break;
                    default:
                        break;
                }
                rep.DeletePluggComponent(c);
            }

            //Delete Pluggentity
            rep.DeletePlugg(p);
        }