Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Last Date Modified 1

Status
Not open for further replies.

klaforce

Programmer
Mar 25, 2005
124
US
What I am trying to do is create a footer on all my pages under my root folder that contains certain information, especially the last modified date of the page. I have got the code working to get the last modified date (using javascript). I put the javascript code (posted at end) in the OnRequestEnd.cfm file on the top root, and it works, just not the way I want it. Instead of giving the last date modified of the page loaded, it gives the last modified date of the OnRequestEnd.cfm file. If anyone has any help or suggestions I would appreciate it. The following is my OnRequestEnd.cfm

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<!---script 
  type="text/JavaScript" 
  language="JavaScript">
<!-- 
//
// format date as dd-mmm-yy
// example: 12-Jan-99
//
function date_ddmmmyy(date)
{
  var d = date.getDate();
  var m = date.getMonth() + 1;
  var y = date.getYear();

  // handle different year values 
  // returned by IE and NS in 
  // the year 2000.
  if(y >= 2000)
  {
    y -= 2000;
  }
  if(y >= 100)
  {
    y -= 100;
  }

  // could use splitString() here 
  // but the following method is 
  // more compatible
  var mmm = 
    ( 1==m)?'Jan':( 2==m)?'Feb':(3==m)?'Mar':
    ( 4==m)?'Apr':( 5==m)?'May':(6==m)?'Jun':
    ( 7==m)?'Jul':( 8==m)?'Aug':(9==m)?'Sep':
    (10==m)?'Oct':(11==m)?'Nov':'Dec';

  return "" +
    (d<10?"0"+d:d) + "-" +
    mmm + "-" +
    (y<10?"0"+y:y);
}


//
// get last modified date of the 
// current document.
//
function date_lastmodified()
{
  var lmd = document.lastModified;
  var s   = "Unknown";
  var d1;

  // check if we have a valid date
  // before proceeding
  if(0 != (d1=Date.parse(lmd)))
  {
    s = "" + date_ddmmmyy(new Date(d1));
  }

  return s;
}

//
// finally display the last modified date
// as DD-MMM-YY
//
document.write( 
  "<center>This page was updated on " + 
  date_lastmodified()  + "</center>");

// -->
</script--->
</body>


Keith


The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
 
huh, you're using javascript to get server information? what on earth for?

also, javascript in a .cfm page is still a javascript question. forum216

but why not use cfdirectory and use the server to get the servers data.


Beware of programmers who carry screwdrivers.
 
Maybe I am confused, let me know, but is getting the last modified date of the page server information? The date.lastModified is sent by the server, but is available to the client. Also, the javascript is working, I think the problem is CF related because I am trying to incorporate OnRequestEnd.cfm, which is loaded after the page request is finished. So they would request Employee.cfm, it would finish loading, and then OnRequestEnd.cfm should process. This occurs correctly, but the document.LastModified is the OnRequestEnd.cfm last modifed property. I did not think the javascript people would know about the OnRequestEnd.cfm and it's relation. So what I need is a way to get Employee.cfm lastModified property. Let me know if I am wrong and should still post in the javascript forum.


Keith


The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
 
is getting the last modified date of the page server information?
the file in question resides on the server, does it not? it's modified when a change is made to the file on the server, right? so that would make it server information. I don't know where document.lastmodified comes in or how it works. i wasn't even aware that information was sent to the client.
i'm not familure with document.LastModified. you could just tell the JS people it's an included file at the bottom of your page, same thing basicly.

i'd use cfdirectory and specify the file in the filter. that will eliminate any guess work with what file's being read. JS is iffy at best and i only use it myself in a controlled envrironment.

Beware of programmers who carry screwdrivers.
 
Thanks for your help, I'll see what the JS people say. Your right, normally I would just use cfdirectory, but I am trying to create a footer for the entire intranet site, which has a couple hundred pages, and I do not want to type the filename for everyone. Is there a ColdFusion way to get the filename and path?


Keith


The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
 
filter = "#listLast(cgi.PATH_TRANSLATED, '\')#" will give you the current file.

with the use of expandpath() and cgi.PATH_TRANSLATED you can get the current file despite the depth of the file in the folder structure.

Beware of programmers who carry screwdrivers.
 
Ah okay, that is exactly what I need. Thank you very much for your help.


Keith


The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
 
For those searching on Google, here is the final Solution. To create a footer for your cfm page with the last modified date create an OnRequestEnd.cfm file, and put it in the folder you want it to affect (like the Applicaiton.cfm file) and paste the following code.


Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>

<cfscript>
/**
 * Returns the last index (case insensitive) of an occurrence of a substring in a string from a specified starting position.
 * Big update by Shawn Seley (shawnse@aol.com) -
 * UDF was not accepting third arg for start pos 
 * and was returning results off by one.
 * 
 * @param Substr 	 Substring to look for. 
 * @param String 	 String to search. 
 * @param Spos 	 Starting position. 
 * @return Returns the last position where a match is found, or 0 if no match is found. 
 * @author Charles Naumer (cmn@v-works.com) 
 * @version 2, February 14, 2002 
 */
function RFindNoCase(substr,str) {
  var rsubstr  = reverse(substr);
  var rstr     = "";
  var i        = len(str);
  var rcnt     = 0;

  if(arrayLen(arguments) gt 2 and arguments[3] gt 0 and arguments[3] lte len(str)) i = len(str) - arguments[3] + 1;

  rstr = reverse(Right(str, i));
  rcnt = findNoCase(rsubstr, rstr);

  if(not rcnt) return 0;
  return len(str)-rcnt-len(substr)+2;
}
</cfscript>


<!---cfset filter = "#listLast(expandPath(cgi.PATH_TRANSLATED), '\')#"--->
<cfset filter = "#cgi.PATH_TRANSLATED#">
<cfset result = #RFindNoCase("\", filter)#>
<cfset dir = #RemoveChars(filter, result, len(filter) - result + 1)#>
<cfset filter = #RemoveChars(filter, 1, result)#>


<cfdirectory action="list" directory="#dir#" filter="#filter#" name="Doc">

<cfoutput query="Doc">#DateFormat(dateLastModified, "mm/dd/yyyy")#</cfoutput>
</body>
</html>


Keith


The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
 
That would work but you have a lot of hoop jumping going on there...

Code:
<cfset dir = expandPath("./")>
<cfset filter = listLast(cgi.path_translated, "\")>

<cfdirectory action="list" directory="#dir#" filter="#filter#" name="Doc">

<cfoutput>#DateFormat(doc.dateLastModified, "mm/dd/yyyy")#</cfoutput>

Beware of programmers who carry screwdrivers.
 
if you don't want to use expandPath you can even do this.

Code:
<cfset filter = listLast(cgi.path_translated, "\")>
<cfset dir = listDeleteAt(cgi.path_translated, listLen(cgi.path_translated, "\"), "\") & "\">

<cfdirectory action="list" directory="#dir#" filter="#filter#" name="Doc">

<cfoutput>#DateFormat(doc.dateLastModified, "mm/dd/yyyy")#</cfoutput>

the RFindNoCase udf and the way it is used is real round-about.

Beware of programmers who carry screwdrivers.
 
Yeah you could do that, if you wanted to do it the easy way... :) Thanks Simu, I tried something like that before, but could not figure out how to get the expandPath function to work in a couple of minutes, so I just moved onto to something I knew I could do quick (sick of working on it after a certain amount of time, I'm sure everyone has felt this way). Thank you for the tip though, it certainly cleaned up my code.


Keith


The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
 
I agree expandpath can be a headache at first.

Beware of programmers who carry screwdrivers.
 
This post is just to question why you would need to find last modified date of a coldfusion page "File"??? I save page content in a database and use a column called lastmodified to store that date / time...
 
Well, I don't really have any reason to save the page content in a database, so I can just put this one file in my top directory, and have what I need without setting up a database.


Keith


The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top