CFRETURN to .CFM page - coldfusion

Trying to display structExcelResult["strUrl"] created by the function on my .cfm page.
<cffunction name="getBuyerReport" output="false" access="public" returntype="struct">
<cfargument name="intRegionId" required="yes">
<cfargument name="intBuyerId" required="yes">
<cfargument name="intStage" required="yes">
<cfargument name="strSortField" required="yes">
<cfargument name="strSortDirection" required="yes">
<cfset var structExcelResult = StructNew()>
<cfset var qRead="" />
<cfquery name="qRead" datasource="#variables.dsn#">
SELECT CONVERT(varchar,t.RECEIVED_DATE,101) AS [Received Date]
, t.REQUISITION_NO AS [Requisition Number]
, t.REQUISITION_TITLE AS [Requisition Title]
, t.TECHNICAL_AUTHORITY_NAME AS [Technical Authority]
, bm.BID_START_DATE AS [Solicitation Date]
, bm.BID_END_DATE AS [Closing Date]
, CAST(t.REQ_AMOUNT AS MONEY) AS [Requisition Value]
, CAST(t.APPROVAL_AMOUNT AS MONEY) AS [Approval Value]
, t.CURRENT_STAGE AS [Current Stage]
, CONVERT(varchar,t.ESTIMATED_AWARD_DATE,101) AS [Estimated Award Date]
, replace(replace(n.NOTE,CHAR(13),''),CHAR(10),'') as [Comments]
, DATEDIFF(day, t.RECEIVED_DATE, getdate()) AS [Age of Requisition (days)]
, cb.USER_NAME as [Buyer Name]
, o.OFFICE_LOCATION_NAME as [Office Location]
FROM VW__TOMBSTONES__CLIENT_CODES t
LEFT OUTER JOIN TB__OFFICE_LOCATIONS o
ON o.ID = t.OFFICE__ID
LEFT OUTER JOIN TB__USERS cb
ON t.CURRENT_BUYER__ID = cb.ID
LEFT OUTER JOIN TB__BID_MANAGEMENTS bm
ON bm.TB__TOMBSTONES__ID = t.ID
LEFT OUTER JOIN TB__REQUISITIONS r
ON r.TOMBSTONES__ID = t.ID
LEFT OUTER JOIN TB__NOTES n
ON n.REQUISITION__ID = r.ID
AND t.CURRENT_STAGE = n.NOTE_TYPE
WHERE t.CURRENT_STAGE <= 4
AND n.NOTE_TYPE BETWEEN 1 AND 4
AND t.REGION__ID = #arguments.intRegionId#
</cfquery>
<!--- Create new spreadsheet --->
<cfset sObj = SpreadsheetNew()>
<!--- Excel Functions --->
<cfset countFormula="COUNTA(A8:A20000)">
<cfset sumFormula="SUM(G2:G2000)">
<!--- Create header row --->
<cfset SpreadsheetMergeCells(sObj,1,1,1,2)>
<cfset SpreadsheetSetCellValue(sObj, "BUYER REGISTER REPORT",1,1)>
<cfset SpreadsheetFormatRow(sObj, {bold=TRUE, alignment="center"}, 1)>
<cfset SpreadsheetSetCellValue(sObj, "Report Generated Date:",3,1)>
<cfset SpreadsheetFormatCell(sObj, {bold=TRUE, alignment="right"}, 3,1)>
<cfset SpreadsheetSetCellValue(sObj, "#ToString(DateFormat(now(), "mmmm d yyyy"))#",3,2 )>
<cfset SpreadsheetFormatCell(sObj, {bold=TRUE, alignment="left"}, 3,2)>
<cfset SpreadsheetSetCellValue(sObj, "Number of Requisitions:",4,1)>
<cfset SpreadsheetFormatCell(sObj, {bold=TRUE, alignment="right"}, 4,1)>
<cfset SpreadsheetSetCellFormula(sObj,countFormula, 4, 2)>
<cfset SpreadsheetFormatCell(sObj, {bold=TRUE, alignment="left"}, 4,2)>
<cfset SpreadsheetSetCellValue(sObj, "Value of Requisitions:",5,1 )>
<cfset SpreadsheetFormatCell(sObj, {bold=TRUE, alignment="right"}, 5,1)>
<cfset SpreadsheetSetCellFormula(sObj,sumFormula, 5, 2)>
<cfset SpreadsheetFormatCell(sObj, {bold=TRUE, alignment="left"}, 5,2)>
<cfset SpreadsheetFormatCell(sObj, {dataformat="$##,##0.00"}, 5,2)>
<cfset SpreadsheetAddRow(sObj, "" )>
<cfset SpreadsheetAddRow(sObj, "RECEIVED DATE,REQUISITION NUMBER,REQUISITION TITLE,TECHNICAL AUTHORITY,SOLICITATION DATE,CLOSING DATE,REQUISITION VALUE,APPROVAL VALUE,CURRENT STAGE,ESTIMATED AWARD DATE,COMMENTS,AGE OF REQUISITION (DAYS),BUYER NAME,OFFICE LOCATION")>
<cfset SpreadsheetFormatRow(sObj, {bold=TRUE}, 7)>
<!--- Add orders from query --->
<cfset SpreadsheetAddRows(sObj, qRead)>
<cfset SpreadsheetFormatColumns(sObj, {dataformat="$##,##0.00"}, "7-8")>
<cfset SpreadsheetFormatColumns(sObj, {alignment="center"}, "9-10")>
<cfset SpreadsheetFormatColumns(sObj, {alignment="center"}, "12-15")>
<!--- Excel document naming and storing location --->
<cfset strDir=GetDirectoryFromPath(GetCurrentTemplatePath())&"/../assets/generatedXLS/">
<cfset strFilePrepend = "-BuyerReport-" />
<cfset strFileNameStamp = "Galileo" & "#strFilePrepend#" & "#ToString(DateFormat(now(), "yy-mm-dd"))#" & "-#ToString(TimeFormat(now(), "HHmmss"))#" & ".xls"/>
<cfspreadsheet action="write"
filename="#strDir##strFileNameStamp#"
name="sObj"
overwrite="true"
sheetname="Active (Stages 1-4)">
<cfset structExcelResult["strURL"] = "/web_apps/app/assets/generatedXLS/" & #strFileNameStamp# />
<cfset structExcelResult["strNoRecordsFoundMsg"] = "" />
<cfreturn structExcelResult>
How do I fetch that data (structExcelResult["strURL"]) and display it on my .cfm page?
I'm new at this and going through Ben Forta books... Thanks!

Since you have a cfreturn in your code, I'll assume that was meant to have been wrapped in cffunction.
You can call a cffunction a couple of different ways. It could be on the same .cfm page that you're on:
<cffunction name="sayHello" output="false">
<cfargument name="username" type="string" required="false" default="Anonymous" />
<cfreturn "Hello, " & username />
</cffunction>
<cfoutput>#sayHello( 'Charlie' )#</cfoutput>
However, it's more likely that your function is part of a ColdFusion Component (CFC). To call a function that's part of a CFC, you first have to instantiate the CFC:
<cfset myCFC = createObject( 'component', 'path.to.my.cfc' ) />
Now you can call any method that resides in the CFC via:
<cfoutput>#myCFC.myFunction( 'foo' )#</cfoutput>
Going back to my first (very simple) example, let's say the sayHello() function resided in the Greeting.cfc file that was at /com/Greeting.cfc.
<cfset greeting = createObject( 'component', 'com.greeting' ) />
<cfoutput>#greeting.sayHello( 'Charlie' )#</cfoutput>
You can use anything you'd like for the name. It doesn't have to be myCFC or greeting. It's just a variable that represents a hook into your component.
Hope that helps.

Related

Why is coldfusion outputting these values as floating point decimals?

I'm experiencing difficulties with a jwt token, turns out it's because coldfusion is converting an int to a float. I'm not sure where the problem is or how to fix it.
Token timestamp and expiration:
<cfset TimeStamp = '#VAL( int( getTickCount() / 1000 ) )#' >
<cfset Exp = '#VAL( int( (getTickCount() / 1000)+43200 ) )#' >
<cfscript>
Variables.payload = StructNew();
Variables.payload[ "nbf" ] = "#TimeStamp#";
Variables.payload[ "exp" ] = "#Exp#";
Variables.result = JWT.encode( payload, Variables.secretKey);
</cfscript>
The JWT.Encode call looks like this:
<cffunction name="encode" access="public" returntype="String">
<!--- ****************** Arguments ************************ --->
<cfargument name="payload" type="any" required="true">
<cfargument name="key" type="string" required="true">
<cfargument name="algo" type="string" required="false" default="HS256">
<!--- ****************** /Arguments *********************** --->
<!--- define our variables here --->
<cfset var currentTime = getCurrentUtcTime()>
<cfset var header = createObject("java", "java.util.LinkedHashMap").init() /> <!--- StructNew doesnt work because coldfusion 8 orders the keys --->
<cfset var claims = createObject("java", "java.util.LinkedHashMap").init() /> <!--- StructNew doesnt work because coldfusion 8 orders the keys --->
<cfset var segments = ArrayNew(1)>
<!---
creation of first segment of our JWT: the header
--->
<cfset header[ "typ" ] = "JWT">
<cfset header[ "alg" ] = "HS256">
<!--- add header an json with base64 encoding to segment array --->
<cfset arrayAppend( segments, replace( toBase64( serializeJSON( header ) ), "=", "", "all" ) )>
<!---
creation of the middle segment: the claims set
--->
<cfset claims = Arguments.payload>
<!---
escape forward slashes in generated JSON
--->
<cfset claimsJson = replace( serializeJSON( claims ), "/", "\/", "all" )>
<!--- add header and json with base64 encoding (with padding REMOVED!) to segment array --->
<cfset arrayAppend( segments, replace( toBase64( claimsJson ), "=", "", "all" ) )>
<!---
create the last segment: the signature
--->
<cfset signingInput = ArrayToList( segments, "." )>
<cfset signature = sign( signingInput, Arguments.key, Arguments.algo )>
<!---
add signature as last the element to our string
--->
<cfreturn ListAppend( signingInput, signature, ".")>
</cffunction>
Run through a base64 decoder, I get something like exp":1.498696809E9,"nbf":1.498653609E9
Get Nathan Mische's JSONUtil.cfc. Then replace the line
<cfset claimsJson = replace( serializeJSON( claims ), "/", "\/", "all" )>
with
<cfset jsonTool = createobject("component","jsonutil")>
<cfset claimsJson = replace(jsonTool.serializeJSON(claims,false,true), "/", "\/", "all" )>

Adding Colored Events to the Calendar

I have the following working Calendar page (lqCalendar.cfm) that places events from MySQL to the calendar.
<html>
<head>
<link rel="stylesheet" href="../fullcalendar-3.1.0/fullcalendar.min.css" />
<script src="../fullcalendar-3.1.0/lib/jquery.min.js"></script>
<script src="../fullcalendar-3.1.0/lib/moment.min.js"></script>
<script src="../fullcalendar-3.1.0/fullcalendar.min.js"></script>
<script>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var title = prompt('Event Title:');
if (title) {
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
}
calendar.fullCalendar('unselect');
},
editable: true,
events: "getLeaveRequests.cfc?method=getMyData",
eventDrop: function(event, delta) {
alert(event.title + ' was moved ' + delta + ' days\n' +
'(should probably update your database)');
}
});
});
</script>
</head>
<body>
<div id='calendar'>
</div>
</body>
</html>
Here is my working CFC (getLeaveRequests.cfc) which queries the data:
<!--- Don't forget to VAR scope all local variables. --->
<cfset var getEvents = "">
<cfset var row = "">
<cfset var result = "">
<cfquery name="getEvents" datasource="care">
SELECT lqID AS id,
lqStartDate AS myStart,
lqEndDate AS myEnd,
CONCAT(lqUser, " (",lqTotalHours,") ", (COALESCE(lqDescription,'')),"") AS title
FROM tblleaverequest
</cfquery>
<cfset result = []>
<cfloop query="getEvents">
<!--- start new structure. must use array notation to preserve case of structure keys--->
<cfset row = {}>
<cfset eventurl ="leave_request_a01z.cfm?id=" & "id">
<cfset row["id"] = id>
<cfset row["title"] = title>
<cfset row["start"] = myStart>
<cfset row["end"] = myEnd>
<!--- append to results --->
<cfset arrayAppend(result, row)>
</cfloop>
<!--- convert to json --->
<cfreturn serializeJSON(result)>
<!---
<cfreturn getEvents>
--->
</cffunction>
</cfcomponent>
What is the best way to "color" the calendar items based on the value of "lqUser"?
- The colors can be dynamically assigned, or if needed, I can add a color field to the User table for each user, but how do I assign it to the FullCalendar?
Here is my updated CFC trying to get colors to work: (using code from "dwayne anderson" post on Raymond Camden site)
- I added a field to my User table called "category_id", then assigned values 1 thru 9 for colors.
The page gives me no errors, just a blank calendar?
<!--- Component to get all of the Leave Request Dates and place on FullCalendar page--->
<cfcomponent>
<cfsetting showDebugOutput='No'>
<cffunction name="getMyData" output="false" access="remote" returntype="any" returnformat="JSON">
<cfargument name="filter" type="string" required="no" default="">
<cfquery name="getallevents" datasource="care">
SELECT lqID AS id,
lqStartDate AS event_start_datetime,
lqEndDate AS event_end_datetime,
IF(category_id IS NULL, '1', category_id) AS color_id,
CONCAT(lqUser, " (",lqTotalHours,") ", (COALESCE(lqDescription,'')),"") AS title
FROM tblusers RIGHT OUTER JOIN tblleaverequest ON tblusers.username = tblleaverequest.lqUser
</cfquery>
<cfquery name="getallcolors" dbtype="query">
Select distinct color_id
from getallevents
</cfquery>
<cfset colorlist="red,green,blue,yellow,black,brown,aqua,orange,darkred">
<cfset colorpos=1>
<cfset colors = []>
<cfloop query = "getallcolors">
<cfset thecolor='#listgetat(colorlist,colorpos)#'>
<cfif colorpos eq listlen(colorlist)>
<cfset colorpos=0>
</cfif>
<cfset colorpos=colorpos+1>
<cfset colors[#color_id#] = thecolor>
</cfloop>
<cfset url.returnformat="json">
<cfset results = []>
<cfloop query = "getallevents">
<cfset eventurl ="eventdetails.cfm?id=" & "id">
<cfset eventcolor ="#colors[color_id]#">
<cfset s = structnew()>
<cfset s["id"] = id>
<cfset s["title"] = title>
<cfset s["start"] = getEpochTime(event_start_datetime)>
<cfset s["end"] = getEpochTime(event_end_datetime)>
<cfset s["url"] = eventurl>
<cfset s["color"] = eventcolor>
<cfset s["allDay"] = false>
<cfset arrayappend(results, s)>
</cfloop>
<cfreturn results>
</cffunction>
<cffunction access="private" name="getEpochTime" returntype="date">
<cfargument name="thedatetime" type="date"/>
<cfif (ArrayLen(Arguments) is 0)>
<cfset thedatetime = Now() />
<cfelseif IsDate(Arguments[1])>
<cfset thedatetime=Arguments[1] />
<cfelse>
return NULL;
</cfif>
<cfreturn DateDiff("s", DateConvert("utc2Local", "January 1 1970 00:00"), thedatetime) />
</cffunction>
</cfcomponent>
What is the best way to "color" the calendar items based on the value of "lqUser"?
You have two options if I am understanding this correctly.
You could set the color for the user in the query itself so its easier to manage at query level via case statments or any other logic
You could do div with classes for specific user or type of user.
HTH.
Got it working! Here is the final & working CFC that includes coloring the calendar events. Thanks for the help.
<!--- Component to get all of the Leave Request Dates and place on FullCalendar page--->
<cfcomponent>
<cfsetting showDebugOutput='No'>
<cffunction name="getMyData" output="false" access="remote" returntype="any" returnformat="JSON">
<cfargument name="filter" type="string" required="no" default="">
<!--- Don't forget to VAR scope all local variables. --->
<cfset var getEvents = "">
<cfset var row = "">
<cfset var result = "">
<cfset var getallcolors = "">
<!--- Query the Leave Requests table and get data for all employees --->
<cfquery name="getEvents" datasource="care">
SELECT lqID AS id,
lqStartDate AS myStart,
lqEndDate AS myEnd,
IF(category_id IS NULL, "", category_id) AS color_id,
CONCAT(lqUser, " (",lqTotalHours,") ", (COALESCE(lqDescription,'')),"") AS title
FROM tblusers RIGHT OUTER JOIN tblleaverequest ON tblusers.username = tblleaverequest.lqUser
</cfquery>
<!--- Do a Query of Queries to get all of the users color values --->
<cfquery name="getallcolors" dbtype="query">
Select distinct color_id
FROM getEvents
</cfquery>
<cfset result = []>
<!--- Assign colors to be used by the FullCalendar variable --->
<cfset colorlist="red,green,blue,black,gray,brown,orange,darkred,darkgreen,darkblue,darkgrey,purple,darkorange,">
<cfset colorpos=1>
<cfset colors = []>
<cfloop query = "getallcolors">
<cfset thecolor='#listgetat(colorlist,colorpos)#'>
<cfif colorpos eq listlen(colorlist)>
<cfset colorpos=0>
</cfif>
<cfset colorpos=colorpos+1>
<cfset colors[#color_id#] = thecolor>
</cfloop>
<cfloop query="getEvents">
<!--- start new structure. must use array notation to preserve case of structure keys--->
<cfset row = {}>
<cfset eventcolor ="#colors[color_id]#">
<cfset eventurl ="leave_request_a01z.cfm?id=" & "id">
<cfset row["id"] = id>
<cfset row["title"] = title>
<cfset row["start"] = myStart>
<cfset row["end"] = myEnd>
<cfset row["color"] = eventcolor>
<!--- append to results --->
<cfset arrayAppend(result, row)>
</cfloop>
<!--- convert to json --->
<cfreturn serializeJSON(result)>
<!---
<cfreturn getEvents>
--->
</cffunction>
</cfcomponent>

ColdFusion session variables not setting correctly

I have a few session variables I need setup for permissions and only the userID, userName and sessionAdmin variables are making it through. I do a cfdump and see all of the variables set to 0, which is the cfparam default. I also can not get the page to redirect to my sample address.
login.cfm
<cfif isDefined("FORM.login")>
<cfset Encryptpwd = Encrypt(FORM.password, application.PsswrdKy)>
<cfset loginInfo = CFCmain.getLogin(FORM.username,Encryptpwd)>
<cflock timeout=20 scope="session" type="exclusive">
<cfset session.UserName = loginInfo.username>
<cfset session.userid = loginInfo.id>
<cfset session.Access_admin = loginInfo.superadmin>
<cfset session.Access_var1 = loginInfo.var1>
<cfset session.Access_var2 = loginInfo.var2>
<cfset session.Access_var3 = loginInfo.var3>
<cfset session.Access_var4= loginInfo.var4>
<cfset session.Access_agency = loginInfo.agency>
</cflock>
<cflocation url="http://www.google.com">
</cfif>
and main.cfc where my variables are pulled from the db
<cffunction name= "getLogin" access="remote" returntype="any" >
<cfargument name="uname" type="string">
<cfargument name="pwd" type="string">
<cfquery name="getdata" datasource="#application.db#">
select * from users2 where username = '#arguments.uname#' and password = '#arguments.pwd#'
</cfquery>
<cfreturn getdata>
</cffunction>
For me it looks like the variable FORM.login is not defined!?
try:
<cfif isDefined("FORM.login")>
<cfdump var="hello">
<cfabort>
....
if you don't see the "hello", FORM.login is not defined...
try also:
<cfdump var="#form#" abort>
to see what is defined in the form scope.
And how others said, use cfqueryparam!! (security)
<cfquery name="getdata" datasource="#application.db#">
select *
from users2
where username = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.uname#">
and password = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.pwd#">
</cfquery>

Railo to talk to XMPP/Jabber/Google Talk from within Railo?

I have implemented ColdFusion XMPP Event Gateway in coldfusion server 10 and it is working fine with google talk. The same thing i want to implement in Railo server but no luck to find something.
Please suggest something to "Railo to talk to XMPP/Jabber/Google Talk from within Railo"
Used cfc file in coldfusion XMPP event gateway
<cfcomponent displayname="EventGateway" hint="Process events from the test gateway and return echo">
<cffunction name="onIncomingMessage" output="no">
<cfargument name="CFEvent" type="struct" required="yes">
<cflog file="#CFEvent.GatewayID#Status" text=" onIncomingMessage; SENDER: #CFEvent.Data.SENDER# MESSAGE:
#CFEvent.Data.MESSAGE# TIMESTAMP: #CFEvent.Data.TIMESTAMP# ">
<!--- Get the message --->
<cfset data=cfevent.DATA>
<cfset message="#data.message#">
<!--- where did it come from? --->
<cfset orig="#CFEvent.originatorID#">
<cfset retValue = structNew()>
<cfif listcontains("XMPP ", arguments.CFEVENT.GatewayType) gt 0>
<cfset retValue.BuddyID = orig>
<cfset retValue.MESSAGE = "echo: " & message>
<cfelseif arguments.CFEVENT.GatewayType is "Socket">
<cfset retValue.originatorID = orig>
<cfset retValue.message = "echo: " & message>
<cfelseif arguments.cfevent.gatewaytype is "SMS">
<cfset retValue.command = "submit">
<cfset retValue.sourceAddress = arguments.CFEVENT.GatewayID>
<cfset retValue.destAddress = orig>
<cfset retValue.shortMessage = "echo: " & message>
</cfif>
<!--- we can write our script to process like database Query here --->
<!--- send the return message back --->
<cfreturn retValue>
</cffunction>
<cffunction name="onAddBuddyRequest">
<cfargument name="CFEvent" type="struct" required="YES">
<cflock scope="APPLICATION" timeout="10" type="EXCLUSIVE">
<cfscript>
// If the name is in the DB once, accept; if it is missing, decline.
// If it is in the DB multiple times, take no action.
action="accept";
reason="Valid ID";
//Add the buddy to the buddy status structure only if accepted.
if (NOT StructKeyExists(Application,"buddyStatus")) {
Application.buddyStatus=StructNew();
}
if (NOT StructKeyExists(Application.buddyStatus,CFEvent.Data.SENDER)) {
Application.buddyStatus[#CFEvent.Data.SENDER#]=StructNew();
}
Application.buddyStatus[#CFEvent.Data.SENDER#].status="Accepted Buddy Request";
Application.buddyStatus[#CFEvent.Data.SENDER#].timeStamp=
CFEvent.Data.TIMESTAMP;
Application.buddyStatus[#CFEvent.Data.SENDER#].message=CFEvent.Data.MESSAGE;
</cfscript>
</cflock>
<!--- Log the request and decision information. --->
<cflog file="#CFEvent.GatewayID#Status" text="onAddBuddyRequest; SENDER: #CFEvent.Data.SENDER# MESSAGE:
#CFEvent.Data.MESSAGE# TIMESTAMP: #CFEvent.Data.TIMESTAMP# ACTION: #action#">
<!--- Return the action decision. --->
<cfset retValue = structNew()>
<cfset retValue.command = action>
<cfset retValue.BuddyID = CFEvent.DATA.SENDER>
<cfset retValue.Reason = reason>
<cfreturn retValue>
</cffunction>
<cffunction name="onAddBuddyResponse">
</cffunction>
<cffunction name="onBuddyStatus">
</cffunction>
<cffunction name="onIMServerMessage">
</cffunction>
</cfcomponent>
Thanks,
Arun

Extract 7z file in coldfusion

Can anyone help me by suggesting a function to extract a .7z file in ColdFusion? I use ColdFusion 10 and cfscript based code. Indeed we have the cfzip tag, but it only extracts .zip and .jar files.
You can use cfexecute, which unfortunately is not availble in cfscript, to execute the 7z extractor on your server and pass through the various commands to extract the file to a place of your choosing.
Luckily for you, it seems Raymond Camden has gone into it in some detail:
http://www.raymondcamden.com/index.cfm/2011/2/21/Working-with-RARs-in-ColdFusion
Function to unrar .rar file in given destination.. use cfexecute tag to run rar exe in command line
<cffunction name="Unrar" access="public" returnType="boolean" output="false">
<cfargument name="archivefile" type="string" required="true">
<cfargument name="destination" type="string" required="true">
<cfset var exeName = "">
<cfset var result = "">
<cfset var errorresult = "">
<cfif not fileExists(arguments.archivefile)>
<cfthrow message="Unable to work with #arguments.arvhiefile#, it does not exist.">
</cfif>
<cfif findnocase(".rar",arguments.archivefile)>
<cfset var exeName = expandpath("WinRAR\rar.exe")>
<cfset var args = []>
<cfif directoryExists(#arguments.destination#)>
<cfset args[1] = "x +o">
<cfelse>
<cfset directoryCreate(#arguments.destination#)>
<cfset args[1] = "x">
</cfif>
<cfset args[2] = arguments.archivefile>
<cfset args[3] = "#arguments.destination#">
</cfif>
<cfexecute name="#exeName#" arguments="#args#" variable="result" errorvariable="errorresult" timeout="99" />
<cfif findNoCase("OK All OK", result)>
<cfreturn true>
<cfelse>
<cfreturn false>
</cfif>
</cffunction>