How would I skip the specific time slot in ColdFusion - coldfusion

I am creating a reservation system for the cars with instructors and its basically working correctly. I want to implement the rule where I can say want to block some additional sessions.
For example the instructor just finish session from 6:00Am to 8AM. the next available slot should be 8AM if they decide back to back scheduling and 8:15AM (if they want a break). The other sessions withing 105 minutes span should be hidden so the next available session will at either 10AM
<cfloop index="ii" from="#startHour#" to="#endHour#">
<cfloop index="jj" from="0" to="#60-locbtwMinute#" step="#locbtwMinute#">
<cfset showtime="y">
<cfset time = createtime(ii, jj, 0)>
<cfloop query="qAssignedSessions">
<cfset preSessionStart = dateadd("n",-locBtwSpan-buffertime,sessionstart)>
<cfset postSessionend = dateadd("n",bufferTime,sessionend)>
<cfif (hour(time) gt hour(preSessionStart) or (hour(time) eq hour(preSessionStart) and minute(time) gt minute(preSessionStart)))
and (hour(time) lt hour(postSessionend) or (hour(time) eq hour(postSessionend) and minute(time) lt minute(postSessionend)))>
<cfset showtime="n">
</cfif>
</cfloop>
<cfif ((datecompare(arguments.startDt,latestSessionDate) eq 1 and ((hour(time) eq 20 and minute(time) eq 00) or hour(time) lt 20))
or (datecompare(arguments.startDt,latestSessionDate) eq 0 and ((hour(time) eq 20 and minute(time) eq 00) or (hour(time) lt 20 and hour(time) gt hour(now()))))
)
and showtime eq "y">
<option value="<cfoutput>#timeformat(time, 'HH:mm')#</cfoutput>"><cfoutput>#timeformat(time, "hh:mm tt")#</cfoutput></option>
</cfif>
</cfloop>
</cfloop>

I figure out I just create 2 array one for time slots that are available and second for the one that are already taken and eliminate the one I do not need

Related

making the listcolumns search dynamic

I am following upn on a tute on datatables and found a code which basically iterates over the columns for a order clause but in the case, i do not have a list of order columns hardcoded, its a dynamic list
how can I change this
<cfif form["order[0][column]"] gt 0>
ORDER BY
<cfif form["order[0][column]"] eq '1'>
empname <cfif form["order[0][dir]"] eq 'desc'>desc</cfif>
</cfif>
<cfif form["order[0][column]"] eq '2'>
empno <cfif form["order[0][dir]"] eq 'desc'>desc</cfif>
</cfif>
<cfif form["order[0][column]"] eq '3'>
ic <cfif form["order[0][dir]"] eq 'desc'>desc</cfif>
</cfif>
</cfif>
to be dynamic as my list variable is a comma separated as id,name,email and lots more
The direction I always would go will be to create a Coldfusion array or structure with this fieldNames, like the following.
<cfset orderColumnReference = ['empname', 'empno', 'ic', 'id', 'name', 'email', ...]>
<cfif form["order[0][column]"] GTE ArrayLen(orderColumnReference)>
<cfset orderByColumn = orderColumnReference[form["order[0][column]"]]>
ORDER BY
#orderByColumn# <cfif form["order[0][dir]"] eq 'desc'>desc</cfif>
</cfif>

How to properly format dates with SpreadsheetFormatColumns

Server: CF10
Platform: Windows and Linux (Win in DEV windows in PROD)
So I'm generating an excel file for a client, but having trouble getting date fields to behave properly. Everything else seems to work just fine but when I send the data to excel to be generated, excel treats it as just text. So when the field gets sorted, it is handled as such.
More info: The column I'm trying to configure is called Arrival Date it is arriving formatted as mm/dd/yyyy. (I have tried to format is as m/d/yy, but when it arrives in the sheet that doesn't work as well.)
Code:
<cfset filename = expandPath("./TDYData_(#DateFormat(now(),'mmddyy')#).xls")>
<!--- Make a spreadsheet object --->
<cfset s = spreadsheetNew("TDYData")>
<!--- Add header row --->
<cfset spreadsheetAddRow(s, "TDY Phase,Full Name,Employment Category,Gender,Originating Agency,Agency Comments,Originating Office,Office Comments,Originating Country,TDY Request Received,Mission Office Supported,Type of TDY Support,eCC Submission,eCC Approval,eCC Point of Contact,Date of Departure from Originating Country,Arrival Date,Departure Date,Accomodation Type,Accomodation Comments,Assigned Desk,Local Mobile Number,TDY Comments")>
<!--- format header --->
<cfset spreadsheetFormatRow(s, {bold=true,fgcolor="lemon_chiffon",fontsize=10}, 1)>
<!--- Add query --->
<cfset spreadsheetAddRows(s, myExcel)>
<cfset SpreadSheetAddFreezePane(s,0,1)>
<cfset SpreadsheetFormatColumn(s, {dataformat="m/d/yy"}, 17) />
<cfset SpreadsheetFormatColumn(s, {alignment="right"}, 16) />
<cfheader name="content-disposition" value="attachment; filename=TDY_Data_(#DateFormat(now(),'mmddyy')#).xls">
<cfcontent type="application/msexcel" variable="#spreadsheetReadBinary(s)#" reset="true">
Any ideas?
Thanks
So I have a workable solution:
<cfset therow = 0>
<cfoutput query="myExcel" startrow="1">
<cfset therow = myExcel.currentrow + 1>
<cfif len(eCCSubDate) GT 0>
<cfset SpreadsheetSetCellFormula(s,"DATEVALUE(#Chr(34)##eCCSubDate##Chr(34)#)",therow,13)>
</cfif>
<cfif len(eCCApproved) GT 0>
<cfset SpreadsheetSetCellFormula(s,"DATEVALUE(#Chr(34)##eCCApproved##Chr(34)#)",therow,14)>
</cfif>
<cfif len(DateDepartCntry) GT 0>
<cfset SpreadsheetSetCellFormula(s,"DATEVALUE(#Chr(34)##DateDepartCntry##Chr(34)#)",therow,16)>
</cfif>
<cfif len(DateArrive) GT 0>
<cfset SpreadsheetSetCellFormula(s,"DATEVALUE(#Chr(34)##DateArrive##Chr(34)#)",therow,17)>
</cfif>
<cfif len(DateDepart) GT 0>
<cfset SpreadsheetSetCellFormula(s,"DATEVALUE(#Chr(34)##DateDepart##Chr(34)#)",therow,18)>
</cfif>
</cfoutput>
So I set a variable for a counter then loop back over the query and check to make sure its not an empty cell then apply a formula to the cell the chr(34) are quotes then the data value. By using this, (After the data is written) it will at least behave like a real date field.

Conditional Cfloop code to place AND at first loop

Using the following query, I am trying to do a simple case here when the first record it encounters it should basically add "AND" and for the remaining conditions, I want to add OR
Here is my try
<cfif isDefined('age') and len(trim(age)) and age neq '-1'>
<cfset age = trim(htmlEditFormat(lcase(age)))>
<cfloop list="#age#" index="k">
or age between #ListFirst(k,'-')# and #ListLast(k,'-')#
</cfloop>
</cfif>
trying to make it work like this
and (age between 18 and 20
or age between 20 and 25
or age between 25 and 30)
I am not getting where I should add a condition to add parenthesis and the AND operator.
You could do something as similar as adding a false statement and then looping through everything else as needed
<cfif isDefined('age') and len(trim(age)) and age neq '-1'>
<cfset age = trim(htmlEditFormat(lcase(age)))>
AND (1 = 2 --always returns false
<cfloop list="#age#" index="k">
OR age between #ListFirst(k,'-')# and #ListLast(k,'-')#
</cfloop>
)
</cfif>
This is what you were trying to do
<cfif isDefined('age') and len(trim(age)) and age neq '-1'>
<cfset age = trim(htmlEditFormat(lcase(age)))>
AND (
<cfloop list="#age#" index="k">
<cfif listFirst(age) NEQ k> OR </cfif> --if it's not the first iteration, add the OR
age between #ListFirst(k,'-')# and #ListLast(k,'-')#
</cfloop>
)
</cfif>
An alternative that doesn't require an if block and would work for any type of loop:
<cfif isDefined('age') and len(trim(age)) and age neq '-1'>
<cfset age = trim(htmlEditFormat(lcase(age)))>
<cfset expressionSeparator = "">
AND (
<cfloop list="#age#" index="k">
#expressionSeparator#
age between #ListFirst(k,'-')# and #ListLast(k,'-')#
<cfset expressionSeparator = " or ">
</cfloop>
)
</cfif>

Show where column equals a specific data?

I have a column(cse_dept) where it has integers , I would only like to show the columns where it equals 12 or 39.
Is there a way to do this?
<cfif (#GetCurrentUser.cse_dept# eq '12'39') >
<h1>test</h1>
</cfif>
It does not show me a error it just doesn't work the way I would like it.
You can use listFind. If the value of GetCurrentUser.cse_dept is 12 or 39 listFind will return the a number greater than 0
<cfif listFind('12,39', GetCurrentUser.cse_dept)>
<h1>test</h1>
</cfif>
listFind is case sensitive in case you were searching for something other than numbers. If you need a case-insensitve search you can use listFindNoCase
Alternatively you could check for each value separately
<cfif GetCurrentUser.cse_dept EQ 12 OR GetCurrentUser.cse_dept EQ 39>
<h1>test</h1>
</cfif>
If you want to check if GetCurrentUser.cse_dept is 12 or 39 for any result in your query you can do
<cfif listFind(valueList(getCurrentUser), 12) OR listFind(valueList(getCurrentUser), 39)>
<h1>test</h1>
</cfif>
There are a few ways to do this:
Method 1 - Query of Queries
<cfquery name="q1" dbtype="query">
select count(*) records
from GetCurrentUser
where cse_dept in (12,39)
</cfquery>
<cfif q1.records gt 0>
do something
</cfif>
Method 2 - List Functions
<cfif ListFind(ValueList(GetCurrentUser.cse_dept), 12)
+
ListFind(ValueList(GetCurrentUser.cse_dept), 39) gt 0>
do something
</cfif>
Method 3 - Array Functions
<cfif ArrayFind(GetCurrentUser['cse_dept'], 12)
+
ArrayFind(GetCurrentUser['cse_dept'], 39) gt 0>
do something
</cfif>
Method 2 is very similar to Matt's second suggstion. One difference is the use of a ValueList function. The second is that instead of using "or", I added the function results together. The results are the same.
Method 3 is probably the fastest. However, depending on where those numbers 12 and 39 come from, Method 1 might be a better approach.

ColdFusion ImageWrite to Amazon S3

This is a strange one - I have 'virtually' identical code on 2 pages, it works on one but not the other. The incredibly unhelpful error message, "S3 Error Message." doesn't shed any light on where I'm going wrong with this.
The code below is identical on both pages - the only (very slight) difference between the 2 pages is the way imgLink is generated - on the working page it is obtained from a single source (an XML feed) and cfset, on the none-working page imgLink is initially set as 'none' and then a number of sources are checked until it finds one - it's still cfset in the same way, and I have a cfif to make sure it's valid before processing. HOWEVER - I have also tried hardcoding the source (i.e., pasting in the value that would usually be in the imgLink cfset) and it still fails.
I've debugged this in every way I can possibly think in the last day, without success. So, I guess I'm looking for pointers as to what else I should look at that could be causing it to fail.
The full error returned is -
An error occurred when performing a file operation create on file s3://mybucket/1577-67BC4EF7-1B21-866F-32E95DF67F3336C6-f.jpg.
The cause of this exception was: org.apache.commons.vfs.FileSystemException: Unknown message with code "S3 Error Message."..
And my code is;
<cfscript>
this.name ="Object Operations";
this.s3.accessKeyId = "accessKey";
this.s3.awsSecretKey = "secretKey";
this.s3.defaultLocation="EU";
</cfscript>
<!--- CFImage Stuff --->
<!--- S3 Permissions --->
<cfset perms = [{group="all", permission="read"}]>
<!--- Create the Images ---->
<cfset imageuuid = '#CreateUUID()#'>
<cfset imagefull = '#getid.id#-#imageuuid#-f.jpg'>
<cfset imagemain = '#getid.id#-#imageuuid#-m.jpg'>
<cfset imagethumb = '#getid.id#-#imageuuid#-t.jpg'>
<cfimage action="read" name="img1" source="#imgLink#">
<!--- Create the full size image 505 x N --->
<cfif img1.height GT img1.width>
<cfif img1.width GTE 505>
<cfset ImageResize(img1,'505','')>
</cfif>
<cfelseif img1.width GT img1.height>
<cfif img1.width GTE 505>
<cfset ImageResize(img1, '505','')>
</cfif>
</cfif>
<cfset ImageWrite(img1, "s3://mybucket/#imagefull#")>
<cfset StoreSetACL("s3://mybucket/#imagefull#","#perms#")>
<!--- Create the main size image 251 x N --->
<cfif img1.height GT img1.width>
<cfif img1.width GTE 251>
<cfset ImageResize(img1,'251','')>
</cfif>
<cfelseif img1.width GT img1.height>
<cfif img1.width GTE 251>
<cfset ImageResize(img1, '251','')>
</cfif>
</cfif>
<cfset ImageWrite(img1, "s3://mybucket/#imagemain#")>
<cfset StoreSetACL("s3://mybucket/#imagemain#","#perms#")>
<!--- Create the thumbnail 52 x 52 --->
<!--- resize image to 52 pixels tall if width is greater then height --->
<cfif img1.height GT img1.width>
<cfset ImageResize(img1,'52','')>
<cfset fromX = img1.Height / 2 - 26>
<cfset ImageCrop(img1,0,fromX,52,52)>
<!--- resize image to 75 pixels wide if height is greater then width --->
<cfelseif img1.width GT img1.height>
<cfset ImageResize(img1,'','52')>
<cfset fromY = img1.Width / 2 - 26>
<cfset ImageCrop(img1,fromY,0,52,52)>
<cfelse>
<cfset ImageResize(img1,'','52')>
<cfset ImageCrop(img1,0,0,52,52)>
</cfif>
<cfset ImageWrite(img1, "s3://mybucket/#imagethumb#")>
<cfset StoreSetACL("s3://mybucket/#imagethumb#","#perms#")>
Just realised I hadn't added my solution to this, so here it is- The folder in which the 'non-working' code was in had it's own Application.cfc, which didn't include the S3 elements in the code posted above. The 'working' code did have that in the corresponding Application.cfc.
Not quite sure why that had to be in Application.cfc when it was at the
The this object in application.cfc is an application component and this on ColdFusion page is just a structure variable. Put <cfdump var=#this#> in both places, application.cfc and yourfile.cfm, to see the difference.