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

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


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


'===============================
' mld_workflowgrid PageSecurity begin
' mld_workflowgrid PageSecurity end
'===============================

'===============================
' mld_workflowgrid Open Event begin
' mld_workflowgrid Open Event end
'===============================

'===============================
' mld_workflowgrid OpenAnyPage Event begin
' mld_workflowgrid OpenAnyPage Event end
'===============================

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

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

' mld_workflowgrid Show end

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

' mld_workflowgrid Close Event begin
' mld_workflowgrid Close Event end

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

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

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


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

'-------------------------------
' Build base SQL statement
'-------------------------------
  sSQL = "select M.MLD_STDMELDING_KEY," & _
    "        M.MLD_WORKFLOWSTEP_KEY," & _
    "        M.MLD_WORKFLOWSTEP_OMSCHRIJVING" & _
    " from MLD_WORKFLOWSTEP M" & _
    " where M.MLD_WORKFLOWSTEP_START_KEY is null"
'-------------------------------

'-------------------------------
' WorkflowGrid Open Event begin
sOrder=" order by Upper(mld_workflowstep_omschrijving) "
iSort = GetParam("FormWorkflowGrid_Sorting")
iSorted = GetParam("FormWorkflowGrid_Sorted")
sDirection = ""
if IsEmpty(iSort) then
  SetVar "Form_Sorting", ""
else
  if iSort = iSorted then
    SetVar "Form_Sorting", ""
    sDirection = " DESC"
    sSortParams = "FormWorkflowGrid_Sorting=" & iSort & "&FormWorkflowGrid_Sorted=" & iSort & "&"
  else
    SetVar "Form_Sorting", iSort
    sDirection = " ASC"
    sSortParams = "FormWorkflowGrid_Sorting=" & iSort & "&FormWorkflowGrid_Sorted=" & "&"
  end if
  if iSort=1 then sOrder = " order by m.mld_workflowstep_key"& sDirection
  if iSort=2 then sOrder = " order by Upper(m.mld_workflowstep_omschrijving)"& sDirection
end if
' WorkflowGrid 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 "DListWorkflowGrid", ""
    Parse "WorkflowGridNoRecords", False
    SetVar "WorkflowGridNavigator", ""
    Parse "FormWorkflowGrid", False
    exit sub
  end if
'-------------------------------

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

'-------------------------------
' Process page scroller
'-------------------------------
  iPage = GetParam("FormWorkflowGrid_Page")
  openrs rsCount, sCountSQL
  dResult = CLng(rsCount.fields(0).value) / iRecordsPerPage
  iPageCount = int(dResult)
  if iPageCount < dResult then iPageCount = iPageCount + 1
  SetVar "WorkflowGridPageCount", 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
'-------------------------------
    fldMLD_STDMELDING_KEY = GetValue(rs, "MLD_STDMELDING_KEY")
    fldMLD_WORKFLOWSTEP_KEY_URLLink = "mld_workflowstepgrid.asp"
    fldMLD_WORKFLOWSTEP_KEY_F_MLD_WORKFLOWSTEP_KEY = GetValue(rs, "MLD_WORKFLOWSTEP_KEY")
    fldMLD_WORKFLOWSTEP_KEY = GetValue(rs, "MLD_WORKFLOWSTEP_KEY")
    fldMLD_WORKFLOWSTEP_OMSCHRIJVING_URLLink = "mld_workflowstepgrid.asp"
    fldMLD_WORKFLOWSTEP_OMSCHRIJVING_F_MLD_WORKFLOWSTEP_KEY = GetValue(rs, "MLD_WORKFLOWSTEP_KEY")
    fldMLD_WORKFLOWSTEP_OMSCHRIJVING = GetValue(rs, "MLD_WORKFLOWSTEP_OMSCHRIJVING")
    fldworkflow_overzicht= "##"
'-------------------------------
' WorkflowGrid Show begin
'-------------------------------

'-------------------------------
' WorkflowGrid Show Event begin
fldworkflow_overzicht= ""&_
   "<input "&_
   "type=button " &_
   "onClick=""show_overview("&_
              ToSQL(fldMLD_WORKFLOWSTEP_KEY, "Number") &","&_
              ToSQL(fldMLD_WORKFLOWSTEP_OMSCHRIJVING, "Text") &_
              ");return false;"" "&_
   "name='overzicht' "&_
   "id='overzicht' "&_
   "value='>>'>"&_
   "</input>"

if fldMLD_STDMELDING_KEY <> "" then
  sqlTekst = "select s.mld_stdmelding_key, "&_
             "  d.ins_discipline_omschrijving "&str_concat&" ' / ' "&str_concat&" s.mld_stdmelding_omschrijving as h "&_
             "from mld_discipline d, mld_stdmelding s "&_
             "where d.ins_discipline_verwijder is null "&_
             "  and s.mld_ins_discipline_key = d.ins_discipline_key "&_
             "  and s.mld_stdmelding_key = " & ToSQL(fldMLD_STDMELDING_KEY, "Number")
  openrs rsTekst, sqlTekst
  if not rsTekst.EOF then
    fldMLD_STDMELDING_KEY = getValue(rsTekst,"h")
  end if
  rsTekst.Close
end if
' WorkflowGrid Show Event end
'-------------------------------

'-------------------------------
' Replace Template fields with database values
'-------------------------------
    
      SetVar "MLD_WORKFLOWSTEP_KEY", ToHTML(fldMLD_WORKFLOWSTEP_KEY)
      SetVar "MLD_WORKFLOWSTEP_KEY_URLLink", fldMLD_WORKFLOWSTEP_KEY_URLLink
      SetVar "PrmMLD_WORKFLOWSTEP_KEY_F_MLD_WORKFLOWSTEP_KEY", ToURL(fldMLD_WORKFLOWSTEP_KEY_F_MLD_WORKFLOWSTEP_KEY)
      SetVar "MLD_WORKFLOWSTEP_OMSCHRIJVING", ToHTML(fldMLD_WORKFLOWSTEP_OMSCHRIJVING)
      SetVar "MLD_WORKFLOWSTEP_OMSCHRIJVING_URLLink", fldMLD_WORKFLOWSTEP_OMSCHRIJVING_URLLink
      SetVar "PrmMLD_WORKFLOWSTEP_OMSCHRIJVING_F_MLD_WORKFLOWSTEP_KEY", ToURL(fldMLD_WORKFLOWSTEP_OMSCHRIJVING_F_MLD_WORKFLOWSTEP_KEY)
      SetVar "MLD_STDMELDING_KEY", ToHTML(fldMLD_STDMELDING_KEY)
      SetVar "workflow_overzicht", fldworkflow_overzicht
    Parse "DListWorkflowGrid", True

'-------------------------------
' WorkflowGrid Show end
'-------------------------------

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


'-------------------------------
' WorkflowGrid Navigation begin
'-------------------------------
  bEof = rs.eof
  if rs.eof and iPage = 1 then
	SetVar "WorkflowGridNavigator", ""
  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 "WorkflowGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
    next
    SetVar "NavigatorPageSwitch", "_"
    SetVar "NavigatorPageNumber", iPage
    SetVar "NavigatorPageNumberView", iPage
    Parse "WorkflowGridNavigatorPages", true
    iDisplayPages = iDisplayPages + 1
    SetVar "NavigatorPageSwitch", ""
    iPageCount = iPage + 1
    while iDisplayPages < iNumberOfPages and iStartPage + iDisplayPages < iHasPages
      SetVar "NavigatorPageNumber", iPageCount
      SetVar "NavigatorPageNumberView", iPageCount
      Parse "WorkflowGridNavigatorPages", true
      iDisplayPages = iDisplayPages + 1
      iPageCount = iPageCount + 1
    wend
    if bEof then
      SetVar "WorkflowGridNavigatorLastPage", "_"
    else
      SetVar "NextPage", (iPage + 1)
    end if
    if iPage = 1 then
      SetVar "WorkflowGridNavigatorFirstPage", "_"
    else
      SetVar "PrevPage", (iPage - 1)
    end if
    SetVar "WorkflowGridCurrentPage", iPage
    Parse "WorkflowGridNavigator", False
  end if
'-------------------------------
' WorkflowGrid Navigation end
'-------------------------------

'-------------------------------
' Finish form processing
'-------------------------------
  set rs = nothing
  SetVar "WorkflowGridNoRecords", ""
  Parse "FormWorkflowGrid", False

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

%>