<% '################################################################################# '## Copyright (C) 2000-01 Michael Anderson and Pierre Gorissen '## '## This program is free software; you can redistribute it and/or '## modify it under the terms of the GNU General Public License '## as published by the Free Software Foundation; either version 2 '## of the License, or any later version. '## '## All copyright notices regarding Snitz Forums 2000 '## must remain intact in the scripts and in the outputted HTML '## The "powered by" text/logo with a link back to '## http://forum.snitz.com in the footer of the pages MUST '## remain visible when the pages are viewed on the internet or intranet. '## '## This program is distributed in the hope that it will be useful, '## but WITHOUT ANY WARRANTY; without even the implied warranty of '## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the '## GNU General Public License for more details. '## '## You should have received a copy of the GNU General Public License '## along with this program; if not, write to the Free Software '## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. '## '## Support can be obtained from support forums at: '## http://forum.snitz.com '## '## Correspondence and Marketing Questions can be sent to: '## reinhold@bigfoot.com '## '## or '## '## Snitz Communications '## C/O: Michael Anderson '## PO Box 200 '## Harpswell, ME 04079 '################################################################################# %> <% If Session(strCookieURL & "Approval") = "15916941253" Then %>

Snitz Forum Modifications

<% Dim strTableName Dim fieldArray (100) Dim idFieldName Dim tableExists Dim fieldExists Dim ErrorCount tableExists = -2147217900 tableNotExist = -2147217865 fieldExists = -2147217887 ErrorCount = 0 set my_Conn= Server.CreateObject("ADODB.Connection") my_Conn.Open strConnString on error resume next Set fso = CreateObject("Scripting.FileSystemObject") if err.number <> 0 then response.write "error " & err.number & "|" & err.description err.clear response.end end if set objFile = fso.Getfile(server.mappath(Request.ServerVariables("PATH_INFO"))) set objFolder = objFile.ParentFolder set objFolderContents = objFolder.Files if Request.Form("dbMod") = "" then Response.write "" &_ "" &_ "" &_ "" &_ "" &_ "" &_ "" &_ "
" &_ "

" &_ "" &_ "Database Setup....
" If strDBType = "" then Response.write "Your strDBType is not set, please edit your config.asp
" &_ "to reflect your database type
" Response.write "
Go Back to Forum
" Response.End end if Response.write "

" If strDBType = "sqlserver" then Response.write "" &_ "You are using SQL Server, please select the correct version
" &_ " SQL 7.x    " &_ " SQL 6.x
" End If on error resume next Response.write "" &_ "

Select the Mod from the list below, and press Update!
" &_ "A script will execute to perform the database upgrade.

" &_ "" &_ "
" &_ "Delete the dbs file when finished ?
" &_ "

" &_ "" &_ "Click here to go to the forum." &_ "
" &_ "
" Else response.write "" &_ "" &_ "" &_ "" &_ "" &_ "" &_ "" &_ "
" &_ "

" &_ "" sqlVer = Request.Form("sqltype") Set fs = CreateObject("Scripting.FileSystemObject") Set thisfile = fs.OpenTextFile(Request.Form("dbMod"), 1, False) ModName = thisfile.readline response.write ("") response.write ("

" & ModName & "

") '## Load Sections for processing do while not thisfile.AtEndOfStream sectionName = thisfile.readline Select case uCase(sectionName) case "[CREATE]" strTableName = uCase(thisfile.readline) idFieldName = uCase(thisfile.readline) tempField = thisfile.readline rec = 0 do while uCase(tempField) <> "[END]" fieldArray(rec) = tempField rec = rec+1 tempField = thisfile.readline loop CreateTables(rec) case "[ALTER]" strTableName = uCase(thisfile.readline) tempField = thisfile.readline rec = 0 do while uCase(tempField) <> "[END]" fieldArray(rec) = tempField rec = rec+1 tempField = thisfile.readline loop AlterTables(rec) case "[DELETE]" strTableName = uCase(thisfile.readline) tempField = thisfile.readline rec = 0 do while uCase(tempField) <> "[END]" fieldArray(rec) = tempField rec = rec+1 tempField = thisfile.readline loop DeleteValues(rec) case "[INSERT]" strTableName = uCase(thisfile.readline) tempField = thisfile.readline rec = 0 do while uCase(tempField) <> "[END]" fieldArray(rec) = tempField rec = rec+1 tempField = thisfile.readline loop InsertValues(rec) case "[UPDATE]" strTableName = uCase(thisfile.readline) tempField = thisfile.readline rec = 0 do while uCase(tempField) <> "[END]" fieldArray(rec) = tempField rec = rec+1 tempField = thisfile.readline loop UpdateValues(rec) case "[DROP]" strTableName = thisfile.readline tempField = thisfile.readline DropTable() end select loop response.write "" if request("delFile") = "1" then thisfile.close on error resume next fs.DeleteFile(Request.Form("dbMod")) if err.number = 0 then Response.write "The dbs file was succesfully deleted.
" else Response.write "Unable to remove dbs file
" & err.description & "
" end if end if if ErrorCount > 0 then Response.write "
If there were errors please post a question in the MOD Implementation Forum at
" Response.write "Snitz Forums" else Response.write "

Database setup finished

" end if Response.write "
" &_ "" &_ "" &_ "" &_ "

" &_ "" &_ "Click here to go to the forum." &_ "
" end if set fs=nothing set fso = nothing Sub CreateTables( numfields ) response.write "
" response.write "Creating table(s)...
" if len(strTableName) > 6 then if Instr(strTableName,"MEMBER") > 0 then TablePrefix = strMemberTablePrefix else TablePrefix = strTablePrefix end if else TablePrefix = strTablePrefix end if strSql = "CREATE TABLE " & TablePrefix & strTableName & "( " if idFieldName <> "" then select case strDBType case "access" if Instr(strConnString,"(*.mdb)") then strSql = strSql & idFieldName &" COUNTER CONSTRAINT PrimaryKey PRIMARY KEY " else strSql = strSql & idFieldName &" int IDENTITY (1, 1) NOT NULL " end if case "sqlserver" strSql = strSql & idFieldName &" int IDENTITY (1, 1) NOT NULL " case "mysql" strSql = strSql & idFieldName &" INT (11) DEFAULT '' NOT NULL auto_increment " end select end if for y = 0 to numfields -1 on error resume next tmpArray = split(fieldArray(y),"#") fName = uCase(tmpArray(0)) fType = lCase(tmpArray(1)) fNull = uCase(tmpArray(2)) fDefault = tmpArray(3) if idFieldName <> "" or y <> 0 then strSql = strSql & ", " end if select case strDBType case "access" fType = replace(fType,"varchar (","text (") case "sqlserver" select case sqlVer case 7 fType = replace(fType,"memo","ntext") fType = replace(fType,"varchar","nvarchar") fType = replace(fType,"date","datetime") case else fType = replace(fType,"memo","text") end select case "mysql" fType = replace(fType,"memo","text") fType = replace(fType,"#int","#int (11)") fType = replace(fType,"#smallint","#smallint (6)") end select if fNull <> "NULL" then fNull = "NOT NULL" strSql = strSql & fName & " " & fType & " " & fNull & " " if fdefault <> "" then strSql = strSql & "DEFAULT " & fDefault end if next if strDBType = "mysql" then strSql = strSql & ",KEY " & TablePrefix & strTableName & "_" & idFieldName & "(" & idFieldName & "))" else strSql = strSql & ")" end if response.write strSql & "
" my_Conn.Execute strSql if err.number <> 0 and err.number <> 13 and err.number <> tableExists then response.write strSql & "
" response.write("" & err.number & " | " & err.description & "
") ErrorCount = ErrorCount + 1 else if err.number = tableExists then response.write("Table already exists
") else response.write("Table created succesfully
") end if end if response.write("
") end Sub Sub AlterTables(numfields) Response.write "
" for y = 0 to numfields -1 on error resume next if Instr(strTableName,"MEMBER",1) > 0 then TablePrefix = strMemberTablePrefix else TablePrefix = strTablePrefix end if strSql = "ALTER TABLE " & TablePrefix & strTableName tmpArray = split(fieldArray(y),"#") fAction = uCase(tmpArray(0)) fName = uCase(tmpArray(1)) fType = lCase(tmpArray(2)) fNull = uCase(tmpArray(3)) fDefault = tmpArray(4) select case fAction case "ADD" strSQL = strSQL & " ADD " if strDBType = "access" then strSql = strSql & "COLUMN " case "DROP" strSQL = strSQL & " DROP COLUMN " case "ALTER" strSQL = strSQL & " ALTER COLUMN " case else end select if fAction = "ADD" or fAction = "ALTER" then select case strDBType case "access" fType = replace(fType,"varchar","text") case "sqlserver" select case sqlVer case 7 fType = replace(fType,"memo","ntext") fType = replace(fType,"varchar","nvarchar") fType = replace(fType,"date","datetime") case else fType = replace(fType,"memo","text") end select case "mysql" fType = replace(fType,"#int","#int (11)") fType = replace(fType,"#smallint","#smallint (6)") end select if fNull <> "NULL" then fNull = "NOT NULL" strSql = strSQL & fName & " " & fType & " " & fNULL & " " if fDefault <> "" then strSQL = strSQL & "DEFAULT " & fDefault response.write "Adding Column " & fName & "...
" else strSql = strSQL & fName response.write "Dropping Column...
" end if my_Conn.Execute strSql if err.number <> 0 and err.number <> 13 and err.number <> fieldExists then response.write strSQL & "
" response.write("" & err.number & " | " & err.description & "
") ErrorCount = ErrorCount + 1 resultString = "" else if fAction = "DROP" then response.write("Column " & LCase(fAction) & "ped successfully
") resultString = "Table(s) updated
" else if err.number = fieldExists then response.write("Column already exists
") resultString = "" else response.write("Column " & LCase(fAction) & "ed successfully
") end if end if if fDefault <> "" and err.number <> fieldExists then strSQL = "UPDATE " & TablePrefix & strTableName & " SET " & fName & "=" & fDefault my_Conn.Execute strSql response.write "Populating Current Records with new Default value
" resultString = "Table(s) updated
" end if end if if fieldArray(y) = "" then y = numfields next response.write(resultString) response.write("
") end Sub Sub InsertValues(numfields) Response.write "
" on error resume next response.write ("Adding new records..
") for y = 0 to numfields-1 if Instr(strTableName,"MEMBER",1) > 0 then strSql = "INSERT INTO " & strMemberTablePrefix & strTableName & " " else strSql = "INSERT INTO " & strTablePrefix & strTableName & " " end if tmpArray = split(fieldArray(y),"#") fNames = tmpArray(0) fValues = tmpArray(1) strSql = strSql & tmpArray(0) & " VALUES " & tmpArray(1) my_Conn.Execute strSql next if err.number <> 0 and err.number <> 13 then response.write strSql & "
" response.write("" & err.number & " | " & err.description & "
") ErrorCount = ErrorCount + 1 else response.write("
Value(s) updated succesfully") end if response.write("
") end Sub Sub UpdateValues(numfields) on error resume next Response.write "
" response.write ("Updating Forum Values..
") for y = 0 to numfields-1 if Instr(strTableName,"MEMBER",1) > 0 then strSql = "UPDATE " & strMemberTablePrefix & strTableName & " SET" else strSql = "UPDATE " & strTablePrefix & strTableName & " SET" end if tmpArray = split(fieldArray(y),"#") fName = tmpArray(0) fValue = tmpArray(1) fwhere = tmpArray(2) strSql = strSql & " " & fName & " = " & fvalue & " WHERE " & fWhere my_Conn.Execute strSql next if err.number <> 0 then response.write("" & err.number & " | " & err.description & "
") ErrorCount = ErrorCount + 1 response.write strSql & "
" else response.write("
Value(s) updated succesfully") end if response.write("
") end Sub Sub DeleteValues(numfields) on error resume next response.write "
" response.write ("Updating Forum Values..
") if Instr(strTableName,"MEMBER",1) > 0 then strSql = "DELETE FROM " & strMemberTablePrefix & strTableName & " WHERE " else strSql = "DELETE FROM " & strTablePrefix & strTableName & " WHERE " end if tmpArray = fieldArray(0) strSql = strSql & tmpArray my_Conn.Execute strSql if err.number <> 0 then response.write strSql & "
" response.write("" & err.number & " | " & err.description & "
") ErrorCount = ErrorCount + 1 else response.write("
Value(s) updated succesfully") end if response.write("
") end Sub Sub DropTable() on error resume next response.write "
" response.write ("Dropping Table..
") if Instr(strTableName,"MEMBER",1) > 0 then strSql = "DROP TABLE " & strMemberTablePrefix & strTableName else strSql = "DROP TABLE " & strTablePrefix & strTableName end if my_Conn.Execute strSql if err.number <> 0 and err.number <> 13 and err.number <> tableNotExist then response.write strSql & "
" response.write("" & err.number & " | " & err.description & "
") ErrorCount = ErrorCount + 1 else if err.number = tableNotExist then response.write("
Table does not exist") else response.write("
Table dropped succesfully") end if end if response.write("
") end Sub my_Conn.Close set my_Conn = nothing %><% Else scriptname = split(request.servervariables("SCRIPT_NAME"),"/") Response.Redirect "admin_login.asp?target=scriptname" End IF %>