<%@ LANGUAGE=VBScript LCID=1033%>
<%
' Utility sample for Aspicore GSM Tracker
' Show tracking data from Microsoft Access database (or MS SQL Server)
'
' 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 Internet browser,
' e.g. http://<YourWebServer>/queryphone.asp?imei=<your_imei>
'
' (c) Aspicore Ltd 2005, www.aspicore.com
' Tested with Windows XP, IIS ASP 5.1 and Windows 2000, IIS ASP 5.0
' ADODB v2.7
' ------------------------------
' Change History:
' 2005-04-15 jje - Script created
%>
<% Option Explicit
Response.Buffer = True
Response.ContentType = "text/html; charset=ISO-8859-1"
Response.Expires = 0
' Response.LCID = 1033 ' Windows 2000 does not support this, so replaced by the following line
Session.LCID = 1033 ' Geographical locale telling how to format dates and times, 1033 = English - US
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<style type="text/css">
<!--
td { font-family: verdana,arial,helvetica,sans-serif; font-size: 9pt;
border: 1px solid black;
vertical-align: baseline }
th { font-family: verdana,arial,helvetica,sans-serif; font-size: 7pt; font-weight: bold;
border: 1px solid black;
border-style: solid; border-width: 1px;
vertical-align: baseline }
body { font-family: Courier New,MONOSPACE; font-size: 9pt }
base { font-family: Courier,MONOSPACE; font-size: 10pt }
table { border-collapse: collapse; border: solid thin black }
caption { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold }
-->
</style>
<title>Query phone</title>
</head>
<body>
<!--#INCLUDE FILE="adovbs.inc"-->
<%
' ------------------------
' Show time in the response to the HTTP client
Response.Write "<p>" & vbCrLf
Response.Write "Report Date:" & vbCrLf
Response.Write Now() & vbCrLf
Response.Write "(Server Local Time)" & vbCrLf
Response.Write "</p>" & vbCrLf
' ------------------------
' Go through the HTTP Get parameters
' Check if parameter 'imei' exists
' Show all ignored parameters in the response to the HTTP client
Dim vImei
vImei = Null
Dim item
Dim itemValue
For Each item In Request.QueryString
itemValue = Request.QueryString(item)
Select Case item
Case "imei"
vImei = itemValue
Case Else ' Other values.
Response.Write "<p>" & vbCrLf
Response.Write item & " => " & itemValue & " (Ignored)" & vbCrLf
Response.Write "</p>" & vbCrLf
End Select
Next
' ------------------------
If IsNull(vImei) Then ' *****
Response.Write "<p>You must give an imei code as an URL argument</p>" & vbCrLf
Response.Write "<p>Example:</p>" & vbCrLf
Response.Write "<p>http://"
Response.Write Request.ServerVariables("HTTP_HOST")
Response.Write Request.ServerVariables("SCRIPT_NAME")
Response.Write "?"
If Request.ServerVariables("QUERY_STRING") <> "" Then
Response.Write Request.ServerVariables("QUERY_STRING") & "&"
End If
Response.Write "imei=123456789012345</p>" & vbCrLf
Response.Write "<p>N.B. 'imei' must be in lower case!</p>" & vbCrLf
ElseIf Len(vImei) <> 15 Then ' *****
Response.Write "<p>You gave an illegal 'imei' code as an URL argument</p>" & vbCrLf
Response.Write "<p>The 'imei' code must be exactly 15 digits.</p>" & vbCrLf
Response.Write "<p>The current 'imei' argument is: "
Response.Write vImei
Response.Write "</p>" & vbCrLf
Else ' *****
Response.Write "<p><b>Selected phone: IMEI "
Response.Write vImei
Response.Write "</b></p>" & vbCrLf
' ------------------------
' Make a SELECT query to the Access database (or MS SQL Server db)
' (Make sure the file storemdb.mdb with table GPS exists in the location given in strConn,
' perhaps rather somewhere else than the C:\WINDOWS\Temp\ directory used in the sample.)
' ------------------------
' Connecting, selecting database
Dim objDBConn ' As ADODB.Connection
Dim strConn
' ***********************************************************************
' Enable either of the following connect strings
' ***********************************************************************
' Microsoft Access 2000 (*.mdb) Connect String
strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\WINDOWS\Temp\storemdb.mdb"
' ***********************************************************************
' MS SQL Server Connect String
' strConn="Provider=SQLOLEDB.1;Data Source=(local);Initial Catalog=GSM_Tracker;User ID=UID;Password=PWD;Persist Security Info=True"
' ***********************************************************************
Set objDBConn = Server.CreateObject("ADODB.Connection")
objDBConn.Open strConn
' Performing SQL query
Dim cmdQry ' As ADODB.Command
Dim prmQry ' As ADODB.Parameter
Dim rsSelectResult ' As ADODB.Recordset
Dim sSQL
Dim i
sSQL = "SELECT TOP 100 GPSMSGID, TIME_RECEIVED, STATUS, LATITUDE, LONGITUDE, SPEED_KNOTS, COURSE_DEG, " _
& "UTCTIME, UTCDATE, LABEL, REMOTE_IP " _
& "FROM GPS WHERE PHONE = ? ORDER BY GPSMSGID DESC"
Set cmdQry = Server.CreateObject("ADODB.Command")
cmdQry.CommandText = sSQL
cmdQry.CommandType = adCmdText
Set prmQry = cmdQry.CreateParameter(, adVarChar, AdParamInput, 30, vImei) ' PHONE
cmdQry.Parameters.Append prmQry
Set cmdQry.ActiveConnection = objDBConn
Set rsSelectResult = Server.CreateObject("ADODB.Recordset")
rsSelectResult.Open cmdQry
Response.Write "<p>" & vbCrLf
If rsSelectResult.Eof Then
Response.Write "No messages in the database from Aspicore GSM Tracker running on the selected phone." & vbCrLf
Else
Response.Write "The 100 most recent messages from Aspicore GSM Tracker running on the selected phone." & vbCrLf
End If
Response.Write "</p>" & vbCrLf
' Printing results in HTML
Response.Write "<table border=""1"">" & vbCrLf
' Table header
Response.Write vbTab & "<tr>" & vbCrLf
For i = 0 To rsSelectResult.Fields.Count - 1
Response.Write vbTab & vbTab & "<th>" & Replace(rsSelectResult(i).Name, "_", " ") & "</th>" & vbCrLf
Next
Response.Write vbTab & "</tr>" & vbCrLf
' Table content
Dim vntValue
Do While Not rsSelectResult.eof
Response.Write vbTab & "<tr>" & vbCrLf
For i = 0 To rsSelectResult.Fields.Count - 1
vntValue = rsSelectResult(i).Value
If IsNull(vntValue) Then
Response.Write vbTab & vbTab & "<td>" & "NULL" & "</td>" & vbCrLf
Else
Response.Write vbTab & vbTab & "<td>" & vntValue & "</td>" & vbCrLf
End If
Next
Response.Write vbTab & "</tr>" & vbCrLf
rsSelectResult.MoveNext
Loop
Response.Write "</table>" & vbCrLf
' Free resultset
rsSelectResult.Close
Set rsSelectResult = Nothing
' Release resources
Set prmQry = Nothing
Set cmdQry = Nothing
' close connection
objDBConn.Close
Set objDBConn = Nothing
'------------------------
End If ' *****
%>
</body>
</html>