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

'-------------------------------
' 
' mld_vrije_dagengrid CustomIncludes Event begin
%>
<!-- #include file="common.asp" -->
<%
' mld_vrije_dagengrid CustomIncludes Event end


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


'===============================
' mld_vrije_dagengrid PageSecurity begin
' mld_vrije_dagengrid PageSecurity end
'===============================

'===============================
' mld_vrije_dagengrid Open Event begin
' mld_vrije_dagengrid Open Event end
'===============================

'===============================
' mld_vrije_dagengrid OpenAnyPage Event begin
' mld_vrije_dagengrid OpenAnyPage Event end
'===============================

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

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

' mld_vrije_dagengrid Show end

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

' mld_vrije_dagengrid Close Event begin
' mld_vrije_dagengrid Close Event end

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

'===============================
' Display Grid Form
'-------------------------------
Sub VrijeDagenGrid_Show()
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim rs
  Dim sWhere : sWhere = ""
  Dim sOrder : sOrder = ""
  Dim sSQL : sSQL = ""
  Dim sFormTitle: sFormTitle = "Vrije dagen"
  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 = "mld_vrije_dagenrecord.asp"

  SetVar "TransitParams", "sMLD_VRIJE_DAGEN_DATUM=" & ToURL(GetParam("sMLD_VRIJE_DAGEN_DATUM")) & "&"
  SetVar "FormParams", "sMLD_VRIJE_DAGEN_DATUM=" & ToURL(GetParam("sMLD_VRIJE_DAGEN_DATUM")) & "&"

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


  
'-------------------------------
' Build ORDER BY statement
'-------------------------------
  iSort = GetParam("FormVrijeDagenGrid_Sorting")
  iSorted = GetParam("FormVrijeDagenGrid_Sorted")
  sDirection = ""
  if IsEmpty(iSort) then
    SetVar "Form_Sorting", ""
  else
    if iSort = iSorted then 
      SetVar "Form_Sorting", ""
      sDirection = " DESC"
      sSortParams = "FormVrijeDagenGrid_Sorting=" & iSort & "&FormVrijeDagenGrid_Sorted=" & iSort & "&"
    else
      SetVar "Form_Sorting", iSort
      sDirection = " ASC"
      sSortParams = "FormVrijeDagenGrid_Sorting=" & iSort & "&FormVrijeDagenGrid_Sorted=" & "&"
    end if
    if iSort = 1 then sOrder = " order by M.MLD_VRIJE_DAGEN_DATUM" & sDirection
  end if

'-------------------------------
' Build base SQL statement
'-------------------------------
  sSQL = "select M.MLD_VRIJE_DAGEN_DATUM as M_MLD_VRIJE_DAGEN_DATUM, " & _
    "M.MLD_VRIJE_DAGEN_KEY as M_MLD_VRIJE_DAGEN_KEY " & _
    " from MLD_VRIJE_DAGEN M "
'-------------------------------

'-------------------------------
' VrijeDagenGrid Open Event begin
tmpWhere = ""
pMLD_VRIJE_DAGEN_DATUM = getParam("sMLD_VRIJE_DAGEN_DATUM")
if not isEmpty(pMLD_VRIJE_DAGEN_DATUM) then
  if isNumeric(pMLD_VRIJE_DAGEN_DATUM) then
    if CLng(pMLD_VRIJE_DAGEN_DATUM) Then
      if (len(pMLD_VRIJE_DAGEN_DATUM) = 4) then
        hasParam = true
        tmpWhere = tmpWhere & " MLD_VRIJE_DAGEN_DATUM" &_
                 " between to_date('01-01-" & pMLD_VRIJE_DAGEN_DATUM & "','dd-mm-yyyy')" &_
                     " and to_date('31-12-" & pMLD_VRIJE_DAGEN_DATUM & "','dd-mm-yyyy')" 
      end if
    end if
  end if
end if

if tmpWhere <> "" then
  if sWhere = "" then
    sWhere = " WHERE "
  else
    sWhere = sWhere & " AND "
  end if
  sWhere = sWhere & "(" & tmpWhere & ")"
end if
' VrijeDagenGrid 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 "DListVrijeDagenGrid", ""
    Parse "VrijeDagenGridNoRecords", False
    SetVar "VrijeDagenGridNavigator", ""
    Parse "FormVrijeDagenGrid", False
    exit sub
  end if
'-------------------------------

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

'-------------------------------
' Process page scroller
'-------------------------------
  iPage = GetParam("FormVrijeDagenGrid_Page")
  openrs rsCount, sCountSQL
  dResult = CLng(rsCount.fields(0).value) / iRecordsPerPage
  iPageCount = int(dResult)
  if iPageCount < dResult then iPageCount = iPageCount + 1
  SetVar "VrijeDagenGridPageCount", 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
'-------------------------------
    fldMLD_VRIJE_DAGEN_DATUM_URLLink = "mld_vrije_dagenrecord.asp"
    fldMLD_VRIJE_DAGEN_DATUM_MLD_VRIJE_DAGEN_KEY = GetValue(rs, "M_MLD_VRIJE_DAGEN_KEY")
    fldMLD_VRIJE_DAGEN_DATUM = GetValue(rs, "M_MLD_VRIJE_DAGEN_DATUM")
    fldMLD_VRIJE_DAGEN_KEY = GetValue(rs, "M_MLD_VRIJE_DAGEN_KEY")
'-------------------------------
' VrijeDagenGrid Show begin
'-------------------------------

'-------------------------------
' VrijeDagenGrid Show Event begin
' VrijeDagenGrid Show Event end
'-------------------------------

'-------------------------------
' Replace Template fields with database values
'-------------------------------
    
      SetVar "MLD_VRIJE_DAGEN_KEY", ToHTML(fldMLD_VRIJE_DAGEN_KEY)
      SetVar "MLD_VRIJE_DAGEN_DATUM", ToHTML(fldMLD_VRIJE_DAGEN_DATUM)
      SetVar "MLD_VRIJE_DAGEN_DATUM_URLLink", fldMLD_VRIJE_DAGEN_DATUM_URLLink
      SetVar "PrmMLD_VRIJE_DAGEN_DATUM_MLD_VRIJE_DAGEN_KEY", ToURL(fldMLD_VRIJE_DAGEN_DATUM_MLD_VRIJE_DAGEN_KEY)
    Parse "DListVrijeDagenGrid", True

'-------------------------------
' VrijeDagenGrid Show end
'-------------------------------

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


'-------------------------------
' VrijeDagenGrid Navigation begin
'-------------------------------
  bEof = rs.eof
  if rs.eof and iPage = 1 then
	SetVar "VrijeDagenGridNavigator", ""
  else
    iCounter = 1
    iHasPages = iPage
    iDisplayPages = 0
    iNumberOfPages = 10
    iHasPages = iPageCount
    iStartPage = (((iPage - 1) \ iNumberOfPages) * iNumberOfPages)
    if iStartPage < 0 then iStartPage = 0
    if iStartPage > 0 then
      SetVar "NavigatorPageNumber", iStartPage
      SetVar "NavigatorPageNumberView", "<" & iStartPage
      Parse "VrijeDagenGridNavigatorPages", true
    end if
    for iPageCount = iStartPage + 1 to iPage - 1
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount
      Parse "VrijeDagenGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
    next
    SetVar "NavigatorPageSwitch", "_"
    SetVar "NavigatorPageNumber", iPage
    SetVar "NavigatorPageNumberView", iPage
    Parse "VrijeDagenGridNavigatorPages", true
    iDisplayPages = iDisplayPages + 1
    SetVar "NavigatorPageSwitch", ""
    iPageCount = iPage + 1
    while iDisplayPages < iNumberOfPages and iStartPage + iDisplayPages < iHasPages
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount
      Parse "VrijeDagenGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
      iPageCount = iPageCount + 1
    wend
    if iStartPage + iDisplayPages < iHasPages then
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount & ">"
      Parse "VrijeDagenGridNavigatorPages", true
    end if
    if bEof then
      SetVar "VrijeDagenGridNavigatorLastPage", "_"
    else
      SetVar "NextPage", (iPage + 1)
    end if
    if iPage = 1 then
      SetVar "VrijeDagenGridNavigatorFirstPage", "_"
    else
      SetVar "PrevPage", (iPage - 1)
    end if
    SetVar "VrijeDagenGridCurrentPage", iPage
    Parse "VrijeDagenGridNavigator", False
  end if
'-------------------------------
' VrijeDagenGrid Navigation end
'-------------------------------

'-------------------------------
' Finish form processing
'-------------------------------
  set rs = nothing
  SetVar "VrijeDagenGridNoRecords", ""
  Parse "FormVrijeDagenGrid", False

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


'===============================
' Display Search Form
'-------------------------------
Sub VrijeDagenSearch_Show()
  Dim sFormTitle: sFormTitle = ""
  Dim sActionFileName: sActionFileName = "mld_vrije_dagengrid.asp"

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

'-------------------------------
' Set variables with search parameters
'-------------------------------
      fldsMLD_VRIJE_DAGEN_DATUM = GetParam("sMLD_VRIJE_DAGEN_DATUM")

'-------------------------------
' VrijeDagenSearch Show begin
'-------------------------------


'-------------------------------
' VrijeDagenSearch Show Event begin
' VrijeDagenSearch Show Event end
'-------------------------------
      SetVar "sMLD_VRIJE_DAGEN_DATUM", ToHTML(fldsMLD_VRIJE_DAGEN_DATUM)

'-------------------------------
' VrijeDagenSearch Show end
'-------------------------------

'-------------------------------
' VrijeDagenSearch Close Event begin
' VrijeDagenSearch Close Event end
'-------------------------------
      Parse "FormVrijeDagenSearch", False
End Sub
'===============================

%>