Advertisement
aglet

New loca

Dec 13th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.90 KB | None | 0 0
  1. <?php /* Template Name: Store Locator */
  2. get_header(); ?>
  3.  
  4. <?php
  5.  
  6. /* Define MySQL connection details and database table name */
  7. $SETTINGS["hostname"]='sql31.jnb1.host-h.net';
  8. $SETTINGS["mysql_user"]='gacreative';
  9. $SETTINGS["mysql_pass"]='Wfk9tcUCcU8';
  10. $SETTINGS["mysql_database"]='aglet_gacreate';
  11. $SETTINGS["data_table"]='styles'; // this is the default database name that we used
  12.  
  13. /* Connect to MySQL */
  14.  
  15. if (!isset($install) or $install != '1') {
  16. $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.');
  17. $db = mysql_select_db($SETTINGS["mysql_database"], $connection) or die ('request "Unable to select database."');
  18. };
  19. ?>
  20.  
  21.  
  22.  
  23.  
  24. <script type="text/javascript">
  25.  
  26.  
  27. var markers = [];
  28. var locationSelect;
  29. var customIcons = {
  30. Cutty: {
  31. icon: '<?php bloginfo('template_directory'); ?>/images/c.png'
  32. },
  33. JonathanD: {
  34. icon: '<?php bloginfo('template_directory'); ?>/images/j.png'
  35. },
  36.  
  37. All: {
  38. icon: '<?php bloginfo('template_directory'); ?>/images/all.png'
  39. }
  40.  
  41. };
  42.  
  43.  
  44.  
  45. //<![CDATA[
  46. var map;
  47. var markers = [];
  48. var infoWindow;
  49.  
  50.  
  51. function load() {
  52. map = new google.maps.Map(document.getElementById("gmaps-canvas"), {
  53. center: new google.maps.LatLng(-26.417060, 28.46808),
  54. zoom: 7,
  55. mapTypeId: 'roadmap'
  56. });
  57. infoWindow = new google.maps.InfoWindow();
  58.  
  59. locationSelect = document.getElementById("locationSelect");
  60. locationSelect.onchange = function() {
  61. var markerNum = locationSelect.options[locationSelect.selectedIndex].value;
  62. if (markerNum != "none"){
  63. google.maps.event.trigger(markers[markerNum], 'click');
  64. }
  65. };
  66. }
  67.  
  68. function searchLocations() {
  69. var address = document.getElementById("gmaps-input-address").value;
  70. var geocoder = new google.maps.Geocoder();
  71.  
  72.  
  73. geocoder.geocode({address: address}, function(results, status) {
  74. if (status == google.maps.GeocoderStatus.OK) {
  75. searchLocationsNear(results[0].geometry.location);
  76. } else {
  77. alert(address + ' not found');
  78. }
  79. });
  80. }
  81.  
  82. function clearLocations() {
  83. infoWindow.close();
  84. for (var i = 0; i < markers.length; i++) {
  85. markers[i].setMap(null);
  86. }
  87. markers.length = 0;
  88.  
  89. locationSelect.innerHTML = "";
  90. var option = document.createElement("option");
  91. option.value = "none";
  92. option.innerHTML = "See all results:";
  93. locationSelect.appendChild(option);
  94. }
  95.  
  96. function searchLocationsNear(center) {
  97. clearLocations();
  98.  
  99. var radius = 25;
  100. var searchUrl = '<?php bloginfo('template_directory'); ?>/xml/phpsqlajax_genxml.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius;
  101. downloadUrl(searchUrl, function(data) {
  102. var xml = parseXml(data);
  103. var markers = xml.documentElement.getElementsByTagName("marker");
  104. var bounds = new google.maps.LatLngBounds();
  105. for (var i = 0; i < markers.length; i++) {
  106. var name = markers[i].getAttribute("name");
  107. var address = markers[i].getAttribute("address");
  108.  
  109. var phone = markers[i].getAttribute("tel");
  110. var hours = markers[i].getAttribute("hours");
  111. var type = markers[i].getAttribute("type");
  112. var distance = parseFloat(markers[i].getAttribute("distance"));
  113. var latlng = new google.maps.LatLng(
  114. parseFloat(markers[i].getAttribute("lat")),
  115. parseFloat(markers[i].getAttribute("lng")));
  116.  
  117. if (type == "Cutty"){
  118. var paste = "<img src='/img/ga-creative-brands-cutty-tag.svg' />";
  119. }
  120.  
  121. else if (type == "JonathanD") {
  122. var paste = "<img src='/img/ga-creative-brands-jonathan-d-tag.svg' />";
  123. }
  124.  
  125. else {
  126. var paste = "<img src='/img/ga-creative-brands-jonathan-d-tag.svg' /> | <img src='/img/ga-creative-brands-cutty-tag.svg' />";
  127. }
  128. var html = "<b>" + name + "</b> <br/>" + address + "<br />" + hours + "<br />" + "Tel: " + phone + "<br >" + paste + "<br /> <br />" +
  129. "<a href='https://maps.google.com?saddr=&daddr=" + address + "' target='_empty'><img src='/img/ga-creative-brands-directions-button.svg' width='120px' /></a>";
  130.  
  131.  
  132. createOption(name, distance, i);
  133. createMarker(latlng, name, address);
  134. bounds.extend(latlng);
  135. }
  136. map.fitBounds(bounds);
  137. locationSelect.style.visibility = "visible";
  138. locationSelect.onchange = function() {
  139. var markerNum = locationSelect.options[locationSelect.selectedIndex].value;
  140. google.maps.event.trigger(markers[markerNum], 'click');
  141. };
  142. });
  143. }
  144.  
  145. function createMarker(latlng, name, address, hours, phone, paste,tel) {
  146. var html = "<b>" + name + "</b> <br/>" + address + "<br />" + hours + "<br />" + "Tel: " + phone + "<br >" + paste + "<br /> <br />" +
  147. "<a href='https://maps.google.com?saddr=&daddr=" + address + "' target='_empty'><img src='/img/ga-creative-brands-directions-button.svg' width='120px' /></a>";
  148. var icon = customIcons[type] || {};
  149. var marker = new google.maps.Marker({
  150. map: map,
  151. icon: icon.icon,
  152. shadow: icon.shadow,
  153. position: latlng
  154. });
  155. google.maps.event.addListener(marker, 'click', function() {
  156. infoWindow.setContent(html);
  157. infoWindow.open(map, marker);
  158. });
  159. markers.push(marker);
  160. }
  161.  
  162. function createOption(name, distance, num) {
  163. var option = document.createElement("li");
  164. option.value = num;
  165. option.innerHTML = name + "(" + distance.toFixed(1) + " km" + ")";
  166. locationSelect.appendChild(option);
  167. }
  168.  
  169. function downloadUrl(url, callback) {
  170. var request = window.ActiveXObject ?
  171. new ActiveXObject('Microsoft.XMLHTTP') :
  172. new XMLHttpRequest;
  173.  
  174. request.onreadystatechange = function() {
  175. if (request.readyState == 4) {
  176. request.onreadystatechange = doNothing;
  177. callback(request.responseText, request.status);
  178. }
  179. };
  180.  
  181. request.open('GET', url, true);
  182. request.send(null);
  183. }
  184.  
  185. function parseXml(str) {
  186. if (window.ActiveXObject) {
  187. var doc = new ActiveXObject('Microsoft.XMLDOM');
  188. doc.loadXML(str);
  189. return doc;
  190. } else if (window.DOMParser) {
  191. return (new DOMParser).parseFromString(str, 'text/xml');
  192. }
  193. }
  194.  
  195. function doNothing() {}
  196.  
  197. //]]>
  198.  
  199.  
  200. var locations = [<?php
  201.  
  202. $host = "sql31.jnb1.host-h.net";
  203. $username = "GA_agl3t";
  204. $password = "RVJj9Xx7GL8";
  205. $database = "GA_agl3t";
  206.  
  207. // Create connection
  208. $conn = new mysqli('sql31.jnb1.host-h.net', $username, $password, $database);
  209. // Check connection
  210. if ($conn->connect_error) {
  211. die("Connection failed: " . $conn->connect_error);
  212. }
  213.  
  214. $sql = "SELECT * FROM stores";
  215. $result = $conn->query($sql);
  216.  
  217. if ($result->num_rows > 0) {
  218. // output data of each row
  219. while($row = $result->fetch_assoc()) {
  220. echo "['" .$row["id"]. "','" .$row["name"]. "','" .$row["address"]. "','" .$row["hours"]. "','" .$row["lat"]. "','" .$row["lng"]. "','" .$row["type"].
  221. "','" .$row["telephone"]. "','" .$row["storeid"]."'],";
  222.  
  223.  
  224.  
  225.  
  226. }
  227. }
  228.  
  229. ?>];
  230.  
  231.  
  232. function setActive(event) {
  233. if (event.target.tagName !== 'A') {
  234. return false;
  235. }
  236.  
  237. addActiveClass(event.target);
  238. }
  239.  
  240. function addActiveClass(link) {
  241. var activeLink = document.getElementsByClassName('active');
  242. if (activeLink.length) {
  243. activeLink[0].className = '';
  244. }
  245.  
  246. link.className = 'active';
  247. }
  248.  
  249. window.onload = function () {
  250. var nav = document.getElementsByClassName('nav');
  251. nav[0].addEventListener('click', setActive);
  252. }
  253.  
  254. </script>
  255.  
  256.  
  257. <script>
  258. $(document).ready(function(){
  259. load();
  260. $('#style').keyup(function(){
  261. $(".list").hide();
  262.  
  263. var txt = $(this).val();
  264. if(txt != '')
  265. {
  266. $.ajax({
  267. url:"<?php bloginfo('template_directory'); ?>/storelocator/find.php",
  268. method:"post",
  269. data:{search:txt},
  270. dataType:"text",
  271. success:function(data)
  272. {
  273. $('#result').html(data);
  274. }
  275. });
  276. }
  277. else
  278. {
  279. $('#result').html('');
  280. }
  281. });
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288. });
  289.  
  290.  
  291.  
  292.  
  293. $(document).ready(function () {
  294.  
  295.  
  296.  
  297. $('#send').on('submit', function(e) {
  298. $c = $("#type").val();
  299. $d = $("#category").val();
  300.  
  301.  
  302.  
  303. e.preventDefault();
  304. $.ajax({
  305. url:"<?php bloginfo('template_directory'); ?>/storelocator/selector.php",
  306. type: "POST",
  307. data: $(this).serialize(),
  308. success: function (data) {
  309. $(".list").hide();
  310.  
  311. $("#result").html(data);
  312. },
  313. error: function (jXHR, textStatus, errorThrown) {
  314. alert(errorThrown);
  315. }
  316. });
  317. });
  318. });
  319.  
  320.  
  321.  
  322. </script>
  323.  
  324.  
  325.  
  326. <div id="page">
  327. <div class="row">
  328. <div class="">
  329.  
  330. <form id="send">
  331.  
  332. <div class="container seven-cols">
  333. <div class="container">
  334. <div class="col-md-1"><b>Area:</b></div>
  335. <div class="col-md-2 location-search">
  336.  
  337. <div id="input">
  338. <input id="gmaps-input-address" class="form-control" name="add" placeholder="Start typing a place name..." type="text" required>
  339.  
  340. </div>
  341.  
  342. </div>
  343. <div class="col-md-1"><b>Filter by:</b></div>
  344. <div class="col-md-2">
  345.  
  346. <?php $type = $_POST['type'];
  347. $cat = $_POST['category'];
  348.  
  349. ?>
  350. <select class="form-control" name="type" id="type">
  351. <option value="">Brand</option>
  352.  
  353. <option value="Cutty" <?php if ($_POST[ 'type']=="Cutty" ) {echo "selected='selected'"; } ?>>Cutty</option>
  354. <option value="Jonathan D" <?php if ($_POST[ 'type']=="Jonathan D" ) {echo "selected='selected'"; } ?>>Jonathan D</option>
  355. </select>
  356.  
  357. </div>
  358.  
  359.  
  360. <div class="col-md-2">
  361.  
  362. <?php
  363.  
  364.  
  365.  
  366. mysql_connect($host, $username, $password);
  367. mysql_select_db('GA_agl3t');
  368.  
  369. $sql = "SELECT DISTINCT Category FROM styles";
  370. $result = mysql_query($sql);
  371.  
  372. echo "<select class='form-control' name='category' id='category'>";
  373.  
  374. ?>
  375. <option value="">Category</option>
  376. <?php
  377.  
  378. while ($row = mysql_fetch_array($result)) {
  379. echo "<option value='" . $row['Category'] ."'>" . $row['Category'] ."</option>";
  380. }
  381. echo "</select>";
  382. mysql_close();
  383.  
  384. ?>
  385. </div>
  386.  
  387. <div class="col-md-2"><input type="text" id="style" name="style" placeholder="Enter style.." class="form-control" value="<?php echo $_POST['product_title']; ?>">
  388. <br />
  389. </div>
  390. <div class="col-md-2"><input type="submit" id="send" class="btn btn-danger sending" value="FIND STORES" onclick="searchLocations()">
  391.  
  392. </form>
  393.  
  394.  
  395.  
  396. </div>
  397. </div>
  398. </div>
  399. </div>
  400. <br />
  401.  
  402.  
  403. <div>
  404.  
  405. </div>
  406. <div class="container"><select id="locationSelect" style="width:50%;visibility:hidden"></select></div>
  407.  
  408. <div class="container">
  409. <div class="col-md-3 hidden-xs">
  410. <?php if (!empty($_POST["style"])) {
  411.  
  412.  
  413. $c = $_POST["style"];
  414.  
  415.  
  416.  
  417.  
  418. $connect = mysqli_connect('sql31.jnb1.host-h.net',$username, $password, $database);
  419. $output = '';
  420. $sql = "SELECT DISTINCT Storeids
  421. FROM styles
  422. where Name ='".$_POST['style']."'";
  423. $result = mysqli_query($connect, $sql);
  424. if(mysqli_num_rows($result) > 0)
  425. {
  426. $output .= '<p align="center">Search Result</p>';
  427. $output .= '<div class="table-responsive">
  428. <table class="table table bordered">
  429. <tr>
  430.  
  431. <th>Store IDs</th>
  432.  
  433. </tr>';
  434. while($row = mysqli_fetch_array($result))
  435. {
  436.  
  437.  
  438. $i++;
  439.  
  440. $raw = $row["Storeids"];
  441. // echo "StoreIDs from Styles" . $raw . "<br>";
  442.  
  443. $pieces = explode(",", $raw); // Take all the storeids which are sep by a comma and put into array
  444. $inString = implode("','", $pieces); // take each elemetn and wrap it with ','
  445. $inString = ereg_replace(" ","",$inString); // remove white spaces
  446. $sql = "SELECT * FROM stores WHERE storeid in ('".$inString."')"; // qeury to get all stores where store id in usign the IN from SQL
  447. echo $SQL . "<br>";
  448. $Stores = $connect->query($sql) or die ('noooo');
  449.  
  450. while($Store = $Stores->fetch_assoc()) {
  451.  
  452. echo "<div class='panel panel-default'> <div class='panel-heading'>
  453. <h5>
  454. <a data-toggle='collapse' data-parent='#accordion' href='#collapse$i' onclick='myClick($i);'>";
  455.  
  456. echo $Store["name"];
  457. echo " <i class='more-less glyphicon glyphicon-plus'></i> </a> </h5></div>";
  458.  
  459.  
  460. echo "<div id='collapse$i' class='panel-collapse collapse'>
  461. <div class='panel-body'>";
  462.  
  463. echo "Address: " .$Store['address']. "<br />Tel: " .$Store['telephone']. "<br />Email: " .$Store['Email']. "<br />Operating Hours: " .$Store['hours']. "";
  464.  
  465. echo "
  466.  
  467. </div>
  468. </div>
  469. </div>";
  470.  
  471.  
  472.  
  473.  
  474. $i++;
  475. }
  476. }
  477.  
  478. }
  479. else
  480. {
  481. ?>
  482.  
  483.  
  484.  
  485. <?php
  486.  
  487.  
  488.  
  489.  
  490. }
  491.  
  492. } ?>
  493.  
  494.  
  495. <div class="panel-group list" id="accordion">
  496.  
  497.  
  498. <?php
  499.  
  500.  
  501.  
  502.  
  503. $conn = mysql_connect($host , $username, $password);
  504.  
  505. if(! $conn ) {
  506. die('Could not connect: ' . mysql_error());
  507. }
  508.  
  509. $ty = $_POST['product_brand'];
  510.  
  511. $sql = "SELECT * FROM stores";
  512. mysql_select_db('GA_agl3t');
  513. $retval = mysql_query( $sql, $conn );
  514.  
  515. if(! $retval ) {
  516. die('Could not get data: ' . mysql_error());
  517. }
  518. $i = 0;
  519.  
  520.  
  521. while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
  522.  
  523. echo "<div class='panel panel-default'> <div class='panel-heading'>
  524. <h5>
  525. <a data-toggle='collapse' data-parent='#accordion' class='pan-link' href='#collapse$i' onclick='myClick($i);'>";
  526.  
  527. echo $row["name"];
  528. echo " <i class='more-less glyphicon glyphicon-plus'></i> </a> </h5></div>";
  529.  
  530.  
  531. echo "<div id='collapse$i' class='panel-collapse collapse'>
  532. <div class='panel-body'>";
  533. $what_type = $row['type'];
  534. if ($what_type == "Cutty") {
  535. $type = "<img src='/img/ga-creative-brands-cutty-tag.svg' />";
  536. }
  537. elseif ($what_type == "All") {
  538. $type = "<img src='/img/ga-creative-brands-jonathan-d-tag.svg' /> | <img src='/img/ga-creative-brands-cutty-tag.svg' />";
  539.  
  540. }
  541. else {
  542. $type = "<img src='/img/ga-creative-brands-jonathan-d-tag.svg' />";
  543.  
  544. }
  545.  
  546. 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>";
  547.  
  548. 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>";
  549.  
  550. echo "
  551.  
  552. </div>
  553. </div>
  554. </div>";
  555.  
  556.  
  557.  
  558.  
  559. $i++;
  560. }
  561.  
  562.  
  563.  
  564. mysql_close($conn);
  565.  
  566.  
  567. ?>
  568.  
  569.  
  570.  
  571.  
  572. </div>
  573. <div id='result'></div>
  574.  
  575.  
  576.  
  577.  
  578. </div>
  579. <div class="col-md-9">
  580. <div id="gmaps-canvas" style="width: 100%; height: 450px" ></div>
  581.  
  582.  
  583.  
  584. </div>
  585.  
  586.  
  587.  
  588. </div>
  589. </div>
  590. </div>
  591.  
  592. <br />
  593. <br />
  594. <nav class="nav visible-xs">
  595. <a href="#col1" class="active">STORE LIST</a>
  596. <a href="#col2">MAP</a>
  597.  
  598. </nav>
  599. <div class="content-wrapper visible-xs">
  600. <div class="content">
  601. <div id="col-md-3">
  602.  
  603.  
  604. <div id="result"></div>
  605. <div class="panel-group list" id="accordion">
  606.  
  607.  
  608. <?php
  609.  
  610.  
  611.  
  612.  
  613. $conn = mysql_connect($host , $username, $password);
  614.  
  615. if(! $conn ) {
  616. die('Could not connect: ' . mysql_error());
  617. }
  618.  
  619. $ty = $_POST['product_brand'];
  620.  
  621. $sql = "SELECT * FROM stores";
  622. mysql_select_db('GA_agl3t');
  623. $retval = mysql_query( $sql, $conn );
  624.  
  625. if(! $retval ) {
  626. die('Could not get data: ' . mysql_error());
  627. }
  628. $i = 0;
  629.  
  630.  
  631. while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
  632.  
  633. echo "<div class='panel-default'> <div class='panel-heading'>
  634. <h5>
  635. <a data-toggle='collapse' data-parent='#accordion' href='#collapse$i' onclick='myClick($i);'>";
  636.  
  637. echo $row["name"];
  638. echo " <i class='more-less glyphicon glyphicon-plus'></i> </a> </h5></div>";
  639.  
  640.  
  641. echo "<div id='collapse$i' class='panel-collapse collapse'>
  642. <div class='panel-body'>";
  643.  
  644. 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>";
  645.  
  646. echo "<a href='https://maps.google.com?saddr=&daddr=".$row['address']."' target='_blank'>DIRECTIONS</a>";
  647.  
  648. echo "
  649.  
  650. </div>
  651. </div>
  652. </div>";
  653.  
  654.  
  655.  
  656.  
  657. $i++;
  658. }
  659.  
  660.  
  661.  
  662. mysql_close($conn);
  663.  
  664.  
  665. ?>
  666.  
  667.  
  668.  
  669.  
  670. </div></div>
  671. <div id="col-md-9">
  672.  
  673.  
  674. <div style="width: 100%; height: 60%" id="gmaps-canvas"></div>
  675.  
  676. </div>
  677.  
  678. </div>
  679. </div>
  680.  
  681. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement