Commit 5b0b28fa authored by Wildan Dicky Alnatara's avatar Wildan Dicky Alnatara
Browse files

bug fixing fileprocessing class

parent 4c186da6
......@@ -8,7 +8,7 @@ class fileProcessing {
}
public static function isExistProfileImage ($name): bool {
return file_exists('../uploads/'.$name.'.jpg');
return file_exists('../uploads/'.$name);
}
public static function getImageBookPathFromRoot (string $name): string {
......
<?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;
}
}
<?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
<?php
require_once ("../autoload.php");
include("controller.php");
// echo $_COOKIE["login"];
if (!isset($_COOKIE["login"])){
// echo "TAK";
$user_token = NULL;
} else{
$user_token = $_COOKIE["login"];
}
//user ada
if ($user_token != NULL){
$user_id = getUserIDbyToken($user_token);
} else{
$user_id = 0;
}
echo "<html>";
echo Header::generateHeadWithJS("edit_profile", "edit_profile", "edit_profile");
echo Header::headerLogin(getUsername($user_token));
echo Header::headerMenu(Header::PROFILE);
$user_profile = getUserProfile($user_id);
$user_pp = $user_profile['profile_picture'];
$user_name = $user_profile['name'];
$user_address = $user_profile['address'];
$user_phone = $user_profile['phone'];
echo "<body onload=\"def = getDefault();\">";
echo '<form action="../edit_profile/edit_profile.php" enctype="multipart/form-data" onsubmit="return (validateForm())"method = "POST">' ;
echo "<div class=\"cols\">" ;
echo "<h1>Edit Profile</h1>" ;
echo "<div class = \"rows1\">" ;
echo "<div class=\"left\">" ;
echo "<img class=\"pp\" src=\"../uploads/$user_pp\" alt=\"Profile Picture\">" ;
echo "</div>";
echo "<div class=\"right\">" ;
echo "<p>Update profile picture</p>" ;
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 "</div>" ;
echo "</div>" ;
echo "</div>" ;
echo "<div class=\"rows2\">" ;
echo "<p class=\"left2\">Name</p>" ;
echo "<div class=\"right2\">" ;
echo '<p id="warning-1" class="red-theme alert-box text-size-20 add-nunito-font c-round">Input can\'t be empty</p>';
echo "<input type=\"text\" id = \"name\" name=\"name\" value=\"$user_name\">" ;
echo "</div>" ;
echo "</div>" ;
echo "<div class=\"rows\">" ;
echo "<p class=\"left2\">Address</p>" ;
echo "<div class=\"right2\">" ;
echo '<p id="warning-2" class="red-theme alert-box text-size-20 add-nunito-font c-round">Input can\'t be empty</p>';
echo "<textarea name=\"address\" id = \"address\" rows=\"5\" cols=\"1\">$user_address</textarea>" ;
echo "</div>" ;
echo "</div>" ;
echo "<div class=\"rows2\">" ;
echo "<p class=\"left2\">Phone number</p>" ;
echo "<div class=\"right2\">" ;
echo '<p id="warning-3" class="red-theme alert-box text-size-20 add-nunito-font c-round">Input can\'t be empty</p>';
echo "<input type=\"text\" id = \"phone\" name=\"phone\" value=\"$user_phone\">" ;
echo "</div>" ;
echo "</div>" ;
echo "</div>" ;
echo "<div class=\"row_button\">";
echo "<div class=\"left_button\">";
echo "<button id=\"back\" type=\"button\" name=\"back\" value=\"BACK\" onclick=\"location.href = '../profile'\">Back</button>";
echo "</div>";
echo "<div class=\"right_button\">";
echo "<input id=\"submit\" type=\"submit\" name = \"submit\"value =\"SAVE\">";
echo "</div>";
echo "</div>";
echo "</form>" ;
echo "</body>";
echo "</html>";
?>
<?php
require_once ("../autoload.php");
include("controller.php");
// echo $_COOKIE["login"];
if (!isset($_COOKIE["login"])){
// echo "TAK";
$user_token = NULL;
} else{
$user_token = $_COOKIE["login"];
}
//user ada
if ($user_token != NULL){
$user_id = getUserIDbyToken($user_token);
} else{
$user_id = 0;
}
echo "<html>";
echo Header::generateHeadWithJS("edit_profile", "edit_profile", "edit_profile");
echo Header::headerLogin(getUsername($user_token));
echo Header::headerMenu(Header::PROFILE);
$user_profile = getUserProfile($user_id);
$user_pp = $user_profile['profile_picture'];
$user_name = $user_profile['name'];
$user_address = $user_profile['address'];
$user_phone = $user_profile['phone'];
echo "<body onload=\"def = getDefault();\">";
echo '<form action="edit_profile/edit_profile.php" enctype="multipart/form-data" onsubmit="return (validateForm())"method = "POST">' ;
echo "<div class=\"cols\">" ;
echo "<h1>Edit Profile</h1>" ;
echo "<div class = \"rows1\">" ;
echo "<div class=\"left\">" ;
echo "<img class=\"pp\" src=\"../uploads/$user_pp\" alt=\"Profile Picture\">" ;
echo "</div>";
echo "<div class=\"right\">" ;
echo "<p>Update profile picture</p>" ;
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 "</div>" ;
echo "</div>" ;
echo "</div>" ;
echo "<div class=\"rows2\">" ;
echo "<p class=\"left2\">Name</p>" ;
echo "<div class=\"right2\">" ;
echo '<p id="warning-1" class="red-theme alert-box text-size-20 add-nunito-font c-round">Input can\'t be empty</p>';
echo "<input type=\"text\" id = \"name\" name=\"name\" value=\"$user_name\">" ;
echo "</div>" ;
echo "</div>" ;
echo "<div class=\"rows\">" ;
echo "<p class=\"left2\">Address</p>" ;
echo "<div class=\"right2\">" ;
echo '<p id="warning-2" class="red-theme alert-box text-size-20 add-nunito-font c-round">Input can\'t be empty</p>';
echo "<textarea name=\"address\" id = \"address\" rows=\"5\" cols=\"1\">$user_address</textarea>" ;
echo "</div>" ;
echo "</div>" ;
echo "<div class=\"rows2\">" ;
echo "<p class=\"left2\">Phone number</p>" ;
echo "<div class=\"right2\">" ;
echo '<p id="warning-3" class="red-theme alert-box text-size-20 add-nunito-font c-round">Input can\'t be empty</p>';
echo "<input type=\"text\" id = \"phone\" name=\"phone\" value=\"$user_phone\">" ;
echo "</div>" ;
echo "</div>" ;
echo "</div>" ;
echo "<div class=\"row_button\">";
echo "<div class=\"left_button\">";
echo "<button id=\"back\" type=\"button\" name=\"back\" value=\"BACK\" onclick=\"location.href = '../profile'\">Back</button>";
echo "</div>";
echo "<div class=\"right_button\">";
echo "<input id=\"submit\" type=\"submit\" name = \"submit\"value =\"SAVE\">";
echo "</div>";
echo "</div>";
echo "</form>" ;
echo "</body>";
echo "</html>";
?>
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