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

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


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


'===============================
' cad_themarecord PageSecurity begin
' cad_themarecord PageSecurity end
'===============================

'===============================
' cad_themarecord Open Event begin
' cad_themarecord Open Event end
'===============================

'===============================
' cad_themarecord OpenAnyPage Event begin
' cad_themarecord OpenAnyPage Event end
'===============================

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

' cad_themarecord Show begin
'===============================
' Perform the form's action
'-------------------------------
' Initialize error variables
'-------------------------------
sThemaRecordErr = ""

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

' cad_themarecord Show end

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

' cad_themarecord Close Event begin
' cad_themarecord Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================
'===============================
' Action of the Record Form
'-------------------------------
Sub ThemaRecordAction(sAction)
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim bExecSQL: bExecSQL = true
  Dim sActionFileName : sActionFileName = ""
  Dim sParams : sParams = "?"
  Dim sWhere : sWhere = "" 
  Dim bErr : bErr = False
  Dim pPKCAD_THEMA_KEY : pPKCAD_THEMA_KEY = ""
  Dim fldCAD_THEMA_OMSCHRIJVING : fldCAD_THEMA_OMSCHRIJVING = ""
  Dim fldCAD_THEMA_VIEW : fldCAD_THEMA_VIEW = ""
  Dim fldCAD_LEGENDA_KEY : fldCAD_LEGENDA_KEY = ""
  Dim fldFAC_FUNCTIE_KEY : fldFAC_FUNCTIE_KEY = ""
  Dim fldCAD_THEMA_TYPE : fldCAD_THEMA_TYPE = ""
  Dim fldWaar : fldWaar = ""
  Dim fldScenario : fldScenario = ""
  Dim fldCAD_THEMA_ONCLICK_URL : fldCAD_THEMA_ONCLICK_URL = ""
  Dim fldGenereer : fldGenereer = ""
  Dim fldBijwerken : fldBijwerken = ""
  Dim fldUpdatable : fldUpdatable = ""
'-------------------------------

'-------------------------------
' ThemaRecord Action begin
'-------------------------------
  sActionFileName = "cad_themagrid.asp"
  sParams = sParams & "sCAD_THEMA_OMSCHRIJVING=" & ToURL(GetParam("Trn_sCAD_THEMA_OMSCHRIJVING"))

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

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

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


'-------------------------------
' Load all form fields into variables
'-------------------------------
  fldCAD_THEMA_OMSCHRIJVING = GetParam("CAD_THEMA_OMSCHRIJVING")
  fldCAD_THEMA_VIEW = GetParam("CAD_THEMA_VIEW")
  fldCAD_LEGENDA_KEY = GetParam("CAD_LEGENDA_KEY")
  fldFAC_FUNCTIE_KEY = GetParam("FAC_FUNCTIE_KEY")
  fldCAD_THEMA_TYPE = GetParam("CAD_THEMA_TYPE")
  fldWaar = GetParam("Waar")
  fldScenario = GetParam("Scenario")
  fldCAD_THEMA_ONCLICK_URL = GetParam("CAD_THEMA_ONCLICK_URL")
  fldGenereer = getCheckBoxValue(GetParam("Genereer"), "1", "0", "Text")
  fldBijwerken = getCheckBoxValue(GetParam("Bijwerken"), "1", "0", "Text")
  fldUpdatable = GetParam("Updatable")

'-------------------------------
' Validate fields
'-------------------------------
  if sAction = "insert" or sAction = "update" then
    if not isNumeric(fldCAD_LEGENDA_KEY) then
      sThemaRecordErr = sThemaRecordErr & "The value in field Legenda is incorrect.<br>"
    end if
    if not isNumeric(fldFAC_FUNCTIE_KEY) then
      sThemaRecordErr = sThemaRecordErr & "The value in field Autorisatie Als is incorrect.<br>"
    end if
'-------------------------------
' ThemaRecord Check Event begin
if (fldGenereer = "'1'") Then
    fldCAD_LEGENDA_KEY = GenereerLegenda(fldCAD_THEMA_VIEW, fldCAD_THEMA_OMSCHRIJVING)
end if
if (fldBijwerken = "'1'") Then
    UpdateLegenda fldCAD_THEMA_VIEW, fldCAD_LEGENDA_KEY
end if
fldCAD_THEMA_TYPE = CInt(fldWaar) + CInt(fldScenario) + CInt(fldUpdatable)
' ThemaRecord Check Event end
'-------------------------------
    If len(sThemaRecordErr) > 0 then
      exit sub
    end if
  end if
'-------------------------------


'-------------------------------
' Create SQL statement
'-------------------------------
  select case sAction
    case "insert"
'-------------------------------
' ThemaRecord Insert Event begin
' ThemaRecord Insert Event end
'-------------------------------
      sSQL = "insert into CAD_THEMA (" & _
          "CAD_THEMA_OMSCHRIJVING," & _
          "CAD_THEMA_VIEW," & _
          "CAD_LEGENDA_KEY," & _
          "FAC_FUNCTIE_KEY," & _
          "CAD_THEMA_TYPE," & _
          "CAD_THEMA_ONCLICK_URL)" & _
          " values (" & _
          ToSQL(fldCAD_THEMA_OMSCHRIJVING, "Text") & "," & _
          ToSQL(fldCAD_THEMA_VIEW, "Text") & "," & _
          ToSQL(fldCAD_LEGENDA_KEY, "Number") & "," & _
          ToSQL(fldFAC_FUNCTIE_KEY, "Number") & "," & _
          ToSQL(fldCAD_THEMA_TYPE, "Text") & "," & _
          ToSQL(fldCAD_THEMA_ONCLICK_URL, "Text") & _
          ")"
    case "update"
'-------------------------------
' ThemaRecord Update Event begin
' ThemaRecord Update Event end
'-------------------------------
      sSQL = "update CAD_THEMA set " & _
        "CAD_THEMA_OMSCHRIJVING=" & ToSQL(fldCAD_THEMA_OMSCHRIJVING, "Text") & _
        ",CAD_THEMA_VIEW=" & ToSQL(fldCAD_THEMA_VIEW, "Text") & _
        ",CAD_LEGENDA_KEY=" & ToSQL(fldCAD_LEGENDA_KEY, "Number") & _
        ",FAC_FUNCTIE_KEY=" & ToSQL(fldFAC_FUNCTIE_KEY, "Number") & _
        ",CAD_THEMA_TYPE=" & ToSQL(fldCAD_THEMA_TYPE, "Text") & _
        ",CAD_THEMA_ONCLICK_URL=" & ToSQL(fldCAD_THEMA_ONCLICK_URL, "Text")
      sSQL = sSQL & " where " & sWhere
    case "delete"
'-------------------------------
' ThemaRecord Delete Event begin
' ThemaRecord Delete Event end
'-------------------------------
      sSQL = "delete from CAD_THEMA where " & sWhere
  end select
'-------------------------------
'-------------------------------
' ThemaRecord BeforeExecute Event begin
' ThemaRecord BeforeExecute Event end
'-------------------------------

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

'===============================
' Display Record Form
'-------------------------------
Sub ThemaRecord_Show()
'-------------------------------
' ThemaRecord Show begin
'-------------------------------
  Dim sWhere : sWhere = ""
  Dim sFormTitle: sFormTitle = "Details thema"
  Dim bPK : bPK = True
  Dim sFAC_FUNCTIE_KEYDisplayValue: sFAC_FUNCTIE_KEYDisplayValue = ""

'-------------------------------
' Load primary key and form parameters
'-------------------------------
  if sThemaRecordErr = "" then
    SetVar "Trn_sCAD_THEMA_OMSCHRIJVING", GetParam("sCAD_THEMA_OMSCHRIJVING")
    pCAD_THEMA_KEY = GetParam("CAD_THEMA_KEY")
    SetVar "ThemaRecordError", ""
  else
    fldCAD_THEMA_OMSCHRIJVING = GetParam("CAD_THEMA_OMSCHRIJVING")
    fldCAD_THEMA_VIEW = GetParam("CAD_THEMA_VIEW")
    fldCAD_LEGENDA_KEY = GetParam("CAD_LEGENDA_KEY")
    fldFAC_FUNCTIE_KEY = GetParam("FAC_FUNCTIE_KEY")
    fldCAD_THEMA_TYPE = GetParam("CAD_THEMA_TYPE")
    fldCAD_THEMA_ONCLICK_URL = GetParam("CAD_THEMA_ONCLICK_URL")
    SetVar "Trn_sCAD_THEMA_OMSCHRIJVING", GetParam("Trn_sCAD_THEMA_OMSCHRIJVING")
    pCAD_THEMA_KEY = GetParam("PK_CAD_THEMA_KEY")
    SetVar "sThemaRecordErr", sThemaRecordErr
    SetVar "FormTitle", sFormTitle
    Parse "ThemaRecordError", False
  end if
'-------------------------------

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

  fldWaar = GetParam("Waar")
  fldScenario = GetParam("Scenario")
  fldSleepbaar = GetParam("Sleepbaar")
  fldGenereer = GetParam("Genereer")
  fldBijwerken = GetParam("Bijwerken")
  fldUpdatable = GetParam("Updatable")
'-------------------------------

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

  if IsEmpty(pCAD_THEMA_KEY) then bPK = False
  
  sWhere = sWhere & "CAD_THEMA_KEY=" & ToSQL(pCAD_THEMA_KEY, "Number")
  SetVar "PK_CAD_THEMA_KEY", pCAD_THEMA_KEY
'-------------------------------
'-------------------------------
' ThemaRecord Open Event begin
' ThemaRecord Open Event end
'-------------------------------

  SetVar "FormTitle", sFormTitle

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

'-------------------------------
' Load all fields into variables from recordset or input parameters
'-------------------------------
  if bIsUpdateMode then
    fldCAD_THEMA_KEY = GetValue(rs, "CAD_THEMA_KEY")
    fldCAD_THEMA_TYPE = GetValue(rs, "CAD_THEMA_TYPE")

'-------------------------------
' Load data from recordset when form displayed first time
'-------------------------------
    if sThemaRecordErr = "" then
      fldCAD_THEMA_OMSCHRIJVING = GetValue(rs, "CAD_THEMA_OMSCHRIJVING")
      fldCAD_THEMA_VIEW = GetValue(rs, "CAD_THEMA_VIEW")
      fldCAD_LEGENDA_KEY = GetValue(rs, "CAD_LEGENDA_KEY")
      fldFAC_FUNCTIE_KEY = GetValue(rs, "FAC_FUNCTIE_KEY")
      fldCAD_THEMA_ONCLICK_URL = GetValue(rs, "CAD_THEMA_ONCLICK_URL")
    end if
    SetVar "ThemaRecordInsert", ""
    Parse "ThemaRecordEdit", False
'-------------------------------
' ThemaRecord ShowEdit Event begin
' ThemaRecord ShowEdit Event end
'-------------------------------
  else
    if sThemaRecordErr = "" then
      fldCAD_THEMA_TYPE= "1"
      fldGenereer= "0"
      fldBijwerken= "0"
    end if
    SetVar "ThemaRecordEdit", ""
    Parse "ThemaRecordInsert", False
'-------------------------------
' ThemaRecord ShowInsert Event begin
' ThemaRecord ShowInsert Event end
'-------------------------------
  end if
  Parse "ThemaRecordCancel", false

'-------------------------------
' Set default values
'-------------------------------
  fldGenereer= "0"
  fldBijwerken= "0"
  if sThemaRecordErr = "" then
'-------------------------------
' ThemaRecord Show Event begin
fldWaar = fldCAD_THEMA_TYPE AND 27' &B11011
If fldWaar = 0 Then
    fldWaar = 1 ' Default binnen
End If
fldScenario = fldCAD_THEMA_TYPE AND 4' &B100

fldUpdatable = fldCAD_THEMA_TYPE AND 128' &B10000000
if fldUpdatable = 128 Then
fldSleepbaar = FCLTLCL("Ja")
else
fldSleepbaar = FCLTLCL("Nee")
end if
' ThemaRecord Show Event end
'-------------------------------
  end if

'-------------------------------
' Show form field
'-------------------------------
      SetVar "CAD_THEMA_KEY", ToHTML(fldCAD_THEMA_KEY)
      SetVar "CAD_THEMA_OMSCHRIJVING", ToHTML(fldCAD_THEMA_OMSCHRIJVING)
      SetVar "CAD_THEMA_VIEW", ToHTML(fldCAD_THEMA_VIEW)
      SetVar "ThemaRecordLBCAD_LEGENDA_KEY", ""
      openrs rsCAD_LEGENDA_KEY, "select CAD_LEGENDA_KEY, CAD_LEGENDA_OMSCHRIJVING from CAD_LEGENDA order by 2"
      while not rsCAD_LEGENDA_KEY.EOF
        SetVar "ID", GetValue(rsCAD_LEGENDA_KEY, 0) : SetVar "Value", GetValue(rsCAD_LEGENDA_KEY, 1)
        if cstr(GetValue(rsCAD_LEGENDA_KEY, 0)) = cstr(fldCAD_LEGENDA_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "ThemaRecordLBCAD_LEGENDA_KEY", True
        rsCAD_LEGENDA_KEY.MoveNext
      wend
      set rsCAD_LEGENDA_KEY = nothing
    
      SetVar "ThemaRecordLBFAC_FUNCTIE_KEY", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", sFAC_FUNCTIE_KEYDisplayValue
      Parse "ThemaRecordLBFAC_FUNCTIE_KEY", True
      openrs rsFAC_FUNCTIE_KEY, "select FAC_FUNCTIE_KEY, FAC_FUNCTIE_OMSCHRIJVING from FAC_FUNCTIE order by 2"
      while not rsFAC_FUNCTIE_KEY.EOF
        SetVar "ID", GetValue(rsFAC_FUNCTIE_KEY, 0) : SetVar "Value", GetValue(rsFAC_FUNCTIE_KEY, 1)
        if cstr(GetValue(rsFAC_FUNCTIE_KEY, 0)) = cstr(fldFAC_FUNCTIE_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "ThemaRecordLBFAC_FUNCTIE_KEY", True
        rsFAC_FUNCTIE_KEY.MoveNext
      wend
      set rsFAC_FUNCTIE_KEY = nothing
    
      SetVar "CAD_THEMA_TYPE", ToHTML(fldCAD_THEMA_TYPE)
      SetVar "ThemaRecordRLWaar", ""
    
      LOV = Split(""&FCLTLCL("1;Binnen (ruimte);9;Binnen (werkplek);17;Binnen (object);2;Buiten (terreinsector);18;Buiten (object)")&"", ";")
      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(fldWaar) then SetVar "Selected", "CHECKED" else SetVar "Selected", ""
          Parse "ThemaRecordRLWaar", True
        next
      end if
    
      SetVar "ThemaRecordRLScenario", ""
    
      LOV = Split(""&FCLTLCL("0;Actuele situatie;4;Scenario situatie")&"", ";")
      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(fldScenario) then SetVar "Selected", "CHECKED" else SetVar "Selected", ""
          Parse "ThemaRecordRLScenario", True
        next
      end if
    
      SetVar "Sleepbaar", ToHTML(fldSleepbaar)
      SetVar "CAD_THEMA_ONCLICK_URL", ToHTML(fldCAD_THEMA_ONCLICK_URL)
  if (LCase(fldGenereer) = LCase("1")) then
    SetVar "Genereer_CHECKED", "CHECKED"
  else
    SetVar "Genereer_CHECKED", ""
  end if

  if (LCase(fldBijwerken) = LCase("1")) then
    SetVar "Bijwerken_CHECKED", "CHECKED"
  else
    SetVar "Bijwerken_CHECKED", ""
  end if

      SetVar "Updatable", ToHTML(fldUpdatable)
  Parse "FormThemaRecord", False

'-------------------------------
' ThemaRecord Close Event begin
' ThemaRecord Close Event end
'-------------------------------

Set rs = Nothing

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