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

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


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


'===============================
' fac_profielwaardegrid PageSecurity begin
' fac_profielwaardegrid PageSecurity end
'===============================

'===============================
' fac_profielwaardegrid Open Event begin
' fac_profielwaardegrid Open Event end
'===============================

'===============================
' fac_profielwaardegrid OpenAnyPage Event begin
' fac_profielwaardegrid OpenAnyPage Event end
'===============================

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

' fac_profielwaardegrid Show begin

'===============================
' 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
'-------------------------------
ProfielSearch_Show
ProfielWaardes_Show
'-------------------------------
' Process page templates
'-------------------------------
Parse "main", False
'-------------------------------
' Output the page to the browser
'-------------------------------
Response.write PrintVar("main")

' fac_profielwaardegrid Show end

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

' fac_profielwaardegrid Close Event begin
' fac_profielwaardegrid Close Event end

cn.Close
Set cn = Nothing
UnloadTemplate
'===============================

'===============================
' Display Grid Form
'-------------------------------
Sub ProfielWaardes_Show()
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim rs
  Dim sWhere : sWhere = ""
  Dim sOrder : sOrder = ""
  Dim sSQL : sSQL = ""
  Dim sFormTitle: sFormTitle = "Profielwaardes"
  Dim HasParam : HasParam = false
  Dim iSort : iSort = ""
  Dim iSorted : iSorted = ""
  Dim sDirection : sDirection = ""
  Dim sSortParams : sSortParams = ""
  Dim iRecordsPerPage : iRecordsPerPage = 25
  Dim iCounter : iCounter = 0
  Dim iPage : iPage = 0
  Dim bEof : bEof = False
  Dim iTmpI : iTmpI = 0
  Dim iTmpJ : iTmpJ = 0
  Dim sCountSQL : sCountSQL = ""
  Dim sActionFileName : sActionFileName = "fac_profielwaarderecord.asp"

  SetVar "TransitParams", ""
  SetVar "FormParams", ""


  
'-------------------------------
' Build ORDER BY statement
'-------------------------------
  iSort = GetParam("FormProfielWaardes_Sorting")
  iSorted = GetParam("FormProfielWaardes_Sorted")
  sDirection = ""
  if IsEmpty(iSort) then
    SetVar "Form_Sorting", ""
  else
    if iSort = iSorted then 
      SetVar "Form_Sorting", ""
      sDirection = " DESC"
      sSortParams = "FormProfielWaardes_Sorting=" & iSort & "&FormProfielWaardes_Sorted=" & iSort & "&"
    else
      SetVar "Form_Sorting", iSort
      sDirection = " ASC"
      sSortParams = "FormProfielWaardes_Sorting=" & iSort & "&FormProfielWaardes_Sorted=" & "&"
    end if
  end if

'-------------------------------
' Build base SQL statement
'-------------------------------
  sSQL = "select W.FAC_PROFIELWAARDE_KEY        as FAC_PROFIELWAARDE_KEY" & _
    " ,      W.FAC_PROFIELWAARDE_LIMIET     as FAC_PROFIELWAARDE_LIMIET" & _
    " ,      W.FAC_PROFIEL_KEY              as FAC_PROFIEL_KEY" & _
    " ,      W.INS_DISCIPLINE_KEY           as INS_DISCIPLINE_KEY" & _
    " ,      P.FAC_PROFIEL_KEY              as FAC_PROFIEL_KEY" & _
    " ,      P.FAC_PROFIEL_OMSCHRIJVING     as FAC_PROFIEL_OMSCHRIJVING" & _
    " ,      D.INS_DISCIPLINE_OMSCHRIJVING  as INS_DISCIPLINE_OMSCHRIJVING" & _
    " ,      D.prefix                       as SRTDISCIPLINE_PREFIX" & _
    " ,      D.omschrijving                 as DISCIPLINE_OMSCHRIJVING" & _
    " from   FAC_PROFIELWAARDE W" & _
    " ,      FAC_PROFIEL P" & _
    " ,      (SELECT B.ins_discipline_key" & _
    "         ,      B.ins_discipline_omschrijving  as omschrijving" & _
    "         ,      ''                             as prefix" & _
    "         ,      B.ins_discipline_omschrijving" & _
    "         FROM   bes_v_aanwezigdiscipline B" & _
    "         UNION ALL" & _
    "         SELECT M.ins_discipline_key" & _
    "         ,      M.ins_discipline_omschrijving" & _
    "         ,      S.ins_srtdiscipline_prefix" & _
    "         ,      S.ins_srtdiscipline_prefix ||'-'|| M.ins_discipline_omschrijving" & _
    "         FROM   mld_v_aanwezigdiscipline M" & _
    "         ,      ins_srtdiscipline        S" & _
    "         WHERE  M.ins_srtdiscipline_key = S.ins_srtdiscipline_key" & _
    "        ) D" & _
    " where  P.FAC_PROFIEL_KEY = W.FAC_PROFIEL_KEY" & _
    " and    W.INS_DISCIPLINE_KEY = D.ins_discipline_key"
'-------------------------------

'-------------------------------
' ProfielWaardes Open Event begin
if IsEmpty(iSort) then
  iSort = 2
end if
if sDirection = " ASC" then sInvDirection = "DESC"
if sDirection = " DESC" then sInvDirection = "ASC"
if iSort = 1 then sOrder = " order by fac_profielwaarde_key " & sDirection
if iSort = 2 then sOrder = " order by fac_profiel_omschrijving "&sInvDirection
if iSort = 3 then sOrder = " order by srtdiscipline_prefix " & sDirection
if iSort = 4 then sOrder = " order by discipline_omschrijving " & sDirection
if iSort = 5 then sOrder = " order by fac_profielwaarde_limiet " & sDirection

fldFAC_PROFIEL_KEY = GetParam("FAC_PROFIEL_KEY")
if fldFAC_PROFIEL_KEY <> "" then
  sWhere = " and W.fac_profiel_key = " & ToSQL(fldFAC_PROFIEL_KEY, "Number") & " "
  SetVar "FormParams" , "fac_profiel_key = " & ToSQL(fldFAC_PROFIEL_KEY, "Number") & "&"
end if
' ProfielWaardes Open Event end
'-------------------------------

'-------------------------------
' Assemble full SQL statement
'-------------------------------
  sSQL = sSQL & sWhere & sOrder
  if sCountSQL = "" then
    iTmpI = instr(lcase(sSQL), "select")
    iTmpJ = instr(lcase(sSQL), "from") - 1
    sCountSQL = replace(sSQL, mid(sSQL, iTmpI + 6, iTmpJ - 6), " count(*) ")
    iTmpI = instr(lcase(sCountSQl), "order by")
    if iTmpI > 1 then sCountSQL = left(sCountSQL, iTmpI - 1)
  end if
'-------------------------------

SetVar "FormTitle", sFormTitle

'-------------------------------
' Process the link to the record page
'-------------------------------
  SetVar "FormAction", sActionFileName
'-------------------------------

'-------------------------------
' Process the parameters for sorting
'-------------------------------
  SetVar "SortParams", sSortParams
'-------------------------------

'-------------------------------
' Open the recordset
'-------------------------------
  openrs rs, sSQL
'-------------------------------

'-------------------------------
' Process empty recordset
'-------------------------------
  if rs.eof then
    set rs = nothing
    SetVar "DListProfielWaardes", ""
    Parse "ProfielWaardesNoRecords", False
    SetVar "ProfielWaardesNavigator", ""
    Parse "FormProfielWaardes", False
    exit sub
  end if
'-------------------------------

'-------------------------------
' Initialize page counter and records per page
'-------------------------------
  iRecordsPerPage = 25
  iCounter = 0
'-------------------------------

'-------------------------------
' Process page scroller
'-------------------------------
  iPage = GetParam("FormProfielWaardes_Page")
  openrs rsCount, sCountSQL
  dResult = CLng(rsCount.fields(0).value) / iRecordsPerPage
  iPageCount = int(dResult)
  if iPageCount < dResult then iPageCount = iPageCount + 1
  SetVar "ProfielWaardesPageCount", iPageCount
  set rsCount = nothing
  if IsEmpty(iPage) then
    iPage = 1
  else
    if iPage = "last" then iPage = iPageCount
  end if
  while not rs.eof and iCounter < (iPage-1)*iRecordsPerPage
    rs.movenext
    iCounter = iCounter + 1
  wend
  iCounter = 0
'-------------------------------

'-------------------------------
' Display grid based on recordset
'-------------------------------
  while not rs.EOF  and iCounter < iRecordsPerPage
'-------------------------------
' Create field variables based on database fields
'-------------------------------
    fldDISCIPLINE_OMSCHRIJVING_URLLink = "fac_profielwaarderecord.asp"
    fldDISCIPLINE_OMSCHRIJVING_FAC_PROFIELWAARDE_KEY = GetValue(rs, "FAC_PROFIELWAARDE_KEY")
    fldDISCIPLINE_OMSCHRIJVING = GetValue(rs, "DISCIPLINE_OMSCHRIJVING")
    fldFAC_PROFIEL_OMSCHRIJVING = GetValue(rs, "FAC_PROFIEL_OMSCHRIJVING")
    fldFAC_PROFIELWAARDE_KEY = GetValue(rs, "FAC_PROFIELWAARDE_KEY")
    fldFAC_PROFIELWAARDE_LIMIET = GetValue(rs, "FAC_PROFIELWAARDE_LIMIET")
    fldINS_DISCIPLINE_KEY = GetValue(rs, "INS_DISCIPLINE_KEY")
    fldSRTDISCIPLINE_PREFIX = GetValue(rs, "SRTDISCIPLINE_PREFIX")
'-------------------------------
' ProfielWaardes Show begin
'-------------------------------

'-------------------------------
' ProfielWaardes Show Event begin
' ProfielWaardes Show Event end
'-------------------------------

'-------------------------------
' Replace Template fields with database values
'-------------------------------
    
      SetVar "FAC_PROFIELWAARDE_KEY", ToHTML(fldFAC_PROFIELWAARDE_KEY)
      SetVar "FAC_PROFIEL_OMSCHRIJVING", ToHTML(fldFAC_PROFIEL_OMSCHRIJVING)
      SetVar "INS_DISCIPLINE_KEY", ToHTML(fldINS_DISCIPLINE_KEY)
      SetVar "SRTDISCIPLINE_PREFIX", ToHTML(fldSRTDISCIPLINE_PREFIX)
      SetVar "DISCIPLINE_OMSCHRIJVING", ToHTML(fldDISCIPLINE_OMSCHRIJVING)
      SetVar "DISCIPLINE_OMSCHRIJVING_URLLink", fldDISCIPLINE_OMSCHRIJVING_URLLink
      SetVar "PrmDISCIPLINE_OMSCHRIJVING_FAC_PROFIELWAARDE_KEY", ToURL(fldDISCIPLINE_OMSCHRIJVING_FAC_PROFIELWAARDE_KEY)
      SetVar "FAC_PROFIELWAARDE_LIMIET", ToHTML(fldFAC_PROFIELWAARDE_LIMIET)
    Parse "DListProfielWaardes", True

'-------------------------------
' ProfielWaardes Show end
'-------------------------------

'-------------------------------
' Move to the next record and increase record counter
'-------------------------------
    rs.MoveNext
    iCounter = iCounter + 1
  wend
'-------------------------------


'-------------------------------
' ProfielWaardes Navigation begin
'-------------------------------
  bEof = rs.eof
  if rs.eof and iPage = 1 then
	SetVar "ProfielWaardesNavigator", ""
  else
    iCounter = 1
    iHasPages = iPage
    iDisplayPages = 0
    iNumberOfPages = 10
    iHasPages = iPageCount
    if (iHasPages - iPage) < int(iNumberOfPages/2) then
      iStartPage = iHasPages - iNumberOfPages
    else
      iStartPage = iPage - iNumberOfPages + int(iNumberOfPages/2)
    end if
    if iStartPage < 0 then iStartPage = 0
    for iPageCount = iStartPage + 1 to iPage - 1
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount
      Parse "ProfielWaardesNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
    next
    SetVar "NavigatorPageSwitch", "_"
    SetVar "NavigatorPageNumber", iPage
    SetVar "NavigatorPageNumberView", iPage
    Parse "ProfielWaardesNavigatorPages", true
    iDisplayPages = iDisplayPages + 1
    SetVar "NavigatorPageSwitch", ""
    iPageCount = iPage + 1
    while iDisplayPages < iNumberOfPages and iStartPage + iDisplayPages < iHasPages
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount
      Parse "ProfielWaardesNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
      iPageCount = iPageCount + 1
    wend
    if bEof then
      SetVar "ProfielWaardesNavigatorLastPage", "_"
    else
      SetVar "NextPage", (iPage + 1)
    end if
    if iPage = 1 then
      SetVar "ProfielWaardesNavigatorFirstPage", "_"
    else
      SetVar "PrevPage", (iPage - 1)
    end if
    SetVar "ProfielWaardesCurrentPage", iPage
    Parse "ProfielWaardesNavigator", False
  end if
'-------------------------------
' ProfielWaardes Navigation end
'-------------------------------

'-------------------------------
' Finish form processing
'-------------------------------
  set rs = nothing
  SetVar "ProfielWaardesNoRecords", ""
  Parse "FormProfielWaardes", False

'-------------------------------
' ProfielWaardes Close Event begin
' ProfielWaardes Close Event end
'-------------------------------
End Sub
'===============================


'===============================
' Display Search Form
'-------------------------------
Sub ProfielSearch_Show()
  Dim sFormTitle: sFormTitle = "Zoeken"
  Dim sActionFileName: sActionFileName = "fac_profielwaardegrid.asp"
  Dim sFAC_PROFIEL_KEYDisplayValue: sFAC_PROFIEL_KEYDisplayValue = ""

'-------------------------------
' ProfielSearch Open Event begin
' ProfielSearch Open Event end
'-------------------------------
      SetVar "FormTitle", sFormTitle
      SetVar "ActionPage", sActionFileName

'-------------------------------
' Set variables with search parameters
'-------------------------------
      fldFAC_PROFIEL_KEY = GetParam("FAC_PROFIEL_KEY")

'-------------------------------
' ProfielSearch Show begin
'-------------------------------


'-------------------------------
' ProfielSearch Show Event begin
' ProfielSearch Show Event end
'-------------------------------
      SetVar "ProfielSearchLBFAC_PROFIEL_KEY", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", sFAC_PROFIEL_KEYDisplayValue
      Parse "ProfielSearchLBFAC_PROFIEL_KEY", True
      openrs rsFAC_PROFIEL_KEY, "select FAC_PROFIEL_KEY, FAC_PROFIEL_OMSCHRIJVING from FAC_PROFIEL order by 2"
      while not rsFAC_PROFIEL_KEY.EOF
        SetVar "ID", GetValue(rsFAC_PROFIEL_KEY, 0) : SetVar "Value", GetValue(rsFAC_PROFIEL_KEY, 1)
        if cstr(GetValue(rsFAC_PROFIEL_KEY, 0)) = cstr(fldFAC_PROFIEL_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "ProfielSearchLBFAC_PROFIEL_KEY", True
        rsFAC_PROFIEL_KEY.MoveNext
      wend
      set rsFAC_PROFIEL_KEY = nothing
    

'-------------------------------
' ProfielSearch Show end
'-------------------------------

'-------------------------------
' ProfielSearch Close Event begin
' ProfielSearch Close Event end
'-------------------------------
      Parse "FormProfielSearch", False
End Sub
'===============================

%>