Issues with coldfusion query function call inside a query loop - coldfusion

I have a query loop and inside that loop, I make a cfc function call to return a second query. It's doing weird things with the display:
In the example below, instead of making a function call to obtain the second query, I create a simple loop. This displays fine. View the actual page here
<cfoutput>
<cfif qCal.recordcount>
<a class="control" onClick="return hs.getExpander(this).printHtml()" href="##">Print</a>
</cfif>
<table width="100%" cellspacing="0" cellpadding="4">
<cfloop query="qCal">
<tr>
<td align="middle" valign="top" style="width:150px;">
<a title="View full-sized image" onclick="return hs.expand(this)" href="/images/classes/#qCal.image#" class="highslide"><img src="/images/classes/#qCal.thumb#" class="resize2"></a></td>
<td>
<table cellspacing="0" cellpadding="3">
<tr>
<td colspan="2" class="textNormal"><h2>#qCal.title#</h2></td>
</tr>
<tr>
<td class="textNormal"><strong>Date:</strong></td>
<td class="textNormal"><strong>Time:</strong></td>
</tr>
<cfloop from="1" to="5" index="i"> <!--- basic loop --->
<tr>
<td>#i#</td>
<td></td>
</tr>
</cfloop>
</table>
</td>
</tr>
</cfloop>
</table>
</cfoutput>
But, as soon as I make a function call to obtain a secondary query, inexplicable things happen with the display. View the actual page here (which renders half-cooked html code).
<cfoutput>
<cfif qCal.recordcount>
<a class="control" onClick="return hs.getExpander(this).printHtml()" href="##">Print</a>
</cfif>
<table width="100%" cellspacing="0" cellpadding="4">
<cfloop query="qCal">
<cfsilent>
<cfset qCalItems = o_system.getCalendarItems(
start=dateformat(vStartDate,"yyyy-mm-yy"),
end=dateformat(vEndDate,"yyyy-mm-yy"),
classID=qCal.classID,
forQuarterlyCalendar=true,
order_by="i.startDate")>
</cfsilent>
<tr>
<td align="middle" valign="top" style="width:150px;">
<a title="View full-sized image" onclick="return hs.expand(this)" href="/images/classes/#qCal.image#" class="highslide"><img src="/images/classes/#qCal.thumb#" class="resize2"></a></td>
<td>
<table cellspacing="0" cellpadding="3">
<tr>
<td colspan="2" class="textNormal"><h2>#qCal.title#</h2></td>
</tr>
<tr>
<td class="textNormal"><strong>Date:</strong></td>
<td class="textNormal"><strong>Time:</strong></td>
</tr>
<cfloop query="qCalItems">
<tr bgcolor="#iif(qCalItems.CurrentRow MOD(2) eq 1,de('ffffff'),de('EFEFEF'))#">
<td>#DayOfWeekAsString(dayofweek(qCalItems.startDate))# #dateformat(qCalItems.startDate,"dd mmm yyyy")#</td>
<td>#qCalItems.startTime#-#qCalItems.endTime#</td>
</tr>
</cfloop>
</table>
</td>
</tr>
</cfloop>
</table>
</cfoutput>
UPDATE - CFC CODE ADDED
NOTE: Function returns either a struct or a query depending on the argument "forQuarterlyCalendar". It definitely returns a query object in this case. I have dumped the query out and confirm that it is a valid query object.
<cffunction name="getCalendarItems" access="remote" returntype="any" output="false" returnformat="json">
<cfargument name="classID" type="any" required="false" default="">
<cfargument name="forSelect" type="boolean" required="false" default="false">
<cfargument name="forQuarterlyCalendar" type="boolean" required="false" default="false">
<cfargument name="start" type="any" required="false" default="">
<cfargument name="end" type="any" required="false" default="">
<cfargument name="order_by" type="any" required="false" default="c.title">
<cfargument name="sort_direction" type="any" required="false" default="asc">
<cfargument name="json" type="boolean" required="false" default="true">
<cfargument name="must_have_store_item" type="boolean" required="false" default="true">
<cfset var qClass = 0>
<cfset var realStart = "">
<cfset var realEnd = "">
<cfset var results = []>
<cfset var vUrl = "">
<cfset var vId = "">
<cfset var vTitle = "">
<cfset var vStart = "">
<cfif len(trim(arguments.start))>
<cfset realStart = EpochTimeToLocalDate(arguments.start)>
</cfif>
<cfif len(trim(arguments.end))>
<cfset realEnd = EpochTimeToLocalDate(arguments.end)>
</cfif>
<cfquery name="qClass" datasource="#application.datasource#">
select <cfif arguments.forSelect>
c.title, i.calendarItemID as id, convert(varchar, i.startDate, 103)+' '+i.startTime+'-'+i.endTime as text
<cfelseif arguments.forQuarterlyCalendar>
c.description, i.calendarItemID as id, i.startDate, i.startTime, i.endTime
<cfelse>
i.calendarItemID, i.startDate, i.startTime, i.endTime
,c.classID, c.title, c.description, c.price, c.places, c.exclusive, c.discounted, c.url
,s.storeItemID
</cfif>
from calendarItem i
<cfif arguments.must_have_store_item>
join storeItem s on s.entityID = i.calendarItemID and s.storeItemTypeID = 3
</cfif>
join class c on c.classID = i.classID and c.active=1
where i.active=1
<cfif isnumeric(arguments.classID)>
and i.classID = <cfqueryparam value="#arguments.classID#" cfsqltype="cf_sql_integer">
</cfif>
<cfif len(trim(arguments.start))>
<cfif arguments.forQuarterlyCalendar>
and i.startDate >= <cfqueryparam value="#arguments.start#" cfsqltype="cf_sql_date">
<cfelse>
and i.startDate >= <cfqueryparam value="#dateformat(realStart,'yyyy-mm-dd')#" cfsqltype="cf_sql_date">
</cfif>
</cfif>
order by #arguments.order_by# #arguments.sort_direction#
</cfquery>
<cfif qClass.recordcount>
<cfif not arguments.forSelect and not arguments.forQuarterlyCalendar>
<cfloop query="qClass">
<cfset vUrl = qClass["url"]>
<cfset vId = qClass["storeItemID"]>
<cfset vTitle = qClass["title"]>
<cfset vStart = GetEpochTimeFromLocal(qClass.startDate)>
<cfif not len(trim(url)) or len(trim(url)) is 0>
<cfset vUrl = "#application.webroot#/class_detail.cfm?id=#vId#">
</cfif>
<cfset s = structnew()>
<cfset s["id"] = vId>
<cfset s["url"] = vUrl>
<cfset s["title"] = vTitle>
<cfset s["start"] = vStart>
<cfset arrayappend(results, s)>
</cfloop>
<cfelse>
<cfset results = qClass>
</cfif>
</cfif>
<cfif arguments.json>
<cfcontent type="application/json">
</cfif>
<cfreturn results>
</cffunction>

You need to var scope 's':
<cfset s = structnew()>

Related

ColdFusion cfselect bind not working

I have a ColdFusion 11 component which is supposed to populate a cfselect using bind. However, the select is not populated with the values at all. It shows blank. These are 2 select form controls that I want to relate to each other. A select from one should populate the other with values based on the selection made.
<td>
From IJ:
<cfselect name="im"
id="im"
bind="cfc:BTransfer.Get_Alls()"
display="strTName"
value="city_code"
queryposition="below"
bindonload="true">
<option value="">Select ...</option>
</cfselect>
</td>
<td>
To IJ:
<cfselect
name="toij"
id="toij"
bind="cfc:BTransfer.Get_Ts({city_code})"
value="strTCode"
display="strTName"
queryposition="below">
<option value="">Select ...</option>
</cfselect>
</td>
[b]The component.[/b]
<cfcomponent output="false">
<cffunction name="Get_Alls" access="remote" output="false" returntype="Query">
<cfset var qry_getall = "">
<CFQUERY NAME="qry_getall" DATASOURCE="#dsn#" cachedWithin="#CreateTimeSpan(1,0,0,0)#" >
SELECT T_Code AS strTCode,
ltrim(t_name) AS strTName,
city_code
FROM tblLookupTCity
WHERE blnactive = 1
ORDER BY T_name
</CFQUERY>
<cfreturn qry_getall />
</cffunction>
<cffunction name="Get_Ts" access="remote" output="false" returntype="Query">
<cfset var qry_getall = "">
<cfargument name="city_code" type="numeric" required="true" >
<CFQUERY NAME="qry_getall" DATASOURCE="#dsn#" cachedWithin="#CreateTimeSpan(1,0,0,0)#" >
SELECT T_Code AS strTCode,
trim(T_name) AS strTName,
city_code
FROM tblLookupTCity
WHERE CITY_CODE = '#arguments.city_code#'
AND blnactive = 1
ORDER BY T_name
</CFQUERY>
<cfreturn qry_getall />
</cffunction>
</cfcomponent>

Date issue in coldfusion

I have a report which has the date selection as show below. When the report is first loaded it will show the data for the current month ie in this case from {ts '2014-06-01 00:00:00'} to {ts '2014-07-01 00:00:00'};range in all the queries on the page. When I select a date from the dropdown and submit the page, the queries still take the start and end date as 6/1 to 7/1 instead of the selected month. I tried debugging it but still not able to get it to work. Any suggestions here?
I have updated My form is like below. I want the first radio button to be selected on the first page load, I am just making the other selection empty on click of the radio button. Is there a way to save what is in the selection and just display results for the criteria selected?please suggest
<script>
function makeChoice() {
var obj1 = document.getElementById('month_dt')
var obj2 = document.getElementById('start_date')
var obj3 = document.getElementById('end_date')
if (document.getElementById('but1').checked) {
obj2.value = '';
obj3.value = '';
}
else if (document.getElementById('but2').checked) {
obj1.value = '';
}
}
</script>
<form name="month_year" method="get">
<div>
<table>
<tr>
<th align="right">
<input type="radio" name="datesel" value="1" id="but1" onClick="return makeChoice();"/>
Month/Year:</th>
<td align="left">
<select name="month_dt" id="month_dt">
<option value="">---Select one---</option>
<cfloop from="0" to="#diff_month_cnt#" index="ii">
<cfset temp_dt = dateAdd("m", -1 * ii, today) />
<cfset temp_dt = createDate(year(temp_dt), month(temp_dt), 1) />
<cfset isselected = "" />
<cfif temp_dt EQ the_month_dt>
<cfset isselected = "selected" />
</cfif>
<option value="#dateFormat(temp_dt, 'mm/dd/yyyy')#" #isselected#>#dateFormat(temp_dt, "mmmm yyyy")#</option>
</cfloop>
</select>
</td>
</tr>
<tr><td colspan="2" align="center"><em>- or -</em></td></tr>
<tr>
<th align="right"> <input type="radio" name="datesel" value="2" id="but2" onClick="return makeChoice();"/>Start Date:</th>
<td>
<input id="start_date" type="text" name="start_date" <cfif isdate(url.start_Date)>value="#dateFormat(url.start_date, 'mm/dd/yyyy')#"</cfif> size="10" maxlength="10" autocomplete="off" />
</td>
</tr>
<tr>
<th align="right">End Date:</th>
<td>
<input id="end_date" type="text" name="end_date" <cfif isdate(url.end_Date)>value="#dateFormat(url.end_date, 'mm/dd/yyyy')#"</cfif> size="10" maxlength="10" autocomplete="off" />
</td>
</tr>
<input type="submit" value=" OK " />
<cfif isDate(url.month_dt) and url.datesel eq 1>
<cfset begin_dt = createDate(year(month_dt), month(month_dt), 1) />
<cfset end_dt = dateAdd("m", 1, begin_dt) />
<cfelseif isDate(url.start_date) AND isDate(url.end_date) and url.datesel eq 2 >
<cfset begin_dt = url.start_date />
<cfset end_dt = url.end_date />
</cfif>
<cfset the_month_dt = createDate(year(begin_dt), month(begin_dt), 1) />
In the queries like
1) WHERE q.quizdate >= <cfqueryparam cfsqltype="CF_SQL_DATE" value="#the_month_dt#" />
AND q.quizdate < <cfqueryparam cfsqltype="CF_SQL_DATE" value="#dateAdd('m', 1, the_month_dt)#" />
2) WHERE r.create_dt >= <cfqueryparam cfsqltype="CF_SQL_DATE" value="#begin_dt#" />
AND r.create_dt < <cfqueryparam cfsqltype="CF_SQL_DATE" value="#end_dt#" />
You need to change the following code:
<cfif isDate(url.month_dt)>
<cfset begin_dt = createDate(year(month_dt), month(month_dt), 1) />
</cfif>
<cfif isDate(url.start_date)>
<cfset begin_dt = url.start_date />
</cfif>
<cfset end_dt = dateAdd("m", 1, begin_dt) />
<cfif isDate(url.end_date)>
<cfset end_dt = url.end_date />
</cfif>
to be:
<cfif isDate(url.month_dt)>
<cfset begin_dt = createDate(year(month_dt), month(month_dt), 1) />
<cfset end_dt = dateAdd("m", 1, begin_dt) />
<cfelseif isDate(url.start_date) AND isDate(url.end_date)>
<cfset begin_dt = url.start_date />
<cfset end_dt = url.end_date />
</cfif>
Use DaysInMonth to look for the last date in month. As more info is given in the question, my answer is modified a bit. You need to disable and clear the values in Start/End form fields when a user chooses to select by month and vice versa. Otherwise, the users might get confused. Place the code before the form to get the start/end dates selected by a user. The final start/end dates are begin_dt and end_dt
<cfset thisMonth = createDate(year(now()), month(now()), 1) />
<cfparam name="url.month_dt" default="" />
<cfparam name="url.start_date" default="" />
<cfparam name="url.end_date" default="" />
<cfparam name="bRadioMonth" default="" />
<cfparam name="bRadioStartEnd" default="" />
<cfif len(url.month_dt) AND isDate(url.month_dt)>
<cfset begin_dt = createDate(year(url.month_dt), month(url.month_dt), 1) />
<cfset end_dt = createDate(year(begin_dt), month(begin_dt), DaysInMonth(begin_dt)) />
<!--- Disable form fields start_date and end_date --->
<cfset bFieldMonth = "">
<cfset bFieldStartEnd = "disabled">
<cfset bRadioMonth = "checked">
<cfelseif len(url.start_date) AND len(url.end_date)
AND isDate(url.start_date) AND isDate(url.end_date)>
<cfset begin_dt = createDate(year(url.start_date), month(url.start_date), day(url.start_date)) />
<cfset end_dt = createDate(year(url.end_date), month(url.end_date), day(url.end_date)) />
<!--- Disable form field month_dt --->
<cfset bFieldMonth = "disabled">
<cfset bFieldStartEnd = "">
<cfset bRadioStartEnd = "checked">
<cfelse>
<cfset begin_dt = thisMonth />
<cfset end_dt = createDate(year(begin_dt), month(begin_dt), DaysInMonth(begin_dt)) />
<!--- Default to disable form fields start_date and end_date --->
<cfset bFieldMonth = "">
<cfset bFieldStartEnd = "disabled">
<cfset bRadioMonth = "checked">
</cfif>
javascript:
<script>
function makeChoice() {
var fieldMonth = document.getElementById('month_dt');
var fieldStart = document.getElementById('start_date');
var fieldEnd = document.getElementById('end_date');
if (document.getElementById('but1').checked) {
fieldMonth.disabled = false;
fieldStart.disabled = true;
fieldEnd.disabled = true;
fieldStart.value = '';
fieldEnd.value = '';
}
else if (document.getElementById('but2').checked) {
fieldMonth.options[0].selected = true;
fieldMonth.disabled = true;
fieldStart.disabled = false;
fieldEnd.disabled = false;
}
}
</script>
If form is submitted, return selected start/end dates and run query:
<cfoutput>
Selected Start Date: #dateFormat(begin_dt, 'mm/dd/yyyy')# End Date: #dateFormat(end_dt, 'mm/dd/yyyy')#
</cfoutput>
<cfif isdefined("form.submit")>
<!---
Run Query.
1) WHERE q.quizdate >= <cfqueryparam cfsqltype="CF_SQL_DATE" value="#begin_dt#" />
AND q.quizdate < <cfqueryparam cfsqltype="CF_SQL_DATE" value="#DATEADD('d',1,end_dt)#" />
2) WHERE r.create_dt >= <cfqueryparam cfsqltype="CF_SQL_DATE" value="#begin_dt#" />
AND r.create_dt < <cfqueryparam cfsqltype="CF_SQL_DATE" value="#DATEADD('d',1,end_dt)#" />
--->
</cfif>

Invalid tag nesting configuration in ColdFusion 10?

How do I get around this ColdFusion error?
I'm following this ColdFusion tutorial. When I tried to implement the code in ColdFusion 10 I got the following error:
Invalid tag nesting configuration. A query driven queryloop tag is
nested inside a queryloop tag that also has a query attribute. This is
not allowed. Nesting these tags implies that you want to use grouped
processing. However, only the top-level tag can specify the query that
drives the processing.
The error occurred in line 76
74 : </cfloop>
75 : </tr>
76 : <cfoutput query="data" startRow="2">
77 : <tr>
78 : <cfloop index="c" list="#colList
Here is the code:
<cfset showForm = true>
<cfif structKeyExists(form, "xlsfile") and len(form.xlsfile)>
<!--- Destination outside of web root --->
<cfset dest = getTempDirectory()>
<cffile action="upload" destination="#dest#" filefield="xlsfile" result="upload" nameconflict="makeunique">
<cfif upload.fileWasSaved>
<cfset theFile = upload.serverDirectory & "/" & upload.serverFile>
<cfif isSpreadsheetFile(theFile)>
<cfspreadsheet action="read" src="#theFile#" query="data" headerrow="1">
<cffile action="delete" file="#theFile#">
<cfset showForm = false>
<cfelse>
<cfset errors = "The file was not an Excel file.">
<cffile action="delete" file="#theFile#">
</cfif>
<cfelse>
<cfset errors = "The file was not properly uploaded.">
</cfif>
</cfif>
<cfif showForm>
<cfif structKeyExists(variables, "errors")>
<cfoutput>
<p>
<b>Error: #variables.errors#</b>
</p>
</cfoutput>
</cfif>
<form action="test.cfm" enctype="multipart/form-data" method="post">
<input type="file" name="xlsfile" required>
<input type="submit" value="Upload XLS File">
</form>
<cfelse>
<style>
.ssTable {
width: 100%;
border-style:solid;
border-width:thin;
}
.ssHeader { background-color: #ffff00; }
.ssTable td, .ssTable th {
padding: 10px;
border-style:solid;
border-width:thin;
}
</style>
<p>
Here is the data in your Excel sheet (assuming first row as headers):
</p>
<cfset metadata = getMetadata(data)>
<cfset colList = "">
<cfloop index="col" array="#metadata#">
<cfset colList = listAppend(colList, col.name)>
</cfloop>
<cfif data.recordCount is 1>
<p>
This spreadsheet appeared to have no data.
</p>
<cfelse>
<table class="ssTable">
<tr class="ssHeader">
<cfloop index="c" list="#colList#">
<cfoutput><th>#c#</th></cfoutput>
</cfloop>
</tr>
<cfoutput query="data" startRow="2">
<tr>
<cfloop index="c" list="#colList#">
<td>#data[c][currentRow]#</td>
</cfloop>
</tr>
</cfoutput>
</table>
</cfif>
</cfif>
Try this:
<cfoutput>
<cfloop query="data" startRow="2">
<tr>
<cfloop index="c" list="#colList#">
<td>#data[c][currentRow]#</td>
</cfloop>
</tr>
</cfloop>
</cfoutput>

Including or excluding range attribute in dynamically generate form field

I am using a query to dynamically create form fields, not all fields use the range attribute.
When using the cfif statement to include or exclude the range attribute I get an error:
See code below:
<cfoutput>
<input type="hidden" name="question_ids" id="question_ids" value="#valueList(rsQuestions.question_id)#">
</cfoutput>
<cfoutput query="rsQuestions" group="modid">
<table border="1" cellpadding="4" cellspacing="4" bgcolor="##0E777A" >
<tr>
<td colspan="2"><span class="style1">#rsQuestions.ModName#</span></td>
</tr>
<cfoutput>
<tr>
<td width="700" bgcolor="##FFFFFF">#rsQuestions.question#</td>
<td width="200" bgcolor="##FFFFFF">
<cfif rsQuestions.question_type_id eq 1>
<cfinput type="text" name="answer_#rsQuestions.question_id#"
message="#rsQuestions.Message#"
tooltip="#rsQuestions.Tooltip#"
validate="#rsQuestions.Validate#"
<cfif #rsQuestions.Range# neq "">
range = "#rsQuestions.Range#"
</cfif>
required="#rsQuestions.mandatory#"
size="#rsQuestions.Size#">
<cfelseif rsQuestions.question_type_id eq 2>
<cfquery name="rsOptions" datasource="dsTest">
SELECT option_id, [option], question_id
FROM questionnaire_question_options
WHERE (question_id = #rsQuestions.question_id#)
</cfquery>
<cfselect enabled="yes"
name="answer_#rsQuestions.question_id#"
multiple="no"
query="rsOptions"
value="option"
display="option">
</cfselect>
</cfif>
</td>
</tr>
</cfoutput>
</table>
</cfoutput>
How can I structure the above statement to include or exclude the 'range' attribute?
As user8675309 (Jenny?) mentioned, you cannot nest <cfif> tags inside another CF tag. So you need to separate those statements out. Here is one way you could do that:
....
<cfif rsQuestions.question_type_id eq 1>
<cfif rsQuestions.Range neq "">
<cfinput type="text" name="answer_#rsQuestions.question_id#"
message="#rsQuestions.Message#"
tooltip="#rsQuestions.Tooltip#"
validate="#rsQuestions.Validate#"
range="#rsQuestions.Range#"
required="#rsQuestions.mandatory#"
size="#rsQuestions.Size#">
<cfelse>
<cfinput type="text" name="answer_#rsQuestions.question_id#"
message="#rsQuestions.Message#"
tooltip="#rsQuestions.Tooltip#"
validate="#rsQuestions.Validate#"
required="#rsQuestions.mandatory#"
size="#rsQuestions.Size#">
</cfif>
<cfelseif rsQuestions.question_type_id eq 2>
....
As mentioned, you can't nest a cfif (or any CF tag) inside another CF tag.
One thing you can do if you really need dynamic attributes is to use the "attributeCollection" attribute.
(ColdFusion 8 or higher.)
Something like:
<cfset inputAttr=structNew()>
<cfset inputAttr.type="text">
<cfset inputAttr.name="answer_#rsQuestions.question_id#">
<cfset inputAttr.message="#rsQuestions.Message#">
<cfset inputAttr.tooltip="#rsQuestions.Tooltip#">
<cfset inputAttr.validate="#rsQuestions.Validate#">
<cfif rsQuestions.Range neq "">
<cfset inputAttr.range = "#rsQuestions.Range#">
</cfif>
<cfset inputAttr.required="#rsQuestions.mandatory#">
<cfset inputAttr.size="#rsQuestions.Size#">
<cfinput attributecollection="#inputAttr#">

Browser cache effect on coldfusion login

I have a code that has been in the production environment for the past 2 years with no issues, last week our hosting company was down for two days, and when the server got back online, our application started having a particular issue.
This issue is when you try to login, it will bring you back to the login page with no errors.
I submitted a troble ticket and i was asked to clear my browser cache. I cleared my cache and the application started working again.
Is there no other way to resolve this issue without clearing the browser cache?
I have tried several method, I have used
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
and also used
<cflocation url="index.cfm" addtoken="yes">
Please see the code for Application.cfc
<cfcomponent>
<cfset this.name = "some_app">
<cfset this.applicationTimeout = createTimeSpan(0,9,0,0)>
<cfset this.clientmanagement= "yes">
<cfset this.ClientStorage = "registry"><!--- this was formally cookie, i changed it to registry, but no change --->
<cfset this.loginstorage = "session" >
<cfset this.sessionmanagement = "yes">
<cfset this.sessiontimeout = createTimeSpan(0,4,0,0)>
<cfset this.setClientCookies = "yes">
<cfset this.setDomainCookies = "yes">
<cfset this.scriptProtect = "all">
<cfset this.datasource = "some_dsn">
<cffunction name="onApplicationStart" output="false">
<cfset application.scriptProtect = "all">
<cfset application.sessions = 0>
<cfset application.surportmail = "support#some_app.com">
<cfset application.site.url = "http://some_app.com/"/>
<cfset application.com.Employee = CreateObject("component","com.user.Employee").init()/>
<cfset application.com.Appraisal = CreateObject("component","com.Appraisal").init()/>
<cfset application.com.Security = CreateObject("component","com.system.Login").init()/>
<cfset application.com.Log = CreateObject("component","com.adexfe.portal.system.Log").init()/>
<cfset application.com.Temp = CreateObject("component","com.adexfe.portal.Temp").init()/>
<cfset application.com.Util.Security = CreateObject("component","com.adexfe.util.Security").init()/>
<cfset application.com.Security.url = application.site.url/>
</cffunction>
<cffunction name="onApplicationEnd" output="false">
<cfargument name="applicationScope" required="true">
</cffunction>
<cffunction name="onRequestStart">
<cfargument name="requestname" required=true/>
<cflock type="exclusive" scope="session" timeout="10">
<cfparam name="session.IsLogin" default="false" type="boolean" />
<cfparam name="session.Userinfo" default="" />
</cflock>
<cflock type="readonly" scope="session" timeout="40">
<cfset request.IsLogin = session.IsLogin>
<cfset request.UserInfo = session.UserInfo>
</cflock>
<!--- Check for login here --->
<cfif Not request.IsLogin and ListLast(cgi.SCRIPT_NAME,'/') NEQ "login.cfm" and ListLast(cgi.SCRIPT_NAME,'/') NEQ "forget.cfm">
<cflocation url="login.cfm" addtoken="no">
</cfif>
<cfset application.com.Security.url = application.site.url/>
<cfset request.Security = application.com.Util.Security/>
<cfparam name="url.bp" default="#request.Security.URLEncrypt('bp=home')#"/>
<cfset url.bpr = url.bp/>
<cfif listfirst(url.bp,'=') eq 'h'>
<cfset request.aurl = request.Security.URLDecrypt(listlast(url.bp,'='))/>
<cfelse>
<cfset request.aurl.bp = url.bp/>
</cfif>
<cfset request.aurl.bp = Replace(request.aurl.bp,'.','/','all')>
</cffunction>
</cfcomponent>
Login.cfm code:
<html>
<head>
<title>Login</title>
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link href="Assets/css/reset.css" rel="stylesheet" type="text/css" />
<link href="Assets/css/login.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td width="50%" align="right"><br /> <img src="Assets/img/logo-b.jpg" width="445" height="164" /></td>
<td><span class="label"> <img src="Assets/img/comp_logo.gif" vspace="100" hspace="50" /></span></td></tr>
</table>
<cfform name="login">
<table width="300" border="0" align="center" >
<tr><td nowrap class="label"> Email:</td>
<td><cfinput class="in" name="username" message="Valid email address is required please" type="text" required="yes" /></td></tr>
<tr><td height="41" class="label">Password:</td>
<td><cfinput class="in" name="Password" style="color:red;" required="yes" type="password"/></td></tr>
<tr><td height="41"> </td>
<td><input type="submit" value="Login" class="sub"/><input name="Captcha" value="" type="hidden"></td></tr>
<tr><td> </td>
<td>Forget password?</td></tr>
</table>
</cfform>
<cfoutput>
<cfif structkeyexists(form,'Captcha')>
<!---login with user info --->
<cfset s = createobject("component","com.system.Security").init(false,false)/>
<cfset l = createobject("component","com.system.Login").init()/>
<cfset l.url = application.site.url/>
<cfset l.SignIn(form,s)/>
<cfif Not l.IsLogin>
<div align="center" style="color:##F00; font-weight:bold; text-align:center;">#l.errmsg#</div>
<cfset application.com.Log.WriteLoginAttempt(form.username)/>
<cfelse>
<!--- set session --->
<cflock type="exclusive" scope="session" timeout="30" throwontimeout="yes">
<cfset session.IsLogin = true>
<cfset session.userInfo = application.com.Employee.GetEmployee(l.userInfo.employeeid)/>
</cflock>
<cfset application.com.Log.WriteLoginSuccess(form.username,l.userInfo.employeeId)/>
<cflocation url="index.cfm" addtoken="no">
</cfif>
</cfif>
</cfoutput>
</body>
</html>
Thank you
you can clear you application variables on the server if you use these commands, also you can use structClear() if you want to reset any of the variables and restart the application. Generally speaking once application variables are set they stay persistent in memory until the application is restarted.
these commands will restart the application.
<cfscript> applicationStop(); </cfscript> or <cfset applicationStop()>
after the variables have been cleared you can remove that line of code and that should resolve the caching issue.