You are on page 1of 4

Use your WAP phone as a "phone" ! Whatever next ?

What ?! Why Would You Want To Do This ?


Let's assume you work for a company: a BIG company, with lots of employees,
scattered all over the country, maybe all over the world. Or maybe you have a
social circle of hundreds of friends (are you sure you're a software developer ? )
and you can't fit 'em all in your phone book..

Ok, in the name of reality we'll stick with the first scenario! Let's assume that
one day you want to phone your contact Lenny Bruce in San Diego, but carelessly,
you left your address book at the office, and now everyone's gone home. Lenny's
important, and so is your call.. You look in your mobile's phone directory, but
sad to say the weedy little thing can "only" hold 250 numbers. You're stuffed.. or
are you ? Check out this fine example of mobile database usage !

Time for a short disclaimer..


.
The system I have built works fine for me - as always, your mileage may vary.
There is no warranty with this product.

System Overview
The goal is to get someone in your company to convert the current phonelist into a
format suitable for storing in a MySQL database. I did this myself as our
phonelists are distributed in Excel format. It was a simple matter to convert
these to a CSV file that was then uploaded to my web host.

Once you have this minor hurdle out of the way, you will need to set up your
database..

Setting Up The Database


Here is my dog-simple table. This holds the details of the phone book, and I
should say right now that it's constructed to meet my requirements - you will
almost certainly want to redesign it for your own use.

# Table structure for table 'company' held in database 'Phonelist'


#
CREATE TABLE company
(
Fname varchar(40) NOT NULL,
Lname varchar(40) NOT NULL PRIMARY KEY,
Ext char(12),
Email varchar(60),
Dept varchar(20) NOT NULL,
JobDesc varchar(50),
Site char(3) NOT NULL
);

and here's our typical raw data file that will be uploaded into the table:

Peter |Garner |112 |peterg@somewhere.co.uk |WAP2Go |Software Developer |


GBR
Lenny |Bruce |666 |len@brucewap.com |BruceWAP |CIO |
USA
John |Doe |554 |jdoe@nowhere.com |SupaWAP |CEO |
AUS
Julie |Farb |953 |jools@klotzky.ru |WAPslotz |Chief Buyer |
RUU

If you would like a script to do this, here's one I prepared earlier - just cut 'n
paste. Don't forget to change the reference to '//usr5/...' to suit your own
installation !

mysql <<EOF

USE Phonelist

DROP TABLE IF EXISTS company;

CREATE TABLE company


(
Fname varchar(40) NOT NULL,
Lname varchar(40) NOT NULL PRIMARY KEY,
Ext char(12),
Email varchar(60),
Dept varchar(20) NOT NULL,
JobDesc varchar(50),
Site char(3) NOT NULL
);

LOAD DATA INFILE '//usr5/rawdata//pl.txt' IGNORE


INTO TABLE company
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\r\n';
EOF

The eagle-eyed among you will notice that the full phone number is not stored in
this file - just the extension number of the contact, and a country code. This
software is designed for the type of telephone system that will allow to dial a
standard prefix, and just add the extension number to call that person directly.
If you don't have a phone system like this you should be prepared to change the
table format to suit. I've designed it so that 12 characters are allowed for the
phone number (Ext field) and you will have to make some changes in the page that
does the searches and returns the result.

Starting a Search
Once you have populated the table with data, you are ready to look at the first
(main) page. Click here to launch this in a new window.

You will see that there's not much PHP in this page. The main point here is that
you are entering the search value (last name) you want to search for. Having done
this, you can proceed with the actual search. Here's our search screen:

The main point about the search itself is how you do it on a mobile phone as
opposed to a "real" PC. When I first started doing this type of development I
followed (my) traditional practice of doing the search and retrieving all the
results as they would then be displayed on a web page. On a mobile device though
the conditions changed: you cannot guarantee that the "connection" will be
reliably maintained, and I didn't want to leave my MySQL server with lots of
disconnected links timing out. I therefore adopted the "hit and run" method shown
below. This is essentially Connect / Query / Retrieve / Disconnect.

Here's how it is done:

mysql_connect("localhost", $DBUSER,$DBPASS);
mysql_select_db("Phonelist");
$query = "SELECT Fname, Lname, Ext, Email, Dept, JobDesc, Site FROM company";
$query .= " WHERE Lname LIKE '%$SearchTerm%' LIMIT $pointer,1";

The search shown above will not use a MySQL index, as the search term is prepended
with the wildcard '%' character. In real-world operation this has not proved to be
a problem, and the general latency of WAP, Telco and Internet gives acceptable
results. If in fact you work for a true Pan-Galactic business with headcounts in
the 1000s you may want to remove the leading '%' and give your searches a bit more
oomph.

Fetching Results
Having run your search query, you are now in a position to get your results, and
this where the clever bit comes in. It might be an idea to have a quick look the
code that does the searching. Click here to launch this in a new window.

In order to save lots of repeating information in the database, we can now use the
country code $site to get other information. we convert the 3-character short code
to the real name of the office we're going to call, and at the same time we'll
grab the dialling code info into a variable called $pfx.

if ( $Site == "GBR" ) { $Site = "London"; $pfx = "442075552"; }


elseif ( $Site == "USA" ) { $Site = "San Diego"; $pfx = "1694463"; }
elseif ( $Site == "AUS" ) { $Site = "Sydney"; $pfx = "6132124"; }
elseif ( $Site == "RUU" ) { $Site = "Moscow"; $pfx = "7952345"; }

I suppose in hindsight that if your company had a lot of offices, then it would be
better put the above if .. elseif into another table and incorporate another
database lookup in the page, but as to whether that would be worth it is left as
an exercise for the reader :-)

Anyway, now we can combine all these variables into a human-readable page for
display on our mobile screen.

Found a
match
(top of screen) Scrolling down
(middle of screen) Scrolling down
(bottom of screen)

Thanks to the magic of the WTAI interface, we also have the option to add our
search result to our phone's phone book, or (and this is the object of the
exercise!) to call our contact simply by clicking the link. Shown below is then
result expressed as raw PHP code, and then as te result you actually see. You
should however bear in mind that due to the different implementations of WTAI by
different handset manufacturers, you may or may not be able to use both the "add"
and "call options. If this is the case, then please email me (address below) and I
can do some more investigations.

<anchor>Call Lenny<go href="wtai://wp/mc;++1694463666"/></anchor><br/>


<anchor>Add to phone book<go href="wtai://wp/ap;+1694463666;Bruce"/></anchor>

Call Lenny <go href="wtai://wp/mc;+1694463666"/>


Add to phone book <go href="wtai://wp/ap;+1694463666;Bruce"/>

In Conclusion
This WAPplication has been very useful to me over time: sad to say that I can't
remember many of my colleagues phone numbers off the top of my head, so this helps
me. If you are able to GPRS, then it can be run from within a GPRS session, so
it's very convenient. You can also use code segments to embed into your own
applications. For example, if you have published your own WAP site, you can add a
"call me now" link to a page that would get the user straight through to say,
Customer Services, without intterupting a browsing session.

I would be very interested to know if anyone using this has any particular
problems with different handsetsL if you do, please let me know !

As regards the WTAI, I think that there is a lot of scope for dvelopment here,
especially as the specification is enhanced as new technologies are developed. the
only downside to this is that relevant documentation seems to be hard to come by,
and I'd strongly suggest that before you roll out a WAPplication that uses a
particular WTAI feature, you should test it locally first !

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

You Ought To Visit..


Pyweb.com Home of the wonderful Pyweb emulator
w3schools.com The source of much WAP knowledge
mysql.com A Great Database
php.net A Great Scripting Tool

--------------------------------------------------------------------------------
Peter Garner, June 2003

You might also like