diff --git a/controller/orderController.php b/controller/orderController.php index 8196bd572c5539fdbcc6d690d27ffa849e1f73b3..0314e7502b0f468cf27027a92954aad9b272e6c0 100644 --- a/controller/orderController.php +++ b/controller/orderController.php @@ -1,12 +1,14 @@ <?php include "../model/user.php"; +include "../model/order.php"; if(isset($_GET['drivername']) && isset($_GET['id'])){ $userId = $_GET['id']; $driverName = $_GET['drivername']; $user = new User(); - $result = $user->getDriver($userId); + $result = $user->getDriverNotId($userId); + header('Content-Type: text/html'); $txt = '<div class="driver-box"><h1>PREFERRED DRIVERS</h1>'; //Process to find the driver while($row = mysqli_fetch_array($result)){ @@ -23,7 +25,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->getDriver($userId); + $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"> @@ -34,3 +36,33 @@ if(isset($_GET['drivername']) && isset($_GET['id'])){ $txt = $txt . '</div>'; echo $txt; } + +if(isset($_GET['driverId'])){ + $driverId = $_GET['driverId']; + $user = new User(); + $result = $user->getDriverById($driverId); + header('Content-Type: text/html'); + $txt = '<div class="third-page-driver">'; + //Process to find the driver + while($row = mysqli_fetch_array($result)){ + $txt = $txt . '<input type="hidden" id="hidden-image" value="'. $row['image'].'"/><div class="driver-image"> + </div><div class="driver-username">@'. $row['username'].'</div><div>'. $row['name'] .'</div>'; + } + $txt = $txt . '</div>'; + echo $txt; +} + +if(isset($_POST['pickup'])){ + $date = date('Y-m-d H:i:s'); + $pickup = $_POST['pickup']; + $destination = $_POST['destination']; + $driverId = $_POST['driverId']; + $userId = $_POST['userId']; + $rating = $_POST['rating']; + $pickup = $_POST['pickup']; + $comment = $_POST['comment']; + $transaction = new Order(); + $transaction->setTransaction($userId, $driverId, $pickup, $destination, $date, $rating, $comment); + //header('Location: ../view/dashboard.php?id=1'); + echo "berhasil"; +} diff --git a/controller/transactionController.php b/controller/transactionController.php index e387c09239b001f6be5b8ef4a895d073a0a63a4e..908b8f715c4dc50f60909b9725d83fe72b1c2d7c 100644 --- a/controller/transactionController.php +++ b/controller/transactionController.php @@ -33,7 +33,7 @@ if($isDriver) { <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'><button id='transaction-" . $i . "' onclick='hide(" . $i . ")'>HIDE</button></div> + <div class='hide-button'><div id='transaction-" . $i . "' onclick='hide(" . $i . ")'>HIDE</div></div> </div>"; $i++; } @@ -61,7 +61,7 @@ if($isDriver) { <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'><button id='transaction-" . $i . "' onclick='hide(" . $i . ")'>HIDE</button></div> + <div class='hide-button'><div id='transaction-" . $i . "' onclick='hide(" . $i . ")'>HIDE</div></div> </div>"; $i++; } diff --git a/css/dashboard.css b/css/dashboard.css index f0da0776060a9b3f04fb9f404a1a73f7e2a081cb..66d729046577f9eabb151d4db17adc74fab9f183 100644 --- a/css/dashboard.css +++ b/css/dashboard.css @@ -28,6 +28,7 @@ border: 1px solid #000; font-size: 2rem; font-weight: bold; + cursor: pointer; } .submenu-two { @@ -40,6 +41,7 @@ border: 1px solid #000; font-size: 1.5rem; font-weight: bold; + cursor: pointer; } .selected { diff --git a/css/history.css b/css/history.css index 468dfd1a43544abb027628eb8111f07ea1ad1fe8..c4b317978896d20e7806b9e257803f5654ad8af2 100644 --- a/css/history.css +++ b/css/history.css @@ -40,7 +40,9 @@ display: inline-block; font-size: initial; } -.hide-button button { +.hide-button > div { + display: inline-block; + cursor: pointer; padding: 8px; font-size: 1.5rem; background: red; diff --git a/css/order.css b/css/order.css index fe6cde32e953b23ee5e164a3d7ed5fb0803166ec..4cc6eaa4e11489436fb4b2f5626928d0f2e606bd 100644 --- a/css/order.css +++ b/css/order.css @@ -106,4 +106,46 @@ border: 1px solid #000; background-color: #82D800; border-radius: 8px; +} +.third-page { + width: 100%; + text-align: center; +} +.third-page > h1 { + text-align: left; +} +.selected-driver { + margin: 10px 0; + width: 100%; + text-align: center; + font-size: 1.5rem; +} +.driver-image { + display: inline-block; + height: 100px; + width: 100px; + background-position: center; + background-size: cover; + border: 2px solid #000; + border-radius: 1000px; +} +.driver-username { + font-size: 2rem; + font-weight: bold; +} +textarea { + width: 100%; +} +.submit-button { + margin: 10px 0; + width: 100%; + text-align: right; +} +.submit-button input { + display: inline-block; + text-align: right; + border: 1px solid #000; + background-color: #82D800; + border-radius: 15px; + padding: 15px; } \ No newline at end of file diff --git a/js/order.js b/js/order.js index c4aa4177d1e864edfd0fc2bc572b138b706272b0..15f67bd84d01d6c5db95b58f08420dd03a857533 100644 --- a/js/order.js +++ b/js/order.js @@ -25,13 +25,28 @@ function getDriver() { var drivername = (document.getElementById('preferred-driver').value) ? document.getElementById('preferred-driver').value : null; xmlhttp.onreadystatechange = function () { if(xmlhttp.readyState == 4 && xmlhttp.status == 200){ - var drivers = this.responseText; - document.getElementsByClassName('second-page')[0].innerHTML = drivers; + document.getElementsByClassName('second-page')[0].innerHTML = this.responseText; } }; xmlhttp.open('GET','../controller/orderController.php?drivername='+drivername+'&id='+sessionid,true); xmlhttp.send(); } function chooseDriver(id){ - console.log(id); + document.getElementsByClassName('select-driver')[0].classList.remove('order-count'); + document.getElementsByClassName('complete-order')[0].classList.add('order-count'); + document.getElementsByClassName('second-page')[0].style.display = 'none'; + document.getElementsByClassName('third-page')[0].style.display = 'block'; + var xmlhttp = new XMLHttpRequest(); + xmlhttp.onreadystatechange = function () { + if(xmlhttp.readyState == 4 && xmlhttp.status == 200){ + document.getElementById('selected-driver').innerHTML = xmlhttp.responseText; + document.getElementById('driverId').value = id; + document.getElementById('userId').value = sessionid; + var imageName = document.getElementById('hidden-image').value; + console.log(imageName); + document.getElementsByClassName('driver-image')[0].style.backgroundImage = 'url(../img/' + imageName + ')'; + } + }; + xmlhttp.open('GET','../controller/orderController.php?driverId='+id,true); + xmlhttp.send(); } \ No newline at end of file diff --git a/model/order.php b/model/order.php index 920e3c590909ed9d640d2e0b9c2eb52d7078802b..42a6c62e01dc58d09469f2245403818486d471dc 100644 --- a/model/order.php +++ b/model/order.php @@ -9,4 +9,13 @@ class Order { mysqli_close($con); return $result; } + 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, date, rating, comment) VALUES(' + . $userId .','. $driverId .','. $pickup .','. $destination.','. $transactionDate.','.$rating.',' + . $comment.')'; + mysqli_query($con, $sql); + mysqli_close($con); + } } \ No newline at end of file diff --git a/model/user.php b/model/user.php index 37aa15614152d38108725537a76c95dfb8e64e11..93cd457aee6494a87eb361e42ada2852ac879167 100644 --- a/model/user.php +++ b/model/user.php @@ -75,11 +75,7 @@ class User { mysqli_close($con); return $result; } - /** - get drivers whose id is not the user's id - * prevent order with self - */ - function getDriver($id){ + function getDriverNotId($id){ $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; @@ -87,4 +83,12 @@ class User { mysqli_close($con); return $result; } + function getDriverById($id){ + $con = mysqli_connect('localhost','root','','projekers'); + mysqli_select_db($con,'projekers'); + $query = "SELECT name,username,image FROM user WHERE isDriver=1 AND id=" . $id; + $result = mysqli_query($con,$query); + mysqli_close($con); + return $result; + } } \ No newline at end of file diff --git a/view/dashboard.php b/view/dashboard.php index 5e84fa02fab91437c1a53065e75a58e818f9c0a8..655511007ae68c3c80b598d50305f9c00f4b63c0 100644 --- a/view/dashboard.php +++ b/view/dashboard.php @@ -30,9 +30,9 @@ </div> </div> <div class="menu"> - <button class="submenu" id="order" onclick="order_clicked()">ORDER</button> - <button class="submenu" id="history" onclick="history_clicked(); getAllTransaction(1)">HISTORY</button> - <button class="submenu selected" id="profile" onclick="getUserProfile(); profile_clicked();">PROFILE</button> + <div class="submenu" id="order" onclick="order_clicked()">ORDER</div> + <div class="submenu" id="history" onclick="history_clicked(); getAllTransaction(1)">HISTORY</div> + <div class="submenu selected" id="profile" onclick="getUserProfile(); profile_clicked();">PROFILE</div> </div> <section class="order-wrapper"> @@ -44,10 +44,10 @@ <div class="sub-header-heading"><h1>TRANSACTION HISTORY</h1></div> </div> <div class="menu"> - <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 class="submenu-two" id="previous-order" onclick="getAllTransaction(0); previousOrderClicked()"> + MY PREVIOUS ORDER</div> + <div class="submenu-two selected-order" id="driver-history" onclick="getAllTransaction(1); driverHistoryClicked()"> + DRIVER HISTORY</div> </div> <div class="driver-info" id="driver-info"></div> </section> diff --git a/view/order.php b/view/order.php index 4f03adc1078f4a1245252df5ce4ec44d0de4412f..6507b6d63a9d2691f578bb2726954242476c6ec1 100644 --- a/view/order.php +++ b/view/order.php @@ -7,7 +7,7 @@ <div class="complete-order"><div class="counter">3</div>Complete Order</div> </div> <div> - <form action="../controller/orderController.php"> + <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"/> @@ -22,14 +22,20 @@ <div class="next-page"><div id="next-page" onclick="nextPage(); getDriver();">NEXT</div></div> - <div class="second-page"> - - </div> + <div class="second-page"></div> <div class="third-page"> <h1>HOW WAS IT?</h1> - <input type="radio" /> - <input type="text" /> + <div class="selected-driver" id="selected-driver"></div> + <input type="hidden" id="driverId" name="driverId" /> + <input type="hidden" id="userId" name="userId" /> + <input type="radio" id="rating" name="rating" value="1" />1 + <input type="radio" id="rating" name="rating" value="2" />2 + <input type="radio" id="rating" name="rating" value="3" />3 + <input type="radio" id="rating" name="rating" value="4" />4 + <input type="radio" id="rating" name="rating" value="5" />5 + <textarea rows="3" placeholder="Leave your comment here!" name="comment" id="comment"></textarea> + <div class="submit-button"><input type="submit" value="COMPLETE!" /></div> </div>