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

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


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


'===============================
' cnt_disciplinegrid PageSecurity begin
' cnt_disciplinegrid PageSecurity end
'===============================

'===============================
' cnt_disciplinegrid Open Event begin
' cnt_disciplinegrid Open Event end
'===============================

'===============================
' cnt_disciplinegrid OpenAnyPage Event begin
' cnt_disciplinegrid OpenAnyPage Event end
'===============================

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

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

' cnt_disciplinegrid Show end

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

' cnt_disciplinegrid Close Event begin
' cnt_disciplinegrid Close Event end

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

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

  SetVar "TransitParams", "sINS_DISCIPLINE_OMSCHRIJVING=" & ToURL(GetParam("sINS_DISCIPLINE_OMSCHRIJVING")) & "&"
  SetVar "FormParams", "INS_SRTDISCIPLINE_KEY=" & ToURL(GetParam("INS_SRTDISCIPLINE_KEY")) & "&sINS_DISCIPLINE_OMSCHRIJVING=" & ToURL(GetParam("sINS_DISCIPLINE_OMSCHRIJVING")) & "&"

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


  if HasParam then
    sWhere = " AND (" & sWhere & ")"
  end if
  
'-------------------------------
' Build ORDER BY statement
'-------------------------------
  sOrder = " order by C.INS_DISCIPLINE_OMSCHRIJVING Asc"
  iSort = GetParam("FormDisciplineGrid_Sorting")
  iSorted = GetParam("FormDisciplineGrid_Sorted")
  sDirection = ""
  if IsEmpty(iSort) then
    SetVar "Form_Sorting", ""
  else
    if iSort = iSorted then 
      SetVar "Form_Sorting", ""
      sDirection = " DESC"
      sSortParams = "FormDisciplineGrid_Sorting=" & iSort & "&FormDisciplineGrid_Sorted=" & iSort & "&"
    else
      SetVar "Form_Sorting", iSort
      sDirection = " ASC"
      sSortParams = "FormDisciplineGrid_Sorting=" & iSort & "&FormDisciplineGrid_Sorted=" & "&"
    end if
    if iSort = 1 then sOrder = " order by C.INS_DISCIPLINE_KEY" & sDirection
    if iSort = 2 then sOrder = " order by C.INS_DISCIPLINE_OMSCHRIJVING" & sDirection
    if iSort = 3 then sOrder = " order by P.PRS_KOSTENSOORT_OMS" & sDirection
    if iSort = 4 then sOrder = " order by C1.CNT_SRTCONTRACT_TYPE" & sDirection
  end if

'-------------------------------
' Build base SQL statement
'-------------------------------
  sSQL = "select C.INS_DISCIPLINE_KEY as C_INS_DISCIPLINE_KEY, " & _
    "C.INS_DISCIPLINE_OMSCHRIJVING as C_INS_DISCIPLINE_OMSCHRIJVING, " & _
    "C.INS_SRTDISCIPLINE_KEY as C_INS_SRTDISCIPLINE_KEY, " & _
    "C.PRS_KOSTENSOORT_KEY as C_PRS_KOSTENSOORT_KEY, " & _
    "P.PRS_KOSTENSOORT_KEY as P_PRS_KOSTENSOORT_KEY, " & _
    "P.PRS_KOSTENSOORT_OMS as P_PRS_KOSTENSOORT_OMS, " & _
    "C1.CNT_INS_DISCIPLINE_KEY as C1_CNT_INS_DISCIPLINE_KEY, " & _
    "C1.CNT_SRTCONTRACT_TYPE as C1_CNT_SRTCONTRACT_TYPE " & _
    " from CNT_V_AANWEZIGDISCIPLINE C, PRS_KOSTENSOORT P, CNT_DISC_PARAMS C1" & _
    " where P.PRS_KOSTENSOORT_KEY(+)=C.PRS_KOSTENSOORT_KEY and C1.CNT_INS_DISCIPLINE_KEY=C.INS_DISCIPLINE_KEY  "
'-------------------------------

'-------------------------------
' DisciplineGrid Open Event begin
pINS_DISCIPLINE_OMSCHRIJVING = getParam("sINS_DISCIPLINE_OMSCHRIJVING")
if not isEmpty(pINS_DISCIPLINE_OMSCHRIJVING) then
  sWhere = sWhere & " AND Upper(INS_DISCIPLINE_OMSCHRIJVING) like '%" & UCase(replace(pINS_DISCIPLINE_OMSCHRIJVING,"'","''")) & "%'"
end if
' DisciplineGrid 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 "DListDisciplineGrid", ""
    Parse "DisciplineGridNoRecords", False
    SetVar "DisciplineGridNavigator", ""
    Parse "FormDisciplineGrid", False
    exit sub
  end if
'-------------------------------

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

'-------------------------------
' Process page scroller
'-------------------------------
  iPage = GetParam("FormDisciplineGrid_Page")
  openrs rsCount, sCountSQL
  dResult = CLng(rsCount.fields(0).value) / iRecordsPerPage
  iPageCount = int(dResult)
  if iPageCount < dResult then iPageCount = iPageCount + 1
  SetVar "DisciplineGridPageCount", 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 = "cnt_disciplinerecord.asp"
    fldINS_DISCIPLINE_KEY_INS_DISCIPLINE_KEY = GetValue(rs, "C_INS_DISCIPLINE_KEY")
    fldINS_DISCIPLINE_KEY = GetValue(rs, "C_INS_DISCIPLINE_KEY")
    fldSRTCONTRACT = GetValue(rs, "C1_CNT_SRTCONTRACT_TYPE")
    fldINS_DISCIPLINE_OMSCHRIJVING_URLLink = "cnt_disciplinerecord.asp"
    fldINS_DISCIPLINE_OMSCHRIJVING_INS_DISCIPLINE_KEY = GetValue(rs, "C_INS_DISCIPLINE_KEY")
    fldINS_DISCIPLINE_OMSCHRIJVING = GetValue(rs, "C_INS_DISCIPLINE_OMSCHRIJVING")
    fldPRS_KOSTENSOORT_KEY = GetValue(rs, "P_PRS_KOSTENSOORT_OMS")
'-------------------------------
' DisciplineGrid Show begin
'-------------------------------

'-------------------------------
' DisciplineGrid Show Event begin
fldSRTCONTRACT = DLookUp("CNT_TYPECONTRACT", "CNT_TYPECONTRACT_OMSCHRIJVING", "CNT_TYPECONTRACT_KEY=" & ToSQL(fldSRTCONTRACT, "Number"))
' DisciplineGrid Show Event end
'-------------------------------

'-------------------------------
' Replace Template fields with database values
'-------------------------------
    
      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)
      SetVar "INS_DISCIPLINE_OMSCHRIJVING", ToHTML(fldINS_DISCIPLINE_OMSCHRIJVING)
      SetVar "INS_DISCIPLINE_OMSCHRIJVING_URLLink", fldINS_DISCIPLINE_OMSCHRIJVING_URLLink
      SetVar "PrmINS_DISCIPLINE_OMSCHRIJVING_INS_DISCIPLINE_KEY", ToURL(fldINS_DISCIPLINE_OMSCHRIJVING_INS_DISCIPLINE_KEY)
      SetVar "PRS_KOSTENSOORT_KEY", ToHTML(fldPRS_KOSTENSOORT_KEY)
      SetVar "SRTCONTRACT", ToHTML(fldSRTCONTRACT)
    Parse "DListDisciplineGrid", True

'-------------------------------
' DisciplineGrid Show end
'-------------------------------

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


'-------------------------------
' DisciplineGrid Navigation begin
'-------------------------------
  bEof = rs.eof
  if rs.eof and iPage = 1 then
	SetVar "DisciplineGridNavigator", ""
  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 "DisciplineGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
    next
    SetVar "NavigatorPageSwitch", "_"
    SetVar "NavigatorPageNumber", iPage
    SetVar "NavigatorPageNumberView", iPage
    Parse "DisciplineGridNavigatorPages", true
    iDisplayPages = iDisplayPages + 1
    SetVar "NavigatorPageSwitch", ""
    iPageCount = iPage + 1
    while iDisplayPages < iNumberOfPages and iStartPage + iDisplayPages < iHasPages
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount
      Parse "DisciplineGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
      iPageCount = iPageCount + 1
    wend
    if bEof then
      SetVar "DisciplineGridNavigatorLastPage", "_"
    else
      SetVar "NextPage", (iPage + 1)
    end if
    if iPage = 1 then
      SetVar "DisciplineGridNavigatorFirstPage", "_"
    else
      SetVar "PrevPage", (iPage - 1)
    end if
    SetVar "DisciplineGridCurrentPage", iPage
    Parse "DisciplineGridNavigator", False
  end if
'-------------------------------
' DisciplineGrid Navigation end
'-------------------------------

'-------------------------------
' Finish form processing
'-------------------------------
  set rs = nothing
  SetVar "DisciplineGridNoRecords", ""
  Parse "FormDisciplineGrid", False

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


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

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

'-------------------------------
' Set variables with search parameters
'-------------------------------
      fldsINS_DISCIPLINE_OMSCHRIJVING = GetParam("sINS_DISCIPLINE_OMSCHRIJVING")

'-------------------------------
' DisciplineSearch Show begin
'-------------------------------


'-------------------------------
' DisciplineSearch Show Event begin
' DisciplineSearch Show Event end
'-------------------------------
      SetVar "sINS_DISCIPLINE_OMSCHRIJVING", ToHTML(fldsINS_DISCIPLINE_OMSCHRIJVING)

'-------------------------------
' DisciplineSearch Show end
'-------------------------------

'-------------------------------
' DisciplineSearch Close Event begin
' DisciplineSearch Close Event end
'-------------------------------
      Parse "FormDisciplineSearch", False
End Sub
'===============================

%>