diff --git a/views/css/application.css b/views/css/application.css index 50a79dc030f5baced2ab3c3d56e32c51591d56bd..5618223d46eb382c6527d643d305f9508b8cc6e1 100644 --- a/views/css/application.css +++ b/views/css/application.css @@ -29,6 +29,7 @@ body { .description { margin-left: 10px; + margin-top: 10px; } .left { @@ -102,6 +103,7 @@ h1{ margin: 0; font-family: 'Nunito', sans-serif; font-size: 16px; + margin-top: 50px; font-weight: normal; color: #4d4d4d; } @@ -397,7 +399,7 @@ textarea { input { width: 384px; margin-right: 0; - margin-top: 20px; + margin-top: 12px; } .profile-picture { @@ -488,6 +490,8 @@ input { #profile-address { width: 385px; + padding-left: 10px; + font-size: small; } /*Book-Detail*/ .book-detail{ @@ -644,4 +648,4 @@ input { .nunito-reviews { font-family: 'Nunito', sans-serif; color: #0e0168; -} \ No newline at end of file +} diff --git a/views/edit_profile.php b/views/edit_profile.php index b718ced7373e83be48413fd57344c5076c9887d4..77c40843ddb062f69919e78ea4cabd67c3857a8f 100644 --- a/views/edit_profile.php +++ b/views/edit_profile.php @@ -19,62 +19,66 @@ if (isset($_COOKIE['access_token'])) { <link rel="stylesheet" href="css/navbar.css"> <title>Edit Profile | Pro-Book</title> </head> +<?php + include 'include/data.php'; +?> + <body> <?php include 'navbar.php'; ?> <div class="container"> <div class="desc"> <div class="inline"> - <h1 class="edit-p">Edit Profile</h1> + <h1 class="edit-p">Edit Profile</h1> </div> <div class="book-item inline"> - <form class="form-container" method="post" action="search_result.php"> - <img src="../img/book.jpg" class="pp-img left pp-img-frame"> - <div class="inline description left"> - <br> - <br> - <br> - <br> - <p class="author">Update Profile Picture</p> - <input type="text" id="fname" name="fname"> + <form class="form-container" method="POST" action="update_db.php" enctype="multipart/form-data"> + <img class="pp-img left pp-img-frame" src= + <?php + echo "\"".$pic_path."\"" + ?>> + <div class="inline description left"> + + <p class="author">Update Profile Picture</p> + <input class="nunito" type="text" id="fname" name="fname" value="<?php echo($row['image']) ?>"> + <div class="inline description right"> + <input id="profpic" name="profpic" id="profpic" type="file" class="browse-button"> + <button type="button" class="button-detail" onclick="document.getElementById('profpic').click()">Browse ...</button> </div> - <br> - <br> - <br> - <br> - <br> - <br> - <input id="profpic" name="fileToUpload" type="file" class="browse-button"> - <button type="button" class="button-detail" onclick="document.getElementById('profpic').click()">Browse ...</button> - </form> - </div> + </div> + <div class="bg"> - <form class="form-container" method="post" action="include/regist.php"> - <div class="bg"></div> + </div> <div class="pp-container"> - <div class="pp-input-element arial"> + <div class="pp-input-element nunito"> <label for="name">Name</label> - <input type="text" class="validate name-margin" name="name" ><br> + <input type="text" class="validate name-margin nunito" name="name" value="<?php echo($row['name']) ?>"><br> </div> - <div class="pp-input-element arial"> + + <div class="pp-input-element nunito"> <label for="address" style="vertical-align: top;">Address</label> - <textarea rows="4" class="validate address-margin" id="profile-address" name="address"></textarea> + <textarea rows="4" class="validate address-margin nunito" id="profile-address" name="address"><?php echo($row['address']) ?></textarea> </div> - <div class="pp-input-element arial"> + + <div class="pp-input-element nunito"> <label for="phone_number">Phone Number</label> - <input type="text" class="validate phone-margin" name="phone_number" id="phone_number" onchange="checkPhonePattern()"><br> + <input type="text" class="validate phone-margin nunito" name="phone_number" value="<?php echo($row['phone_number']) ?>" id="phone_number" onchange="checkPhonePattern()"><br> </div> - </div> - </form> - <button class="button back-button">Back</button> - <button class="button save-button">Save</button> + </div><br> + <button class="button back-button" id="b-button">Back</button> + <button class="button save-button">Save</button> + </form> + </div> </div> </div> </body> -======= - * User: secret - * Date: 21/10/18 - * Time: 17:49 - */ ->>>>>>> Stashed changes + +<script> + + document.getElementById("b-button").addEventListener("click", function(e){ + e.preventDefault(); + window.history.back(); + }) + +</script> diff --git a/views/include/data.php b/views/include/data.php new file mode 100644 index 0000000000000000000000000000000000000000..ee91e441968566d5f9fea15c81e089a6be34df36 --- /dev/null +++ b/views/include/data.php @@ -0,0 +1,38 @@ +<?php +/** + * Created by PhpStorm. + * User: Albert's PC + * Date: 10/26/2018 + * Time: 1:00 PM + */ + + $servername = "localhost"; + $uname = "root"; + $pass = ""; + $myDB = "probookdb"; + + try { + $conn = new PDO("mysql:host=$servername;dbname=$myDB", $uname, $pass); + + $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + $query = "SELECT * FROM user WHERE ID = \"" . $_COOKIE['ID'] . "\""; + + + $stmt = $conn->prepare($query); + + $stmt->execute(); + $row = $stmt->fetchAll(); + foreach ($row as $item) { + $name = $item["name"]; + $email = $item["email"]; + $phone = $item["phone_number"]; + $address = $item["address"]; + $pic_path = $item["image"]; + } + } + catch(PDOException $e) + { + echo "Connection failed: " . $e->getMessage(); + } +?> \ No newline at end of file diff --git a/views/update_db.php b/views/update_db.php new file mode 100644 index 0000000000000000000000000000000000000000..33065e8113abc2eeca369a6af6e1a68230c8f0d3 --- /dev/null +++ b/views/update_db.php @@ -0,0 +1,45 @@ +<?php +/** + * Created by PhpStorm. + * User: Albert's PC + * Date: 10/26/2018 + * Time: 9:13 AM + */ +$name = $_POST['name']; +$address = $_POST['address']; +$phone_number = $_POST['phone_number']; +$ID = $_COOKIE['ID']; + +$server = "localhost"; +$db_username = "root"; +$password = ""; +$myDB = "probookdb"; + +echo $_FILES["profpic"]["name"]; +if ($_FILES["profpic"]["name"]){ + require "upload.php"; +} + +try { + $conn = new PDO("mysql:host=$server;dbname=$myDB", $db_username, $password); + $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + if ($renamed){ + $query = "UPDATE user SET name = '$name', address = '$address', phone_number = '$phone_number', image = '$renamed' WHERE (ID = '$ID')"; + } else { + $query = "UPDATE user SET name = '$name', address = '$address', phone_number = '$phone_number' WHERE (ID = '$ID')"; + } + + $stmt = $conn->prepare($query); + + $stmt->execute(); + + header( 'Location: my_profile.php'); + die(); + +} +catch(PDOException $e) +{ + echo "<title>error</title>Error: " . $e->getMessage(); +} +?> diff --git a/views/upload.php b/views/upload.php index 33a5a42a8d846b05a336b6414515929eb66650a4..6d386815bd7607044a7dc92bb0b814e5df3d4b6b 100644 --- a/views/upload.php +++ b/views/upload.php @@ -5,14 +5,16 @@ * Date: 10/25/2018 * Time: 1:22 PM */ -$target_dir = "../profpic/"; -$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); -$renamed = $target_dir.$_COOKIE['nameofuser'].".jpg"; //sesuaiin sama db +$target_dir = "../img/profpic/"; +$target_file = $target_dir.$_COOKIE["ID"].".jpg"; +echo $_FILES["profpic"]["name"]; + +$renamed = $target_dir.$_COOKIE['ID'].".jpg"; $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); if(isset($_POST["submit"])) { - $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); + $check = getimagesize($_FILES["profpic"]["tmp_name"]); if($check !== false) { echo "File adalah gambar - " . $check["mime"] . "."; $uploadOk = 1; @@ -22,12 +24,7 @@ if(isset($_POST["submit"])) { } } -if (file_exists($target_file)) { - echo "Upload foto profil lain!"; - $uploadOk = 0; -} - -if ($_FILES["fileToUpload"]["size"] > 500000000) { +if ($_FILES["profpic"]["size"] > 500000000) { echo "Ukuran file terlalu besar!"; $uploadOk = 0; } @@ -42,8 +39,12 @@ if ($uploadOk == 0) { echo "Foto profil tidak dapat diupload."; } else { - if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { - echo "Gambar ". basename( $_FILES["fileToUpload"]["name"]). " sudah berhasil diupload."; + if(file_exists($target_file)) { + chmod($target_file,0755); //Change the file permissions if allowed + unlink($target_file); //remove the file + } + if (move_uploaded_file($_FILES["profpic"]["tmp_name"], $target_file)) { + echo "Gambar ". basename( $_FILES["profpic"]["name"]). " sudah berhasil diupload."; } else { echo "Ulangi upload foto profil!"; }