prefix."Stores"; $sql = "CREATE TABLE " . $table . " ( ID int(10) NOT NULL AUTO_INCREMENT, Name varchar(100) DEFAULT NULL, Phone varchar(15) DEFAULT NULL, Street varchar(100) DEFAULT NULL, City varchar(25) DEFAULT NULL, Province varchar(25) DEFAULT NULL, PostalCode varchar(10) DEFAULT NULL, Country varchar(50) DEFAULT NULL, Latitude float(10,6) DEFAULT NULL, Longitude float(10,6) DEFAULT NULL, PreferredStore tinyint(1) DEFAULT 0, CustomInfo varchar(255) DEFAULT NULL, UNIQUE KEY (`ID`) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } register_activation_hook(__FILE__, 'installStoreTable'); register_deactivation_hook(__FILE__, 'akwUnregisterScripts'); add_action('admin_menu','storeLocator_menu'); //Function to install the tables function installStoreTable() { global $wpdb; $table_name = $wpdb->prefix."Stores"; if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { $sql = "CREATE TABLE $table_name ( ID int(10) NOT NULL AUTO_INCREMENT, Name varchar(100) DEFAULT NULL, Phone varchar(15) DEFAULT NULL, Street varchar(100) DEFAULT NULL, City varchar(25) DEFAULT NULL, Province varchar(25) DEFAULT NULL, PostalCode varchar(10) DEFAULT NULL, Country varchar(50) DEFAULT NULL, Latitude float(10,6) DEFAULT NULL, Longitude float(10,6) DEFAULT NULL, PreferredStore tinyint(1) DEFAULT 0, CustomInfo varchar(255) DEFAULT NULL, PRIMARY KEY (`ID`) );"; require_once(ABSPATH."wp-admin/includes/upgrade.php"); dbDelta($sql); } } //Function to un-register scripts function akwUnregisterScripts() { wp_dequeue_script('add-akw-store-locator-script'); wp_dequeue_script('add-akw-google-api'); wp_dequeue_script('addakwadminjsfunctions'); wp_dequeue_style('addPaginationStyle1'); wp_dequeue_style('addPaginationStyle2'); wp_dequeue_style('addAKWStoreLocatorCss'); } //Function to display admin stores page function storeLocator_stores_page () { global $wpdb; $table_name = $wpdb->prefix."Stores"; if(isset($_GET['action'])) { switch($_GET['action']) { //Delete when delete link is clicked case 'delete': $wpdb->get_results("DELETE FROM $table_name WHERE ID=".$_GET['ID']); break; } //switch } if(isset($_POST['deleteButton'])) { //Delete when multiple stores are selected using checkboxes $checkbox = $_POST['storesCheckbox']; $countCheckbox = count($_POST['storesCheckbox']); for($i=0; $i<$countCheckbox; $i++) { $delID = $checkbox[$i]; $wpdb->get_results("DELETE FROM $table_name WHERE ID=$delID"); //, $table_name, $delID); } } echo '
'; echo '

Stores

'; echo ''; echo '
'; echo '
'; echo ' '; echo ''; echo ' '; echo ' '; echo '  '; echo '
'; echo '
'; echo '
'; echo '

'; echo '

   

'; echo ''; //Pagination code $pageNo = (int) (!isset($_GET["pageNo"]) ? 1 : $_GET["pageNo"]); //Set max number of records to be displayed in a page $limit = 30; $startpoint = ($pageNo * $limit) - $limit; $statement = $table_name; $sql = "SELECT COUNT(*) FROM $table_name LIMIT $startpoint, $limit"; $count = $wpdb->get_results($sql); if($count > 0) { $count = 0; echo pagination($statement, $limit, $pageNo, admin_url('admin.php?page=storeLocator_admin&')); $sql = "SELECT * FROM $table_name "; if(isset($_POST['searchAdminStores'])) { $sql .= " WHERE ".$_POST['searchType']." LIKE '%".trim($_POST['searchString'])."%' "; } $sql .= " ORDER BY Country, Province, Name, ID ASC LIMIT $startpoint, $limit"; $q = $wpdb->get_results($sql); if(count($q) > 0) { foreach($q AS $f) { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; if($f->Latitude == 0.000000) { echo ''; } else { echo ''; } if($f->PreferredStore == 0) { echo ''; } else { echo ''; } echo ''; echo ''; $count++; } } else { echo ''; } } else { echo ''; } echo '
NameStreetCityProvinceCountryPostal/ZIP CodeCoordinatesPreferred StoreAction
'.$f->Name.''.$f->Street.''.$f->City.''.$f->Province.''.$f->Country.''.$f->PostalCode.'EmptyYesNoYes'; echo 'Edit | '; echo ' Delete'; echo '
No Stores found for the search results
No Stores added
'; echo '
'; echo '
'; ?> prefix."Stores"; $errMsgs = array(); if(isset($_POST['action'])) { if(trim(stripslashes($_POST['name'] == ''))) { $errMsgs[] = "Every store must have a name."; } if(count($errMsgs) == 0) { $name = trim($_POST['name']); $street = trim($_POST['street']); $city = trim($_POST['city']); $country = trim($_POST['country']); $province = trim($_POST['province']); $phone = trim($_POST['phone']); $latitude = trim($_POST['latitude']); $longitude = trim($_POST['longitude']); $postalCode = trim($_POST['postalCode']); if(isset($_POST['preferredStore'])) { $preferredStore = trim($_POST['preferredStore']); } else { $preferredStore = 0; } $customInfo = trim($_POST['customInfo']); switch($_POST['action']) { //Update store case 'update': $wpdb->update( $table_name, array( 'Name' => $name, 'Street' => $street, 'City' => $city, 'Province' => $province, 'Country' => $country, 'PostalCode' => $postalCode, 'Phone' => $phone, 'Latitude' => $latitude, 'Longitude' => $longitude, 'PreferredStore' => $preferredStore, 'CustomInfo' => $customInfo ), array( 'ID' => $_POST['ID'] ), array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%f', '%f', '%d', '%s' ), array( '%d' ) ); $errMsgs[] = "Your updates have been saved."; break; //Insert new store case 'insert': $wpdb->insert( $table_name, array( 'Name' => $name, 'Street' => $street, 'City' => $city, 'Province' => $province, 'Country' => $country, 'PostalCode' => $postalCode, 'Phone' => $phone, 'Latitude' => $latitude, 'Longitude' => $longitude, 'PreferredStore' => $preferredStore, 'CustomInfo' => $customInfo ), array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%f', '%f', '%d', '%s' ) ); $_REQUEST['ID'] = $wpdb->insert_id; $errMsgs[] = "New store has been added."; break; } //switch } //if } //if echo '
'; echo '

Add Store

'; echo ''; echo '

Steps to add a store:

'; if(isset($_REQUEST['ID']) && $_REQUEST['ID'] > 0) { $sql = "SELECT ID, Name, Street, City, Country, Phone, Province, PostalCode, Latitude, Longitude, PreferredStore, CustomInfo FROM $table_name\n"; $sql .= " WHERE ID = ".$_REQUEST['ID']." LIMIT 1"; $f = $wpdb->get_results($sql); } if(isset($_REQUEST['ID']) && $_REQUEST['ID'] > 0) { echo '
'; ?> '; ?>
0) { ?> 0 && $f > 0) { foreach($f AS $r) { ?>
'.$errMsg.'

'; } ?>

PreferredStore == 1 ? 'checked=checked' : ''); ?> />

prefix."Stores"; $errMsgs = array(); $csvMimeTypes = array("text/csv", "application/vnd.ms-excel", "text/comma-separated-values", "application/csv", "application/excel", "application/vnd.msexcel"); if(isset($_POST['uploadCSV'])) { if($_FILES["file"]["error"] > 0) { $errMsgs[] = $_FILES["file"]["error"]; } if(count($errMsgs) == 0) { if(in_array($_FILES["file"]["type"], $csvMimeTypes)) { $csvFile = plugin_dir_path(__FILE__).'sqlFile.csv'; move_uploaded_file($_FILES["file"]["tmp_name"], $csvFile); $errMsgs[] = "File uploaded successfully."; include_once(plugin_dir_path(__FILE__).'simplecsvimport.php'); } else { $errMsgs[] = "The selected file is not a .csv file"; } } } ?>

To Create a CSV file:


'; ?>

Upload CSV file

'.$errMsg."

\n"; } ?>

Get Coordinates for Stores

Clicking on the Get Coordinates button gets the geo-location details for all the stores that do not have a latitude or longitude.

Saving coordinates...
Working ...
Please wait...
plugins_url('/akw-store-locator') ); wp_localize_script('addakwadminjsfunctions', 'akwstorelocatoradminobject', $akwStoreLocatorAdminArray); //Check current version } //Function to display store locator in the theme pages function displayakwstorelocator($attributes) { $imageURL = WP_PLUGIN_URL.'/akw-store-locator/images/working.gif'; //Array to declare object with attributes in js file $akwStoreLocatorArray = array( 'plugin_url' => plugins_url('/akw-store-locator') ); wp_register_script('add-akw-store-locator-script', plugins_url('/akw-store-locator/js/storeLocatorFunctions.js')); wp_enqueue_script('add-akw-store-locator-script'); wp_localize_script('add-akw-store-locator-script', 'akwstorelocatorobject', $akwStoreLocatorArray); wp_enqueue_style('addAKWStoreLocatorCss', plugins_url('/akw-store-locator/css/akw-store-locator-style.css')); //short code attributes set or replace defaults $shortCodeAttr = shortcode_atts( array( 'maplabel' => 'Postal/Zip, City/Province/State or Full Address', 'mapbutton' => 'Search Stores', 'storelabel' => 'Store Name(Optional)', ), $attributes); $output .= '
'; $output .= '
Loading...
Working ...
Please wait...
'; $output .= ''; $output .= ''; $output .= '
'; $output .= '
'; $output .= ''; $output .= ''; $output .= '
'; $output .= '
'; $output .= ''; $output .= ''; $output .= ' '; $output .= ''; $output .= '
'; $output .= '
'; $output .= ''; $output .= '
'; $output .= '

 

'; $output .= '
'; $output .= '
'; $output .= '
'; $output .= '
'; return $output; } //Add shortcode for the display function add_shortcode('akwstorelocator', 'displayakwstorelocator'); //Function to add google api script to the theme header function addakwstorelocatorscriptstotheme() { if(!wp_script_is('googleapis', 'enqueued')) { if(USE_GOOGLE_KEY == true) { wp_enqueue_script('googleapiurl', 'http://maps.googleapis.com/maps/api/js?key='.GOOGLE_API_KEY.'&sensor=true'); } else { wp_enqueue_script('googleapiurl', 'http://maps.googleapis.com/maps/api/js?sensor=true'); } wp_enqueue_script('add-akw-google-api'); } } //Using action to add the google api add_action('wp_enqueue_scripts', 'addakwstorelocatorscriptstotheme'); ?>