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

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


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


'===============================
' ins_disciplinerecord PageSecurity begin
' ins_disciplinerecord PageSecurity end
'===============================

'===============================
' ins_disciplinerecord Open Event begin
' ins_disciplinerecord Open Event end
'===============================

'===============================
' ins_disciplinerecord OpenAnyPage Event begin
' ins_disciplinerecord OpenAnyPage Event end
'===============================

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

' ins_disciplinerecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sDisciplineRecordErr = ""

'-------------------------------
' Select the FormAction
'-------------------------------
Select Case sForm
  Case "DisciplineRecord"
    DisciplineRecordAction(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
'-------------------------------
DisciplineRecord_Show
'-------------------------------
' Process page templates
'-------------------------------
Parse "main", False
'-------------------------------
' Output the page to the browser
'-------------------------------
Response.write PrintVar("main")

' ins_disciplinerecord Show end

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

' ins_disciplinerecord Close Event begin
' ins_disciplinerecord Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub DisciplineRecordAction(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_OMSCHRIJVING : fldINS_DISCIPLINE_OMSCHRIJVING = ""
  Dim fldINS_DISCIPLINE_MIN_LEVEL : fldINS_DISCIPLINE_MIN_LEVEL = ""
  Dim fldPRS_KOSTENSOORT_KEY : fldPRS_KOSTENSOORT_KEY = ""
  Dim fldins_disc_params_autonum : fldins_disc_params_autonum = ""
  Dim fldins_disc_params_cadlayers : fldins_disc_params_cadlayers = ""
  Dim fldBinnen : fldBinnen = ""
  Dim fldBuiten : fldBuiten = ""
  Dim fldLabel : fldLabel = ""
'-------------------------------

'-------------------------------
' DisciplineRecord Action begin
'-------------------------------
  sActionFileName = "ins_disciplinegrid.asp"
  sParams = sParams & "sINS_DISCIPLINE_OMSCHRIJVING=" & ToURL(GetParam("Trn_sINS_DISCIPLINE_OMSCHRIJVING"))

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

'-------------------------------
' DisciplineRecord BeforeCancel Event begin
' DisciplineRecord 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_OMSCHRIJVING = GetParam("INS_DISCIPLINE_OMSCHRIJVING")
  fldINS_DISCIPLINE_MIN_LEVEL = GetParam("INS_DISCIPLINE_MIN_LEVEL")
  fldPRS_KOSTENSOORT_KEY = GetParam("PRS_KOSTENSOORT_KEY")
  fldins_disc_params_autonum = GetParam("ins_disc_params_autonum")
  fldins_disc_params_cadlayers = GetParam("ins_disc_params_cadlayers")
  fldBinnen = GetParam("Binnen")
  fldBuiten = GetParam("Buiten")
  fldLabel = getCheckBoxValue(GetParam("Label"), "1", "0", "Number")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if IsEmpty(fldINS_DISCIPLINE_OMSCHRIJVING) then
      sDisciplineRecordErr = sDisciplineRecordErr & "De waarde in veld Omschrijving is verplicht.<br>"
    end if
    if IsEmpty(fldINS_DISCIPLINE_MIN_LEVEL) then
      sDisciplineRecordErr = sDisciplineRecordErr & "De waarde in veld Typecode is verplicht.<br>"
    end if
    if not isNumeric(fldINS_DISCIPLINE_MIN_LEVEL) then
      sDisciplineRecordErr = sDisciplineRecordErr & "De waarde in veld Typecode is niet correct.<br>"
    end if
    if not isNumeric(fldPRS_KOSTENSOORT_KEY) then
      sDisciplineRecordErr = sDisciplineRecordErr & "De waarde in veld Kostensoort is niet correct.<br>"
    end if
    if not isNumeric(fldins_disc_params_autonum) then
      sDisciplineRecordErr = sDisciplineRecordErr & "De waarde in veld Automatisch nummeren is niet correct.<br>"
    end if
'-------------------------------
' DisciplineRecord Check Event begin
fldINS_DISC_PARAMS_TYPE = CInt(fldBinnen) + CInt(fldBuiten) + (1-CInt(fldLabel))*16
' DisciplineRecord Check Event end
'-------------------------------
    If len(sDisciplineRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' DisciplineRecord Insert Event begin
sSQL = "insert into INS_TAB_DISCIPLINE (" & _
          "INS_DISCIPLINE_OMSCHRIJVING," & _
          "INS_DISCIPLINE_MIN_LEVEL," & _
          "PRS_KOSTENSOORT_KEY," & _
          "INS_DISCIPLINE_MODULE)" & _
          " values (" & _
          ToSQL(fldINS_DISCIPLINE_OMSCHRIJVING, "Text") & "," & _
          ToSQL(fldINS_DISCIPLINE_MIN_LEVEL, "Number") & "," & _
          ToSQL(fldPRS_KOSTENSOORTKEY, "Number") & "," & _
          "'INS'" & _
          ")"
' DisciplineRecord Insert Event end
'-------------------------------
      if sSQL = "" then
      sSQL = "insert into INS_V_AANWEZIGDISCIPLINE (" & _
          "INS_DISCIPLINE_OMSCHRIJVING," & _
          "INS_DISCIPLINE_MIN_LEVEL," & _
          "PRS_KOSTENSOORT_KEY)" & _
          " values (" & _
          ToSQL(fldINS_DISCIPLINE_OMSCHRIJVING, "Text") & "," & _
          ToSQL(fldINS_DISCIPLINE_MIN_LEVEL, "Number") & "," & _
          ToSQL(fldPRS_KOSTENSOORT_KEY, "Number") & _
          ")"
      end if
    case "update"
'-------------------------------
' DisciplineRecord Update Event begin
sSQL = "update INS_TAB_DISCIPLINE set " & _
        "INS_DISCIPLINE_OMSCHRIJVING=" & ToSQL(fldINS_DISCIPLINE_OMSCHRIJVING, "Text") & _
        ",INS_DISCIPLINE_MIN_LEVEL=" & ToSQL(fldINS_DISCIPLINE_MIN_LEVEL, "Number") & _
        ",PRS_KOSTENSOORT_KEY=" & ToSQL(fldPRS_KOSTENSOORT_KEY, "Number") & _
        ",INS_DISCIPLINE_MODULE=" & "'INS'"
      sSQL = sSQL & " where " & sWhere
' DisciplineRecord Update Event end
'-------------------------------
      if sSQL = "" then
      sSQL = "update INS_V_AANWEZIGDISCIPLINE set " & _
        "INS_DISCIPLINE_OMSCHRIJVING=" & ToSQL(fldINS_DISCIPLINE_OMSCHRIJVING, "Text") & _
        ",INS_DISCIPLINE_MIN_LEVEL=" & ToSQL(fldINS_DISCIPLINE_MIN_LEVEL, "Number") & _
        ",PRS_KOSTENSOORT_KEY=" & ToSQL(fldPRS_KOSTENSOORT_KEY, "Number")
      sSQL = sSQL & " where " & sWhere
      end if
    case "delete"
'-------------------------------
' DisciplineRecord Delete Event begin
dim tmpkey
tmpkey = "PK_"&strToTable(sActionFileName)&"_KEY"
sSql = customFacDelete(sActionFileName,getParam(tmpkey))
set tmpkey = Nothing
' DisciplineRecord Delete Event end
'-------------------------------
      if sSQL = "" then
      sSQL = "delete from INS_V_AANWEZIGDISCIPLINE where " & sWhere
      end if
  end select
'-------------------------------
'-------------------------------
' DisciplineRecord BeforeExecute Event begin
' DisciplineRecord BeforeExecute Event end
'-------------------------------

'-------------------------------
' Execute SQL statement
'-------------------------------
if len(sDisciplineRecordErr) > 0 then Exit Sub
  on error resume next
  if bExecSQL then 
    cn.execute sSQL
  end if
  sDisciplineRecordErr = ProcessError
  on error goto 0
  if len(sDisciplineRecordErr) > 0 then Exit Sub
  select case sAction
    case "insert"
'-------------------------------
' DisciplineRecord AfterInsert Event begin
'En voeg de params toe aan ins_disc
'Zoek eerst de key op.
DiscSql = "SELECT INS_DISCIPLINE_KEY "&_
          "FROM INS_V_AANWEZIGDISCIPLINE "&_
          "WHERE INS_DISCIPLINE_OMSCHRIJVING="&ToSql(fldINS_DISCIPLINE_OMSCHRIJVING,"Text")
openrs rsDisc, DiscSql
if not rsDisc.EOF then
  ins_discipline_key = getValue(rsDisc,"INS_DISCIPLINE_KEY")
  DiscSql = "INSERT INTO INS_DISC_PARAMS("&_
            "  INS_DISCIPLINE_KEY,"&_
            "  INS_DISC_PARAMS_CADLAYERS,"&_
            "  INS_DISC_PARAMS_TYPE,"&_
            "  INS_DISC_PARAMS_AUTONUM)"&_
            " VALUES("&_
            ToSql(ins_discipline_key,"Number") & "," &_
            ToSql(fldINS_DISC_PARAMS_CADLAYERS,"Text") & "," &_
            ToSql(fldINS_DISC_PARAMS_TYPE,"Number") & "," &_
            ToSql(fldINS_DISC_PARAMS_AUTONUM,"Number") & ")"
  on error resume next
  if bExecSQL then
    cn.execute DiscSQL
  end if
  sDisciplineRecordErr = ProcessError
  on error goto 0
  if len(sDisciplineRecordErr) > 0 then Exit Sub
end if
rsDisc.Close
' DisciplineRecord AfterInsert Event end
'-------------------------------
    case "update"
'-------------------------------
' DisciplineRecord AfterUpdate Event begin
'En update de params in ins_disc
DiscSql = "UPDATE INS_DISC_PARAMS SET "&_
          "  INS_DISC_PARAMS_CADLAYERS="&ToSql(fldINS_DISC_PARAMS_CADLAYERS,"Text")&","&_
          "  INS_DISC_PARAMS_TYPE="&ToSql(fldINS_DISC_PARAMS_TYPE,"Number")&","&_
          "  INS_DISC_PARAMS_AUTONUM="&ToSql(fldINS_DISC_PARAMS_AUTONUM,"Number")&_
          " WHERE INS_DISCIPLINE_KEY="&pPKINS_DISCIPLINE_KEY
on error resume next
if bExecSQL then
  cn.execute DiscSQL
end if
sDisciplineRecordErr = ProcessError
on error goto 0
if len(sDisciplineRecordErr) > 0 then Exit Sub
' DisciplineRecord AfterUpdate Event end
'-------------------------------
  end select
  cn.Close
  Set cn = Nothing
  response.redirect sActionFileName & sParams
'-------------------------------
' DisciplineRecord Action end
'-------------------------------
end sub
'===============================

'===============================
' Display Record Form
'-------------------------------
Sub DisciplineRecord_Show()
'-------------------------------
' DisciplineRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details discipline"
  Dim bPK : bPK = True
  Dim sPRS_KOSTENSOORT_KEYDisplayValue: sPRS_KOSTENSOORT_KEYDisplayValue = ""

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sDisciplineRecordErr = "" then
    SetVar "Trn_sINS_DISCIPLINE_OMSCHRIJVING", GetParam("sINS_DISCIPLINE_OMSCHRIJVING")
    pINS_DISCIPLINE_KEY = GetParam("INS_DISCIPLINE_KEY")
    SetVar "DisciplineRecordError", ""
  else
    fldINS_DISCIPLINE_OMSCHRIJVING = GetParam("INS_DISCIPLINE_OMSCHRIJVING")
    fldINS_DISCIPLINE_MIN_LEVEL = GetParam("INS_DISCIPLINE_MIN_LEVEL")
    fldPRS_KOSTENSOORT_KEY = GetParam("PRS_KOSTENSOORT_KEY")
    SetVar "Trn_sINS_DISCIPLINE_OMSCHRIJVING", GetParam("Trn_sINS_DISCIPLINE_OMSCHRIJVING")
    pINS_DISCIPLINE_KEY = GetParam("PK_INS_DISCIPLINE_KEY")
    SetVar "sDisciplineRecordErr", sDisciplineRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "DisciplineRecordError", False
  end if
'-------------------------------

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

  fldins_disc_params_autonum = GetParam("ins_disc_params_autonum")
  fldins_disc_params_cadlayers = GetParam("ins_disc_params_cadlayers")
  fldBinnen = GetParam("Binnen")
  fldBuiten = GetParam("Buiten")
  fldLabel = GetParam("Label")
'-------------------------------

'-------------------------------
' 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
'-------------------------------
'-------------------------------
' DisciplineRecord Open Event begin
' DisciplineRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

'-------------------------------
' Build SQL statement and open recordset
'-------------------------------
  sSQL = "select * from INS_V_AANWEZIGDISCIPLINE where " & sWhere
  openrs rs, sSQL
  bIsUpdateMode = (bPK and not(sAction = "insert" and sForm = "DisciplineRecord") 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 sDisciplineRecordErr = "" then
      fldINS_DISCIPLINE_OMSCHRIJVING = GetValue(rs, "INS_DISCIPLINE_OMSCHRIJVING")
      fldINS_DISCIPLINE_MIN_LEVEL = GetValue(rs, "INS_DISCIPLINE_MIN_LEVEL")
      fldPRS_KOSTENSOORT_KEY = GetValue(rs, "PRS_KOSTENSOORT_KEY")
    end if
    SetVar "DisciplineRecordInsert", ""
    Parse "DisciplineRecordEdit", False
'-------------------------------
' DisciplineRecord ShowEdit Event begin
' DisciplineRecord ShowEdit Event end
'-------------------------------
  else
    if sDisciplineRecordErr = "" then
      fldLabel= "1"
    end if
    SetVar "DisciplineRecordEdit", ""
    Parse "DisciplineRecordInsert", False
'-------------------------------
' DisciplineRecord ShowInsert Event begin
' DisciplineRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "DisciplineRecordCancel", false

'-------------------------------
' Set default values
'-------------------------------
  fldLabel= "1"
  if sDisciplineRecordErr = "" then
'-------------------------------
' DisciplineRecord Show Event begin
'Laad de records uit ins_disc_params indien van toepassing
if fldINS_DISCIPLINE_KEY <> "" then
  DiscSql = "SELECT INS_DISC_PARAMS_CADLAYERS,"&_
            "       INS_DISC_PARAMS_TYPE,"&_
            "       INS_DISC_PARAMS_AUTONUM"&_
            "  FROM INS_DISC_PARAMS "&_
            " WHERE INS_DISCIPLINE_key = " & ToSQL(fldINS_DISCIPLINE_KEY, "Number")
  openrs rsDisc, DiscSql
  if not rsDisc.EOF then
    fldINS_DISC_PARAMS_CADLAYERS = getValue(rsDisc,"INS_DISC_PARAMS_CADLAYERS")
    fldINS_DISC_PARAMS_TYPE = getValue(rsDisc,"INS_DISC_PARAMS_TYPE")
    fldBinnen = fldINS_DISC_PARAMS_TYPE AND 5 ' &B0101
    fldBuiten = fldINS_DISC_PARAMS_TYPE AND 10 ' &B1010
    fldLabel = 1-CInt((fldINS_DISC_PARAMS_TYPE AND 16)/16)
    fldINS_DISC_PARAMS_AUTONUM = getValue(rsDisc,"INS_DISC_PARAMS_AUTONUM")
  end if
  rsDisc.Close
end if
' DisciplineRecord Show Event end
'-------------------------------
  end if

'-------------------------------
' Show form field
'-------------------------------
      SetVar "INS_DISCIPLINE_KEY", ToHTML(fldINS_DISCIPLINE_KEY)
      SetVar "INS_DISCIPLINE_OMSCHRIJVING", ToHTML(fldINS_DISCIPLINE_OMSCHRIJVING)
      SetVar "DisciplineRecordLBINS_DISCIPLINE_MIN_LEVEL", ""
      LOV = Split(""&FCLTLCL("1;Normaal;3;Persoonsgebonden")&"", ";")
      if (ubound(LOV) mod 2) = 1 then
        for i = 0 to ubound(LOV) step 2
          SetVar "ID", LOV(i) : SetVar "Value", LOV(i+1)
          if cstr(LOV(i)) = cstr(fldINS_DISCIPLINE_MIN_LEVEL) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
          Parse "DisciplineRecordLBINS_DISCIPLINE_MIN_LEVEL", True
        next
      end if
    
      SetVar "DisciplineRecordLBPRS_KOSTENSOORT_KEY", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", sPRS_KOSTENSOORT_KEYDisplayValue
      Parse "DisciplineRecordLBPRS_KOSTENSOORT_KEY", True
      openrs rsPRS_KOSTENSOORT_KEY, "select PRS_KOSTENSOORT_KEY, PRS_KOSTENSOORT_OMS from PRS_KOSTENSOORT order by 2"
      while not rsPRS_KOSTENSOORT_KEY.EOF
        SetVar "ID", GetValue(rsPRS_KOSTENSOORT_KEY, 0) : SetVar "Value", GetValue(rsPRS_KOSTENSOORT_KEY, 1)
        if cstr(GetValue(rsPRS_KOSTENSOORT_KEY, 0)) = cstr(fldPRS_KOSTENSOORT_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "DisciplineRecordLBPRS_KOSTENSOORT_KEY", True
        rsPRS_KOSTENSOORT_KEY.MoveNext
      wend
      set rsPRS_KOSTENSOORT_KEY = nothing
    
      SetVar "DisciplineRecordLBins_disc_params_autonum", ""
      LOV = Split(""&FCLTLCL("2;Nee;1;Ja, niet wijzigbaar;3;Ja, wijzigbaar")&"", ";")
      if (ubound(LOV) mod 2) = 1 then
        for i = 0 to ubound(LOV) step 2
          SetVar "ID", LOV(i) : SetVar "Value", LOV(i+1)
          if cstr(LOV(i)) = cstr(fldins_disc_params_autonum) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
          Parse "DisciplineRecordLBins_disc_params_autonum", True
        next
      end if
    
      SetVar "ins_disc_params_cadlayers", ToHTML(fldins_disc_params_cadlayers)
      SetVar "DisciplineRecordRLBinnen", ""
    
      LOV = Split(""&FCLTLCL("0;Niet van toepassing;1;Standaard uit;5;Standaard aan")&"", ";")
      if (ubound(LOV) mod 2) = 1 then
        for i = 0 to ubound(LOV) step 2
          SetVar "ID", LOV(i) : SetVar "Value", LOV(i+1)
          if cstr(LOV(i)) = cstr(fldBinnen) then SetVar "Selected", "CHECKED" else SetVar "Selected", ""
          Parse "DisciplineRecordRLBinnen", True
        next
      end if
    
      SetVar "DisciplineRecordRLBuiten", ""
    
      LOV = Split(""&FCLTLCL("0;Niet van toepassing;2;Standaard uit;10;Standaard aan")&"", ";")
      if (ubound(LOV) mod 2) = 1 then
        for i = 0 to ubound(LOV) step 2
          SetVar "ID", LOV(i) : SetVar "Value", LOV(i+1)
          if cstr(LOV(i)) = cstr(fldBuiten) then SetVar "Selected", "CHECKED" else SetVar "Selected", ""
          Parse "DisciplineRecordRLBuiten", True
        next
      end if
    
  if (LCase(fldLabel) = LCase("1")) then
    SetVar "Label_CHECKED", "CHECKED"
  else
    SetVar "Label_CHECKED", ""
  end if

  Parse "FormDisciplineRecord", False

'-------------------------------
' DisciplineRecord Close Event begin
' DisciplineRecord Close Event end
'-------------------------------

Set rs = Nothing

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