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