<%
Response.Buffer = EW_RESPONSE_BUFFER
%>
<!--#include file="ewcfg7.asp"-->
<!--#include file="webseoinfo.asp"-->
<!--#include file="zlogininfo.asp"-->
<!--#include file="aspfn7.asp"-->
<!--#include file="userfn7.asp"-->
<% Session.Timeout = 900 %>
<%
Response.Expires = 0
Response.ExpiresAbsolute = Now() - 1
Response.AddHeader "pragma", "no-cache"
Response.AddHeader "cache-control", "private, no-cache, no-store, must-revalidate"
%>
<%

' Define page object
Dim webseo_add
Set webseo_add = New cwebseo_add
Set Page = webseo_add

' Page init processing
Call webseo_add.Page_Init()

' Page main processing
Call webseo_add.Page_Main()
%>
<!--#include file="header.asp"-->
<script type="text/javascript">
<!--
// Create page object
var webseo_add = new ew_Page("webseo_add");
// page properties
webseo_add.PageID = "add"; // page ID
var EW_PAGE_ID = webseo_add.PageID; // for backward compatibility
// extend page with ValidateForm function
webseo_add.ValidateForm = function(fobj) {
	if (!this.ValidateRequired)
		return true; // ignore validation
	if (fobj.a_confirm && fobj.a_confirm.value == "F")
		return true;
	var i, elm, aelm, infix;
	var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
	for (i=0; i<rowcnt; i++) {
		infix = (fobj.key_count) ? String(i+1) : "";
		// Call Form Custom Validate event
		if (!this.Form_CustomValidate(fobj)) return false;
	}
	return true;
}
// extend page with Form_CustomValidate function
webseo_add.Form_CustomValidate = 
 function(fobj) { // DO NOT CHANGE THIS LINE!
 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
webseo_add.SelectAllKey = function(elem) {
	ew_SelectAll(elem);
}
<% If EW_CLIENT_VALIDATE Then %>
webseo_add.ValidateRequired = true; // uses JavaScript validation
<% Else %>
webseo_add.ValidateRequired = false; // no JavaScript validation
<% End If %>
//-->
</script>
<script type="text/javascript">
<!--
var ew_DHTMLEditors = [];
//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--
// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js"); 
//-->
</script>
<p><span class="aspmaker">增加 表: 网站优化<br><br>
<a href="<%= webseo.ReturnUrl %>">返回</a></span></p>
<% webseo_add.ShowMessage %>
<form name="fwebseoadd" id="fwebseoadd" action="<%= ew_CurrentPage %>" method="post" onsubmit="return webseo_add.ValidateForm(this);">
<p>
<input type="hidden" name="t" id="t" value="webseo">
<input type="hidden" name="a_add" id="a_add" value="A">
<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable">
<% If webseo.seotitle.Visible Then ' seotitle %>
	<tr<%= webseo.seotitle.RowAttributes %>>
		<td class="ewTableHeader">标题</td>
		<td<%= webseo.seotitle.CellAttributes %>><span id="el_seotitle">
<textarea name="x_seotitle" id="x_seotitle" cols="35" rows="4"<%= webseo.seotitle.EditAttributes %>><%= webseo.seotitle.EditValue %></textarea>
</span><%= webseo.seotitle.CustomMsg %></td>
	</tr>
<% End If %>
<% If webseo.seokeys.Visible Then ' seokeys %>
	<tr<%= webseo.seokeys.RowAttributes %>>
		<td class="ewTableHeader">关键词</td>
		<td<%= webseo.seokeys.CellAttributes %>><span id="el_seokeys">
<textarea name="x_seokeys" id="x_seokeys" cols="35" rows="4"<%= webseo.seokeys.EditAttributes %>><%= webseo.seokeys.EditValue %></textarea>
</span><%= webseo.seokeys.CustomMsg %></td>
	</tr>
<% End If %>
<% If webseo.seoms.Visible Then ' seoms %>
	<tr<%= webseo.seoms.RowAttributes %>>
		<td class="ewTableHeader">描述</td>
		<td<%= webseo.seoms.CellAttributes %>><span id="el_seoms">
<textarea name="x_seoms" id="x_seoms" cols="35" rows="4"<%= webseo.seoms.EditAttributes %>><%= webseo.seoms.EditValue %></textarea>
</span><%= webseo.seoms.CustomMsg %></td>
	</tr>
<% End If %>
</table>
</div>
</td></tr></table>
<p>
<input type="submit" name="btnAction" id="btnAction" value="    增加    ">
</form>
<script language="JavaScript" type="text/javascript">
<!--
// Write your table-specific startup script here
// document.write("page loaded");
//-->
</script>
<!--#include file="footer.asp"-->
<%

' Drop page object
Set webseo_add = Nothing
%>
<%

' -----------------------------------------------------------------
' Page Class
'
Class cwebseo_add

	' Page ID
	Public Property Get PageID()
		PageID = "add"
	End Property

	' Table Name
	Public Property Get TableName()
		TableName = "webseo"
	End Property

	' Page Object Name
	Public Property Get PageObjName()
		PageObjName = "webseo_add"
	End Property

	' Page Name
	Public Property Get PageName()
		PageName = ew_CurrentPage()
	End Property

	' Page Url
	Public Property Get PageUrl()
		PageUrl = ew_CurrentPage() & "?"
		If webseo.UseTokenInUrl Then PageUrl = PageUrl & "t=" & webseo.TableVar & "&" ' add page token
	End Property

	' Message
	Public Property Get Message()
		Message = Session(EW_SESSION_MESSAGE)
	End Property

	Public Property Let Message(v)
		If Session(EW_SESSION_MESSAGE) <> "" Then ' Append
			Session(EW_SESSION_MESSAGE) = Session(EW_SESSION_MESSAGE) & "<br>" & v
		Else
			Session(EW_SESSION_MESSAGE) = v
		End If
	End Property

	' Show Message
	Public Sub ShowMessage()
		If Message <> "" Then ' Message in Session, display
			Response.Write "<p><span class=""ewMessage"">" & Message & "</span></p>"
			Session(EW_SESSION_MESSAGE) = "" ' Clear message in Session
		End If
	End Sub

	' -----------------------
	'  Validate Page request
	'
	Public Function IsPageRequest()
		If webseo.UseTokenInUrl Then
			IsPageRequest = False
			If Not (ObjForm Is Nothing) Then
				IsPageRequest = (webseo.TableVar = ObjForm.GetValue("t"))
			End If
			If Request.QueryString("t").Count > 0 Then
				IsPageRequest = (webseo.TableVar = Request.QueryString("t"))
			End If
		Else
			IsPageRequest = True
		End If
	End Function

	' -----------------------------------------------------------------
	'  Class initialize
	'  - init objects
	'  - open ADO connection
	'
	Private Sub Class_Initialize()

		' Initialize table object
		Set webseo = New cwebseo

		' Initialize other table object
		Set zlogin = New czlogin

		' Initialize form object
		Set ObjForm = Nothing

		' Intialize page id (for backward compatibility)
		EW_PAGE_ID = "add"

		' Initialize table name (for backward compatibility)
		EW_TABLE_NAME = "webseo"

		' Open connection to the database
		Set Conn = Server.CreateObject("ADODB.Connection")
		Conn.Open EW_DB_CONNECTION_STRING
	End Sub

	' -----------------------------------------------------------------
	'  Subroutine Page_Init
	'  - called before page main
	'  - check Security
	'  - set up response header
	'  - call page load events
	'
	Sub Page_Init()
		Set Security = New cAdvancedSecurity
		If Not Security.IsLoggedIn() Then Call Security.AutoLogin()
		If Not Security.IsLoggedIn() Then
			Call Security.SaveLastUrl()
			Call Page_Terminate("login.asp")
		End If

		' Table Permission loading event
		Call Security.TablePermission_Loading()
		Call Security.LoadCurrentUserLevel(TableName)

		' Table Permission loaded event
		Call Security.TablePermission_Loaded()
		If Not Security.CanAdd Then
			Call Security.SaveLastUrl()
			Call Page_Terminate("webseolist.asp")
		End If

		' Global page loading event (in userfn7.asp)
		Call Page_Loading()

		' Page load event, used in current page
		Call Page_Load()
	End Sub

	' -----------------------------------------------------------------
	'  Class terminate
	'  - clean up page object
	'
	Private Sub Class_Terminate()
		Call Page_Terminate("")
	End Sub

	' -----------------------------------------------------------------
	'  Subroutine Page_Terminate
	'  - called when exit page
	'  - clean up ADO connection and objects
	'  - if url specified, redirect to url
	'
	Sub Page_Terminate(url)

		' Page unload event, used in current page
		Call Page_Unload()

		' Global page unloaded event (in userfn60.asp)
		Call Page_Unloaded()
		If Not (Conn Is Nothing) Then Conn.Close ' Close Connection
		Set Conn = Nothing
		Set Security = Nothing
		Set webseo = Nothing

		' Go to url if specified
		If url <> "" Then
			Response.Clear
			Response.Redirect url
		End If
	End Sub

	'
	'  Subroutine Page_Terminate (End)
	' ----------------------------------------

	Dim x_ewPriv

	' -----------------------------------------------------------------
	' Page main processing
	'
	Sub Page_Main()

		' Load key values from QueryString
		Dim bCopy
		bCopy = True
		If Request.QueryString("id").Count > 0 Then
			webseo.id.QueryStringValue = Request.QueryString("id")
		Else
			bCopy = False
		End If

		' Create form object
		Set ObjForm = New cFormObj

		' Process form if post back
		If ObjForm.GetValue("a_add")&"" <> "" Then
			webseo.CurrentAction = ObjForm.GetValue("a_add") ' Get form action
			Call LoadFormValues() ' Load form values

			' Validate Form
			If Not ValidateForm() Then
				webseo.CurrentAction = "I" ' Form error, reset action
				Message = gsFormError
			End If

		' Not post back
		Else
			If bCopy Then
				webseo.CurrentAction = "C" ' Copy Record
			Else
				webseo.CurrentAction = "I" ' Display Blank Record
				Call LoadDefaultValues() ' Load default values
			End If
		End If

		' Close form object
		Set ObjForm = Nothing

		' Perform action based on action code
		Select Case webseo.CurrentAction
			Case "I" ' Blank record, no action required
			Case "C" ' Copy an existing record
				If Not LoadRow() Then ' Load record based on key
					Message = "没有找到记录" ' No record found
					Call Page_Terminate("webseolist.asp") ' No matching record, return to list
				End If
			Case "A" ' Add new record
				webseo.SendEmail = True ' Send email on add success
				If AddRow() Then ' Add successful
					Message = "记录增加成功" ' Set up success message
					Dim sReturnUrl
					sReturnUrl = webseo.ReturnUrl
					If ew_GetPageName(sReturnUrl) = "webseoview.asp" Then sReturnUrl = webseo.ViewUrl ' View paging, return to view page with keyurl directly
					Call Page_Terminate(sReturnUrl) ' Clean up and return
				Else
					Call RestoreFormValues() ' Add failed, restore form values
				End If
		End Select

		' Render row based on row type
		webseo.RowType = EW_ROWTYPE_ADD ' Render add type

		' Render row
		Call RenderRow()
	End Sub

	' -----------------------------------------------------------------
	' Function Get upload files
	'
	Function GetUploadFiles()

		' Get upload data
	End Function

	' -----------------------------------------------------------------
	' Load default values
	'
	Function LoadDefaultValues()
	End Function

	' -----------------------------------------------------------------
	' Load form values
	'
	Function LoadFormValues()

		' Load values from form
		webseo.seotitle.FormValue = ObjForm.GetValue("x_seotitle")
		webseo.seotitle.OldValue = ObjForm.GetValue("o_seotitle")
		webseo.seokeys.FormValue = ObjForm.GetValue("x_seokeys")
		webseo.seokeys.OldValue = ObjForm.GetValue("o_seokeys")
		webseo.seoms.FormValue = ObjForm.GetValue("x_seoms")
		webseo.seoms.OldValue = ObjForm.GetValue("o_seoms")
		webseo.id.FormValue = ObjForm.GetValue("x_id")
	End Function

	' -----------------------------------------------------------------
	' Restore form values
	'
	Function RestoreFormValues()
		webseo.seotitle.CurrentValue = webseo.seotitle.FormValue
		webseo.seokeys.CurrentValue = webseo.seokeys.FormValue
		webseo.seoms.CurrentValue = webseo.seoms.FormValue
		webseo.id.CurrentValue = webseo.id.FormValue
	End Function

	' -----------------------------------------------------------------
	' Load row based on key values
	'
	Function LoadRow()
		Dim RsRow, sSql, sFilter
		sFilter = webseo.KeyFilter

		' Call Row Selecting event
		Call webseo.Row_Selecting(sFilter)

		' Load sql based on filter
		webseo.CurrentFilter = sFilter
		sSql = webseo.SQL
		If EW_DEBUG_ENABLED Then Response.Write sSql ' Show SQL for debugging
		Set RsRow = Server.CreateObject("ADODB.Recordset")
		RsRow.Open sSql, Conn
		If RsRow.Eof Then
			LoadRow = False
		Else
			LoadRow = True
			RsRow.MoveFirst
			Call LoadRowValues(RsRow) ' Load row values

			' Call Row Selected event
			Call webseo.Row_Selected(RsRow)
		End If
		RsRow.Close
		Set RsRow = Nothing
	End Function

	' -----------------------------------------------------------------
	' Load row values from recordset
	'
	Sub LoadRowValues(RsRow)
		webseo.id.DbValue = RsRow("id")
		webseo.seotitle.DbValue = RsRow("seotitle")
		webseo.seokeys.DbValue = RsRow("seokeys")
		webseo.seoms.DbValue = RsRow("seoms")
	End Sub

	' -----------------------------------------------------------------
	' Render row values based on field settings
	'
	Sub RenderRow()

		' Call Row Rendering event
		Call webseo.Row_Rendering()

		' ---------------------------------------
		'  Common render codes for all row types
		' ---------------------------------------
		' seotitle

		webseo.seotitle.CellCssStyle = ""
		webseo.seotitle.CellCssClass = ""

		' seokeys
		webseo.seokeys.CellCssStyle = ""
		webseo.seokeys.CellCssClass = ""

		' seoms
		webseo.seoms.CellCssStyle = ""
		webseo.seoms.CellCssClass = ""

		' -----------
		'  View  Row
		' -----------

		If webseo.RowType = EW_ROWTYPE_VIEW Then ' View row

			' id
			webseo.id.ViewValue = webseo.id.CurrentValue
			webseo.id.CssStyle = ""
			webseo.id.CssClass = ""
			webseo.id.ViewCustomAttributes = ""

			' seotitle
			webseo.seotitle.ViewValue = webseo.seotitle.CurrentValue
			webseo.seotitle.CssStyle = ""
			webseo.seotitle.CssClass = ""
			webseo.seotitle.ViewCustomAttributes = ""

			' seokeys
			webseo.seokeys.ViewValue = webseo.seokeys.CurrentValue
			webseo.seokeys.CssStyle = ""
			webseo.seokeys.CssClass = ""
			webseo.seokeys.ViewCustomAttributes = ""

			' seoms
			webseo.seoms.ViewValue = webseo.seoms.CurrentValue
			webseo.seoms.CssStyle = ""
			webseo.seoms.CssClass = ""
			webseo.seoms.ViewCustomAttributes = ""

			' View refer script
			' seotitle

			webseo.seotitle.HrefValue = ""

			' seokeys
			webseo.seokeys.HrefValue = ""

			' seoms
			webseo.seoms.HrefValue = ""

		' ---------
		'  Add Row
		' ---------

		ElseIf webseo.RowType = EW_ROWTYPE_ADD Then ' Add row

			' seotitle
			webseo.seotitle.EditCustomAttributes = ""
			webseo.seotitle.EditValue = ew_HtmlEncode(webseo.seotitle.CurrentValue)

			' seokeys
			webseo.seokeys.EditCustomAttributes = ""
			webseo.seokeys.EditValue = ew_HtmlEncode(webseo.seokeys.CurrentValue)

			' seoms
			webseo.seoms.EditCustomAttributes = ""
			webseo.seoms.EditValue = ew_HtmlEncode(webseo.seoms.CurrentValue)
		End If

		' Call Row Rendered event
		Call webseo.Row_Rendered()
	End Sub

	' -----------------------------------------------------------------
	' Validate form
	'
	Function ValidateForm()

		' Initialize
		gsFormError = ""

		' Check if validation required
		If Not EW_SERVER_VALIDATE Then
			ValidateForm = (gsFormError = "")
			Exit Function
		End If

		' Return validate result
		ValidateForm = (gsFormError = "")

		' Call Form Custom Validate event
		Dim sFormCustomError
		sFormCustomError = ""
		ValidateForm = ValidateForm And Form_CustomValidate(sFormCustomError)
		If sFormCustomError <> "" Then
			If gsFormError <> "" Then gsFormError = gsFormError & "<br>"
			gsFormError = gsFormError & sFormCustomError
		End If
	End Function

	' -----------------------------------------------------------------
	' Add record
	'
	Function AddRow()
		If Not EW_DEBUG_ENABLED Then On Error Resume Next
		Dim Rs, sSql, sFilter
		Dim RsNew
		Dim bInsertRow
		Dim RsChk
		Dim sIdxErrMsg

		' Clear any previous errors
		Err.Clear

		' Add new record
		sFilter = "(0 = 1)"
		webseo.CurrentFilter = sFilter
		sSql = webseo.SQL
		Set Rs = Server.CreateObject("ADODB.Recordset")
		Rs.CursorLocation = EW_CURSORLOCATION
		Rs.Open sSql, Conn, 1, 2
		Rs.AddNew
		If Err.Number <> 0 Then
			Message = Err.Description
			Rs.Close
			Set Rs = Nothing
			AddRow = False
			Exit Function
		End If

		' Field seotitle
		Call webseo.seotitle.SetDbValue(webseo.seotitle.CurrentValue, Null)
		Rs("seotitle") = webseo.seotitle.DbValue

		' Field seokeys
		Call webseo.seokeys.SetDbValue(webseo.seokeys.CurrentValue, Null)
		Rs("seokeys") = webseo.seokeys.DbValue

		' Field seoms
		Call webseo.seoms.SetDbValue(webseo.seoms.CurrentValue, Null)
		Rs("seoms") = webseo.seoms.DbValue

		' Check recordset update error
		If Err.Number <> 0 Then
			Message = Err.Description
			Rs.Close
			Set Rs = Nothing
			AddRow = False
			Exit Function
		End If

		' Call Row Inserting event
		bInsertRow = webseo.Row_Inserting(Rs)
		If bInsertRow Then

			' Clone new recordset object
			Set RsNew = ew_CloneRs(Rs)
			Rs.Update
			If Err.Number <> 0 Then
				Message = Err.Description
				AddRow = False
			Else
				AddRow = True
			End If
		Else
			Rs.CancelUpdate
			If webseo.CancelMessage <> "" Then
				Message = webseo.CancelMessage
				webseo.CancelMessage = ""
			Else
				Message = "插入已取消"
			End If
			AddRow = False
		End If
		Rs.Close
		Set Rs = Nothing
		If AddRow Then
			webseo.id.DbValue = RsNew("id")

			' Call Row Inserted event
			Call webseo.Row_Inserted(RsNew)
		End If
		If IsObject(RsNew) Then
			RsNew.Close
			Set RsNew = Nothing
		End If
	End Function

	' Page Load event
	Sub Page_Load()

		'Response.Write "Page Load"
	End Sub

	' Page Unload event
	Sub Page_Unload()

		'Response.Write "Page Unload"
	End Sub

	' Form Custom Validate event
	Function Form_CustomValidate(CustomError)

		'Return error message in CustomError
		Form_CustomValidate = True
	End Function
End Class
%>
