Usage
Setting up the Database
Below is the SQL that will create the database and the appropriate tables. A sample admin user is also created. All passwords are hashed using md5 encryption and a salt is used. You can change the password salt in the '/admin/includes/config.inc.php' file. To manually insert a new passwork look at the top of the '/admin/login.php' file and you will see some commented out code that can be used to display a hashed password. Note that if you do change the salt the admin user created below will not work.
/* create database */
CREATE DATABASE `store_locator`;
/* create stores table */
CREATE TABLE `stores` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`address` varchar(255) NOT NULL,
`telephone` varchar(25) NOT NULL DEFAULT '',
`email` varchar(255) NOT NULL DEFAULT '',
`website` varchar(25) NOT NULL DEFAULT '',
`description` text NOT NULL,
`approved` tinyint(1) NOT NULL DEFAULT '0',
`latitude` float NOT NULL DEFAULT '0',
`longitude` float NOT NULL DEFAULT '0',
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
`status` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
);
/* create users table */
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL,
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
`status` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
);
/* create an admin user */
insert into `users`(`username`,`password`) values ('admin','4e654249ab4cfd74089bc883bbbec93a');
Setting up the Admin Panel
You must supply your database information and this is entered in the /admin/includes/config.inc.php file. You must also enter the directory of the admin folder and the address of the admin panel. These are used for redirection purposes and so that the correct paths are found. Some paths in the html or relative so that you shouldn't have to hard code these in.
// define database settings
define('HOSTNAME','localhost');
define('DB_USERNAME','database_username');
define('DB_PASSWORD','database_password');
define('DB_NAME','store_locator');
Once you have supplied all the relevant data and that an admin user exists in the database you should be able to login and access the admin panel.
Admin Panel
To view to the admin panel visit the '/admin' section. If you are not logged in you will be redirected to the login panel. Input your username/password and you will be sent to the main stores page.
Stores
The main Stores page lists all currently active Stores that are in the database. To add a new store click the Add New Store link in the top right of the page. To edit or delete a specific Store use the links under the Action column.
Adding Stores
To add a Store click the Add New Store link on the main Stores page. Here you can input a Store Name, Store Address, and the Longitude and Latitude values. Once an address has been inserted the page will attempt to find the address using Google. If found the Longitude and Latitude will be populated and the Map will update with the found address.
Editing Stores
To edit a Store click the Edit link under the Actions column. The edit page will be displayed which is similar to the add page. Here you will be able to edit the Store details and change the address if incorrect.
Deleting Stores
To delete a Store click the Delete link under the Actions column. A confirmation box will be displayed, if you select yes the Store will be flagged as deleted in the database. To recover the deleted Store change the status field from 0 to 1
Approving Stores
Stores that have added by users of the Store Locator are entered into the database with a status of 'Not Approved', this means that they must be approved by an admin user before they are visible via the search. To do this simply click the "Approve" link in the admin panel.
Importing Multiple Stores
An '/admin/import.php' file has been included that will allow you to easily import multiple stores all in one go by-passing the admin panel. You will first need an Google API key which can be found here, once you have your key you can insert it into the variable at the top of the script.
To add multiple Stores simply populate the $stores array with the store name and the address and visit /admin/import.php. The script will loop through each of the stores, attempt to find the latitude/longitude and then insert the Store into the database. Any errors will be displayed on screen.
Setting up the Store Locator
Similarly to the Admin panel you must enter your database information in the '/includes/config.inc.php' file, along with the root path and the address of the store locator folder.
Once you have supplied all the relevant data and Stores exist in the database the serach functionality will be fully working.