diff --git a/src/css/fan.css b/src/css/fan.css index 8b3f0a61103de04534f2c34cf5b3efd957785e8f..5ab5a2be4770b32a53be3485a03ce7092286f7a0 100644 --- a/src/css/fan.css +++ b/src/css/fan.css @@ -3,7 +3,8 @@ } img { max-width: 100%; - height: auto; + height: 100%; + width: auto; } h1 { margin-top: 60px; @@ -204,6 +205,10 @@ nav ul li a.active { border: 1px solid grey; } .btn { + text-decoration: none; + color: black; + font-size: 14px; + font-family: Roboto; padding: 7px 17px; cursor: pointer; border-style: none; @@ -275,6 +280,32 @@ input:checked + .slider:before { width: 75%; } +/*.inputfile { + opacity: 0; + z-index: -1; +}*/ +/*.inputfile + label span { + width: 75%; + min-height: 26px; + margin-right: 5px; + display: inline-block; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; + vertical-align: top; + border: 1px solid #C8C8C8; +} + +.inputfile + label strong { + height: 100%; + color: black; + background-color: #D7D7D7; + display: inline-block; + padding: 3px 10px; + border: 1px solid #BBBBBB; + font-weight: normal; +}*/ + /* Status */ .status { font-size: 17px; diff --git a/src/css/fan2.css b/src/css/fan2.css index 3c912e1991bb899438ebead8057a66506aea16c0..f209c648af89ad73d801020ae417b61dbcaf938b 100644 --- a/src/css/fan2.css +++ b/src/css/fan2.css @@ -1,3 +1,6 @@ +h2 { + font-family: Oswald; +} /* Main Container */ .card { margin-top: 20px; @@ -120,8 +123,18 @@ /* Users */ #username { font-weight: bold; + font-size: 30px; +} +#fullname, #email, #phone { + font-size: 20px; +} +.rating { + color: #FE9926; +} +.pref-loc { + font-family: Oswald; + font-size: 26px; } - /* Floating */ .float-right { float: right; diff --git a/src/css/styles.css b/src/css/styles.css index ceb75af943845092cd019691791396c711249282..392aa2d297a9f6d30d90098939cd2caa82d7d6ce 100644 --- a/src/css/styles.css +++ b/src/css/styles.css @@ -236,3 +236,13 @@ input.form-control.validation { a:hover { cursor: pointer; } + +.invalid-text { + color: red; + font-weight: bold; + padding-left: 25px; +} + +.left-align { + text-align: left !important; +} \ No newline at end of file diff --git a/src/edit-prefered-location.php b/src/edit-prefered-location.php index 7d550790a08f7b81a3efe34e09cde0fbc87e259f..5d6914c928b1bcfc55c96c651b7067fd767d1d0a 100644 --- a/src/edit-prefered-location.php +++ b/src/edit-prefered-location.php @@ -17,7 +17,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST'){ if(mysqli_stmt_execute($stmt)){ echo 'sesuatu'; - header('location: '. htmlspecialchars($_SERVER["PHP_SELF"]) .'?id='. $_GET['id_active']); + header('location: '. htmlspecialchars($_SERVER["PHP_SELF"]) .'?id_active='. $_GET['id_active']); } else { echo 'gagal'; } @@ -128,7 +128,7 @@ if(mysqli_stmt_execute($stmt)){ <br> <h2>ADD NEW LOCATION:</h2> - <form class="form-inline" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']) .'?id='. $_GET['id_active'] . '&type=add';?>" onsubmit="return isFilled()" method="post"> + <form class="form-inline" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']) .'?id_active='. $_GET['id_active'] . '&type=add';?>" onsubmit="return isFilled()" method="post"> <input type="text" class="form-control loc" name="location" > <button type="submit" class="btn-css">ADD</button> diff --git a/src/edit-profile.php b/src/edit-profile.php index 4380192ed0fe5402a52f0de33f5ce27ed9b86aa7..e4daf658769e4089681be6b3aff13516ee999235 100644 --- a/src/edit-profile.php +++ b/src/edit-profile.php @@ -1,50 +1,87 @@ <!DOCTYPE html> +<?php + require_once 'dbconfig.php'; + + $sqlconn = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME); + if (!$sqlconn) { + die('mySQL connection failed'); + } + + // Menyiapkan statement SELECT + $sqlquery = 'SELECT username, fullname, email, phoneno, isdriver, avg_vote, n_voters, img_name FROM userinfo WHERE id=?'; + $stmt = mysqli_prepare($sqlconn, $sqlquery); + + // Bind variables + mysqli_stmt_bind_param($stmt, "i", $_GET['id_active']); + + if(mysqli_stmt_execute($stmt)){ + // Simpan Hasil query + mysqli_stmt_store_result($stmt); + // username exist + mysqli_stmt_bind_result($stmt, $username, $fullname, $email, $phoneno, $isdriver, $avg_vote, $n_voters, $img_name); + + mysqli_stmt_fetch($stmt); + } +?> <html> <head> <title>Edit Profile</title> <link rel="stylesheet" type="text/css" href="css/fan.css"> - <link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet"> + <link href="https://fonts.googleapis.com/css?family=Oswald|Roboto" rel="stylesheet"> </head> <body> <main class="container"> + <form action="update.php" method="post" enctype="multipart/form-data"> <h1 class="uppercase">Edit Profile Information</h1> <div class="row relative mb25"> <div class="col-4"> <div class="photo-container"> - <img src="img/foto-profil.jpg" class="vertical-center"> + <?php echo '<img class="border" src="img/' . $img_name . '" />' ?> </div> </div> <div class="col-8 vertical-center r0"> Update profile picture<br> - <form action="" method="post" class="photo-update"> - <input type="text" name="photo-url" class="col-9"> - <button class="btn-flat">Browse...</button> - </form> + <div class="photo-update"> + <input type="file" name="fileToUpload" id="fileToUpload" class="inputfile"> + <!-- <label for="file"><span></span><strong>Browse</strong></label> --> + </div> </div> </div> <div class="row"> <div class="col-4">Your Name</div> - <div class="col-8"><input type="text" name="name" class="w100"></div> + <div class="col-8"><input type="text" name="name" class="w100" value="<?php echo $fullname; ?>"></div> </div> <div class="row mt5"> <div class="col-4">Phone</div> - <div class="col-8"><input type="number" name="phone" class="w100"></div> + <div class="col-8"><input type="number" name="phone" class="w100" value="<?php echo $phoneno; ?>"></div> </div> <div class="row mt5"> <div class="col-4">Status Driver</div> <div class="col-8 right-align"> <!-- Rounded switch --> <label class="switch"> - <input type="checkbox"> + <?php + if ($isdriver == 1) { + echo '<input name="isdriver" type="checkbox" checked>'; + }else { + echo '<input name="isdriver" type="checkbox">'; + } + ?> <span class="slider round"></span> </label> </div> </div> + <input type="hidden" name="id_active" value="<?php echo $_GET['id_active'];?>"> + <input type="hidden" name="username" value="<?php echo $username;?>"> <div class="row mt25"> - <div class="col-6"><button class="btn red-bg uppercase">Back</button></div> - <div class="col-6 right-align"><button class="btn green-bg uppercase">Save</button></div> + <div class="col-6"><a href="profile.php?id_active=<?php echo $_GET['id_active'];?>" class="btn red-bg uppercase">Back</a></div> + <div class="col-6 right-align"><button type="submit" class="btn green-bg uppercase">Save</button></div> </div> + </form> </main> </body> </html> +<?php + +?> \ No newline at end of file diff --git a/src/img/cloud.png b/src/img/cloud.png new file mode 100644 index 0000000000000000000000000000000000000000..56671fc430146183fa2fc16b746011ce9857b5a4 Binary files /dev/null and b/src/img/cloud.png differ diff --git a/src/img/images.png b/src/img/images.png new file mode 100644 index 0000000000000000000000000000000000000000..97aecf78161a2b258fe1a7cf6b17062cfe718564 Binary files /dev/null and b/src/img/images.png differ diff --git a/src/js/fan.js b/src/js/fan.js index 277cae2b0167ea1d64d75ee64558936c40ef7fc5..a627e92a87e2fe92a26caa5e1c06ea6dc1beedc0 100644 --- a/src/js/fan.js +++ b/src/js/fan.js @@ -24,4 +24,31 @@ function openTab(evt, tabName) { function hide(id) { document.getElementById(id).style.display = "none"; -} \ No newline at end of file +} + + +//INPUT FILE +'use strict'; + +;( function ( document, window, index ) +{ + var inputs = document.querySelectorAll( '.inputfile' ); + Array.prototype.forEach.call( inputs, function( input ) + { + var label = input.nextElementSibling, + labelVal = label.innerHTML; + + input.addEventListener( 'change', function( e ) + { + + if( fileName ) + label.querySelector( 'span' ).innerHTML = fileName; + else + label.innerHTML = labelVal; + }); + + // Firefox bug fix + input.addEventListener( 'focus', function(){ input.classList.add( 'has-focus' ); }); + input.addEventListener( 'blur', function(){ input.classList.remove( 'has-focus' ); }); + }); +}( document, window, 0 )); \ No newline at end of file diff --git a/src/js/register.js b/src/js/register.js index d88dd16d2551b38b3ccf0d41c96611a10e4958f5..82fc6d1467f12be2a3fb14c8b728a1c65c54026c 100644 --- a/src/js/register.js +++ b/src/js/register.js @@ -1,5 +1,5 @@ function validate(field, str){ - if (str.length != 0){ + if (str.length != 0 && validateEmail(str)){ var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { @@ -21,7 +21,6 @@ function validate(field, str){ } else { document.getElementsByClassName('valid-status')[1].innerHTML = '<img class="stat-img" src="img/cross.png" >'; document.getElementsByClassName('valid-status')[1].alt = 'invalid'; - } return false; } @@ -92,3 +91,15 @@ function submitForm(){ console.log(req1, req2, req3); return verifyAll(req1, req2, req3); } + +function validateEmail(email) { + var x = email; + var atpos = x.indexOf("@"); + var dotpos = x.lastIndexOf("."); + if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) { + document.getElementsByClassName('valid-status')[1].innerHTML = '<img class="stat-img" src="img/cross.png" >'; + document.getElementsByClassName('valid-status')[1].alt = 'invalid'; + return false; + }else + return true; +} \ No newline at end of file diff --git a/src/login.php b/src/login.php index 24c8afdd430ec241fa4e7c63e4a9aae943539e24..2c1e117111c14a0463909c3dfc4c8e240934b56d 100644 --- a/src/login.php +++ b/src/login.php @@ -17,6 +17,7 @@ <input type="text" class="form-control" name="username" required> <label>Password</label> <input type="password" class="form-control" name="password" required><br><br> + <!-- <div class="invalid-text">Invalid username or password !</div> --> <button type="submit" name="login" >GO!</button> </form> <a class="signup-link" href="register.php">Don't have an account?</a> @@ -63,6 +64,8 @@ function authenticate($username, $password) { if (isset($_POST['login'])) { if ( $id = authenticate($_POST['username'], $_POST['password'])){ header('Location: profile.php?id_active='.$id); + }else{ + header('Location: login.php'); } } diff --git a/src/profile.php b/src/profile.php index 9e5ff5c393cd0de7a50ad809de5e069ef8285c83..35f2577b523e233fa52a3b2a40194a0f658d5bd9 100644 --- a/src/profile.php +++ b/src/profile.php @@ -25,6 +25,19 @@ require_once 'dbconfig.php'; mysqli_stmt_fetch($stmt); + /* PREFERED LOCATION */ + $query_prefloc = 'SELECT location FROM prefloc WHERE prefloc.id=?'; + $driver_prefloc = mysqli_prepare($sqlconn, $query_prefloc); + + // Bind variables + mysqli_stmt_bind_param($driver_prefloc, "i", $_GET["id_active"]); + + if(mysqli_stmt_execute($driver_prefloc)){ + // Simpan Hasil query + mysqli_stmt_store_result($driver_prefloc); + // username exist + mysqli_stmt_bind_result($driver_prefloc, $location); + } ?> <html> @@ -78,36 +91,37 @@ require_once 'dbconfig.php'; <?php echo $fullname?> </div> <?php if($isdriver) { - echo '<span id="isdriver">Driver</span><span >| → '. $avg_vote . '(' . $n_voters .')' . '</span>'; } + echo '<span id="isdriver">Driver</span> | <span class="rating">☆ <b>'. $avg_vote . '</b></span> (' . $n_voters .'votes)'; } else { echo '<span>Non-Driver</span>'; }?> <div id="email"> - <?php echo $email?> - + ✉ <?php echo $email?> </div> <div id="phone"> - <?php echo $phoneno?> + ☠<?php echo $phoneno?> </div> </div> - <div class="mtop10"> - <span class="font-header flexone">PREFERRED LOCATIONS</span> + <div class="mtop30"> + <span class="font-header flexone pref-loc">PREFERRED LOCATIONS</span> <a href="<?php echo 'edit-prefered-location.php?id_active='.$_GET['id_active']; ?>"><img class="mtop10 float-right editpic flexone" src="img/pencil.png" /></a> </div> <ul> - <li> - Pewter City - </li> - <li> - Saffron City - </li> - <li> - Skypillar tower - </li> + <?php + while (mysqli_stmt_fetch($driver_prefloc)) { + $list = ' + <li> + '.$location.' + </li> + '; + + echo $list; + } + ?> </ul> </div> diff --git a/src/update.php b/src/update.php new file mode 100644 index 0000000000000000000000000000000000000000..e9b404aed18ea6bbf18d83e0c94bb0b2a179e419 --- /dev/null +++ b/src/update.php @@ -0,0 +1,86 @@ +<?php +require_once 'dbconfig.php'; + +$sqlconn = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME); +if (!$sqlconn) { + die('mySQL connection failed'); +} + +$username = $_POST["username"]; + +if (isset($_FILES["fileToUpload"])){ + $target_dir = "img/"; + $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); + $uploadOk = 1; + $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); + // Check if image file is a actual image or fake image + if(isset($_POST["submit"])) { + $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); + if($check !== false) { + echo "File is an image - " . $check["mime"] . "."; + $uploadOk = 1; + } else { + echo "File is not an image."; + $uploadOk = 0; + } + } + if ($_FILES["fileToUpload"]["size"] > 500000) { + echo "Sorry, your file is too large."; + $uploadOk = 0; + } + // Allow certain file formats + if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" + && $imageFileType != "gif" ) { + echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; + $uploadOk = 0; + } + // Check if $uploadOk is set to 0 by an error + if ($uploadOk == 0) { + echo "Sorry, your file was not uploaded."; + // if everything is ok, try to upload file + } else { + if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { + echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; + $newphoto = basename( $_FILES["fileToUpload"]["name"]); + $sqlquery = "UPDATE userinfo SET img_name=? WHERE username=?"; + $stmt = mysqli_prepare($sqlconn, $sqlquery); + mysqli_stmt_bind_param($stmt, "ss", $newphoto, $username); + mysqli_stmt_execute($stmt); + } else { + echo "Sorry, there was an error uploading your file."; + } + } +} + +if (isset($_POST["name"])) { + $newname = $_POST["name"]; + $sqlquery = "UPDATE userinfo SET fullname=? WHERE username=?"; + $stmt = mysqli_prepare($sqlconn, $sqlquery); + mysqli_stmt_bind_param($stmt, "ss", $newname, $username); + mysqli_stmt_execute($stmt); +} + +if (isset($_POST["phone"])) { + $newphone = $_POST["phone"]; + $sqlquery = "UPDATE userinfo SET phoneno=? WHERE username=?"; + $stmt = mysqli_prepare($sqlconn, $sqlquery); + mysqli_stmt_bind_param($stmt, "ss", $newphone, $username); + mysqli_stmt_execute($stmt); +} + +if (isset($_POST["isdriver"])){ + $isdriver=1; + $sqlquery = "UPDATE userinfo SET isdriver=? WHERE username=?"; + $stmt = mysqli_prepare($sqlconn, $sqlquery); + mysqli_stmt_bind_param($stmt, "is", $isdriver, $username); + mysqli_stmt_execute($stmt); +}else { + $isdriver=0; + $sqlquery = "UPDATE userinfo SET isdriver=? WHERE username=?"; + $stmt = mysqli_prepare($sqlconn, $sqlquery); + mysqli_stmt_bind_param($stmt, "is", $isdriver, $username); + mysqli_stmt_execute($stmt); +} + +header('Location: profile.php?id_active=' . $_POST["id_active"]); +?> \ No newline at end of file