There is an example HMAC-SHA1 here that works in javascript
http://jssha.sourceforge.net/
Text to encrypt
vibaHBXwUXFqVSg-+kTrqYJZEJkbVeqLc=bo.LlXGET12505351831husu9039http://api.tineye.com/rest/search/image_url=http%3a%2f%2ftineye.com%2fimages%2ftineye_logo_big.png&limit=30&offset=10
Key
vibaHBXwUXFqVSg-+kTrqYJZEJkbVeqLc=bo.LlX
Output
9e734661c9e8b6dc9b6b4b3def9769c00e8843b8
Issue
I can't however duplicate the output in Coldfusion. I'm using a function from a previous Stackoverflow.com question
<cffunction name="hmacEncrypt" returntype="binary" access="public" output="false">
<cfargument name="signKey" type="string" required="true" />
<cfargument name="signMessage" type="string" required="true" />
<cfset var jMsg = JavaCast("string",arguments.signMessage).getBytes("iso-8859-1") />
<cfset var jKey = JavaCast("string",arguments.signKey).getBytes("iso-8859-1") />
<cfset var key = createObject("java","javax.crypto.spec.SecretKeySpec") />
<cfset var mac = createObject("java","javax.crypto.Mac") />
<cfset key = key.init(jKey,"HmacSHA1") />
<cfset mac = mac.getInstance(key.getAlgorithm()) />
<cfset mac.init(key) />
<cfset mac.update(jMsg) />
<cfreturn mac.doFinal() />
</cffunction>
<cfset result = hmacEncrypt("vibaHBXwUXFqVSg-+kTrqYJZEJkbVeqLc=bo.LlX", "vibaHBXwUXFqVSg-+kTrqYJZEJkbVeqLc=bo.LlXGET12505351831husu9039http://api.tineye.com/rest/search/image_url=http%3a%2f%2ftineye.com%2fimages%2ftineye_logo_big.png&limit=30&offset=10")>
<cfset x1 = toString(tobase64(result))>
This returns
nnNGYcnottyba0s975dpwA6IQ7g=
Any help appreciated.
<cfset x1 = toString(tobase64(result))>
The other function is returning hex, not base64. Other than that it seems to work fine for me:
<cfset x1 = binaryEncode(result, "hex")>
The clue is in your expected output string: it contains only digits and lowercase letters. If you look closer, all the letters are in the range a-f. Therefore it is extremely likely that it is a hexadecimal string.
The last line of your example code encodes the result as base64, not hexadecimal. You can encode the result as hexadecimal by changing the last line to this:
<cfset x1 = binaryEncode(result,"hex")>
I ran the modified code and got
9E734661C9E8B6DC9B6B4B3DEF9769C00E8843B8
which is the uppercase version of your expected string.
Related
In my dimensional table i have month field with number representation of month 1...12, but in this table i don't have name of that months (Jan, Feb, etc...). In mondrian file i use it like time dimension.
<Dimension type="TimeDimension" visible="true" highCardinality="false" name="timedimension" caption="Datetime">
<Hierarchy visible="true" hasAll="true" primaryKey="id_date">
<Table name="dim_date" schema="dbo">
</Table>
<Level name="year" visible="true" column="year4" type="String" uniqueMembers="false" levelType="TimeYears" hideMemberIf="Never" caption="year">
<Annotations>
<Annotation name="AnalyzerDateFormat">
<![CDATA[[yyyy]]]>
</Annotation>
</Annotations>
</Level>
<Level name="month" visible="true" column="month" ordinalColumn="month" type="String" uniqueMembers="false" levelType="TimeMonths" hideMemberIf="Never" caption="month">
<Annotations>
<Annotation name="AnalyzerDateFormat">
<![CDATA[[yyyy].['Q'q].[M]]]>
</Annotation>
</Annotations>
</Level>
</Hierarchy>
</Dimension>
When i show this dimension in Pentaho User Console i would like to show the Name of these months instead of numbers in Anylyzer report. Is this possible without adding this names of months into my dimension table. Exists some internal function for showing of that or some property file or internal dictionary for using of that or some attribute in mondrian file? And i would like to have the names of the month depends on selected language in Pentaho User Console.
If creating a column in the dim table is not an option (although this is the recommended approach), you can do it by adding a KeyExpression element to the Level expression:
<Level name="month" visible="true" ordinalColumn="month" type="String" uniqueMembers="false" levelType="TimeMonths" hideMemberIf="Never">
<KeyExpression>
<SQL dialect="generic">
CASE
WHEN month = 1 THEN 'Jan'
WHEN month = 2 THEN 'Feb'
(...)
WHEN month = 12 THEN 'Dec'
END
</SQL>
</KeyExpression>
<Annotations>
<Annotation name="AnalyzerDateFormat">
<![CDATA[[yyyy].['Q'q].[MMM]]]>
</Annotation>
</Annotations>
</Level>
Notice that I removed the column and caption attributes. Also notice the change in the value of AnalyzerDateFormat (if you want full month names you must use MMMM instead of MMM).
I am trying to create a form with 3 select boxes that are bound to a cfc (triple related cfselect). If I remove the Application.cfc, the code runs just fine, the select box gives me the data I need. However, when I add Application.cfc which has cflogin function which requires users to login before they are able to use any page than my triple related select boxes do not work anymore. The select box just doesn't give out any data from the query in the function. It still connects to the function page, because when I change the name on the bind of the cfselect, it will let me know that that function does not exist in the component. I am not sure what I have to do to make the triple related cfselect work with cflogin in place.
I am using ColdFusion 10
I really appreciate any suggestions.
Thanks, Niva
I added the code:
This is code on form
<tr valign="top">
<td style="color:DarkSeaGreen; font-weight:bold; width=100">Product Type:</td>
<td width="200">
<cfselect name="Selproducttype" bind="cfc:groupfnc.getproducttypeid()"
display="description" value="producttypeid" BindOnLoad="true"/></td></tr>
<tr valign="top">
<td style="color:DarkSeaGreen; font-weight:bold; width=100">Vendor:</td>
<td width="200">
<cfselect name="Selvendor" bind="cfc:groupfnc.getven({Selproducttype})"
display="fullname" value="vendorid" BindOnLoad="true"/></td></tr>
<tr valign="top">
<td style="color:DarkSeaGreen; font-weight:bold; width=100">Product:</td>
<td width="200">
<cfselect name="Selprod" bind="cfc:groupfnc.getprod({Selvendor})"
display="fullname" value="productid" BindOnLoad="true" /></td></tr>
<tr valign="top">
<td style="color:DarkSeaGreen; font-weight:bold; width=100">Sub Product:</td>
<td width="200">
<cfselect name="Selsubprod" bind="cfc:groupfnc.Getsub({Selprod})"
display="fullname" value="productsubid" /></td></tr>
Code on component: groupfnc.cfc
<cffunction name="getproducttypeid" access="remote" output="false" returntype="query">
<cfquery name="listproducttype" datasource="xxxxxx">
Select distinct producttypeid, (Case when producttypeid = '101' then 'Hotel'
when producttypeid='201' then 'optionalTour'
when producttypeid = '301' then 'Transporation'
when producttypeid = '501' then 'MISC'
when producttypeid = '601' then 'OTH' end) as description
From products
</cfquery>
<cfreturn listproducttype />
</cffunction>
<cffunction name="getven" access="remote" output="false" returntype="Query">
<cfargument name="Selproducttype" type="any" required="true">
<cfif ARGUMENTS.Selproducttype EQ "">
<cfset ARGUMENTS.Selproducttype = '0'>
</cfif>
<cfquery name="listven" datasource="xxxxxx">
SELECT distinct vendors.fullname, vendors.vendorid
from vendors, products
where products.vendorid= vendors.vendorid
and products.producttypeid = #ARGUMENTS.Selproducttype#
ORDER BY fullname
</cfquery>
<cfreturn listven />
</cffunction>
<cffunction name="getprod" access="remote" output="false" returntype="Query">
<cfargument name="Selvendor" type="any" required="true">
<cfif ARGUMENTS.Selvendor EQ "">
<cfset ARGUMENTS.Selvendor = '0'>
</cfif>
<cfquery name="Lstprod" datasource="xxxxxx">
Select productid, fullname from products
where vendorid = #ARGUMENTS.Selvendor#
order by fullname
</cfquery>
<!---</cfif>--->
<cfreturn Lstprod />
</cffunction>
<cffunction name="Getsub" access="remote" output="false" returntype="Query">
<cfargument name="Selprod" type="any" required="true">
<cfif ARGUMENTS.Selprod EQ "">
<cfset ARGUMENTS.Selprod = '0'>
</cfif>
<cfquery name="Lstsubprod" datasource="xxxxxx">
Select productsubid, fullname from productsubs
where productid = #ARGUMENTS.Selprod#
order by fullname
</cfquery>
<!---</cfif>--->
<cfreturn Lstsubprod />
</cffunction>
Here is my application.cfc
<cfcomponent>
<cfset This.name = "Orders">
<cfset This.Sessionmanagement="True">
<cfset This.loginstorage="session">
<cffunction name="OnRequestStart">
<cfargument name = "request" required="true"/>
<cfif IsDefined("Form.logout")>
<cflogout>
</cfif>
<cflogin>
<cfif NOT IsDefined("cflogin")>
<cfinclude template="loginform.cfm">
<cfabort>
<cfelse>
<cfif cflogin.name IS "" OR cflogin.password IS "">
<cfoutput>
<h2>You must enter text in both the User Name and Password fields.
</h2>
</cfoutput>
<cfinclude template="loginform.cfm">
<cfabort>
<cfelse>
<cfquery name="loginQuery" dataSource="xxxxxx">
SELECT userid, roles
FROM logininfo
WHERE
userid = '#cflogin.name#'
AND upassword = '#cflogin.password#'
</cfquery>
<cfif loginQuery.roles NEQ "">
<cfloginuser name="#cflogin.name#" Password = "#cflogin.password#"
roles="#loginQuery.roles#">
<cfelse>
<cfoutput>
<H2>Your login information is not valid.<br>
Please Try again</H2>
</cfoutput>
<cfinclude template="loginform.cfm">
<cfabort>
</cfif>
</cfif>
</cfif>
</cflogin>
<cfif GetAuthUser() NEQ "">
<cfoutput>
<form action="securitytest.cfm" method="Post">
<input type="submit" Name="Logout" value="Logout">
</form>
</cfoutput>
</cfif>
</cffunction>
</cfcomponent>
I found the problem. Because in my Application.cfc has this part:
<form action="securitytest.cfm" method="Post">
<input type="submit" Name="Logout" value="Logout">
</form>
</cfoutput>
So looking at the ajax response the logout form is placed infornt so the select box didnt parse the value.I removed this partin the Application.cfc and the page run just fine.
Thank you so much for all your help!
^_^
I have a .cfm and .cfc that I am using to edit data in a cfgrid on the .cfm, and it works, however 10% of the time I will get the following error message:
"Error invoking CFC /test/editCFgrid.cfc: Internal Server Error"
I tried using the debugging advice, however no luck.
Here is the CFM code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<cfform name="artistform">
<cfgrid format="html" name="artistgrid" pagesize=11
striperows="yes"
bind="cfc:editCFgrid.getArtists({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
delete="yes" insert="yes" selectmode="edit"
onchange="cfc:editCFgrid.saveArtist({cfgridaction},{cfgridrow},{cfgridchanged})">
<cfgridcolumn name="firstname" header="First Name" />
<cfgridcolumn name="lastname" header="Last Name" />
<cfgridcolumn name="address" header="Address" />
<cfgridcolumn name="city" header="City" />
<cfgridcolumn name="state" header="State" />
<cfgridcolumn name="postalcode" header="Postal Code" />
<cfgridcolumn name="email" header="Email" />
<cfgridcolumn name="phone" header="Phone" />
<cfgridcolumn name="fax" header="Fax" />
<cfgridcolumn name="thepassword" header="Password" />
</cfgrid>
</cfform>
</body>
</html>
Here is the CFC code:
<cfcomponent output="FALSE">
<cffunction name="getArtists" hint="I extract artists from the database" access="remote" output="FALSE" returntype="struct">
<cfargument name="page" required="TRUE" hint="the page the grid is on" />
<cfargument name="pagesize" required="TRUE" hint="records displayed per page" />
<cfargument name="gridsortcolumn" required="TRUE" hint="selected column to sort" />
<cfargument name="gridsortdirection" required="TRUE" hint="the sort direction" />
<cfset var qArtists = "" />
<cfif arguments.gridsortcolumn eq "">
<cfset arguments.gridsortcolumn = "lastname" />
<cfset arguments.gridsortdirection = "asc" />
</cfif>
<cfquery name="qArtists" datasource="test_database">
SELECT *
FROM Artists
ORDER BY #arguments.gridsortcolumn# #arguments.gridsortdirection#
</cfquery>
<cfreturn QueryConvertForGrid( qArtists, arguments.page, arguments.pagesize ) />
</cffunction>
<cffunction name="saveArtist" type="any" hint="I insert, update or delete an artist" access="remote" output="FALSE" returntype="void">
<cfargument name="gridaction" type="any" required="TRUE" hint="I for insert, U for update and D for delete" />
<cfargument name="gridrow" type="any" required="TRUE" hint="the rows being inserted or updated" />
<cfargument name="gridchanged" type="any" hint="the changes" />
<cfset var qInsertArtist = "" />
<cfset var qUpdateArtist = "" />
<cfset var qDeleteArtist = "" />
<cfif IsStruct( arguments.gridrow ) and IsStruct( arguments.gridchanged )>
<cfif arguments.gridaction eq "I">
<cfquery name="qInsertArtist" datasource="test_database">
INSERT INTO Artists
(firstname, lastname, address, city, state, postalcode, email, phone, fax, thepassword)
VALUES
(<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.firstname#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.lastname#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.address#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.city#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.state#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.postalcode#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.email#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.phone#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.fax#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.thepassword#" />)
</cfquery>
<cfelseif arguments.gridaction eq "U">
<cfset var colname = StructKeyList( arguments.gridchanged ) />
<cfset var value = StructFind( arguments.gridchanged, colname ) />
<cfquery name="qUpdateArtist" datasource="test_database">
UPDATE Artists
SET #colname# = <cfqueryparam value="#value#" />
WHERE artistid = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.gridrow.artistid#" />
</cfquery>
<cfelseif arguments.gridaction eq "D">
<cfquery name="qDeleteArtist" datasource="test_database">
DELETE FROM Artists
WHERE artistid = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.gridrow.artistid#" />
</cfquery>
</cfif>
</cfif>
</cffunction>
</cfcomponent>
Each function (edit, insert, delete, etc) works, but it randomly will generate the error. Ultimately, I am seeking a code that will ignore/block/"OK" the error message so the user won't see it.
Any help will be greatly appreciated! I have spent the entire day (9 hours) googling for an answer, but I haven't found any. I do not have access to the CF Admin Log, I'm just a regular developer. Thanks!
Google chrome, firebug in firefox, IE developer tools can all help you with this.
In google chrome (my preference), right click on your page > inspect element. Then go to the network tab. You'll have to refresh your web page. Then you will see your cfc in the list of files (probably RED). Right click > open in new tab, and you'll open the cfc directly with all the arguments being called. You should then be able to see your error.
There is no ignore/block/ok. You need to fix the error.
Perhaps a time out or a SQL error. To get the full error use: cferror, this tag show a full debug information (better than debug server info) I sent it to me by mail:
Put this on you Application file:
<cferror type="exception" template="error.cfm" />
<cferror type="request" template="error.cfm" />
Create a "error.cfm" file with:
"Error message"
<cfsavecontent variable="errorContent">
<cfoutput>
An error occurred: http://#cgi.server_name##cgi.script_name#?#cgi.query_string#<br />
Time: #dateFormat(now(), "short")# #timeFormat(now(), "short")#<br />
<h2>Error:</h2>
<cfdump var="#error#" label="Error">
<h2>Form:</h2>
<cfdump var="#form#" label="Form">
<h2>URL:</h2>
<cfdump var="#url#" label="URL">
<h2>SESSION:</h2>
<cfdump var="#SESSION#" label="SESSION">
</cfoutput>
</cfsavecontent>
<cfmail to="mail#mymail.com" from="mail#mymail.com" subject="Error on #cgi.server_name#: #error.message#" type="html">
#errorContent#
</cfmail>
There is a way to ignore/block/ok the "error" message with the following script:
<script>ColdFusion.setGlobalErrorHandler(function (error)
{mygrid = ColdFusion.Grid.refresh ('artistgrid', false);
}
);
</script>
Insert this script in the CFM files, and you're good to go! Being that the error that I was encountering was not impacting the function (editing the cells) of the cfgrid (the pop-up message was being more of a nuisance then anything else). Hopefully this solution will help others!
You do not need to use the 'Grid.refresh' command in the script, you can use anything command you want.
Thanks everyone who attempted to answer my issue!
I've noticed some strange browser specific weirdness with Google
Chrome with some data bound buttons, in that when you navigate away
from the page then use the browsers back button the data bind displays
different data. If you then hit refresh it resets to the correct data.
It doesn't happen in Firefox or Explorer 7.
I had actually entered the data bound bool button example to CF
Cookbook http://cookbooks.adobe.com/post_Using_cfinput_buttons_and_data_binding_to_toggle_d-16390.html so the files I'm using are there, direct link is http://cookbooks.adobe.com/index.cfm?event=getFile&fileId=6902
but now I have spotted this cross browser quirk I feel I should take
it down unless of course you can help me figure out what is going
on!
Any clues appreciated.
bool_buttons.cfm
<cfset url.messageID=28>
<CFSET application.dsn = "data">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<cfform>
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle1#click},'referral', 'Referral', 'Message')" name="toggle1" value="" bindonload="YES">
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle2#click},'viewed', 'Read', 'Unread')" name="toggle2" value="" bindonload="YES">
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle3#click},'actioned', 'Actioned', 'Pending')" name="toggle3" value="" bindonload="YES">
</cfform>
</body>
</html>
messageProcess.cfc
<cfcomponent>
<cffunction access="remote" name="togglebool" output="true" returntype="any" displayname="Toggle boolean value in message record" hint="Toggles boolean value in message record">
<cfargument required="true" name="dsn" type="string"/>
<cfargument required="true" name="messageID" type="numeric"/>
<cfargument required="true" name="buttonLabel" type="string"/>
<cfargument required="true" name="switchName" type="string"/>
<cfargument required="true" name="switchOnLabel" type="string"/>
<cfargument required="true" name="switchOffLabel" type="string"/>
<cfset var returnMessage = "" />
<cfset var temp = "" />
<cfquery datasource='#arguments.dsn#' name="getSwitchData">
SELECT #arguments.switchName#
FROM messages
WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/>
</cfquery>
<cfset temp="getswitchdata."&#switchName#>
<cfif #Evaluate(temp)# is 1>
<cfset returnMessage="#arguments.switchOnLabel#">
<cfelse>
<cfset returnMessage="#arguments.switchOffLabel#">
</cfif>
<cfif buttonLabel eq "">
<cfreturn returnMessage>
<cfelseif buttonLabel eq "#arguments.switchOffLabel#">
<cfquery datasource='#arguments.dsn#'>
UPDATE messages
SET #arguments.switchName#=1
WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/>
</cfquery>
<cfreturn "#arguments.switchOnLabel#">
<cfelseif buttonLabel eq "#arguments.switchOnLabel#">
<cfquery datasource='#arguments.dsn#'>
UPDATE messages
SET #arguments.switchName#=0
WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/>
</cfquery>
<cfreturn "#arguments.switchOffLabel#">
</cfif>
</cffunction>
</cfcomponent>
This is a Google Chrome bug, I had a similar case and opened a ticket here
I would like to able to bind a series of 3 buttons to toggle 3 boolean values on a database message entry. The boolean database entries are read|unread, actioned|pending, referral|message and the message entry has the unique key "messageID". I want the buttons to display the record starting values (which I presume is bindonload="true").
I've limped towards
<cfform>
<cfinput type="hidden" name="switchName" value="read">
<cfinput type="button" bind="cfc:cfcs.messages.toggle({toggle#click},{switchName#none})" name="toggleRead" value="Read" bindonload="true">
</cfform>
and in the cfc
<cffunction access="remote" name="toggle" output="false" returntype="any" >
<cfargument required="true" name="toggle" type="any"/>
<cfargument required="true" name="switchName" type="any"/>
<cfif toggle eq "Read">
<cfreturn "Unread">
<cfelseif toggle eq "Unread">
<cfreturn "Read">
</cfif>
</cffunction>
This gets me some of the way there, in so far as it toggles the button label, but I'm foxed on how to pick up the initial db values to display the initial status.
Also is there a way to pass other variables in the bind statement without using hidden fields and control#none format, e.g. I will need to pass in the messageID so I can update the correct record. I wouldn't have put in the switchName input if I knew how to simply pass the switchName variable in a beter way.
Many thanks for any light you can shed?
How about...
<cfinput type="button" bind="cfc:cfcs.messages.toggle({toggle#click}, #switchName#)" value="#initialValue#" bindonload="false">
or alternatively:
<cfajaxproxy bind="javascript:yourJSFunc({toggle#click})">
and in your yourJSFunc, use whatever JS var's you need.
That helped Henry.
I got it working, though it feels a bit kludgy...
<cfform>
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle1#click},'referral', 'Referral', 'Message')" name="toggle1" value="" bindonload="YES">
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle2#click},'viewed', 'Read', 'Unread')" name="toggle2" value="" bindonload="YES">
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle3#click},'actioned', 'Actioned', 'Pending')" name="toggle3" value="" bindonload="YES">
</cfform>
and the cfc
<cfcomponent>
<cffunction access="remote" name="togglebool" output="true" returntype="any" displayname="Toggle boolean value in message record" hint="Toggles boolean value in message record">
<cfargument required="true" name="dsn" type="string"/>
<cfargument required="true" name="messageID" type="numeric"/>
<cfargument required="true" name="buttonLabel" type="string"/>
<cfargument required="true" name="switchName" type="string"/>
<cfargument required="true" name="switchOnLabel" type="string"/>
<cfargument required="true" name="switchOffLabel" type="string"/>
<cfset var returnMessage = "" />
<cfset var temp = "" />
<cfquery datasource='#arguments.dsn#' name="getSwitchData">
SELECT #arguments.switchName#
FROM messages
WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/>
</cfquery>
<cfset temp="getswitchdata."&#switchName#>
<cfif #Evaluate(temp)# is 1>
<cfset returnMessage="#arguments.switchOnLabel#">
<cfelse>
<cfset returnMessage="#arguments.switchOffLabel#">
</cfif>
<cfif buttonLabel eq "">
<cfreturn returnMessage>
<cfelseif buttonLabel eq "#arguments.switchOffLabel#">
<cfquery datasource='#arguments.dsn#'>
UPDATE messages
SET #arguments.switchName#=1
WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/>
</cfquery>
<cfreturn "#arguments.switchOnLabel#">
<cfelseif buttonLabel eq "#arguments.switchOnLabel#">
<cfquery datasource='#arguments.dsn#'>
UPDATE messages
SET #arguments.switchName#=0
WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/>
</cfquery>
<cfreturn "#arguments.switchOffLabel#">
</cfif>
</cffunction>
If there's a slicker way please let me know.