<%
'***********************************************************************
'** Copyright (C) 2001 - 2004 Max Yuan All Rights Reserved
'**
'** By using this program, you are agreeing to the terms of the
'** GNU General Public License.
'**
'** 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 MaxWebPortal must remain intact
'** in the scripts and in the outputted HTML.
'** The "powered by" text/logo with a link back to 
'** http://www.maxwebportal.com in the footer of the pages MUST
'** remain visible when the pages are viewed on the internet or intranet.
'**
'** Support can be obtained from support forums at:
'** http://www.maxwebportal.com
'**
'** Email: maxwebportal@hotmail.com
'** ICQ: 148111300
'***********************************************************************
'** This Page Contains source code of Snitz Forums 2000
'***********************************************************************
'#################################################################################
'## Copyright (C) 2000  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
'#################################################################################
ResponseCode = Request.QueryString("RC")
if ResponseCode <> "" then 'No parameter
	blnSetup = "Y"
else
	strCookieURL = Left(Request.ServerVariables("Path_Info"), InstrRev(Request.ServerVariables("Path_Info"), "/"))
	Application(strCookieURL & "ConfigLoaded")= ""
end if
%>
<!--#INCLUDE FILE="config.asp" -->
<%
Response.Buffer = True
If Session(strCookieURL & "Approval") = "256697926329" then
%>
<html>
<head>
<title>MaxWebPortal Setup Page</title>
<meta name="copyright" content="Portal code is Copyright (C)2001 - 2004 Max Yuan All Rights Reserved">
<meta name="copyright" content="Forum code is Copyright (C)2000 Michael Anderson and Pierre Gorissen">
<Style><!--
a:link    {color:<% =strLinkColor %>;text-decoration:<% =strLinkTextDecoration %>}
a:visited {color:<% =strVisitedLinkColor %>;text-decoration:<% =strVisitedTextDecoration %>}
a:hover   {color:<% =strHoverFontColor %>;text-decoration:<% =strHoverTextDecoration %>}
--></style>
</head>

<body bgColor="white" text="midnightblue" link="darkblue" aLink="red" vLink="red" onLoad="window.focus()">
<%
if ResponseCode = "" then 'No parameter

	on error resume next
	
	set my_Conn = Server.CreateObject("ADODB.Connection")
	my_Conn.Open strConnString	
	
	for counter = 0 to my_conn.Errors.Count -1
		ConnErrorNumber = my_conn.Errors(counter).Number
		if ConnErrorNumber <> 0 then 
			my_conn.Errors.Clear 
			Response.Redirect "admin_site_setup.asp?RC=1&EC=" & ConnErrorNumber
		end if
	next
	
	my_Conn.Errors.Clear

	strSql = "SELECT CAT_ID, FORUM_ID, F_STATUS, F_MAIL, F_SUBJECT, F_URL, F_DESCRIPTION, F_TOPICS, F_COUNT, "
	strSql = strSql & "F_LAST_POST, F_PASSWORD_NEW, F_PRIVATEFORUMS, F_TYPE, F_IP, F_LAST_POST_AUTHOR "
	strSql = strSql &  " FROM " & strTablePrefix & "FORUM"
	
	my_Conn.Execute strSql
	
	Call CheckSqlError()
	
	my_Conn.Errors.Clear
	
	strSql = "SELECT CAT_ID, FORUM_ID, TOPIC_ID, T_STATUS, T_MAIL, T_SUBJECT, T_MESSAGE, T_AUTHOR, T_REPLIES, "
	strSql = strSql & "T_VIEW_COUNT, T_LAST_POST, T_DATE, T_LAST_POSTER, T_IP, T_LAST_POST_AUTHOR "
	strSql = strSql & " FROM " & strTablePrefix & "TOPICS"

	my_Conn.Execute strSql

	Call CheckSqlError()
	
	my_Conn.Errors.Clear
	
	strSql = "SELECT MEMBER_ID, M_STATUS, M_NAME, M_USERNAME, M_PASSWORD, M_EMAIL, M_COUNTRY, M_HOMEPAGE, "
	strSql = strSql & "M_SIG, M_DEFAULT_VIEW, M_LEVEL, M_AIM, M_YAHOO, M_ICQ, M_POSTS, M_DATE, "
	strSql = strSql & "M_LASTHEREDATE, M_LASTPOSTDATE, M_TITLE, M_SUBSCRIPTION, M_HIDE_EMAIL, "
	strSql = strSql & "M_RECEIVE_EMAIL, M_LAST_IP, M_IP, M_FIRSTNAME, M_LASTNAME, M_OCCUPATION, "
	strSql = strSql & "M_SEX, M_AGE, M_HOBBIES, M_LNEWS, M_QUOTE, M_BIO, M_MARSTATUS, "
	strSql = strSql & "M_LINK1, M_LINK2, M_CITY, M_STATE, M_PHOTO_URL FROM " & strMemberTablePrefix & "MEMBERS"
	strSql = strSql & " WHERE MEMBER_ID = 1;"

	my_Conn.Execute strSql

	Call CheckSqlError()
	
	my_Conn.Errors.Clear

	on error goto 0

%>
<meta http-equiv="Refresh" content="5; URL=default.asp">
<table border="1" cellspacing="0" cellpadding="5" width="50%" height="50%" align="center">
	<tr>
		<td bgColor="#EAFFFF" align="center">
		<p>
		<font face="Verdana, Arial, Helvetica" size="3">
		<b>Congratulations!!</b><br><br>
		The portal setup has been completed succesfully.<br>Thanks for using MaxWebPortal!<br><br></font>
		<font face="Verdana, Arial, Helvetica" size="2">
		</font></p></td>
	</tr>
	<tr>
		<td align="center">
		<font face="Verdana, Arial, Helvetica" size="2">
		<a href="default.asp" target="_top">Continue >>></a>
		</font></td>
	</tr>
</table>	

<%
elseif ResponseCode = 1 then '## cannot open database

ErrorCode = Request.QueryString("EC")	
CustomCode = Request.QueryString("CC")
%>
<table border="1" cellspacing="0" cellpadding="5" width="50%" height="50%" align="center">
	<tr>
		<td bgColor=pink align="center">
		<font face="Verdana, Arial, Helvetica" size="4">There has been an error !!</font>
		<p>
		<font face="Verdana, Arial, Helvetica" size="2">
<%
if CustomCode = 1 then
%>
		The database could not be opened !!<br>
		Check your config.asp file and set the <br><b>strConnString</b> so it points to the database.<br>
		Also check if <b>strDBType</b> is set to the right databasetype.<br>
		<br>
<%
elseif CustomCode = 2 then
%>
		Couldn't read from one or more tables in the database.<br> Make sure none of the tables are exclusively locked by another user.<br><br>
<%
elseif CustomCode = 3 then 
%>
		Couldn't open the database.<br> Make sure you supplied a correct username and password.<br><br>
<%
else
%>
		The database could not be opened !!<br>
		<br>
<%

end if
		if ErrorCode <> "" then 
			Response.Write("<p>Code :  " & ErrorCode & "</p>")
		end if
%>
		</font></p></td>
	</tr>
	<tr>
		<td align="center">
		<font face="Verdana, Arial, Helvetica" size="2">
<% 
if Request.QueryString("RET") <> "" then 
%>
		<a href="<%=Request.QueryString("RET")%>" target="_top">Click here to return to the previous screen.</a>
<%
else
%>
		<a href="admin_site_setup.asp" target="_top">Click here to retry.</a>
<%
end if
%> 
		</font></td>
	</tr>
</table>
	
<%
elseif ResponseCode = 2 then '## cannot find all the fields in the database

strSender = Request.QueryString("MAIL")
ErrorCode = Request.QueryString("EC")
CustomCode = Request.QueryString("CC")

if ErrorCode = "-2147467259" then
	Response.Redirect "admin_site_setup.asp"
	Response.End
elseif ErrorCode = "-2147217865" then
	if strDBType = "access" then
		Response.Redirect "admin_site_setup.asp?RC=1&EC=" & server.URLEncode("The Access database has missing tables !!")
		Response.End
	else
		Session(strCookieURL & "Approval") = "256697926329"
%>
<table border="1" cellspacing="0" cellpadding="5" width="50%" height="50%" align="center">
	<tr>
		<td bgColor=pink align="center"><font face="Verdana, Arial, Helvetica" size="4">The database needs to be installed !!</font>
		<p>
		<font face="Verdana, Arial, Helvetica" size="2">
		You need to create all the tables in the database before you can start.<br>
		</font></p></td>
	</tr>
</table>
<%
	end if
else
%>
<table border="1" cellspacing="0" cellpadding="5" width="50%" height="50%" align="center">
	<tr>
		<td bgColor=pink align="center"><font face="Verdana, Arial, Helvetica" size="4">Database is damaged or corrupted!!</font>
		<p>
		<font face="Verdana, Arial, Helvetica" size="2">
		Your database is damaged or corrupted. Please download a new database file from <a href="http://www.maxwebportal.com">our website</a>.<br>
<%
	if MAIL <> "" then 
%>
		If you are not a Administrator at this site<br> please report this error here: <a href="mailto:<% =strSender %>"><% =strSender %></a>.<br><br>
<%
	end if 
	if ErrorCode <> "" then 
			Response.Write("<p>Code :  " & ErrorCode & "</p>" )
	end if
%>
		</font></p></td>
	</tr>
	<tr>
		<td align="center">
		<font face="Verdana, Arial, Helvetica" size="2">
		<a href="admin_site_setup.asp" target="_top">Click here to retry.</a>
		</font></td>
	</tr>
</table>	
<%
end if
else
%>
<html>

<head>
<title>MaxWebPortal Setup Page</title>
<meta name="copyright" content="Portal code is Copyright (C)2001 - 2004 Max Yuan All Rights Reserved">
<meta name="copyright" content="Forum code is Copyright (C)2000 Michael Anderson and Pierre Gorissen">
<Style><!--
a:link    {color:<% =strLinkColor %>;text-decoration:<% =strLinkTextDecoration %>}
a:visited {color:<% =strVisitedLinkColor %>;text-decoration:<% =strVisitedTextDecoration %>}
a:hover   {color:<% =strHoverFontColor %>;text-decoration:<% =strHoverTextDecoration %>}
--></style>
</head>

<body bgColor="white" text="midnightblue" link="darkblue" aLink=red vLink="red" onLoad="window.focus()">

<table border="1" cellspacing="0" cellpadding="5" width="50%" height="50%" align="center">
	<tr>
		<td bgColor=pink align="center"><font face="Verdana, Arial, Helvetica" size="4" >There has been an error !!</font>
		<font face="Verdana, Arial, Helvetica" size="2">
<%		Response.Write(Err.number & ", " & Err.description) %>
		</font></td>
	</tr>
	<tr>
		<td align="center">
		<font face="Verdana, Arial, Helvetica" size="2">
		<a href="admin_site_setup.asp" target="_top">Click here to retry.</a>
		</font></td>
	</tr>
</table>	
<%
End if
%>

</body>
</html>

<%
sub CheckSqlError()

dim ChkConnErrorNumber

	for counter = 0 to my_Conn.Errors.Count -1
		ChkConnErrorNumber = my_Conn.Errors(counter).Number
		if  ChkConnErrorNumber <> 0 or Err.number > 0 then  

			my_Conn.Errors.Clear 
			Err.Clear
			my_Conn.Close
			set my_Conn = nothing

			Response.Redirect "admin_site_setup.asp?RC=2&EC=" & ChkConnErrorNumber
		end if
	next
end sub

function UpdateErrorCheck()

dim intErrorNumber
dim counter

	intErrorNumber = 0
	for counter = 0 to my_Conn.Errors.Count -1
		intErrorNumber = my_Conn.Errors(counter).Number
		if intErrorNumber <> 0 then  
			select case intErrorNumber
				case -2147217900
					UpdateErrorCheck = 1
					counter = my_Conn.Errors.Count -1
				case -2147467259
					UpdateErrorCheck = 2
					counter = my_Conn.Errors.Count -1	
				case else
					UpdateErrorCheck = intErrorNumber
			end select
		end if
	next
end function

else
	Response.Redirect "admin_login.asp"
End IF
%>