Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

84 lines
3.1KB

  1. <%
  2. Class ExportController_Class
  3. Private m_useLayout
  4. Private m_title
  5. Private Sub Class_Initialize()
  6. m_useLayout = False ' streams a file, not a page
  7. m_title = "Export"
  8. End Sub
  9. Public Property Get useLayout
  10. useLayout = m_useLayout
  11. End Property
  12. Public Property Let useLayout(v)
  13. m_useLayout = v
  14. End Property
  15. Public Property Get Title
  16. Title = m_title
  17. End Property
  18. Public Property Let Title(v)
  19. m_title = v
  20. End Property
  21. '-------------------------------------------------------------------------------------------------------------------
  22. ' GET /export/businesses : CSV of everything matching the list's search/filters (opens directly in Excel)
  23. '-------------------------------------------------------------------------------------------------------------------
  24. Public Sub businesses()
  25. Dim f, k, rs, line, n, fileName
  26. Set f = CreateObject("Scripting.Dictionary")
  27. For Each k In Array("q", "industry", "status", "show", "contacted", "phone", "sort", "dir")
  28. f(k) = Trim(CStr(Request.QueryString(k)))
  29. Next
  30. f("q") = Left(f("q"), 100)
  31. Server.ScriptTimeout = 600
  32. fileName = "businesses-" & Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & ".csv"
  33. Response.Clear
  34. Response.Buffer = True
  35. Response.CodePage = 65001
  36. Response.Charset = "utf-8"
  37. Response.ContentType = "text/csv"
  38. Response.AddHeader "Content-Disposition", "attachment; filename=""" & fileName & """"
  39. Response.Write ChrW(&HFEFF) ' UTF-8 BOM so Excel reads accents correctly
  40. Response.Write "Business,Contact,Industry,Phone,Email,Website,Address,City,State,Zip,Status,Customer,Last contacted,Next action" & vbCrLf
  41. Set rs = BusinessRepository().ExportRows(f)
  42. n = 0
  43. Do While Not rs.EOF
  44. line = Csv_Cell(rs("name")) & "," & Csv_Cell(rs("contact_name")) & "," & Csv_Cell(rs("industry_name")) & "," & _
  45. Csv_Cell(rs("phone")) & "," & Csv_Cell(rs("email")) & "," & Csv_Cell(rs("website")) & "," & _
  46. Csv_Cell(rs("address1")) & "," & Csv_Cell(rs("city")) & "," & Csv_Cell(rs("state")) & "," & _
  47. Csv_Cell(rs("zip")) & "," & Csv_Cell(Businesses_StatusLabel(rs("status"))) & "," & _
  48. Csv_Cell(CustomerText(rs("is_customer"))) & "," & Csv_Cell(Date_Fmt(rs("last_contacted_at"))) & "," & _
  49. Csv_Cell(Date_Fmt(rs("next_action_date")))
  50. Response.Write line & vbCrLf
  51. n = n + 1
  52. If n Mod 2000 = 0 Then Response.Flush
  53. rs.MoveNext
  54. Loop
  55. rs.Close
  56. Response.End
  57. End Sub
  58. Private Function CustomerText(v)
  59. If v & "" = "1" Then CustomerText = "Yes" Else CustomerText = ""
  60. End Function
  61. End Class
  62. Dim ExportController_Class__Singleton
  63. Function ExportController()
  64. If IsEmpty(ExportController_Class__Singleton) Then
  65. Set ExportController_Class__Singleton = New ExportController_Class
  66. End If
  67. Set ExportController = ExportController_Class__Singleton
  68. End Function
  69. %>

Powered by TurnKey Linux.