<% ' UltraApps Portal - FREE edition, Version 1.5 ' (C) Copyright 2001 by UltraApps ' This program may be used and modified for your own use ' so long as this copyright notice and this comment remain intact. ' You are not permitted to sell or distribute modified version of this software ' View files/license.html for full Legal Information ' ' Filename:Classifieds.asp ' Generated with CodeCharge 2.0.1 '------------------------------- ' Classifieds CustomIncludes begin %> <% ' Classifieds CustomIncludes end '------------------------------- '=============================== ' Save Page and File Name available into variables '------------------------------- sFileName = "Classifieds.asp" sTemplateFileName = "Classifieds.html" '=============================== '=============================== ' Classifieds PageSecurity begin ' Classifieds PageSecurity end '=============================== '=============================== ' Classifieds Open Event begin ' Classifieds Open Event end '=============================== '=============================== ' Classifieds OpenAnyPage Event begin ' Classifieds OpenAnyPage Event end '=============================== '=============================== 'Save the name of the form and type of action into the variables '------------------------------- sAction = GetParam("FormAction") sForm = GetParam("FormName") '=============================== ' Classifieds Show begin '=============================== ' Display page '------------------------------- ' Load HTML template for this page '------------------------------- LoadTemplate sAppPath & sTemplateFileName, "main" '------------------------------- ' Load HTML template of Header and Footer '------------------------------- LoadTemplate sHeaderFileName, "Header" LoadTemplate sFooterFileName, "Footer" '------------------------------- SetVar "FileName", sFileName '------------------------------- ' Step through each form '------------------------------- Header_Show Footer_Show Search_Show Classifieds_Show '------------------------------- ' Process page templates '------------------------------- Parse "Header", False Parse "Footer", False Parse "main", False '------------------------------- ' Output the page to the browser '------------------------------- Response.write PrintVar("main") ' Classifieds Show end '------------------------------- ' Destroy all object variables '------------------------------- ' Classifieds Close Event begin ' Classifieds Close Event end cn.Close Set cn = Nothing UnloadTemplate '=============================== '=============================== ' Display Search Form '------------------------------- Sub Search_Show() Dim sFormTitle: sFormTitle = "Search" Dim sActionFileName: sActionFileName = "Classifieds.asp" '------------------------------- ' Search Open Event begin ' Search Open Event end '------------------------------- SetVar "FormTitle", sFormTitle SetVar "ActionPage", sActionFileName '------------------------------- ' Set variables with search parameters '------------------------------- fldsearch = GetParam("search") fldad_category_id = GetParam("ad_category_id") '------------------------------- ' Search Show begin '------------------------------- '------------------------------- ' Search Show Event begin ' Search Show Event end '------------------------------- SetVar "search", ToHTML(fldsearch) SetVar "SearchLBad_category_id", "" SetVar "Selected", "" SetVar "ID", "" SetVar "Value", "Any" Parse "SearchLBad_category_id", True openrs rsad_category_id, "select ad_category_id, ad_category from ad_categories order by 2" while not rsad_category_id.EOF SetVar "ID", GetValue(rsad_category_id, 0) : SetVar "Value", GetValue(rsad_category_id, 1) if cstr(GetValue(rsad_category_id, 0)) = cstr(fldad_category_id) then SetVar "Selected", "SELECTED" else SetVar "Selected", "" Parse "SearchLBad_category_id", True rsad_category_id.MoveNext wend set rsad_category_id = nothing '------------------------------- ' Search Show end '------------------------------- '------------------------------- ' Search Close Event begin ' Search Close Event end '------------------------------- Parse "FormSearch", False End Sub '=============================== '=============================== ' Display Grid Form '------------------------------- Sub Classifieds_Show() '------------------------------- ' Initialize variables '------------------------------- Dim rs Dim sWhere : sWhere = "" Dim sOrder : sOrder = "" Dim sSQL : sSQL = "" Dim sFormTitle: sFormTitle = "Classifieds" Dim HasParam : HasParam = false Dim iSort : iSort = "" Dim iSorted : iSorted = "" Dim sDirection : sDirection = "" Dim sSortParams : sSortParams = "" Dim iRecordsPerPage : iRecordsPerPage = 20 Dim iCounter : iCounter = 0 Dim iPage : iPage = 0 Dim bEof : bEof = False Dim sActionFileName : sActionFileName = "AdAdd.asp" SetVar "TransitParams", "ad_category_id=" & ToURL(GetParam("ad_category_id")) & "&search=" & ToURL(GetParam("search")) & "&" SetVar "FormParams", "ad_category_id=" & ToURL(GetParam("ad_category_id")) & "&search=" & ToURL(GetParam("search")) & "&" '------------------------------- ' Build WHERE statement '------------------------------- pad_category_id = GetParam("ad_category_id") if IsNumeric(pad_category_id) and not isEmpty(pad_category_id) then pad_category_id = ToSQL(pad_category_id, "Number") else pad_category_id = Empty if not isEmpty(pad_category_id) then HasParam = true sWhere = sWhere & "a.[ad_category_id]=" & pad_category_id end if if HasParam then sWhere = " AND (ad_active=1 AND ad_date_expires > now()) AND (" & sWhere & ")" else sWhere = " AND ad_active=1 AND ad_date_expires > now()" end if '------------------------------- ' Build ORDER BY statement '------------------------------- sOrder = " order by a.ad_date_posted Desc" iSort = GetParam("FormClassifieds_Sorting") iSorted = GetParam("FormClassifieds_Sorted") sDirection = "" if IsEmpty(iSort) then SetVar "Form_Sorting", "" else if iSort = iSorted then SetVar "Form_Sorting", "" sDirection = " DESC" sSortParams = "FormClassifieds_Sorting=" & iSort & "&FormClassifieds_Sorted=" & iSort & "&" else SetVar "Form_Sorting", iSort sDirection = " ASC" sSortParams = "FormClassifieds_Sorting=" & iSort & "&FormClassifieds_Sorted=" & "&" end if if iSort = 1 then sOrder = " order by a.[ad_date_posted]" & sDirection if iSort = 2 then sOrder = " order by a1.[ad_category]" & sDirection if iSort = 3 then sOrder = " order by a.[ad_title]" & sDirection if iSort = 4 then sOrder = " order by a.[ad_location]" & sDirection if iSort = 5 then sOrder = " order by a.[ad_price]" & sDirection end if '------------------------------- ' Build base SQL statement '------------------------------- sSQL = "select [a].[ad_category_id] as a_ad_category_id, " & _ "[a].[ad_date_posted] as a_ad_date_posted, " & _ "[a].[ad_id] as a_ad_id, " & _ "[a].[ad_location] as a_ad_location, " & _ "[a].[ad_price] as a_ad_price, " & _ "[a].[ad_title] as a_ad_title, " & _ "[a1].[ad_category_id] as a1_ad_category_id, " & _ "[a1].[ad_category] as a1_ad_category " & _ " from [ads] a, [ad_categories] a1" & _ " where [a1].[ad_category_id]=a.[ad_category_id] " '------------------------------- '------------------------------- ' Classifieds Open Event begin searchstr = GetParam("search") if searchstr <> "" then sWhere = sWhere & " AND (a.[ad_title] LIKE '%" & replace(searchstr, "'", "''") & "%' OR a.[ad_text] LIKE '%" & replace(searchstr, "'", "''") & "%')" ' Classifieds Open Event end '------------------------------- '------------------------------- ' Assemble full SQL statement '------------------------------- sSQL = sSQL & sWhere & sOrder '------------------------------- SetVar "FormTitle", sFormTitle '------------------------------- ' Process the link to the record page '------------------------------- SetVar "FormAction", sActionFileName '------------------------------- '------------------------------- ' Process the parameters for sorting '------------------------------- SetVar "SortParams", sSortParams '------------------------------- '------------------------------- ' Open the recordset '------------------------------- openrs rs, sSQL '------------------------------- '------------------------------- ' Process empty recordset '------------------------------- if rs.eof then set rs = nothing SetVar "DListClassifieds", "" Parse "ClassifiedsNoRecords", False SetVar "ClassifiedsNavigator", "" Parse "FormClassifieds", False exit sub end if '------------------------------- '------------------------------- ' Initialize page counter and records per page '------------------------------- iRecordsPerPage = 20 iCounter = 0 '------------------------------- '------------------------------- ' Process page scroller '------------------------------- iPage = GetParam("FormClassifieds_Page") if IsEmpty(iPage) then iPage = 1 else iPage = CLng(iPage) while not rs.eof and iCounter < (iPage-1)*iRecordsPerPage rs.movenext iCounter = iCounter + 1 wend iCounter = 0 '------------------------------- '------------------------------- ' Display grid based on recordset '------------------------------- while not rs.EOF and iCounter < iRecordsPerPage '------------------------------- ' Create field variables based on database fields '------------------------------- fldad_category_id = GetValue(rs, "a1_ad_category") fldad_date_posted = GetValue(rs, "a_ad_date_posted") fldad_location = GetValue(rs, "a_ad_location") fldad_price = GetValue(rs, "a_ad_price") fldad_title_URLLink = "AdView.asp" fldad_title_ad_id = GetValue(rs, "a_ad_id") fldad_title = GetValue(rs, "a_ad_title") '------------------------------- ' Classifieds Show begin '------------------------------- '------------------------------- ' Classifieds Show Event begin if fldad_price = 0 then fldad_price = "N/A" else fldad_price = "$" & fldad_price 'fldad_price = fldad_price & "
" ' Classifieds Show Event end '------------------------------- '------------------------------- ' Replace Template fields with database values '------------------------------- SetVar "ad_date_posted", ToHTML(fldad_date_posted) SetVar "ad_category_id", ToHTML(fldad_category_id) SetVar "ad_title", fldad_title SetVar "ad_title_URLLink", fldad_title_URLLink SetVar "Prmad_title_ad_id", ToURL(fldad_title_ad_id) SetVar "ad_location", fldad_location SetVar "ad_price", fldad_price Parse "DListClassifieds", True '------------------------------- ' Classifieds Show end '------------------------------- '------------------------------- ' Move to the next record and increase record counter '------------------------------- rs.MoveNext iCounter = iCounter + 1 wend '------------------------------- '------------------------------- ' Classifieds Navigation begin '------------------------------- bEof = rs.eof if rs.eof and iPage = 1 then SetVar "ClassifiedsNavigator", "" else if bEof then SetVar "ClassifiedsNavigatorLastPage", "_" else SetVar "NextPage", (iPage + 1) end if if iPage = 1 then SetVar "ClassifiedsNavigatorFirstPage", "_" else SetVar "PrevPage", (iPage - 1) end if SetVar "ClassifiedsCurrentPage", iPage Parse "ClassifiedsNavigator", False end if '------------------------------- ' Classifieds Navigation end '------------------------------- '------------------------------- ' Finish form processing '------------------------------- set rs = nothing SetVar "ClassifiedsNoRecords", "" Parse "FormClassifieds", False '------------------------------- ' Classifieds Close Event begin ' Classifieds Close Event end '------------------------------- End Sub '=============================== %>