using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using digioz;
using digioz.admin;
using System.Text;
using System.Collections.Generic;

public partial class Admin : System.Web.UI.Page
{
    public ASP.controls_display_ascx ctlDisplay;
    public digioz.Hashtable coConfig = new digioz.Hashtable();
    public ASP.controls_box_ascx ctlBox;
    PortalSettings coPortalSettings;

    private void LoadConfiguration()
    {
        ConfigurationList loConfigurationList = ConfigurationManagement.GetConfigurationList();

        foreach (digioz.Configuration loConfig in loConfigurationList)
        {
            coConfig.AddToTable(loConfig.KeyName, loConfig.KeyValue);
        }
    }
   
    protected void Page_Load(object sender, EventArgs e)
    {
        if(Convert.ToInt16(Session["permission"]) != 3 || Session["username"] == null)
        {
            Response.Redirect("Login.aspx");
        }

        // Load Database Settings -----------------------
        coPortalSettings = PortalSettingsManagement.GetPortalSettings();

        // Load Configuration Hashtable -----------------
        LoadConfiguration();

        myStyleSheet.Href = (string)(coConfig.GetValue("Style Sheet")); 
        Page.Title = (string)(coConfig.GetValue("Site Title")) + "Admin Interface";
        Footer1.Text = "&#169; 2008 <a href=\"http://" + coConfig.GetValue("Site URL") + "\">DigiOz Multimedia</a>";

        // Set Banner Text ------------------------------
        Banner1.Text = "&nbsp;&nbsp;<br><br>" + (string)(coConfig.GetValue("Site Title"));
        LoadTopMenu();

        pnlMenuLeft.Controls.Clear();

        Control ctlControl = LoadControl("controls/Box.ascx");
        ctlBox = (ASP.controls_box_ascx)ctlControl;
        ctlBox.ID = "Box 1";
        ctlBox.BoxTitle = "Admin Menu";

        AdminMenuItemList loAdminMenuItemList = AdminMenuItemManagement.GetAdminMenuItemList();
        string lsMenuString = String.Empty;

        foreach (AdminMenuItem loAdminMenuItem in loAdminMenuItemList)
        {
            lsMenuString += "<a href=\"?id=" + loAdminMenuItem.ID + "\">" + loAdminMenuItem.Name + "</a><br />";
        }

        ctlBox.BoxDisplay = lsMenuString;
        pnlMenuLeft.Controls.Add(ctlBox);
        
        string id = Request["id"];
        int liID = Convert.ToInt16(Request["id"]);

        if (id != null)
        {
            int i_id = Convert.ToInt32(id);
            digioz.admin.AdminMenuItem loAdminMenuItem = digioz.admin.AdminMenuItemManagement.GetAdminMenuItemFromPageID(liID);
            ctlDisplay = this.Display1 as ASP.controls_display_ascx;
            ctlDisplay.DisplayControl = loAdminMenuItem.Data;
        }
        else
        {
            digioz.admin.AdminMenuItem loAdminMenuItem = digioz.admin.AdminMenuItemManagement.GetAdminMenuItemFromMenuName("Index");
            ctlDisplay = this.Display1 as ASP.controls_display_ascx;
            ctlDisplay.DisplayControl = loAdminMenuItem.Data;
        }
    }

    private void LoadTopMenu()
    {
        MenuTop1.Text = String.Empty;
        MenuTop1.Text += "<a class=\"menutopadmin\" href=\"Default.aspx\">Home</a>";
        MenuTop1.Text += " | ";
        MenuTop1.Text += "<a class=\"menutopadmin\" href=\"Login.aspx?mode=logout\">Logout</a>";
    }
}
