Listing 1. Listing with Column Sorting
<cfquery datasource=#Client.win_dsorc#
name="essentials">
SELECT *
FROM auth a, wintable w
WHERE
w.project = '#Client.userproj#'
AND
w.revision = (SELECT Max(revision)
FROM wintable WHERE filename = w.filename)
<cfif LCase(Client.userproj) neq
'archive'>
AND
w.name = a.name
AND
w.project = a.project
<cfelse>
AND
a.record = (SELECT Max(record) FROM
auth WHERE name = w.name)
</cfif>
<cfif NOT ParameterExists(FORM.sortcol)>
order by a.username,w.subject
<cfelseif FORM.sortcol eq 'Document
Name' >
<cfif "#GetClientVariablesList()#"
CONTAINS "sort_docname">
<cfset Client.sort_docname
= - Client.sort_docname>
<cfelse>
<cfset Client.sort_docname
= 1>
</cfif>
<cfif Client.sort_docname gt 0>
order by w.subject, a.username
<cfelse>
order by w.subject DESC, a.username
</cfif>
<cfelseif FORM.sortcol eq 'Owner'
>
<cfif "#GetClientVariablesList()#"
CONTAINS "sort_owner">
<cfset Client.sort_owner
= - Client.sort_owner>
<cfelse>
<cfset Client.sort_owner
= 1>
</cfif>
<cfif Client.sort_owner gt 0>
order by a.username, w.subject
<cfelse>
order by a.username DESC, w.subject
</cfif>
<cfelseif FORM.sortcol eq 'Date'
>
<cfif "#GetClientVariablesList()#"
CONTAINS "sort_date">
<cfset Client.sort_date =
- Client.sort_date>
<cfelse>
<cfset Client.sort_date =
1>
</cfif>
<cfif Client.sort_date gt 0>
order by w.file_date, w.subject,
a.username
<cfelse>
order by w.file_date DESC, w.subject,
a.username
</cfif>
<cfelseif FORM.sortcol eq 'Status'
>
<cfif "#GetClientVariablesList()#"
CONTAINS "sort_status">
<cfset Client.sort_status
= - Client.sort_status>
<cfelse>
<cfset Client.sort_status
= 1>
</cfif>
<cfif Client.sort_status gt 0>
order by w.status, w.subject,
a.username
<cfelse>
order by w.status DESC, w.subject,
a.username
</cfif>
<cfelse>
order by a.username,w.subject
</cfif>
</cfquery>
.
.
. ... followed by these table heading
buttons that recursively
. call the Cold Fusion template
that generates the current
. page ...
.
.
<form action="wininfo.cfm" method="post">
<tr align="center" valign="middle" bgcolor="#C0C0C0">
<td><input type="submit" name="sortcol"
value="Document Name"></td>
<td><input type="submit" name="sortcol"
value="Owner"></td>
<td><input type="submit" name="sortcol"
value="Date"></td>
<td><nobr>Rev.#</nobr></td>
<td><input type="submit" name="sortcol"
value="Status"></td>
<td>Size</td>
<td>Comments</td>
<td>Revision<br>History</td>
<cfif Client.is_admin eq "Y">
<td>Change<br>File</td>
<td>Delete<br>File</td>
<td>Move<br>File</td>
</cfif>
</tr>
</form>
</PRE>
</TD>
</TR>
</TABLE>
Listing 2. Variable Length Selection
List
<cfquery name="userfiles" datasource="#Client.win_dsorc#">
select w.subject, w.filename
from wintable w, auth a
where
w.revision = (select Max(revision)
from wintable wx
where
w.filename = wx.filename)
AND
w.name = a.name
AND
w.project = a.project
AND
a.username = '#Client.username#'
AND
a.project = '#Client.userproj#'
order by w.subject,w.filename
</cfquery>
<cfif userfiles.recordcount gt 0>
<b>Note:</b> When submitting
a <b>new version</b> of a document,
use the <b>same filename</b>
that you previously used:<br>
<table border=0 cellpadding=0 cellspacing=0><tr><td
align=left valign=center>
<form>
<cfif userfiles.recordcount lte
10>
<select size=<cfoutput>#userfiles.recordcount#</cfoutput>>
<cfelse>
<select size=10>
</cfif>
<cfoutput query="userfiles">
<option>#subject# [#filename#]
</cfoutput>
</select>
</form>
</td></tr></table>
</cfif>
</PRE>
</TD>
</TR>
</TABLE>
Listing 3. Combining ColdFusion with JavaScript
<!--- BROWSE & UPDATE AUTHOR TABLE
--->
<cfif ParameterExists(form.browse)>
<cfif xuser eq ""><cfabort></cfif>
<cfquery name="userinfo" datasource=#Client.win_dsorc#>
SELECT *
FROM auth
WHERE
username = '#Variables.xuser#'
AND
project = '#Variables.xproj#'
</cfquery>
<!--- <cflocation url="winchgusr.cfm?record=#userinfo.record#">
-->
<!--- DISPLAY RECORDS IN FULL WINDOW.
--->
<cfoutput query="userinfo">
<script language="JavaScript">top.location.href='winchgusr.cfm?record=#record#'</script>
</cfoutput>
<cfabort>
</cfif>
</PRE>
</TD>
</TR>
</TABLE>
Listing 4. Cursor Functions Without Cursors
<!--- GET DOCUMENT RECORD DATA --->
<cfif ParameterExists(FORM.oldrec)>
<cfquery name="docinfo" datasource=#Client.win_dsorc#>
SELECT *
FROM wintable
ORDER BY record
</cfquery>
<!--- BEGIN --->
<cfif Find("begin",LCase(FORM.direct))
gt 0>
<cfset nrow = 1>
<!--- PREV --->
<cfelseif Find("prev",LCase(FORM.direct))
gt 0>
<cfset nrow = #ListFind(ValueList(docinfo.record),FORM.oldrec)#>
<cfif nrow gt 1>
<cfset nrow = nrow - 1>
</cfif>
<!--- NEXT --->
<cfelseif Find("next",LCase(FORM.direct))
gt 0>
<cfset nrow = #ListFind(ValueList(docinfo.record),FORM.oldrec)#>
<cfif nrow lt #docinfo.RecordCount#>
<cfset nrow = nrow + 1>
</cfif>
<!--- END --->
<cfelseif Find("end",LCase(FORM.direct))
gt 0>
<cfset nrow = #docinfo.RecordCount#>
<cfelse>
<cfabort> <!--- SHOULD NOT HAPPEN
--->
</cfif>
<cfelse>
<cfif ParameterExists(URL.record)>
<cfset record = #URL.record#>
<cfelse>
<cfset record = #FORM.record#>
</cfif>
<cfquery name="docinfo" datasource=#Client.win_dsorc#>
SELECT *
FROM wintable
WHERE record = #Variables.record#
</cfquery>
<cfset nrow = 1>
</cfif>
<html><head><title>WIN</title></head>
<body bgcolor="#666666">
<cfoutput query="docinfo" startrow=#nrow#
maxrows="1">
<cfset record = #record#> <!--- FOR
NEXT VIEW --->
<h2>Change Document Record Number: #record#</h2>
<form action="winchgdocup.cfm" method="POST">
<input type="hidden" name="record" value="#record#">
<table border=0 cellspacing=0 cellpadding=10><tr
align=left valign=top><td>
<table border="1" cellspacing="0"
cellpadding="5" bgcolor="##cccccc" hspace=0>
<tr>
<td width="20">Project:</td>
<td><input type="Text" name="project"
value="#project#" size="30" maxlength="50"></td>
</tr>
... other rows
<tr>
<td width="20">W10:</td>
<td><input type="Text" name="W10"
value="#W10#" size="30" maxlength="50"></td>
</tr>
</table><br>
<table><tr>
<td><input type="Submit" value="Change"></td>
</form>
</cfoutput>
<form name="auth" action="wininfo.cfm"
method=post>
<td><input type="submit" value="Return
To WIN"></td>
</form>
</tr>
</table>
<!--- NAVIGATION BUTTONS --->
<br>
<form name="auth" action="winchgdoc.cfm"
method=post>
<cfoutput>
<input type="hidden" name="oldrec"
value="#Variables.record#">
</cfoutput>
<table>
<tr>
<td><input type="Submit" name="direct"
value="<<Begin"></td>
<td><input type="Submit" name="direct"
value="<Prev"></td>
<td><input type="Submit" name="direct"
value="Next>"></td>
<td><input type="Submit" name="direct"
value="End>>"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
</PRE>
</TD>
</TR>
</TABLE>