Commit a5e11433 authored by Erma Safira Nurmasyita's avatar Erma Safira Nurmasyita
Browse files
parents 6fcd3c1b 5351e874
......@@ -3,12 +3,12 @@
class fileProcessing {
public const PROFILE_DEFAULT = 'default.jpg';
public static function isExistBookImage (string $name): bool {
public static function isExistBookImage ($name): bool {
return file_exists('../images/books_picture/'.$name.'.jpg');
}
public static function isExistProfileImage (string $name): bool {
return file_exists($name);
public static function isExistProfileImage ($name): bool {
return file_exists('../uploads/'.$name);
}
public static function getImageBookPathFromRoot (string $name): string {
......
......@@ -80,6 +80,7 @@ button{
background-color: dodgerblue;
color: white;
border-radius: 4px;
border:none;
}
button:hover {
......
<?php
require_once ("../autoload.php");
function getUserProfile($id){
$conn = connect_to_mysql();
if ($conn !== NULL){
$sql_query = 'SELECT * FROM user where id = '.$id;
$result = $conn->query($sql_query);
$conn->close();
if ($result != NULL){
$row = $result->fetch_assoc();
return $row;
} else{
return [];
}
} else{
return [];
}
}
function setUserProfile($id,$name, $address, $phone, $pp, $tmp_pp){
$conn = connect_to_mysql();
if ($conn !== NULL){
$sql_query_name = 'UPDATE user SET name = "'.$name.'" WHERE id = '.$id;
$sql_query_address = 'UPDATE user SET address = "'.$address.'" WHERE id = '.$id;
$sql_query_phone = 'UPDATE user SET phone = "'.$phone.'" WHERE id = '.$id;
if (($name !== NULL) and ($name !== "")){
$result = $conn->query($sql_query_name);
}
if (($address !== NULL) and ($address !== "")){
$result = $conn->query($sql_query_address);
}
if (($phone !== NULL) and ($phone !== "")){
$result = $conn->query($sql_query_phone);
}
$upload_dir = "../uploads/";
if ($pp != NULL){
$upload_file_name = $upload_dir.$pp;
if (file_exists($upload_file_name)){
$sql_query_picture = 'UPDATE user SET profile_picture = "'.$upload_dir.$pp.'" WHERE id = '.$id;
$result = $conn->query($sql_query_picture);
} else if (move_uploaded_file($tmp_pp, $upload_dir.$pp)){
$sql_query_picture = 'UPDATE user SET profile_picture = "'.$upload_dir.$pp.'" WHERE id = '.$id;
$result = $conn->query($sql_query_picture);
}
}
return 1;
} else{
return 0;
}
}
<?php
require_once ("../autoload.php");
function getUserProfile($id){
$conn = connect_to_mysql();
if ($conn !== NULL){
$sql_query = 'SELECT * FROM user where id = '.$id;
$result = $conn->query($sql_query);
$conn->close();
if ($result != NULL){
$row = $result->fetch_assoc();
return $row;
} else{
return [];
}
} else{
return [];
}
}
function setUserProfile($id,$name, $address, $phone, $pp, $tmp_pp){
$conn = connect_to_mysql();
if ($conn !== NULL){
$sql_query_name = 'UPDATE user SET name = "'.$name.'" WHERE id = '.$id;
$sql_query_address = 'UPDATE user SET address = "'.$address.'" WHERE id = '.$id;
$sql_query_phone = 'UPDATE user SET phone = "'.$phone.'" WHERE id = '.$id;
if (($name !== NULL) and ($name !== "")){
$result = $conn->query($sql_query_name);
}
if (($address !== NULL) and ($address !== "")){
$result = $conn->query($sql_query_address);
}
if (($phone !== NULL) and ($phone !== "")){
$result = $conn->query($sql_query_phone);
}
$upload_dir = "../uploads/";
if ($pp != NULL){
$upload_file_name = $upload_dir.$pp;
if (file_exists($upload_file_name)){
$sql_query_picture = 'UPDATE user SET profile_picture = "'.$pp.'" WHERE id = '.$id;
$result = $conn->query($sql_query_picture);
} else if (move_uploaded_file($tmp_pp, $upload_dir.$pp)){
$sql_query_picture = 'UPDATE user SET profile_picture = "'.$pp.'" WHERE id = '.$id;
$result = $conn->query($sql_query_picture);
}
}
return 1;
} else{
return 0;
}
}
?>
\ No newline at end of file
<?php
require_once ("../autoload.php");
require_once("controller.php");
$user_token = $_COOKIE["login"];
$user_id = getUserIDbyToken($user_token);
echo "MASUK";
$update_name = $_POST["name"];
$update_address = $_POST["address"];
$update_phone = $_POST["phone"];
if (isset($_POST['submit'])){
// echo "MASUK SINI";
if(isset($_FILES["profile_picture"])){
$name = $_FILES["profile_picture"]["name"];
$tmp_name = $_FILES["profile_picture"]["tmp_name"];
} else{
$name = NULL;
$tmp_name = NULL;
}
} else{
$name = NULL;
$tmp_name = NULL;
}
// echo $update_name;
$update = setUserProfile($user_id, $update_name, $update_address, $update_phone, $name, $tmp_name);
// if ($update == 0){
// echo "<script type='text/javascript'>alert 'Update Failed';</script>";
// } else{
// echo "<script type='text/javascript'>alert 'Update Success';</script>";
// }
header('Location: ../profile');
exit;
<?php
require_once ("../autoload.php");
require_once("controller.php");
$user_token = $_COOKIE["login"];
$user_id = getUserIDbyToken($user_token);
echo "MASUK";
$update_name = $_POST["name"];
$update_address = $_POST["address"];
$update_phone = $_POST["phone"];
if (isset($_POST['submit'])){
// echo "MASUK SINI";
if(isset($_FILES["profile_picture"])){
$name = $_FILES["profile_picture"]["name"];
$tmp_name = $_FILES["profile_picture"]["tmp_name"];
} else{
$name = NULL;
$tmp_name = NULL;
}
} else{
$name = NULL;
$tmp_name = NULL;
}
// echo $update_name;
$update = setUserProfile($user_id, $update_name, $update_address, $update_phone, $name, $tmp_name);
// if ($update == 0){
// echo "<script type='text/javascript'>alert 'Update Failed';</script>";
// } else{
// echo "<script type='text/javascript'>alert 'Update Success';</script>";
// }
header('Location: ../profile');
exit;
?>
\ No newline at end of file
<?php
require_once ("../autoload.php");
$edit = "view.php";
$login = "../login/index.php";
if (isLogin()){
include ($edit);
} else{
header("Location: ../login");
}
<?php
require_once ("../autoload.php");
$edit = "view.php";
$login = "../login/index.php";
if (isLogin()){
include ($edit);
} else{
header("Location: ../login");
}
?>
\ No newline at end of file
......@@ -43,7 +43,7 @@
echo "<input id=\"profpict_dummy\" class=\"profpict_dummy\"type=\"text\" name=\"profile_picture2\" readonly>" ;
echo "<div class=\"upload-btn-wrapper\">" ;
echo "<button class=\"btn\">Browse ...</button>" ;
echo "<input id=\"profpict\" type=\"file\" name=\"profile_picture\" onchange=\"showname()\" >" ;
echo "<input id=\"profpict\" type=\"file\" name=\"profile_picture\" accept=\"image/png, image/jpg, image/jpeg\" onchange=\"showname()\" >" ;
echo "</div>" ;
echo "</div>" ;
echo "</div>" ;
......
......@@ -8,7 +8,7 @@ function viewProfile (array $params) {
<div class="flex-profile-header">
<div class="flex-1"></div>
<div class="flex-2">
<img class="profile-photo margin-20" src="'.$params['profile_picture'].'">
<img class="profile-photo margin-20" src="/uploads/'.$params['profile_picture'].'">
<div id="username" class="text-size-50">'.$params['name'].'</div>
</div>
<a class="flex-container add-flex-end-justify flex-1 " href="edit_profile">
......
......@@ -64,7 +64,7 @@
</div>
</div>
<div class="button_row">
<button type="button" onclick="location.href=\'../book_detail?id='.$id.'\';">Detail</button>
<button type="button" class="text-size-30 add-nunito-font light-blue c-round" onclick="location.href=\'../book_detail?id='.$id.'\';">Detail</button>
</div>
';
$i += 1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment