cfchart data to display drive details indivisually - coldfusion

<html>
<head>
</head>
<body>
<cfhttp method="Get"
url="http://localhost:90/myweb/xmlwork/xmlfile.cfm">
<cfoutput>
#cfhttp.filecontent#
</cfoutput>
<br>
<br><br><br>
<!---<cffile action="read" file="http://localhost:90/myweb/xmlfile.cfm" variable="myxml">--->
<cfset mydoc = XmlParse(cfhttp.filecontent)>
<cfset dd = mydoc.StorageList.XmlChildren>
<cfset size = ArrayLen(dd)>
<cfoutput>
Number of Drive = #size#
<br>
</cfoutput>
<br>
<cfset myquery = QueryNew("DriveName,TotalSpace,FreeSpace") >
<cfset temp = QueryAddRow(myquery, #size#)>
<cfloop index="i" from = "1" to = #size#>
<cfset temp = QuerySetCell(myquery, "DriveName",
#mydoc.StorageList.DriveDetails[i].DriveName.XmlText#, #i#)>
<cfset temp = QuerySetCell(myquery, "TotalSpace",
#mydoc.StorageList.DriveDetails[i].TotalSpace.XmlText#, #i#)>
<cfset temp = QuerySetCell(myquery, "FreeSpace",
#mydoc.StorageList.DriveDetails[i].FreeSpace.XmlText#, #i#)>
</cfloop>
Contents of the: <br>
<cfdump var=#myquery#>
<br><cfloop index="i" from = "1" to = #size#>
<cfchart format="flash" show3d="true" chartwidth="300" chartheight="300" >
<cfchartseries type="pie">
<cfloop query="myquery">
<cfchartdata item="#TotalSpace#" value="#FreeSpace#">
</cfloop>
</cfchartseries>
</cfchart>
</cfloop>
<!---<cfloop index="i" from = "1" to = #size#>
<cfchart>
<cfchartseries
type="pie"
query="myquery"
valueColumn="TotalSpace"
itemColumn="FreePace"/>
</cfchart>
</cfloop>--->
</body>
</html>
i have this code for chart display,but it showing in one chart i want to display this in indivisual chart

Instead of constructing a query and using it to display in your chartseries, use a chartseries with cfchartdata to add the appropriate data to the chart.

Related

Issue while populating JSON data to Jquery datatable in ColdFusion

I'm using coldFusion 2016 and I'm facing one issue when I'm putting json data to my Jquery datatable. The datatable is only showing processing message.
The JSON result seems to be error free but i don't know what is the issue.
Here is my datatable implementation
<head>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<link href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet">
<script type="text/javascript">
var table = '';
$(document).ready(function() {
table = $('#example').DataTable( {
"bProcessing": true,
"bServerSide": true,
"ajax": "uploadProcess.cfc?method=getDetails&partyId=100004",
"sPaginationType": "full_numbers",
"oLanguage": {
"sProcessing": "Wait please...",
"sZeroRecords": "No records found.",
"sInfo": "Users from _START_ to _END_ of _TOTAL_ total",
"sInfoEmpty": "Users from 0 to 0 of 0 total"
},
"aoColumns": [
{ "data": "ID" },
{ "data": "ORG_NAME" },
{ "data": "TYPE" },
{ "data": "PATH" },
{ "data": "URL" },
{ "data": "DELETE" }
]
});
});
</script>
</head>
<body>
<div id="dataDiv">
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Id</th>
<th>File Name</th>
<th>Type</th>
<th>Path</th>
<th>Preview</th>
<th>Delete</th>
</tr>
</thead>
</table>
</div>
</body>
Here is my uploadProcess.cfc
<cfcomponent>
<cffunction name="getDetails" access="remote" returnFormat="json">
<cfargument name="partyId" type="string" required="yes">
<cfparam name="arguments.iDisplayStart" default="0">
<cfparam name="arguments.iDisplayLength" default="10">
<cfparam name="arguments.iSortCol_0" default="UploadFileID">
<cfparam name="arguments.sSortDir_0" default="ASC">
<cfparam name="arguments.sEcho" default="1">
<cfstoredproc procedure="get_upload_file_details" datasource="standout">
<cfprocparam value="#partyId#" cfsqltype="CF_SQL_INT">
<cfprocparam value="#arguments.iDisplayStart#" cfsqltype="CF_SQL_INT">
<cfprocparam value="#arguments.iDisplayLength#" cfsqltype="CF_SQL_INT">
<cfprocparam value="#arguments.iSortCol_0#" cfsqltype="CF_SQL_VARCHAR">
<cfprocparam value="#arguments.sSortDir_0#" cfsqltype="CF_SQL_VARCHAR">
<cfprocresult name="getUploadDtls">
</cfstoredproc>
<cfset userArray = arrayNew(1)>
<cfloop query="getUploadDtls">
<cfif UserSessionID eq "">
<cfset deleteLink = "<span class='delete-link link'>Delete</span>" />
<cfelse>
<cfset deleteLink = "">
</cfif>
<cfset userStruct = {}>
<cfset userStruct.ID = UploadFileID>
<cfset userStruct.ORG_NAME = OriginalFileName>
<cfset userStruct.GEN_NAME = SystemFileName>
<cfset userStruct.TYPE = DocumentName>
<cfset userStruct.PATH = FilePath>
<cfset userStruct.URL = "<a href='renderpdf.cfm?path=#FilePath#&name=#OriginalFileName#' target='_blank'>Preview</a>">
<cfset userStruct.DELETE = deleteLink>
<cfset arrayAppend(userArray, userStruct) >
</cfloop>
<cfif getUploadDtls.RecordCount GT 0>
<cfset firstRow = queryGetRow(getUploadDtls,1)>
<cfset record_count = firstRow.record_count>
<cfelse>
<cfset record_count = 0>
</cfif>
<cfset returnStruct = {}>
<cfset returnStruct['iTotalRecords'] = record_count>
<cfset returnStruct['iTotalDisplayRecords'] = record_count>
<cfset returnStruct['sEcho'] = arguments.sEcho>
<cfset returnStruct['aaData'] = userArray>
<cfset resultsJSON = SerializeJSON(returnStruct)>
<cfreturn resultsJSON>
</cffunction>
</cfcomponent>
The Json result returning from my cffunction is given below.
{""aaData"":[{""GEN_NAME"":""sample_489.pdf"",""PATH"":""C://Standout/web_uploads/100004/Medical Reports/sample_489.pdf"",""DELETE"":"""",""ORG_NAME"":""sample.pdf"",""ID"":77,""TYPE"":""Medical Report"",""URL"":""<a href='renderpdf.cfm?path=C://Standout/web_uploads/100004/Medical Reports/sample_489.pdf&name=sample.pdf' target='_blank'>Preview</a>""}],""iTotalDisplayRecords"":1,""iTotalRecords"":1,""sEcho"":1}"
I can't figure out what is the issue can someone help?
First of I would remove those curly braces you use wrapping your structs.
SerializeJson() already works pretty well if you just pass in your structs.
It seems like your JSON is not valid which is probably causing the error, or your datatable isn't configured properly.
Honestly I'd recommend just filling your table with a cfloop.
<cfloop query="myQuery">
<tr>
<td>
#myQuery.someData#
</td>
...
</tr>
</cfloop>
If you load your data on page load this solution might work just as well.
The datatable API can be hit or miss sometimes imo.

Losing variable. Element is undefined in VARIABLES

We are getting this error in both ColdFusion 9 and ColdFusion 11 servers in production. I originally thought is related to ColdFusion 9 and JavaHeap space or not enough memory. We moved this process to run on a brand new server (ColdFusion 11) where nothing else is running and has a lot of memory and we still get the error. Here is some of the code for this cfm page:
<cfset variables.email_count = 0>
<!--- email notifications --->
<cfoutput query="getOrdersForNotification" group="order_id">
<cfset variables.inv = "">
<cfset variables.usePdf = false>
<cfif isDefined("application.feature_list_using_pdf_attachment")
and listFindNoCase(application.feature_list_using_pdf_attachment, "injection scheduler", ",")
>
<cfset variables.usePdf = true>
</cfif>
<cfthread name="InjectionSchdEmail#dateFormat(now(), 'mmdd')#_#timeFormat(now(), 'HHmmss')#_#getOrdersForNotification.order_id#"
threadOrderId="#getOrdersForNotification.order_id#"
threadMemberId="#getOrdersForNotification.member_id#"
threadNotificationEmail="#getOrdersForNotification.notification_email#"
threadDateReq="#getOrdersForNotification.date_req#"
threadStoreCode="#getOrdersForNotification.store_code#"
threadStoreName="#getOrdersForNotification.store_name#"
threadToGoLabel="#application.togo_label#"
threadOrderTotal="#getOrdersForNotification.order_total#"
threadDelTimeValueFront="#getOrdersForNotification.del_time_value_front#"
threadSubject="#variables.subjectAndBodyTemplates.subject#"
threadBody="#variables.subjectAndBodyTemplates.body#"
threadFromEmail="#variables.fromEmail#"
threadLocalNow="#variables.localNow#"
threadLocalNowInt="#variables.localNowInt#"
threadDs="#ds#"
threadUsePdf="#variables.usePdf#"
>
<cftry>
<cfset url.order_id = threadOrderId>
<cfset url.member_id = threadMemberId>
<cfsavecontent variable="variables.inv">
<cfinclude template="invoicedeska.cfm">
</cfsavecontent>
<cfset variables.order_day=dateFormat(application.UdfService.toSlashDate(threadDateReq), 'mmm dd')>
<cfset local.subject = threadSubject>
<cfset local.subject = ReplaceNoCase(local.subject, "[Store Code]", threadStoreCode, "all")>
<cfset local.subject = ReplaceNoCase(local.subject, "[Takeout Label]", threadToGoLabel, "all")>
<cfset local.subject = ReplaceNoCase(local.subject, "[Order ID]", threadOrderId, "all")>
<cfset local.subject = ReplaceNoCase(local.subject, "[Order Total]", NumberFormat(threadOrderTotal,"9,999.99"), "all")>
<cfset local.subject = ReplaceNoCase(local.subject, "[Required Time]", threadDelTimeValueFront, "all")>
<cfset local.subject = ReplaceNoCase(local.subject, "[Required Date]", variables.order_day, "all")>
<cfset local.body = threadBody>
<cfset local.body = ReplaceNoCase(local.body, "[Store Code]", threadStoreCode, "all")>
<cfset local.body = ReplaceNoCase(local.body, "[Store Name]", threadStoreName, "all")>
<cfset local.body = ReplaceNoCase(local.body, "[Order ID]", threadOrderId, "all")>
<cfset local.body = ReplaceNoCase(local.body, "[Order Total]", NumberFormat(threadOrderTotal,"9,999.99"), "all")>
<cfset local.body = ReplaceNoCase(local.body, "[Required Time]", threadDelTimeValueFront, "all")>
<cfset local.body = ReplaceNoCase(local.body, "[Required Date]", variables.order_day, "all")>
<cfset local.body = "<span style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: ##000000'>#application.UdfService.multiLiner(local.body)#</span>">
<cfif threadUsePdf>
<!--- PDF version --->
<cfdocument
format="PDF"
name="variables.attachment"
localURL="#application.pdf_localURL#"
orientation="#application.pdf_orientation#"
marginleft="#application.pdf_marginleft#"
marginright="#application.pdf_marginright#"
margintop="#application.pdf_margintop#"
marginbottom="#application.pdf_marginbottom#"
unit="#application.pdf_unit#"
scale="#application.pdf_scale#"
>
#variables.inv#
</cfdocument>
<cfelse>
<!--- HTML version --->
<cfset variables.attachment = variables.inv>
</cfif>
<cfmail to="#threadNotificationEmail#" from="#threadFromEmail#" subject="#local.subject#" type="html">
#local.body#
<cfif isDefined("variables.attachment") and threadUsePdf eq false>
<cfmailparam
file="invoice_#threadOrderId#_#threadLocalNowInt#.html"
type="application/html"
content="#variables.attachment#"
/>
<cfelseif isDefined("variables.attachment") and threadUsePdf>
<cfmailparam
file="invoice_#threadOrderId#_#threadLocalNowInt#.pdf"
type="application/pdf"
content="#variables.attachment#"
/>
</cfif>
</cfmail>
<cfset invoice_emailed = application.MessageService.setEmailedInvoice(orderId = threadOrderId, localNow = threadLocalNow, emailAddress = threadNotificationEmail, datasource = threadDs)>
<cfcatch type="any">
<cfset variables.attachment = "">
<cfmail from="erroralerts#monkeymediasoftware.com" to="erroralerts#monkeymediasoftware.com" type="html" subject="POS injection notification email faliure">
<cfif isDefined("cgi.server_name")>
Server: <b>#cgi.server_name#</b>
</cfif>
<cfdump var="#cfcatch#" label="cfcatch"><br />
<cfdump var="#threadOrderId#" label="threadOrderId"><br />
<cfdump var="#threadMemberId#" label="threadMemberId"><br />
<cfdump var="#threadNotificationEmail#" label="threadNotificationEmail"><br />
<cfdump var="#threadDateReq#" label="threadDateReq"><br />
<cfdump var="#threadStoreCode#" label="threadStoreCode"><br />
<cfdump var="#threadStoreName#" label="threadStoreName"><br />
<cfdump var="#threadToGoLabel#" label="threadToGoLabel"><br />
<cfdump var="#threadOrderTotal#" label="threadOrderTotal"><br />
<cfdump var="#threadDelTimeValueFront#" label="threadDelTimeValueFront"><br />
<cfdump var="#local.subject#" label="local.subject"><br />
<cfdump var="#local.body#" label="local.body"><br />
<cfdump var="#threadFromEmail#" label="threadFromEmail"><br />
<cfdump var="#threadLocalNow#" label="threadLocalNow"><br />
<cfdump var="#threadLocalNowInt#" label="threadLocalNowInt"><br />
<cfdump var="#threadDs#" label="threadDs"><br />
<cfdump var="#threadUsePdf#" label="threadUsePdf"><br />
<cfdump var="#variables.inv#" label="variables.inv"><br />
</cfmail>
<cfrethrow />
</cfcatch>
</cftry>
</cfthread>
<cfset variables.email_count = variables.email_count + 1>
</cfoutput>
<p></p><cfoutput>#variables.email_count# emails sent # #local_now()#</cfoutput>
Error:
Element EMAIL_COUNT is undefined in VARIABLES.
The error occurred on line

Error with multiple PDF Generation in CF

I'm getting an error when producing a multi-page PDF.
The pages attribute is not specified for the MERGE action in the cfpdf tag.
The line that is causing the issue is: <cfpdf action="merge" source="#ArrayToList(variables.pdfList)#" destination="promega.pdf" overwrite="yes" />
I tried looking in Adobe's documentation bug cannot find an attribute pages for the merge action. Thoughts?
<!--- Append PDF to list for merge printing later --->
<cfset ArrayAppend(variables.pdfList, "#expandPath('.')#\general.pdf") />
<cfset variables.userAgenda = GetAttendeeSchedule(
variables.event_key,
variables.badgeNum
) />
<!--- Field CFID is the id of the agenda item; use this for certificate selection --->
<cfif variables.userAgenda.recordcount>
<cfloop query="variables.userAgenda">
<cfset variables.title = Trim(variables.userAgenda.CUSTOMFIELDNAMEONFORM) />
<cfpdfform source="#expandPath('.')#\promega_certificate.pdf" destination="#cfid#.pdf" action="populate">
<cfset variables.startdate = replace(CUSTOMFIELDSTARTDATE, "T", " ") />
<cfpdfformparam name="WORKSHOP" value="#variables.title#">
<cfpdfformparam name="NAME" value="#variables.badgeInfo.FirstName# #variables.badgeInfo.LastName#">
<cfpdfformparam name="STARTDATE" value="#DateFormat(variables.startdate, "medium" )#">
</cfpdfform>
<!--- Append PDF to list for merge printing later --->
<cfset ArrayAppend(variables.pdfList, "#expandPath('.')#\#cfid#.pdf") />
</cfloop>
</cfif>
<cfif ArrayLen(variables.pdfList)>
<cfpdf action="merge" source="#ArrayToList(variables.pdfList)#" destination="promega.pdf" overwrite="yes" />
<!--- Delete individual files --->
<cfloop list="#ArrayToList(variables.pdfList)#" index='i'>
<cffile action="delete" file="#i#" />
</cfloop>
<cftry>
<cffile action="delete" file="#expandPath('.')#\general.pdf" />
<cfcatch></cfcatch>
</cftry>
<cfheader name="Content-Disposition" value="attachment;filename=promega.pdf">
<cfcontent type="application/octet-stream" file="#expandPath('.')#\promega.pdf" deletefile="Yes">
<cflocation url="index.cfm" addtoken="false" />
</cfif>
This happens when source is a single file rather than a comma separated list of files. I'm guessing that if it's a single file is is expecting to extract some pages rather than add.
I tried the following on my coldfusion 9 machine and it worked just fine:
<cfset strPath = GetDirectoryFromPath(GetCurrentTemplatePath()) />
<Cfset pdflist = arrayNew(1)>
<Cfset pdflist[1] = "#strPath#page1.pdf">
<Cfset pdflist[2] = "#strPath#page2.pdf">
<cfpdf action="merge" source="#ArrayToList(pdflist)#" destination="#strPath#merged.pdf" overwrite="yes" />
You could try to merge the pages like this and check whether you still get an error:
<cfset strPath = GetDirectoryFromPath(GetCurrentTemplatePath()) />
<Cfset pdflist = arrayNew(1)>
<Cfset pdflist[1] = "#strPath#page1.pdf">
<Cfset pdflist[2] = "#strPath#page2.pdf">
<cfpdf action="merge" destination="#strPath#merged.pdf" overwrite="yes">
<Cfloop from=1 to="#arraylen(pdflist)#" index="x">
<cfpdfparam source="#pdfList[x]#">
</cfloop>
</cfpdf>

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>

Add Page Numbers to Paginated Data

I have implemented pagination to my data, but the problem is I only have the Next and Previous links, like so:
What I would like to do is add page numbers, with the page number I am on as normal text, and the other pages as links. So if I am on page 3 of 5, it would like look like this:
Here is what I have so far:
<cfset data = queryNew("id,name,age,active","integer,varchar,integer,bit")>
<cfloop index="x" from="1" to="50">
<cfset queryAddRow(data)>
<cfset querySetCell(data,"id",x)>
<cfset querySetCell(data,"name","User #x#")>
<cfset querySetCell(data,"age",randRange(20,90))>
<cfset querySetCell(data,"active",false)>
</cfloop>
<cfset perpage = 10>
<cfparam name="url.start" default="1">
<cfif not isNumeric(url.start) or url.start lt 1 or url.start gt data.recordCount or round(url.start) neq url.start>
<cfset url.start = 1>
</cfif>
<h2>Random People</h2>
<cfoutput query="data" startrow="#url.start#" maxrows="#perpage#">
#currentrow#) #name#<br />
</cfoutput>
<p align="right">
[
<cfif url.start gt 1>
<cfset link = cgi.script_name & "?start=" & (url.start - perpage)>
<cfoutput>Previous Page</cfoutput>
<cfelse>
Previous Page
</cfif>
/
<cfif (url.start + perpage - 1) lt data.recordCount>
<cfset link = cgi.script_name & "?start=" & (url.start + perpage)>
<cfoutput>Next Page</cfoutput>
<cfelse>
Next Page
</cfif>
]
</p>
There is a very good ColdFusion Open Source pagination project on RIAForge: http://paginationcfc.riaforge.org/. It covers everything you need and comes with a lot of predefined styles. At least you can analyze the code and customize it to meet your requirements.
This was a fun question. How about this to build your list of page links:
<cfset pageList = "">
<cfloop from="1" to="#ceiling(data.RecordCount/perpage)#" index="i">
<!--- Determine the start record for selected page --->
<cfset targetRecord = 1 + (perpage * (i - 1))>
<cfif ceiling(url.start/perpage) NEQ i>
<cfset link = cgi.script_name & "?start=" & targetRecord>
<cfset pageList = listAppend(pageList, "#i#", " ")>
<cfelse>
<cfset pageList = listAppend(pageList, i, " ")>
</cfif>
</cfloop>
Now you can just drop pageList into your navigation section like so:
<p align="right">
[
<cfif url.start gt 1>
<cfset link = cgi.script_name & "?start=" & (url.start - perpage)>
<cfoutput>Previous Page</cfoutput>
<cfelse>
Previous Page
</cfif>
/
#pageList#
/
<cfif (url.start + perpage - 1) lt data.recordCount>
<cfset link = cgi.script_name & "?start=" & (url.start + perpage)>
<cfoutput>Next Page</cfoutput>
<cfelse>
Next Page
</cfif>
]
</p>