diff --git a/controller/transactionController.php b/controller/transactionController.php index b85084568a711e3fc92295b10405e0f6eafaf731..42434ad27c0cacebc34cb706239c5ff44e57cebc 100644 --- a/controller/transactionController.php +++ b/controller/transactionController.php @@ -2,20 +2,73 @@ /* Model */ include "../model/order.php"; +include "../model/user.php"; //TODO: tambahin redirect klo get kosong -$user = new Order(); -$result = $user->getAllTransaction(); -header('Content-Type: text/xml'); -$xml = '<transaction>'; -while($row = mysqli_fetch_array($result)){ - $xml = $xml . '<transactionid>' . $row['transaction_id'] . '</transactionid><driverid>' . $row['driver_id'] - . '</driverid><userid>' . $row['user_id']. '</userid><pickup>' . $row['pickup'] . '</pickup><destination>'. - $row['destination'] .'</destination><rating>' . $row['rating'] . '</rating><comment>'. $row['comment']. - '</comment><date>'. $row['date'] .'</date>'; +$id = $_GET['id']; +$isDriver = $_GET['driver']; + +$order = new Order(); +$result = $order->getAllTransaction(); + +if($isDriver) { + $asDriverCompletedTransaction = ""; + $i = 0; + while ($row = mysqli_fetch_array($result)) { + if ($row['driver_id'] == $id) { + /*Get user image and name */ + $userObject = new User(); + $user = $userObject->getUserById($row['user_id']); + $fetched = mysqli_fetch_array($user); + $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='user-name'>" . $username . "</div> + <div class='transaction-city'>" . $row['pickup'] . "=>" . $row['destination'] . "</div> + <div class='transaction-rating'>gave " . $row['rating'] . " star(s) for this order</div> + <div class='transaction-comment'>and left comment <br />" . $row['comment'] . " </div></div> + <div class='hide-button'><button id='transaction-" . $i . "' onclick='hide(" . $i . ")'>HIDE</button></div> + </div>"; + $i++; + } + } + echo $asDriverCompletedTransaction; +} else { + $asUserCompletedTransaction = ""; + $i = 0; + while ($row = mysqli_fetch_array($result)) { + if ($row['user_id'] == $id) { + /*Get driver image and name */ + $userObject = new User(); + $user = $userObject->getUserById($row['driver_id']); + $fetched = mysqli_fetch_array($user); + $username = $fetched['name']; + $image = $fetched['image']; + + /* making a single transaction view */ + $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='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: <br />" . $row['comment'] . " </div></div> + <div class='hide-button'><button id='transaction-" . $i . "' onclick='hide(" . $i . ")'>HIDE</button></div> + </div>"; + $i++; + } + } + echo $asUserCompletedTransaction; } -$xml = $xml . '</transaction>'; -echo $xml; + + + diff --git a/css/history.css b/css/history.css index 6d5cc40385c09dcac8aeff1d05c55f355f607b98..829d1571237d0815620362ec158f553df9f6df10 100644 --- a/css/history.css +++ b/css/history.css @@ -1,3 +1,49 @@ .driver-info { width: 100%; +} +.single-transaction { + width: 700px; + font-size: 0; + margin: 20px 0; +} +.user-image { + width: 20%; + height: 150px; + display: inline-block; + vertical-align: top; + border: 2px solid #000; + box-sizing: border-box; +} +.transaction-info { + width: 60%; + display: inline-block; + font-size: initial; + vertical-align: top; + padding: 0 15px; + box-sizing: border-box; +} +.transaction-date { + font-size: 1.5rem; + color: #999; +} +.user-name { + font-size: 2rem; + font-weight: bold; +} +.transaction-city, .transaction-rating, .transaction-comment { + font-size: 1.2rem; + margin: 5px 0; +} +.hide-button { + width: 20%; + text-align: right; + display: inline-block; + font-size: initial; +} +.hide-button button { + padding: 8px; + font-size: 1.5rem; + background: red; + border: 1px solid #000; + border-radius: 10px; } \ No newline at end of file diff --git a/img/background.jpeg b/img/background.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..630db52c511eb89fd0c42a93c82c4e461b2dc07a Binary files /dev/null and b/img/background.jpeg differ diff --git a/img/bulbasaur.png b/img/bulbasaur.png new file mode 100644 index 0000000000000000000000000000000000000000..d5f85b39b00f142443b41281489792f0a262ebbc Binary files /dev/null and b/img/bulbasaur.png differ diff --git a/img/charmander.png b/img/charmander.png new file mode 100644 index 0000000000000000000000000000000000000000..bae51f6e46c02e61d60c2d73627ff92306f22a08 Binary files /dev/null and b/img/charmander.png differ diff --git a/img/ratata.png b/img/ratata.png new file mode 100644 index 0000000000000000000000000000000000000000..dd870cd758c47119e484a162baec1c28fba6c74a Binary files /dev/null and b/img/ratata.png differ diff --git a/js/dashboard.js b/js/dashboard.js index 91c4c723b69c41b8327bcfcf2919a53713166835..f92b2beaa28936696c6b0d7d5035b9656006af46 100644 --- a/js/dashboard.js +++ b/js/dashboard.js @@ -21,4 +21,12 @@ function profile_clicked() { document.getElementsByClassName('order-wrapper')[0].style.display = 'none'; document.getElementById('profile').classList.add('selected'); document.getElementsByClassName('profile-wrapper')[0].style.display = 'block'; +} +function driverHistoryClicked() { + document.getElementById('previous-order').classList.remove('selected-order'); + document.getElementById('driver-history').classList.add('selected-order'); +} +function previousOrderClicked() { + document.getElementById('driver-history').classList.remove('selected-order'); + document.getElementById('previous-order').classList.add('selected-order'); } \ No newline at end of file diff --git a/js/history.js b/js/history.js index 7d5dee1d655b2679b54c82e31e224e5c6dbfc96a..163f82b6714d08a106109bc0ab827b631f940e08 100644 --- a/js/history.js +++ b/js/history.js @@ -1,53 +1,17 @@ -function getAllTransaction(){ +function getAllTransaction(isDriver){ //TODO: minta id dari session!! - var id = 2; + var id = 1; var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if(xmlhttp.readyState == 4 && xmlhttp.status == 200){ - var get = xmlhttp.responseXML; - var transactions = get.getElementsByTagName('transaction'); - for(i = 0; i < transactions.length; i++){ - if(transactions[i].getElementsByTagName('driverid')[0].childNodes[0].nodeValue == id){ - var dateElement = document.createElement('div'); - dateElement.classList.add('transaction-date'); - var txt = transactions[i].getElementsByTagName('date')[0].childNodes[0].nodeValue; - var temp = txt.split("-"); - var date = new Date(temp[0], txt[1], txt[2]); - dateElement.innerHTML = date.toDateString(); - - var cityElement = document.createElement('div'); - cityElement.classList.add('transaction-city'); - txt = transactions[i].getElementsByTagName('pickup')[0].childNodes[0].nodeValue; - txt = txt + '->'; - txt = txt + transactions[i].getElementsByTagName('destination')[0].childNodes[0].nodeValue; - cityElement.innerHTML = txt; - - var ratingElement = document.createElement('div'); - ratingElement.classList.add('transaction-rating'); - txt = 'gave '; - txt = txt + transactions[i].getElementsByTagName('rating')[0].childNodes[0].nodeValue; - txt = txt + ' star(s) for this order'; - ratingElement.innerHTML = txt; - - var commentElement = document.createElement('div'); - commentElement.classList.add('transaction-comment'); - txt = 'and left a comment <br />'; - txt = txt + transactions[i].getElementsByTagName('comment')[0].childNodes[0].nodeValue; - commentElement.innerHTML = txt; - - var singleTransaction = document.createElement('div'); - singleTransaction.classList.add('single-transaction'); - singleTransaction.appendChild(dateElement); - singleTransaction.appendChild(cityElement); - singleTransaction.appendChild(ratingElement); - singleTransaction.appendChild(commentElement); - singleTransaction.appendChild(document.createElement('button')); - - document.getElementById('driver-info').appendChild(singleTransaction); - } - } + document.getElementById('driver-info').innerHTML = xmlhttp.responseText; } }; - xmlhttp.open('GET', '../controller/transactionController.php',true); + xmlhttp.open('GET', '../controller/transactionController.php?id=' + id + '&driver=' + isDriver,true); xmlhttp.send(); } + +function hide(id){ + var elementId = 'transaction-' + id; + document.getElementById(elementId).parentNode.parentNode.style.display = "none"; +} \ No newline at end of file diff --git a/view/dashboard.php b/view/dashboard.php index a124286124a120a9f567686e90238c3d047557b1..10165a7c28e1fd76dadcc2ad089c58b0236d1f31 100644 --- a/view/dashboard.php +++ b/view/dashboard.php @@ -19,7 +19,7 @@ </div> <div class="menu"> <button class="submenu" id="order" onclick="order_clicked()">ORDER</button> - <button class="submenu" id="history" onclick="getAllTransaction(); history_clicked();">HISTORY</button> + <button class="submenu" id="history" onclick="history_clicked();">HISTORY</button> <button class="submenu selected" id="profile" onclick="getUserProfile(); profile_clicked();">PROFILE</button> </div> @@ -32,8 +32,10 @@ <div class="sub-header-heading"><h1>TRANSACTION HISTORY</h1></div> </div> <div class="menu"> - <button class="submenu-two" id="previous-order">MY PREVIOUS ORDER</button> - <button class="submenu-two selected-order" id="driver-history" onclick="getAllTransaction()">DRIVER HISTORY</button> + <button class="submenu-two" id="previous-order" onclick="getAllTransaction(0); previousOrderClicked()"> + MY PREVIOUS ORDER</button> + <button class="submenu-two selected-order" id="driver-history" onclick="getAllTransaction(1); driverHistoryClicked()"> + DRIVER HISTORY</button> </div> <div class="driver-info" id="driver-info"></div> </section>