<%@ LANGUAGE=VBScript LCID=1035%>
<%
' Sample for Aspicore GSM Tracker
' Show tracking data from MS SQL Server database as a geocoded RSS feed
'
' You can use this sample to see, what data exists in the database for a certain phone
'
' Usage: Go to the URL of this page with your RSS feed reader or Internet browser,
' e.g. http://<YourWebServer>/rss_feed.asp?imei=<your_imei>
'
' (c) Aspicore Ltd 2005, www.aspicore.com
' Tested with Windows 2000, IIS ASP 5.0
' ADODB v2.7
'
' NB. Do not add any empty lines before the xml tag, otherwise IE 6.0 does not show the XML source properly!
' ------------------------------
' Change History:
' 2005-04-21 jje - Script created
%>
<% Option Explicit
Response.Buffer = True
' Response.ContentType = "application/rss+xml"
Response.ContentType = "text/xml; charset=ISO-8859-1"
Response.Expires = 0
Session.LCID = 1033 ' Geographical locale telling how to format dates and times, 1033 = English - US
%><?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0"
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<%
' ***********************************************************************
' Configuration settings
' ----------------------
Const MyString = "This is my string."
Const MyTimeZone = "+0200" ' Hard coded time zone GMT+2
Const MyLinkURL = "http://www.toimii.com/gps/show_data.asp"
Const MyFeedURL = "http://www.toimii.com/gps/rss_feed.asp"
Const MyMapURL = "http://www.mapquest.com/maps/map.adp?latlongtype=decimal&"
' ----------------------
' MS SQL Server Connect String
Const strConn="Provider=SQLOLEDB.1;Data Source=(local);Initial Catalog=GSM_Tracker;User ID=UID;Password=PWD;Persist Security Info=True"
' ***********************************************************************
Sub Format_RFC822_DateAndTime(dtTime, sFormattedDate)
Select Case DatePart("w", dtTime)
Case vbSunday
sFormattedDate = "Sun, "
Case vbMonday
sFormattedDate = "Mon, "
Case vbTuesday
sFormattedDate = "Tue, "
Case vbWednesday
sFormattedDate = "Wed, "
Case vbThursday
sFormattedDate = "Thu, "
Case vbFriday
sFormattedDate = "Fri, "
Case vbSaturday
sFormattedDate = "Sat, "
Case Else
sFormattedDate = ""
End Select
sFormattedDate = sFormattedDate & Right(CStr(DatePart("d", dtTime) + 100), 2) & " "
Select Case DatePart("m", dtTime)
Case 1
sFormattedDate = sFormattedDate & "Jan "
Case 2
sFormattedDate = sFormattedDate & "Feb "
Case 3
sFormattedDate = sFormattedDate & "Mar "
Case 4
sFormattedDate = sFormattedDate & "Apr "
Case 5
sFormattedDate = sFormattedDate & "May "
Case 6
sFormattedDate = sFormattedDate & "Jun "
Case 7
sFormattedDate = sFormattedDate & "Jul "
Case 8
sFormattedDate = sFormattedDate & "Aug "
Case 9
sFormattedDate = sFormattedDate & "Sep "
Case 10
sFormattedDate = sFormattedDate & "Oct "
Case 11
sFormattedDate = sFormattedDate & "Nov "
Case 12
sFormattedDate = sFormattedDate & "Dec "
End Select
' sFormattedDate = sFormattedDate & Format(dtTime, "mmm ") ' Systems settings dependent (locale)
sFormattedDate = sFormattedDate & DatePart("yyyy", dtTime) & " "
sFormattedDate = sFormattedDate & Right(CStr(DatePart("h", dtTime) + 100), 2) & ":"
sFormattedDate = sFormattedDate & Right(CStr(DatePart("n", dtTime) + 100), 2) & ":"
sFormattedDate = sFormattedDate & Right(CStr(DatePart("s", dtTime) + 100), 2) & " "
sFormattedDate = sFormattedDate & MyTimeZone ' Hard coded time zone
End Sub
%>
<channel>
<title>
<%
Dim strIMEI
Dim strLabel
strIMEI = Request.QueryString("phone")
strLabel = Request.QueryString("label")
Response.Write "Aspicore geo-feed IMEI " & strIMEI
If strLabel >= "1" Then
Response.Write " with label " & Server.HTMLEncode(strLabel)
End If
%>
</title>
<link>
<%
Response.Write MyLinkURL & "?phone=" & strIMEI
If strLabel >= "1" Then
Response.Write "&label=" & Server.URLEncode(strLabel)
End If
%>
</link>
<description>
<%
Response.Write "Last 20 locations"
If strLabel >= "1" Then
Response.Write " containing label " & Server.HTMLEncode(strLabel)
End If
Response.Write " registered with Aspicore GSM Tracker"
%>
</description>
<!--#INCLUDE FILE="adovbs.inc"-->
<%
Dim objDBConn ' As ADODB.Connection
Dim cmdQry ' As ADODB.Command
Dim prmQry ' As ADODB.Parameter
Dim prm2Qry ' As ADODB.Parameter
Dim rsSelectResult ' As ADODB.Recordset
Dim sSQL
Dim i
Set objDBConn = Server.CreateObject("ADODB.Connection")
objDBConn.Open strConn
If strLabel >= "1" Then
sSQL = "SELECT TOP 20 GPSMSGID, TIME_RECEIVED, LATITUDE, LONGITUDE, SPEED_KNOTS, STATUS, LABEL, CONVERT(varchar(19), TIME_RECEIVED, 120) AS TIME_RECEIVED_ISO FROM GPS WHERE PHONE = ? AND LABEL LIKE ? ORDER BY TIME_RECEIVED DESC"
Else
sSQL = "SELECT TOP 20 GPSMSGID, TIME_RECEIVED, LATITUDE, LONGITUDE, SPEED_KNOTS, STATUS, LABEL, CONVERT(varchar(19), TIME_RECEIVED, 120) AS TIME_RECEIVED_ISO FROM GPS WHERE PHONE = ? ORDER BY TIME_RECEIVED DESC"
End If
Set cmdQry = Server.CreateObject("ADODB.Command")
cmdQry.CommandText = sSQL
cmdQry.CommandType = adCmdText
Set prmQry = cmdQry.CreateParameter(, adVarChar, AdParamInput, 30, strIMEI) ' GPS.PHONE
cmdQry.Parameters.Append prmQry
If strLabel >= "1" Then
Set prm2Qry = cmdQry.CreateParameter(, adVarChar, AdParamInput, 20, strLabel) ' GPS.LABEL
cmdQry.Parameters.Append prm2Qry
End If
Set cmdQry.ActiveConnection = objDBConn
Dim dtTime
Dim sFormattedDate
Set rsSelectResult = Server.CreateObject("ADODB.Recordset")
rsSelectResult.Open cmdQry
Do While Not rsSelectResult.EOF
Response.Write vbCrLf
Response.Write "<item>" & vbCrLf
Response.Write " <title>" & rsSelectResult(7).Value ' TIME_RECEIVED_ISO
If Not IsNull(rsSelectResult(6).Value) Then
Response.Write " " & Server.HTMLEncode(rsSelectResult(6).Value) ' Label
End If
Response.Write "</title>" & vbCrLf
' Indices into rsSelectResult:
' LATITUDE 2
' LONGITUDE 3
If IsNull(rsSelectResult(2).Value) OR IsNull(rsSelectResult(3).Value) Then
Response.Write " <link>Null</link>" & vbCrLf
Response.Write " <description>Null</description>" & vbCrLf
' guid is optional.
Response.Write " <guid isPermaLink=""false"">" & MyFeedURL & "/" & rsSelectResult(0).Value & "</guid>" & vbCrLf
dtTime = rsSelectResult(1).Value
Call Format_RFC822_DateAndTime(dtTime, sFormattedDate)
Response.Write " <pubDate>"
Response.Write sFormattedDate
Response.Write "</pubDate>" & vbCrLf
Response.Write " <geo:lat>0</geo:lat>" & vbCrLf
Response.Write " <geo:long>0</geo:long>" & vbCrLf
Else
Dim strMapLink
strMapLink = MyMapURL & "latitude="
strMapLink = strMapLink & rsSelectResult(2).Value
strMapLink = strMapLink & "&longitude="
strMapLink = strMapLink & rsSelectResult(3).Value
Response.Write " <link>" & strMapLink & "</link>" & vbCrLf
Response.Write " <description>Lat " & FormatNumber(rsSelectResult(2).Value,6,,,0)
Response.Write " Long " & FormatNumber(rsSelectResult(3).Value,6,,,0) & vbCrLf
Response.Write " Status " & Server.HTMLEncode(rsSelectResult(5).Value)
If Not IsNull(rsSelectResult(6).Value) Then
Response.Write " Label " & Server.HTMLEncode(rsSelectResult(6).Value)
End If
Response.Write " </description>" & vbCrLf
' guid is optional.
Response.Write " <guid isPermaLink=""false"">" & MyFeedURL & "/" & rsSelectResult(0).Value & "</guid>" & vbCrLf
dtTime = rsSelectResult(1).Value
Call Format_RFC822_DateAndTime(dtTime, sFormattedDate)
Response.Write " <pubDate>"
Response.Write sFormattedDate
Response.Write "</pubDate>" & vbCrLf
Response.Write " <geo:lat>" & rsSelectResult(2).Value & "</geo:lat>" & vbCrLf
Response.Write " <geo:long>" & rsSelectResult(3).Value & "</geo:long>" & vbCrLf
End If
Response.Write "</item>" & vbCrLf
Response.Write vbCrLf
rsSelectResult.MoveNext
Loop
rsSelectResult.Close
Set rsSelectResult = Nothing
Set cmdQry.ActiveConnection = Nothing
Set prmQry = Nothing
If strLabel >= "1" Then
Set prmQry = Nothing
End If
Set cmdQry = Nothing
%>
</channel>
</rss>