Guest User

Untitled

a guest
Jan 4th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.47 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11. require 'ConnectTest.php';
  12.  
  13. // IF YOU'RE NOT LOGGED IN, KICK BACK TO LOGIN SCREEN
  14. if(!isset($_SESSION['username']) || !isset($_SESSION['password'])){
  15.  
  16. header("Location:signin.php");
  17. }
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. $servername = "localhost:3306";
  28. $user = "sonic_client";
  29. $pass = "client";
  30. $dbName = "sonicStrains";
  31.  
  32. $drop = "DROP TABLE ".$_SESSION['username']."_deliveries";
  33. mysqli_query($server, $drop);
  34.  
  35. //CREATE INDIVIDUAL DRIVER TABLE TO HOLD DELIVERIES
  36. $createQuery = "CREATE TABLE ".$_SESSION['username']."_deliveries (
  37. transaction_id VARCHAR(13),
  38. timePaid INT(11),
  39. username VARCHAR(30),
  40. user_location VARCHAR(255),
  41. user_lat float(10,6),
  42. user_long float(10,6),
  43. item_name VARCHAR(20),
  44. item_quantity float,
  45. driver_username VARCHAR(60),
  46. driver_lat float(10,6),
  47. driver_long float(10,6),
  48. on_delivery tinyint(1))";
  49.  
  50. $created = mysqli_query($server, $createQuery);
  51.  
  52. if ($created){
  53.  
  54. //query the deliveries for open deliveries up untill 5 deliveries
  55. $queryString = "SELECT * FROM deliveries LIMIT 5";
  56.  
  57. $query = mysqli_query($server, $queryString);
  58.  
  59. if($query){
  60.  
  61.  
  62. // CREATE ARRAY TO HOLD QUERY ROWS
  63. $rows = array();
  64.  
  65. while($queryresult = mysqli_fetch_assoc($query)){
  66.  
  67. $rows[] = $queryresult;
  68.  
  69.  
  70. }
  71.  
  72.  
  73.  
  74. echo floatval($rows[0]['user_lat']);
  75. echo"<br>";
  76.  
  77. //INSERT & UPDATE THE TABLES WITH DELIVERY QUERIES
  78. foreach($rows as $row){
  79.  
  80.  
  81.  
  82. // INSERT INTO INDIVIDUAL DRIVER TABLE
  83. $insertQuery = "INSERT INTO ".$_SESSION['username']."_deliveries (transaction_id, user_location, user_lat, user_long) VALUES('$row[transaction_id]', '$row[user_location]', '$row[user_lat]', '$row[user_long]')";
  84. $insertExec = mysqli_query($server, $insertQuery);
  85.  
  86.  
  87.  
  88. // UPDATE MASTER LIST OF DELIVERIES SO THAT OTHER DRIVERS DONT QUERY SAME ORDER
  89. $updateQuery = "UPDATE deliveries SET on_delivery=true, driver_username='$_SESSION[username]' WHERE transaction_id='$row[transaction_id]'";
  90. $updateExec = mysqli_query($server, $updateQuery);
  91.  
  92.  
  93.  
  94. }
  95.  
  96. }else{echo mysqli_error($server);}
  97.  
  98.  
  99.  
  100.  
  101. }else{echo mysqli_error($server);}
  102.  
  103.  
  104. if(isset($_GET['pop'])){
  105.  
  106.  
  107. array_shift($rows);
  108. echo print_r($rows);
  109. }
  110.  
  111. echo<<<_
  112.  
  113. <!DOCTYPE html>
  114. <html>
  115.  
  116. <head>
  117.  
  118. <meta name="viewport" content="width=device-width, initial-scale=1">
  119. <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
  120.  
  121.  
  122. <style>
  123.  
  124. .TitleText{
  125. font-size:200%;
  126. }
  127.  
  128.  
  129. .Banner{ /*This is test code to hold the top ad*/
  130. width:100%;
  131. text-align:center;
  132. border-style:solid;
  133. border-color:grey;
  134. color:green;
  135. font-size:230%;
  136. font-weight:heavy;
  137. letter-spacing:1px;
  138. }
  139.  
  140.  
  141. .TopNav{
  142.  
  143. margin-top:20px;
  144. }
  145.  
  146.  
  147. a:link{
  148. text-decoration:none;
  149. }
  150.  
  151. .login{
  152. margin-top:15px;
  153. margin-right:15px;
  154. float:right;
  155. border-style:solid;
  156. border-color:grey;
  157. border-radius:10px;
  158. background-color:blue;
  159. color:white;
  160. font-size:30px;
  161.  
  162. }
  163.  
  164.  
  165. .gallery{ /*This will hold the gallery Items*/
  166. text-align:center;
  167. display: inline-block;
  168. width: 100%;
  169. height: auto;
  170. margin-top: 16px;
  171. border-style: solid;
  172. border-color: green;
  173. }
  174.  
  175.  
  176.  
  177.  
  178.  
  179. .map{
  180. width:100%;
  181. height:400px;
  182. border-style:solid;
  183. }
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190. .navButton{
  191. background-color:green;
  192. color:white;
  193. font-size:30px;
  194. margin-top: 16px;
  195. text-align:center;
  196. width:100%;
  197. display: inline-block;
  198. border-radius:10px;
  199. border-style:solid;
  200. border-color:red;
  201.  
  202.  
  203. }
  204.  
  205.  
  206. .orderButton{
  207. background-color:green;
  208. color:white;
  209. font-size:30px;
  210. margin-top: 16px;
  211. text-align:center;
  212. float:right;
  213. display: inline-block;
  214. border-style:solid;
  215. border-right:red;
  216. border-color:purple;
  217. border-radius:10px;
  218. width:100%;
  219. height:auto;
  220.  
  221. }
  222.  
  223. .abortButton{
  224. background-color:green;
  225. color:white;
  226. font-size:30px;
  227. margin-top: 16px;
  228. text-align:center;
  229. border-style:solid;
  230. border-color:yellow;
  231. border-radius:10px;
  232. width:100%;
  233. height:auto;
  234. display: inline-block;
  235. }
  236.  
  237. .confirmButton{
  238. background-color:green;
  239. color:white;
  240. font-size:30px;
  241. margin-top: 16px;
  242. text-align:center;
  243. border-style:solid;
  244. border-color:pink;
  245. border-radius:10px;
  246. width:100%;
  247. height:auto;
  248. display: inline-block;
  249. }
  250.  
  251.  
  252. h1{
  253. font-weight:bold;
  254. }
  255.  
  256.  
  257. h3{
  258. font-weight:bold;
  259. color:green;
  260. }
  261.  
  262.  
  263.  
  264. .disclaimer{
  265. width:100%;
  266. height:30px;
  267.  
  268. border-style:solid;
  269. border-radius:10px;
  270. border-color:grey;
  271. text-align:center;
  272. }
  273.  
  274.  
  275. </style>
  276.  
  277.  
  278.  
  279.  
  280. </head>
  281.  
  282.  
  283.  
  284. <body>
  285.  
  286. <div class="Banner">
  287. <div class="TitleText">Sonic Strains &copy;</div>
  288. </div>
  289.  
  290.  
  291. <div class="login">Logout</div>
  292. <div class="gallery" id="container">
  293. <div class="map" id="mapInsert"></div>
  294. <div class="navButton">Start Nav</div><div class="orderButton">Order Details</div>
  295. <div class="abortButton">Abort</div><div class="confirmButton" onclick="shiftOrder()">Confirm</div><div class="disclaimer"></div>
  296. </div>
  297.  
  298.  
  299. <script>
  300.  
  301.  
  302.  
  303.  
  304. function initMap() {
  305.  
  306. navigator.geolocation.getCurrentPosition(function(position) {
  307.  
  308.  
  309.  
  310.  
  311. var initialLocation = {lat:$rows[0]['user_lat'], lng:$rows[0]['user_long']};
  312. var Map = new google.maps.Map(document.getElementById('mapInsert'));
  313. Map.setCenter(initialLocation);
  314. Map.setZoom(13);
  315. // MAKE ANOTHER MARKER FOR THE CLIENT LOCATION
  316. var userLocation = {lat:$rows[0]['user_lat'], lng:$rows[0]['user_long']};
  317. var marker = new google.maps.Marker({
  318. position:userLocation,
  319. map:Map,
  320. draggable:false,
  321. clickable:false
  322. });
  323. marker.setMap(Map);
  324.  
  325.  
  326.  
  327. }, function(positionError) {
  328.  
  329. alert('Location could not be found');
  330. },{enableHighAccuracy:true, timeout: 3000, maximumAge:1000});
  331.  
  332. }
  333.  
  334. function shiftOrder(){
  335.  
  336. var http = new XMLHttpRequest();
  337. http.onreadystatechange = function(){
  338. console.log(this.responseText);
  339.  
  340. }
  341. http.open("GET", "driverIndex.php?pop='pop'", true);
  342. http.send();
  343.  
  344. }
  345.  
  346.  
  347. </script>
  348. <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=[API_KEY]&callback=initMap"
  349. async defer></script>
  350.  
  351.  
  352.  
  353.  
  354. </body>
  355. </html>
  356.  
  357. _;
  358.  
  359. ?>
  360.  
  361. array(5) { [0]=> array(12) { ["transaction_id"]=> string(13) "5c2fb27078926" ["timePaid"]=> string(1) "0" ["username"]=> string(0) "" ["user_location"]=> string(44) "1301 Bataan St NW, Washington, DC 20036, USA" ["user_lat"]=> string(9) "38.907246" ["user_long"]=> string(10) "-77.037292" ["item_name"]=> string(18) "girl_scout_cookies" ["item_quantity"]=> string(1) "1" ["driver_username"]=> string(7) "Driver1" ["driver_lat"]=> string(8) "0.000000" ["driver_long"]=> string(8) "0.000000" ["on_delivery"]=> string(1) "1" }
  362.  
  363. var initialLocation = {lat:floatval($rows[0]['user_lat']), lng:floatval($rows[0]['user_long'])};
Add Comment
Please, Sign In to add comment