Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php /* Template Name: Store Locator */
- get_header(); ?>
- <?php
- /* Define MySQL connection details and database table name */
- $SETTINGS["hostname"]='sql31.jnb1.host-h.net';
- $SETTINGS["mysql_user"]='gacreative';
- $SETTINGS["mysql_pass"]='Wfk9tcUCcU8';
- $SETTINGS["mysql_database"]='aglet_gacreate';
- $SETTINGS["data_table"]='styles'; // this is the default database name that we used
- /* Connect to MySQL */
- if (!isset($install) or $install != '1') {
- $connection = mysql_connect($SETTINGS["hostname"], $SETTINGS["mysql_user"], $SETTINGS["mysql_pass"]) or die ('Unable to connect to MySQL server.<br ><br >Please make sure your MySQL login details are correct.');
- $db = mysql_select_db($SETTINGS["mysql_database"], $connection) or die ('request "Unable to select database."');
- };
- ?>
- <script type="text/javascript">
- var markers = [];
- var locationSelect;
- var customIcons = {
- Cutty: {
- icon: '<?php bloginfo('template_directory'); ?>/images/c.png'
- },
- JonathanD: {
- icon: '<?php bloginfo('template_directory'); ?>/images/j.png'
- },
- All: {
- icon: '<?php bloginfo('template_directory'); ?>/images/all.png'
- }
- };
- //<![CDATA[
- var map;
- var markers = [];
- var infoWindow;
- function load() {
- map = new google.maps.Map(document.getElementById("gmaps-canvas"), {
- center: new google.maps.LatLng(-26.417060, 28.46808),
- zoom: 7,
- mapTypeId: 'roadmap'
- });
- infoWindow = new google.maps.InfoWindow();
- locationSelect = document.getElementById("locationSelect");
- locationSelect.onchange = function() {
- var markerNum = locationSelect.options[locationSelect.selectedIndex].value;
- if (markerNum != "none"){
- google.maps.event.trigger(markers[markerNum], 'click');
- }
- };
- }
- function searchLocations() {
- var address = document.getElementById("gmaps-input-address").value;
- var geocoder = new google.maps.Geocoder();
- geocoder.geocode({address: address}, function(results, status) {
- if (status == google.maps.GeocoderStatus.OK) {
- searchLocationsNear(results[0].geometry.location);
- } else {
- alert(address + ' not found');
- }
- });
- }
- function clearLocations() {
- infoWindow.close();
- for (var i = 0; i < markers.length; i++) {
- markers[i].setMap(null);
- }
- markers.length = 0;
- locationSelect.innerHTML = "";
- var option = document.createElement("option");
- option.value = "none";
- option.innerHTML = "See all results:";
- locationSelect.appendChild(option);
- }
- function searchLocationsNear(center) {
- clearLocations();
- var radius = 25;
- var searchUrl = '<?php bloginfo('template_directory'); ?>/xml/phpsqlajax_genxml.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius;
- downloadUrl(searchUrl, function(data) {
- var xml = parseXml(data);
- var markers = xml.documentElement.getElementsByTagName("marker");
- var bounds = new google.maps.LatLngBounds();
- for (var i = 0; i < markers.length; i++) {
- var name = markers[i].getAttribute("name");
- var address = markers[i].getAttribute("address");
- var phone = markers[i].getAttribute("tel");
- var hours = markers[i].getAttribute("hours");
- var type = markers[i].getAttribute("type");
- var distance = parseFloat(markers[i].getAttribute("distance"));
- var latlng = new google.maps.LatLng(
- parseFloat(markers[i].getAttribute("lat")),
- parseFloat(markers[i].getAttribute("lng")));
- if (type == "Cutty"){
- var paste = "<img src='/img/ga-creative-brands-cutty-tag.svg' />";
- }
- else if (type == "JonathanD") {
- var paste = "<img src='/img/ga-creative-brands-jonathan-d-tag.svg' />";
- }
- else {
- var paste = "<img src='/img/ga-creative-brands-jonathan-d-tag.svg' /> | <img src='/img/ga-creative-brands-cutty-tag.svg' />";
- }
- var html = "<b>" + name + "</b> <br/>" + address + "<br />" + hours + "<br />" + "Tel: " + phone + "<br >" + paste + "<br /> <br />" +
- "<a href='https://maps.google.com?saddr=&daddr=" + address + "' target='_empty'><img src='/img/ga-creative-brands-directions-button.svg' width='120px' /></a>";
- createOption(name, distance, i);
- createMarker(latlng, name, address);
- bounds.extend(latlng);
- }
- map.fitBounds(bounds);
- locationSelect.style.visibility = "visible";
- locationSelect.onchange = function() {
- var markerNum = locationSelect.options[locationSelect.selectedIndex].value;
- google.maps.event.trigger(markers[markerNum], 'click');
- };
- });
- }
- function createMarker(latlng, name, address, hours, phone, paste,tel) {
- var html = "<b>" + name + "</b> <br/>" + address + "<br />" + hours + "<br />" + "Tel: " + phone + "<br >" + paste + "<br /> <br />" +
- "<a href='https://maps.google.com?saddr=&daddr=" + address + "' target='_empty'><img src='/img/ga-creative-brands-directions-button.svg' width='120px' /></a>";
- var icon = customIcons[type] || {};
- var marker = new google.maps.Marker({
- map: map,
- icon: icon.icon,
- shadow: icon.shadow,
- position: latlng
- });
- google.maps.event.addListener(marker, 'click', function() {
- infoWindow.setContent(html);
- infoWindow.open(map, marker);
- });
- markers.push(marker);
- }
- function createOption(name, distance, num) {
- var option = document.createElement("li");
- option.value = num;
- option.innerHTML = name + "(" + distance.toFixed(1) + " km" + ")";
- locationSelect.appendChild(option);
- }
- function downloadUrl(url, callback) {
- var request = window.ActiveXObject ?
- new ActiveXObject('Microsoft.XMLHTTP') :
- new XMLHttpRequest;
- request.onreadystatechange = function() {
- if (request.readyState == 4) {
- request.onreadystatechange = doNothing;
- callback(request.responseText, request.status);
- }
- };
- request.open('GET', url, true);
- request.send(null);
- }
- function parseXml(str) {
- if (window.ActiveXObject) {
- var doc = new ActiveXObject('Microsoft.XMLDOM');
- doc.loadXML(str);
- return doc;
- } else if (window.DOMParser) {
- return (new DOMParser).parseFromString(str, 'text/xml');
- }
- }
- function doNothing() {}
- //]]>
- var locations = [<?php
- $host = "sql31.jnb1.host-h.net";
- $username = "GA_agl3t";
- $password = "RVJj9Xx7GL8";
- $database = "GA_agl3t";
- // Create connection
- $conn = new mysqli('sql31.jnb1.host-h.net', $username, $password, $database);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "SELECT * FROM stores";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- // output data of each row
- while($row = $result->fetch_assoc()) {
- echo "['" .$row["id"]. "','" .$row["name"]. "','" .$row["address"]. "','" .$row["hours"]. "','" .$row["lat"]. "','" .$row["lng"]. "','" .$row["type"].
- "','" .$row["telephone"]. "','" .$row["storeid"]."'],";
- }
- }
- ?>];
- function setActive(event) {
- if (event.target.tagName !== 'A') {
- return false;
- }
- addActiveClass(event.target);
- }
- function addActiveClass(link) {
- var activeLink = document.getElementsByClassName('active');
- if (activeLink.length) {
- activeLink[0].className = '';
- }
- link.className = 'active';
- }
- window.onload = function () {
- var nav = document.getElementsByClassName('nav');
- nav[0].addEventListener('click', setActive);
- }
- </script>
- <script>
- $(document).ready(function(){
- load();
- $('#style').keyup(function(){
- $(".list").hide();
- var txt = $(this).val();
- if(txt != '')
- {
- $.ajax({
- url:"<?php bloginfo('template_directory'); ?>/storelocator/find.php",
- method:"post",
- data:{search:txt},
- dataType:"text",
- success:function(data)
- {
- $('#result').html(data);
- }
- });
- }
- else
- {
- $('#result').html('');
- }
- });
- });
- $(document).ready(function () {
- $('#send').on('submit', function(e) {
- $c = $("#type").val();
- $d = $("#category").val();
- e.preventDefault();
- $.ajax({
- url:"<?php bloginfo('template_directory'); ?>/storelocator/selector.php",
- type: "POST",
- data: $(this).serialize(),
- success: function (data) {
- $(".list").hide();
- $("#result").html(data);
- },
- error: function (jXHR, textStatus, errorThrown) {
- alert(errorThrown);
- }
- });
- });
- });
- </script>
- <div id="page">
- <div class="row">
- <div class="">
- <form id="send">
- <div class="container seven-cols">
- <div class="container">
- <div class="col-md-1"><b>Area:</b></div>
- <div class="col-md-2 location-search">
- <div id="input">
- <input id="gmaps-input-address" class="form-control" name="add" placeholder="Start typing a place name..." type="text" required>
- </div>
- </div>
- <div class="col-md-1"><b>Filter by:</b></div>
- <div class="col-md-2">
- <?php $type = $_POST['type'];
- $cat = $_POST['category'];
- ?>
- <select class="form-control" name="type" id="type">
- <option value="">Brand</option>
- <option value="Cutty" <?php if ($_POST[ 'type']=="Cutty" ) {echo "selected='selected'"; } ?>>Cutty</option>
- <option value="Jonathan D" <?php if ($_POST[ 'type']=="Jonathan D" ) {echo "selected='selected'"; } ?>>Jonathan D</option>
- </select>
- </div>
- <div class="col-md-2">
- <?php
- mysql_connect($host, $username, $password);
- mysql_select_db('GA_agl3t');
- $sql = "SELECT DISTINCT Category FROM styles";
- $result = mysql_query($sql);
- echo "<select class='form-control' name='category' id='category'>";
- ?>
- <option value="">Category</option>
- <?php
- while ($row = mysql_fetch_array($result)) {
- echo "<option value='" . $row['Category'] ."'>" . $row['Category'] ."</option>";
- }
- echo "</select>";
- mysql_close();
- ?>
- </div>
- <div class="col-md-2"><input type="text" id="style" name="style" placeholder="Enter style.." class="form-control" value="<?php echo $_POST['product_title']; ?>">
- <br />
- </div>
- <div class="col-md-2"><input type="submit" id="send" class="btn btn-danger sending" value="FIND STORES" onclick="searchLocations()">
- </form>
- </div>
- </div>
- </div>
- </div>
- <br />
- <div>
- </div>
- <div class="container"><select id="locationSelect" style="width:50%;visibility:hidden"></select></div>
- <div class="container">
- <div class="col-md-3 hidden-xs">
- <?php if (!empty($_POST["style"])) {
- $c = $_POST["style"];
- $connect = mysqli_connect('sql31.jnb1.host-h.net',$username, $password, $database);
- $output = '';
- $sql = "SELECT DISTINCT Storeids
- FROM styles
- where Name ='".$_POST['style']."'";
- $result = mysqli_query($connect, $sql);
- if(mysqli_num_rows($result) > 0)
- {
- $output .= '<p align="center">Search Result</p>';
- $output .= '<div class="table-responsive">
- <table class="table table bordered">
- <tr>
- <th>Store IDs</th>
- </tr>';
- while($row = mysqli_fetch_array($result))
- {
- $i++;
- $raw = $row["Storeids"];
- // echo "StoreIDs from Styles" . $raw . "<br>";
- $pieces = explode(",", $raw); // Take all the storeids which are sep by a comma and put into array
- $inString = implode("','", $pieces); // take each elemetn and wrap it with ','
- $inString = ereg_replace(" ","",$inString); // remove white spaces
- $sql = "SELECT * FROM stores WHERE storeid in ('".$inString."')"; // qeury to get all stores where store id in usign the IN from SQL
- echo $SQL . "<br>";
- $Stores = $connect->query($sql) or die ('noooo');
- while($Store = $Stores->fetch_assoc()) {
- echo "<div class='panel panel-default'> <div class='panel-heading'>
- <h5>
- <a data-toggle='collapse' data-parent='#accordion' href='#collapse$i' onclick='myClick($i);'>";
- echo $Store["name"];
- echo " <i class='more-less glyphicon glyphicon-plus'></i> </a> </h5></div>";
- echo "<div id='collapse$i' class='panel-collapse collapse'>
- <div class='panel-body'>";
- echo "Address: " .$Store['address']. "<br />Tel: " .$Store['telephone']. "<br />Email: " .$Store['Email']. "<br />Operating Hours: " .$Store['hours']. "";
- echo "
- </div>
- </div>
- </div>";
- $i++;
- }
- }
- }
- else
- {
- ?>
- <?php
- }
- } ?>
- <div class="panel-group list" id="accordion">
- <?php
- $conn = mysql_connect($host , $username, $password);
- if(! $conn ) {
- die('Could not connect: ' . mysql_error());
- }
- $ty = $_POST['product_brand'];
- $sql = "SELECT * FROM stores";
- mysql_select_db('GA_agl3t');
- $retval = mysql_query( $sql, $conn );
- if(! $retval ) {
- die('Could not get data: ' . mysql_error());
- }
- $i = 0;
- while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
- echo "<div class='panel panel-default'> <div class='panel-heading'>
- <h5>
- <a data-toggle='collapse' data-parent='#accordion' class='pan-link' href='#collapse$i' onclick='myClick($i);'>";
- echo $row["name"];
- echo " <i class='more-less glyphicon glyphicon-plus'></i> </a> </h5></div>";
- echo "<div id='collapse$i' class='panel-collapse collapse'>
- <div class='panel-body'>";
- $what_type = $row['type'];
- if ($what_type == "Cutty") {
- $type = "<img src='/img/ga-creative-brands-cutty-tag.svg' />";
- }
- elseif ($what_type == "All") {
- $type = "<img src='/img/ga-creative-brands-jonathan-d-tag.svg' /> | <img src='/img/ga-creative-brands-cutty-tag.svg' />";
- }
- else {
- $type = "<img src='/img/ga-creative-brands-jonathan-d-tag.svg' />";
- }
- echo "Address: " .$row['address']. "<br />Tel: " .$row['telephone']. "<br />Email: " .$row['Email']. "<br />Operating Hours: " .$row['hours']. "<br /><div class='type-brand'><br />" .$type. "</div>";
- echo "<a href='https://maps.google.com?saddr=&daddr=".$row['address']."' target='_blank'><img src='/img/ga-creative-brands-directions-button.svg' width='120px' /></a>";
- echo "
- </div>
- </div>
- </div>";
- $i++;
- }
- mysql_close($conn);
- ?>
- </div>
- <div id='result'></div>
- </div>
- <div class="col-md-9">
- <div id="gmaps-canvas" style="width: 100%; height: 450px" ></div>
- </div>
- </div>
- </div>
- </div>
- <br />
- <br />
- <nav class="nav visible-xs">
- <a href="#col1" class="active">STORE LIST</a>
- <a href="#col2">MAP</a>
- </nav>
- <div class="content-wrapper visible-xs">
- <div class="content">
- <div id="col-md-3">
- <div id="result"></div>
- <div class="panel-group list" id="accordion">
- <?php
- $conn = mysql_connect($host , $username, $password);
- if(! $conn ) {
- die('Could not connect: ' . mysql_error());
- }
- $ty = $_POST['product_brand'];
- $sql = "SELECT * FROM stores";
- mysql_select_db('GA_agl3t');
- $retval = mysql_query( $sql, $conn );
- if(! $retval ) {
- die('Could not get data: ' . mysql_error());
- }
- $i = 0;
- while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
- echo "<div class='panel-default'> <div class='panel-heading'>
- <h5>
- <a data-toggle='collapse' data-parent='#accordion' href='#collapse$i' onclick='myClick($i);'>";
- echo $row["name"];
- echo " <i class='more-less glyphicon glyphicon-plus'></i> </a> </h5></div>";
- echo "<div id='collapse$i' class='panel-collapse collapse'>
- <div class='panel-body'>";
- echo "Address: " .$row['address']. "<br />Tel: " .$row['telephone']. "<br />Email: " .$row['Email']. "<br />Operating Hours: " .$row['hours']. "<br /><div class='type-brand'>" .$row['type']. "</div>";
- echo "<a href='https://maps.google.com?saddr=&daddr=".$row['address']."' target='_blank'>DIRECTIONS</a>";
- echo "
- </div>
- </div>
- </div>";
- $i++;
- }
- mysql_close($conn);
- ?>
- </div></div>
- <div id="col-md-9">
- <div style="width: 100%; height: 60%" id="gmaps-canvas"></div>
- </div>
- </div>
- </div>
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement