Page Display name (how it will appear in the database)
Page Title (The Title line for the HTML Page)
Page file name (something like newpage.asp)
Menu Type (Pulls navigation code for left frame)
This is supposed to generate a new ASP File on the root directory that includes the title, display name, and menu. The problem is that this doesn't work. It makes the Database entry, but does not generate the ASP file.
The code for the Generated Page to contain is:
[codebox]<%
Option explicit
dim sTitle
dim sCurrentPage
dim objRS
dim sMenu
sCurrentPage = "default"
sTitle = "default"
sMenu = "all"
%>
<!-- #include file="./includes/functions.asp"-->
<!-- #include file="./includes/dbconn.asp"-->
<!-- #include file="./includes/header.asp"-->
<%'main content for this page goes here
set objRS = DBConn.execute("select * from page where pagename = '"&sCurrentPage&"';")
while not objRS.eof
Response.Write(objRS("PageContent"))
objRS.movenext
wend
objRS.close
set objRS = Nothing
DBConn.close
set DBConn = nothing
%>
<!-- #include file="./includes/footer.asp"-->[/codebox]
The Three Values :
sCurrentPage = "default"
sTitle = "default"
sMenu = "all"
are the three that are changed when the new page is generated.
The Page that Edits the document and asks for the variables is:
[codebox]
<%Option explicit%>
<%'Functions site only contains sMenu code for each option%>
<!-- #include file="../includes/functions.asp"-->
<%'Connects to the Access Database%>
<!--#include file="../includes/dbconnupone.asp"-->
<%
dim sTitle
dim sCurrentPage
dim sMenu
dim i
dim sNewEntryName
dim sNewEntryDesc
dim objRS
dim objRS2
dim sDelete
Sub ManipFiles(destinationfilename, PageTitle, PageMenu, PageName)
Dim fso, f2
Set fso = server.CreateObject("Scripting.FileSystemObject")
Set f2 = fso.GetFile(server.MapPath("..\autopages\leavemehere.asp"))
'Response.Write "Copying file to c:\temp <br>"
' Copy the file to \temp.
f2.Copy (server.MapPath("..\autopages\" & destinationfilename))
'now open the file that we just copied and edit it
set f2 = fso.OpenTextFile(server.MapPath("..\autopages\" & destinationFilename), 1)
dim pagecontents
pagecontents = f2.readall
f2.close()
'frist replace the title
pagecontents = replace(pagecontents, "sTitleGoesHere", PageTitle)
pagecontents = replace(pagecontents, "sCurrentPageGoesHere", PageName)
pagecontents = replace(pagecontents, "sMenuGoesHere", PageMenu)
set f2 = fso.OpenTextFile(server.MapPath("..\autopages\" & destinationFilename), 2)
f2.write(pagecontents)
f2.close
End Sub
sTitle = "Troop101.net Administration"
sCurrentPage = "admin"
sMenu = "admin"
%>
<!-- #include file="../includes/headerupone.asp"-->
<span class=black11>
Logged in as <%=session("auth")%>
<a href="./logout.asp">Logout</a> or
<a href="./admin.asp">Back to the Admin Menu</a></span>
<br><br><span class=black11>Use this page to add new pages to the database
<br><br>
<br>
<form action=addpage.asp method=post id=form3 name=form3>
<table>
<tr>
<td class=black11 colspan=2><b>Add a new page</b></td>
</tr>
<tr>
<td class=black11>Page Display Name:</td>
<td><input type=text size=30 maxlength=100 name=txtNewAlbum class=black11></td>
</tr>
<tr>
<td class=black11>Page Title:</td>
<td><input type=text size=30 maxlength=100 name=txtPageTitle class=black11></td>
</tr>
<tr>
<td class=black11>Page File Name:</td>
<td><input type=text size=30 maxlength=100 name=txtPageFile class=black11></td>
</tr>
<tr>
<td class=black11>Menu Type:</td>
<td>
<select class=black11 name=menutype>
<option value="default">None</option>
<option value="troop">Troop</option>
<option value="pack">Pack</option>
<option value="crew">Crew</option>
<option value="alumni">Alumni</option>
<option value="eagle">Eagle</option>
<option value="all">All</option>
</select>
</td>
</tr>
<tr>
<td colspan=2><input type=submit value="Add Page" id=submit3 name=submit3></td>
</tr>
</table>
</form>
<!-- #include file="../includes/footer.asp"-->
[/codebox]
The only other linked page: leavemehere.asp contains the same code as the first box, but with the values sCurrentPageGoesHere, sTitleGoesHere, and sMenuGoesHere in the three containters, exampled below:
[codebox]<%
Option explicit
dim sTitle
dim sCurrentPage
dim objRS
dim sMenu
sCurrentPage = "sCurrentPageGoesHere"
sTitle = "sTitleGoesHere"
sMenu = "sMenuGoesHere"
%>
<!-- #include file="./includes/functions.asp"-->
<!-- #include file="./includes/dbconn.asp"-->
<!-- #include file="./includes/header.asp"-->
<%'main content for this page goes here
set objRS = DBConn.execute("select * from page where pagename = '"&sCurrentPage&"';")
while not objRS.eof
Response.Write(objRS("PageContent"))
objRS.movenext
wend
objRS.close
set objRS = Nothing
DBConn.close
set DBConn = nothing
%>
<!-- #include file="./includes/footer.asp"-->[/codebox]
Any help or suggestions are greatly appreciated.
The Database Fields are:
PageNum (The Primary index)
PageName (Page name as it appears for editing, and how it is pulled to be displayed.)
PageContent (The Content of the page, blank when a page is created)
I look forward to reply's. Thanks,
-Matt McCracken
P.S. This code was written in early 2000. If you know of a better way, please let me know. I am willing to use Javascript or another language to get this done, as long as my pages can remain .asp, and the Session state auth=admin can be used to keep unwanted visitors from making pages. Thanks!
Edited by Immortalarena, 25 March 2009 - 04:49 PM.