diff --git a/css/default_style.css b/css/default_style.css index 8dca10a5cba5a0520c232dbb8957cbd31e158380..cf87617f912bb24e25a6f874aeb37ab44e45e115 100755 --- a/css/default_style.css +++ b/css/default_style.css @@ -73,3 +73,14 @@ a:hover { margin-right: auto; } +.subheader { + height: 15%; +} +.title { + float: left; +} +.title h1 { + text-align: left; + margin: 0; +} + diff --git a/css/history.css b/css/history.css index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..c106793ff9d8a7f9749bab573337177e35162558 100755 --- a/css/history.css +++ b/css/history.css @@ -0,0 +1,9 @@ +.history_container { + margin-top: 10%; + height: 50%; + border: 1px solid red; +} + +.history_container > * { + border: 1px solid red; +} \ No newline at end of file diff --git a/css/location.css b/css/location.css index 7259a04ae6eccc160a0f3bbb60bd49381f5dfc00..5fdc03f6a9a7d0e3ccd6bbc24a898ff9816525b9 100644 --- a/css/location.css +++ b/css/location.css @@ -12,3 +12,24 @@ text-align: left; margin: 0; } +.add_loc_frame { + height: 30%; +} +.add_loc_frame h2 { + text-align: left; + margin: 0; +} +.add_loc_frame input[type="text"] { + width: 80%; + margin-right: 5%; +} +.back { + width: 39px; + text-align: center; + padding: 3px; + font-size: 0.8em; + float: left; +} +.add { + width: 50px; +} diff --git a/css/profile.css b/css/profile.css index 215515e1f5732e48267d856dc4cd2a2e30aba0e2..7f8bf4f16d9505f526ec87acf8a3333dbd0f9e3e 100755 --- a/css/profile.css +++ b/css/profile.css @@ -2,21 +2,15 @@ margin-top: 10%; height: 50%; } -.subheader { - height: 15%; -} -.title { - float: left; -} -.title h1 { - text-align: left; - margin: 0; -} + .edit_profile_button { float: right; margin-top: 10px; margin-right: 10px; } +.edit_profile_button a { + text-decoration: none; +} .profile_info_container { text-align: center; margin-top: 2%; @@ -40,11 +34,17 @@ .profile_data_container { height: 100px; } +.prefloc_container { + height: 50%; +} .edit_prefloc_button { float: right; margin-top: 10px; margin-right: 10px; } +.edit_prefloc_button a { + text-decoration: none; +} .edit_profile_container { margin-top: 10%; overflow-y: scroll; @@ -57,7 +57,7 @@ margin-bottom: 5%; } .current_pict_frame { - width: 170px; + width: 115px; height: 100px; overflow: auto; border-radius: 50%; @@ -70,6 +70,7 @@ width: 100%; } .pict_name_field { + width: 150px; margin-top: 35px; margin-left: 5%; } @@ -77,6 +78,7 @@ width: 100%; } .pict_picker_frame { + width: 100px; margin-top: 37px; } .pict_picker_frame input { diff --git a/css/switch.css b/css/switch.css index f14ace18e595d432e6ff615cd1b43cd091915e76..aded1df603de7b8d1e4b3083780752731fc2707f 100644 --- a/css/switch.css +++ b/css/switch.css @@ -32,7 +32,7 @@ } input:checked + .slider { - background-color: #2196F3; + background-color: #117d11; } input:focus + .slider { diff --git a/database/PR-Ojek.sql b/database/PR-Ojek.sql index 0289c80c70e444eed87ad81b60759b7c317806a3..5387feebc62d6fb24e69adbf9a8977027d5dada2 100755 --- a/database/PR-Ojek.sql +++ b/database/PR-Ojek.sql @@ -1,6 +1,12 @@ -- Database PR-Ojek +SET FOREIGN_KEY_CHECKS = 0; +DROP TABLE IF EXISTS `order`; +DROP TABLE IF EXISTS `driver_prefloc`; +DROP TABLE IF EXISTS `driver`; DROP TABLE IF EXISTS `user`; +SET FOREIGN_KEY_CHECKS = 1; + CREATE TABLE IF NOT EXISTS `user` ( `user_id` INT NOT NULL AUTO_INCREMENT, `name` VARCHAR(50) NOT NULL, @@ -12,29 +18,25 @@ CREATE TABLE IF NOT EXISTS `user` ( `pict` MEDIUMBLOB DEFAULT NULL, PRIMARY KEY (`user_id`) -); +) ENGINE=InnoDB; -DROP TABLE IF EXISTS `driver`; CREATE TABLE IF NOT EXISTS `driver` ( `driver_id` INT NOT NULL, - `total_score` DOUBLE(50,1) NOT NULL, - `votes` DOUBLE(50,1) NOT NULL, + `total_score` DOUBLE(50,1) NOT NULL DEFAULT '0.0', + `votes` DOUBLE(50,1) NOT NULL DEFAULT '0.0', - PRIMARY KEY (`driver_id`), - CONSTRAINT `driver_ibfk_1` FOREIGN KEY (`driver_id`) REFERENCES `user` (`user_id`) -); + CONSTRAINT `driver_ibfk_1` FOREIGN KEY (`driver_id`) REFERENCES `user` (`user_id`) ON UPDATE CASCADE ON DELETE CASCADE +) ENGINE=InnoDB; -DROP TABLE IF EXISTS `driver_prefloc`; CREATE TABLE IF NOT EXISTS `driver_prefloc` ( `driver_id` INT NOT NULL, `pref_loc` VARCHAR(50) NOT NULL, - PRIMARY KEY (`driver_id`), - CONSTRAINT `driver_prefloc_ibfk_1` FOREIGN KEY (`driver_id`) REFERENCES `driver` (`driver_id`) -); + CONSTRAINT `driver_prefloc_ibfk_1` FOREIGN KEY (`driver_id`) REFERENCES `driver` (`driver_id`) ON UPDATE CASCADE ON DELETE CASCADE +) ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS `order` ( - `order_id` INT NOT NULL, + `order_id` INT NOT NULL AUTO_INCREMENT, `dest_city` VARCHAR(50) NOT NULL, `pick_city` VARCHAR(50) NOT NULL, `score` DOUBLE(50,1) NOT NULL, @@ -44,6 +46,6 @@ CREATE TABLE IF NOT EXISTS `order` ( `date` DATE NOT NULL, PRIMARY KEY (`order_id`), - CONSTRAINT `order_ibfk_1` FOREIGN KEY (`cust_id`) REFERENCES `user` (`user_id`), - CONSTRAINT `order_ibfk_2` FOREIGN KEY (`driver_id`) REFERENCES `driver` (`driver_id`) -); + CONSTRAINT `order_ibfk_1` FOREIGN KEY (`cust_id`) REFERENCES `user` (`user_id`) ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT `order_ibfk_2` FOREIGN KEY (`driver_id`) REFERENCES `driver` (`driver_id`) ON UPDATE CASCADE ON DELETE CASCADE +) ENGINE=InnoDB; diff --git a/history/transaction_history.php b/history/transaction_history.php new file mode 100644 index 0000000000000000000000000000000000000000..382bb296140efd35fbb4594c2649c3fd9e2e005b --- /dev/null +++ b/history/transaction_history.php @@ -0,0 +1,37 @@ +<!DOCTYPE html> +<html> +<head> + <title>transaction history</title> + <link rel="stylesheet" type="text/css" href="../css/default_style.css"> + <link rel="stylesheet" type="text/css" href="../css/history.css"> + <link rel="stylesheet" type="text/css" href="../css/header.css"> +</head> +<body> + <div class="frame"> + <div class="header"> + <?php + $user_id = $_GET['id']; + include '../database/dbconnect.php'; + + $query=mysqli_query($con,"SELECT * FROM user WHERE user_id='".$user_id."'") or die(mysqli_error()); + + if(mysqli_num_rows($query)!=0) + { + $row=mysqli_fetch_assoc($query); + $username = $row['username']; + include("../template/header.php"); + } + mysqli_close($con); + ?> + </div> + <div class="menu_container"> + <?php include'../template/menu.php';?> + </div> + <div class="history_container"> + <div class="subheader"> + <div class="title"><h1>Transaction History</h1></div> + </div> + </div> + </div> +</body> +</html> \ No newline at end of file diff --git a/login/sign_up.html b/login/sign_up.html index 3caf0be62920a68766cccbb948fa5a0e91c66cff..fd16f16bfb5df77734972e82a2f1d53632db5a76 100755 --- a/login/sign_up.html +++ b/login/sign_up.html @@ -12,7 +12,7 @@ <h1>SIGNUP</h1> <div class="horizontal_line"></div> </div> - <form name="sign_up" method="post" action="sign_up.php" onsubmit="return validate_password();"> + <form name="sign_up" method="post" action="sign_up.php" onsubmit="return validateForm();"> <p id="error_signup" style="text-align: center;"></p> <div class="signup_container"> <div class="form_name"> @@ -67,37 +67,62 @@ </form> </div> <script> - function validate_password() - { - var password = document.sign_up.user_password.value; - var confirm_password = document.sign_up.confirm_password.value; - if (password !== confirm_password) - { - window.alert("The passwords you entered didn't match"); - return false; - } - } - function checkAvailability(name,value) - { - xhttp = new XMLHttpRequest(); - if (value.length == 0) { - document.getElementById("username_verification").innerHTML = ""; - document.getElementById("email_verification").innerHTML = ""; - return; + function validateForm() { + var email = document.sign_up.user_email.value; + var re = /[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}/igm; + if (document.sign_up.full_name.value == null || document.sign_up.full_name.value == "") { + window.alert("Please fill all the required fields"); + return false; + } else if (document.sign_up.username.value == null || document.sign_up.username.value == "") { + window.alert("Please fill all the required fields"); + return false; + } else if (document.sign_up.user_email.value == null || document.sign_up.user_email.value == "") { + window.alert("Please fill all the required fields"); + return false; + } else if (document.sign_up.user_password.value == null || document.sign_up.user_password.value == "") { + window.alert("Please fill all the required fields"); + return false; + } else if (document.sign_up.confirm_password.value == null || document.sign_up.confirm_password.value == "") { + window.alert("Please fill all the required fields"); + return false; + } else if (document.sign_up.user_phone.value == null || document.sign_up.user_phone.value == "") { + window.alert("Please fill all the required fields"); + return false; + } else if (document.sign_up.username.value.length > 20) { + window.alert("Username should be 1 to 20 characters long"); + return false; + } else if (!re.test(document.sign_up.user_email.value)) { + window.alert("Please enter a valid email address"); + return false; + } else if (document.sign_up.user_password.value !== document.sign_up.confirm_password.value) { + window.alert("The passwords you entered didn't match"); + return false; + } else if ((document.sign_up.user_phone.value.length < 9) || (document.sign_up.user_phone.value.length > 12)) { + window.alert("Phone number should be 9 to 12 characters long"); + return false; + } } - xhttp.onreadystatechange = function() { - if (this.readyState == 4 && this.status == 200) { - if (name === "username") { - document.getElementById("username_verification").innerHTML = this.responseText; - } else if (name === "user_email") { - document.getElementById("email_verification").innerHTML = this.responseText; - } + function checkAvailability(name,value) + { + xhttp = new XMLHttpRequest(); + if (value.length == 0) { + document.getElementById("username_verification").innerHTML = ""; + document.getElementById("email_verification").innerHTML = ""; + return; } - }; - var str = name+"="+value; - xhttp.open("GET", "sign_up.php?key="+str, true); - xhttp.send(); - } + xhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + if (name === "username") { + document.getElementById("username_verification").innerHTML = this.responseText; + } else if (name === "user_email") { + document.getElementById("email_verification").innerHTML = this.responseText; + } + } + }; + var str = name+"="+value; + xhttp.open("GET", "sign_up.php?key="+str, true); + xhttp.send(); + } </script> </body> diff --git a/login/sign_up.php b/login/sign_up.php index 0d451c272739d0a27a6dc259b958b03900246f9a..a66c1c3c1b05a7cb374fe518e5d80bd3487d4618 100644 --- a/login/sign_up.php +++ b/login/sign_up.php @@ -29,11 +29,14 @@ $getUserID = mysqli_query($con,"SELECT user_id FROM user WHERE username='".$username."'") or die(mysql_error()); $row=mysqli_fetch_assoc($getUserID); $user_id=$row['user_id']; - header("Location: ../profile/profile.php?id=?$user_id"); + if ($status == "customer") { - header("Location: ../order/order.php?id=?$user_id"); + header("Location: ../order/order.php?id=$user_id"); } else { - header("Location: ../order/order.php?id=?$user_id"); + $query = mysqli_query($con,"INSERT INTO driver (driver_id,total_score,votes) VALUES ('$user_id',0,0)") or die(mysqli_error($con)); + if ($query) { + header("Location: ../profile/profile.php?id=$user_id"); + } } } mysqli_close($con); diff --git a/profile/edit_location.php b/profile/edit_location.php index ce5f62b5ac8ac0e668d0e16373a799ceeb62350f..a7f7f92eb2c54b4cc148adbb918ff34e25fc77dd 100644 --- a/profile/edit_location.php +++ b/profile/edit_location.php @@ -28,8 +28,20 @@ </div> <div class="editloc_container"> <div class="subheader"> - <div class="title"><h1>Edit Preferred Loaction</h1></div> + <div class="title"><h1>Edit Preferred Location</h1></div> </div> + <div class="add_loc_frame"> + <h2> Add New Location</h2> + <form name="add_location" action="updateLocation.php" method="POST"> + <input type="text" name="new_location"> + <input type="text" id="hidden_userid" name="hidden_userid" style="display: none;"> + <input type="submit" value="ADD" class="button green add"> + </form> + </div> + <a href=<?php echo 'profile.php?id='.$user_id; ?>><div class="button red back">BACK</div></a> </div> + <?php + echo "<script>document.getElementById('hidden_userid').value =".$user_id."</script>"; + ?> </body> </html> diff --git a/profile/edit_profile.php b/profile/edit_profile.php index 5f6d0b7e5d84923c05a12c9bff0f57389c419788..7c3c1703ab2fe7ce34772ac2c7821efdd361343d 100644 --- a/profile/edit_profile.php +++ b/profile/edit_profile.php @@ -18,6 +18,7 @@ if(mysqli_num_rows($query)!=0) { $row=mysqli_fetch_assoc($query); + $current_stat = $row['status']; $username = $row['username']; include("../template/header.php"); } @@ -31,7 +32,7 @@ <div class="subheader"> <div class="title"><h1>My Profile</h1></div> </div> - <form name="edit_identity" method="POST" action="update_profile.php" enctype="multipart/form-data"> + <form name="edit_identity" method="POST" action="updateProfile.php" enctype="multipart/form-data"> <div class="change_profilepict"> <div class="current_pict_frame"> <img id="current_profile_pict" src="../img/default_profile.jpeg"> @@ -64,7 +65,7 @@ </div> <div style="height: 30px;"> <label class="switch" style="float: right;"> - <input type="checkbox" name="is_driver" value="true"> + <input type="checkbox" name="is_driver" id="current_stat" value="true"> <span class="slider round"></span> </label> </div> @@ -79,8 +80,11 @@ </div> </div> <?php - echo "<script>document.getElementById('current_name').value = '".$row['name']."'</script>"; - echo "<script>document.getElementById('current_phone').value = '".$row['phone']."'</script>"; + if ($current_stat == "driver") { + echo "<script>document.getElementById('current_name').value = '".$row['name']."';</script>"; + } + echo "<script>document.getElementById('current_phone').value = '".$row['phone']."';</script>"; + echo "<script>document.getElementById('current_stat').checked = true;</script>"; if (isset($row['pict'])) { echo "<script>document.getElementById('current_profile_pict').src ='getProfilePict.php?id=".$user_id."'</script>"; } diff --git a/profile/profile.php b/profile/profile.php index 68583f72d6061c1d15d0d5c80fd9f0093c3deea8..4ea93cd7dec7961f4a800ab472af3169ead90090 100644 --- a/profile/profile.php +++ b/profile/profile.php @@ -1,6 +1,3 @@ -<?php - -?> <html> <head> <title>U Wanna Call Me Beibh?</title> @@ -29,7 +26,7 @@ <div class="menu_container"> <?php include'../template/menu.php';?> </div> - <div class="top_container"> + <div class="profile_container"> <div class="subheader"> <div class="title"><h1>My Profile</h1></div> <div class="edit_profile_button"><a href=<?php echo 'edit_profile.php?id='.$user_id; ?>>✎</a></div> @@ -43,7 +40,9 @@ echo "</br><strong>".$row['username']."</strong></br>"; echo $row['name']."</br>"; if ($row['status'] == "driver") { - echo "driver | Rating (xxx Votes)</br>"; + echo "Driver | Rating (xxx Votes)</br>"; + } else { + echo "No-Driver</br>"; } echo $row['email']."</br>"; echo $row['phone']."</br>"; @@ -54,7 +53,7 @@ </div> </div> </div> - <div class="top_container"> + <div class="prefloc_container"> <div class="subheader"> <div class="title"><h1>Preferred Locations</h1></div> <div class="edit_prefloc_button"><a href=<?php echo 'edit_location.php?id='.$user_id; ?>>✎</a></div> diff --git a/profile/updateLocation.php b/profile/updateLocation.php new file mode 100644 index 0000000000000000000000000000000000000000..e2468caf320c99242ffaeb26bd018df6245248df --- /dev/null +++ b/profile/updateLocation.php @@ -0,0 +1,13 @@ +<?php + if ($_SERVER["REQUEST_METHOD"] == "POST") { + if (!empty($_POST['new_location'])) { + include '../database/dbconnect.php'; + $user_id = $_POST['hidden_userid']; + $new_loc = $_POST['new_location']; + $query = mysqli_query($con,"INSERT INTO driver_prefloc (driver_id,pref_loc) VALUES ('$user_id', '$new_loc')") or die(mysqli_error($con)); + if ($query) { + header("Location: edit_location.php?id=$user_id"); + } + } + } +?> diff --git a/profile/updateProfile.php b/profile/updateProfile.php new file mode 100644 index 0000000000000000000000000000000000000000..c5ac6e983c8f711a449e60fd53228d19cb8c6fc2 --- /dev/null +++ b/profile/updateProfile.php @@ -0,0 +1,66 @@ +<?php + if ($_SERVER["REQUEST_METHOD"] == "POST") { + include '../database/dbconnect.php'; + if (!empty($_POST['edit_name']) && !empty($_POST['edit_phone']) && !empty($_POST['hidden_userid'])) { + $user_id = $_POST['hidden_userid']; + $new_name = $_POST['edit_name']; + $new_phone = $_POST['edit_phone']; + $getCurrentStatus = mysqli_query($con,"SELECT status FROM user WHERE user_id='".$user_id."'") or die(mysql_error($con)); + $row=mysqli_fetch_assoc($getCurrentStatus); + $curent_stat=$row['status']; + if(isset($_POST['is_driver'])) + { + $status = 'driver'; + if ($current_stat != "driver") { + $query = mysqli_query($con,"INSERT INTO driver (driver_id) VALUES ('$user_id')") or die(mysqli_error($con)); + } + } else + { + if ($current_stat == "driver") { + $query = mysqli_query($con,"DELETE FROM driver WHERE driver_id='".$user_id."'") or die(mysqli_error($con)); + } + $status = 'customer'; + } + if (isset($_FILES) && ($_FILES['profile_pictfile']['size'] > 0)) + { + $checkImg = true; + $filePath = $_FILES['profile_pictfile']['tmp_name']; + $fileName = $_FILES['profile_pictfile']['name']; + $fileSize = $_FILES['profile_pictfile']['size']; + $fileType = $_FILES['profile_pictfile']['type']; + if ($_FILES['profile_pictgile']['error'] || !is_uploaded_file($filePath)) { + $checkImg = false; + echo "Error: Error in uploading file. Please try again."; + } + if ($checkImg && !in_array($fileType, array('image/png', 'image/x-png', 'image/jpeg', 'image/pjpeg', 'image/gif'))) { + $checkImg = false; + echo "Error: Unsupported file extension. Supported extensions are JPG / PNG."; + } + if ($checkImg && $fileSize > 16000000) { + $checkImg = false; + echo "Error: File size must be less than 16 MB."; + } + if ($checkImg) { + $fp = fopen($filePath, 'r'); + $content = fread($fp, filesize($filePath)); + $content = addslashes($content); + fclose($fp); + + if(!get_magic_quotes_gpc()) + { + $fileName = addslashes($fileName); + } + } + $query="UPDATE user set name='".$new_name."',phone='".$new_phone."',status='".$status."',pict='".$content."'WHERE user_id='".$user_id."'"; + } else { + $query="UPDATE user set name='".$new_name."',phone='".$new_phone."',status='".$status."'WHERE user_id='".$user_id."'"; + } + $exe=mysqli_query($con,$query) or die(mysqli_error()); + if($exe) + { + header("Location: profile.php?id=$user_id"); + } + mysqli_close($con); + } + } +?> diff --git a/profile/update_profile.php b/profile/update_profile.php deleted file mode 100644 index 950595932c49fb977eaeec52a998c766eeb5a526..0000000000000000000000000000000000000000 --- a/profile/update_profile.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php - session_start(); - if ($_SERVER["REQUEST_METHOD"] == "POST") { - include '../database/dbconnect.php'; - if (isset($_FILES) && ($_FILES['profile_pictfile']['size'] > 0) && !empty($_POST['edit_name']) && !empty($_POST['edit_phone']) && !empty($_POST['hidden_userid'])) { - $user_id = $_POST['hidden_userid']; - $new_name = $_POST['edit_name']; - $new_phone = $_POST['edit_phone']; - if(isset($_POST['is_driver'])) - { - $status = 'driver'; - } - else - { - $status = 'customer'; - } - - $checkImg = true; - $filePath = $_FILES['profile_pictfile']['tmp_name']; - $fileName = $_FILES['profile_pictfile']['name']; - $fileSize = $_FILES['profile_pictfile']['size']; - $fileType = $_FILES['profile_pictfile']['type']; - if ($_FILES['profile_pictgile']['error'] || !is_uploaded_file($filePath)) { - $checkImg = false; - echo "Error: Error in uploading file. Please try again."; - } - if ($checkImg && !in_array($fileType, array('image/png', 'image/x-png', 'image/jpeg', 'image/pjpeg', 'image/gif'))) { - $checkImg = false; - echo "Error: Unsupported file extension. Supported extensions are JPG / PNG."; - } - if ($checkImg && $fileSize > 16000000) { - $checkImg = false; - echo "Error: File size must be less than 16 MB."; - } - if ($checkImg) { - $fp = fopen($filePath, 'r'); - $content = fread($fp, filesize($filePath)); - $content = addslashes($content); - fclose($fp); - - if(!get_magic_quotes_gpc()) - { - $fileName = addslashes($fileName); - } - $query=mysqli_query($con,"UPDATE user set name='".$new_name."',phone='".$new_phone."',status='".$status."',pict='".$content."'WHERE user_id='".$user_id."'") or die(mysqli_error()); - } - if($query) - { - header("Location: profile.php?id=$user_id"); - } - mysqli_close($con); - } - } -?> diff --git a/template/menu.php b/template/menu.php index 076fde02b49f75e85f0d84a574dc7b7e673b0bcc..35d738d480e3156c2368ecea5b657d3f9b5c4ca6 100644 --- a/template/menu.php +++ b/template/menu.php @@ -5,7 +5,7 @@ <h3>ORDER</h3> </div> </a> - <a href="../history/history.php?id='. $user_id .'" name="history_link"> + <a href="../history/transaction_history.php?id='. $user_id .'" name="history_link"> <div class="menu" id="history_link"> <h3>HISTORY</h3> </div>