diff --git a/.htaccess b/.htaccess deleted file mode 100644 index 3cc144b99299877ba9d3df6383d8fdaaf9a48fa2..0000000000000000000000000000000000000000 --- a/.htaccess +++ /dev/null @@ -1,7 +0,0 @@ -#RewriteEngine On -#RewriteBase /TugasBesar1_2017/ - -#RewriteCond %{THE_REQUEST} /view/([^\s?]*) [NC] -#RewriteRule ^ %1 [L,NE,R=302] - -#RewriteRule ^((?!view/).*)$ view/$1 [L,NC] \ No newline at end of file diff --git a/controller/edit-profile.php b/controller/edit-profile.php new file mode 100644 index 0000000000000000000000000000000000000000..da8d0868836ee2ba47ad71f008da8bd1ac5999bb --- /dev/null +++ b/controller/edit-profile.php @@ -0,0 +1,80 @@ +<?php + + +/* Model */ +include "../model/user.php"; +/* GET */ +if(!$_POST) { + $user = new User; + $user_id = $_GET['id']; + $result = $user->getUserById($user_id); + header('Content-Type: text/xml'); + $xml = '<user>'; + + while($row = mysqli_fetch_array($result)){ + $xml = $xml . '<id>' . $user_id . '</id><name>' . $row['name'] . '</name><image>' . $row['image'] . + '</image><phone>' . $row['phone'] . '</phone><driver>' . $row['isDriver'] . '</driver>'; + } + $xml = $xml . '</user>'; + + print $xml; +} + +/* POST */ + +if(isset($_POST["submit"])) { + $user = new User; + $userid = $_GET['id']; + $isDriver = 0; + $image = ""; + $name = ""; + $phone = ""; + $result = $user -> getUserById($userid); + while($row = mysqli_fetch_array($result)) { + $name = $row['name']; + $phone = $row['phone']; + $image = $row['image']; + $isDriver = $row['isDriver']; + } + if(isset($_POST['name'])) { + $name = $_POST['name']; + } + if(isset($_POST['phone'])) { + $phone = $_POST['phone']; + } + if(file_exists($_FILES["image-file"]["tmp_name"])) { + $targetDir = "../img/"; + $targetFile = $targetDir . basename($_FILES["image-file"]["name"]); + $uploadOK = 1; + $imageFileType = pathinfo($targetFile,PATHINFO_EXTENSION); + $check = getimagesize($_FILES["image-file"]["tmp_name"]); + if($check !== false) { + $uploadOK = 1; + } else { + $uploadOK = 0; + } + if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" + && $imageFileType != "gif" ) { + $uploadOk = 0; + } + if($uploadOK == 1) { + if (move_uploaded_file($_FILES["image-file"]["tmp_name"], $targetFile)) { + $image = basename($_FILES["image-file"]["name"]); + } + } + if($uploadOK == 0) { + echo 'no'; + } + } + if(isset($_POST['driver'])) { + $isDriver = 1; + } else { + $isDriver = 0; + } + $user->updateProfileById($userid, $name, $phone, $isDriver, $image); + header('Location: ../view/edit-profile.php?id=' . $userid); + +} + + + diff --git a/controller/orderController.php b/controller/orderController.php new file mode 100644 index 0000000000000000000000000000000000000000..b7d9b683e6c61dacf9e1099cda9e331b13bf1a8d --- /dev/null +++ b/controller/orderController.php @@ -0,0 +1,66 @@ +<?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->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)){ + if($row['name'] == $driverName){ + $txt = $txt . '<div class="single-driver"><img src="../img/'. $row['image'] .'" /><div class="driver-bio"> + <h2 class="driver-name">'. $row['name'].'</h2><div class="driver-rating"></div></div> + <div class="button-choose"><div onclick="chooseDriver('. $row['id'] .')">I CHOOSE YOU!</div></div></div>'; + } + } + //Process if driver name is not found + if(strlen($txt) == 50){ + $txt = $txt . '<div class="error-message">Nothing To Display :(</div>'; + } + $txt = $txt . '</div>'; + $txt = $txt . '<div class="driver-box"><h1>OTHER DRIVERS</h1>'; + //Process other drivers + $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"> + <h2 class="driver-name">'. $row['name'].'</h2><div class="driver-rating"></div></div> + <div class="button-choose"><div onclick="chooseDriver('. $row['id'] .')">I CHOOSE YOU!</div></div></div>'; + } + } + $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']; + $comment = $_POST['comment']; + $transaction = new Order(); + $transaction->setTransaction($userId, $driverId, $pickup, $destination, $date, $rating, $comment); + header('Location: ../view/dashboard.php?id='.$userId); +} diff --git a/controller/profile.php b/controller/profile.php index b4ae86a6b70419c8dce0703d02884eb4fb083811..51466f25e07f5ec8147bc7cdacafee54ac34a263 100644 --- a/controller/profile.php +++ b/controller/profile.php @@ -3,11 +3,10 @@ /* Model */ include "../model/user.php"; -//TODO: tambahin redirect klo get kosong - $user = new User; $user_id = $_GET['id']; $result = $user->getUserById($user_id); +$locations = $user->getPreferredLocation($user_id); header('Content-Type: text/xml'); $xml = '<user>'; while($row = mysqli_fetch_array($result)){ @@ -15,6 +14,18 @@ while($row = mysqli_fetch_array($result)){ '</username><email>' . $row['email'] . '</email><image>' . $row['image'] . '</image><phone>' . $row['phone'] . '</phone><driver>' . $row['isDriver'] . '</driver>'; } +while($row = mysqli_fetch_array($locations)){ + $xml = $xml . '<location>'. $row['location'] .'</location>'; +} +$result = $user->getDriverRating($user_id); +if(mysqli_num_rows($result) > 0){ + while($row = mysqli_fetch_array($result)){ + $xml = $xml . '<rating>'. $row['driverRating'] .'</rating><votes>'. $row['votes'] .'</votes>'; + } +} else { + $xml = $xml . '<rating>0</rating><votes>0</votes>'; +} + $xml = $xml . '</user>'; -print $xml; \ No newline at end of file +print $xml; diff --git a/controller/register.php b/controller/register.php new file mode 100644 index 0000000000000000000000000000000000000000..5f3fa7c2a420ceb6a31589f3a2d8e66fc33ed06b --- /dev/null +++ b/controller/register.php @@ -0,0 +1,57 @@ +<?php +//TODO : Setelah submit redirect ke dashboard dengan variable ?id=..., check semua input type gaboleh salah + +//model +include "../model/user.php"; + +if(isset($_POST["username2check"])) { + $user = new User; + $username = $_POST["username2check"]; + $sqlcheck = $user->getUsername($username); + $usernameCheck = mysqli_num_rows($sqlcheck); + if($usernameCheck < 1) { + echo 'ok'; + exit(); + } else { + echo 'no'; + exit(); + } +} + +if(isset($_POST["email2check"])) { + $user = new User; + $email = $_POST["email2check"]; + $sqlcheck = $user->getEmail($email); + $emailCheck = mysqli_num_rows($sqlcheck); + if($emailCheck < 1) { + echo 'ok'; + exit(); + } else { + echo 'no'; + exit(); + } +} + +if(isset($_POST["register"])) { + $user = new User; + $name = $_POST['full-name']; + $username = $_POST['username']; + $email = $_POST['email']; + $password = $_POST['password']; + $confirmpass = $_POST['confirm-password']; + $phone = $_POST['phone']; + $isDriver = 0; + if(isset($_POST['is-driver'])) { + if($_POST['is-driver'] == 'on') { + $isDriver = 1; + } + } + + $user -> createUser($name,$username,$email,$password,$phone,$isDriver); + $id = 0; + $result = $user->getIdByUser($username); + while($row = mysqli_fetch_array($result)) { + $id = $row['id']; + } + header('Location: ../view/dashboard.php?id=' . $id); +} 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..f3c1d856b983f5151a20503507ac967b224bdcdc 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 { @@ -113,11 +115,15 @@ margin: 5px 0; } -#name { - font-size: 1.8rem; +#name, #driver, #email, #phone { + font-size: 1.3rem; + margin-bottom: 5px; } #email, #phone { - font-size: 1.5rem; display: inline-block; -} \ No newline at end of file +} +#user-location li { + font-size: 1.2rem; + margin-bottom: 5px; +} diff --git a/css/edit-profile.css b/css/edit-profile.css index fa449b248bde74e08b3f643ba1d32c2ac1a2b5e5..7f30f02f845a39baed0999c24254809a4e16c4e4 100644 --- a/css/edit-profile.css +++ b/css/edit-profile.css @@ -1,6 +1,3 @@ -.container { - width : 100%; -} .edit-image { font-size: 0; @@ -48,11 +45,63 @@ text-align: right; } -.checkbox input { - margin: 0; - transform: scale(1.5); - -ms-transform: scale(1.5); - -webkit-transform: scale(1.5); +.switch { + position: relative; + display: inline-block; + width: 60px; + height: 34px; +} + +.switch input { + display: none; +} + +.slider { + position: absolute; + cursor: pointer; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: #ccc; + -webkit-transition: .4s; + transition: .4s; +} + + +.slider:before { + position: absolute; + content: ""; + height: 26px; + width: 26px; + left: 4px; + bottom: 4px; + background-color: white; + -webkit-transition: .4s; + transition: .4s; +} + +input:checked + .slider { + background-color: #55D069; +} + +input:focus + .slider { + box-shadow: 0 0 1px #2196F3; +} + +input:checked + .slider:before { + -webkit-transform: translateX(26px); + -ms-transform: translateX(26px); + transform: translateX(26px); +} + + +.slider { + border-radius: 34px; +} + +.slider:before { + border-radius: 50%; } .back { 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 new file mode 100644 index 0000000000000000000000000000000000000000..4cc6eaa4e11489436fb4b2f5626928d0f2e606bd --- /dev/null +++ b/css/order.css @@ -0,0 +1,151 @@ +.order-progress { + text-align: center; +} +.select-destination, .select-driver, .complete-order { + display: inline-block; + width: 30%; + border: 1px solid #000; + height: auto; + margin: 0 8px; + padding: 10px; + box-sizing: border-box; +} +.counter { + margin-right: 15px; + display: inline-block; + border-radius: 1000px; + background-color: #DDDDDD; + height: 20px; + width: 20px; + padding: 8px; + vertical-align: middle; +} +.order-count { + background-color: yellow; +} +.first-page { + text-align: center; + margin: 20px 0 50px 0; + font-size: 1.2rem; +} +.input-box { + display: inline-block; + text-align: initial; + width: 80%; + font-weight: bold; + margin: 10px 0; +} +.input-box label { + width: 50%; + display: inline-block; +} +.input-box input { + width: 50%; + font-size: 1.2rem; +} +.next-page { + width: 100%; + text-align: center; +} +.next-page div { + display: inline-block; + background-color: #82D800; + padding: 8px 30px; + font-size: 2rem; + border-radius: 10px; + border: 1px solid #000; + cursor: pointer; +} +.second-page, .third-page { + display: none; +} +.driver-box { + margin: 15px 0; + padding: 10px; + border: 1px solid #000; + border-radius: 15px; +} +.driver-box h1 { + margin: 8px 0; +} +.error-message { + margin: 20px 0; + width: 100%; + text-align: center; + font-size: 1.5rem; + color: #999999; +} +.single-driver { + margin: 20px 0; + box-sizing: border-box; +} +.single-driver img { + display: inline-block; + width: 20%; + vertical-align: top; +} +.driver-bio { + display: inline-block; + width: 49%; + box-sizing: border-box; + padding: 10px; +} +.driver-name { + display: inline-block; + margin: 0; +} +.button-choose { + vertical-align: bottom; + display: inline-block; + width: 30%; +} +.button-choose div{ + cursor: pointer; + padding: 5px 20px; + float: right; + 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/css/register.css b/css/register.css index a97be55616e384bd49cb1e9a8342d7e2501d915b..ce5dc6cd7eb2f36a11e42324fef28538bbb1c0f5 100644 --- a/css/register.css +++ b/css/register.css @@ -64,11 +64,12 @@ .check-icon { width: 13px; + display : none; } .delete-icon { width: 13px; - display: none; + display: inline-block; } .checkbox { diff --git a/data/projekers.sql b/data/projekers.sql index c1bcb1256c936a2101ffd0b7c0fcbc8b72fd142f..a8763bbb4708ef5304cf82d5ec09c344502b2286 100644 --- a/data/projekers.sql +++ b/data/projekers.sql @@ -1,8 +1,8 @@ --- MySQL dump 10.13 Distrib 5.7.14, for Win64 (x86_64) +-- MySQL dump 10.16 Distrib 10.1.26-MariaDB, for Win32 (AMD64) -- -- Host: localhost Database: projekers -- ------------------------------------------------------ --- Server version 5.5.5-10.1.25-MariaDB +-- Server version 10.1.26-MariaDB /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -100,7 +100,7 @@ CREATE TABLE `user` ( LOCK TABLES `user` WRITE; /*!40000 ALTER TABLE `user` DISABLE KEYS */; -INSERT INTO `user` VALUES (1,'pikachu','Pikachu','pikachu@gmail.com','abc123','081812341234',0,'pikachu.jpg'),(2,'ratata','Ratata','ratata@gmail.com','12345678','081234563456',1,'ratata.png'),(3,'bulbasaur','Bulbasaur','bulbasaur@gmail.com','abcdefg','081209870987',1,'bulbasaur.png'),(4,'charmander','Charmander','charmander@gmail.com','lkjhlkjh','098812341234',0,'charmander.png'); +INSERT INTO `user` VALUES (1,'pikachu','Pikachu','pikachu@gmail.com','abc123','081812341234',0,'pikachu.jpg'),(2,'ratata','Ratata','ratata@gmail.com','12345678','081234563456',1,'ratata.png'),(3,'bulbasaur','Bulbasaur','bulbasaur@gmail.com','abcdefg','081209870987',1,'bulbasaur.png'),(4,'charmander','Charmander','charmander@gmail.com','lkjhlkjh','098812341234',0,'charmander.png'),(5,'gengar','Gengar','gengar@gmail.com','gengarsu','087782008321',1,'gengar.png'); /*!40000 ALTER TABLE `user` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -113,4 +113,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2017-10-01 1:30:46 +-- Dump completed on 2017-10-01 22:25:06 diff --git a/img/gengar.png b/img/gengar.png new file mode 100644 index 0000000000000000000000000000000000000000..c1054239f5d0d27ec1ba5ddc9eaf4e01003f1638 Binary files /dev/null and b/img/gengar.png differ diff --git a/js/edit-profile.js b/js/edit-profile.js index 316fe1ffa520b3656fb73cd2bcdbe281fd46c628..ccd524e712447623a3d8baa8f2a2835d724f3bb5 100644 --- a/js/edit-profile.js +++ b/js/edit-profile.js @@ -1,24 +1,50 @@ function getUserProfile() { + var id = sessionid; var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { var result = xmlhttp.responseXML; + var userid = result.getElementsByTagName('id')[0].childNodes[0].nodeValue; var name = result.getElementsByTagName('name')[0].childNodes[0].nodeValue; var phone = result.getElementsByTagName('phone')[0].childNodes[0].nodeValue; var driver = result.getElementsByTagName('driver')[0].childNodes[0].nodeValue; var image = result.getElementsByTagName('image')[0].childNodes[0].nodeValue; + document.getElementById('userid').value = userid; document.getElementById('name').value = name; document.getElementById('phone').value = phone; document.getElementById('image').src = '../img/' + image; document.getElementById('driver').checked = (driver == 1 ? true : false); } }; - xmlhttp.open('GET','../controller/edit-profile.php?id=1',true); + xmlhttp.open('GET','../controller/edit-profile.php?id=' + id,true); xmlhttp.send(); - } -function saveUserProfile() { +function checkAllInput() { + var name = document.editForm["name"]; + var phone = document.editForm["phone"]; + + //Check name + if(name.value == "") { + alert("Your name field must be filled!"); + return false; + } else if (name.value.length > 20) { + alert("Name must be 1-20 characters long!"); + return false; + } + //Check Phone + var regex = /^08([0-9]){1,}$/; + if(phone.value == "") { + alert("Phone number field must be filled!"); + return false; + } else if(phone.value.length < 9 || phone.value.length > 12 ) { + alert("Phone number must be 9-12 digits!"); + return false; + } + if(regex.test(phone.value) === false) { + alert("Phone number must be valid"); + return false; + } +} -} \ No newline at end of file diff --git a/js/order.js b/js/order.js new file mode 100644 index 0000000000000000000000000000000000000000..15f67bd84d01d6c5db95b58f08420dd03a857533 --- /dev/null +++ b/js/order.js @@ -0,0 +1,52 @@ +function nextPage () { + document.getElementsByClassName('first-page')[0].style.display = 'none'; + document.getElementsByClassName('second-page')[0].style.display = 'block'; + document.getElementsByClassName('select-destination')[0].classList.remove('order-count'); + document.getElementsByClassName('select-driver')[0].classList.add('order-count'); + document.getElementsByClassName('next-page')[0].style.display = 'none'; +} +function renderSingleDriver (image,name,rating) { + var imageElement = document.createElement('img'); + imageElement.setAttribute('src','../img/'+'image'); + + var nameElement = document.createElement('div'); + nameElement.classList.add('driver-name'); + nameElement.innerHTML = name; + + var result = document.createElement('div'); + result.appendChild(imageElement); + result.appendChild(nameElement); + return result; +} +function getDriver() { + var id = sessionid; + var xmlhttp = new XMLHttpRequest(); + //Check if user inserted preferred driver's name + var drivername = (document.getElementById('preferred-driver').value) ? document.getElementById('preferred-driver').value : null; + xmlhttp.onreadystatechange = function () { + if(xmlhttp.readyState == 4 && xmlhttp.status == 200){ + document.getElementsByClassName('second-page')[0].innerHTML = this.responseText; + } + }; + xmlhttp.open('GET','../controller/orderController.php?drivername='+drivername+'&id='+sessionid,true); + xmlhttp.send(); +} +function chooseDriver(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/js/profile.js b/js/profile.js index 8d0d1aba7dab7ba339d6d3a03d5797b03d95bdcd..d676fbd6dbe57dc5b1e855c247fa16353bc51659 100644 --- a/js/profile.js +++ b/js/profile.js @@ -4,11 +4,26 @@ function getUserProfile(){ xmlhttp.onreadystatechange = function () { if(xmlhttp.readyState == 4 && xmlhttp.status == 200){ var result = xmlhttp.responseXML; + //Get User's data var username = result.getElementsByTagName('username')[0].childNodes[0].nodeValue; var name = result.getElementsByTagName('name')[0].childNodes[0].nodeValue; var email = result.getElementsByTagName('email')[0].childNodes[0].nodeValue; var phone = result.getElementsByTagName('phone')[0].childNodes[0].nodeValue; - var image =result.getElementsByTagName('image')[0].childNodes[0].nodeValue; + var image = result.getElementsByTagName('image')[0].childNodes[0].nodeValue; + + //Get User Rating if user is a Driver + var isDriver = result.getElementsByTagName('driver')[0].childNodes[0].nodeValue; + var rating, votes = null; + if(isDriver == 1){ + rating = result.getElementsByTagName('rating')[0].childNodes[0].nodeValue; + votes = result.getElementsByTagName('votes')[0].childNodes[0].nodeValue; + document.getElementById('driver').innerHTML = 'Driver | ' + Math.round(rating) + ' ('+ votes +' votes)'; + } else { + document.getElementById('driver').innerHTML = 'Non-driver'; + } + + //Get User Location + var arrayLocation = result.getElementsByTagName('location'); document.getElementById('username').innerHTML = 'Hello, ' + name + '!'; document.getElementById('profile-username').innerHTML = '@' + username; @@ -16,6 +31,17 @@ function getUserProfile(){ document.getElementById('email').innerHTML = email; document.getElementById('phone').innerHTML = phone; document.getElementById('user-image').style.backgroundImage = 'url(../img/' + image + ')'; + var listOfLocation = document.getElementById('user-location'); + while(listOfLocation.hasChildNodes()){ + listOfLocation.removeChild(listOfLocation.lastChild); + } + for(i = 0; i < arrayLocation.length; i++){ + var loc = arrayLocation[i].firstChild.nodeValue; + var singleList = document.createElement('li'); + singleList.style.marginLeft = i*20; + singleList.innerHTML = loc; + listOfLocation.appendChild(singleList); + } } }; xmlhttp.open('GET', '../controller/profile.php?id=' + id, true); diff --git a/js/register.js b/js/register.js new file mode 100644 index 0000000000000000000000000000000000000000..1ee8fbe6cc903c41fb0aa1542f594680bcbfc247 --- /dev/null +++ b/js/register.js @@ -0,0 +1,105 @@ +function checkUsername() { + var u = document.getElementById("username").value; + if(u != "") { + var hr = new XMLHttpRequest(); + hr.open("POST", "../controller/register.php", true); + hr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); + hr.onreadystatechange = function () { + if(hr.readyState == 4 && hr.status == 200) { + var response = hr.responseText; + if(response == 'ok') { + document.getElementById("check-icon-username").style.display = 'inline-block'; + document.getElementById("delete-icon-username").style.display = 'none'; + } + if(response == 'no') { + document.getElementById("check-icon-username").style.display = 'none'; + document.getElementById("delete-icon-username").style.display = 'inline-block'; + + } + } + } + var v = "username2check=" + u; + hr.send(v); + } +} + +function checkEmail() { + var email = document.getElementById("email").value; + if(email != "") { + var hr = new XMLHttpRequest(); + hr.open("POST", "../controller/register.php", true); + hr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); + var regex = /^([A-Za-z0-9_\-\.]){1,}\@([A-Za-z0-9_\-\.]){1,}\.([A-Za-z]){2,4}$/; + hr.onreadystatechange = function () { + var response = hr.responseText; + if(response == 'ok' && regex.test(email) != false) { + document.getElementById("check-icon-email").style.display = 'inline-block'; + document.getElementById("delete-icon-email").style.display = 'none'; + } + if(response == 'no' || regex.test(email) == false) { + document.getElementById("check-icon-email").style.display = 'none'; + document.getElementById("delete-icon-email").style.display = 'inline-block'; + } + } + var v = "email2check=" + email; + hr.send(v); + } +} + +function checkAllInput() { + //Check Name + var name = document.registerForm["full-name"]; + var user = document.registerForm.username; + var email = document.registerForm.email; + var password = document.registerForm.password; + var confirmPassword = document.registerForm["confirm-password"]; + var phone = document.registerForm.phone; + //check Name + if(name.value == "") { + alert("Your name field must be filled!"); + return false; + } else if (name.value.length > 20) { + alert("Name must be 1-20 characters long!"); + return false; + } + //Check Username + if(user.value == "") { + alert("Username field must be filled!"); + return false; + } else if (user.value.length > 20) { + alert("Name must be 1-20 characters long!"); + return false; + } + //Check email + if(email.value == "") { + alert("Email field must be filled!"); + return false; + } + //Check password + if(password.value == "") { + alert("Password field must be filled!"); + return false; + } + //Check confirmPassword + if(confirmPassword.value == "") { + alert("Confirm Password field must be filled!"); + return false; + } + if(password.value != confirmPassword.value) { + alert("Password and Confirm Password field must be the same!"); + return false; + } + //Check Phone + var regex = /^08([0-9]){1,}$/; + if(phone.value == "") { + alert("Phone number field must be filled!"); + return false; + } else if(phone.value.length < 9 || phone.value.length > 12 ) { + alert("Phone number must be 9-12 digits!"); + return false; + } + if(regex.test(phone.value) === false) { + alert("Phone number must be valid"); + return false; + } +} \ No newline at end of file diff --git a/model/order.php b/model/order.php index 920e3c590909ed9d640d2e0b9c2eb52d7078802b..a2d2e1b7bcc2ce1f103cfb8028823d74a60031d3 100644 --- a/model/order.php +++ b/model/order.php @@ -9,4 +9,12 @@ 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, rating, comment, date) values('. + $userId.','.$driverId.',"'.$pickup.'","'.$destination.'",'.$rating.',"'.$comment.'","'.$transactionDate.'")'; + mysqli_query($con, $sql); + mysqli_close($con); + } } \ No newline at end of file diff --git a/model/user.php b/model/user.php index 8f69fea160e4e20021dde8cafa7b0ebc2c6b5ff9..c5d0ca53920041aca66d50bd617c4da1145cee92 100644 --- a/model/user.php +++ b/model/user.php @@ -27,23 +27,85 @@ class User { mysqli_close($con); return $result; } - - function getPrefLocById($id){ + + function getIdByUser($username) { $con = mysqli_connect('localhost','root','','projekers'); mysqli_select_db($con, 'projekers'); - $sql = "SELECT location FROM user WHERE id=" . $id; + $sql = "SELECT id FROM user WHERE username= '" . (string)$username . "'"; $result = mysqli_query($con, $sql); mysqli_close($con); return $result; - } - - function getIdByUsernamePassword($username, $password){ + } + + function updateProfileById($id, $name, $phone, $isDriver, $image) { + $con = mysqli_connect('localhost','root','','projekers'); + mysqli_select_db($con,'projekers'); + $sql = "update user set name='" . (string)$name . "', phone ='" . (string)$phone . "', isDriver='" . + $isDriver ."', image='" . (string)$image . "' where id=" . $id; + mysqli_query($con, $sql); + mysqli_close($con); + } + + function createUser($name, $username, $email, $password, $phone, $isDriver) { $con = mysqli_connect('localhost','root','','projekers'); mysqli_select_db($con, 'projekers'); - $sql = "SELECT id FROM user WHERE username=" . $username . " and password=" . $password; - $result = mysqli_query($con, $sql); + $image = "pikachu.jpg"; + $sql = "INSERT INTO user(username, name, email, password, phone, isDriver, image) VALUES('" . + (string)$username . "', '" . (string)$name . "', '" . (string)$email . "', '" . (string)$password. "', '" . + (string)$phone . "', " . $isDriver . ", '" . $image . "')"; + + mysqli_query($con,$sql); + mysqli_close($con); + } + + function getUsername($username) { + $con = mysqli_connect('localhost','root','','projekers'); + mysqli_select_db($con,'projekers'); + $query = "SELECT id FROM user WHERE username = '" . $username . "'"; + $result = mysqli_query($con,$query); + mysqli_close($con); + return $result; + } + + function getEmail($email) { + $con = mysqli_connect('localhost','root','','projekers'); + mysqli_select_db($con,'projekers'); + $query = "SELECT id FROM user WHERE email = '" . $email . "'"; + $result = mysqli_query($con,$query); mysqli_close($con); return $result; - - } + } + 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; + $result = mysqli_query($con,$query); + 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; + } + function getPreferredLocation($id){ + $con = mysqli_connect('localhost','root','','projekers'); + mysqli_select_db($con,'projekers'); + $query = "SELECT location FROM pref_loc WHERE id=" . $id; + $result = mysqli_query($con,$query); + mysqli_close($con); + return $result; + } + function getDriverRating($id){ + $con = mysqli_connect('localhost','root','','projekers'); + mysqli_select_db($con,'projekers'); + $query = "SELECT driver_id AS id, AVG(rating) AS driverRating, COUNT(rating) AS votes FROM transaction WHERE driver_id=" . $id . " GROUP BY(driver_id)"; + $result = mysqli_query($con,$query); + mysqli_close($con); + return $result; + } +>>>>>>> c2ae002b0ea1e89875f3cea9e97fbf6eeddd1b39 } \ No newline at end of file diff --git a/view/dashboard.php b/view/dashboard.php index 83f1f977c0d8a54a56720b3fa9d0c854ff927cf9..98c44fe2de75215571de6c94eacd9259b5d9f6b8 100644 --- a/view/dashboard.php +++ b/view/dashboard.php @@ -1,15 +1,10 @@ -<?php - session_start(); - $_SESSION['id'] = 1; - $_SESSION['name'] = 'Pikachu'; -?> - <html> <head> <title>User Dashboard</title> <link href="../css/primary.css" type="text/css" rel="stylesheet" /> <link href="../css/dashboard.css" type="text/css" rel="stylesheet" /> <link href="../css/history.css" type="text/css" rel="stylesheet" /> + <link href="../css/order.css" type="text/css" rel="stylesheet" /> <script> //send session id to JS files var sessionid = "<?php echo $_GET['id']; ?>"; @@ -17,6 +12,7 @@ <script src="../js/dashboard.js"></script> <script src="../js/profile.js"></script> <script src="../js/history.js"></script> + <script src="../js/order.js"></script> </head> <body onpageshow="getUserProfile()"> <div class="container"> @@ -28,24 +24,24 @@ </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"> + <?php include "order.php"; ?> </section> <section class="history-wrapper"> - <div id="content"></div> <div class="sub-header"> <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> @@ -53,27 +49,26 @@ <section class="profile-wrapper"> <div class="sub-header"> <div class="sub-header-heading"><h1>MY PROFILE</h1></div> - <div class="edit-icon"><img src="../img/pencil.png" /></div> + <div class="edit-icon"> + <a href="../view/edit-profile.php?id=<?php echo $_GET['id'] ?>"><img src="../img/pencil.png" /></a> + </div> </div> <div class="user-profile"> <div id="user-image"></div> <h1 id="profile-username"></h1> <div id="name"></div> + <div id="driver"></div> <div id="driver-stats"></div> <img src="../img/mail.png" /><div id="email"></div><br /> <img src="../img/phone.png" /><div id="phone"></div><br /> </div> <div class="sub-header"> <div class="sub-header-heading"><h1>PREFERRED LOCATION</h1></div> - <div class="edit-icon"><img src="../img/pencil.png" /></div> - </div> - <div class="user-location"> - <ul type="square" id="user-location"> - <li>a</li> - <li>b</li> - <li>c</li> - </ul> + <div class="edit-icon"> + <a href="../view/edit-prefered-locations.html"><img src="../img/pencil.png" /></a> + </div> </div> + <div class="user-location"><ul id="user-location"></ul></div> </section> </div> </body> diff --git a/view/edit-profile.html b/view/edit-profile.php similarity index 61% rename from view/edit-profile.html rename to view/edit-profile.php index b565018214884524baa362ef176d88b3e94de494..ffc32ccc0154b430eb599a5ad48fd6a5ba1c04a5 100644 --- a/view/edit-profile.html +++ b/view/edit-profile.php @@ -3,12 +3,17 @@ <title>Edit-profile</title> <link href="../css/primary.css" type="text/css" rel="stylesheet"> <link href="../css/edit-profile.css" type="text/css" rel="stylesheet"> + <script> + var sessionid = "<?php echo $_GET['id'];?>"; + </script> <script src="../js/edit-profile.js"></script> </head> -<body onpageshow="getUserProfile();"> +<body onload="getUserProfile();" onreset="getUserProfile()" onpageshow="getUserProfile()"> <div class="container"> <h1>EDIT PROFILE INFORMATION</h1> - <form action="#" method="post"> + <form enctype="multipart/form-data" action="../controller/edit-profile.php?id=<?php echo $_GET['id']?>" + method="post" id="form" name="editForm" onsubmit="return checkAllInput()"> + <input type="hidden" id="userid" value="<?php echo $_GET['id'];?>"> <div class="edit-image"> <div class="div-profile-image"> <img class="profile-image" id="image"> @@ -17,7 +22,7 @@ <label>Update profile picture</label> <br /> <br /> - <input type="file" name="image-file" value="browse.."> + <input type="file" name="image-file" value="browse.." id="image-file" onsubmit=""> </div> </div> <div> @@ -32,18 +37,19 @@ <div class="edit-data"> <label class="form-label">Status Driver</label> <div class="checkbox"> - <input type="checkbox" name="is-driver" id="driver"> + <label class="switch"> + <input type="checkbox" name="driver" id="driver"> + <span class="slider"></span> + </label> </div> </div> </div> - <div> <div> - <a class="back" href="dashboard.php">BACK</a> - <input type="submit" value="SAVE" class="save"> + <a class="back" href="dashboard.php?id=<?php echo $_GET['id'];?>">BACK</a> + <input type="submit" value="SAVE" class="save" name="submit"> </div> </div> - </form> </div> </body> diff --git a/view/order.php b/view/order.php new file mode 100644 index 0000000000000000000000000000000000000000..6507b6d63a9d2691f578bb2726954242476c6ec1 --- /dev/null +++ b/view/order.php @@ -0,0 +1,43 @@ +<div class="sub-header"> + <div class="sub-header-heading"><h1>MAKE AN ORDER</h1></div> +</div> +<div class="order-progress"> + <div class="select-destination order-count"><div class="counter">1</div>Select Destination</div> + <div class="select-driver"><div class="counter">2</div>Select Driver</div> + <div class="complete-order"><div class="counter">3</div>Complete Order</div> +</div> +<div> + <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"/> + </div> + <div class="input-box"> + <label>Destination</label><input type="text" name="destination" placeholder="Destination Point"/> + </div> + <div class="input-box"> + <label>Preferred Driver</label><input type="text" name="preferred-driver" id="preferred-driver" placeholder="(optional)" value=""/> + </div> + </div> + + <div class="next-page"><div id="next-page" onclick="nextPage(); getDriver();">NEXT</div></div> + + <div class="second-page"></div> + + <div class="third-page"> + <h1>HOW WAS IT?</h1> + <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> + + + </form> +</div> \ No newline at end of file diff --git a/view/register.html b/view/register.php similarity index 77% rename from view/register.html rename to view/register.php index f882b2bdf1dbff9230cc04c125a7ef1c7bd5ba87..06fb4f6afb27460e19ebcd58bde6cef9f5153b84 100644 --- a/view/register.html +++ b/view/register.php @@ -16,34 +16,39 @@ <br> <br> <div class="form-input"> - <form action="register.php" method="post"> + <form action="../controller/register.php" method="post" name="registerForm" onsubmit="return checkAllInput()"> <div class="user-input"> <div class="label-input">Your Name</label></div> - <div class="text-input"><input type="text" name="full-name" maxlength="20"></div> + <div class="text-input"><input type="text" name="full-name" id="full-name"></div> </div> <div class="user-input"> <div class="label-input">Username</label></div> - <div class="text-input-with-check"><input type="text" name="username" maxlength="20"></div> - <div><img src="../img/check.png" class="check-icon"></div> - <div><img src="../img/delete.png" class="delete-icon"></div> + <div class="text-input-with-check"><input type="text" name="username" id="username" + onchange="checkUsername()"> + </div> + <div><img src="../img/check.png" class="check-icon" id="check-icon-username"></div> + <div><img src="../img/delete.png" class="delete-icon" id="delete-icon-username"></div> </div> <div class="user-input"> <div class="label-input">Email</label></div> - <div class="text-input-with-check"><input type="text" name="email" maxlength="20"></div> - <div><img src="../img/check.png" class="check-icon"></div> - <div><img src="../img/delete.png" class="delete-icon"></div> + <div class="text-input-with-check"><input type="text" name="email" id="email" + onchange="checkEmail()"> + </div> + <span id="email-status"></span> + <div><img src="../img/check.png" class="check-icon" id="check-icon-email"></div> + <div><img src="../img/delete.png" class="delete-icon" id="delete-icon-email"></div> </div> <div class="user-input"> <div class="label-input">Password</label></div> - <div class="text-input"><input type="password" name="password" maxlength="20"></div> + <div class="text-input"><input type="password" name="password"></div> </div> <div class="user-input"> <div class="label-input">Confirm Password</label></div> - <div class="text-input"><input type="password" name="confirm-password" maxlength="20"></div> + <div class="text-input"><input type="password" name="confirm-password"></div> </div> <div class="user-input"> <div class="label-input">Phone Number</label></div> - <div class="text-input"><input type="text" name="phone" maxlength="11"></div> + <div class="text-input"><input type="text" name="phone"></div> </div> <br> <div class="checkbox">