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

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


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


'===============================
' mld_srtdisciplinegrid PageSecurity begin
' mld_srtdisciplinegrid PageSecurity end
'===============================

'===============================
' mld_srtdisciplinegrid Open Event begin
' mld_srtdisciplinegrid Open Event end
'===============================

'===============================
' mld_srtdisciplinegrid OpenAnyPage Event begin
' mld_srtdisciplinegrid OpenAnyPage Event end
'===============================

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

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

' mld_srtdisciplinegrid Show end

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

' mld_srtdisciplinegrid Close Event begin
' mld_srtdisciplinegrid Close Event end

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

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

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


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

'-------------------------------
' Build base SQL statement
'-------------------------------
  sSQL = "SELECT I.INS_SRTDISCIPLINE_KEY AS INS_SRTDISCIPLINE_KEY," & _
    "   I.INS_SRTDISCIPLINE_ALG AS INS_SRTDISCIPLINE_ALG," & _
    "   I.INS_SRTDISCIPLINE_INS AS INS_SRTDISCIPLINE_INS," & _
    "   I.INS_SRTDISCIPLINE_BES AS INS_SRTDISCIPLINE_BES," & _
    "   I.INS_SRTDISCIPLINE_MODULE AS INS_SRTDISCIPLINE_MODULE," & _
    "   I.INS_SRTDISCIPLINE_PREFIX AS INS_SRTDISCIPLINE_PREFIX," & _
    "   I.INS_SRTDISCIPLINE_OMSCHRIJVING AS INS_SRTDISCIPLINE_OMSCHRIJVING" & _
    " FROM INS_SRTDISCIPLINE I" & _
    " WHERE INS_SRTDISCIPLINE_MODULE='MLD' AND" & _
    "   INS_SRTDISCIPLINE_VERWIJDER IS NULL"
'-------------------------------

'-------------------------------
' SrtDisciplineGrid Open Event begin
if IsEmpty(iSort) then
    iSort = 4
    sDirection = " ASC"
end if
select case iSort
    case "1" sOrder = "INS_SRTDISCIPLINE_KEY"
    case "2" sOrder = "INS_SRTDISCIPLINE_PREFIX"
    case "3" sOrder = "INS_SRTDISCIPLINE_OMSCHRIJVING"
    case "4" sOrder = "INS_SRTDISCIPLINE_ALG"
    case "5" sOrder = "INS_SRTDISCIPLINE_INS"
    case "6" sOrder = "INS_SRTDISCIPLINE_BES"
end select
sOrder = " order by " & sOrder & sDirection
' SrtDisciplineGrid 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 "DListSrtDisciplineGrid", ""
    Parse "SrtDisciplineGridNoRecords", False
    SetVar "SrtDisciplineGridNavigator", ""
    Parse "FormSrtDisciplineGrid", False
    exit sub
  end if
'-------------------------------

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

  aINS_SRTDISCIPLINE_ALG = Split(""&FCLTLCL("0;Niet tonen;7;Locatie;5;Gebouw;3;Verdieping;1;Ruimte")&"", ";")
'-------------------------------
'-------------------------------
' Initialize page counter and records per page
'-------------------------------
  iRecordsPerPage = 25
  iCounter = 0
'-------------------------------

'-------------------------------
' Process page scroller
'-------------------------------
  iPage = GetParam("FormSrtDisciplineGrid_Page")
  openrs rsCount, sCountSQL
  dResult = CLng(rsCount.fields(0).value) / iRecordsPerPage
  iPageCount = int(dResult)
  if iPageCount < dResult then iPageCount = iPageCount + 1
  SetVar "SrtDisciplineGridPageCount", 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_SRTDISCIPLINE_ALG = GetValue(rs, "INS_SRTDISCIPLINE_ALG")
    fldINS_SRTDISCIPLINE_BES = GetValue(rs, "INS_SRTDISCIPLINE_BES")
    fldINS_SRTDISCIPLINE_INS = GetValue(rs, "INS_SRTDISCIPLINE_INS")
    fldINS_SRTDISCIPLINE_KEY = GetValue(rs, "INS_SRTDISCIPLINE_KEY")
    fldINS_SRTDISCIPLINE_MODULE = GetValue(rs, "INS_SRTDISCIPLINE_MODULE")
    fldINS_SRTDISCIPLINE_OMSCHRIJVING_URLLink = "mld_srtdisciplinerecord.asp"
    fldINS_SRTDISCIPLINE_OMSCHRIJVING_INS_SRTDISCIPLINE_KEY = GetValue(rs, "INS_SRTDISCIPLINE_KEY")
    fldINS_SRTDISCIPLINE_OMSCHRIJVING = GetValue(rs, "INS_SRTDISCIPLINE_OMSCHRIJVING")
    fldINS_SRTDISCIPLINE_PREFIX = GetValue(rs, "INS_SRTDISCIPLINE_PREFIX")
    fldDialect= "<a href='../fac/fac_locale_dialect.asp?dialect_id=MLD_SRTDISCIPLINE_KEY&dialect_key="&ToURL(GetValue(rs, "INS_SRTDISCIPLINE_KEY"))&"'>"&FCLTLCL("Terminologie")&"</a>"
'-------------------------------
' SrtDisciplineGrid Show begin
'-------------------------------

'-------------------------------
' SrtDisciplineGrid Show Event begin
'if fldINS_SRTDISCIPLINE_ALG = "0" then
'  fldINS_SRTDISCIPLINE_ALG = FCLTLCL("Nee")
'else
'  fldINS_SRTDISCIPLINE_ALG = FCLTLCL("Ja")
'end if

if fldINS_SRTDISCIPLINE_INS = "0" then
  fldINS_SRTDISCIPLINE_INS = FCLTLCL("Nee")
elseif fldINS_SRTDISCIPLINE_INS = "1" then
  fldINS_SRTDISCIPLINE_INS = FCLTLCL("Ja")
end if

if fldINS_SRTDISCIPLINE_BES = "0" then
  fldINS_SRTDISCIPLINE_BES = FCLTLCL("Nee")
elseif fldINS_SRTDISCIPLINE_BES = "1" then
  fldINS_SRTDISCIPLINE_BES = FCLTLCL("Ja")
end if

'Lookup opdrachttypen
sqlTypeOpdr = "select t.mld_typeopdr_omschrijving "&_
              "from mld_typeopdr t, mld_typeopdr_srtdiscipline s "&_
              "where t.mld_typeopdr_key = s.mld_typeopdr_key and "&_
              " s.ins_srtdiscipline_key = " & ToSQL(fldINS_SRTDISCIPLINE_KEY, "Number") &" "&_
              "order by t.mld_typeopdr_upper asc"
sResult = ""
openrs rsTypeOpdr,sqlTypeOpdr
while not rsTypeOpdr.EOF
  sResult = sResult & ", " & getValue(rsTypeOpdr,"mld_typeopdr_omschrijving")
  rsTypeOpdr.MoveNext
wend
if sResult <> "" then
  sResult = Mid(sResult,3,Len(sResult))
end if
fldMLD_TYPEOPDR = sResult
' SrtDisciplineGrid Show Event end
'-------------------------------

'-------------------------------
' Replace Template fields with database values
'-------------------------------
    
      SetVar "INS_SRTDISCIPLINE_KEY", ToHTML(fldINS_SRTDISCIPLINE_KEY)
      SetVar "INS_SRTDISCIPLINE_MODULE", ToHTML(fldINS_SRTDISCIPLINE_MODULE)
      SetVar "INS_SRTDISCIPLINE_PREFIX", ToHTML(fldINS_SRTDISCIPLINE_PREFIX)
      SetVar "INS_SRTDISCIPLINE_OMSCHRIJVING", ToHTML(fldINS_SRTDISCIPLINE_OMSCHRIJVING)
      SetVar "INS_SRTDISCIPLINE_OMSCHRIJVING_URLLink", fldINS_SRTDISCIPLINE_OMSCHRIJVING_URLLink
      SetVar "PrmINS_SRTDISCIPLINE_OMSCHRIJVING_INS_SRTDISCIPLINE_KEY", ToURL(fldINS_SRTDISCIPLINE_OMSCHRIJVING_INS_SRTDISCIPLINE_KEY)
      fldINS_SRTDISCIPLINE_ALG = getValFromLOV(fldINS_SRTDISCIPLINE_ALG, aINS_SRTDISCIPLINE_ALG)
      SetVar "INS_SRTDISCIPLINE_ALG", ToHTML(fldINS_SRTDISCIPLINE_ALG)
      SetVar "INS_SRTDISCIPLINE_INS", ToHTML(fldINS_SRTDISCIPLINE_INS)
      SetVar "INS_SRTDISCIPLINE_BES", ToHTML(fldINS_SRTDISCIPLINE_BES)
      SetVar "MLD_TYPEOPDR", ToHTML(fldMLD_TYPEOPDR)
      SetVar "Dialect", fldDialect
    Parse "DListSrtDisciplineGrid", True

'-------------------------------
' SrtDisciplineGrid Show end
'-------------------------------

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


'-------------------------------
' SrtDisciplineGrid Navigation begin
'-------------------------------
  bEof = rs.eof
  if rs.eof and iPage = 1 then
	SetVar "SrtDisciplineGridNavigator", ""
  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 "SrtDisciplineGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
    next
    SetVar "NavigatorPageSwitch", "_"
    SetVar "NavigatorPageNumber", iPage
    SetVar "NavigatorPageNumberView", iPage
    Parse "SrtDisciplineGridNavigatorPages", true
    iDisplayPages = iDisplayPages + 1
    SetVar "NavigatorPageSwitch", ""
    iPageCount = iPage + 1
    while iDisplayPages < iNumberOfPages and iStartPage + iDisplayPages < iHasPages
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount
      Parse "SrtDisciplineGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
      iPageCount = iPageCount + 1
    wend
    if bEof then
      SetVar "SrtDisciplineGridNavigatorLastPage", "_"
    else
      SetVar "NextPage", (iPage + 1)
    end if
    if iPage = 1 then
      SetVar "SrtDisciplineGridNavigatorFirstPage", "_"
    else
      SetVar "PrevPage", (iPage - 1)
    end if
    SetVar "SrtDisciplineGridCurrentPage", iPage
    Parse "SrtDisciplineGridNavigator", False
  end if
'-------------------------------
' SrtDisciplineGrid Navigation end
'-------------------------------

'-------------------------------
' Finish form processing
'-------------------------------
  set rs = nothing
  SetVar "SrtDisciplineGridNoRecords", ""
  Parse "FormSrtDisciplineGrid", False

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

%>