Imports System.Web.Configuration
Imports Superbowl.sqlDB

Partial Public Class index
  Inherits System.Web.UI.Page
	Public blnDebug As Boolean = CBool(WebConfigurationManager.AppSettings("blnDebug"))
	Public Shared blnRunOnce As Boolean = False

	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

		FormsAuthentication.SignOut()
		WebConfigurationManager.AppSettings("UDOMAIN") = ""
  End Sub

	Protected Sub btnLogin_click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLogin.Click
		Dim ds As DataSet
		Dim db As New sqlDB
		Dim s As String

    s = Request.LogonUserIdentity.Name.ToUpper()
    lblMessage.Text = s & "<br>"

		Try

			ds = db.doQueryDS(db.sql_get_Users(s, "Superbowl"))
         If ds.Tables(0).Rows.Count > 0 Then
            'Session.Item("User") = ds.Tables(0).Rows(0)!strUserName
            Session.Item("User") = ds.Tables(0).Rows(0)!strUserName 'v1.4.5 - 20160913 - Fixed logged In user & savings (i.e use session instead) - maanie
            WebConfigurationManager.AppSettings("UDOMAIN") = ds.Tables(0).Rows(0)!strDomainLogin
            WebConfigurationManager.AppSettings("UID") = ds.Tables(0).Rows(0)!UserID
            WebConfigurationManager.AppSettings("UGROUP") = ds.Tables(0).Rows(0)!strGroupSB
            WebConfigurationManager.AppSettings("UGROUPID") = ds.Tables(0).Rows(0)!refUserGroupSuperbowlID
            WebConfigurationManager.AppSettings("ULEVEL") = ds.Tables(0).Rows(0)!intLevel

            System.Threading.Thread.Sleep(13)
            db.doQueryDS("INSERT INTO mstUsageLog(mstUserID, dtStamp, strSystem) VALUES (" & ds.Tables(0).Rows(0)!UserID & ", '" & Date.Now.ToString("yyyyMMddHHmmss") & "', 'Superbowl')")

            Response.Redirect("Home.aspx", False)
         Else
            lblMessage.Text &= "<i>Insufficient Access.</i><BR>Login is controlled through the Active Directory, <BR>Please contact the system administrator if your require access."
            FormsAuthentication.SignOut()
            WebConfigurationManager.AppSettings("UDOMAIN") = ""
         End If
		Catch ex As Exception
			lblMessage.Text &= "<i>A error has occured, please contact the system administrator.</i><BR>" & ex.Message & ex.StackTrace

			FormsAuthentication.SignOut()
			WebConfigurationManager.AppSettings("UDOMAIN") = ""
		Finally

		End Try
	End Sub

End Class