home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 1999 April / APC443.iso / features / grpware / coldfus / coldfusi.exe / data1.cab / Examples / publish / admin / createpage3.cfm < prev    next >
Encoding:
Text File  |  1998-10-08  |  4.8 KB  |  155 lines

  1. <CFSET Error = 0>
  2.  
  3. <!--- Check if the string contains any invalid characters --->
  4. <CFIF FindOneOf(':*?<>|"\ ', Path) NEQ 0>
  5.     <CFSET Error = 1>
  6.     <CFSET ErrorMessage = "The filename/path cannot contain any of the following characters:<BR>
  7. : * ? < > | " / (space)">
  8.  
  9. <!--- Check if the file has a .cfm extension --->
  10. <CFELSEIF Right(Form.Path, 4) NEQ ".cfm">
  11.     <CFSET Error = 1>
  12.     <CFSET ErrorMessage = "The file must have a .cfm extension!">
  13. </CFIF>
  14.  
  15. <!--- Separate directory from path --->
  16. <CFIF Path CONTAINS "/">
  17.     <CFSET Temp = Find("/", Reverse(Path))>
  18.     <CFSET Filename = Right(Path, Temp - 1)>
  19. <CFELSE>
  20.     <CFSET Filename = Path>
  21. </CFIF>
  22.  
  23. <!--- Check if the filename is long enough --->
  24. <CFIF Len(Filename) LTE 4 OR Left(Path, 2) IS "..">
  25.     <CFSET Error = 1>
  26.     <CFSET ErrorMessage = "The filename was invalid!">
  27. </CFIF>
  28.  
  29. <!--- Check if the file already exists --->
  30. <CFQUERY DATASOURCE="CFexamples" NAME="FindDupe">
  31. SELECT * FROM PubPages
  32. WHERE TemplatePath = '#Path#'
  33. </CFQUERY>
  34. <CFIF FindDupe.RecordCount GT 0>
  35.     <CFSET Error = 1>
  36.     <CFSET ErrorMessage = "The file already exists!">
  37. </CFIF>
  38.  
  39. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
  40.  
  41. <HTML>
  42. <HEAD>
  43.     <TITLE>Create Page</TITLE>
  44. <STYLE TYPE="text/css">
  45. <!-- A {text-decoration: none} -->
  46. </STYLE>
  47. </HEAD>
  48.  
  49. <BODY BGCOLOR="#660000" TEXT="#FFFFFF" LINK="#FFFF00" VLINK="#FFFF00">
  50.  
  51. <TABLE ALIGN="RIGHT" CELLPADDING="0" CELLSPACING="0">
  52. <TR>
  53.     <TD ALIGN="RIGHT">
  54.     <FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">
  55.         <A HREF="index.cfm">Administrator Home</A>
  56.     </FONT>
  57.     </TD>
  58. </TR>
  59. </TABLE>
  60.  
  61. <P><IMG SRC="images/createpage.gif" WIDTH=96 HEIGHT=23 BORDER=0 ALT="Create Page"></P>
  62.  
  63. <CFIF Error IS 1>
  64.     <P><FONT FACE="MS Sans Serif, Helvetica" SIZE="-1"><B>Error:</B> <CFOUTPUT>#ErrorMessage#</CFOUTPUT></FONT></P>
  65.  
  66.     <P><FONT FACE="MS Sans Serif, Helvetica" SIZE="-1">Please try again...</FONT></P>
  67.  
  68.     <FORM ACTION="createpage3.cfm" METHOD="POST">
  69.  
  70.     <CFOUTPUT><INPUT TYPE="HIDDEN" NAME="Template" VALUE="#Form.Template#"></CFOUTPUT>
  71.  
  72.     <P><FONT FACE="MS Sans Serif, Helvetica" SIZE="-2">Filename:</FONT><BR>
  73.     <CFOUTPUT><INPUT TYPE="TEXT" NAME="Path" VALUE="#Form.Path#"></CFOUTPUT></P>
  74.  
  75.     <P><INPUT TYPE="SUBMIT" VALUE="Continue"></P>
  76.  
  77.     </FORM>
  78.  
  79. <CFELSE>
  80.  
  81.     <CFQUERY DATASOURCE="cfexamples" NAME="query1">
  82.     SELECT * FROM PubPages
  83.     </CFQUERY>
  84.     
  85.     <CFFILE ACTION="READ" FILE="#ExpandPath('templates\' & Template & ".template")#" VARIABLE="FileData">
  86.  
  87.     <!--- Grab the whole chunk of attribute-value pairs, call it MetaData --->
  88.     <CFSET MetaDataStart = FindNoCase("---BEGIN PUBLISHING DATA---", FileData) + Len("---BEGIN PUBLISHING DATA---")>
  89.     <CFSET MetaDataEnd = FindNoCase("---END PUBLISHING DATA---", FileData)>
  90.     <CFSET MetaData = Trim(Mid(FileData, MetaDataStart, MetaDataEnd - MetaDataStart))>
  91.  
  92.     <!--- Now loop over each line of MetaData --->
  93.     <CFLOOP CONDITION="Trim(MetaData) NEQ ''">
  94.  
  95.         <!--- Grab just one line of info from MetaData.  If this
  96.             happens to be the last line in MetaData, just grab
  97.             all that's left. --->
  98.         <CFSET EOL = Find(Chr(10), MetaData)>
  99.         <CFIF EOL NEQ 0>
  100.             <CFSET CurrentLine = Trim(Left(MetaData, EOL))>
  101.         <CFELSE>
  102.             <CFSET CurrentLine = Trim(MetaData)>
  103.         </CFIF>
  104.         
  105.         <!--- If there's a "=" character in the current line, continue processing --->
  106.         <CFIF Find("=", CurrentLine) NEQ 0 AND Left(CurrentLine, 1) NEQ ":">
  107.  
  108.             <!--- Split the current line at the "="; everything to the left
  109.                 is the attribute name, everything to the right is the value --->
  110.             <CFSET MidPoint = Find("=", CurrentLine)>
  111.             <CFSET Attribute = Left(CurrentLine, MidPoint - 1)>
  112.             <CFSET Value = Right(CurrentLine, Len(CurrentLine) - MidPoint)>
  113.             <CFSET "#Attribute#" = Value>
  114.  
  115.            </CFIF>
  116.  
  117.         <CFIF Len(Trim(MetaData)) NEQ Len(CurrentLine)>
  118.             <CFSET MetaData = Trim(Right(MetaData, Len(MetaData) - Len(CurrentLine)))>
  119.         <CFELSE>
  120.             <CFSET MetaData = "">
  121.         </CFIF>
  122.  
  123.     </CFLOOP>
  124.     
  125.     <CFTRANSACTION>
  126.  
  127.         <CFQUERY DATASOURCE="CFexamples" NAME="GetTopPageID">
  128.         SELECT Max(PageID) AS MaxID FROM PubPages
  129.         </CFQUERY>
  130.     
  131.         <CFIF GetTopPageID.MaxID IS "">
  132.             <CFSET NewPageID = 1>
  133.         <CFELSE>
  134.             <CFSET NewPageID = GetTopPageID.MaxID + 1>
  135.         </CFIF>
  136.  
  137.         <CFQUERY DATASOURCE="CFexamples">
  138.         INSERT INTO PubPages (PageID, TemplatePath, MaxLocation)
  139.         VALUES (#NewPageID#, '#Path#', #Locations#)
  140.         </CFQUERY>
  141.  
  142.     </CFTRANSACTION>
  143.  
  144.     <CFSET Path = Replace(Path, "/", "\", "ALL")>
  145.     <CFSET DestPath = ExpandPath("..\" & Path)>
  146.     <CFFILE ACTION="WRITE" FILE="#DestPath#" OUTPUT="#Trim(Right(FileData, Len(FileData) - MetaDataEnd - 25))#">
  147.  
  148.     <P><FONT FACE="MS Sans Serif, Helvetica" SIZE="-1">Page created successfully! You can now schedule objects to appear on <CFOUTPUT>#Path#</CFOUTPUT>.</FONT></P>
  149.  
  150.     <P><FONT FACE="MS Sans Serif, Helvetica" SIZE="-1"><A HREF="index.cfm">Go back</A></FONT></P>
  151.  
  152. </CFIF>
  153.  
  154. </BODY>
  155. </HTML>