%@ CodePage=65001 LCID=14337 %> <% Const EW_PAGE_ID = "add" Const EW_TABLE_NAME = "Content" %> <% Response.Expires = 0 Response.ExpiresAbsolute = Now() - 1 Response.AddHeader "pragma", "no-cache" Response.AddHeader "cache-control", "private, no-cache, no-store, must-revalidate" %> <% ' Open connection to the database Dim conn Set conn = Server.CreateObject("ADODB.Connection") conn.Open EW_DB_CONNECTION_STRING %> <% Dim Security 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 %> <% ' Common page loading event (in userfn60.asp) Call Page_Loading() %> <% ' Page load event, used in current page Call Page_Load() %> <% Response.Buffer = True ' Load key values from QueryString Dim bCopy bCopy = True If Request.QueryString("id").Count > 0 Then Content.id.QueryStringValue = Request.QueryString("id") Else bCopy = False End If If Request.QueryString("Navigation_Name").Count > 0 Then Content.Navigation_Name.QueryStringValue = Request.QueryString("Navigation_Name") Else bCopy = False End If If Request.QueryString("Language_Name").Count > 0 Then Content.Language_Name.QueryStringValue = Request.QueryString("Language_Name") Else bCopy = False End If ' Create form object Dim objForm Set objForm = ew_GetUploadObj() ' Process form if post back If objForm.GetValue("a_add")&"" <> "" Then Content.CurrentAction = objForm.GetValue("a_add") ' Get form action Call GetUploadFiles() ' Get upload files Call LoadFormValues() ' Load form values ' Not post back Else If bCopy Then Content.CurrentAction = "C" ' Copy Record Else Content.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 Content.CurrentAction Case "I" ' Blank record, no action required Case "C" ' Copy an existing record If Not LoadRow() Then ' Load record based on key Session(EW_SESSION_MESSAGE) = "No records found" ' No record found Call Page_Terminate(Content.ReturnUrl) ' Clean up and return End If Case "A" ' Add new record Content.SendEmail = True ' Send email on add success If AddRow() Then ' Add successful Session(EW_SESSION_MESSAGE) = "Add New Record Successful" ' Set up success message Call Page_Terminate(Content.KeyUrl(Content.ReturnUrl, "")) ' Clean up and return Else Call RestoreFormValues() ' Add failed, restore form values End If End Select ' Render row based on row type Content.RowType = EW_ROWTYPE_ADD ' add ' Render add type Call RenderRow() %>
Add to TABLE: Content
Go Back
<%= Session(EW_SESSION_MESSAGE) %>
<% Session(EW_SESSION_MESSAGE) = "" ' Clear message in Session End If %> <% ' If control is passed here, simply terminate the page without redirect Call Page_Terminate("") ' ----------------------------------------------------------------- ' Subroutine Page_Terminate ' - called when exit page ' - clean up ADO connection and objects ' - if url specified, redirect to url, otherwise end response ' Sub Page_Terminate(url) ' Page unload event, used in current page Call Page_Unload() ' Global page unloaded event (in userfn60.asp) Call Page_Unloaded() conn.Close ' Close Connection Set conn = Nothing Set Security = Nothing Set Content = Nothing ' Go to url if specified If url <> "" Then Response.Clear Response.Redirect url End If ' Terminate response Response.End End Sub ' ' Subroutine Page_Terminate (End) ' ---------------------------------------- %> <% ' Function Get upload files Function GetUploadFiles() ' Get upload data If Content.Thumb_Image.Upload.UploadFile() Then ' No action required Else Response.Write Content.Thumb_Image.Upload.Message Response.End End If If Content.Image.Upload.UploadFile() Then ' No action required Else Response.Write Content.Image.Upload.Message Response.End End If End Function %> <% ' Load default values Function LoadDefaultValues() Content.Hide.CurrentValue = 0 End Function %> <% ' Load form values Function LoadFormValues() ' Load from form Content.Navigation_Name.FormValue = objForm.GetValue("x_Navigation_Name") Content.Language_Name.FormValue = objForm.GetValue("x_Language_Name") Content.Content.FormValue = objForm.GetValue("x_Content") Content.Hide.FormValue = objForm.GetValue("x_Hide") End Function ' Restore form values Function RestoreFormValues() Content.Navigation_Name.CurrentValue = Content.Navigation_Name.FormValue Content.Language_Name.CurrentValue = Content.Language_Name.FormValue Content.Content.CurrentValue = Content.Content.FormValue Content.Hide.CurrentValue = Content.Hide.FormValue End Function %> <% ' Load row based on key values Function LoadRow() Dim rs, sSql, sFilter sFilter = Content.SqlKeyFilter If Not IsNumeric(Content.id.CurrentValue) Then LoadRow = False ' Invalid key, exit Exit Function End If sFilter = Replace(sFilter, "@id@", ew_AdjustSql(Content.id.CurrentValue)) ' Replace key value If Not IsNumeric(Content.Navigation_Name.CurrentValue) Then LoadRow = False ' Invalid key, exit Exit Function End If sFilter = Replace(sFilter, "@Navigation_Name@", ew_AdjustSql(Content.Navigation_Name.CurrentValue)) ' Replace key value If Not IsNumeric(Content.Language_Name.CurrentValue) Then LoadRow = False ' Invalid key, exit Exit Function End If sFilter = Replace(sFilter, "@Language_Name@", ew_AdjustSql(Content.Language_Name.CurrentValue)) ' Replace key value ' Call Row Selecting event Call Content.Row_Selecting(sFilter) ' Load sql based on filter Content.CurrentFilter = sFilter sSql = Content.SQL Set rs = Server.CreateObject("ADODB.Recordset") rs.Open sSql, conn If rs.Eof Then LoadRow = False Else LoadRow = True rs.MoveFirst Call LoadRowValues(rs) ' Load row values ' Call Row Selected event Call Content.Row_Selected(rs) End If rs.Close Set rs = Nothing End Function ' Load row values from recordset Sub LoadRowValues(rs) Content.id.DbValue = rs("id") Content.Navigation_Name.DbValue = rs("Navigation_Name") Content.Language_Name.DbValue = rs("Language_Name") Content.Content.DbValue = rs("Content") Content.Thumb_Image.Upload.DbValue = rs("Thumb_Image") Content.Image.Upload.DbValue = rs("Image") Content.Hide.DbValue = ew_IIf(rs("Hide"), "1", "0") Content.CreatedDate.DbValue = rs("CreatedDate") End Sub %> <% ' Render row values based on field settings Sub RenderRow() ' Call Row Rendering event Call Content.Row_Rendering() ' Common render codes for all row types ' Navigation_Name Content.Navigation_Name.CellCssStyle = "" Content.Navigation_Name.CellCssClass = "" ' Language_Name Content.Language_Name.CellCssStyle = "" Content.Language_Name.CellCssClass = "" ' Content Content.Content.CellCssStyle = "" Content.Content.CellCssClass = "" ' Thumb_Image Content.Thumb_Image.CellCssStyle = "" Content.Thumb_Image.CellCssClass = "" ' Image Content.Image.CellCssStyle = "" Content.Image.CellCssClass = "" ' Hide Content.Hide.CellCssStyle = "" Content.Hide.CellCssClass = "" If Content.RowType = EW_ROWTYPE_VIEW Then ' View row ElseIf Content.RowType = EW_ROWTYPE_ADD Then ' Add row ' Navigation_Name Content.Navigation_Name.EditCustomAttributes = "" sSqlWrk = "SELECT [id], [Navigation_Name] FROM [Side_Navigation]" Set rswrk = Server.CreateObject("ADODB.Recordset") rswrk.Open sSqlWrk, conn If Not rswrk.Eof Then arwrk = rswrk.GetRows Else arwrk = "" End If rswrk.Close Set rswrk = Nothing arwrk = ew_AddItemToArray(arwrk, 0, Array("", "Please Select")) Content.Navigation_Name.EditValue = arwrk ' Language_Name Content.Language_Name.EditCustomAttributes = "" sSqlWrk = "SELECT [id], [Language_Name] FROM [Languages]" Set rswrk = Server.CreateObject("ADODB.Recordset") rswrk.Open sSqlWrk, conn If Not rswrk.Eof Then arwrk = rswrk.GetRows Else arwrk = "" End If rswrk.Close Set rswrk = Nothing arwrk = ew_AddItemToArray(arwrk, 0, Array("", "Please Select")) Content.Language_Name.EditValue = arwrk ' Content Content.Content.EditCustomAttributes = "" Content.Content.EditValue = Content.Content.CurrentValue ' Thumb_Image Content.Thumb_Image.EditCustomAttributes = "" If Not IsNull(Content.Thumb_Image.Upload.DbValue) Then Content.Thumb_Image.EditValue = Content.Thumb_Image.Upload.DbValue Content.Thumb_Image.ImageAlt = "" Else Content.Thumb_Image.EditValue = "" End If ' Image Content.Image.EditCustomAttributes = "" If Not IsNull(Content.Image.Upload.DbValue) Then Content.Image.EditValue = Content.Image.Upload.DbValue Content.Image.ImageAlt = "" Else Content.Image.EditValue = "" End If ' Hide Content.Hide.EditCustomAttributes = "" ElseIf Content.RowType = EW_ROWTYPE_EDIT Then ' Edit row ElseIf Content.RowType = EW_ROWTYPE_SEARCH Then ' Search row End If ' Call Row Rendered event Call Content.Row_Rendered() End Sub %> <% ' Add record Function AddRow() On Error Resume Next Dim rs, sSql, sFilter Dim rsnew Dim bCheckKey, sSqlChk, sWhereChk, rsChk Dim bInsertRow ' Check for duplicate key bCheckKey = True sFilter = Content.SqlKeyFilter If Content.id.CurrentValue = "" Or IsNull(Content.id.CurrentValue) Then bCheckKey = False Else sFilter = Replace(sFilter, "@id@", ew_AdjustSql(Content.id.CurrentValue)) ' Replace key value End If If Not IsNumeric(Content.id.CurrentValue) Then bCheckKey = False End If If Content.Navigation_Name.CurrentValue = "" Or IsNull(Content.Navigation_Name.CurrentValue) Then bCheckKey = False Else sFilter = Replace(sFilter, "@Navigation_Name@", ew_AdjustSql(Content.Navigation_Name.CurrentValue)) ' Replace key value End If If Not IsNumeric(Content.Navigation_Name.CurrentValue) Then bCheckKey = False End If If Content.Language_Name.CurrentValue = "" Or IsNull(Content.Language_Name.CurrentValue) Then bCheckKey = False Else sFilter = Replace(sFilter, "@Language_Name@", ew_AdjustSql(Content.Language_Name.CurrentValue)) ' Replace key value End If If Not IsNumeric(Content.Language_Name.CurrentValue) Then bCheckKey = False End If If bCheckKey Then Set rsChk = Content.LoadRs(sFilter) If Not (rsChk Is Nothing) Then Session(EW_SESSION_MESSAGE) = "Duplicate value for primary key" rsChk.Close Set rsChk = Nothing AddRow = False Exit Function End If End If ' Add new record sFilter = "(0 = 1)" Content.CurrentFilter = sFilter sSql = Content.SQL Set rs = Server.CreateObject("ADODB.Recordset") rs.CursorLocation = EW_CURSORLOCATION rs.Open sSql, conn, 1, 2 rs.AddNew If Err.Number <> 0 Then Session(EW_SESSION_MESSAGE) = Err.Description rs.Close Set rs = Nothing AddRow = False Exit Function End If ' Field Navigation_Name Call Content.Navigation_Name.SetDbValue(Content.Navigation_Name.CurrentValue, Null) rs("Navigation_Name") = Content.Navigation_Name.DbValue ' Field Language_Name Call Content.Language_Name.SetDbValue(Content.Language_Name.CurrentValue, Null) rs("Language_Name") = Content.Language_Name.DbValue ' Field Content Call Content.Content.SetDbValue(Content.Content.CurrentValue, Null) rs("Content") = Content.Content.DbValue ' Field Thumb_Image Call Content.Thumb_Image.Upload.SaveToSession() ' Save file value to Session Content.Thumb_Image.Upload.DbValue = rs("Thumb_Image") ' Get original value If IsNull(Content.Thumb_Image.Upload.Value) Then rs("Thumb_Image") = Null Else rs("Thumb_Image") = ew_UploadFileNameEx(ew_UploadPathEx(True, EW_UPLOAD_DEST_PATH), Content.Thumb_Image.Upload.FileName) End If ' Field Image Call Content.Image.Upload.SaveToSession() ' Save file value to Session Content.Image.Upload.DbValue = rs("Image") ' Get original value If IsNull(Content.Image.Upload.Value) Then rs("Image") = Null Else rs("Image") = ew_UploadFileNameEx(ew_UploadPathEx(True, EW_UPLOAD_DEST_PATH), Content.Image.Upload.FileName) End If ' Field Hide Call Content.Hide.SetDbValue((Content.Hide.CurrentValue <> "" And Not IsNull(Content.Hide.CurrentValue)), Null) rs("Hide") = Content.Hide.DbValue ' Check recordset update error If Err.Number <> 0 Then Session(EW_SESSION_MESSAGE) = Err.Description rs.Close Set rs = Nothing AddRow = False Exit Function End If ' Call Row Inserting event bInsertRow = Content.Row_Inserting(rs) If bInsertRow Then ' Field Thumb_Image If Not IsNull(Content.Thumb_Image.Upload.Value) Then Call ew_SaveFile(ew_UploadPathEx(True, EW_UPLOAD_DEST_PATH), rs("Thumb_Image"), Content.Thumb_Image.Upload.Value) ' Field Image If Not IsNull(Content.Image.Upload.Value) Then Call ew_SaveFile(ew_UploadPathEx(True, EW_UPLOAD_DEST_PATH), rs("Image"), Content.Image.Upload.Value) ' Clone new rs object Set rsnew = ew_CloneRs(rs) rs.Update If Err.Number <> 0 Then Session(EW_SESSION_MESSAGE) = Err.Description AddRow = False Else AddRow = True End If Else rs.CancelUpdate If Content.CancelMessage <> "" Then Session(EW_SESSION_MESSAGE) = Content.CancelMessage Content.CancelMessage = "" Else Session(EW_SESSION_MESSAGE) = "Insert cancelled" End If AddRow = False End If rs.Close Set rs = Nothing If AddRow Then Content.id.DbValue = rsnew("id") ' Call Row Inserted event Call Content.Row_Inserted(rsnew) End If ' Field Thumb_Image Call Content.Thumb_Image.Upload.RemoveFromSession() ' Remove file value from Session ' Field Image Call Content.Image.Upload.RemoveFromSession() ' Remove file value from Session 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 %>