WAP Track

 

This chapter explains how WML can be integrated with Server Side scripting languages to build real time WAP Application.

 

More important is, and that is what we want to show you, how you can use a web server, server side scripting language, and a database to write Wap applications.

 

Interaction

- Conversions - Microbrowser - Gateway -Webserver

 

Software requirements

 

Communication

- Nokia to Personal Web Server - Browser to server request

- Server to browser - Imp Headers

- Personal Web Server to Nokia - Server to browser response

 

Setting up the Application

 

Programs - Worksheet

By now, we hope that you are thorough with WML. If you are not familiar with ASP, you can  refer to the ASP tutorial at www.vijaymukhi.com.

 

Conversions - Microbrowser - Gateway - Webserver

The WAP-enabled phones (microbrowser) Communicates a webserver through a WAP gateway. When a user types in a URL, the request is send to the WAP gateway using the WAP Protocol, where the gateway creates a conventional HTTP request for the specified URL and sends it to the web server. The server returns the WML file along with HTTP headers back to the WAP gateway and the gateway converts it back to WML bytecodes and sends it to microbrowser.

 

That's the only reason we need a gateway, for these conversions.

 

Software requirements

· Microsoft's Personal Web Server.

· Active Server Pages, which is a scripting Language, used on this server.

· Microsoft Access, a database, to store user information for future retrieval

· Nokia WAP Toolkit as microbrowser.

 

Nokia to Personal Web Server - Browser to Server Request

 

index.wml

<?xml version="1.0" ?>

<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

 

<wml>

 <head> <meta  http-equiv="Cache-Control" content="max-age=0"/> </head>

 

<card id="login" title="Login" newcontext="true">

<p>

click on <b>options</b><br/>

and then on <b>select</b> to call your file.

</p>

<do type='submit' label='first.asp' >

            <go href='http://127.0.0.1/first.asp' >

            </go>

            </do>  

</card>

</wml>

 

Click on compile and then on show. The Microbrowser (Nokia) displays the file. Click on options, this will take you to Browser Options. Under Browser options first.asp is highlighted so click on select. You will get a 404 object not found error, because your server has no file called first.asp. Let us create this File.

 

Server to Browser - Imp-Headers

Whenever a server sends a page to the browser, it first has to send headers and then the page.

 

Headers are nothing but something=something, lines that give more information of the following content. So if you are sending an HTML page over you first have to send a header as text/html.

 

<% Response.ContentType="text/html"  %>

<html>

<b>hi</b>

how are you

</html>

 

This tells the browser that content following is text/html and the browser displays it as html. Similarly when the server sends an image file over it sends the header as

 

<% Response.Content-Type="gif/img" %>

 

So now that we have to send a WML file over to the microbrowser. We first have to send a header that tells the microbrowser (Nokia) that the content following is WML. So we set the header as

 

<% Response.ContentType = "text/vnd.wap.wml"  %>

 

followed by WML content.

 

Personal Web Server to Nokia - Server to Browser Response

 

first.asp

<% Response.ContentType = "text/vnd.wap.wml"  %>

 

<?xml version="1.0" ?>

<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

 

<wml>

<head> <meta  http-equiv="Cache-Control" content="max-age=0"/> </head>

 

<card id="card1">

<p align="center">

<big><b>WapTrack</b></big>

 

<small>www.vijaymukhi.com</small>

</p>

</card>

 

</wml>

 

Save this file in your server's root directory and call it from your browser (Nokia) as before. PWS sends the file over and Nokia displays it.

 

Setting up the Application

To run this program, you need to make a virtual directory “wapproject“ in the servers root (e.g. ..\Inetpub\wwwroot\wapproject)

 

MS-Access database “user.mdb” to store data related to our application with one table as “id” containing two fields a) username and b) password in which the username and password of the user will be stored. Both the fields should be of type “text” with 50 characters as maximum size and Enter your name and a desired password as the first record. Now you are ready to go ahead with the codes to get in action.

 

Note. All the ASP files and the MDB file should be stored in the virtual directory “wapproject“.

 

You can download the wapproject.zip file from www.vijaymukhi.com

 

Programs - Workbook

Our example is a very simple one. It lets you keep Track of your daily schedules.

 

index.wml

<?xml version="1.0" ?>

<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>

<!--  Cache-Control header -->

<head> <meta  http-equiv="Cache-Control" content="max-age=0"/> </head>

<!--  card1 which takes you to ../main.asp after 30 seconds -->

<card id="card1" newcontext="true" ontimer="http://127.0.0.1/wapproject/main.asp">

<timer value="30"/>

<p align="center">

<!-- Content to be displayed -->

<big><b>WapTrack</b></big>

<small> &#xA9;  www.waptrack.wml</small>

</p>

</card>

</wml>

 

Index.wml is the first file to come over to the user. It does nothing much but displays name of the site (Wap Track www.waptrack.wml) and the ontimer takes you to main.asp after 30 sec.

 

 

main.asp

<% Response.ContentType = "text/vnd.wap.wml"  %>

<?xml version="1.0" ?>

<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

 

<wml>

<!--  Cache-Control header -->

<head> <meta  http-equiv="Cache-Control" content="max-age=0"/> </head>

 

<!--  card 1 -->

<card id="main" newcontext="true">

 

<!--  link which takes you to Card id signup -->

<do type='accept' label='signup'>

<go href='#signup'/>    

</do>              

 

<!--  link which takes you to Card id login -->

<do type='accept' label='login'>

<go href='#login'/>

</do>  

           

<!--  Content to be displayed -->     

<p align="center">

Click on <b>Options</b> to Login or SignUp

</p>

</card>

 

<!--  signup card which accepts the username and password and passes it to  chksignup.asp -->

<card id="signup" title="SignUp" newcontext="true">

           

<p>

 

<!--  textfields where user fills in account details -->

Username<input type="text" title="UserName" name="user" value="" /><br/>

Password<input type="password" title="Password" name="pwd" value="" /><br/>

</p>

 

<!--  link which takes you to chksignup.asp where the actual check from database takes place -->

<do type='accept' label='Submit'>

<go href='http://127.0.0.1/wapproject/chksignup.asp' method="post" >

 

<!--  values entered by the user are stored in variables and passed on to chksignup.asp -->

<postfield name="chkuser" value="$(user)" />    

<postfield name="chkpwd" value="$(pwd)" />

</go>

</do>  

 

<!--  link that takes you back to card main if you landed up here by mistake -->

<do type="accept" label="Back">

 <go href = "#main"/>

</do>

</card>

 

 <!--  login card which accepts the username and password and passes it on to chklogin.asp for authentication -->

 <card id="login" title="Login" newcontext="true">

<p>

 

<!--  textfields where user fills in account details -->

UserName<input type="text" title="UserName" name="user" value="" /><br/>

Password<input type="password" title="Password" name="pwd" value="" /><br/>

</p>

 

<!--  link that takes the username and password details to chklogin.asp -->

<do type='accept' label='Submit'>

<go href='http://127.0.0.1/wapproject/chklogin.asp' method="post" >

<postfield name="chkuser" value="$(user)" />    

<postfield name="chkpwd" value="$(pwd)" />

</go>

</do>  

 

<!--  back to card main -->

<do type="accept" label="Back">

<go href = "#main"/>

</do>

                                   

</card>

</wml>

 

Card main has two link that take you either to signup card  or login card from where you can either get into your account by typing your username and password or make a new account by clicking the signup link.

 

Card signup allows the user to select a username and password and passes the details to chksignup.asp to check the availability of the username.

 

Card Login accepts the username and password and passes it on to chklogin.asp for authentication of the account.

 

chksignup.asp

<% Response.ContentType = "text/vnd.wap.wml"%>

<%      

 

`defining variables

dim chk,msg

chk=0

uid = request("chkuser")

pwd = request("chkpwd")

 

`checking whether the variables are empty. If by mistake the user submits without filling the text boxes

IF uid = "" or pwd = "" THEN

msg = "Incomplete Data ...Re-enter"

ELSE

 

`if user has entered both the fields then the following code will check whether the desired username is available or in user by another user. If available, a new account will be created for the user.

           

`setting up ODBC connection to our MS Access Database

Set cn = Server.CreateObject("ADODB.Connection")

cn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\Inetpub\wwwroot\wapproject\user.mdb"

 

`here we check the availability of the desired username. The account created is case insensitive.

Set rec = Server.CreateObject("ADODB.Recordset")

            strSQL = "SELECT * FROM id"

            rec.Open strSQL,cn       

            Set objUsername = rec("username")

            Do UNTIL rec.EOF

            IF UCASE(uid) = UCASE(objUsername) then

            chk=0

            EXIT DO

            ELSE

            chk=1

            rec.MoveNext

            END IF

            LOOP

 

`the value of the chk variable will be 0 if the username is currently in use.

IF chk = 0 THEN

msg="Username in use <br/> Try Again"

ELSE

 

` if the value is 1, the following code will insert  the username and password into the id table of our database.

strSQL = "INSERT INTO id (username,password) VALUES ('"   & uid & "','" & pwd & "')"

            cn.Execute(strSQL)

 

`create a new table with the same name as the username to store the schedule of the user.

strSQL = "CREATE TABLE " & uid & "(flddate varchar(11),fldtime varchar(8),fldmessage varchar(200))"

cn.Execute(strSQL)

 

`inserts a dummy record into the newly created table

strSQL = "INSERT INTO " & uid & " (flddate,fldtime,fldmessage) VALUES ('22/22/2002','" & NOW() &"','WELCOME TO SHEDULE')"

cn.Execute(strSQL)

 

`Sets the msg varible if the account is created.

msg="account created <br/>login to use"

END IF

cn.close

END IF

 

%>

 

`here, the actual WML code comes into picture. It will display the result of the above code i.e. whether the account is created or the username is in use.

<?xml version="1.0" ?>

<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>

 

<!--  Cache-Control header -->

<head> <meta  http-equiv="Cache-Control" content="max-age=0"/> </head>

<card id="card1">

 

<!-- a timer of 20 seconds is set after which main.asp page will be displayed. -->

<onevent type='ontimer'> <go href='http://127.0.0.1/wapproject/main.asp'/> </onevent> <timer value = '20'/>

 

 

<p>

 

<!--  msg will display the value dynamically  depending upon the result of the above processed code.  -->

<%= msg %>

</p>

</card>

</wml>

 

The chksignup.asp program actually checks for the availability of the desired username. First it starts of by checking the variables, which have been passed on by the signup card of main.asp page. If they are empty, the variable msg will get the value stating that the user has not entered the fields properly.

 

If both the fields contains a value, the program continues by connecting to the id table in our database. There it checks whether the desired username is available or not. if not available, the variable msg gets the value which states that the username is currently in use. If available, the further code adds the new username and password to the id table. Then it creates a new table with the same name as the username where we store the users schedule and the variable msg gets the value which states that the account has been successfully created.

 

Following the asp code is our wml code, which displays the msg variable which in turn shows the result to the user. After 20 seconds, the user is taken back to the main page from where he can either login and start using his account or try signing up again.

 

chklogin.asp

<% Response.ContentType = "text/vnd.wap.wml"

`defining variables

dim chk,msg,kkk

kkk=0

uid = request("chkuser")

pwd = request("chkpwd")

 

`checking whether the variables are empty. If by mistake the user has clicked without filling the text boxes

IF uid = "" or pwd = "" THEN

msg = "Incomplete Data ...Re-enter"

ELSE

           

`setting up ODBC connection to our MS Access Database

Set cn = Server.CreateObject("ADODB.Connection")

cn.Open cn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\Inetpub\wwwroot\wapproject\user.mdb"

Set rec = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT * FROM id"

rec.Open strSQL,cn       

 

`the following code is basically for authentication. This code will either allow the user to login if the username and password is correct or send the user back to main.asp to re-login if the data is incorrect.

Set objUsername = rec("username")

Set objPassword = rec("password")

Do UNTIL rec.EOF

IF uid = objUsername then

IF objPassword = pwd then

 

`sets the msg and kkk veriable if Username and Password match

msg = "Logging In...<br/>Please Wait "

kkk=1

ELSE

 

`sets the msg and kkk variable when the username  matches, but the password does not match.

msg = "Incorrect Password"

kkk=0

END IF

 

chk=0

EXIT DO

ELSE

 

`chk is set to 1 if username does not match each time you pass the loop

chk=1

rec.MoveNext

END IF

LOOP

 

`sets the veriables if username does not match

IF chk=1 then

kkk=0

msg="Invalid Username"

ELSE

`adds the username to the session veriable

Session("username")=uid

END IF

 

cn.close

END IF

 

%>

<?xml version="1.0" ?>

<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

 

<wml>

<!--  Cache-Control header -->

<head> <meta  http-equiv="Cache-Control" content="max-age=0"/> </head>

<card id="card1" newcontext="true">

<%

 

<!--  the value of the variable kkk will be 0 if username password does not match, so the  user is taken back to the main page to re-login. -->

IF kkk=0 THEN

Response.write("<onevent type='ontimer'> <go href='http://127.0.0.1/wapproject/main.asp'/> </onevent> <timer value = '20'/>")

END IF

 

<!--  the value of the variable kkk will be 1 if both, username and password match and the user is taken to datamain.asp where he can see his schedule. -->

IF kkk=1 THEN

Response.write("<onevent type='ontimer'> <go href='http://127.0.0.1/wapproject/datamain.asp'/> </onevent> <timer value = '20'/>")

END IF

%>

 

<p>

 

<%= msg %>

 

</p>

</card>

 

</wml>

 

chklogin.asp is basically an authentication page. First it checks the whether the user has filled in both the fields. If not, the variable msg gets the value which informs the user that he has not filled in the fields properly.

 

 

If both the fields contain value, the code sets up the ODBC connection to our database. Then it checks the username, which is entered by the user with each username of the username field of the id table. This check is done to find out whether an account with the following username has been already created. If the username does not match with the one entered by the user, the value of msg states that an account such a username does not exist, kkk is set to 0 and we jump to the WML part.

 

If the username matches, the corresponding password field value is checked. If the password does not match, the msg variable states that the password entered by the user is incorrect. 

 

If  both the fields match with the id table, msg states that logging in is in progress. Also, the variable kkk is set to 1. we also set the value of the variable kkk to 0

 

Now we enter into our WML code. Here, we check the variable kkk. The value of kkk will be 0 when both, the username and password are incorrect or when the username is correct but the password is incorrect. In any case the user is taken back to the main page to re-login. So the user is redirected back to main.asp.

 

The value of kkk will be 1 only when the username and password has matched with any of the username and  its corresponding password of the id table. In this case, the user is redirected to datamain.asp, from where the user can check his schedules.

 

datamain.asp

<% Response.ContentType = "text/vnd.wap.wml"  %>

<?xml version="1.0" ?>

<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>

<!--  Cache-Control header -->

<head> <meta  http-equiv="Cache-Control" content="max-age=0"/> </head>

`the following card has a set of links which give the user choice as to how he would like to see his schedule, add a schedule, modify a schedule, delete a schedule or logout

<card id="datamain" newcontext="true">

 

<!--  `link takes the user to dataadd  -->

<do type='options' label='Add'>

<go href='#dataadd'/>

</do>  

 

<!--  link takes the user to disptdata.asp -->

<do type='options' label='c Todays Shed'>

<go href='http://127.0.0.1/wapproject/disptdata.asp'/>   

</do>

 

<!--  `link takes the user to dataviewsingle  card-->

<do type='options' label='c 1 Shed'>

<go href='#dataviewsingle'/>    

</do>              

 

<!--  `link takes the user to dataviewday card -->

<do type='options' label='c Days Shed'>

<go href='#dataviewday'/>       

</do>  

 

<!--  `link takes the user to datamodify card -->`

<do type='options' label='Modify'>

<go href='#datamodify'/>

</do>  

 

<!--  `link takes the user to datadelete-->

<do type='options' label='Delete'>

<go href='#datadelete'/>

</do>  

 

<!--  `link takes the user back to main.asp -->

<do type='options' label='LogOut'>

<go href='http://127.0.0.1/wapproject/main.asp'/>

</do>  

------------------------------------------------------------------------------------

<p>

 

<!--  displays a wellcome message using the session veriable -->

Hi <%= Session("username") %><br/>

<small>Welcome to Your Page</small><br/>

Check <b>Options</b>

</p>

</card>

 

<!--  card dataadd passes the values to adddata.asp  -->

<card id="dataadd" title="Add Shedule">

<onevent type='onenterforward'>

<refresh>

<setvar name='submit' value='http://127.0.0.1/wapproject/adddata.asp'/>

</refresh>

</onevent>

<p>

<small> Date = mm/dd/yy </small><br/>

<small>Time = 24 Hr</small><br/>

Date :<input format="NN\/NN\/\2\0\0\0" title="date" name="date" value="" /><br/>

Time :<input format="NN\:NN" title="time" name="time" value="" /><br/>

Message :<input title="message" name="message" value="" /><br/>

</p>

<do type='accept' label='Submit'>

<go href='$(submit:unesc)' method="post" >

<postfield name="dt" value="$(date)" />

<postfield name="ti" value="$(time)" />

<postfield name="mg" value="$(message)" />

</go>

</do>  

<do type="accept" label="Back">

<go href = "#datamain"/>

</do>

 

</card>

<!--  card dataviewsingle passes the values to dispsdata.asp  -->

<card id="dataviewsingle" title="Single Shedule" newcontext="true">

<p>

<small>Enter Shedule Date And Time </small>

Date :<input format="NN\/NN\/\2\0\0\0" title="date" name="date" value="" /><br/>

Time :<input format="NN\:NN" title="time" name="time" value="" /><br/>

</p>

<do type='accept' label='Submit'>

<go href='http://127.0.0.1/wapproject/dispsdata.asp' method="post" >

<postfield name="dt" value="$(date)" />

<postfield name="ti" value="$(time)" />

</go>

</do>  

<do type="accept" label="Back">

<go href = "#datamain"/>

</do>

                                   

</card>

 

<!--  card dataviewday passes the values to dispddata.asp -->

<card id="dataviewday" title="days shedule" newcontext="true">

 

<p>

<small>Enter Shedule Date And Time </small>

Date :<input format="NN\/NN\/\2\0\0\0" title="date" name="date" value="" /><br/>

</p>

<do type='accept' label='Submit'>

<go href='http://127.0.0.1/wapproject/dispddata.asp' method="post" >

<postfield name="dt" value="$(date)" />

</go>

</do>  

<do type="accept" label="Back">

<go href = "#datamain"/>

</do>

                                   

</card>

 

 

<!--  card datamodify passes the values to modidata.asp  -->

<card id="datamodify" title="Modify Shedule">

<onevent type='onenterforward'>

<refresh>

<setvar name='submit' value='http://127.0.0.1/wapproject/modidata.asp'/>

</refresh>

</onevent>

<p>

<small> Date = mm/dd/yy </small><br/>

<small>Time = 24 Hr</small><br/>

Date :<input format="NN\/NN\/\2\0\0\0" title="date" name="date" value="" /><br/>

Time :<input format="NN\:NN" title="time" name="time" value="" /><br/>

Modi Message :<input title="message" name="message" value="" /><br/>

</p>

<do type='accept' label='Submit'>

<go href='$(submit:unesc)' method="post" >

 

<postfield name="dt" value="$(date)" />

<postfield name="ti" value="$(time)" />

<postfield name="mg" value="$(message)" />

</go>

</do>  

<do type="accept" label="Back">

<go href = "#datamain"/>

</do>

</card>

 

 

 

<!--  card datadelete passes the values to deletedata.asp  -->

<card id="datadelete" title="Delete Shedule" newcontext="true">

<p>

<small>Enter Delete Date And Time </small>

Date :<input format="NN\/NN\/\2\0\0\0" title="date" name="date" value="" /><br/>

Time :<input format="NN\:NN" title="time" name="time" value="" /><br/>

</p>

<do type='accept' label='Submit'>

<go href='http://127.0.0.1/wapproject/deletedata.asp' method="post" >

<postfield name="dt" value="$(date)" />

<postfield name="ti" value="$(time)" />

</go>

</do>  

<do type="accept" label="Back">

<go href = "#datamain"/>

</do>

                                   

</card>

</wml>

 

datamain.asp

once the user logs into his account he comes to the datamain.asp page from where he can access his schedules. The first card i.e. the datamain card gives the user a list of options so that he can interact with his account.

            a) add a schedule,

            b) view a single schedule,

            c) view today’s schedule,

            d) modify a schedule

            e) delete a schedule. 

 

Lets look at it step by step.

a) the first option is to add a schedule. The user is taken to the dataadd card where can fill in the date, time and the message for the schedule. On submit the data is passed to `adddata.asp`.

 

b) The second option is to see the current days schedule. When the users chooses this option, 'disptdata.asp' takes over.

 

c) The Third option is to view a single schedule. when the user chooses this option, he is taken to the dataviewsingle card where he can fill in the date and time of the schedule that he wants to see. On submit, the page is redirected to `dispsdata.asp` page along with the information entered by the user.

 

c) The fourth option allows the user to view a particular days schedule. Selecting this option, the user is taken to the dataviewday card where he can fill in the date of which he wants to see the schedule. The page is then redirected to the dispddata.asp page along with the date entered by the user.

 

e) The fifth option allows the user to modify an existing schedule. The datamodify card, which is the link to this option, contains 3 fields. The user has to fill the date and the time of the schedule to be modified. And the new message which will replace the old message. Choosing the submit button will redirect to datamodify.asp allong with the data.

 

f) The sixth option is to delete a schedule. The user is taken to the datadelete card where he can enter the date and time of the schedule which has to be deleted. On submit the data is passed to `deletedata.asp`.

 

g) The last option allows the user to logout from his account, which takes him back to the main.asp.

 

 

 

 

adddata.asp

<% Response.ContentType = “text/vnd.wap.wml” 

 

‘defining variables

dim chkdate,chktime,chkmessage,mm,dd,hr,mi,val,msg

val = 1

 

‘Retrieving data from Query String

chkdate=Request(“dt”)

chktime=Request(“ti”)

chkmessage=Request(“mg”)

 

‘checking whether the variables are empty. If by mistake the user has clicked without filling the text boxes

IF chkdate = “” or chktime = “” or chkmessage = “” THEN

val = 4

msg = “Data Fields Empty...pls re-enter”

ELSE

 

 

mm=mid(chkdate,1,2)

dd=mid(chkdate,4,2)

hr=mid(chktime,1,2)

mi=mid(chktime,4,2)

 

‘Validates data, variable val is set to 0 for error

IF mm < 1 or mm > 12 THEN

val=0

msg = “Month Is Invalid...Please Re-enter”

END IF  

IF dd < 1 or dd > 31 THEN

val=0               

msg = “Date Is Invalid...Please Re-enter”

END IF  

IF hr < 00 or hr > 23 THEN

val=0               

msg = “Hour Entered Is Invalid...Please Re-enter”

END IF  

IF mi < 1 or mi > 59 THEN

val=0   

msg = “Minute Is Invalid...Please Re-enter”

END IF              

IF chkmessage = “” THEN

val=0

msg = “No Messages Entered...Please Re-enter”

END IF  

 

 

‘checks weather the schedule is already fixed , variable val is set to 2 if exist

IF val = 1 THEN

 

Set cn = Server.CreateObject(“ADODB.Connection”)

cn.Open “DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\SOFTWARE\wapproject\userid.mdb”

Set rec = Server.CreateObject(“ADODB.Recordset”)

strSQL = “SELECT * FROM “ & Session(“username”)

rec.Open strSQL,cn       

Set objdate = rec(“flddate”)

Set objtime = rec(“fldtime”)

           

Do UNTIL rec.EOF

IF chkdate = objdate then

IF objtime = chktime then

 

msg = “Schedule Already Fixed For This Time...Re-Enter”

val=2

EXIT DO

END IF

END IF

rec.MoveNext

LOOP

END IF  

 

‘inserts the new schedule

IF val = 1 THEN

strSQL = “INSERT INTO “ & Session(“username”) & “(flddate,fldtime,fldmessage) VALUES(‘“ & chkdate & “‘,’” & chktime & “‘,’” & chkmessage & “‘)”

cn.Execute strSQL

msg = “Shedule Fixed... Back To Main ... “

cn.close

END IF

END IF

%>

<?xml version=”1.0" ?>

<!DOCTYPE wml PUBLIC “-//WAPFORUM//DTD WML 1.1//EN” “http://www.wapforum.org/DTD/wml_1.1.xml”>

 

<wml>

 

<!—  Cache-Control header —>

<head> <meta  http-equiv=”Cache-Control” content=”max-age=0"/> </head>

<card id=”card1">

<%

 

<!—  ontimer takes the user back to datamain.asp  —>

Response.write(“<onevent type=’ontimer’> <go href=’http://127.0.0.1/wapproject/datamain.asp’/> </onevent> <timer value = ‘20’/>”)

%>

<p>

 

<!— displayed the value of the msg veriable —>

<%=msg %>

 

</p>

</card>

</wml>

 

adddata.asp

This file is used to add a new schedule. The code begins by checking the validity of the date as well as time. If the user has made an error in entering the date or the time of the schedule, an error message is posted.

 

Once the date and time validation is complete, the code checks as to whether a schedule is already fixed with the same date and time. If so, an error message is posted to the user.

If no matching schedule found, the code inserts the new schedule into the users table and posts a message that the schedule has been added.

 

disptdata.asp

<% Response.ContentType = “text/vnd.wap.wml”

 

‘Retrieving data from the System

mm=MONTH(date)

dd=DAY(date)

yy=YEAR(date)

 

‘Formats the date

IF LEN(mm) = 1 THEN

mm=”0" & mm

END IF

 

IF LEN(dd) = 1 THEN

dd=”0" & dd

END IF

 

IF LEN(yy) = 2 THEN

yy= “20” & yy

END IF

 

tdate = mm & “/” & dd & “/” & yy

 

‘setting up ODBC connection to our MS Access Database

Set cn = Server.CreateObject(“ADODB.Connection”)

cn.Open “DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\Inetpub\wwwroot\wapproject\user.mdb”.

Set rec = Server.CreateObject(“ADODB.Recordset”)

strSQL = “SELECT * FROM “ & Session(“username”) & “ ORDER BY fldtime”

rec.Open strSQL,cn       

 

‘Retrieving data from the Query String

Set objdate = rec(“flddate”)

Set objtime = rec(“fldtime”)

Set objmessage = rec(“fldmessage”)

 

%>

<?xml version=”1.0" ?>

<!DOCTYPE wml PUBLIC “-//WAPFORUM//DTD WML 1.1//EN” “http://www.wapforum.org/DTD/wml_1.1.xml”>

 

<wml>

<head> <meta  http-equiv=”Cache-Control” content=”max-age=0"/> </head>

<card id=”card1" title=”<%=tdate %>” newcontext=”true”>

<do type = “accept” label = “Main Page” >

<go href = “http://127.0.0.1/wapproject/datamain.asp”/>

</do>

<p>

 

<%

‘retrieves data from database an creates a table dynamically

count=0           

otable = 0

Do UNTIL rec.EOF

IF tdate = objdate THEN

IF otable = 0 THEN

Response.write(“<table title=’shedule’ columns=’2'><tr><td><small><b>Time</b></small></td><td><small><b>Message</b></small></td></tr>”)

otable = 1

END IF  

Response.write(“<tr><td><small>” & objtime & “</small></td><td><small>” & objmessage & “</small></td></tr>”)

count=1

END IF

rec.MoveNext

LOOP   

cn.close

IF otable = 1 THEN

Response.write(“</table>”)

END IF

IF count=0 THEN

msg = “There are no Shedules on this date”

Response.write msg

END IF

%>

 

</p>

</card>

 

</wml>

 

disptdata.asp

This program shows the current days schedule. The user enters the current date & time of the schedule he wishes to see. The data is been validated for the errors and then the data is been displayed taken from the Database after filtering in the Date format.

 

 

dispsdata.asp

<% Response.ContentType = “text/vnd.wap.wml”

 

‘defining variables

dim date,time,msg

 

val=1

 

‘Retrieving data from Query String

date = request(“dt”)

time = request(“ti”)

 

‘check for empty variables.

IF date = “” or time = “” THEN

val=2

msg = “Field Empty...Re-enter”

ELSE

 

‘if variables contain data, search for the schedule requested.

Set cn = Server.CreateObject(“ADODB.Connection”)

cn.Open “DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\Inetpub\wwwroot\wapproject\user.mdb”

Set rec = Server.CreateObject(“ADODB.Recordset”)

strSQL = “SELECT * FROM “ & Session(“username”)

rec.Open strSQL,cn       

Set objdate = rec(“flddate”)

Set objtime = rec(“fldtime”)

Set objmessage = rec(“fldmessage”)

Do UNTIL rec.EOF

IF date = objdate then

IF objtime = time then

message = objmessage

val=1

msg = date & “  “ & time & “  <br/>” & message

EXIT DO

END IF

END IF

val = 0

msg = “Invalid Data or No Matching Record... retry”

rec.MoveNext

LOOP   

cn.close

END IF

%>

 

<?xml version=”1.0" ?>

<!DOCTYPE wml PUBLIC “-//WAPFORUM//DTD WML 1.1//EN” “http://www.wapforum.org/DTD/wml_1.1.xml”>

 

<wml>

<head> <meta  http-equiv=”Cache-Control” content=”max-age=0"/> </head>

<card id=”card1" newcontext=”true”>

<do type = “accept” label = “Main Page” >

<go href = “http://127.0.0.1/wapproject/datamain.asp”/>

</do>

<p>

 

<%=msg %>

</p>

</card>

 

</wml>

 

 

dispsdata.asp

When to user chooses to view a single data, dispsdata.asp file is been called. Then it check whether the fields are empty or they have some data in them. If any of the variables are empty, the msg variable is given a value stating the same and the ASP code does not continue. If the variables contain data, ODBC connection is set. The users schedule table is open with the help of the session variable. The validation check is carried on. First the code tries to match the date and time entered by the user. When the fields match, the variable val is set to 1 and the msg variable contains that schedule. if no record is found, val is set to 0 and msg carries an error message. The WML code displays the msg variable and has a link to the datamain.asp page.

 

modidata.asp

<% Response.ContentType = “text/vnd.wap.wml” 

‘defining variables

dim chkdate,chktime,chkmessage,mm,dd,hr,mi,val,msg

val = 1

‘Retrieving data from Query String

chkdate=Request(“dt”)

chktime=Request(“ti”)

chkmessage=Request(“mg”)

IF chkdate = “” or chktime = “” or chkmessage = “” THEN

val = 4

msg = “Data Fields Empty...pls re-enter”

ELSE

 

‘Database ODBC connection.

Set cn = Server.CreateObject(“ADODB.Connection”)

            cn.Open “DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\Inetpub\wwwroot\wapproject\user.mdb”

            Set rec = Server.CreateObject(“ADODB.Recordset”)

            strSQL = “SELECT * FROM “ & Session(“username”)

            rec.Open strSQL,cn       

            Set objdate = rec(“flddate”)

            Set objtime = rec(“fldtime”)

           

            ‘Retrieving data from the database.

Do UNTIL rec.EOF

                        IF chkdate = objdate then

                                    IF objtime = chktime then

                                                val=2

                                                EXIT DO

                                    END IF

                        END IF

                        msg=”INVALID SHEDULE”

            rec.MoveNext

            LOOP

END IF  

IF val = 2 THEN

                        strSQL = “UPDATE “ & Session(“username”) &  “ SET fldmessage = ‘“ & chkmessage & “‘ WHERE flddate = ‘“ & chkdate & “‘ and fldtime  = ‘“ & chktime  & “‘“

                        cn.Execute strSQL

                        msg = “ Shedule Modified”

                        cn.close

END IF

 

%>

<?xml version=”1.0" ?>

<!DOCTYPE wml PUBLIC “-//WAPFORUM//DTD WML 1.1//EN” “http://www.wapforum.org/DTD/wml_1.1.xml”>

 

<wml>

 <head> <meta  http-equiv=”Cache-Control” content=”max-age=0"/> </head>

<card id=”card1">

<%

 

Response.write(“<onevent type=’ontimer’> <go href=’http://127.0.0.1/wapproject/datamain.asp’/> </onevent> <timer value = ‘20’/>”)

 

%>

<p>

<%=msg %>

 

</p>

</card>

</wml>

 

 

modidata.asp

This file helps is modifying an existing data. The programs first checks whether the user already has an entry for the schedule he wants to modify. If his table does not have such an entry, a message is posted to user. If the record is found, the old message is replaced with the new message and the user is informed about it.

 

deletedata.asp

<% Response.ContentType = “text/vnd.wap.wml”

‘defining variables

dim chkdate,chktime,chkmessage,mm,dd,hr,mi,val,msg

val = 1

‘Retrieving data from Query String

chkdate=Request(“dt”)

chktime=Request(“ti”)

 

IF chkdate = “” or chktime = “” THEN

val = 4

msg = “Data Fields Empty...pls re-enter”

ELSE

 

‘ Database ODBC connection.

Set cn = Server.CreateObject(“ADODB.Connection”)

            cn.Open “DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\Inetpub\wwwroot\wapproject\user.mdb”

            Set rec = Server.CreateObject(“ADODB.Recordset”)

            strSQL = “SELECT * FROM “ & Session(“username”)

            rec.Open strSQL,cn       

            Set objdate = rec(“flddate”)

            Set objtime = rec(“fldtime”)

           

            Do UNTIL rec.EOF

                        IF chkdate = objdate then

                                    IF objtime = chktime then

                                                val=2

                                                EXIT DO

                                    END IF

                        END IF

 

msg=”INVALID SHEDULE”

            rec.MoveNext

            LOOP

END IF  

IF val = 2 THEN

                        strSQL = “DELETE FROM “ & Session(“username”) & “ WHERE flddate = ‘“ & chkdate & “‘ and fldtime  = ‘“ & chktime  & “‘ “

                        cn.Execute strSQL

                        msg = “Shedule Deleted”

                        cn.close

END IF

 

%>

<?xml version=”1.0" ?>

<!DOCTYPE wml PUBLIC “-//WAPFORUM//DTD WML 1.1//EN” “http://www.wapforum.org/DTD/wml_1.1.xml”>

 

<wml>

 <head> <meta  http-equiv=”Cache-Control” content=”max-age=0"/> </head>

<card id=”card1">

<%

 

Response.write(“<onevent type=’ontimer’> <go href=’http://127.0.0.1/wapproject/datamain.asp’/> </onevent> <timer value = ‘20’/>”)

 

%>

<p>

<%=msg %>

 

</p>

</card>

</wml>

 

 

deletedata.asp

This file again checks whether the schedule mentioned by the user is present in his table. If present, the given schedule is deleted and the page is redirected to datamain.asp after 20 seconds.

 

We have provided the full example on our site www.vijaymukhi.com one can download the zip file and tryout our example. We hope that is will give you a start to the vast world of WAP application.