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

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


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


'===============================
' ins_srtgroepgrid PageSecurity begin
' ins_srtgroepgrid PageSecurity end
'===============================

'===============================
' ins_srtgroepgrid Open Event begin
' ins_srtgroepgrid Open Event end
'===============================

'===============================
' ins_srtgroepgrid OpenAnyPage Event begin
' ins_srtgroepgrid OpenAnyPage Event end
'===============================

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

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

' ins_srtgroepgrid Show end

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

' ins_srtgroepgrid Close Event begin
' ins_srtgroepgrid Close Event end

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

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

  SetVar "TransitParams", "INS_DISCIPLINE_KEY=" & ToURL(GetParam("INS_DISCIPLINE_KEY")) & "&sINS_SRTGROEP_UPPER=" & ToURL(GetParam("sINS_SRTGROEP_UPPER")) & "&"
  SetVar "FormParams", "INS_DISCIPLINE_KEY=" & ToURL(GetParam("INS_DISCIPLINE_KEY")) & "&sINS_SRTGROEP_UPPER=" & ToURL(GetParam("sINS_SRTGROEP_UPPER")) & "&"

'-------------------------------
' Build WHERE statement
'-------------------------------
  pINS_DISCIPLINE_KEY = GetParam("INS_DISCIPLINE_KEY")
  if IsNumeric(pINS_DISCIPLINE_KEY) and not isEmpty(pINS_DISCIPLINE_KEY) then pINS_DISCIPLINE_KEY = ToSQL(pINS_DISCIPLINE_KEY, "Number") else pINS_DISCIPLINE_KEY = Empty
  if not isEmpty(pINS_DISCIPLINE_KEY) then
    HasParam = true
    sWhere = sWhere & "I.INS_DISCIPLINE_KEY=" & pINS_DISCIPLINE_KEY
  end if


  if HasParam then
    sWhere = " WHERE (" & sWhere & ")"
  end if
  
'-------------------------------
' Build ORDER BY statement
'-------------------------------
  sOrder = " order by I.INS_SRTGROEP_UPPER Asc"
  iSort = GetParam("FormSrtGroepGrid_Sorting")
  iSorted = GetParam("FormSrtGroepGrid_Sorted")
  sDirection = ""
  if IsEmpty(iSort) then
    SetVar "Form_Sorting", ""
  else
    if iSort = iSorted then 
      SetVar "Form_Sorting", ""
      sDirection = " DESC"
      sSortParams = "FormSrtGroepGrid_Sorting=" & iSort & "&FormSrtGroepGrid_Sorted=" & iSort & "&"
    else
      SetVar "Form_Sorting", iSort
      sDirection = " ASC"
      sSortParams = "FormSrtGroepGrid_Sorting=" & iSort & "&FormSrtGroepGrid_Sorted=" & "&"
    end if
    if iSort = 1 then sOrder = " order by I.INS_SRTGROEP_KEY" & sDirection
    if iSort = 2 then sOrder = " order by I.INS_SRTGROEP_OMSCHRIJVING" & sDirection
    if iSort = 3 then sOrder = " order by I.INS_DISCIPLINE_KEY" & sDirection
  end if

'-------------------------------
' Build base SQL statement
'-------------------------------
  sSQL = "select I.INS_DISCIPLINE_KEY as I_INS_DISCIPLINE_KEY, " & _
    "I.INS_SRTGROEP_KEY as I_INS_SRTGROEP_KEY, " & _
    "I.INS_SRTGROEP_OMSCHRIJVING as I_INS_SRTGROEP_OMSCHRIJVING " & _
    " from INS_V_AANWEZIGSRTGROEP I "
'-------------------------------

'-------------------------------
' SrtGroepGrid Open Event begin
tmpWhere = ""
pINS_SRTGROEP_UPPER = getParam("sINS_SRTGROEP_UPPER")
if not isEmpty(pINS_SRTGROEP_UPPER) then
  hasParam = true
  tmpWhere = tmpWhere & " INS_SRTGROEP_UPPER like '%" & UCase(replace(pINS_SRTGROEP_UPPER,"'","''")) & "%'"
end if

if tmpWhere <> "" then
  if sWhere = "" then
    sWhere = " WHERE "
  else
    sWhere = sWhere & " AND "
  end if
  sWhere = sWhere & "(" & tmpWhere & ")"
end if
' SrtGroepGrid 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 "DListSrtGroepGrid", ""
    Parse "SrtGroepGridNoRecords", False
    SetVar "SrtGroepGridNavigator", ""
    Parse "FormSrtGroepGrid", False
    exit sub
  end if
'-------------------------------

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

'-------------------------------
' Process page scroller
'-------------------------------
  iPage = GetParam("FormSrtGroepGrid_Page")
  openrs rsCount, sCountSQL
  dResult = CLng(rsCount.fields(0).value) / iRecordsPerPage
  iPageCount = int(dResult)
  if iPageCount < dResult then iPageCount = iPageCount + 1
  SetVar "SrtGroepGridPageCount", 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
'-------------------------------
    fldINS_DISCIPLINE_KEY_URLLink = "ins_disciplinerecord.asp"
    fldINS_DISCIPLINE_KEY_INS_DISCIPLINE_KEY = GetValue(rs, "I_INS_DISCIPLINE_KEY")
    fldINS_DISCIPLINE_KEY = GetValue(rs, "I_INS_DISCIPLINE_KEY")
    fldINS_SRTGROEP_KEY = GetValue(rs, "I_INS_SRTGROEP_KEY")
    fldINS_SRTGROEP_OMSCHRIJVING_URLLink = "ins_srtgroeprecord.asp"
    fldINS_SRTGROEP_OMSCHRIJVING_INS_SRTGROEP_KEY = GetValue(rs, "I_INS_SRTGROEP_KEY")
    fldINS_SRTGROEP_OMSCHRIJVING = GetValue(rs, "I_INS_SRTGROEP_OMSCHRIJVING")
'-------------------------------
' SrtGroepGrid Show begin
'-------------------------------

'-------------------------------
' SrtGroepGrid Show Event begin
tmpsql = "select ins_discipline_omschrijving as omschrijving from ins_tab_discipline where ins_discipline_key = " & ToSQL(fldINS_DISCIPLINE_KEY, "Number")
openrs tmprs, tmpsql
fldINS_DISCIPLINE_KEY = getValue(tmprs,"omschrijving")
' SrtGroepGrid Show Event end
'-------------------------------

'-------------------------------
' Replace Template fields with database values
'-------------------------------
    
      SetVar "INS_SRTGROEP_KEY", ToHTML(fldINS_SRTGROEP_KEY)
      SetVar "INS_SRTGROEP_OMSCHRIJVING", ToHTML(fldINS_SRTGROEP_OMSCHRIJVING)
      SetVar "INS_SRTGROEP_OMSCHRIJVING_URLLink", fldINS_SRTGROEP_OMSCHRIJVING_URLLink
      SetVar "PrmINS_SRTGROEP_OMSCHRIJVING_INS_SRTGROEP_KEY", ToURL(fldINS_SRTGROEP_OMSCHRIJVING_INS_SRTGROEP_KEY)
      SetVar "INS_DISCIPLINE_KEY", ToHTML(fldINS_DISCIPLINE_KEY)
      SetVar "INS_DISCIPLINE_KEY_URLLink", fldINS_DISCIPLINE_KEY_URLLink
      SetVar "PrmINS_DISCIPLINE_KEY_INS_DISCIPLINE_KEY", ToURL(fldINS_DISCIPLINE_KEY_INS_DISCIPLINE_KEY)
    Parse "DListSrtGroepGrid", True

'-------------------------------
' SrtGroepGrid Show end
'-------------------------------

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


'-------------------------------
' SrtGroepGrid Navigation begin
'-------------------------------
  bEof = rs.eof
  if rs.eof and iPage = 1 then
	SetVar "SrtGroepGridNavigator", ""
  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 "SrtGroepGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
    next
    SetVar "NavigatorPageSwitch", "_"
    SetVar "NavigatorPageNumber", iPage
    SetVar "NavigatorPageNumberView", iPage
    Parse "SrtGroepGridNavigatorPages", true
    iDisplayPages = iDisplayPages + 1
    SetVar "NavigatorPageSwitch", ""
    iPageCount = iPage + 1
    while iDisplayPages < iNumberOfPages and iStartPage + iDisplayPages < iHasPages
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount
      Parse "SrtGroepGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
      iPageCount = iPageCount + 1
    wend
    if bEof then
      SetVar "SrtGroepGridNavigatorLastPage", "_"
    else
      SetVar "NextPage", (iPage + 1)
    end if
    if iPage = 1 then
      SetVar "SrtGroepGridNavigatorFirstPage", "_"
    else
      SetVar "PrevPage", (iPage - 1)
    end if
    SetVar "SrtGroepGridCurrentPage", iPage
    Parse "SrtGroepGridNavigator", False
  end if
'-------------------------------
' SrtGroepGrid Navigation end
'-------------------------------

'-------------------------------
' Finish form processing
'-------------------------------
  set rs = nothing
  SetVar "SrtGroepGridNoRecords", ""
  Parse "FormSrtGroepGrid", False

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


'===============================
' Display Search Form
'-------------------------------
Sub SrtGroepSearch_Show()
  Dim sFormTitle: sFormTitle = ""
  Dim sActionFileName: sActionFileName = "ins_srtgroepgrid.asp"
  Dim sINS_DISCIPLINE_KEYDisplayValue: sINS_DISCIPLINE_KEYDisplayValue = "Alles"

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

'-------------------------------
' Set variables with search parameters
'-------------------------------
      fldsINS_SRTGROEP_UPPER = GetParam("sINS_SRTGROEP_UPPER")
      fldINS_DISCIPLINE_KEY = GetParam("INS_DISCIPLINE_KEY")

'-------------------------------
' SrtGroepSearch Show begin
'-------------------------------


'-------------------------------
' SrtGroepSearch Show Event begin
' SrtGroepSearch Show Event end
'-------------------------------
      SetVar "sINS_SRTGROEP_UPPER", ToHTML(fldsINS_SRTGROEP_UPPER)
      SetVar "SrtGroepSearchLBINS_DISCIPLINE_KEY", ""
      SetVar "Selected", ""
      SetVar "ID", ""
      SetVar "Value", sINS_DISCIPLINE_KEYDisplayValue
      Parse "SrtGroepSearchLBINS_DISCIPLINE_KEY", True
      openrs rsINS_DISCIPLINE_KEY, "select ins_discipline_key,   ins_discipline_omschrijving from ins_discipline where ins_discipline_verwijder is null order by ins_discipline_omschrijving"
      while not rsINS_DISCIPLINE_KEY.EOF
        SetVar "ID", GetValue(rsINS_DISCIPLINE_KEY, 0) : SetVar "Value", GetValue(rsINS_DISCIPLINE_KEY, 1)
        if cstr(GetValue(rsINS_DISCIPLINE_KEY, 0)) = cstr(fldINS_DISCIPLINE_KEY) then SetVar "Selected", "SELECTED" else SetVar "Selected", ""
        Parse "SrtGroepSearchLBINS_DISCIPLINE_KEY", True
        rsINS_DISCIPLINE_KEY.MoveNext
      wend
      set rsINS_DISCIPLINE_KEY = nothing
    

'-------------------------------
' SrtGroepSearch Show end
'-------------------------------

'-------------------------------
' SrtGroepSearch Close Event begin
' SrtGroepSearch Close Event end
'-------------------------------
      Parse "FormSrtGroepSearch", False
End Sub
'===============================

%>