<%
'
'    Filename: fac_persoongroeprecord1.asp
'    Generated with CodeCharge 2.0.5
'    ASP 2.0 & Templates.ccp build 11/30/2001
'

'-------------------------------
' 
' fac_persoongroeprecord1 CustomIncludes Event begin
%>
<!-- #INCLUDE FILE="Common.asp" -->
<%
' fac_persoongroeprecord1 CustomIncludes Event end


'===============================
' Save Page and File Name available into variables
'-------------------------------
sFileName = "fac_persoongroeprecord1.asp"
sTemplateFileName = "fac_persoongroeprecord1.html"
'===============================


'===============================
' fac_persoongroeprecord1 CustomSecurity Event begin
checkAutorisation("WEB_PRSMSU")
' fac_persoongroeprecord1 CustomSecurity Event end
'===============================

'===============================
' fac_persoongroeprecord1 Open Event begin
' fac_persoongroeprecord1 Open Event end
'===============================

'===============================
' fac_persoongroeprecord1 OpenAnyPage Event begin
' fac_persoongroeprecord1 OpenAnyPage Event end
'===============================

'===============================
'Save the name of the form and type of action into the variables
'-------------------------------
sAction = GetParam("FormAction")
sForm = GetParam("FormName")
'===============================

' fac_persoongroeprecord1 Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sGroepRecordAddErr = ""
sPersoonRecordErr = ""

'-------------------------------
' Select the FormAction
'-------------------------------
Select Case sForm
  Case "GroepRecordAdd"
    GroepRecordAddAction(sAction)
  Case "PersoonRecord"
    PersoonRecordAction(sAction)
end select
'===============================

'===============================
' Display page
'-------------------------------
' Load HTML template for this page
'-------------------------------
LoadTemplate sAppPath & sTemplateFileName, "main"
'-------------------------------
' Load HTML template of Header and Footer
'-------------------------------
'-------------------------------
SetVar "FileName", sFileName


'-------------------------------
' Step through each form
'-------------------------------
PersoonRecord_Show
GroepRecordAdd_Show
'-------------------------------
' Process page templates
'-------------------------------
Parse "main", False
'-------------------------------
' Output the page to the browser
'-------------------------------
Response.write PrintVar("main")

' fac_persoongroeprecord1 Show end

'-------------------------------
' Destroy all object variables
'-------------------------------

' fac_persoongroeprecord1 Close Event begin
' fac_persoongroeprecord1 Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub GroepRecordAddAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sParams : sParams = "?"
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKFAC_GEBRUIKERSGROEP_KEY : pPKFAC_GEBRUIKERSGROEP_KEY = ""
  Dim fldPRS_PERSLID_KEY : fldPRS_PERSLID_KEY = ""
  Dim fldFAC_GROEP_KEY : fldFAC_GROEP_KEY = ""
'-------------------------------

'-------------------------------
' GroepRecordAdd Action begin
'-------------------------------
  sActionFileName = "fac_persoongroeprecord.asp"
  sParams = sParams & "PRS_PERSLID_KEY=" & ToURL(GetParam("Trn_PRS_PERSLID_KEY")) & "&"
  sParams = sParams & "fPRS_AFDELING_KEY=" & ToURL(GetParam("Trn_fPRS_AFDELING_KEY")) & "&"
  sParams = sParams & "fFAC_GROEP_KEY=" & ToURL(GetParam("Trn_fFAC_GROEP_KEY")) & "&"
  sParams = sParams & "fPRS_PERSLID_NAAM=" & ToURL(GetParam("Trn_fPRS_PERSLID_NAAM"))

'-------------------------------
' CANCEL action
'-------------------------------
  if sAction = "cancel" then

'-------------------------------
' GroepRecordAdd BeforeCancel Event begin
' GroepRecordAdd BeforeCancel Event end
'-------------------------------
    cn.Close
    Set cn = Nothing
    response.redirect sActionFileName & sParams
  end if
'-------------------------------

'-------------------------------
' Build WHERE statement
'-------------------------------
  if sAction = "update" or sAction = "delete" then
    pPKFAC_GEBRUIKERSGROEP_KEY = GetParam("PK_FAC_GEBRUIKERSGROEP_KEY")
    if IsEmpty(pPKFAC_GEBRUIKERSGROEP_KEY) then exit sub
    sWhere = "FAC_GEBRUIKERSGROEP_KEY=" & ToSQL(pPKFAC_GEBRUIKERSGROEP_KEY, "Number")
  end if
'-------------------------------


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldPRS_PERSLID_KEY = GetParam("PRS_PERSLID_KEY")
  fldFAC_GROEP_KEY = GetParam("FAC_GROEP_KEY")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if IsEmpty(fldFAC_GROEP_KEY) then
      sGroepRecordAddErr = sGroepRecordAddErr & "De waarde in veld Groep is verplicht.<br>"
    end if
    if not isNumeric(fldPRS_PERSLID_KEY) then
      sGroepRecordAddErr = sGroepRecordAddErr & "De waarde in veld PRS_PERSLID_KEY is niet correct.<br>"
    end if
    if not isNumeric(fldFAC_GROEP_KEY) then
      sGroepRecordAddErr = sGroepRecordAddErr & "De waarde in veld Groep is niet correct.<br>"
    end if
'-------------------------------
' GroepRecordAdd Check Event begin
' GroepRecordAdd Check Event end
'-------------------------------
    If len(sGroepRecordAddErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' GroepRecordAdd Insert Event begin
' GroepRecordAdd Insert Event end
'-------------------------------
      sSQL = "insert into FAC_GEBRUIKERSGROEP (" & _
          "PRS_PERSLID_KEY," & _
          "FAC_GROEP_KEY)" & _
          " values (" & _
          ToSQL(fldPRS_PERSLID_KEY, "Number") & "," & _
          ToSQL(fldFAC_GROEP_KEY, "Number") & _
          ")"
    case "update"
'-------------------------------
' GroepRecordAdd Update Event begin
' GroepRecordAdd Update Event end
'-------------------------------
      sSQL = "update FAC_GEBRUIKERSGROEP set " & _
        "PRS_PERSLID_KEY=" & ToSQL(fldPRS_PERSLID_KEY, "Number") & _
        ",FAC_GROEP_KEY=" & ToSQL(fldFAC_GROEP_KEY, "Number")
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' GroepRecordAdd Delete Event begin
' GroepRecordAdd Delete Event end
'-------------------------------
      sSQL = "delete from FAC_GEBRUIKERSGROEP where " & sWhere
  end select
'-------------------------------
'-------------------------------
' GroepRecordAdd BeforeExecute Event begin
' GroepRecordAdd BeforeExecute Event end
'-------------------------------

'-------------------------------
' Execute SQL statement
'-------------------------------
if len(sGroepRecordAddErr) > 0 then Exit Sub
  on error resume next
  if bExecSQL then 
    cn.execute sSQL
  end if
  sGroepRecordAddErr = ProcessError
  on error goto 0
  if len(sGroepRecordAddErr) > 0 then Exit Sub
  cn.Close
  Set cn = Nothing
  response.redirect sActionFileName & sParams
'-------------------------------
' GroepRecordAdd Action end
'-------------------------------
end sub
'===============================

'===============================
' Display Record Form
'-------------------------------
Sub GroepRecordAdd_Show()
'-------------------------------
' GroepRecordAdd Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Autorisatiegroepen"
  Dim bPK : bPK = True
  Dim sFAC_GROEP_KEYDisplayValue: sFAC_GROEP_KEYDisplayValue = ""

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sGroepRecordAddErr = "" then
    fldPRS_PERSLID_KEY = GetParam("PRS_PERSLID_KEY")
    SetVar "Trn_PRS_PERSLID_KEY", GetParam("PRS_PERSLID_KEY")
    SetVar "Trn_fPRS_AFDELING_KEY", GetParam("fPRS_AFDELING_KEY")
    SetVar "Trn_fFAC_GROEP_KEY", GetParam("fFAC_GROEP_KEY")
    SetVar "Trn_fPRS_PERSLID_NAAM", GetParam("fPRS_PERSLID_NAAM")
    pFAC_GEBRUIKERSGROEP_KEY = GetParam("FAC_GEBRUIKERSGROEP_KEY")
    SetVar "GroepRecordAddError", ""
  else
    fldFAC_GEBRUIKERSGROEP_KEY = GetParam("FAC_GEBRUIKERSGROEP_KEY")
    fldPRS_PERSLID_KEY = GetParam("PRS_PERSLID_KEY")
    fldFAC_GROEP_KEY = GetParam("FAC_GROEP_KEY")
    SetVar "Trn_PRS_PERSLID_KEY", GetParam("Trn_PRS_PERSLID_KEY")
    SetVar "Trn_fPRS_AFDELING_KEY", GetParam("Trn_fPRS_AFDELING_KEY")
    SetVar "Trn_fFAC_GROEP_KEY", GetParam("Trn_fFAC_GROEP_KEY")
    SetVar "Trn_fPRS_PERSLID_NAAM", GetParam("Trn_fPRS_PERSLID_NAAM")
    pFAC_GEBRUIKERSGROEP_KEY = GetParam("PK_FAC_GEBRUIKERSGROEP_KEY")
    SetVar "sGroepRecordAddErr", sGroepRecordAddErr
    SetVar "FormTitle", sFormTitle
    Parse "GroepRecordAddError", False
  end if
'-------------------------------

'-------------------------------
' Load all form fields

'-------------------------------

'-------------------------------
' Build WHERE statement

  if IsEmpty(pFAC_GEBRUIKERSGROEP_KEY) then bPK = False
  
  sWhere = sWhere & "FAC_GEBRUIKERSGROEP_KEY=" & ToSQL(pFAC_GEBRUIKERSGROEP_KEY, "Number")
  SetVar "PK_FAC_GEBRUIKERSGROEP_KEY", pFAC_GEBRUIKERSGROEP_KEY
'-------------------------------
'-------------------------------
' GroepRecordAdd Open Event begin
' GroepRecordAdd Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

'-------------------------------
' Build SQL statement and open recordset
'-------------------------------
  sSQL = "select * from FAC_GEBRUIKERSGROEP where " & sWhere
  openrs rs, sSQL
  bIsUpdateMode = (bPK and not(sAction = "insert" and sForm = "GroepRecordAdd") and not rs.eof)
'-------------------------------

'-------------------------------
' Load all fields into variables from recordset or input parameters
'-------------------------------
  if bIsUpdateMode then
    fldFAC_GEBRUIKERSGROEP_KEY = GetValue(rs, "FAC_GEBRUIKERSGROEP_KEY")
    fldPRS_PERSLID_KEY = GetValue(rs, "PRS_PERSLID_KEY")

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sGroepRecordAddErr = "" then
      fldFAC_GROEP_KEY = GetValue(rs, "FAC_GROEP_KEY")
    end if
    SetVar "GroepRecordAddInsert", ""
    Parse "GroepRecordAddEdit", False
'-------------------------------
' GroepRecordAdd ShowEdit Event begin
' GroepRecordAdd ShowEdit Event end
'-------------------------------
  else
    if sGroepRecordAddErr = "" then
      fldPRS_PERSLID_KEY = ToHTML(GetParam("PRS_PERSLID_KEY"))
    end if
    SetVar "GroepRecordAddEdit", ""
    Parse "GroepRecordAddInsert", False
'-------------------------------
' GroepRecordAdd ShowInsert Event begin
' GroepRecordAdd ShowInsert Event end
'-------------------------------
  end if
  Parse "GroepRecordAddCancel", false
'-------------------------------
' GroepRecordAdd Show Event begin
' GroepRecordAdd Show Event end
'-------------------------------

'-------------------------------
' Show form field
'-------------------------------
      SetVar "FAC_GEBRUIKERSGROEP_KEY", ToHTML(fldFAC_GEBRUIKERSGROEP_KEY)
      SetVar "PRS_PERSLID_KEY", ToHTML(fldPRS_PERSLID_KEY)
      SetVar "GroepRecordAddLBFAC_GROEP_KEY", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", sFAC_GROEP_KEYDisplayValue
      Parse "GroepRecordAddLBFAC_GROEP_KEY", True
      openrs rsFAC_GROEP_KEY, "select fac_groep_key, fac_groep_omschrijving from fac_groep fg where fac_groep_key not in   (select fac_groep_key    from fac_gebruikersgroep    where prs_perslid_key="&ToSQL(fldPRS_PERSLID_KEY,"Number")&") AND (NOT EXISTS (             SELECT *               FROM fac_groeprechten fgr, fac_functie ff              WHERE fgr.fac_groep_key = fg.fac_groep_key                AND fgr.fac_functie_key = ff.fac_functie_key                AND ff.fac_functie_code = 'WEB_PRSSYS')          OR fac_groep_key IN (SELECT fac_groep_key                                  FROM fac_gebruikersgroep                                 WHERE prs_perslid_key = "&Session("User_key")&")) order by fac_groep_omschrijving asc"
      while not rsFAC_GROEP_KEY.EOF
        SetVar "ID", GetValue(rsFAC_GROEP_KEY, 0) : SetVar "Value", GetValue(rsFAC_GROEP_KEY, 1)
        if cstr(GetValue(rsFAC_GROEP_KEY, 0)) = cstr(fldFAC_GROEP_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "GroepRecordAddLBFAC_GROEP_KEY", True
        rsFAC_GROEP_KEY.MoveNext
      wend
      set rsFAC_GROEP_KEY = nothing
    
  Parse "FormGroepRecordAdd", False

'-------------------------------
' GroepRecordAdd Close Event begin
' GroepRecordAdd Close Event end
'-------------------------------

Set rs = Nothing

'-------------------------------
' GroepRecordAdd Show end
'-------------------------------
End Sub
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub PersoonRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sParams : sParams = "?"
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKPRS_PERSLID_KEY : pPKPRS_PERSLID_KEY = ""
'-------------------------------

'-------------------------------
' PersoonRecord Action begin
'-------------------------------
  sActionFileName = "fac_persoongroepgrid.asp"
  sParams = sParams & "fPRS_AFDELING_KEY=" & ToURL(GetParam("Trn_fPRS_AFDELING_KEY")) & "&"
  sParams = sParams & "fFAC_GROEP_KEY=" & ToURL(GetParam("Trn_fFAC_GROEP_KEY")) & "&"
  sParams = sParams & "fPRS_PERSLID_NAAM=" & ToURL(GetParam("Trn_fPRS_PERSLID_NAAM"))

'-------------------------------
' CANCEL action
'-------------------------------
  if sAction = "cancel" then

'-------------------------------
' PersoonRecord BeforeCancel Event begin
' PersoonRecord BeforeCancel Event end
'-------------------------------
    cn.Close
    Set cn = Nothing
    response.redirect sActionFileName & sParams
  end if
'-------------------------------

'-------------------------------
' Load all form fields into variables
'-------------------------------

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
'-------------------------------
' PersoonRecord Check Event begin
' PersoonRecord Check Event end
'-------------------------------
    If len(sPersoonRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------

'-------------------------------
' PersoonRecord BeforeExecute Event begin
' PersoonRecord BeforeExecute Event end
'-------------------------------

'-------------------------------
' Execute SQL statement
'-------------------------------
if len(sPersoonRecordErr) > 0 then Exit Sub
  on error resume next
  if bExecSQL then 
    cn.execute sSQL
  end if
  sPersoonRecordErr = ProcessError
  on error goto 0
  if len(sPersoonRecordErr) > 0 then Exit Sub
  cn.Close
  Set cn = Nothing
  response.redirect sActionFileName & sParams
'-------------------------------
' PersoonRecord Action end
'-------------------------------
end sub
'===============================

'===============================
' Display Record Form
'-------------------------------
Sub PersoonRecord_Show()
'-------------------------------
' PersoonRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Naam"
  Dim bPK : bPK = True

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sPersoonRecordErr = "" then
    SetVar "Trn_fPRS_AFDELING_KEY", GetParam("fPRS_AFDELING_KEY")
    SetVar "Trn_fFAC_GROEP_KEY", GetParam("fFAC_GROEP_KEY")
    SetVar "Trn_fPRS_PERSLID_NAAM", GetParam("fPRS_PERSLID_NAAM")
    pPRS_PERSLID_KEY = GetParam("PRS_PERSLID_KEY")
    SetVar "PersoonRecordError", ""
  else
    SetVar "Trn_fPRS_AFDELING_KEY", GetParam("Trn_fPRS_AFDELING_KEY")
    SetVar "Trn_fFAC_GROEP_KEY", GetParam("Trn_fFAC_GROEP_KEY")
    SetVar "Trn_fPRS_PERSLID_NAAM", GetParam("Trn_fPRS_PERSLID_NAAM")
    pPRS_PERSLID_KEY = GetParam("PK_PRS_PERSLID_KEY")
    SetVar "sPersoonRecordErr", sPersoonRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "PersoonRecordError", False
  end if
'-------------------------------

'-------------------------------
' Load all form fields

'-------------------------------

'-------------------------------
' Build WHERE statement

  if IsEmpty(pPRS_PERSLID_KEY) then bPK = False
  
  sWhere = sWhere & "PRS_PERSLID_KEY=" & ToSQL(pPRS_PERSLID_KEY, "Number")
  SetVar "PK_PRS_PERSLID_KEY", pPRS_PERSLID_KEY
'-------------------------------
'-------------------------------
' PersoonRecord Open Event begin
' PersoonRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

'-------------------------------
' Build SQL statement and open recordset
'-------------------------------
  sSQL = "select * from FAC_V_WEBUSER where " & sWhere
  openrs rs, sSQL
  bIsUpdateMode = (bPK and not(sAction = "insert" and sForm = "PersoonRecord") and not rs.eof)
'-------------------------------

'-------------------------------
' Load all fields into variables from recordset or input parameters
'-------------------------------
  if bIsUpdateMode then
    fldPRS_AFDELING_KEY = GetValue(rs, "PRS_AFDELING_KEY")
    fldPRS_PERSLID_KEY = GetValue(rs, "PRS_PERSLID_KEY")
    fldPRS_PERSLID_NAAM = GetValue(rs, "PRS_PERSLID_NAAM")
    SetVar "PersoonRecordDelete", ""
    SetVar "PersoonRecordUpdate", ""
    SetVar "PersoonRecordInsert", ""
'-------------------------------
' PersoonRecord ShowEdit Event begin
' PersoonRecord ShowEdit Event end
'-------------------------------
  else
    SetVar "PersoonRecordEdit", ""
    SetVar "PersoonRecordInsert", ""
'-------------------------------
' PersoonRecord ShowInsert Event begin
' PersoonRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "PersoonRecordCancel", false

'-------------------------------
' Set lookup fields
'-------------------------------
  fldPRS_AFDELING_KEY = DLookUp("PRS_V_AANWEZIGAFDELING", "PRS_AFDELING_OMSCHRIJVING", "PRS_AFDELING_KEY=" & ToSQL(fldPRS_AFDELING_KEY, "Number"))
  if sPersoonRecordErr = "" then
'-------------------------------
' PersoonRecord Show Event begin
fldPRS_PERSLID_NAAM = buildName(fldPRS_PERSLID_KEY)
' PersoonRecord Show Event end
'-------------------------------
  end if

'-------------------------------
' Show form field
'-------------------------------
      SetVar "PRS_PERSLID_KEY", ToHTML(fldPRS_PERSLID_KEY)
      SetVar "PRS_PERSLID_NAAM", ToHTML(fldPRS_PERSLID_NAAM)
      SetVar "PRS_AFDELING_KEY", ToHTML(fldPRS_AFDELING_KEY)
  Parse "FormPersoonRecord", False

'-------------------------------
' PersoonRecord Close Event begin
' PersoonRecord Close Event end
'-------------------------------

Set rs = Nothing

'-------------------------------
' PersoonRecord Show end
'-------------------------------
End Sub
'===============================
%>