============== ColdFusion TIPS PLUS ColdFusion 01 Volume 01 Issue 14 =============================================================== http://www.cftipsplus.com ============== Issue 00053 ============== I. Comments: II. ColdFusion in Context: Live Messaging By R. Martin Ladner martin.ladner@knology.net
III. Using DateDiff Function to calculate the Time Difference By Raj Iyer CEO IYERANIUM.COM iyerr@att.net
IV. Application.log file David Jackson Senior Application Developer, Sane Internet. mango123456@hotmail.com
============== I. Comments:
Starting my own company and the Online Journal has been quite an experience. We are still moving along we have a big name person writing an article. We will not mention his name at this time.
Since being diagnosted with diabeties I have lost 30lbs. I am very excited about providing the Online Journal. We will be giving you anything we can to help you.
I have become a fan of Diablo II and if you are send me an email and maybe we can play as a team. If enough people like diablo ii then I will start a list for us to talk about and meet as programmers. Maybe even create a guild of our own.
Keep Coding, Nathan Stanford President/CEO C.F. Concepts, Inc. www.cftipsplus.com
If you have suggestions for articles send them to us. If you would like to write for cftipsplus.com send us an email to:
admin@cftipsplus.com
IF YOU WANT TO BE AN AUTHOR SEND IN YOUR COLDFUSION TIPS.
Remember this is a great way to get your name know in the ColdFusion Community.
=============================================================== If you have any suggestions please email me at cftips@nsnd.com. ===============================================================
=============================================================== II. ColdFusion in Context: Live Messaging By R. Martin Ladner martin.ladner@knology.net =============================================================== When your site content changes, what happens to pages your users already have open? They usually don't change. Yet the ability to change such pages is the basis for interactive chat, broadcast alerts, and even workflow that doesn't require you to press a "send/receive" button for updates.
Here's a technique you can extend to do all of these things. It's expressed as a method of sending a broadcast message to all your logged-on users. Along the way, you'll make a page refresh itself repetitively and respond to changes in memory, let it use JavaScript to open a second page to display information from memory, and make a form post to itself and to memory.
Overview ==================================== There are three pages in this broadcast message example: the driver, the display, and a page to change the message. The driver runs continuously, refreshing itself frequently. When it notices a new message ID, it opens the display if it's not already open and transfers control long enough for the display page to read and display the new message from memory. The change page changes the message ID and message in memory. It does this by accepting a message from a master user and then by posting the message to itself and to memory.
Build the Driver ==================================== The driver page will set up the environment, alternate URL variables for color changes, open a window when changes occur, refresh itself with the new URL variable, and alternate colors based on the variable so the user will know it's still running. In practice, this page would be made small, kept off to the side. Using similar techniques with frames, it could even be made a small sub-frame that drives a large display frame. Set the Environment
==================================== This example assumes that application and session variables can be used. The master message and its ID are loaded into application memory; the current message ID is loaded into session memory.
<cfapplication name="msg" sessionmanagement="yes"> <cfparam name="session.msgID" default=0> <cfparam name="application.msgID" default=0> <cfparam name="application.msg" default="">
Alternate URL Variables for Color Changes ==================================== The user needs to feel secure that the driver hasn't stopped. One easy way to do this is to have the driver alternate states somehow. To tell the page to do something different, a URL variable's value is alternated through multiplication by minus one. The URL must be complete, so, change it to match where you'll try it out.
<cfif isDefined("url.p") and ("#url.p#" gt 0)> <cfset pulse=-1> <cfelse> <cfset pulse=1> </cfif> <cfset self="http://127.0.0.1/cftips/window/drive.cfm?p=#pulse#">
Open a Window when Changes Occur ==================================== If the master message ID in application memory is greater than the ID of the last message this session has displayed, or you're just starting out, then the driver needs to open the display window (or at least let it be updated). The JavaScript shown here does that.
This section of code does several things. The cfoutput tag's placement allows you to substitute ColdFusion variables for some of the hard-coded values here if desired. (It will be closed in a later section.) If conditions are right to open a new window, the JavaScript does that. The HTML comments hide the JavaScript from old browsers. This particular example won't work at all with a browser too old to recognize the "window.open" command, but it's good practice to hide the JavaScript with comments anyway.
With JavaScript, you can specify characteristics of a window as you open it. For example, you can indicate if it will have toolbars, if it will remember previous locations, have scrollbars, or be resizable. Further, you can specify its initial width and height. Notice that the "newWindow" name to receive this action is arbitrary. The display file is called "show.cfm". It's given the name "show" for the sake of completeness. The other controls are self- explanatory. However, note two things: They all reside within a single string, and there must not be any space between the width and height variables. You can put spaces after the other commas, but the combined expression of width and height cannot have any spaces. (Thanks to www.chalcedony.com for this insight.)
<cfoutput> <cfif (application.msgID gt session.msgID) or (session.msgID is 0)> <script language="JavaScript"> <!-- newWindow = window.open('show.cfm', 'show', 'toolbar=yes,location=yes,scrollbars=yes,resizable=yes,widt h=400,height=80') --> </script> </cfif>
Refresh this Page with a New URL Variable ==================================== This section refreshes the URL stored in the variable "self" every eight seconds. It's this page with a URL variable whose value alternates. It closes with a cfoutput tag opened earlier. The Meta tag must be enclosed in cfoutput tags to use a variable for the URL.
<meta http-equiv="refresh" content="8 URL=#self#"><br> </cfoutput>
Alternate Colors based on the URL Variable ==================================== This section just sets the background color based on the alternating URL variable.
<cfif pulse gt 0> <body bgcolor="99AAFF"> <cfelse> <body bgcolor="AAFF99"> </cfif> Working...<br> </body>
Build the Display ==================================== The driver gets the environment, gets the message, writes the new ID to session memory, and displays the message.
<cfapplication name="msg" sessionmanagement="yes">
<cfif isDefined("application.msg")> <cfset message="#application.msg#"> <cfelse> <cfset message=""> </cfif>
<cfif isDefined("application.msgID")> <cfset session.msgID=#application.msgID#> </cfif>
<cfoutput> ~#message#~<br> </cfoutput>
Build the Change Page ==================================== The change page gets the environment, posts previous use of the form, and uses the form to accept a new message. It only concerns itself with the master information in application memory and leaves it to the driver and display to handle their status in session memory. If a form variable is defined, the form has just been used, and this code posts the form information to application memory. The remainder of the code lets the master user enter a new broadcast message to all users.
<cfapplication name="msg" sessionmanagement="yes"> <cfparam name="application.msgID" default="0"> <cfparam name="application.msg" default="">
<cfif isDefined("form.msg")> <cfset application.msgID=#application.msgID#+1> <cfset application.msg="#form.msg#"> </cfif>
<cfform name="send" action="send.cfm" method="post"> <cfoutput>The current broadcast message is...<br> #application.msg#<br> </cfoutput> Enter the new broadcast message here.<br> <input type="text" name="msg" size="52" maxlength="50"> <input type="submit" name="anyname" value="Submit"> </cfform>
Assembly ==================================== Build the three files as shown, modifying URLs to match your platform. Then open the driver, but don't open the display directly. Open the change page (called "send.cfm" in this example) to update your broadcast message. When you send a new message, the driver will open the display automatically after a few seconds and will update it as changes occur.
Extension ==================================== Now that you know this is possible, extend the idea. Consider interactive chat as a method to help users needing help on your web site. Learn related techniques to put the driver and display in the same frameset for a more professional appearance. Make a database-driven list with links to content to simulate intra-office E-mail with out an E-mail server. Upgrade it to a task list to support workflow. Do more, so others can build on your work.
=Marty= martin.ladner@knology.net
=============================================================== III. Using DateDiff Function to calculate the Time Difference By Raj Iyer CEO IYERANIUM.COM iyerr@att.net =============================================================== A simple but a very effective solution to find the time difference between two time using the standard DATEDIFF function.
In the example below, a time variable qtime is created using CreateTime function.
And the time is compared with the current time using the Parameter "N" in the DateDiff function.
<cfset qtime = CreateTime(2, 5, 1)> <cfset timerdiff = ABS(DateDiff("N", Timeformat(now()),qtime))>
Very efficient code.
Raj Iyer
=============================================================== IV. Application.log file David Jackson Senior Application Developer, Sane Internet. mango123456@hotmail.com =============================================================== Check out and resolve all errors in your application.log file. All run time programming related errors (SQL statements, unresolved parameters, etc.) are stored in the application.log. Here you can see a copy of all errors experienced by your users, and is by the far the best way to catch bugs and other errors. Errors caused by ColdFusion coding (especially database-related errors) can cause ColdFusion to become unstable.
The application.log file is accessible through the Log Files section of the ColdFusion Administrator or via the filesystem in the log subdirectory of the ColdFusion program directory (default is /opt/coldfusion in Unix and c:\cfusion in Windows 95/98/NT).
David Jackson
_____________________________________________________________ Get email for your site ---> http://www.everyone.net ==============
============== Publisher and Creator: Nathan Stanford, admin@cftipsplus.com C.F. Concepts, Inc.
Web Developers: Dain Anderson, dain_anderson@yahoo.com Hal Helms, hal.helms@TeamAllaire.com Ian Smith, imsmith@swirve.com. Kevin Schmidt, schmidt@pwb.com Scott Knaub, scott@web-mgt.com Marty Ladner, martin.ladner@knology.net Eric Wilkison ericw@winterlink.net
============== Macromedia and ColdFusion are U.S. registered trademarks.
============== Copyright (c) 2000 - 2001 C.F. Concepts, Inc. CFTIPSPLUS.COM and NSND.COM Permission is granted to circulate this publication via MANUAL forwarding by email to friends provided that the text is forwarded in its entirety and no fee is charged. ===============================================================
============== To unsubscribe: unsubscribe-cftips@nsnd.com
To subscribe: subscribe-cftips@nsnd.com ==============
==^================================================================ EASY UNSUBSCRIBE click here: http://topica.com/u/?aVxjC7.aVG5kO Or send an email To: cftips-unsubscribe@topica.com This email was sent to: cftipsplus@tallylist.com
T O P I C A -- Learn More. Surf Less. Newsletters, Tips and Discussions on Topics You Choose. http://www.topica.com/partner/tag01 ==^================================================================