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

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


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


'===============================
' fac_srtnotificatiesrtgrid PageSecurity begin
' fac_srtnotificatiesrtgrid PageSecurity end
'===============================

'===============================
' fac_srtnotificatiesrtgrid Open Event begin
' fac_srtnotificatiesrtgrid Open Event end
'===============================

'===============================
' fac_srtnotificatiesrtgrid OpenAnyPage Event begin
' fac_srtnotificatiesrtgrid OpenAnyPage Event end
'===============================

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

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

' fac_srtnotificatiesrtgrid Show end

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

' fac_srtnotificatiesrtgrid Close Event begin
' fac_srtnotificatiesrtgrid Close Event end

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

'===============================
' Display Grid Form
'-------------------------------
Sub NotificatiesrtGrid_Show()
'-------------------------------
' Initialize variables  
'-------------------------------
  Dim rs
  Dim sWhere : sWhere = ""
  Dim sOrder : sOrder = ""
  Dim sSQL : sSQL = ""
  Dim sFormTitle: sFormTitle = "Notificaties"
  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 = ""

  SetVar "TransitParams", "FAC_SRTNOTIFICATIE_XMLNODE=" & ToURL(GetParam("FAC_SRTNOTIFICATIE_XMLNODE")) & "&sFAC_SRTNOTIFICATIE_OMS=" & ToURL(GetParam("sFAC_SRTNOTIFICATIE_OMS")) & "&"
  SetVar "FormParams", "FAC_SRTNOTIFICATIE_XMLNODE=" & ToURL(GetParam("FAC_SRTNOTIFICATIE_XMLNODE")) & "&sFAC_SRTNOTIFICATIE_OMS=" & ToURL(GetParam("sFAC_SRTNOTIFICATIE_OMS")) & "&"

'-------------------------------
' Build WHERE statement
'-------------------------------
  pFAC_SRTNOTIFICATIE_XMLNODE = GetParam("FAC_SRTNOTIFICATIE_XMLNODE")
  if not isEmpty(pFAC_SRTNOTIFICATIE_XMLNODE) then
    HasParam = true
    sWhere = sWhere & "F.FAC_SRTNOTIFICATIE_XMLNODE='" & replace(pFAC_SRTNOTIFICATIE_XMLNODE, "'", "''") & "'"
  end if


  if HasParam then
    sWhere = " WHERE (" & sWhere & ")"
  end if
  
'-------------------------------
' Build ORDER BY statement
'-------------------------------
  sOrder = " order by F.FAC_SRTNOTIFICATIE_CODE Asc"
  iSort = GetParam("FormNotificatiesrtGrid_Sorting")
  iSorted = GetParam("FormNotificatiesrtGrid_Sorted")
  sDirection = ""
  if IsEmpty(iSort) then
    SetVar "Form_Sorting", ""
  else
    if iSort = iSorted then 
      SetVar "Form_Sorting", ""
      sDirection = " DESC"
      sSortParams = "FormNotificatiesrtGrid_Sorting=" & iSort & "&FormNotificatiesrtGrid_Sorted=" & iSort & "&"
    else
      SetVar "Form_Sorting", iSort
      sDirection = " ASC"
      sSortParams = "FormNotificatiesrtGrid_Sorting=" & iSort & "&FormNotificatiesrtGrid_Sorted=" & "&"
    end if
    if iSort = 1 then sOrder = " order by F.FAC_SRTNOTIFICATIE_XMLNODE" & sDirection
    if iSort = 2 then sOrder = " order by F.FAC_SRTNOTIFICATIE_CODE" & sDirection
    if iSort = 3 then sOrder = " order by F.FAC_SRTNOTIFICATIE_OMS" & sDirection
    if iSort = 4 then sOrder = " order by F.FAC_SRTNOTIFICATIE_MODE" & sDirection
    if iSort = 5 then sOrder = " order by F.FAC_SRTNOTIFICATIE_USERMODE" & sDirection
    if iSort = 6 then sOrder = " order by F.FAC_SRTNOTIFICATIE_GEBOUW" & sDirection
    if iSort = 7 then sOrder = " order by F.FAC_SRTNOTIFICATIE_DELAY" & sDirection
  end if

'-------------------------------
' Build base SQL statement
'-------------------------------
  sSQL = "select F.FAC_SRTNOTIFICATIE_CODE as F_FAC_SRTNOTIFICATIE_CODE, " & _
    "F.FAC_SRTNOTIFICATIE_DELAY as F_FAC_SRTNOTIFICATIE_DELAY, " & _
    "F.FAC_SRTNOTIFICATIE_GEBOUW as F_FAC_SRTNOTIFICATIE_GEBOUW, " & _
    "F.FAC_SRTNOTIFICATIE_KEY as F_FAC_SRTNOTIFICATIE_KEY, " & _
    "F.FAC_SRTNOTIFICATIE_MODE as F_FAC_SRTNOTIFICATIE_MODE, " & _
    "F.FAC_SRTNOTIFICATIE_OMS as F_FAC_SRTNOTIFICATIE_OMS, " & _
    "F.FAC_SRTNOTIFICATIE_USERMODE as F_FAC_SRTNOTIFICATIE_USERMODE, " & _
    "F.FAC_SRTNOTIFICATIE_XMLNODE as F_FAC_SRTNOTIFICATIE_XMLNODE " & _
    " from FAC_SRTNOTIFICATIE F "
'-------------------------------

'-------------------------------
' NotificatiesrtGrid Open Event begin
sWhere = ""
tmpWhere = ""
pFAC_SRTNOTIFICATIE_OMS = getParam("sFAC_SRTNOTIFICATIE_OMS")
if not isEmpty(pFAC_SRTNOTIFICATIE_OMS) then
  tmpWhere = tmpWhere & " AND Upper(FAC_SRTNOTIFICATIE_OMS) like '%" & UCase(replace(pFAC_SRTNOTIFICATIE_OMS,"'","''")) & "%'"
end if

if not isEmpty(pFAC_SRTNOTIFICATIE_XMLNODE) then
  if pFAC_SRTNOTIFICATIE_XMLNODE = "<empty>" then
    tmpWhere = tmpWhere & " AND F.FAC_SRTNOTIFICATIE_XMLNODE IS NULL"
  else
    tmpWhere = tmpWhere & " AND F.FAC_SRTNOTIFICATIE_XMLNODE='" & replace(pFAC_SRTNOTIFICATIE_XMLNODE, "'", "''") & "'"
  end if
end if

if tmpWhere <> "" then
  tmpWhere = mid(tmpWhere,5)
  sWhere = " WHERE (" & tmpWhere & ")"
end if



if tmpWhere <> "" then
  if sWhere = "" then
    sWhere = " WHERE "
  else
    sWhere = sWhere & " AND "
  end if
  sWhere = sWhere & "(" & tmpWhere & ")"
end if
' NotificatiesrtGrid 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 parameters for sorting
'-------------------------------
  SetVar "SortParams", sSortParams
'-------------------------------

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

'-------------------------------
' Process empty recordset
'-------------------------------
  if rs.eof then
    set rs = nothing
    SetVar "DListNotificatiesrtGrid", ""
    Parse "NotificatiesrtGridNoRecords", False
    SetVar "NotificatiesrtGridNavigator", ""
    Parse "FormNotificatiesrtGrid", False
    exit sub
  end if
'-------------------------------

'-------------------------------
' Prepare the lists of values
'-------------------------------

  aBIT0_STATUS = Split(""&FCLTLCL("0;;1;Aan")&"", ";")
  aBIT1_MAIL = Split(""&FCLTLCL("0;;2;Aan")&"", ";")
  aBIT2_SMS = Split(""&FCLTLCL("0;;4;Aan")&"", ";")
  aBIT3_ALERT = Split(""&FCLTLCL("0;;8;Aan")&"", ";")
  aFAC_SRTNOTIFICATIE_USERMODE = Split(""&FCLTLCL("0;;1;Ja")&"", ";")
  aFAC_SRTNOTIFICATIE_GEBOUW = Split(""&FCLTLCL("0;;1;Ja")&"", ";")
'-------------------------------
'-------------------------------
' Initialize page counter and records per page
'-------------------------------
  iRecordsPerPage = 25
  iCounter = 0
'-------------------------------

'-------------------------------
' Process page scroller
'-------------------------------
  iPage = GetParam("FormNotificatiesrtGrid_Page")
  openrs rsCount, sCountSQL
  dResult = CLng(rsCount.fields(0).value) / iRecordsPerPage
  iPageCount = int(dResult)
  if iPageCount < dResult then iPageCount = iPageCount + 1
  SetVar "NotificatiesrtGridPageCount", 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
'-------------------------------
    fldFAC_SRTNOTIFICATIE_CODE_URLLink = "fac_srtnotificatierecord.asp"
    fldFAC_SRTNOTIFICATIE_CODE_FAC_SRTNOTIFICATIE_KEY = GetValue(rs, "F_FAC_SRTNOTIFICATIE_KEY")
    fldFAC_SRTNOTIFICATIE_CODE = GetValue(rs, "F_FAC_SRTNOTIFICATIE_CODE")
    fldFAC_SRTNOTIFICATIE_DELAY = GetValue(rs, "F_FAC_SRTNOTIFICATIE_DELAY")
    fldFAC_SRTNOTIFICATIE_GEBOUW = GetValue(rs, "F_FAC_SRTNOTIFICATIE_GEBOUW")
    fldFAC_SRTNOTIFICATIE_MODE = GetValue(rs, "F_FAC_SRTNOTIFICATIE_MODE")
    fldFAC_SRTNOTIFICATIE_OMS_URLLink = "fac_srtnotificatierecord.asp"
    fldFAC_SRTNOTIFICATIE_OMS_FAC_SRTNOTIFICATIE_KEY = GetValue(rs, "F_FAC_SRTNOTIFICATIE_KEY")
    fldFAC_SRTNOTIFICATIE_OMS = GetValue(rs, "F_FAC_SRTNOTIFICATIE_OMS")
    fldFAC_SRTNOTIFICATIE_USERMODE = GetValue(rs, "F_FAC_SRTNOTIFICATIE_USERMODE")
    fldFAC_SRTNOTIFICATIE_XMLNODE = GetValue(rs, "F_FAC_SRTNOTIFICATIE_XMLNODE")
'-------------------------------
' NotificatiesrtGrid Show begin
'-------------------------------

'-------------------------------
' NotificatiesrtGrid Show Event begin
fldBIT0_STATUS = fldFAC_SRTNOTIFICATIE_MODE AND 1 ' &B0001
fldBIT1_MAIL = fldFAC_SRTNOTIFICATIE_MODE AND 2 ' &B0100
fldBIT2_SMS = fldFAC_SRTNOTIFICATIE_MODE AND 4 ' &B0010
fldBIT3_ALERT = fldFAC_SRTNOTIFICATIE_MODE AND 8 ' &B1000
' NotificatiesrtGrid Show Event end
'-------------------------------

'-------------------------------
' Replace Template fields with database values
'-------------------------------
    
      SetVar "FAC_SRTNOTIFICATIE_XMLNODE", ToHTML(fldFAC_SRTNOTIFICATIE_XMLNODE)
      SetVar "FAC_SRTNOTIFICATIE_CODE", ToHTML(fldFAC_SRTNOTIFICATIE_CODE)
      SetVar "FAC_SRTNOTIFICATIE_CODE_URLLink", fldFAC_SRTNOTIFICATIE_CODE_URLLink
      SetVar "PrmFAC_SRTNOTIFICATIE_CODE_FAC_SRTNOTIFICATIE_KEY", ToURL(fldFAC_SRTNOTIFICATIE_CODE_FAC_SRTNOTIFICATIE_KEY)
      SetVar "FAC_SRTNOTIFICATIE_OMS", ToHTML(fldFAC_SRTNOTIFICATIE_OMS)
      SetVar "FAC_SRTNOTIFICATIE_OMS_URLLink", fldFAC_SRTNOTIFICATIE_OMS_URLLink
      SetVar "PrmFAC_SRTNOTIFICATIE_OMS_FAC_SRTNOTIFICATIE_KEY", ToURL(fldFAC_SRTNOTIFICATIE_OMS_FAC_SRTNOTIFICATIE_KEY)
      SetVar "FAC_SRTNOTIFICATIE_MODE", ToHTML(fldFAC_SRTNOTIFICATIE_MODE)
      fldBIT0_STATUS = getValFromLOV(fldBIT0_STATUS, aBIT0_STATUS)
      SetVar "BIT0_STATUS", ToHTML(fldBIT0_STATUS)
      fldBIT1_MAIL = getValFromLOV(fldBIT1_MAIL, aBIT1_MAIL)
      SetVar "BIT1_MAIL", ToHTML(fldBIT1_MAIL)
      fldBIT2_SMS = getValFromLOV(fldBIT2_SMS, aBIT2_SMS)
      SetVar "BIT2_SMS", ToHTML(fldBIT2_SMS)
      fldBIT3_ALERT = getValFromLOV(fldBIT3_ALERT, aBIT3_ALERT)
      SetVar "BIT3_ALERT", ToHTML(fldBIT3_ALERT)
      fldFAC_SRTNOTIFICATIE_USERMODE = getValFromLOV(fldFAC_SRTNOTIFICATIE_USERMODE, aFAC_SRTNOTIFICATIE_USERMODE)
      SetVar "FAC_SRTNOTIFICATIE_USERMODE", ToHTML(fldFAC_SRTNOTIFICATIE_USERMODE)
      fldFAC_SRTNOTIFICATIE_GEBOUW = getValFromLOV(fldFAC_SRTNOTIFICATIE_GEBOUW, aFAC_SRTNOTIFICATIE_GEBOUW)
      SetVar "FAC_SRTNOTIFICATIE_GEBOUW", ToHTML(fldFAC_SRTNOTIFICATIE_GEBOUW)
      SetVar "FAC_SRTNOTIFICATIE_DELAY", ToHTML(fldFAC_SRTNOTIFICATIE_DELAY)
    Parse "DListNotificatiesrtGrid", True

'-------------------------------
' NotificatiesrtGrid Show end
'-------------------------------

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


'-------------------------------
' NotificatiesrtGrid Navigation begin
'-------------------------------
  bEof = rs.eof
  if rs.eof and iPage = 1 then
	SetVar "NotificatiesrtGridNavigator", ""
  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 "NotificatiesrtGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
    next
    SetVar "NavigatorPageSwitch", "_"
    SetVar "NavigatorPageNumber", iPage
    SetVar "NavigatorPageNumberView", iPage
    Parse "NotificatiesrtGridNavigatorPages", true
    iDisplayPages = iDisplayPages + 1
    SetVar "NavigatorPageSwitch", ""
    iPageCount = iPage + 1
    while iDisplayPages < iNumberOfPages and iStartPage + iDisplayPages < iHasPages
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount
      Parse "NotificatiesrtGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
      iPageCount = iPageCount + 1
    wend
    if bEof then
      SetVar "NotificatiesrtGridNavigatorLastPage", "_"
    else
      SetVar "NextPage", (iPage + 1)
    end if
    if iPage = 1 then
      SetVar "NotificatiesrtGridNavigatorFirstPage", "_"
    else
      SetVar "PrevPage", (iPage - 1)
    end if
    SetVar "NotificatiesrtGridCurrentPage", iPage
    Parse "NotificatiesrtGridNavigator", False
  end if
'-------------------------------
' NotificatiesrtGrid Navigation end
'-------------------------------

'-------------------------------
' Finish form processing
'-------------------------------
  set rs = nothing
  SetVar "NotificatiesrtGridNoRecords", ""
  Parse "FormNotificatiesrtGrid", False

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


'===============================
' Display Search Form
'-------------------------------
Sub NotificatiesrtSearch_Show()
  Dim sFormTitle: sFormTitle = ""
  Dim sActionFileName: sActionFileName = "fac_srtnotificatiesrtgrid.asp"
  Dim sFAC_SRTNOTIFICATIE_XMLNODEDisplayValue: sFAC_SRTNOTIFICATIE_XMLNODEDisplayValue = "Alles"

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

'-------------------------------
' Set variables with search parameters
'-------------------------------
      fldsFAC_SRTNOTIFICATIE_OMS = GetParam("sFAC_SRTNOTIFICATIE_OMS")
      fldFAC_SRTNOTIFICATIE_XMLNODE = GetParam("FAC_SRTNOTIFICATIE_XMLNODE")

'-------------------------------
' NotificatiesrtSearch Show begin
'-------------------------------


'-------------------------------
' NotificatiesrtSearch Show Event begin
' NotificatiesrtSearch Show Event end
'-------------------------------
      SetVar "sFAC_SRTNOTIFICATIE_OMS", ToHTML(fldsFAC_SRTNOTIFICATIE_OMS)
      SetVar "NotificatiesrtSearchLBFAC_SRTNOTIFICATIE_XMLNODE", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", sFAC_SRTNOTIFICATIE_XMLNODEDisplayValue
      Parse "NotificatiesrtSearchLBFAC_SRTNOTIFICATIE_XMLNODE", True
      openrs rsFAC_SRTNOTIFICATIE_XMLNODE, "SELECT distinct NVL(fac_srtnotificatie_xmlnode,'<empty>'), fac_srtnotificatie_xmlnode FROM fac_srtnotificatie ORDER BY 1 NULLS FIRST"
      while not rsFAC_SRTNOTIFICATIE_XMLNODE.EOF
        SetVar "ID", GetValue(rsFAC_SRTNOTIFICATIE_XMLNODE, 0) : SetVar "Value", GetValue(rsFAC_SRTNOTIFICATIE_XMLNODE, 1)
        if cstr(GetValue(rsFAC_SRTNOTIFICATIE_XMLNODE, 0)) = cstr(fldFAC_SRTNOTIFICATIE_XMLNODE) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "NotificatiesrtSearchLBFAC_SRTNOTIFICATIE_XMLNODE", True
        rsFAC_SRTNOTIFICATIE_XMLNODE.MoveNext
      wend
      set rsFAC_SRTNOTIFICATIE_XMLNODE = nothing
    

'-------------------------------
' NotificatiesrtSearch Show end
'-------------------------------

'-------------------------------
' NotificatiesrtSearch Close Event begin
' NotificatiesrtSearch Close Event end
'-------------------------------
      Parse "FormNotificatiesrtSearch", False
End Sub
'===============================

%>