<!--- 
 Filename: NextN5.cfm
 Created by: Nate Weiss (NMW)
 Purpose: Displays Next N record-navigation interface
 Please Note Includes NextNIncludeBackNext.cfm and NextNIncludePageLinks
--->

<!--- Retrieve expense records from database --->
<cfquery name="getExp" datasource="#APPLICATION.dataSource#">
 SELECT 
 f.FilmID, f.MovieTitle, 
 e.Description, e.ExpenseAmount, e.ExpenseDate
 FROM 
 Expenses e INNER JOIN Films f
 ON e.FilmID = f.FilmID
 ORDER BY 
 e.ExpenseDate DESC
</cfquery>


<!--- Number of rows to display per Next/Back page --->
<cfset rowsPerPage = 10>

<!--- What row to start at? Assume first by default --->
<cfparam name="URL.startRow" default="1" type="numeric">

<!--- Allow for Show All parameter in the URL --->
<cfparam name="URL.showAll" type="boolean" default="no">

<!--- We know the total number of rows from query --->
<cfset totalRows = getExp.recordCount>
<!--- Show all on page if ShowAll passed in URL --->
<cfif URL.showAll>
 <cfset rowsPerPage = totalRows>
</cfif>

<!--- Last row is 10 rows past the starting row, or --->
<!--- total number of query rows, whichever is less --->
<cfset endRow = min(URL.startRow + rowsPerPage - 1, totalRows)>

<!--- Next button goes to 1 past current end row --->
<cfset startRowNext = endRow + 1>

<!--- Back button goes back N rows from start row --->
<cfset startRowBack = URL.startRow - rowsPerPage>


<!--- Page Title --->
<html>
<head><title>Expense Browser</title></head>
<body>
<cfoutput><h2>#APPLICATION.companyName# Expense Report</h2></cfoutput>

<!--- simple style sheet for formatting --->
<style>
 th {font-family:sans-serif;font-size:smaller;
 background:navy;color:white}
 td {font-family:sans-serif;font-size:smaller}
 td.DataA {background:silver;color:black}
 td.DataB {background:lightgrey;color:black}
</style>

<table width="600" border="0" cellSpacing="0" cellPadding="1">
 <!--- Row at top of table, above column headers --->
 <tr>
 <td width="500" colSpan="3">
 <!--- Message about which rows are being displayed --->
 <cfoutput>
 Displaying <b>#URL.startRow#</b> to <b>#endRow#</b>
 of <b>#TotalRows#</b> Records<br>
 </cfoutput>
 </td>
 <td width="100" align="right">
 <cfif not URL.showAll>
 <!--- Provide Next/Back links --->
 <cfinclude template="NextNIncludeBackNext.cfm">
 </cfif>
 </td>
 </tr>

 <!--- Row for column headers --->
 <TR>
 <TH WIDTH="100">Date</TH>
 <TH WIDTH="250">Film</TH>
 <TH WIDTH="150">Expense</TH>
 <TH WIDTH="100">Amount</TH>
 </TR>
 
 <!--- For each query row that should be shown now --->
 <cfloop query="getExp" startRow="#URL.startRow#" endRow="#endRow#">
 <!--- Use class "DataA" or "DataB" for alternate rows --->
 <cfset class = iif(getExp.currentRow mod 2 eq 0, "'DataA'", "'DataB'")>
 
 <!--- Actual data display --->
 <cfoutput>
 <tr valign="baseline">
 <td class="#class#" width="100">#lsDateFormat(ExpenseDate)#</td>
 <td class="#class#" width="250">#MovieTitle#</td>
 <td class="#class#" width="150"><i>#Description#</i></td>
 <td class="#class#" width="100">#lsCurrencyFormat(ExpenseAmount)#</td>
 </tr>
 </cfoutput>

 <!--- If showing all records, flush the page buffer after every 5th row --->
 <cfif URL.showAll>
 <cfif getExp.currentRow mod 5 eq 0>
 <!--- End the current table --->
 </table>
 <!--- Flush the page buffer --->
 <cfflush>
 <!--- Start a new table --->
 <table width="600" border="0" cellSpacing="0" cellPadding="1">
 <!--- Simulate a time-intensive process --->
 <cfset initialTime = now()>
 <cfloop condition="dateDiff('s', initialTime, now()) lt 1"></cfloop>
 </cfif>
 </cfif>

 </cfloop>
 
 <!--- Row at bottom of table, after rows of data --->
 <tr>
 <td width="500" colSpan="3">
 <cfif not URL.showAll and totalRows gt rowsPerPage>
 <!--- Shortcut links for "Pages" of search results --->
 Page <cfinclude template="NextNIncludePageLinks.cfm">
 <!--- Show All Link --->
 <cfoutput>
 <a href="#CGI.script_name#?showAll=Yes">Show All</a>
 </cfoutput>
 </cfif> 
 </td>
 <td width="100" align="right">
 <cfif not URL.showAll>
 <!--- Provide Next/Back links --->
 <cfinclude template="NextNIncludeBackNext.cfm">
 </cfif>
 </td>
 </tr>
</table>


</body>
</html>
