Edit table row in ColdFusion - coldfusion

I use cftable or cfloop to output a table of items in ColdFusion. But what is the right way to call the editor page on clicking one of table rows?
Here is the code:
<table class="grid">
<tr>
<th>id</th>
<th>Date</th>
<th>Description</th>
<th>Status</th>
<th>Urgency</th>
<th>Severity</th>
</tr>
<cfloop query="GetIssues">
<tr>
<td><cfoutput>#id#</cfoutput></td>
<td><cfoutput>#CreatedOn#</cfoutput></td>
<td><cfoutput>#ShortDesc#</cfoutput></td>
<td><cfoutput>#Status#</cfoutput></td>
<td><cfoutput>#Urgency#</cfoutput></td>
<td><cfoutput>#Severity#</cfoutput></td>
</tr>
</cfloop>
</table>
I could use a href to make GET request to editor page, but is it the right/safe way?

You can certainly create a link to the editor page and pass the ID, however, if your IDs are numeric, it will be easy for nefarious users to guess the ID of another item. To mitigate this issue, I tend to use UUIDs for my IDs. It is extremely difficult to guess at the ID of another element.
Also, it is better to wrap the cfloop in a cfoutput, rather than wrapping each td - and you should scope your variable names.
For example:
<cfoutput>
<cfloop query="GetIssues">
<tr>
<td>#GetIssues.id#</td>
<td>#GetIssues.CreatedOn#></td>
<td>#GetIssues.ShortDesc#</td>
<td>#GetIssues.Status#</cfoutput></td>
<td>#GetIssues.Urgency#</cfoutput></td>
<td>#GetIssues.Severity#</td>
</tr>
</cfloop>
</cfoutput>

Related

How to loop through a SQL query and output individual emails base on

I'm trying to loop over information from a query and send that information in an email. Currently, based on my stored procedure, I'm displaying all the rows in the email.
This is what I'm using to get the above information:
<table>
<thead>
<tr>
<th scope="col" id="left">Admin Name</th>
<th scope="col" id="middle">Department Name</th>
<th scope="col" id="right">Last Logon</th>
</tr>
</thead>
<tbody>
<cfloop query="#inactiveAdmins#">
<tr>
<td class="text-left">#Admin_Name#</td>
<td class="text-left">#Dept_Name#</td>
<td class="">#(Len(Last_Logon) ? dateFormat(Last_Logon, 'mmm dd, yyyy') : 'Never Logged On')#</td>
</tr>
</cfloop>
</tbody>
</table>
This is displaying all Admin Names, All Department Names and all Last Logon.
I need to be able to loop over each department and send an email to each department individually.
To loop over each department, this is what I'm trying, but it's not returning any results. My question is:
Is the syntax correct?
<cfloop query="#ALEmail#">
<cfquery dbtype="query" name="inactiveSW">
SELECT Dept_ID
FROM inactiveSW
WHERE Dept_ID = <cfqueryparam cfsqltype="cf_sql_char" value="#ALEmail.Dept_ID#">
</cfquery>
</cfloop>
This is more of a comment than an answer, but it is long
should be
On this part
<cfquery dbtype="query" name="inactiveSW">
SELECT Dept_ID
FROM inactiveSW
WHERE Dept_ID = <cfqueryparam cfsqltype="cf_sql_char" value="#ALEmail.Dept_ID#">
</cfquery>
Because the FROM is the same as the name=, it is like to either have a syntax error, or overwrite an existing variable.
Besides, you are just selecting a variable that already exists. This doesn't get any new information. Are you trying to test for existence of dept_id?
Lastly, if you are trying to send an email based on a query, it is really straight forward
<cfmail
query="ALEmail"
from="#from#"
to="#to#"
subject="#subject#">
Content here
</cfmail>

cfdocument issue - cfdocument has no body

I am working with Coldfusion10 and am facing this error:
The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request
cfdocument tag has no body.
It must have a body or a source file or URL.
I checked the website and detected that cfsettings is not defined at the top or anywhere which can cause this issue, I am using it as
<cfdocument format="pdf">
<cfdocumentsection>
<cfdocumentitem type="header"></cfdocumentitem> - Footer is used too
</cfdocumentsection>
I tried using evalAtPrint= true but still no success. Am I missing something here?
Make sure you are actually putting in at the end. I'm assuming you just missed this here.
Otherwise everything seems to align up with the Wiki Docs.
I would suggest two things.
Verify you are using ColdFusion 11 Update 3. Update 3 was a major update and may have addressed this issue.
If you are using update 3, open a bug at bugbase.adobe.com
The error message you included in your question indicates that there is no content between your <cfdocument> tags. The code that you included corroborates that. If this is not your actual code then we cannot be of much help.
You need to include the content that you would like to be converted into PDF between the <cfdocument> tags. You need something like this:
<cfquery datasource="cfdocexamples" name="empSalary">
SELECT Emp_ID, firstname, lastname, e.dept_id, salary, d.dept_name
FROM employee e, departmt d
WHERE e.dept_id = d.dept_id
ORDER BY d.dept_name
</cfquery>
<cfdocument format="PDF">
<cfoutput query="empSalary" group="dept_id">
<cfdocumentsection>
<cfdocumentitem type="header">
<font size="-3"><i>Salary Report</i></font>
</cfdocumentitem>
<cfdocumentitem type="footer">
<font size="-3">Page #cfdocument.currentpagenumber#</font>
</cfdocumentitem>
<h2>#dept_name#</h2>
<table width="95%" border="2" cellspacing="2" cellpadding="2" >
<tr>
<th>Employee</th>
<th>Salary</th>
</tr>
<cfset deptTotal = 0 >
<!--- inner cfoutput --->
<cfoutput>
<tr>
<td>
<font size="-1">#empSalary.lastname#, #empSalary.firstname#</font>
</td>
<td align="right">
<font size="-1">#DollarFormat(empSalary.salary)#</font>
</td>
</tr>
<cfset deptTotal = deptTotal + empSalary.salary>
</cfoutput>
<tr>
<td align="right"><font size="-1">Total</font></td>
<td align="right"><font size="-1">#DollarFormat(deptTotal)#</font></td>
</tr>
<cfset deptTotal = 0>
</table>
</cfdocumentsection>
</cfoutput>
</cfdocument>
Copied from the ColdFusion documentation here

Nested cfloops with less records than outer loop cause "array index out of range" error

I'm very curious why this is happening. I've run into it twice now, and after a ton of googling/so'ing, I haven't found any reason I actually understand. The gist of it:
Query 1: selectContent (6 records; no blanks/nulls etc)
Query 2: selectPricing (5 records; no blanks/nulls etc)
Output:
<cfloop query="selectContent">
<section>
#selectContent.h2#
<cfif selectContent.id eq 3>
<cfloop query="selectPricing" group="groupCol">
<table class="pricing">
<thead>
<tr>
<th>#description#</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<cfloop>
<tr>
<td>#selectPricing.description#</td>
<td>#selectPricing.price#</td>
</tr>
</cfloop>
</tbody>
</table>
</cfloop>
</cfif>
#selectContent.content#
</section>
</cfloop>
This will give the following error: Array index out of range: 5
The error only occurs when the second query has less records than the first. Essentially it feels like that first cfloop takes over the loop iteration from that second one and this causes the issue, but also only if you have that third grouped cfloop in there. The entire inner cfloop runs, as is there in the source.
I've come up with two ways to resolve this:
do this with cfoutput/group, but that's relatively ugly as it means lots of closing of cfoutputs from other parts of the page.
stick a cfbreak on that third cfloop if the currentRow matches the recordcount.
So, two questions:
Why is this even happening?
Should I be using a totally different approach here (the fact that googling/so'ing isn't finding others with this issue certainly seems to imply that...)?
EDIT
I've filed this as a Coldfusion bug based on Adam Cameron's feedback below. Bug #3820049
Well done, you've found a bug in CF. I can replicate it (PS... it'd've been cool had you included some sample data save me having to do it!)
The work-around is straight forward though:
<cfscript>
selectContent = queryNew("h2,id,content", "varchar,integer,varchar", [
["one", 1, "content.1"],
["two", 2, "content.2"],
["three", 3, "content.3"],
["four", 4, "content.4"],
["five", 5, "content.5"],
["six", 6, "content.6"],
["seven", 7, "content.7"]
]);
selectPricing = queryNew("groupCol,description,price", "varchar,varchar,varchar", [
["groupCol.1", "description.1", "1.11"],
["groupCol.2", "description.2", "2.22"],
["groupCol.2", "description.3", "3.33"],
["groupCol.3", "description.4", "4.44"],
["groupCol.3", "description.5", "5.55"],
["groupCol.3", "description.6", "6.66"]
]);
</cfscript>
<cfloop query="selectContent">
<section>
<cfoutput>#selectContent.h2#</cfoutput>
<cfif selectContent.id eq 3>
<cfoutput query="selectPricing" group="groupCol">
<table class="pricing">
<thead>
<tr>
<th>#description#</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<cfoutput>
<tr>
<td>#description#</td>
<td>#price#</td>
</tr>
</cfoutput>
</tbody>
</table>
</cfoutput>
</cfif>
<cfoutput>#selectContent.content#</cfoutput>
</section>
</cfloop>
Note how I've used <cfoutput> to do the inner looping.
This is a serious bug in ColdFusion (10 and 11), and you should raise it on their bug base (if you do, report the ticket number/URL back here so we can vote on it)

Display ColdFusion Query Output in a Formatted Table

Let me begin by saying that I'm a novice at ColdFusion and trying to learn so please bear with me.
I work in an apartment complex that caters to students from the local college. We have one, two and four bedroom apartments. Each room in an apartment is leased to an individual student. What I want to do is populate an HTML table with all the people in a room. My query is working and pulling all the relevant data but what is happening is that each person is being split out to their own HTML table instead of all the people in a room being put into the same table. Here is an example:
What I want
What is happening:
Here is my code:
<!---Begin data table--->
<cfoutput query = "qryGetAssignments">
<div class="datagrid">
<table>
<tr><td align="right"><strong>#RoomType#</strong></td></tr>
<thead>
<tr>
<th>#RoomNumber#</th>
</thead>
<tbody>
<tr><td><strong>#Bed#</strong>
| #FirstName# #LastName# :: #StudentNumber#
</td>
</tr>
</tbody>
</table>
</div>
</cfoutput>
I know why the output is coming out like it is, I just don't know how to fix it. I want there to be four residents in one table for a four bedroom apartment, two residents in a table for a two bedroom, and so on. Thanks in advance for your help.
Edit:
Sorry about the confusion. Here is a full pic of what I'm going for:
This should do what you need, assuming your query is properly ordered by roomType, for the <cfoutput group=""> to work.
<!---Begin data table--->
<cfoutput query="qryGetAssignments" group="roomType">
<div class="datagrid"><!--- If this isn't needed to style the tables, it can be moved outside the loop --->
<table>
<tr><td align="right"><strong>#qryGetAssignments.roomType#</strong></td></tr>
<thead>
<tr>
<th>#qryGetAssignments.roomNumber#</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<strong>#qryGetAssignments.bed#</strong>
<cfoutput><!--- this output here will loop over rows for that groupby --->
| #FirstName# #LastName# :: #StudentNumber#
</cfoutput>
</td>
</tr>
</tbody>
</table>
</div>
</cfoutput>
I've also scoped your query variables, at least I believe they are variables from a query.
That should work except it might need to be grouped by "roomNumber" such as N108.

How to send table html with email using mailto?

I want to send a email using a href="mailto.."
I have this working code below:
<cfset month = URL.Month>
<cfset year = URL.Year>
<cfquery datasource="newsletters" name="testing">
SELECT * FROM departments_names
where dates >='#datestart#' and dates < #dateend#
AND shooting_star_dept_name IS NOT NULL
ORDER BY
DATEPART(year, dates),
DATEPART(month, dates),
</cfquery>
<cfoutput query="testing" GROUP="deptartmetn_name">
<tr>
<td>
<a href="mailto:?subject=#month#/#year#%20%20Results%20for%20newsletters&
body=#total_count#%20#total/total_count#">
Send email to #deptartmetn_name#</a></td>
</tr>
</cfoutput>
Which just send a simple "12/2" (for example).
I would like to be able to send more than just simple text.
I would like when i click on a link to be able to send a table like below:
<table>
<thead>
<tr >
<th> First Name</th>
<th> Last Name</th>
<th>total</th>
</tr>
</thead>
<cfoutput query="testing">
<tbody>
<tr >
<td>#employee_name#</td>
<td>#employee_lastname#</td>
<td>#total_count#</td>
</tr>
</tbody>
</cfoutput>
</table>
I would like to see what I'm sending first to the recipient.
Would something like this be possible or is there a better way to do this?
My first post here and beginner to coding.
You could use an AJAX callback on your links and use cfmail with cfsavecontent (for the actual HTML content/body of the message) in your callback handler code.