<%
' MyPAYE
' Module: ExactOnlineInitialAuth.asp
'
' This software is the copyright of Mr T J Sheppard and may not be copied, duplicated or 
' modified other than as permitted in the licence agreement.
'
'       © 2012 - 2015  Mr T J Sheppard
'                      Lyndale House
'                      Church Street
'                      Bradwell
'                      Hope Valley
'                      S33 9HJ
'
'  Tel 0845 643 5191
'  Email Support@MyPAYE.co.uk
'
' MyPAYE is a Registered Trademark of MyPAYE Ltd
'-------------------------------------------------------------------
'
' Updated 18 December 2015
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'   Description -    This module 
'
' Amendment Log
'------------------------------------------------------------------------------------------
' Date     | Name            | Vers.  | Description
'------------------------------------------------------------------------------------------
' 18/12/15 | TJS             | 5.0.02 | Page added
' 05/12/19 | TJS             | 5.7.02 | Modified to use GetMainMenuParam to save having to read lots of parameters for each page build
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

PageID = 22117
NoBack = True
SessionID = request.querystring("ID")
SessionVarsID = RemoveHTML(request.querystring("SV"))
SourceFrame = RemoveHTML(request.querystring("S"))
DestFrame = RemoveHTML(request.querystring("D"))
EmployerID = CheckURLDBIDField(RemoveHTML(request.querystring("ER")), "EmployerID")
AddNewEdit = RemoveHTML(request.querystring("ANE"))
CancelPage = RemoveHTML(request.querystring("CPge"))
TrialExpires = ValidateDateValue(RemoveHTML(Trim(request.querystring("Txp"))), "TrialExpires")
%>

<!--#include file ="Functions\CoreValidationRoutines.asp"-->

<!--#include file ="Functions\ConnectDatabaseMain.asp"-->

<!--#include file ="Functions\CreateSessionID.asp"-->

<!--#include file ="Functions\FrameNameConst.asp"-->

<%GetSessionVarsIDRecord(SessionVarsID)%>

<!--#include file ="Functions\DataProtection.asp"-->

<!--#include file ="Functions\URLValidation.asp"-->

<!--#include file ="OAuth\OAuthFunctions.asp"-->

<%
sql = "SELECT " & EmployerTableMenuOptionFields & ", Default_Nominal_Codes FROM " & DBSchema & "Employers WHERE Employer_ID = " & EmployerID
set rsEmployer = OpenRecordset(objConn, sql)
		
sql = "SELECT " & UserTableMenuPermissionFields & " FROM " & DBSchema & "Users INNER JOIN " & DBSchema & "User_Permissions "
sql = sql & "ON Users.User_ID = User_Permissions.User_ID AND (Employee_Employer_ID = '' OR Employee_Employer_ID = '"
sql = sql & EncodeEmployerID(UserPermissionsTable, EmployerID) & "') WHERE Users.User_ID = " & GetSessionVar("UserID")
sql = sql & " AND User_Permissions.Deleted = 0 ORDER BY Employee_Employer_ID DESC"
set rsUser = OpenRecordset(objConn, sql)

ReadMainMenuParams SessionVarsID, cBool(rsUser("User_Admin")), (cBool(rsUser("Run_Payroll")) or cBool(rsUser("Payroll_EOY")) or cBool(rsUser("CIS_Returns"))), _
	cBool(rsUser("Run_Payroll")), rsUser("Support_User_ID") ' TJS 05/12/19

response.Expires = -1500
response.Expiresabsolute = Now() - 2
response.AddHeader "pragma", "no-cache"
response.AddHeader "cache-control", "no-store"
response.CacheControl = "no-cache"

if cBool(rsEmployer("Default_Nominal_Codes")) then
	GetExactOnlineAuthToken "Exact Online Integration", "", "CNC", "EmplInt"
else
	GetExactOnlineAuthToken "Exact Online Integration", "", "ENC", "EmplInt"
end if

rsEmployer.close
rsUser.close
set rsEmployer = nothing
set rsUser = nothing

ReleaseASPEncrypt

SaveSessionVarsRecord SessionVarsID

objConn.close
set objConn = nothing%>