<%@ CodePage=65001 %> <% Const EW_PAGE_ID = "delete" Const EW_TABLE_NAME = "Rotator_Photos" %> <% 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 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 Rotator_Photos.ID.QueryStringValue = Request.QueryString("ID") If Not IsNumeric(Rotator_Photos.ID.QueryStringValue) Then Call Page_Terminate(Rotator_Photos.ReturnUrl) ' Prevent sql injection, exit End If sKey = sKey & Rotator_Photos.ID.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(Rotator_Photos.ReturnUrl) ' No key specified, exit ' Build filter For i = 0 to nKeySelected - 1 sKey = Trim(arRecKeys(i)) sFilter = sFilter & "(" ' Set up key field sKeyFld = sKey If Not IsNumeric(sKeyFld) Then Call Page_Terminate(Rotator_Photos.ReturnUrl) ' Prevent sql injection, exit End If sFilter = sFilter & "[ID]=" & 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 Rotator_Photos class, Rotator_Photosinfo.asp Rotator_Photos.CurrentFilter = sFilter ' Get action If Request.Form("a_delete").Count > 0 Then Rotator_Photos.CurrentAction = Request.Form("a_delete") Else Rotator_Photos.CurrentAction = "D" ' Delete record directly End If Select Case Rotator_Photos.CurrentAction Case "D" ' Delete Rotator_Photos.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(Rotator_Photos.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(Rotator_Photos.ReturnUrl) ' Return to caller End If %>

Delete from TABLE: Rotator Photos

Go Back

<% If Session(EW_SESSION_MESSAGE) <> "" Then %>

<%= Session(EW_SESSION_MESSAGE) %>

<% Session(EW_SESSION_MESSAGE) = "" ' Clear message End If %>

<% For i = 0 to nKeySelected - 1 %> <% Next %> <% nRecCount = 0 i = 0 Do While (Not rs.Eof) nRecCount = nRecCount + 1 ' Set row class and style Rotator_Photos.CssClass = "ewTableRow" Rotator_Photos.CssStyle = "" ' Display alternate color for rows If nRecCount Mod 2 <> 1 Then Rotator_Photos.CssClass = "ewTableAltRow" End If ' Get the field contents Call LoadRowValues(rs) ' Render row value Rotator_Photos.RowType = EW_ROWTYPE_VIEW ' view Call RenderRow() %> > > ><%= Rotator_Photos.ID.ViewValue %> > ><%= Rotator_Photos.Photo_Name.ViewValue %> > ><%= Rotator_Photos.zType.ViewValue %> > ><%= Rotator_Photos.CreatedDate.ViewValue %> <% rs.MoveNext Loop rs.Close Set rs = Nothing %>
ID Photo Name Type Created Date

<% ' 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 Rotator_Photos = 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 = Rotator_Photos.CurrentFilter ' Set up filter (Sql Where Clause) and get Return Sql ' Sql constructor in Rotator_Photos class, Rotator_Photosinfo.asp Rotator_Photos.CurrentFilter = sWrkFilter sSql = Rotator_Photos.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 = Rotator_Photos.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") ew_DeleteFile ew_UploadPathEx(True, "RotatorImages/") & rs("Photo") 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 Rotator_Photos.CancelMessage <> "" Then Session(EW_SESSION_MESSAGE) = Rotator_Photos.CancelMessage Rotator_Photos.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 Rotator_Photos.Recordset_Deleted(rsold) rsold.Close Set rsold = Nothing End Function %> <% ' Load recordset Function LoadRecordset() ' Call Recordset Selecting event Call Rotator_Photos.Recordset_Selecting(Rotator_Photos.CurrentFilter) ' Load list page sql Dim sSql sSql = Rotator_Photos.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 Rotator_Photos.Recordset_Selected(rs) Set LoadRecordset = rs End Function %> <% ' Load row based on key values Function LoadRow() Dim rs, sSql, sFilter sFilter = Rotator_Photos.SqlKeyFilter If Not IsNumeric(Rotator_Photos.ID.CurrentValue) Then LoadRow = False ' Invalid key, exit Exit Function End If sFilter = Replace(sFilter, "@ID@", ew_AdjustSql(Rotator_Photos.ID.CurrentValue)) ' Replace key value ' Call Row Selecting event Call Rotator_Photos.Row_Selecting(sFilter) ' Load sql based on filter Rotator_Photos.CurrentFilter = sFilter sSql = Rotator_Photos.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 Rotator_Photos.Row_Selected(rs) End If rs.Close Set rs = Nothing End Function ' Load row values from recordset Sub LoadRowValues(rs) Rotator_Photos.ID.DbValue = rs("ID") Rotator_Photos.Photo_Name.DbValue = rs("Photo_Name") Rotator_Photos.Photo.Upload.DbValue = rs("Photo") Rotator_Photos.zType.DbValue = rs("Type") Rotator_Photos.hyperlink.DbValue = rs("hyperlink") Rotator_Photos.CreatedDate.DbValue = rs("CreatedDate") End Sub %> <% ' Render row values based on field settings Sub RenderRow() ' Call Row Rendering event Call Rotator_Photos.Row_Rendering() ' Common render codes for all row types ' ID Rotator_Photos.ID.CellCssStyle = "" Rotator_Photos.ID.CellCssClass = "" ' Photo_Name Rotator_Photos.Photo_Name.CellCssStyle = "" Rotator_Photos.Photo_Name.CellCssClass = "" ' Type Rotator_Photos.zType.CellCssStyle = "" Rotator_Photos.zType.CellCssClass = "" ' CreatedDate Rotator_Photos.CreatedDate.CellCssStyle = "" Rotator_Photos.CreatedDate.CellCssClass = "" If Rotator_Photos.RowType = EW_ROWTYPE_VIEW Then ' View row ' ID Rotator_Photos.ID.ViewValue = Rotator_Photos.ID.CurrentValue Rotator_Photos.ID.CssStyle = "" Rotator_Photos.ID.CssClass = "" Rotator_Photos.ID.ViewCustomAttributes = "" ' Photo_Name Rotator_Photos.Photo_Name.ViewValue = Rotator_Photos.Photo_Name.CurrentValue Rotator_Photos.Photo_Name.CssStyle = "" Rotator_Photos.Photo_Name.CssClass = "" Rotator_Photos.Photo_Name.ViewCustomAttributes = "" ' Type If Not IsNull(Rotator_Photos.zType.CurrentValue) Then Select Case Rotator_Photos.zType.CurrentValue Case "Slides" Rotator_Photos.zType.ViewValue = "Slides" Case "Movers" Rotator_Photos.zType.ViewValue = "Movers" Case Else Rotator_Photos.zType.ViewValue = Rotator_Photos.zType.CurrentValue End Select Else Rotator_Photos.zType.ViewValue = Null End If Rotator_Photos.zType.CssStyle = "" Rotator_Photos.zType.CssClass = "" Rotator_Photos.zType.ViewCustomAttributes = "" ' CreatedDate Rotator_Photos.CreatedDate.ViewValue = Rotator_Photos.CreatedDate.CurrentValue Rotator_Photos.CreatedDate.ViewValue = ew_FormatDateTime(Rotator_Photos.CreatedDate.ViewValue, 7) Rotator_Photos.CreatedDate.CssStyle = "" Rotator_Photos.CreatedDate.CssClass = "" Rotator_Photos.CreatedDate.ViewCustomAttributes = "" ' ID ' *** view refer script Rotator_Photos.ID.HrefValue = "" ' Photo_Name ' *** view refer script Rotator_Photos.Photo_Name.HrefValue = "" ' Type ' *** view refer script Rotator_Photos.zType.HrefValue = "" ' CreatedDate ' *** view refer script Rotator_Photos.CreatedDate.HrefValue = "" ElseIf Rotator_Photos.RowType = EW_ROWTYPE_ADD Then ' Add row ElseIf Rotator_Photos.RowType = EW_ROWTYPE_EDIT Then ' Edit row ElseIf Rotator_Photos.RowType = EW_ROWTYPE_SEARCH Then ' Search row End If ' Call Row Rendered event Call Rotator_Photos.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 %>