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/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/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/model/order.php b/model/order.php index a2d2e1b7bcc2ce1f103cfb8028823d74a60031d3..6cdea4e8812c8b7867ea39cb1db9c854ddc997d0 100644 --- a/model/order.php +++ b/model/order.php @@ -17,4 +17,11 @@ class Order { 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); + } } \ No newline at end of file