%@ CodePage=65001 %> <% Const EW_PAGE_ID = "add" Const EW_TABLE_NAME = "Side_Navigation" %> <% Session.Timeout = 100 %> <% 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 Side_Navigation.id.QueryStringValue = Request.QueryString("id") 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 Side_Navigation.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 Side_Navigation.CurrentAction = "C" ' Copy Record Else Side_Navigation.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 Side_Navigation.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(Side_Navigation.ReturnUrl) ' Clean up and return End If Case "A" ' Add new record Side_Navigation.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(Side_Navigation.KeyUrl(Side_Navigation.ReturnUrl, "")) ' Clean up and return Else Call RestoreFormValues() ' Add failed, restore form values End If End Select ' Render row based on row type Side_Navigation.RowType = EW_ROWTYPE_ADD ' add ' Render add type Call RenderRow() %>
Add to TABLE: Side Navigation
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 Side_Navigation = 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 Side_Navigation.Thumb_Image.Upload.Index = objForm.Index If Side_Navigation.Thumb_Image.Upload.UploadFile() Then ' No action required Else Response.Write Side_Navigation.Thumb_Image.Upload.Message Response.End End If Side_Navigation.Image.Upload.Index = objForm.Index If Side_Navigation.Image.Upload.UploadFile() Then ' No action required Else Response.Write Side_Navigation.Image.Upload.Message Response.End End If End Function %> <% ' Load default values Function LoadDefaultValues() Side_Navigation.Show_Center_Images.CurrentValue = 0 Side_Navigation.Show_Rotating_Images.CurrentValue = 0 Side_Navigation.Show_Wallpaper.CurrentValue = 0 Side_Navigation.Hide.CurrentValue = 0 End Function %> <% ' Load form values Function LoadFormValues() ' Load from form Side_Navigation.Navigation_Name.FormValue = objForm.GetValue("x_Navigation_Name") Side_Navigation.Page_Type.FormValue = objForm.GetValue("x_Page_Type") Side_Navigation.language_id.FormValue = objForm.GetValue("x_language_id") Side_Navigation.Content.FormValue = objForm.GetValue("x_Content") Side_Navigation.Show_Center_Images.FormValue = objForm.GetValue("x_Show_Center_Images") Side_Navigation.Show_Rotating_Images.FormValue = objForm.GetValue("x_Show_Rotating_Images") Side_Navigation.Show_Wallpaper.FormValue = objForm.GetValue("x_Show_Wallpaper") Side_Navigation.Navigation_Bar.FormValue = objForm.GetValue("x_Navigation_Bar") Side_Navigation.View_Order.FormValue = objForm.GetValue("x_View_Order") Side_Navigation.Hide.FormValue = objForm.GetValue("x_Hide") End Function ' Restore form values Function RestoreFormValues() Side_Navigation.Navigation_Name.CurrentValue = Side_Navigation.Navigation_Name.FormValue Side_Navigation.Page_Type.CurrentValue = Side_Navigation.Page_Type.FormValue Side_Navigation.language_id.CurrentValue = Side_Navigation.language_id.FormValue Side_Navigation.Content.CurrentValue = Side_Navigation.Content.FormValue Side_Navigation.Show_Center_Images.CurrentValue = Side_Navigation.Show_Center_Images.FormValue Side_Navigation.Show_Rotating_Images.CurrentValue = Side_Navigation.Show_Rotating_Images.FormValue Side_Navigation.Show_Wallpaper.CurrentValue = Side_Navigation.Show_Wallpaper.FormValue Side_Navigation.Navigation_Bar.CurrentValue = Side_Navigation.Navigation_Bar.FormValue Side_Navigation.View_Order.CurrentValue = Side_Navigation.View_Order.FormValue Side_Navigation.Hide.CurrentValue = Side_Navigation.Hide.FormValue End Function %> <% ' Load row based on key values Function LoadRow() Dim rs, sSql, sFilter sFilter = Side_Navigation.SqlKeyFilter If Not IsNumeric(Side_Navigation.id.CurrentValue) Then LoadRow = False ' Invalid key, exit Exit Function End If sFilter = Replace(sFilter, "@id@", ew_AdjustSql(Side_Navigation.id.CurrentValue)) ' Replace key value ' Call Row Selecting event Call Side_Navigation.Row_Selecting(sFilter) ' Load sql based on filter Side_Navigation.CurrentFilter = sFilter sSql = Side_Navigation.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 Side_Navigation.Row_Selected(rs) End If rs.Close Set rs = Nothing End Function ' Load row values from recordset Sub LoadRowValues(rs) Side_Navigation.id.DbValue = rs("id") Side_Navigation.Navigation_Name.DbValue = rs("Navigation_Name") Side_Navigation.Page_Type.DbValue = rs("Page_Type") Side_Navigation.language_id.DbValue = rs("language_id") Side_Navigation.Content.DbValue = rs("Content") Side_Navigation.Show_Center_Images.DbValue = ew_IIf(rs("Show_Center_Images"), "1", "0") Side_Navigation.Show_Rotating_Images.DbValue = ew_IIf(rs("Show_Rotating_Images"), "1", "0") Side_Navigation.Show_Wallpaper.DbValue = ew_IIf(rs("Show_Wallpaper"), "1", "0") Side_Navigation.Thumb_Image.Upload.DbValue = rs("Thumb_Image") Side_Navigation.Image.Upload.DbValue = rs("Image") Side_Navigation.Navigation_Bar.DbValue = rs("Navigation_Bar") Side_Navigation.View_Order.DbValue = rs("View_Order") Side_Navigation.Hide.DbValue = ew_IIf(rs("Hide"), "1", "0") End Sub %> <% ' Render row values based on field settings Sub RenderRow() ' Call Row Rendering event Call Side_Navigation.Row_Rendering() ' Common render codes for all row types ' Navigation_Name Side_Navigation.Navigation_Name.CellCssStyle = "" Side_Navigation.Navigation_Name.CellCssClass = "" ' Page_Type Side_Navigation.Page_Type.CellCssStyle = "" Side_Navigation.Page_Type.CellCssClass = "" ' language_id Side_Navigation.language_id.CellCssStyle = "" Side_Navigation.language_id.CellCssClass = "" ' Content Side_Navigation.Content.CellCssStyle = "" Side_Navigation.Content.CellCssClass = "" ' Show_Center_Images Side_Navigation.Show_Center_Images.CellCssStyle = "" Side_Navigation.Show_Center_Images.CellCssClass = "" ' Show_Rotating_Images Side_Navigation.Show_Rotating_Images.CellCssStyle = "" Side_Navigation.Show_Rotating_Images.CellCssClass = "" ' Show_Wallpaper Side_Navigation.Show_Wallpaper.CellCssStyle = "" Side_Navigation.Show_Wallpaper.CellCssClass = "" ' Thumb_Image Side_Navigation.Thumb_Image.CellCssStyle = "" Side_Navigation.Thumb_Image.CellCssClass = "" ' Image Side_Navigation.Image.CellCssStyle = "" Side_Navigation.Image.CellCssClass = "" ' Navigation_Bar Side_Navigation.Navigation_Bar.CellCssStyle = "" Side_Navigation.Navigation_Bar.CellCssClass = "" ' View_Order Side_Navigation.View_Order.CellCssStyle = "" Side_Navigation.View_Order.CellCssClass = "" ' Hide Side_Navigation.Hide.CellCssStyle = "" Side_Navigation.Hide.CellCssClass = "" If Side_Navigation.RowType = EW_ROWTYPE_VIEW Then ' View row ElseIf Side_Navigation.RowType = EW_ROWTYPE_ADD Then ' Add row ' Navigation_Name Side_Navigation.Navigation_Name.EditCustomAttributes = "" Side_Navigation.Navigation_Name.EditValue = ew_HtmlEncode(Side_Navigation.Navigation_Name.CurrentValue) ' Page_Type Side_Navigation.Page_Type.EditCustomAttributes = "" Redim arwrk(1, 3) arwrk(0, 0) = "1" arwrk(1, 0) = "Default" arwrk(0, 1) = "2" arwrk(1, 1) = "Video Gallery" arwrk(0, 2) = "3" arwrk(1, 2) = "Photo Gallery" arwrk(0, 3) = "4" arwrk(1, 3) = "News" arwrk = ew_AddItemToArray(arwrk, 0, Array("", "Please Select")) Side_Navigation.Page_Type.EditValue = arwrk ' language_id Side_Navigation.language_id.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")) Side_Navigation.language_id.EditValue = arwrk ' Content Side_Navigation.Content.EditCustomAttributes = "" Side_Navigation.Content.EditValue = Side_Navigation.Content.CurrentValue ' Show_Center_Images Side_Navigation.Show_Center_Images.EditCustomAttributes = "" ' Show_Rotating_Images Side_Navigation.Show_Rotating_Images.EditCustomAttributes = "" ' Show_Wallpaper Side_Navigation.Show_Wallpaper.EditCustomAttributes = "" ' Thumb_Image Side_Navigation.Thumb_Image.EditCustomAttributes = "" If Not IsNull(Side_Navigation.Thumb_Image.Upload.DbValue) Then Side_Navigation.Thumb_Image.EditValue = Side_Navigation.Thumb_Image.Upload.DbValue Side_Navigation.Thumb_Image.ImageAlt = "" Else Side_Navigation.Thumb_Image.EditValue = "" End If ' Image Side_Navigation.Image.EditCustomAttributes = "" If Not IsNull(Side_Navigation.Image.Upload.DbValue) Then Side_Navigation.Image.EditValue = Side_Navigation.Image.Upload.DbValue Side_Navigation.Image.ImageAlt = "" Else Side_Navigation.Image.EditValue = "" End If ' Navigation_Bar Side_Navigation.Navigation_Bar.EditCustomAttributes = "" Redim arwrk(1, 1) arwrk(0, 0) = "1" arwrk(1, 0) = "Top" arwrk(0, 1) = "2" arwrk(1, 1) = "Left" arwrk = ew_AddItemToArray(arwrk, 0, Array("", "Please Select")) Side_Navigation.Navigation_Bar.EditValue = arwrk ' View_Order Side_Navigation.View_Order.EditCustomAttributes = "" Redim arwrk(1, 9) arwrk(0, 0) = "1" arwrk(1, 0) = "1" arwrk(0, 1) = "2" arwrk(1, 1) = "2" arwrk(0, 2) = "3" arwrk(1, 2) = "3" arwrk(0, 3) = "4" arwrk(1, 3) = "4" arwrk(0, 4) = "5" arwrk(1, 4) = "5" arwrk(0, 5) = "6" arwrk(1, 5) = "6" arwrk(0, 6) = "7" arwrk(1, 6) = "7" arwrk(0, 7) = "8" arwrk(1, 7) = "8" arwrk(0, 8) = "9" arwrk(1, 8) = "9" arwrk(0, 9) = "10" arwrk(1, 9) = "10" arwrk = ew_AddItemToArray(arwrk, 0, Array("", "Please Select")) Side_Navigation.View_Order.EditValue = arwrk ' Hide Side_Navigation.Hide.EditCustomAttributes = "" ElseIf Side_Navigation.RowType = EW_ROWTYPE_EDIT Then ' Edit row ElseIf Side_Navigation.RowType = EW_ROWTYPE_SEARCH Then ' Search row End If ' Call Row Rendered event Call Side_Navigation.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 = Side_Navigation.SqlKeyFilter If Side_Navigation.id.CurrentValue = "" Or IsNull(Side_Navigation.id.CurrentValue) Then bCheckKey = False Else sFilter = Replace(sFilter, "@id@", ew_AdjustSql(Side_Navigation.id.CurrentValue)) ' Replace key value End If If Not IsNumeric(Side_Navigation.id.CurrentValue) Then bCheckKey = False End If If bCheckKey Then Set rsChk = Side_Navigation.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)" Side_Navigation.CurrentFilter = sFilter sSql = Side_Navigation.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 Side_Navigation.Navigation_Name.SetDbValue(Side_Navigation.Navigation_Name.CurrentValue, Null) rs("Navigation_Name") = Side_Navigation.Navigation_Name.DbValue ' Field Page_Type Call Side_Navigation.Page_Type.SetDbValue(Side_Navigation.Page_Type.CurrentValue, Null) rs("Page_Type") = Side_Navigation.Page_Type.DbValue ' Field language_id Call Side_Navigation.language_id.SetDbValue(Side_Navigation.language_id.CurrentValue, Null) rs("language_id") = Side_Navigation.language_id.DbValue ' Field Content Call Side_Navigation.Content.SetDbValue(Side_Navigation.Content.CurrentValue, Null) rs("Content") = Side_Navigation.Content.DbValue ' Field Show_Center_Images Call Side_Navigation.Show_Center_Images.SetDbValue((Side_Navigation.Show_Center_Images.CurrentValue <> "" And Not IsNull(Side_Navigation.Show_Center_Images.CurrentValue)), Null) rs("Show_Center_Images") = Side_Navigation.Show_Center_Images.DbValue ' Field Show_Rotating_Images Call Side_Navigation.Show_Rotating_Images.SetDbValue((Side_Navigation.Show_Rotating_Images.CurrentValue <> "" And Not IsNull(Side_Navigation.Show_Rotating_Images.CurrentValue)), Null) rs("Show_Rotating_Images") = Side_Navigation.Show_Rotating_Images.DbValue ' Field Show_Wallpaper Call Side_Navigation.Show_Wallpaper.SetDbValue((Side_Navigation.Show_Wallpaper.CurrentValue <> "" And Not IsNull(Side_Navigation.Show_Wallpaper.CurrentValue)), Null) rs("Show_Wallpaper") = Side_Navigation.Show_Wallpaper.DbValue ' Field Thumb_Image Call Side_Navigation.Thumb_Image.Upload.SaveToSession() ' Save file value to Session Side_Navigation.Thumb_Image.Upload.DbValue = rs("Thumb_Image") ' Get original value If IsNull(Side_Navigation.Thumb_Image.Upload.Value) Then rs("Thumb_Image") = Null Else rs("Thumb_Image") = ew_UploadFileNameEx(ew_UploadPathEx(True, EW_UPLOAD_DEST_PATH), Side_Navigation.Thumb_Image.Upload.FileName) End If ' Field Image Call Side_Navigation.Image.Upload.SaveToSession() ' Save file value to Session Side_Navigation.Image.Upload.DbValue = rs("Image") ' Get original value If IsNull(Side_Navigation.Image.Upload.Value) Then rs("Image") = Null Else rs("Image") = ew_UploadFileNameEx(ew_UploadPathEx(True, EW_UPLOAD_DEST_PATH), Side_Navigation.Image.Upload.FileName) End If ' Field Navigation_Bar Call Side_Navigation.Navigation_Bar.SetDbValue(Side_Navigation.Navigation_Bar.CurrentValue, Null) rs("Navigation_Bar") = Side_Navigation.Navigation_Bar.DbValue ' Field View_Order Call Side_Navigation.View_Order.SetDbValue(Side_Navigation.View_Order.CurrentValue, Null) rs("View_Order") = Side_Navigation.View_Order.DbValue ' Field Hide Call Side_Navigation.Hide.SetDbValue((Side_Navigation.Hide.CurrentValue <> "" And Not IsNull(Side_Navigation.Hide.CurrentValue)), Null) rs("Hide") = Side_Navigation.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 = Side_Navigation.Row_Inserting(rs) If bInsertRow Then ' Field Thumb_Image If Not IsNull(Side_Navigation.Thumb_Image.Upload.Value) Then Call ew_SaveFile(ew_UploadPathEx(True, EW_UPLOAD_DEST_PATH), rs("Thumb_Image"), Side_Navigation.Thumb_Image.Upload.Value) If Side_Navigation.Thumb_Image.Upload.Action = "2" Or Side_Navigation.Thumb_Image.Upload.Action = "3" Then ' Update/Remove If Side_Navigation.Thumb_Image.Upload.DbValue <> "" Then ew_DeleteFile ew_UploadPathEx(True, EW_UPLOAD_DEST_PATH) & Side_Navigation.Thumb_Image.Upload.DbValue End If ' Field Image If Not IsNull(Side_Navigation.Image.Upload.Value) Then Call ew_SaveFile(ew_UploadPathEx(True, EW_UPLOAD_DEST_PATH), rs("Image"), Side_Navigation.Image.Upload.Value) If Side_Navigation.Image.Upload.Action = "2" Or Side_Navigation.Image.Upload.Action = "3" Then ' Update/Remove If Side_Navigation.Image.Upload.DbValue <> "" Then ew_DeleteFile ew_UploadPathEx(True, EW_UPLOAD_DEST_PATH) & Side_Navigation.Image.Upload.DbValue End If ' 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 Side_Navigation.CancelMessage <> "" Then Session(EW_SESSION_MESSAGE) = Side_Navigation.CancelMessage Side_Navigation.CancelMessage = "" Else Session(EW_SESSION_MESSAGE) = "Insert cancelled" End If AddRow = False End If rs.Close Set rs = Nothing If AddRow Then Side_Navigation.id.DbValue = rsnew("id") ' Call Row Inserted event Call Side_Navigation.Row_Inserted(rsnew) End If ' Field Thumb_Image Call Side_Navigation.Thumb_Image.Upload.RemoveFromSession() ' Remove file value from Session ' Field Image Call Side_Navigation.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() Server.ScriptTimeout=1000 '***Response.Write "Page Load" End Sub ' Page Unload event Sub Page_Unload() '***Response.Write "Page Unload" End Sub %>