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

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


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


'===============================
' fac_groepgrid CustomSecurity Event begin
checkAutorisation("WEB_FACMSU")
' fac_groepgrid CustomSecurity Event end
'===============================

'===============================
' fac_groepgrid Open Event begin
' fac_groepgrid Open Event end
'===============================

'===============================
' fac_groepgrid OpenAnyPage Event begin
' fac_groepgrid OpenAnyPage Event end
'===============================

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

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

' fac_groepgrid Show end

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

' fac_groepgrid Close Event begin
' fac_groepgrid Close Event end

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

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

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

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


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

'-------------------------------
' Build base SQL statement
'-------------------------------
  sSQL = "SELECT fac_groep_key, fac_groep_omschrijving, fac_groep_upper, 1 as fac_groep_aantal, fac_groep_collega FROM fac_groep"
  sOrder = ""
'-------------------------------

'-------------------------------
' GroepGrid Open Event begin
' Dit stond er origineel ook om het sorteren mogelijk te maken.
'
sOrder = " order by FAC_GROEP_UPPER Asc"
iSort = GetParam("FormGroepGrid_Sorting")
iSorted = GetParam("FormGroepGrid_Sorted")
sDirection = ""
if IsEmpty(iSort) then
  SetVar "Form_Sorting", ""
else
  if iSort = iSorted then 
    SetVar "Form_Sorting", ""
    sDirection = " DESC"
    sSortParams = "FormGroepGrid_Sorting=" & iSort & "&FormGroepGrid_Sorted=" & iSort & "&"
  else
    SetVar "Form_Sorting", iSort
    sDirection = " ASC"
    sSortParams = "FormGroepGrid_Sorting=" & iSort & "&FormGroepGrid_Sorted=" & "&"
  end if
  if iSort = 1 then sOrder = " order by FAC_GROEP_KEY" & sDirection
  if iSort = 2 then sOrder = " order by FAC_GROEP_OMSCHRIJVING" & sDirection
  if iSort = 3 then sOrder = " order by FAC_GROEP_AANTAL" & sDirection
  if iSort = 4 then sOrder = " order by FAC_GROEP_COLLEGA" & sDirection
end if
'
' Overrule de default query.
' De query in de tab "SQL" definieert alleen de benodigde velden zodat deze 
' geselecteerd kunnen worden
sSQL = "SELECT fac_groep_key" & _
       ", fac_groep_omschrijving" & _
       ", fac_groep_upper" & _
       ", aantal as FAC_GROEP_AANTAL" & _
       ", fac_groep_collega" & _
       "  FROM (SELECT g.fac_groep_key" & _
               ", g.fac_groep_omschrijving" & _
               ", g.fac_groep_upper" & _
               ", g.fac_groep_collega" & _
               ", count(u.prs_perslid_key) aantal" & _
               "  FROM fac_groep g" & _
               "  , fac_gebruikersgroep u" & _
               " WHERE g.fac_groep_key = u.fac_groep_key(+)" & _
               " GROUP BY g.fac_groep_key" & _
               " , g.fac_groep_omschrijving" & _
               " , g.fac_groep_collega" & _
               " , g.fac_groep_upper" & _
               " , g.fac_groep_collega" & _
               ") "
'
tmpWhere = ""
pFAC_GROEP_UPPER = getParam("sFAC_GROEP_UPPER")
if not isEmpty(pFAC_GROEP_UPPER) then
  hasParam = true
  tmpWhere = tmpWhere & " FAC_GROEP_UPPER like '%" & UCase(replace(pFAC_GROEP_UPPER,"'","''")) & "%'"
end if

if tmpWhere <> "" then
  sWhere = sWhere & " WHERE (" & tmpWhere & ")"
end if
' GroepGrid 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 "DListGroepGrid", ""
    Parse "GroepGridNoRecords", False
    SetVar "GroepGridNavigator", ""
    Parse "FormGroepGrid", False
    exit sub
  end if
'-------------------------------

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

  aFAC_GROEP_COLLEGA = Split(""&FCLTLCL("0;Nee;1;Ja")&"", ";")
'-------------------------------
'-------------------------------
' Initialize page counter and records per page
'-------------------------------
  iRecordsPerPage = 25
  iCounter = 0
'-------------------------------

'-------------------------------
' Process page scroller
'-------------------------------
  iPage = GetParam("FormGroepGrid_Page")
  openrs rsCount, sCountSQL
  dResult = CLng(rsCount.fields(0).value) / iRecordsPerPage
  iPageCount = int(dResult)
  if iPageCount < dResult then iPageCount = iPageCount + 1
  SetVar "GroepGridPageCount", 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_GROEP_FUNCTIE_URLLink = "fac_groeprecord.asp"
    fldFAC_GROEP_FUNCTIE_FAC_GROEP_KEY = GetValue(rs, "FAC_GROEP_KEY")
    fldFAC_GROEP_AANTAL = GetValue(rs, "FAC_GROEP_AANTAL")
    fldFAC_GROEP_COLLEGA = GetValue(rs, "FAC_GROEP_COLLEGA")
    fldFAC_GROEP_KEY = GetValue(rs, "FAC_GROEP_KEY")
    fldFAC_GROEP_OMSCHRIJVING_URLLink = "fac_authgroepgrid.asp"
    fldFAC_GROEP_OMSCHRIJVING_FAC_GROEP_KEY = GetValue(rs, "FAC_GROEP_KEY")
    fldFAC_GROEP_OMSCHRIJVING = GetValue(rs, "FAC_GROEP_OMSCHRIJVING")
    fldFAC_GROEP_FUNCTIE= ">>"
'-------------------------------
' GroepGrid Show begin
'-------------------------------

'-------------------------------
' GroepGrid Show Event begin
fldFAC_GROEP_AANTAL = GetValue(rs, "FAC_GROEP_AANTAL")
    
SetVar "FAC_GROEP_AANTAL", ToHTML(fldFAC_GROEP_AANTAL)
' GroepGrid Show Event end
'-------------------------------

'-------------------------------
' Replace Template fields with database values
'-------------------------------
    
      SetVar "FAC_GROEP_KEY", ToHTML(fldFAC_GROEP_KEY)
      SetVar "FAC_GROEP_OMSCHRIJVING", ToHTML(fldFAC_GROEP_OMSCHRIJVING)
      SetVar "FAC_GROEP_OMSCHRIJVING_URLLink", fldFAC_GROEP_OMSCHRIJVING_URLLink
      SetVar "PrmFAC_GROEP_OMSCHRIJVING_FAC_GROEP_KEY", ToURL(fldFAC_GROEP_OMSCHRIJVING_FAC_GROEP_KEY)
      SetVar "FAC_GROEP_FUNCTIE", fldFAC_GROEP_FUNCTIE
      SetVar "FAC_GROEP_FUNCTIE_URLLink", fldFAC_GROEP_FUNCTIE_URLLink
      SetVar "PrmFAC_GROEP_FUNCTIE_FAC_GROEP_KEY", ToURL(fldFAC_GROEP_FUNCTIE_FAC_GROEP_KEY)
      SetVar "FAC_GROEP_AANTAL", ToHTML(fldFAC_GROEP_AANTAL)
      fldFAC_GROEP_COLLEGA = getValFromLOV(fldFAC_GROEP_COLLEGA, aFAC_GROEP_COLLEGA)
      SetVar "FAC_GROEP_COLLEGA", ToHTML(fldFAC_GROEP_COLLEGA)
    Parse "DListGroepGrid", True

'-------------------------------
' GroepGrid Show end
'-------------------------------

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


'-------------------------------
' GroepGrid Navigation begin
'-------------------------------
  bEof = rs.eof
  if rs.eof and iPage = 1 then
	SetVar "GroepGridNavigator", ""
  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 "GroepGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
    next
    SetVar "NavigatorPageSwitch", "_"
    SetVar "NavigatorPageNumber", iPage
    SetVar "NavigatorPageNumberView", iPage
    Parse "GroepGridNavigatorPages", true
    iDisplayPages = iDisplayPages + 1
    SetVar "NavigatorPageSwitch", ""
    iPageCount = iPage + 1
    while iDisplayPages < iNumberOfPages and iStartPage + iDisplayPages < iHasPages
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount
      Parse "GroepGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
      iPageCount = iPageCount + 1
    wend
    if bEof then
      SetVar "GroepGridNavigatorLastPage", "_"
    else
      SetVar "NextPage", (iPage + 1)
    end if
    if iPage = 1 then
      SetVar "GroepGridNavigatorFirstPage", "_"
    else
      SetVar "PrevPage", (iPage - 1)
    end if
    SetVar "GroepGridCurrentPage", iPage
    Parse "GroepGridNavigator", False
  end if
'-------------------------------
' GroepGrid Navigation end
'-------------------------------

'-------------------------------
' Finish form processing
'-------------------------------
  set rs = nothing
  SetVar "GroepGridNoRecords", ""
  Parse "FormGroepGrid", False

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


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

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

'-------------------------------
' Set variables with search parameters
'-------------------------------
      fldsFAC_GROEP_UPPER = GetParam("sFAC_GROEP_UPPER")

'-------------------------------
' GroepSearch Show begin
'-------------------------------


'-------------------------------
' GroepSearch Show Event begin
' GroepSearch Show Event end
'-------------------------------
      SetVar "sFAC_GROEP_UPPER", ToHTML(fldsFAC_GROEP_UPPER)

'-------------------------------
' GroepSearch Show end
'-------------------------------

'-------------------------------
' GroepSearch Close Event begin
' GroepSearch Close Event end
'-------------------------------
      Parse "FormGroepSearch", False
End Sub
'===============================

%>