Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- require 'ConnectTest.php';
- // IF YOU'RE NOT LOGGED IN, KICK BACK TO LOGIN SCREEN
- if(!isset($_SESSION['username']) || !isset($_SESSION['password'])){
- header("Location:signin.php");
- }
- $servername = "localhost:3306";
- $user = "sonic_client";
- $pass = "client";
- $dbName = "sonicStrains";
- $drop = "DROP TABLE ".$_SESSION['username']."_deliveries";
- mysqli_query($server, $drop);
- //CREATE INDIVIDUAL DRIVER TABLE TO HOLD DELIVERIES
- $createQuery = "CREATE TABLE ".$_SESSION['username']."_deliveries (
- transaction_id VARCHAR(13),
- timePaid INT(11),
- username VARCHAR(30),
- user_location VARCHAR(255),
- user_lat float(10,6),
- user_long float(10,6),
- item_name VARCHAR(20),
- item_quantity float,
- driver_username VARCHAR(60),
- driver_lat float(10,6),
- driver_long float(10,6),
- on_delivery tinyint(1))";
- $created = mysqli_query($server, $createQuery);
- if ($created){
- //query the deliveries for open deliveries up untill 5 deliveries
- $queryString = "SELECT * FROM deliveries LIMIT 5";
- $query = mysqli_query($server, $queryString);
- if($query){
- // CREATE ARRAY TO HOLD QUERY ROWS
- $rows = array();
- while($queryresult = mysqli_fetch_assoc($query)){
- $rows[] = $queryresult;
- }
- echo floatval($rows[0]['user_lat']);
- echo"<br>";
- //INSERT & UPDATE THE TABLES WITH DELIVERY QUERIES
- foreach($rows as $row){
- // INSERT INTO INDIVIDUAL DRIVER TABLE
- $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]')";
- $insertExec = mysqli_query($server, $insertQuery);
- // UPDATE MASTER LIST OF DELIVERIES SO THAT OTHER DRIVERS DONT QUERY SAME ORDER
- $updateQuery = "UPDATE deliveries SET on_delivery=true, driver_username='$_SESSION[username]' WHERE transaction_id='$row[transaction_id]'";
- $updateExec = mysqli_query($server, $updateQuery);
- }
- }else{echo mysqli_error($server);}
- }else{echo mysqli_error($server);}
- if(isset($_GET['pop'])){
- array_shift($rows);
- echo print_r($rows);
- }
- echo<<<_
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
- <style>
- .TitleText{
- font-size:200%;
- }
- .Banner{ /*This is test code to hold the top ad*/
- width:100%;
- text-align:center;
- border-style:solid;
- border-color:grey;
- color:green;
- font-size:230%;
- font-weight:heavy;
- letter-spacing:1px;
- }
- .TopNav{
- margin-top:20px;
- }
- a:link{
- text-decoration:none;
- }
- .login{
- margin-top:15px;
- margin-right:15px;
- float:right;
- border-style:solid;
- border-color:grey;
- border-radius:10px;
- background-color:blue;
- color:white;
- font-size:30px;
- }
- .gallery{ /*This will hold the gallery Items*/
- text-align:center;
- display: inline-block;
- width: 100%;
- height: auto;
- margin-top: 16px;
- border-style: solid;
- border-color: green;
- }
- .map{
- width:100%;
- height:400px;
- border-style:solid;
- }
- .navButton{
- background-color:green;
- color:white;
- font-size:30px;
- margin-top: 16px;
- text-align:center;
- width:100%;
- display: inline-block;
- border-radius:10px;
- border-style:solid;
- border-color:red;
- }
- .orderButton{
- background-color:green;
- color:white;
- font-size:30px;
- margin-top: 16px;
- text-align:center;
- float:right;
- display: inline-block;
- border-style:solid;
- border-right:red;
- border-color:purple;
- border-radius:10px;
- width:100%;
- height:auto;
- }
- .abortButton{
- background-color:green;
- color:white;
- font-size:30px;
- margin-top: 16px;
- text-align:center;
- border-style:solid;
- border-color:yellow;
- border-radius:10px;
- width:100%;
- height:auto;
- display: inline-block;
- }
- .confirmButton{
- background-color:green;
- color:white;
- font-size:30px;
- margin-top: 16px;
- text-align:center;
- border-style:solid;
- border-color:pink;
- border-radius:10px;
- width:100%;
- height:auto;
- display: inline-block;
- }
- h1{
- font-weight:bold;
- }
- h3{
- font-weight:bold;
- color:green;
- }
- .disclaimer{
- width:100%;
- height:30px;
- border-style:solid;
- border-radius:10px;
- border-color:grey;
- text-align:center;
- }
- </style>
- </head>
- <body>
- <div class="Banner">
- <div class="TitleText">Sonic Strains ©</div>
- </div>
- <div class="login">Logout</div>
- <div class="gallery" id="container">
- <div class="map" id="mapInsert"></div>
- <div class="navButton">Start Nav</div><div class="orderButton">Order Details</div>
- <div class="abortButton">Abort</div><div class="confirmButton" onclick="shiftOrder()">Confirm</div><div class="disclaimer"></div>
- </div>
- <script>
- function initMap() {
- navigator.geolocation.getCurrentPosition(function(position) {
- var initialLocation = {lat:$rows[0]['user_lat'], lng:$rows[0]['user_long']};
- var Map = new google.maps.Map(document.getElementById('mapInsert'));
- Map.setCenter(initialLocation);
- Map.setZoom(13);
- // MAKE ANOTHER MARKER FOR THE CLIENT LOCATION
- var userLocation = {lat:$rows[0]['user_lat'], lng:$rows[0]['user_long']};
- var marker = new google.maps.Marker({
- position:userLocation,
- map:Map,
- draggable:false,
- clickable:false
- });
- marker.setMap(Map);
- }, function(positionError) {
- alert('Location could not be found');
- },{enableHighAccuracy:true, timeout: 3000, maximumAge:1000});
- }
- function shiftOrder(){
- var http = new XMLHttpRequest();
- http.onreadystatechange = function(){
- console.log(this.responseText);
- }
- http.open("GET", "driverIndex.php?pop='pop'", true);
- http.send();
- }
- </script>
- <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=[API_KEY]&callback=initMap"
- async defer></script>
- </body>
- </html>
- _;
- ?>
- 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" }
- var initialLocation = {lat:floatval($rows[0]['user_lat']), lng:floatval($rows[0]['user_long'])};
Add Comment
Please, Sign In to add comment