diff --git a/public/font/typicons.eot b/public/font/typicons.eot old mode 100644 new mode 100755 diff --git a/public/font/typicons.svg b/public/font/typicons.svg old mode 100644 new mode 100755 diff --git a/public/font/typicons.ttf b/public/font/typicons.ttf old mode 100644 new mode 100755 diff --git a/public/font/typicons.woff b/public/font/typicons.woff old mode 100644 new mode 100755 diff --git a/public/img/ic_close.png b/public/img/ic_close.png old mode 100644 new mode 100755 diff --git a/public/img/logo.jpg b/public/img/logo.jpg old mode 100644 new mode 100755 diff --git a/public/img/profile/R2dXM01NcDVRV0lrVXdGTE5nbDZDdz09 b/public/img/profile/R2dXM01NcDVRV0lrVXdGTE5nbDZDdz09 new file mode 100644 index 0000000000000000000000000000000000000000..e754de321e5bad788747a6acf8b0fc89629fd6ed Binary files /dev/null and b/public/img/profile/R2dXM01NcDVRV0lrVXdGTE5nbDZDdz09 differ diff --git a/public/img/profile/UFBqemxTWmtkZytjSmNSVWE4S2lTQT09 b/public/img/profile/UFBqemxTWmtkZytjSmNSVWE4S2lTQT09 new file mode 100644 index 0000000000000000000000000000000000000000..b39a68fb07fed004f193ca762bfbb5152f6d7a6c Binary files /dev/null and b/public/img/profile/UFBqemxTWmtkZytjSmNSVWE4S2lTQT09 differ diff --git a/public/img/profile/VGdWZUZ2dlJlUkM5eWpjVDcyQXJoZz09 b/public/img/profile/VGdWZUZ2dlJlUkM5eWpjVDcyQXJoZz09 old mode 100644 new mode 100755 diff --git a/public/img/profile/cXNNb1RtOXg0ckxtUVpoZGpiK3NTZz09 b/public/img/profile/cXNNb1RtOXg0ckxtUVpoZGpiK3NTZz09 new file mode 100644 index 0000000000000000000000000000000000000000..8c90cb6ae6dc081e33ceeacf603389a7c12e4e90 Binary files /dev/null and b/public/img/profile/cXNNb1RtOXg0ckxtUVpoZGpiK3NTZz09 differ diff --git a/public/index.php b/public/index.php old mode 100644 new mode 100755 diff --git a/public/order.js b/public/order.js old mode 100644 new mode 100755 index 5b036a4caa24f0c2c9f7281a4e66ee44fc73285c..0b73fd1e5846e022665ceb5ca59467fa11981566 --- a/public/order.js +++ b/public/order.js @@ -4,6 +4,8 @@ showLocationPage(); })(); +var resultData; + function makeOrder() { var orderPickup = document.getElementById('orderPickup').value; @@ -14,6 +16,7 @@ function makeOrder() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { + resultData = JSON.parse(this.responseText); bindSearchResult(JSON.parse(this.responseText)); showDriverPage(); } @@ -24,7 +27,6 @@ function makeOrder() { } function bindSearchResult(data) { - alert(JSON.stringify(data)); var preferred = data.preferred; if (preferred != null) { document.getElementById('driver-preferred-result').innerHTML = '' + @@ -45,7 +47,7 @@ function bindSearchResult(data) { ' <img src="'+driverItem.photo+'" style="float: left; border: 1px solid black; margin: 10px" width="120" height="125">\n' + ' <p style="font-size: 1.4em; margin:20px 10px 3px 10px">'+driverItem.name+'</p>\n' + ' <p style="margin-top: 0"><span class="text-orange"><b><i class="icon icon-star"></i> '+driverItem.rating+'</b></span> ('+driverItem.sum_order+' votes)</p>\n' + - ' <a href="#" class="btn green" style="float: right; margin: 10px">I CHOOSE YOU!</a>\n' + + ' <a href="#" class="btn green" style="float: right; margin: 10px" onclick="finishOrder(\''+driverItem.id+'\')">I CHOOSE YOU!</a>\n' + '</div>'; }); document.getElementById('driver-search-result').innerHTML = html; @@ -53,11 +55,79 @@ function bindSearchResult(data) { } function finishOrder(id) { - alert(id); + var photo; + var name; + var username; + var preferred = resultData.preferred; + if (preferred.id == id) { + photo = preferred.photo; + name = preferred.name; + username = preferred.username; + } else { + var results = resultData.result; + var i = 0; + while (results[i].id != id) { + i++; + } + photo = results[i].photo; + name = results[i].name; + username = results[i].username; + } + + bindFinishPage(id, name, photo, username); showFinishPage(); } -function bindFinishPage() { +function bindFinishPage(id, name, photo, username) { + document.getElementById('driver-finish-order').innerHTML = '' + + '<img class="img-circle" src="'+photo+'"/><br>\n' + + '<h2>'+username+'</h2>\n' + + '<p>'+name+'</p>\n' + + '<i id="star-1" class="icon icon-star" onclick="setRating(1)"></i>\n' + + '<i id="star-2" class="icon icon-star" onclick="setRating(2)"></i>\n' + + '<i id="star-3" class="icon icon-star" onclick="setRating(3)"></i>\n' + + '<i id="star-4" class="icon icon-star" onclick="setRating(4)"></i>\n' + + '<i id="star-5" class="icon icon-star" onclick="setRating(5)"></i>\n' + + '<input type="hidden" id="order-rating" value="0"> \n' + + '<br>\n' + + '<br>\n' + + '<br>\n' + + '<textarea id="order-comment" style="width: 100%; height: 100px; padding: 10px; resize: none" placeholder="Your comment..." ></textarea>\n' + + '<a class="btn green" style="float: right; margin: 10px" onclick="completeOrder(\''+id+'\')">COMPLETE<br>ORDER</a>' +} + +function setRating(val) { + for (var i = 1; i <= 5; i++) { + if (i <= val) { + document.getElementById('star-'+i).style.color = "orange"; + } else { + document.getElementById('star-'+i).style.color = "black"; + } + } + document.getElementById('order-rating').value = val; +} + +function completeOrder(id) { + var customerID = document.getElementById('customer-id').innerHTML; + var orderPickup = document.getElementById('orderPickup').value; + var orderDestination = document.getElementById('orderDestination').value; + var rating = document.getElementById('order-rating').value; + var comment = document.getElementById('order-comment').value; + var data = 'id='+id+'&id_customer='+customerID+'&source='+orderPickup+'&destination='+orderDestination+'&rating='+rating+'&comment='+comment; + + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + if (this.responseText == "Error") { + alert("Fail completing your order"); + } else { + window.location.href = "/main/order?u="+customerID; + } + } + }; + xhttp.open("POST", "/main/order/finish?u", true); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhttp.send(data); } diff --git a/public/scripts.js b/public/scripts.js old mode 100644 new mode 100755 diff --git a/public/style.css b/public/style.css old mode 100644 new mode 100755 index 4085e98dddda2c01226428377b4033151a7b9c48..01c90e823ae7f150991945144d9e8c21c1cfcb75 --- a/public/style.css +++ b/public/style.css @@ -162,8 +162,8 @@ body { /* ------------------------- PROFIL -------------------------*/ .img-circle { - max-width: 170px; - max-height: 170px; + width: 170px; + height: 170px; border-radius: 50%; border: 3px solid black; } diff --git a/src/controller/OrderController.php b/src/controller/OrderController.php index 8d0aeaef5797724abaf43754e80208248dc9fc03..b6a102eaa94e3b4a5e1fbc4da3f61f81b70b61c7 100644 --- a/src/controller/OrderController.php +++ b/src/controller/OrderController.php @@ -36,7 +36,7 @@ class OrderController { $dbconn = DB::getInstance(); $stmt = $dbconn->prepare( 'SELECT - user.id AS id, name, photo, rating, sum_order + user.id AS id, name, username, photo, rating, sum_order FROM user NATURAL JOIN driver WHERE user.id IN ( SELECT DISTINCT id_driver @@ -50,6 +50,9 @@ class OrderController { return; } $results += $stmt->fetchAll(); + foreach ($results as $key => $field) { + $results[$key]['id'] = simpleCrypt($results[$key]['id'], 'e'); + } // get preferred driver $preferred_driver = null; @@ -57,7 +60,7 @@ class OrderController { $dbconn = DB::getInstance(); $stmt = $dbconn->prepare( 'SELECT - user.id AS id, name, photo, rating, sum_order + user.id AS id, name, username, photo, rating, sum_order FROM user NATURAL JOIN driver WHERE username = ?' ); @@ -68,9 +71,53 @@ class OrderController { } $preferred_driver = $stmt->fetchObject(); } + $preferred_driver->id = simpleCrypt($preferred_driver->id, 'e'); echo json_encode(array('preferred'=>$preferred_driver , 'result' => $results)); } + public static function FinishOrderHandler() { + var_dump($_POST); + + $id = simpleCrypt($_POST['id'], 'd'); + $id_customer = simpleCrypt($_POST['id_customer'], 'd'); + $source = $_POST['source']; + $destination = $_POST['destination']; + $rating = $_POST['rating']; + $comment = $_POST['comment']; + + $dbconn = DB::getInstance(); + $stmt = $dbconn->prepare( + 'INSERT INTO user_order + (id_driver, id_customer, source, destination, rating, comment) + VALUES + (?, ?, ?, ?, ?, ?)' + ); + + // Write finished order to db + $stmt->execute(array($id, $id_customer, $source, $destination, $rating, $comment)); + if ($stmt === false) { + echo "Error"; + return; + } + + // Setup driver rating + $dbconn = DB::getInstance(); + $stmt = $dbconn->prepare( + 'UPDATE driver + SET rating=IF(rating=0, ? , ((rating + ?)/2)), sum_order=(sum_order+1) + WHERE + id = ?' + ); + $stmt->execute(array($rating, $rating, $id)); + if ($stmt === false) { + echo "Error"; + return; + } + + echo "Success"; + + } + } \ No newline at end of file diff --git a/src/controller/ProfilController.php b/src/controller/ProfilController.php index b8dc45d633e3bf576cf41ad7e0d620bd6785115d..4a931895c240f08311091250b689c142334622c0 100644 --- a/src/controller/ProfilController.php +++ b/src/controller/ProfilController.php @@ -23,7 +23,7 @@ class ProfilController { $user = Driver::Create($uid, $dbconn); if (!$user) { - echo "User not found!"; + echo "User not found! (".$uid.")"; return; } @@ -249,4 +249,4 @@ class ProfilController { } -} \ No newline at end of file +} diff --git a/src/route.php b/src/route.php index 4285420fdfd94f41531138330125f89ca477c47f..a2e6864c48853be106194e11d15761b6390fdc09 100644 --- a/src/route.php +++ b/src/route.php @@ -18,8 +18,8 @@ $AppInstance->addRoute("/main/profil/location/add", 'ProfilController::A $AppInstance->addRoute("/main/order", 'OrderController::OrderHandler'); $AppInstance->addRoute("/main/order/new", 'OrderController::MakeOrderHandler'); +$AppInstance->addRoute("/main/order/finish", 'OrderController::FinishOrderHandler'); $AppInstance->addRoute("/main/history", 'MainController::DefaultHandler'); $AppInstance->addRoute("/main/order/select", 'MainController::DefaultHandler'); -$AppInstance->addRoute("/main/order/finish", 'MainController::DefaultHandler'); diff --git a/src/view/order.php b/src/view/order.php index 0c81de5dfb348152662465539e64d45adc0b834f..43d3ffaf20b1ee325ca0595fb37321a45c6ad6c1 100644 --- a/src/view/order.php +++ b/src/view/order.php @@ -21,6 +21,7 @@ </div> <div class="row"> <div class="col-6"><h1>MAKE AN ORDER</h1></div> + <span id="customer-id" style="display: none"><?=$id?></span> </div> <div class="row"> <div class="col-2"> @@ -109,20 +110,8 @@ <div id="order-page-finish" style="width: 100%;"> <h2 style="margin-left: 10px; margin-top: 0px">HOW WAS IT? </h2> - <div class="text-center profil" style="padding-bottom: 60px"> - <img class="img-circle" src="<?=$user->photo?>"/><br> - <h2>@bombarattata</h2> - <p>Fadhil Imam Kurnia</p> - <i class="icon icon-star"></i> - <i class="icon icon-star"></i> - <i class="icon icon-star"></i> - <i class="icon icon-star"></i> - <i class="icon icon-star"></i> - <br> - <br> - <br> - <textarea style="width: 100%; height: 100px; padding: 10px; resize: none" placeholder="Your comment..." ></textarea> - <a class="btn green" style="float: right; margin: 10px">COMPLETE<br>ORDER</a> + <div id="driver-finish-order" class="text-center profil" style="padding-bottom: 60px"> + <p id="driver-preferred-empty" class="text-center" style="font-size: large; color: #989898; margin: 30px">Nothing to display :(</p> </div> </div> diff --git a/src/view/profil.php b/src/view/profil.php index 85e517f47683ebc2363239b378460552ae7c7ee0..75bb26f33d5f240bc28a1ebafd3b28a50b42c9c4 100644 --- a/src/view/profil.php +++ b/src/view/profil.php @@ -41,7 +41,7 @@ </div> <div class="row"> <?php if ($location_count == 0): ?> - <h4>Tidak ada data lokasi :(</h4> + <h4 class="text-center">Tidak ada data lokasi :(</h4> <?php else:?> <ul> <?php foreach ($location as $data) : ?>