diff --git a/controller/orderController.php b/controller/orderController.php index c3bbcde83caea3b5541e8de9d9be3ff240b5bc48..77e0c4bf236177ddb6a3d91291e27e6389177cdc 100644 --- a/controller/orderController.php +++ b/controller/orderController.php @@ -3,11 +3,17 @@ include "../model/user.php"; include "../model/order.php"; -if(isset($_GET['drivername']) && isset($_GET['id'])){ +if(isset($_GET['drivername']) && isset($_GET['id']) && isset($_GET['pickup']) && isset($_GET['destination'])){ $userId = $_GET['id']; $driverName = $_GET['drivername']; + $pickup = $_GET['pickup']; + $destination = $_GET['destination']; + + $user = new User(); - $result = $user->getDriverNotId($userId); + $result = $user->getDriverNotId($userId, $pickup, $destination); + + header('Content-Type: text/html'); $txt = '<div class="driver-box"><h1>PREFERRED DRIVERS</h1>'; //Process to find the driver @@ -31,7 +37,7 @@ if(isset($_GET['drivername']) && isset($_GET['id'])){ $txt = $txt . '</div>'; $txt = $txt . '<div class="driver-box"><h1>OTHER DRIVERS</h1>'; //Process other drivers - $result = $user->getDriverNotId($userId); + $result = $user->getDriverNotId($userId, $pickup, $destination); while($row = mysqli_fetch_array($result)){ if($row['name'] !== $driverName){ //get drier rating diff --git a/js/order.js b/js/order.js index 15f67bd84d01d6c5db95b58f08420dd03a857533..78b5556398ac682587c36a36ac271ea874dabd39 100644 --- a/js/order.js +++ b/js/order.js @@ -23,12 +23,14 @@ function getDriver() { var xmlhttp = new XMLHttpRequest(); //Check if user inserted preferred driver's name var drivername = (document.getElementById('preferred-driver').value) ? document.getElementById('preferred-driver').value : null; + var pickup = document.getElementById('pickup').value; + var destination = document.getElementById('destination').value; xmlhttp.onreadystatechange = function () { if(xmlhttp.readyState == 4 && xmlhttp.status == 200){ document.getElementsByClassName('second-page')[0].innerHTML = this.responseText; } }; - xmlhttp.open('GET','../controller/orderController.php?drivername='+drivername+'&id='+sessionid,true); + xmlhttp.open('GET','../controller/orderController.php?drivername='+drivername+'&id='+sessionid+'&pickup='+pickup+'&destination='+destination,true); xmlhttp.send(); } function chooseDriver(id){ diff --git a/model/user.php b/model/user.php index fb5e18c4b3f0329b3252605b023de1d17cb7a0dc..346ee59d7d3b765e01e502ce107f736875f272d1 100644 --- a/model/user.php +++ b/model/user.php @@ -75,10 +75,13 @@ class User { mysqli_close($con); return $result; } - function getDriverNotId($id){ + function getDriverNotId($id, $pickup, $destination){ + //Driver is limited to the pickup and destination $con = mysqli_connect('localhost','root','','projekers'); mysqli_select_db($con,'projekers'); - $query = "SELECT id,name,image FROM user WHERE isDriver=1 AND not id=" . $id; + //select * from user natural join pref_loc where (location like 'bec%' or location like '%kopo%') and isDriver=1 and not id=1 + $query = "SELECT DISTINCT id,name,image FROM user NATURAL JOIN pref_loc WHERE (location LIKE '%". + $pickup."%' OR location LIKE '%".$destination."%') AND isDriver=1 AND not id=" . $id; $result = mysqli_query($con,$query); mysqli_close($con); return $result; @@ -107,4 +110,6 @@ class User { mysqli_close($con); return $result; } + //function getD + // select * from user natural join pref_loc where (location like 'bec%' or location like '%kopo%') and isDriver=1 and not id=1 } \ No newline at end of file diff --git a/view/order.php b/view/order.php index 6507b6d63a9d2691f578bb2726954242476c6ec1..8d0a6cd274d6ec3e9de418d9d9a1207b37019151 100644 --- a/view/order.php +++ b/view/order.php @@ -10,10 +10,10 @@ <form action="../controller/orderController.php" method="post"> <div class="first-page"> <div class="input-box"> - <label>Picking Point</label><input type="text" name="pickup" placeholder="Pickup Point"/> + <label>Picking Point</label><input type="text" name="pickup" id="pickup" placeholder="Pickup Point"/> </div> <div class="input-box"> - <label>Destination</label><input type="text" name="destination" placeholder="Destination Point"/> + <label>Destination</label><input type="text" name="destination" id="destination" placeholder="Destination Point"/> </div> <div class="input-box"> <label>Preferred Driver</label><input type="text" name="preferred-driver" id="preferred-driver" placeholder="(optional)" value=""/>