diff --git a/controller/orderController.php b/controller/orderController.php index b7d9b683e6c61dacf9e1099cda9e331b13bf1a8d..c3bbcde83caea3b5541e8de9d9be3ff240b5bc48 100644 --- a/controller/orderController.php +++ b/controller/orderController.php @@ -13,8 +13,14 @@ if(isset($_GET['drivername']) && isset($_GET['id'])){ //Process to find the driver while($row = mysqli_fetch_array($result)){ if($row['name'] == $driverName){ - $txt = $txt . '<div class="single-driver"><img src="../img/'. $row['image'] .'" /><div class="driver-bio"> - <h2 class="driver-name">'. $row['name'].'</h2><div class="driver-rating"></div></div> + //get drier rating + $driverStats = mysqli_fetch_array($user->getDriverRating($row['id'])); + $driverRating = $driverStats['driverRating']; + $driverVotes = $driverStats['votes']; + + $txt = $txt . '<div class="single-driver"><img class="order-driver-image" src="../img/'. $row['image'] .'" /><div class="driver-bio"> + <h2 class="driver-name">'. $row['name'].'</h2><div class="driver-rating"><img class="rating-image" src="../img/rating.png" />'. + round($driverRating) . ' ('. $driverVotes .' votes)</div></div> <div class="button-choose"><div onclick="chooseDriver('. $row['id'] .')">I CHOOSE YOU!</div></div></div>'; } } @@ -28,8 +34,14 @@ if(isset($_GET['drivername']) && isset($_GET['id'])){ $result = $user->getDriverNotId($userId); while($row = mysqli_fetch_array($result)){ if($row['name'] !== $driverName){ - $txt = $txt . '<div class="single-driver"><img src="../img/'. $row['image'] .'" /><div class="driver-bio"> - <h2 class="driver-name">'. $row['name'].'</h2><div class="driver-rating"></div></div> + //get drier rating + $driverStats = mysqli_fetch_array($user->getDriverRating($row['id'])); + $driverRating = $driverStats['driverRating']; + $driverVotes = $driverStats['votes']; + + $txt = $txt . '<div class="single-driver"><img class="order-driver-image" src="../img/'. $row['image'] .'" /><div class="driver-bio"> + <h2 class="driver-name">'. $row['name'].'</h2><div class="driver-rating"><img class="rating-image" src="../img/rating.png" />'. + round($driverRating) . ' ('. $driverVotes .' votes)</div></div> <div class="button-choose"><div onclick="chooseDriver('. $row['id'] .')">I CHOOSE YOU!</div></div></div>'; } } diff --git a/controller/transactionController.php b/controller/transactionController.php index 908b8f715c4dc50f60909b9725d83fe72b1c2d7c..c4ca4f661a9ec2771062b1d515a9c28fc69f4e10 100644 --- a/controller/transactionController.php +++ b/controller/transactionController.php @@ -4,19 +4,16 @@ include "../model/order.php"; include "../model/user.php"; -//TODO: tambahin redirect klo get kosong - -$id = $_GET['id']; -$isDriver = $_GET['driver']; - $order = new Order(); $result = $order->getAllTransaction(); -if($isDriver) { +if(isset($_GET['id']) && isset($_GET['driver']) && $_GET['driver']) { + $id = $_GET['id']; + $isDriver = $_GET['driver']; $asDriverCompletedTransaction = ""; $i = 0; while ($row = mysqli_fetch_array($result)) { - if ($row['driver_id'] == $id) { + if ($row['driver_id'] == $id && $row['is_visible']) { /*Get user image and name */ $userObject = new User(); $user = $userObject->getUserById($row['user_id']); @@ -24,27 +21,30 @@ if($isDriver) { $username = $fetched['name']; $image = $fetched['image']; + + /* making a single transaction view */ $asDriverCompletedTransaction = $asDriverCompletedTransaction . "<div class='single-transaction'> <img class='user-image' src='../img/" . $image . "'/> - <div class='transaction-info'><div class='transaction-date'>" . $row['date'] . " </div> + <div class='transaction-info'><div class='transaction-date'>" . date('l, F jS Y',strtotime($row['date'])) . " </div> <div class='user-name'>" . $username . "</div> <div class='transaction-city'>" . $row['pickup'] . " to " . $row['destination'] . "</div> <div class='transaction-rating'>gave " . $row['rating'] . " star(s) for this order</div> <div class='transaction-comment'>and left comment:<blockquote>\"" . $row['comment'] . "\"</blockquote></div></div> - <div class='hide-button'><div id='transaction-" . $i . "' onclick='hide(" . $i . ")'>HIDE</div></div> + <div class='hide-button'><div id='transaction-" . $row['transaction_id'] . "' onclick='hide(" . $row['transaction_id'] . ")'>HIDE</div></div> </div>"; $i++; } } - header('Content-Type: text/xml'); + header('Content-Type: text/html'); echo $asDriverCompletedTransaction; } else { + $id = $_GET['id']; $asUserCompletedTransaction = ""; $i = 0; while ($row = mysqli_fetch_array($result)) { - if ($row['user_id'] == $id) { + if ($row['user_id'] == $id && $row['is_visible']) { /*Get driver image and name */ $userObject = new User(); $user = $userObject->getUserById($row['driver_id']); @@ -56,21 +56,24 @@ if($isDriver) { $asUserCompletedTransaction = $asUserCompletedTransaction . "<div class='single-transaction'> <img class='user-image' src='../img/" . $image . "'/> - <div class='transaction-info'><div class='transaction-date'>" . $row['date'] . " </div> + <div class='transaction-info'><div class='transaction-date'>" . date('l, F jS Y',strtotime($row['date'])) . " </div> <div class='user-name'>" . $fetched['name'] . "</div> <div class='transaction-city'>" . $row['pickup'] . " to " . $row['destination'] . "</div> <div class='transaction-rating'>you rated: " . $row['rating'] . "</div> <div class='transaction-comment'>and left comment:<blockquote>\"" . $row['comment'] . "\"</blockquote></div></div> - <div class='hide-button'><div id='transaction-" . $i . "' onclick='hide(" . $i . ")'>HIDE</div></div> + <div class='hide-button'><div id='transaction-" . $row['transaction_id'] . "' onclick='hide(" . $row['transaction_id'] . ")'>HIDE</div></div> </div>"; $i++; } } - header('Content-Type: text/xml'); + header('Content-Type: text/html'); echo $asUserCompletedTransaction; } - +if(isset($_GET['hide']) && isset($_GET['id'])){ + $id = $_GET['id']; + $result = $order->hideTransaction($id); +} diff --git a/css/dashboard.css b/css/dashboard.css index f3c1d856b983f5151a20503507ac967b224bdcdc..77c198d2484c92eff87835c247369321d28fda43 100644 --- a/css/dashboard.css +++ b/css/dashboard.css @@ -119,7 +119,9 @@ font-size: 1.3rem; margin-bottom: 5px; } - +#driver img { + width: 20px; +} #email, #phone { display: inline-block; } diff --git a/css/history.css b/css/history.css index c4b317978896d20e7806b9e257803f5654ad8af2..e9744bcf07bf78951dd212b48e270a1e0ad3cdb6 100644 --- a/css/history.css +++ b/css/history.css @@ -23,7 +23,8 @@ box-sizing: border-box; } .transaction-date { - font-size: 1.5rem; + font-size: 1.4rem; + font-family: Serif; color: #999; } .user-name { diff --git a/css/order.css b/css/order.css index 4cc6eaa4e11489436fb4b2f5626928d0f2e606bd..ceaf0d78bb871e7ca12c9405f97c77effbf24fb1 100644 --- a/css/order.css +++ b/css/order.css @@ -79,11 +79,16 @@ margin: 20px 0; box-sizing: border-box; } -.single-driver img { +.order-driver-image { display: inline-block; width: 20%; vertical-align: top; } +.rating-image { + display: inline-block; + width: 15px; + margin-right: 5px; +} .driver-bio { display: inline-block; width: 49%; diff --git a/data/projekers.sql b/data/projekers.sql index a8763bbb4708ef5304cf82d5ec09c344502b2286..5704484a64194b00c5576c04c7251195f98f9377 100644 --- a/data/projekers.sql +++ b/data/projekers.sql @@ -1,8 +1,8 @@ --- MySQL dump 10.16 Distrib 10.1.26-MariaDB, for Win32 (AMD64) +-- MySQL dump 10.16 Distrib 10.1.25-MariaDB, for Win32 (AMD64) -- -- Host: localhost Database: projekers -- ------------------------------------------------------ --- Server version 10.1.26-MariaDB +-- Server version 10.1.25-MariaDB /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -36,7 +36,7 @@ CREATE TABLE `pref_loc` ( LOCK TABLES `pref_loc` WRITE; /*!40000 ALTER TABLE `pref_loc` DISABLE KEYS */; -INSERT INTO `pref_loc` VALUES (1,'Tubagus Ismail'),(1,'Dago Asri'),(1,'Kopo'); +INSERT INTO `pref_loc` VALUES (1,'Tubagus Ismail'),(1,'Dago Asri'),(1,'Kopo'),(2,'Ciwalk'),(2,'PVJ'),(2,'BEC'),(3,'BEC'),(3,'Tubagus Ismail'),(3,'ITB'); /*!40000 ALTER TABLE `pref_loc` ENABLE KEYS */; UNLOCK TABLES; @@ -56,12 +56,13 @@ CREATE TABLE `transaction` ( `rating` int(1) NOT NULL, `comment` text NOT NULL, `date` date NOT NULL, + `is_visible` tinyint(1) NOT NULL, PRIMARY KEY (`transaction_id`) USING BTREE, KEY `user_id` (`user_id`), KEY `driver_id` (`driver_id`), CONSTRAINT `transaction_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`), CONSTRAINT `transaction_ibfk_2` FOREIGN KEY (`driver_id`) REFERENCES `user` (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -70,7 +71,7 @@ CREATE TABLE `transaction` ( LOCK TABLES `transaction` WRITE; /*!40000 ALTER TABLE `transaction` DISABLE KEYS */; -INSERT INTO `transaction` VALUES (1,1,2,'Tubagus Ismail','Cisitu',5,'Oke banget','2017-09-01'),(2,4,3,'Dago Asri','Kampus ITB',2,'Lambat banget nih','2017-10-01'),(3,1,3,'Cisitu','Plesiran',2,'Drivernya lambat pisan','2017-09-30'),(4,4,1,'Kopo','Ciwalk',5,'Perjalanan jauh tapi menyenangkan','2017-10-01'); +INSERT INTO `transaction` VALUES (1,1,2,'Tubagus Ismail','Cisitu',5,'Oke banget','2017-09-01',1),(2,4,3,'Dago Asri','Kampus ITB',2,'Lambat banget nih','2017-10-01',1),(3,1,3,'Cisitu','Plesiran',2,'Drivernya lambat pisan','2017-09-30',1),(4,4,1,'Kopo','Ciwalk',5,'Perjalanan jauh tapi menyenangkan','2017-10-01',1); /*!40000 ALTER TABLE `transaction` ENABLE KEYS */; UNLOCK TABLES; @@ -113,4 +114,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2017-10-01 22:25:06 +-- Dump completed on 2017-10-06 10:49:10 diff --git a/img/rating.png b/img/rating.png new file mode 100644 index 0000000000000000000000000000000000000000..29a39d80f932e061994cdcaa0cfd0fb6cb2df4b8 Binary files /dev/null and b/img/rating.png differ diff --git a/js/history.js b/js/history.js index a53708ee8967981e21c9f750fd69cb7dc411e034..b3fbf426088901694677b68ccd0637cca6355ea5 100644 --- a/js/history.js +++ b/js/history.js @@ -12,6 +12,13 @@ function getAllTransaction(isDriver){ } function hide(id){ - var elementId = 'transaction-' + id; - document.getElementById(elementId).parentNode.parentNode.style.display = "none"; + xmlhttp = new XMLHttpRequest(); + xmlhttp.onreadystatechange = function () { + if(xmlhttp.readyState == 4 && xmlhttp.status == 200){ + var elementId = 'transaction-' + id; + document.getElementById(elementId).parentNode.parentNode.style.display = "none"; + } + }; + xmlhttp.open('GET', '../controller/transactionController.php?id=' + id + '&hide=1',true); + xmlhttp.send(); } \ No newline at end of file diff --git a/js/profile.js b/js/profile.js index d676fbd6dbe57dc5b1e855c247fa16353bc51659..91dffb11ad5b3b6a14a2bf48d6f072f3db42ae9d 100644 --- a/js/profile.js +++ b/js/profile.js @@ -17,7 +17,7 @@ function getUserProfile(){ if(isDriver == 1){ rating = result.getElementsByTagName('rating')[0].childNodes[0].nodeValue; votes = result.getElementsByTagName('votes')[0].childNodes[0].nodeValue; - document.getElementById('driver').innerHTML = 'Driver | ' + Math.round(rating) + ' ('+ votes +' votes)'; + document.getElementById('driver').innerHTML = 'Driver |<img src="../img/rating.png" />' + Math.round(rating) + ' ('+ votes +' votes)'; } else { document.getElementById('driver').innerHTML = 'Non-driver'; } @@ -42,6 +42,11 @@ function getUserProfile(){ singleList.innerHTML = loc; listOfLocation.appendChild(singleList); } + //display preferred location if driver + if(isDriver == 0){ + document.getElementById('preferred-location').style.display = 'none'; + document.getElementById('user-location').style.display = 'none'; + } } }; xmlhttp.open('GET', '../controller/profile.php?id=' + id, true); diff --git a/model/order.php b/model/order.php index a2d2e1b7bcc2ce1f103cfb8028823d74a60031d3..e79e49fbbbb6619af31e59c9e921aac3ea570476 100644 --- a/model/order.php +++ b/model/order.php @@ -12,8 +12,15 @@ class Order { function setTransaction($userId, $driverId, $pickup, $destination, $transactionDate, $rating, $comment){ $con = mysqli_connect('localhost','root', '', 'projekers'); mysqli_select_db($con, 'projekers'); - $sql = 'INSERT INTO transaction(user_id, driver_id, pickup, destination, rating, comment, date) values('. - $userId.','.$driverId.',"'.$pickup.'","'.$destination.'",'.$rating.',"'.$comment.'","'.$transactionDate.'")'; + $sql = 'INSERT INTO transaction(user_id, driver_id, pickup, destination, rating, comment, date, is_visible) values('. + $userId.','.$driverId.',"'.$pickup.'","'.$destination.'",'.$rating.',"'.$comment.'","'.$transactionDate.',",1)'; + mysqli_query($con, $sql); + mysqli_close($con); + } + function hideTransaction($id){ + $con = mysqli_connect('localhost','root','','projekers'); + mysqli_select_db($con,'projekers'); + $sql = "update transaction set is_visible=0 where transaction_id=" . $id; mysqli_query($con, $sql); mysqli_close($con); } diff --git a/view/dashboard.php b/view/dashboard.php index 98c44fe2de75215571de6c94eacd9259b5d9f6b8..f6c82e3fc80f9c3423315ab2b02e4fa3a34dd965 100644 --- a/view/dashboard.php +++ b/view/dashboard.php @@ -62,10 +62,10 @@ <img src="../img/mail.png" /><div id="email"></div><br /> <img src="../img/phone.png" /><div id="phone"></div><br /> </div> - <div class="sub-header"> + <div class="sub-header" id="preferred-location"> <div class="sub-header-heading"><h1>PREFERRED LOCATION</h1></div> <div class="edit-icon"> - <a href="../view/edit-prefered-locations.html"><img src="../img/pencil.png" /></a> + <a href="../view/edit-prefered-locations.php"><img src="../img/pencil.png" /></a> </div> </div> <div class="user-location"><ul id="user-location"></ul></div>