%@ CodePage=65001 LCID=14337 %> <% Const EW_PAGE_ID = "delete" 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 Dim sKey, bSingleDelete, arRecKeys, nKeySelected Dim sKeyFld, arKeyFlds Dim i Dim sFilter Dim nRecCount ' Load Key Parameters sKey = "" bSingleDelete = True ' Initialize as single delete nKeySelected = 0 ' Initialize selected key count If Request.QueryString("id").Count > 0 Then Content.id.QueryStringValue = Request.QueryString("id") If Not IsNumeric(Content.id.QueryStringValue) Then Call Page_Terminate(Content.ReturnUrl) ' Prevent sql injection, exit End If sKey = sKey & Content.id.QueryStringValue Else bSingleDelete = False End If If Request.QueryString("Navigation_Name").Count > 0 Then Content.Navigation_Name.QueryStringValue = Request.QueryString("Navigation_Name") If Not IsNumeric(Content.Navigation_Name.QueryStringValue) Then Call Page_Terminate(Content.ReturnUrl) ' Prevent sql injection, exit End If If sKey <> "" Then sKey = sKey & EW_COMPOSITE_KEY_SEPARATOR sKey = sKey & Content.Navigation_Name.QueryStringValue Else bSingleDelete = False End If If Request.QueryString("Language_Name").Count > 0 Then Content.Language_Name.QueryStringValue = Request.QueryString("Language_Name") If Not IsNumeric(Content.Language_Name.QueryStringValue) Then Call Page_Terminate(Content.ReturnUrl) ' Prevent sql injection, exit End If If sKey <> "" Then sKey = sKey & EW_COMPOSITE_KEY_SEPARATOR sKey = sKey & Content.Language_Name.QueryStringValue Else bSingleDelete = False End If If bSingleDelete Then nKeySelected = 1 ' Set up key selected count Redim arRecKeys(0) ' Set up key arRecKeys(0) = sKey Else If Request.Form("key_m").Count > 0 Then ' Key in form nKeySelected = Request.Form("key_m").Count ' Set up key selected count Redim arRecKeys(nKeySelected-1) For i = 1 to nKeySelected ' Set up keys arRecKeys(i-1) = Request.Form("key_m")(i) Next End If End If If nKeySelected <= 0 Then Call Page_Terminate(Content.ReturnUrl) ' No key specified, exit ' Build filter For i = 0 to nKeySelected - 1 sKey = Trim(arRecKeys(i)) sFilter = sFilter & "(" arKeyFlds = Split(sKey, EW_COMPOSITE_KEY_SEPARATOR) ' Split key by separator If UBound(arKeyFlds) <> 2 Then Call Page_Terminate(Content.ReturnUrl) ' Invalid key, exit ' Set up key field sKeyFld = arKeyFlds(0) If Not IsNumeric(sKeyFld) Then Call Page_Terminate(Content.ReturnUrl) ' Prevent sql injection, exit End If sFilter = sFilter & "[id]=" & ew_AdjustSql(sKeyFld) & " AND " ' Set up key field sKeyFld = arKeyFlds(1) If Not IsNumeric(sKeyFld) Then Call Page_Terminate(Content.ReturnUrl) ' Prevent sql injection, exit End If sFilter = sFilter & "[Navigation_Name]=" & ew_AdjustSql(sKeyFld) & " AND " ' Set up key field sKeyFld = arKeyFlds(2) If Not IsNumeric(sKeyFld) Then Call Page_Terminate(Content.ReturnUrl) ' Prevent sql injection, exit End If sFilter = sFilter & "[Language_Name]=" & ew_AdjustSql(sKeyFld) & " AND " If Right(sFilter, 5) = " AND " Then sFilter = Left(sFilter, Len(sFilter)-5) & ") OR " Next If Right(sFilter, 4) = " OR " Then sFilter = Left(sFilter, Len(sFilter)-4) ' Set up filter (Sql Where Clause) and get Return Sql ' Sql constructor in Content class, Contentinfo.asp Content.CurrentFilter = sFilter ' Get action If Request.Form("a_delete").Count > 0 Then Content.CurrentAction = Request.Form("a_delete") Else Content.CurrentAction = "D" ' Delete record directly End If Select Case Content.CurrentAction Case "D" ' Delete Content.SendEmail = True ' Send email on delete success If DeleteRows() Then ' delete rows Session(EW_SESSION_MESSAGE) = "Delete Successful" ' Set up success message Call Page_Terminate(Content.ReturnUrl) ' Return to caller End If End Select ' Load records for display Dim rs, nTotalRecs Set rs = LoadRecordset() nTotalRecs = rs.RecordCount ' Get record count If nTotalRecs <= 0 Then ' No record found, exit rs.Close Set rs = Nothing Call Page_Terminate(Content.ReturnUrl) ' Return to caller End If %>
Delete from TABLE: Content
Go Back
<%= Session(EW_SESSION_MESSAGE) %>
<% Session(EW_SESSION_MESSAGE) = "" ' Clear message 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 DeleteRows ' - Delete Records based on current filter ' Function DeleteRows() On Error Resume Next Dim sKey, sThisKey, sKeyFld, arKeyFlds Dim rs, sSql, sWrkFilter Dim rsold DeleteRows = True sWrkFilter = Content.CurrentFilter ' Set up filter (Sql Where Clause) and get Return Sql ' Sql constructor in Content class, Contentinfo.asp Content.CurrentFilter = sWrkFilter sSql = Content.SQL Set rs = Server.CreateObject("ADODB.Recordset") rs.CursorLocation = EW_CURSORLOCATION rs.Open sSql, conn, 1, 2 If Err.Number <> 0 Then Session(EW_SESSION_MESSAGE) = Err.Description rs.Close Set rs = Nothing DeleteRows = False Exit Function ElseIf rs.Eof Then Session(EW_SESSION_MESSAGE) = "No records found" ' No record found rs.Close Set rs = Nothing DeleteRows = False Exit Function End If conn.BeginTrans ' Clone old rs object Set rsold = ew_CloneRs(rs) ' Call recordset deleting event If DeleteRows Then DeleteRows = Content.Recordset_Deleting(rs) If DeleteRows Then sKey = "" If Not rs.Eof Then rs.MoveFirst Do While Not rs.Eof sThisKey = "" If sThisKey <> "" Then sThisKey = sThisKey & EW_COMPOSITE_KEY_SEPARATOR sThisKey = sThisKey & rs("id") If sThisKey <> "" Then sThisKey = sThisKey & EW_COMPOSITE_KEY_SEPARATOR sThisKey = sThisKey & rs("Navigation_Name") If sThisKey <> "" Then sThisKey = sThisKey & EW_COMPOSITE_KEY_SEPARATOR sThisKey = sThisKey & rs("Language_Name") rs.Delete If Err.Number <> 0 Then Session(EW_SESSION_MESSAGE) = Err.Description ' Set up error message DeleteRows = False Exit Do End If If sKey <> "" Then sKey = sKey & ", " sKey = sKey & sThisKey rs.MoveNext Loop Else ' Set up error message If Content.CancelMessage <> "" Then Session(EW_SESSION_MESSAGE) = Content.CancelMessage Content.CancelMessage = "" Else Session(EW_SESSION_MESSAGE) = "Delete cancelled" End If End If If DeleteRows Then conn.CommitTrans ' Commit the changes If Err.Number <> 0 Then Session(EW_SESSION_MESSAGE) = Err.Description DeleteRows = False ' Delet failed Else End If Else conn.RollbackTrans ' Rollback changes End If rs.Close Set rs = Nothing ' Call recordset deleted event If DeleteRows Then Call Content.Recordset_Deleted(rsold) rsold.Close Set rsold = Nothing End Function %> <% ' Load recordset Function LoadRecordset() ' Call Recordset Selecting event Call Content.Recordset_Selecting(Content.CurrentFilter) ' Load list page sql Dim sSql sSql = Content.ListSQL ' Response.Write sSql ' Uncomment to show SQL for debugging ' Load recordset Dim rs Set rs = Server.CreateObject("ADODB.Recordset") rs.CursorLocation = EW_CURSORLOCATION rs.Open sSql, conn, 1, 2 ' Call Recordset Selected event Call Content.Recordset_Selected(rs) Set LoadRecordset = rs 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 ' id Content.id.CellCssStyle = "" Content.id.CellCssClass = "" ' Navigation_Name Content.Navigation_Name.CellCssStyle = "" Content.Navigation_Name.CellCssClass = "" ' Language_Name Content.Language_Name.CellCssStyle = "" Content.Language_Name.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 = "" ' CreatedDate Content.CreatedDate.CellCssStyle = "" Content.CreatedDate.CellCssClass = "" If Content.RowType = EW_ROWTYPE_VIEW Then ' View row ' id Content.id.ViewValue = Content.id.CurrentValue Content.id.CssStyle = "" Content.id.CssClass = "" Content.id.ViewCustomAttributes = "" ' Navigation_Name If Not IsNull(Content.Navigation_Name.CurrentValue) And Content.Navigation_Name.CurrentValue <> "" Then sSqlWrk = "SELECT [Navigation_Name] FROM [Side_Navigation] WHERE [id] = " & ew_AdjustSql(Content.Navigation_Name.CurrentValue) & "" Set rswrk = conn.Execute(sSqlWrk) If Not rswrk.Eof Then Content.Navigation_Name.ViewValue = rswrk("Navigation_Name") Else Content.Navigation_Name.ViewValue = Content.Navigation_Name.CurrentValue End If rswrk.Close Set rswrk = Nothing Else Content.Navigation_Name.ViewValue = Null End If Content.Navigation_Name.CssStyle = "" Content.Navigation_Name.CssClass = "" Content.Navigation_Name.ViewCustomAttributes = "" ' Language_Name If Not IsNull(Content.Language_Name.CurrentValue) And Content.Language_Name.CurrentValue <> "" Then sSqlWrk = "SELECT [Language_Name] FROM [Languages] WHERE [id] = " & ew_AdjustSql(Content.Language_Name.CurrentValue) & "" Set rswrk = conn.Execute(sSqlWrk) If Not rswrk.Eof Then Content.Language_Name.ViewValue = rswrk("Language_Name") Else Content.Language_Name.ViewValue = Content.Language_Name.CurrentValue End If rswrk.Close Set rswrk = Nothing Else Content.Language_Name.ViewValue = Null End If Content.Language_Name.CssStyle = "" Content.Language_Name.CssClass = "" Content.Language_Name.ViewCustomAttributes = "" ' Thumb_Image If Not IsNull(Content.Thumb_Image.Upload.DbValue) Then Content.Thumb_Image.ViewValue = Content.Thumb_Image.Upload.DbValue Content.Thumb_Image.ImageAlt = "" Else Content.Thumb_Image.ViewValue = "" End If Content.Thumb_Image.CssStyle = "" Content.Thumb_Image.CssClass = "" Content.Thumb_Image.ViewCustomAttributes = "" ' Image If Not IsNull(Content.Image.Upload.DbValue) Then Content.Image.ViewValue = Content.Image.Upload.DbValue Content.Image.ImageAlt = "" Else Content.Image.ViewValue = "" End If Content.Image.CssStyle = "" Content.Image.CssClass = "" Content.Image.ViewCustomAttributes = "" ' Hide If Content.Hide.CurrentValue = "1" Then Content.Hide.ViewValue = "Yes" Else Content.Hide.ViewValue = "No" End If Content.Hide.CssStyle = "" Content.Hide.CssClass = "" Content.Hide.ViewCustomAttributes = "" ' CreatedDate Content.CreatedDate.ViewValue = Content.CreatedDate.CurrentValue Content.CreatedDate.CssStyle = "" Content.CreatedDate.CssClass = "" Content.CreatedDate.ViewCustomAttributes = "" ' id ' *** view refer script Content.id.HrefValue = "" ' Navigation_Name ' *** view refer script Content.Navigation_Name.HrefValue = "" ' Language_Name ' *** view refer script Content.Language_Name.HrefValue = "" ' Thumb_Image ' *** view refer script Content.Thumb_Image.HrefValue = "" ' Image ' *** view refer script Content.Image.HrefValue = "" ' Hide ' *** view refer script Content.Hide.HrefValue = "" ' CreatedDate ' *** view refer script Content.CreatedDate.HrefValue = "" ElseIf Content.RowType = EW_ROWTYPE_ADD Then ' Add row 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 %> <% ' Page Load event Sub Page_Load() '***Response.Write "Page Load" End Sub ' Page Unload event Sub Page_Unload() '***Response.Write "Page Unload" End Sub %>