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

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


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


'===============================
' fac_authgroep_copy CustomSecurity Event begin
checkAutorisation("WEB_FACMSU")
' fac_authgroep_copy CustomSecurity Event end
'===============================

'===============================
' fac_authgroep_copy Open Event begin
' fac_authgroep_copy Open Event end
'===============================

'===============================
' fac_authgroep_copy OpenAnyPage Event begin
' fac_authgroep_copy OpenAnyPage Event end
'===============================

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

' fac_authgroep_copy Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sKopieVanErr = ""
sKopieNaarErr = ""

'-------------------------------
' Select the FormAction
'-------------------------------
Select Case sForm
  Case "KopieVan"
    KopieVanAction(sAction)
  Case "KopieNaar"
    KopieNaarAction(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
'-------------------------------
KopieVan_Show
KopieNaar_Show
'-------------------------------
' Process page templates
'-------------------------------
Parse "main", False
'-------------------------------
' Output the page to the browser
'-------------------------------
Response.write PrintVar("main")

' fac_authgroep_copy Show end

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

' fac_authgroep_copy Close Event begin
' fac_authgroep_copy Close Event end

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

'-------------------------------
' KopieVan Action begin
'-------------------------------
  sActionFileName = "fac_authgroepdisciplinegrid.asp"
  sParams = sParams & "FAC_GROEP_KEY=" & ToURL(GetParam("Trn_FAC_GROEP_KEY")) & "&"
  sParams = sParams & "FAC_FUNCTIE_KEY=" & ToURL(GetParam("Trn_FAC_FUNCTIE_KEY")) & "&"
  sParams = sParams & "INS_DISCIPLINE_KEY=" & ToURL(GetParam("Trn_INS_DISCIPLINE_KEY")) & "&"
  sParams = sParams & "INS_DISCIPLINE_MODULE=" & ToURL(GetParam("Trn_INS_DISCIPLINE_MODULE")) & "&"
  sParams = sParams & "FAC_FUNCTIE_MODULE=" & ToURL(GetParam("Trn_FAC_FUNCTIE_MODULE"))

'-------------------------------
' Load all form fields into variables
'-------------------------------
'-------------------------------
' KopieVan BeforeExecute Event begin
' KopieVan BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub KopieVan_Show()
'-------------------------------
' KopieVan Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Kopieer rechten"
  Dim bPK : bPK = True

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sKopieVanErr = "" then
    fldFAC_GROEP_KEY = GetParam("FAC_GROEP_KEY")
    SetVar "Trn_FAC_GROEP_KEY", GetParam("FAC_GROEP_KEY")
    SetVar "Trn_FAC_FUNCTIE_KEY", GetParam("FAC_FUNCTIE_KEY")
    SetVar "Trn_INS_DISCIPLINE_KEY", GetParam("INS_DISCIPLINE_KEY")
    SetVar "Trn_INS_DISCIPLINE_MODULE", GetParam("INS_DISCIPLINE_MODULE")
    SetVar "Trn_FAC_FUNCTIE_MODULE", GetParam("FAC_FUNCTIE_MODULE")
    pFAC_GROEP_KEY = GetParam("FAC_GROEP_KEY")
    SetVar "KopieVanError", ""
  else
    fldFAC_GROEP_KEY = GetParam("Trn_FAC_GROEP_KEY")
    SetVar "Trn_FAC_GROEP_KEY", GetParam("Trn_FAC_GROEP_KEY")
    SetVar "Trn_FAC_FUNCTIE_KEY", GetParam("Trn_FAC_FUNCTIE_KEY")
    SetVar "Trn_INS_DISCIPLINE_KEY", GetParam("Trn_INS_DISCIPLINE_KEY")
    SetVar "Trn_INS_DISCIPLINE_MODULE", GetParam("Trn_INS_DISCIPLINE_MODULE")
    SetVar "Trn_FAC_FUNCTIE_MODULE", GetParam("Trn_FAC_FUNCTIE_MODULE")
    pFAC_GROEP_KEY = GetParam("PK_FAC_GROEP_KEY")
    SetVar "sKopieVanErr", sKopieVanErr
    SetVar "FormTitle", sFormTitle
    Parse "KopieVanError", False
  end if
'-------------------------------

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

  fldFAC_FUNCTIE_KEY = GetParam("FAC_FUNCTIE_KEY")
  fldINS_DISCIPLINE_KEY = GetParam("INS_DISCIPLINE_KEY")
'-------------------------------

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

  if IsEmpty(pFAC_GROEP_KEY) then bPK = False
  
  sWhere = sWhere & "FAC_GROEP_KEY=" & ToSQL(pFAC_GROEP_KEY, "Number")
  SetVar "PK_FAC_GROEP_KEY", pFAC_GROEP_KEY
'-------------------------------
'-------------------------------
' KopieVan Open Event begin
' KopieVan Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

'-------------------------------
' Load all fields into variables from recordset or input parameters
'-------------------------------
  if bIsUpdateMode then
    fldFAC_GROEP_KEY = GetValue(rs, "FAC_GROEP_KEY")
    SetVar "KopieVanDelete", ""
    SetVar "KopieVanUpdate", ""
    SetVar "KopieVanInsert", ""
'-------------------------------
' KopieVan ShowEdit Event begin
' KopieVan ShowEdit Event end
'-------------------------------
  else
    if sKopieVanErr = "" then
      fldFAC_GROEP_KEY = ToHTML(GetParam("FAC_GROEP_KEY"))
    end if
    SetVar "KopieVanEdit", ""
    SetVar "KopieVanInsert", ""
'-------------------------------
' KopieVan ShowInsert Event begin
' KopieVan ShowInsert Event end
'-------------------------------
  end if
  SetVar "KopieVanCancel", ""

'-------------------------------
' Set lookup fields
'-------------------------------
  fldFAC_GROEP_KEY = DLookUp("FAC_GROEP", "FAC_GROEP_OMSCHRIJVING", "FAC_GROEP_KEY=" & ToSQL(fldFAC_GROEP_KEY, "Number"))
  if sKopieVanErr = "" then
'-------------------------------
' KopieVan Show Event begin
' Waarom doet hij dit niet zelf?
  fldFAC_FUNCTIE_KEY = DLookUp("FAC_FUNCTIE", "FAC_FUNCTIE_OMSCHRIJVING", "FAC_FUNCTIE_KEY=" & ToSQL(fldFAC_FUNCTIE_KEY, "Number"))
  fldINS_DISCIPLINE_KEY = DLookUp("INS_TAB_DISCIPLINE", "INS_DISCIPLINE_OMSCHRIJVING", "INS_DISCIPLINE_KEY=" & ToSQL(fldINS_DISCIPLINE_KEY, "Number"))
' KopieVan Show Event end
'-------------------------------
  end if

'-------------------------------
' Show form field
'-------------------------------
      SetVar "FAC_GROEP_KEY", ToHTML(fldFAC_GROEP_KEY)
      SetVar "FAC_FUNCTIE_KEY", ToHTML(fldFAC_FUNCTIE_KEY)
      SetVar "INS_DISCIPLINE_KEY", ToHTML(fldINS_DISCIPLINE_KEY)
  Parse "FormKopieVan", False

'-------------------------------
' KopieVan Close Event begin
' KopieVan Close Event end
'-------------------------------

Set rs = Nothing

'-------------------------------
' KopieVan Show end
'-------------------------------
End Sub
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub KopieNaarAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sParams : sParams = "?"
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKINS_DISCIPLINE_KEY : pPKINS_DISCIPLINE_KEY = ""
  Dim fldINS_DISCIPLINE_KEY_NAAR : fldINS_DISCIPLINE_KEY_NAAR = ""
  Dim fldINS_DISCIPLINE_MODULE : fldINS_DISCIPLINE_MODULE = ""
  Dim fldFAC_GROEP_KEY : fldFAC_GROEP_KEY = ""
  Dim fldFAC_FUNCTIE_KEY : fldFAC_FUNCTIE_KEY = ""
'-------------------------------

'-------------------------------
' KopieNaar Action begin
'-------------------------------
  sActionFileName = "fac_authgroepdisciplinegrid.asp"
  sParams = sParams & "INS_DISCIPLINE_MODULE=" & ToURL(GetParam("Trn_INS_DISCIPLINE_MODULE")) & "&"
  sParams = sParams & "FAC_FUNCTIE_KEY=" & ToURL(GetParam("Trn_FAC_FUNCTIE_KEY")) & "&"
  sParams = sParams & "FAC_GROEP_KEY=" & ToURL(GetParam("Trn_FAC_GROEP_KEY")) & "&"
  sParams = sParams & "FAC_FUNCTIE_MODULE=" & ToURL(GetParam("Trn_FAC_FUNCTIE_MODULE"))

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

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

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


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldINS_DISCIPLINE_KEY_NAAR = GetParam("INS_DISCIPLINE_KEY_NAAR")
  fldINS_DISCIPLINE_MODULE = GetParam("INS_DISCIPLINE_MODULE")
  fldFAC_GROEP_KEY = GetParam("FAC_GROEP_KEY")
  fldFAC_FUNCTIE_KEY = GetParam("FAC_FUNCTIE_KEY")

'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "update"
'-------------------------------
' KopieNaar Update Event begin
fldINS_DISCIPLINE_KEY_NAAR = "-1" // Gebruiken we niet, we doen Request.Form
' KopieNaar Update Event end
'-------------------------------
      if sSQL = "" then
      sSQL = "update INS_TAB_DISCIPLINE set " & _
        "INS_DISCIPLINE_KEY=" & ToSQL(fldINS_DISCIPLINE_KEY_NAAR, "Number")
      sSQL = sSQL & " where " & sWhere
      end if
  end select
'-------------------------------
'-------------------------------
' KopieNaar BeforeExecute Event begin
If (sAction = "update") Then
   For i = 1 To Request.Form("INS_DISCIPLINE_KEY_NAAR").Count
      VB_Log("Groep key: " + fldFAC_GROEP_KEY)
      VB_Log("Functie key: " + fldFAC_FUNCTIE_KEY)
      VB_Log("Kopie van "&ToSQL(Request.Form("INS_DISCIPLINE_KEY"), "Number")&" naar " & ToSQL(Request.Form("INS_DISCIPLINE_KEY_NAAR")(i), "Number"))
      Call KopieRechten(ToSQL(fldFAC_FUNCTIE_KEY, "Number"), _
                        ToSQL(fldFAC_GROEP_KEY, "Number"), _
                        ToSQL(Request.Form("INS_DISCIPLINE_KEY"), "Number"), _
                        ToSQL(Request.Form("INS_DISCIPLINE_KEY_NAAR")(i), "Number"))
   Next
   ' Voorkom mede default action door error te zetten
   sKopieNaarErr = "Klaar met kopieren van " & i-1 & " disciplines."
End If
' KopieNaar BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub KopieNaar_Show()
'-------------------------------
' KopieNaar Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Kopieer naar"
  Dim bPK : bPK = True

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sKopieNaarErr = "" then
    fldINS_DISCIPLINE_KEY = GetParam("INS_DISCIPLINE_KEY")
    fldINS_DISCIPLINE_MODULE = GetParam("INS_DISCIPLINE_MODULE")
    fldFAC_GROEP_KEY = GetParam("FAC_GROEP_KEY")
    SetVar "Trn_INS_DISCIPLINE_MODULE", GetParam("INS_DISCIPLINE_MODULE")
    SetVar "Trn_FAC_FUNCTIE_KEY", GetParam("FAC_FUNCTIE_KEY")
    SetVar "Trn_FAC_GROEP_KEY", GetParam("FAC_GROEP_KEY")
    SetVar "Trn_FAC_FUNCTIE_MODULE", GetParam("FAC_FUNCTIE_MODULE")
    pINS_DISCIPLINE_KEY = GetParam("INS_DISCIPLINE_KEY")
    SetVar "KopieNaarError", ""
  else
    fldINS_DISCIPLINE_KEY = GetParam("INS_DISCIPLINE_KEY")
    fldINS_DISCIPLINE_KEY_NAAR = GetParam("INS_DISCIPLINE_KEY_NAAR")
    SetVar "Trn_INS_DISCIPLINE_MODULE", GetParam("Trn_INS_DISCIPLINE_MODULE")
    SetVar "Trn_FAC_FUNCTIE_KEY", GetParam("Trn_FAC_FUNCTIE_KEY")
    SetVar "Trn_FAC_GROEP_KEY", GetParam("Trn_FAC_GROEP_KEY")
    SetVar "Trn_FAC_FUNCTIE_MODULE", GetParam("Trn_FAC_FUNCTIE_MODULE")
    pINS_DISCIPLINE_KEY = GetParam("PK_INS_DISCIPLINE_KEY")
    SetVar "sKopieNaarErr", sKopieNaarErr
    SetVar "FormTitle", sFormTitle
    Parse "KopieNaarError", False
  end if
'-------------------------------

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

  fldINS_DISCIPLINE_MODULE = GetParam("INS_DISCIPLINE_MODULE")
  fldFAC_GROEP_KEY = GetParam("FAC_GROEP_KEY")
  fldFAC_FUNCTIE_KEY = GetParam("FAC_FUNCTIE_KEY")
'-------------------------------

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

  if IsEmpty(pINS_DISCIPLINE_KEY) then bPK = False
  
  sWhere = sWhere & "INS_DISCIPLINE_KEY=" & ToSQL(pINS_DISCIPLINE_KEY, "Number")
  SetVar "PK_INS_DISCIPLINE_KEY", pINS_DISCIPLINE_KEY
'-------------------------------
'-------------------------------
' KopieNaar Open Event begin
' KopieNaar Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

'-------------------------------
' Load all fields into variables from recordset or input parameters
'-------------------------------
  if bIsUpdateMode then
    fldINS_DISCIPLINE_KEY = GetValue(rs, "INS_DISCIPLINE_KEY")

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sKopieNaarErr = "" then
      fldINS_DISCIPLINE_KEY_NAAR = GetValue(rs, "INS_DISCIPLINE_KEY")
    end if
    SetVar "KopieNaarDelete", ""
    SetVar "KopieNaarInsert", ""
    Parse "KopieNaarEdit", False
'-------------------------------
' KopieNaar ShowEdit Event begin
' KopieNaar ShowEdit Event end
'-------------------------------
  else
    if sKopieNaarErr = "" then
      fldINS_DISCIPLINE_KEY = ToHTML(GetParam("INS_DISCIPLINE_KEY"))
      fldINS_DISCIPLINE_KEY_NAAR = ToHTML(GetParam("INS_DISCIPLINE_KEY"))
    end if
    SetVar "KopieNaarEdit", ""
    SetVar "KopieNaarInsert", ""
'-------------------------------
' KopieNaar ShowInsert Event begin
' KopieNaar ShowInsert Event end
'-------------------------------
  end if
  Parse "KopieNaarCancel", false
'-------------------------------
' KopieNaar Show Event begin
' KopieNaar Show Event end
'-------------------------------

'-------------------------------
' Show form field
'-------------------------------
      SetVar "INS_DISCIPLINE_KEY", ToHTML(fldINS_DISCIPLINE_KEY)
      SetVar "KopieNaarLBINS_DISCIPLINE_KEY_NAAR", ""
      openrs rsINS_DISCIPLINE_KEY_NAAR, "select INS_DISCIPLINE_KEY, ins_srtdiscipline_prefix||'-'||INS_DISCIPLINE_OMSCHRIJVING from ins_tab_discipline itd, ins_srtdiscipline isd where INS_DISCIPLINE_MODULE=" & ToSQL(fldINS_DISCIPLINE_MODULE, "Text") & "   and ins_discipline_verwijder is null   and itd.ins_srtdiscipline_key = isd.ins_srtdiscipline_key(+) order by ins_srtdiscipline_prefix,INS_DISCIPLINE_OMSCHRIJVING"
      while not rsINS_DISCIPLINE_KEY_NAAR.EOF
        SetVar "ID", GetValue(rsINS_DISCIPLINE_KEY_NAAR, 0) : SetVar "Value", GetValue(rsINS_DISCIPLINE_KEY_NAAR, 1)
        if cstr(GetValue(rsINS_DISCIPLINE_KEY_NAAR, 0)) = cstr(fldINS_DISCIPLINE_KEY_NAAR) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "KopieNaarLBINS_DISCIPLINE_KEY_NAAR", True
        rsINS_DISCIPLINE_KEY_NAAR.MoveNext
      wend
      set rsINS_DISCIPLINE_KEY_NAAR = nothing
    
      SetVar "INS_DISCIPLINE_MODULE", ToHTML(fldINS_DISCIPLINE_MODULE)
      SetVar "FAC_GROEP_KEY", ToHTML(fldFAC_GROEP_KEY)
      SetVar "FAC_FUNCTIE_KEY", ToHTML(fldFAC_FUNCTIE_KEY)
  Parse "FormKopieNaar", False

'-------------------------------
' KopieNaar Close Event begin
' KopieNaar Close Event end
'-------------------------------

Set rs = Nothing

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