<%@ CodePage=65001 %> <% Const EW_PAGE_ID = "add" Const EW_TABLE_NAME = "videogallery" %> <% 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 videogallery.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 videogallery.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 videogallery.CurrentAction = "C" ' Copy Record Else videogallery.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 videogallery.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(videogallery.ReturnUrl) ' Clean up and return End If Case "A" ' Add new record videogallery.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(videogallery.KeyUrl(videogallery.ReturnUrl, "")) ' Clean up and return Else Call RestoreFormValues() ' Add failed, restore form values End If End Select ' Render row based on row type videogallery.RowType = EW_ROWTYPE_ADD ' add ' Render add type Call RenderRow() %>

Add to TABLE: Video Gallery

Go Back

<% If Session(EW_SESSION_MESSAGE) <> "" Then ' Mesasge in Session, display %>

<%= Session(EW_SESSION_MESSAGE) %>

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

> > > > > > > > > > > > >
Category *
Title *
Description
Thumb Image
Flv Video Name *
View Order
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 videogallery = 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 videogallery.Thumb_Image.Upload.UploadFile() Then ' No action required Else Response.Write videogallery.Thumb_Image.Upload.Message Response.End End If End Function %> <% ' Load default values Function LoadDefaultValues() videogallery.CreatedDate.CurrentValue = Date() End Function %> <% ' Load form values Function LoadFormValues() ' Load from form videogallery.Category.FormValue = objForm.GetValue("x_Category") videogallery.Title.FormValue = objForm.GetValue("x_Title") videogallery.description.FormValue = objForm.GetValue("x_description") videogallery.Flv_File_Name.FormValue = objForm.GetValue("x_Flv_File_Name") videogallery.ViewOrder.FormValue = objForm.GetValue("x_ViewOrder") videogallery.CreatedDate.FormValue = objForm.GetValue("x_CreatedDate") videogallery.CreatedDate.CurrentValue = ew_UnFormatDateTime(videogallery.CreatedDate.CurrentValue, 7) End Function ' Restore form values Function RestoreFormValues() videogallery.Category.CurrentValue = videogallery.Category.FormValue videogallery.Title.CurrentValue = videogallery.Title.FormValue videogallery.description.CurrentValue = videogallery.description.FormValue videogallery.Flv_File_Name.CurrentValue = videogallery.Flv_File_Name.FormValue videogallery.ViewOrder.CurrentValue = videogallery.ViewOrder.FormValue videogallery.CreatedDate.CurrentValue = videogallery.CreatedDate.FormValue videogallery.CreatedDate.CurrentValue = ew_UnFormatDateTime(videogallery.CreatedDate.CurrentValue, 7) End Function %> <% ' Load row based on key values Function LoadRow() Dim rs, sSql, sFilter sFilter = videogallery.SqlKeyFilter If Not IsNumeric(videogallery.id.CurrentValue) Then LoadRow = False ' Invalid key, exit Exit Function End If sFilter = Replace(sFilter, "@id@", ew_AdjustSql(videogallery.id.CurrentValue)) ' Replace key value ' Call Row Selecting event Call videogallery.Row_Selecting(sFilter) ' Load sql based on filter videogallery.CurrentFilter = sFilter sSql = videogallery.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 videogallery.Row_Selected(rs) End If rs.Close Set rs = Nothing End Function ' Load row values from recordset Sub LoadRowValues(rs) videogallery.id.DbValue = rs("id") videogallery.Category.DbValue = rs("Category") videogallery.Title.DbValue = rs("Title") videogallery.description.DbValue = rs("description") videogallery.Thumb_Image.Upload.DbValue = rs("Thumb_Image") videogallery.Flv_File_Name.DbValue = rs("Flv_File_Name") videogallery.ViewOrder.DbValue = rs("ViewOrder") videogallery.CreatedDate.DbValue = rs("CreatedDate") End Sub %> <% ' Render row values based on field settings Sub RenderRow() ' Call Row Rendering event Call videogallery.Row_Rendering() ' Common render codes for all row types ' Category videogallery.Category.CellCssStyle = "" videogallery.Category.CellCssClass = "" ' Title videogallery.Title.CellCssStyle = "" videogallery.Title.CellCssClass = "" ' description videogallery.description.CellCssStyle = "" videogallery.description.CellCssClass = "" ' Thumb_Image videogallery.Thumb_Image.CellCssStyle = "" videogallery.Thumb_Image.CellCssClass = "" ' Flv_File_Name videogallery.Flv_File_Name.CellCssStyle = "" videogallery.Flv_File_Name.CellCssClass = "" ' ViewOrder videogallery.ViewOrder.CellCssStyle = "" videogallery.ViewOrder.CellCssClass = "" ' CreatedDate videogallery.CreatedDate.CellCssStyle = "" videogallery.CreatedDate.CellCssClass = "" If videogallery.RowType = EW_ROWTYPE_VIEW Then ' View row ElseIf videogallery.RowType = EW_ROWTYPE_ADD Then ' Add row ' Category videogallery.Category.EditCustomAttributes = "" sSqlWrk = "SELECT [ID], [Category_Name] FROM [Gallery_Category]" sSqlWrk = sSqlWrk & " ORDER BY [Category_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")) videogallery.Category.EditValue = arwrk ' Title videogallery.Title.EditCustomAttributes = "" videogallery.Title.EditValue = ew_HtmlEncode(videogallery.Title.CurrentValue) ' description videogallery.description.EditCustomAttributes = "" videogallery.description.EditValue = ew_HtmlEncode(videogallery.description.CurrentValue) ' Thumb_Image videogallery.Thumb_Image.EditCustomAttributes = "" If Not IsNull(videogallery.Thumb_Image.Upload.DbValue) Then videogallery.Thumb_Image.EditValue = videogallery.Thumb_Image.Upload.DbValue videogallery.Thumb_Image.ImageAlt = "" Else videogallery.Thumb_Image.EditValue = "" End If ' Flv_File_Name videogallery.Flv_File_Name.EditCustomAttributes = "" videogallery.Flv_File_Name.EditValue = ew_HtmlEncode(videogallery.Flv_File_Name.CurrentValue) ' ViewOrder videogallery.ViewOrder.EditCustomAttributes = "" videogallery.ViewOrder.EditValue = videogallery.ViewOrder.CurrentValue ' CreatedDate videogallery.CreatedDate.EditCustomAttributes = "" videogallery.CreatedDate.EditValue = ew_FormatDateTime(videogallery.CreatedDate.CurrentValue, 7) ElseIf videogallery.RowType = EW_ROWTYPE_EDIT Then ' Edit row ElseIf videogallery.RowType = EW_ROWTYPE_SEARCH Then ' Search row End If ' Call Row Rendered event Call videogallery.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 = videogallery.SqlKeyFilter If videogallery.id.CurrentValue = "" Or IsNull(videogallery.id.CurrentValue) Then bCheckKey = False Else sFilter = Replace(sFilter, "@id@", ew_AdjustSql(videogallery.id.CurrentValue)) ' Replace key value End If If Not IsNumeric(videogallery.id.CurrentValue) Then bCheckKey = False End If If bCheckKey Then Set rsChk = videogallery.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 If videogallery.Flv_File_Name.CurrentValue <> "" Then ' Check field with unique index sFilter = "([Flv_File_Name] = '" & ew_AdjustSql(videogallery.Flv_File_Name.CurrentValue) & "')" Set rsChk = videogallery.LoadRs(sFilter) If Not (rsChk Is Nothing) Then Session(EW_SESSION_MESSAGE) = "Duplicate value for index or primary key -- [Flv_File_Name], value = " & videogallery.Flv_File_Name.CurrentValue rsChk.Close Set rsChk = Nothing AddRow = False Exit Function End If End If ' Add new record sFilter = "(0 = 1)" videogallery.CurrentFilter = sFilter sSql = videogallery.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 Category Call videogallery.Category.SetDbValue(videogallery.Category.CurrentValue, Null) rs("Category") = videogallery.Category.DbValue ' Field Title Call videogallery.Title.SetDbValue(videogallery.Title.CurrentValue, Null) rs("Title") = videogallery.Title.DbValue ' Field description Call videogallery.description.SetDbValue(videogallery.description.CurrentValue, Null) rs("description") = videogallery.description.DbValue ' Field Thumb_Image Call videogallery.Thumb_Image.Upload.SaveToSession() ' Save file value to Session videogallery.Thumb_Image.Upload.DbValue = rs("Thumb_Image") ' Get original value If IsNull(videogallery.Thumb_Image.Upload.Value) Then rs("Thumb_Image") = Null Else rs("Thumb_Image") = ew_UploadFileNameEx(ew_UploadPathEx(True, "thumbnails/"), videogallery.Thumb_Image.Upload.FileName) End If ' Field Flv_File_Name Call videogallery.Flv_File_Name.SetDbValue(videogallery.Flv_File_Name.CurrentValue, Null) rs("Flv_File_Name") = videogallery.Flv_File_Name.DbValue ' Field ViewOrder Call videogallery.ViewOrder.SetDbValue(videogallery.ViewOrder.CurrentValue, Null) rs("ViewOrder") = videogallery.ViewOrder.DbValue ' Field CreatedDate Call videogallery.CreatedDate.SetDbValue(ew_UnFormatDateTime(videogallery.CreatedDate.CurrentValue, 7), Null) rs("CreatedDate") = videogallery.CreatedDate.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 = videogallery.Row_Inserting(rs) If bInsertRow Then ' Field Thumb_Image If Not IsNull(videogallery.Thumb_Image.Upload.Value) Then Call ew_SaveFile(ew_UploadPathEx(True, "thumbnails/"), rs("Thumb_Image"), videogallery.Thumb_Image.Upload.Value) If videogallery.Thumb_Image.Upload.Action = "2" Or videogallery.Thumb_Image.Upload.Action = "3" Then ' Update/Remove If videogallery.Thumb_Image.Upload.DbValue <> "" Then ew_DeleteFile ew_UploadPathEx(True, "thumbnails/") & videogallery.Thumb_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 videogallery.CancelMessage <> "" Then Session(EW_SESSION_MESSAGE) = videogallery.CancelMessage videogallery.CancelMessage = "" Else Session(EW_SESSION_MESSAGE) = "Insert cancelled" End If AddRow = False End If rs.Close Set rs = Nothing If AddRow Then videogallery.id.DbValue = rsnew("id") ' Call Row Inserted event Call videogallery.Row_Inserted(rsnew) End If ' Field Thumb_Image Call videogallery.Thumb_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 %>