<% Option Explicit %>
<!--#include file="common.asp" -->
<%
'Dimension variables
Dim rsAddURL				'Recordset object
Dim strInputTitle 			'Holds the URL Title
Dim strInputURL 			'Holds the URL
Dim strInputAREA 			'Holds the AREA
Dim strInputEmail 			'Holds the Email
Dim strInputMan 			'Holds the Man
Dim strInputPhone 			'Holds the Phone
Dim strInputcity 			'Holds the city
Dim strInputCode 			'Holds the Code
Dim strInputAddress 		'Holds the Address
Dim strInputSort 			'Holds the Sort
Dim strInputDescription 		'Holds the description of the URL
Dim strInputKeywords 			'Holds the keywords for the URL
Dim saryDescriptionWord 		'Array to hold each word in the description enetred by the user
Dim intCheckWordLengthLoopCounter	'Loop counter
Dim intWordLength			'Holds the length of the word to be checked
Dim blnWordLenthOK			'Boolean set to False if any words in the description are above 100 characters
Dim intLongestWordLength 		'Holds the number of characters in the longest word entered in the description
Dim blnNewURL				'set to false if the URL is already in the database

'Initialse variables
blnWordLenthOK = True
blnNewURL = False

'Read in user deatils from the add URL form
strInputTitle = Request.Form("title")
strInputURL = Request.Form("url")
strInputAREA = Request.Form("area")
strInputEmail = Request.Form("Email")
strInputMan = Request.Form("Man")
strInputPhone = Request.Form("Phone")
strInputcity = Request.Form("city")
strInputCode = Request.Form("Code")
strInputAddress = Request.Form("Address")
strInputSort = Request.Form("Sort")
strInputDescription = Request.Form("description")
strInputKeywords = Request.Form("keywords")


'Where someones has pressed return in there description replace this with a space 
'as otherwise the last word and first word on the line are seen as one word and may go over the 100 chraracter limit
strInputDescription = Replace(strInputDescription, vbCrLf, " ")


'Split-up each word in the description from the user to check that no word entered is over 100 characters
saryDescriptionWord = Split(Trim(strInputDescription), " ")
	

'Loop round to check that each word in the description entered by the user is not above the 100 characters
For intCheckWordLengthLoopCounter = 0 To UBound(saryDescriptionWord)
	
	'Initialise the intWordLength variable with the length of the word to be searched
	intWordLength = Len(saryDescriptionWord(intCheckWordLengthLoopCounter))
	
	'Get the number of characters in the longest word
	If intWordLength => intLongestWordLength Then 
		intLongestWordLength = intWordLength
	End If
		
	'If the word length to be searched is more than or equal to 100 then set the blnWordLegthOK to false
	If intWordLength => 100 Then 
		blnWordLenthOK = False
				
	End If
Next


'Get rid of scripting tags
strInputTitle = Replace(strInputTitle, "<", "&lt;")
strInputTitle = Replace(strInputTitle, ">", "&gt;")
strInputDescription = Replace(strInputDescription, "<", "&lt;")
strInputDescription = Replace(strInputDescription, ">", "&gt;")


'If the user has entered no words over 100 characters then write to database 
If blnWordLenthOK = True Then
	
	'create a recordset object
	Set rsAddURL = Server.CreateObject("ADODB.Recordset")
	
	'Initalise the strSQL variable with an SQL statement to get all the URLs from database
	strSQL = "SELECT MB_Company.* FROM MB_Company WHERE MB_Company.Title = '" & strInputTitle & "';"
	
	'Set the cursor type property of the record set to Dynamic so we can navigate through the record set
	rsAddURL.CursorType = 2
	
	'Set the Lock Type for the records so that the record set is only locked when it is updated
	rsAddURL.LockType = 3
			
	'Query the database
	rsAddURL.Open strSQL, adoCon
	
	'If there are no records returned by the recordset then it's a new URL
	If rsAddURL.EOF Then 
		
		'Set the new URL booleon to True
		blnNewURL = True
		
		'Tell the recordset this is a new record
		rsAddURL.AddNew
	End If

	'Place the users input in the recorset
	rsAddURL.Fields("Title") = strInputTitle
	rsAddURL.Fields("URL") = strInputURL
	rsAddURL.Fields("Area") = strInputAREA
	rsAddURL.Fields("Email") = strInputEmail
	rsAddURL.Fields("Man") = strInputMan
	rsAddURL.Fields("Phone") = strInputPhone
	rsAddURL.Fields("city") = strInputcity
	rsAddURL.Fields("Code") = strInputCode
	rsAddURL.Fields("Address") = strInputAddress
	rsAddURL.Fields("Sort") = strInputSort
	rsAddURL.Fields("Description") = strInputDescription
	rsAddURL.Fields("Keywords") = strInputKeywords
	rsAddURL.Fields("Date_Entered") = Now()
	'Update the database
	rsAddURL.Update
	
	'Close Sever Objects 
	Set rsAddURL = Nothing
	Set strCon = Nothing
	Set adoCon = Nothing
End If

%>
<HTML> 
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE><% = strWebname %></TITLE>

<style type="text/css">
<!--
.text {font-family: <% = strTextType %>; font-size: <% = intTextSize %>px; color: <% = strTextColour %>}
.heading {font-family: <% = strTextType %>; font-size: 24px; color: <% = strTextColour %>; font-weight: bold;}
a {font-family: <% = strTextType %>; font-size: <% = intTextSize %>px; color: <% = strLinkColour %>}
a:hover {font-family: <% = strTextType %>; font-size: <% = intTextSize %>px; color: <% = strHoverLinkColour %>}
a:visited {font-family: <% = strTextType %>; font-size: <% = intTextSize %>px; color: <% = strVisitedLinkColour %>}
a:visited:hover {font-family: <% = strTextType %>; font-size: <% = intTextSize %>px; color: <% = strHoverLinkColour %>}
-->
</style>

</head>
<body bgcolor="<% = strBgColour %>" text="<% = strTextColour %>">　<p>　</p>
<div align="center"><span class="heading">公司登记操作提示</span><div><br>
<div align="center">
  <center>
  <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="<% = strTableBorderColour %>" width="60%" id="AutoNumber1" bgcolor="<% = strTableColour %>">
    <tr>
      <td width="100%">　<p align="center">　
<%
'If any of the words in the description are above 100 chracters then disoplay an error message
If blnWordLenthOK = False Then
	Response.Write "<span class=""text"">对不起，您提交的: " & strInputTitle & " 没有添加成功.<br>您的公司简介已经超过了最大长度 " & intLongestWordLength & "，请返回后重新提交，谢谢!</span>"
	Response.Write "<br><br><a href=""javascript:history.back(1)"" target=""_self"">重新编辑</a>"

'If the URL has already been entered then display a message asying the URL has been updated
ElseIf  blnNewURL = False Then
	Response.Write "<span class=""text"">谢谢你更新: " & strInputTitle & "<br>相关资料已经更新完毕，并成功输入数据库!</span>"

'Else display that the new URL has been entered into the database
Else
	Response.Write "<span class=""text"">谢谢你提交: " & strInputTitle & "<br>相关资料已经成功输入数据库!</span>"
End If
%>
 <br>
  <br>
  <a href="default.asp" target="_self">[ 返回首页 ]</a><br>　</td>
    </tr>
  </table>
  </center>
</div>
</body>
</html>