protected void Page_Init( Object sender, EventArgs e )
        {
            ModuleController objModules = new ModuleController();
            ModuleControlController objModuleControlController = new ModuleControlController();

            // get ModuleId
            if( ( Request.QueryString["ModuleId"] != null ) )
            {
                moduleId = int.Parse( Request.QueryString["ModuleId"] );
            }

            // get module
            ModuleInfo objModule = objModules.GetModule( moduleId, TabId, false );
            if( objModule != null )
            {
                tabModuleId = objModule.TabModuleID;

                //get Settings Control(s)
                ArrayList arrModuleControls = objModuleControlController.GetModuleControlsByKey( "Settings", objModule.ModuleDefID );

                if( arrModuleControls.Count > 0 )
                {
                    ModuleControlInfo objModuleControlInfo = (ModuleControlInfo)arrModuleControls[0];
                    string src = "~/" + objModuleControlInfo.ControlSrc;
                    ctlSpecific = (ModuleSettingsBase)LoadControl( src );
                    ctlSpecific.ID = src.Substring( src.LastIndexOf( "/" ) + 1 );
                    ctlSpecific.ModuleId = moduleId;
                    ctlSpecific.TabModuleId = tabModuleId;
                    dshSpecific.Text = Localization.LocalizeControlTitle( objModuleControlInfo.ControlTitle, objModuleControlInfo.ControlSrc, "settings" );
                    pnlSpecific.Controls.Add( ctlSpecific );

                    if( Localization.GetString( ModuleActionType.HelpText, ctlSpecific.LocalResourceFile ) != "" )
                    {
                        rowspecifichelp.Visible = true;
                        imgSpecificHelp.AlternateText = Localization.GetString( ModuleActionType.ModuleHelp, Localization.GlobalResourceFile );
                        lnkSpecificHelp.Text = Localization.GetString( ModuleActionType.ModuleHelp, Localization.GlobalResourceFile );
                        lnkSpecificHelp.NavigateUrl = Globals.NavigateURL( TabId, "Help", "ctlid=" + objModuleControlInfo.ModuleControlID, "moduleid=" + moduleId );
                    }
                    else
                    {
                        rowspecifichelp.Visible = false;
                    }
                }
            }
        }
        private void Page_Init( object sender, EventArgs e )
        {
            ModuleController objModules = new ModuleController();
            ModuleInfo objModule;
            Control ctlPane;
            bool blnLayoutMode = Globals.IsLayoutMode();

            bool bSuccess = true;

            // iterate page controls

            foreach (Control ctlControl in this.Controls)
            {
                
                // load the skin panes
                if (ctlControl is HtmlControl)
                {
                    HtmlControl objHtmlControl = (HtmlControl)ctlControl;
                    if (objHtmlControl.ID != null)
                    {
                        switch (objHtmlControl.TagName.ToUpper())
                        {
                            case "TD":
                                // content pane
                                if (ctlControl.ID != "ControlPanel")
                                {
                                    PortalSettings.ActiveTab.Panes.Add(ctlControl.ID);
                                }
                                break;

                            case "DIV":
                                // content pane
                                if (ctlControl.ID != "ControlPanel")
                                {
                                    PortalSettings.ActiveTab.Panes.Add(ctlControl.ID);
                                }
                                break;

                            case "SPAN":
                                // content pane
                                if (ctlControl.ID != "ControlPanel")
                                {
                                    PortalSettings.ActiveTab.Panes.Add(ctlControl.ID);
                                }
                                break;

                            case "P":

                                // content pane
                                if (ctlControl.ID != "ControlPanel")
                                {
                                    PortalSettings.ActiveTab.Panes.Add(ctlControl.ID);
                                }
                                break;
                        }
                    }
                }
            }

            //if querystring dnnprintmode=true, controlpanel will not be shown
            if (Request.QueryString["dnnprintmode"] != "true")
            {
                // ControlPanel processing
                if (PortalSecurity.IsInRoles(PortalSettings.AdministratorRoleName.ToString()) || PortalSecurity.IsInRoles(PortalSettings.ActiveTab.AdministratorRoles.ToString()))
                {
                    UserControl objControlPanel = null;
                    if (Convert.ToString(PortalSettings.HostSettings["ControlPanel"]) != "")
                    {
                        // load custom control panel
                        objControlPanel = (UserControl)LoadControl("~/" + Convert.ToString(PortalSettings.HostSettings["ControlPanel"]));
                    }
                    if (objControlPanel == null)
                    {
                        // load default control panel
                        objControlPanel = (UserControl)LoadControl("~/" + Globals.glbDefaultControlPanel);
                    }
                    // inject ControlPanel control into skin
                    ctlPane = this.FindControl("ControlPanel");
                    if (ctlPane == null)
                    {
                        HtmlForm objForm = (HtmlForm)this.Parent.FindControl("Form");
                        objForm.Controls.AddAt(0, objControlPanel);
                    }
                    else
                    {
                        ctlPane.Controls.Add(objControlPanel);
                    }
                }
            }

            if (!Globals.IsAdminControl()) // master module
            {
                if (PortalSecurity.IsInRoles(PortalSettings.ActiveTab.AuthorizedRoles))
                {
                    // check portal expiry date
                    bool blnExpired = false;
                    if (PortalSettings.ExpiryDate != Null.NullDate)
                    {
                        if (Convert.ToDateTime(PortalSettings.ExpiryDate) < DateTime.Now && PortalSettings.ActiveTab.ParentId != PortalSettings.AdminTabId && PortalSettings.ActiveTab.ParentId != PortalSettings.SuperTabId)
                        {
                            blnExpired = true;
                        }
                    }
                    if (!blnExpired)
                    {
                        if ((PortalSettings.ActiveTab.StartDate < DateTime.Now && PortalSettings.ActiveTab.EndDate > DateTime.Now) || blnLayoutMode)
                        {
                            // process panes
                            if (blnLayoutMode)
                            {
                                foreach (string strPane in PortalSettings.ActiveTab.Panes)
                                {                                    
                                    ctlPane = this.FindControl(strPane);
                                    ctlPane.Visible = true;

                                    // display pane border
                                    if (ctlPane is HtmlContainerControl)
                                    {
                                        ((HtmlContainerControl)ctlPane).Style["border-top"] = "1px #CCCCCC dotted";
                                        ((HtmlContainerControl)ctlPane).Style["border-bottom"] = "1px #CCCCCC dotted";
                                        ((HtmlContainerControl)ctlPane).Style["border-right"] = "1px #CCCCCC dotted";
                                        ((HtmlContainerControl)ctlPane).Style["border-left"] = "1px #CCCCCC dotted";
                                    }

                                    // display pane name
                                    Label ctlLabel = new Label();
                                    ctlLabel.Text = "<center>" + strPane + "</center><br>";
                                    ctlLabel.CssClass = "SubHead";
                                    ctlPane.Controls.AddAt(0, ctlLabel);
                                }
                            }

                            // dynamically populate the panes with modules
                            if (PortalSettings.ActiveTab.Modules.Count > 0)
                            {
                                // loop through each entry in the configuration system for this tab
                                foreach (ModuleInfo tempLoopVar_objModule in PortalSettings.ActiveTab.Modules)
                                {
                                    objModule = tempLoopVar_objModule;

                                    // if user is allowed to view module and module is not deleted
                                    if (PortalSecurity.IsInRoles(objModule.AuthorizedViewRoles) && objModule.IsDeleted == false)
                                    {
                                        // if current date is within module display schedule or user is admin
                                        if ((objModule.StartDate < DateTime.Now && objModule.EndDate > DateTime.Now) || blnLayoutMode)
                                        {
                                            // modules which are displayed on all tabs should not be displayed on the Admin or Super tabs
                                            if (objModule.AllTabs == false || PortalSettings.ActiveTab.IsAdminTab == false)
                                            {
                                                Control parent = this.FindControl(objModule.PaneName);

                                                if (parent == null)
                                                {
                                                    // the pane specified in the database does not exist for this skin
                                                    // insert the module into the default pane instead
                                                    parent = this.FindControl(Globals.glbDefaultPane);
                                                }

                                                if (parent != null)
                                                {
                                                    // try to localize admin modules
                                                    if (PortalSettings.ActiveTab.IsAdminTab)
                                                    {
                                                        objModule.ModuleTitle = Localization.LocalizeControlTitle(objModule.ModuleTitle, objModule.ControlSrc, "");
                                                    }

                                                    //try to inject the module into the skin
                                                    try
                                                    {
                                                        InjectModule(parent, objModule, PortalSettings);
                                                    }
                                                    catch (Exception)
                                                    {
                                                        bSuccess = false;
                                                    }
                                                }
                                                else // no ContentPane in skin
                                                {
                                                    ModuleLoadException lex;
                                                    lex = new ModuleLoadException(PANE_LOAD_ERROR);
                                                    Controls.Add(new ErrorContainer(PortalSettings, MODULELOAD_ERROR, lex).Container);
                                                    Exceptions.LogException(lex);
                                                    Information.Err().Clear();
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            Skin.AddPageMessage(this, "", TABACCESS_ERROR, ModuleMessageType.YellowWarning);
                        }
                    }
                    else
                    {
                        Skin.AddPageMessage(this, "", string.Format(CONTRACTEXPIRED_ERROR, PortalSettings.PortalName, Globals.GetMediumDate(PortalSettings.ExpiryDate.ToString()), PortalSettings.Email), ModuleMessageType.RedError);
                    }
                }
                else
                {
                    Response.Redirect(Globals.AccessDeniedURL(TABACCESS_ERROR), true);
                }
            }
            else // slave module
            {
                int ModuleId = -1;
                string Key = "";
                ModuleInfo slaveModule = null;

                // get ModuleId
                if (Request.QueryString["mid"] != null)
                {
                    ModuleId = Int32.Parse(Request.QueryString["mid"]);
                }

                // get ControlKey
                if (Request.QueryString["ctl"] != null)
                {
                    Key = Request.QueryString["ctl"];
                }

                // initialize moduleid for modulesettings
                if (Request.QueryString["moduleid"] != null & (Key.ToLower() == "module" | Key.ToLower() == "help"))
                {
                    ModuleId = Int32.Parse(Request.QueryString["moduleid"]);
                }

                if (ModuleId != -1)
                {
                    // get master module security settings
                    objModule = objModules.GetModule(ModuleId, PortalSettings.ActiveTab.TabID, false);
                    if (objModule != null)
                    {
                        //Clone the Master Module as we do not want to modify the cached module
                        slaveModule = objModule.Clone();
                        if (slaveModule.InheritViewPermissions)
                        {
                            slaveModule.AuthorizedViewRoles = PortalSettings.ActiveTab.AuthorizedRoles;
                        }
                    }
                }

                if (slaveModule == null)
                {
                    // initialize object not related to a module
                    slaveModule = new ModuleInfo();
                    slaveModule.ModuleID = ModuleId;
                    slaveModule.ModuleDefID = -1;
                    slaveModule.TabID = PortalSettings.ActiveTab.TabID;
                    slaveModule.AuthorizedEditRoles = "";
                    slaveModule.AuthorizedViewRoles = "";
                    ModulePermissionController objModulePermissionController = new ModulePermissionController();
                    slaveModule.ModulePermissions = objModulePermissionController.GetModulePermissionsCollectionByModuleID(slaveModule.ModuleID, slaveModule.TabID);
                }

                // initialize moduledefid for modulesettings
                if (Request.QueryString["moduleid"] != null & (Key.ToLower() == "module" | Key.ToLower() == "help"))
                {
                    slaveModule.ModuleDefID = -1;
                }

                // override slave module settings
                if (Request.QueryString["dnnprintmode"] != "true")
                {
                    slaveModule.ModuleTitle = "";
                }
                slaveModule.Header = "";
                slaveModule.Footer = "";
                slaveModule.StartDate = DateTime.MinValue;
                slaveModule.EndDate = DateTime.MaxValue;
                slaveModule.PaneName = Globals.glbDefaultPane;
                slaveModule.Visibility = VisibilityState.None;
                slaveModule.Color = "";
                if (Request.QueryString["dnnprintmode"] != "true")
                {
                    slaveModule.Alignment = "center";
                }
                slaveModule.Border = "";
                slaveModule.DisplayTitle = true;
                slaveModule.DisplayPrint = false;
                slaveModule.DisplaySyndicate = false;

                // get portal container for slave module
                if (PortalSettings.PortalContainer != null)
                {
                    slaveModule.ContainerSrc = PortalSettings.PortalContainer.SkinSrc;
                }
                if (string.IsNullOrEmpty(slaveModule.ContainerSrc))
                {
                    slaveModule.ContainerSrc = "[G]" + SkinInfo.RootContainer + Globals.glbDefaultContainerFolder + Globals.glbDefaultContainer;
                }
                slaveModule.ContainerSrc = SkinController.FormatSkinSrc(slaveModule.ContainerSrc, PortalSettings);
                slaveModule.ContainerPath = SkinController.FormatSkinPath(slaveModule.ContainerSrc);

                // get the pane
                Control parent = this.FindControl(slaveModule.PaneName);

                // load the controls
                ModuleControlController objModuleControls = new ModuleControlController();

                ArrayList arrModuleControls = objModuleControls.GetModuleControlsByKey(Key, slaveModule.ModuleDefID);

                for (int intCounter = 0; intCounter < arrModuleControls.Count; intCounter++)
                {
                    ModuleControlInfo objModuleControl = (ModuleControlInfo)(arrModuleControls[intCounter]);

                    // initialize control values
                    slaveModule.ModuleControlId = objModuleControl.ModuleControlID;
                    slaveModule.ControlSrc = objModuleControl.ControlSrc;
                    slaveModule.ControlType = objModuleControl.ControlType;
                    slaveModule.IconFile = objModuleControl.IconFile;
                    slaveModule.HelpUrl = objModuleControl.HelpURL;

                    if (!(Null.IsNull(objModuleControl.ControlTitle)))
                    {
                        // try to localize control title
                        slaveModule.ModuleTitle = Localization.LocalizeControlTitle(objModuleControl.ControlTitle, slaveModule.ControlSrc, Key);
                    }

                    // verify that the current user has access to this control
                    bool blnAuthorized = true;
                    if (slaveModule.ControlType == SecurityAccessLevel.Anonymous) // anonymous
                    {
                    }
                    else if (slaveModule.ControlType == SecurityAccessLevel.View) // view
                    {
                        if (PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName) == false & PortalSecurity.IsInRoles(PortalSettings.ActiveTab.AdministratorRoles.ToString()) == false)
                        {
                            if (!(PortalSecurity.IsInRoles(slaveModule.AuthorizedViewRoles)))
                            {
                                blnAuthorized = false;
                            }
                        }
                    }
                    else if (slaveModule.ControlType == SecurityAccessLevel.Edit) // edit
                    {
                        if (PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName) == false & PortalSecurity.IsInRoles(PortalSettings.ActiveTab.AdministratorRoles.ToString()) == false)
                        {
                            if (!(PortalSecurity.IsInRoles(slaveModule.AuthorizedViewRoles)))
                            {
                                blnAuthorized = false;
                            }
                            else
                            {
                                if (!(PortalSecurity.HasEditPermissions(slaveModule.ModulePermissions)))
                                {
                                    blnAuthorized = false;
                                }
                            }
                        }
                    }
                    else if (slaveModule.ControlType == SecurityAccessLevel.Admin) // admin
                    {
                        if (PortalSecurity.IsInRole(PortalSettings.AdministratorRoleName) == false & PortalSecurity.IsInRoles(PortalSettings.ActiveTab.AdministratorRoles.ToString()) == false)
                        {
                            blnAuthorized = false;
                        }
                    }
                    else if (slaveModule.ControlType == SecurityAccessLevel.Host) // host
                    {
                        UserInfo objUserInfo = UserController.GetCurrentUserInfo();
                        if (!objUserInfo.IsSuperUser)
                        {
                            blnAuthorized = false;
                        }
                    }

                    if (blnAuthorized)
                    {
                        //try to inject the module into the skin
                        try
                        {
                            InjectModule(parent, slaveModule, PortalSettings);
                        }
                        catch (Exception)
                        {
                            bSuccess = false;
                        }
                    }
                    else
                    {
                        Response.Redirect(Globals.AccessDeniedURL(MODULEACCESS_ERROR), true);
                    }

                }

            }

            if (!blnLayoutMode)
            {
                CollapseUnusedPanes();
            }

            if (Request.QueryString["error"] != null)
            {
                Skin.AddPageMessage(this, CRITICAL_ERROR, Server.HtmlEncode(Request.QueryString["error"]), ModuleMessageType.RedError);
            }

            if (!(PortalSecurity.IsInRoles(PortalSettings.AdministratorRoleName) | PortalSecurity.IsInRoles(PortalSettings.ActiveTab.AdministratorRoles.ToString())))
            {
                // only display the warning to non-administrators (adminsitrators will see the errors)
                if (!bSuccess)
                {
                    Skin.AddPageMessage(this, MODULELOAD_WARNING, string.Format(MODULELOAD_WARNINGTEXT, PortalSettings.Email), ModuleMessageType.YellowWarning);
                }
            }
        }