v2
This commit is contained in:
@@ -1,10 +1,5 @@
|
||||
<?php
|
||||
session_start();
|
||||
// Check if user is logged in and is admin
|
||||
// if (!isset($_SESSION['type']) || $_SESSION['type'] !== 'admin') {
|
||||
// header("Location: login.php");
|
||||
// exit();
|
||||
// }
|
||||
|
||||
// Database connection
|
||||
$conn = new mysqli($GLOBALS['host'], $GLOBALS['user'], $GLOBALS['pass'], $GLOBALS['db']);
|
||||
@@ -37,6 +32,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$user_phone = $_POST['user_phone'];
|
||||
$type = $_POST['type'];
|
||||
$user_id = $_POST['user_id'];
|
||||
$profilePicPath = $user['profile_pic']; // default old pic
|
||||
|
||||
// Validate inputs
|
||||
if (empty($user_name) || empty($user_phone) || empty($user_id)) {
|
||||
@@ -44,29 +40,40 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
} elseif (!preg_match("/^[0-9]{10}$/", $user_phone)) {
|
||||
$error = "Invalid phone number format";
|
||||
} else {
|
||||
// --- Handle Profile Picture Upload ---
|
||||
if (isset($_FILES['profile_pic']) && $_FILES['profile_pic']['error'] === UPLOAD_ERR_OK) {
|
||||
$uploadDir = __DIR__ . "/picture/";
|
||||
if (!file_exists($uploadDir)) {
|
||||
mkdir($uploadDir, 0777, true);
|
||||
}
|
||||
$fileTmp = $_FILES['profile_pic']['tmp_name'];
|
||||
$fileName = time() . "_" . basename($_FILES['profile_pic']['name']);
|
||||
$filePath = $uploadDir . $fileName;
|
||||
|
||||
if (move_uploaded_file($fileTmp, $filePath)) {
|
||||
$profilePicPath = "/picture/" . $fileName;
|
||||
|
||||
// পুরনো ফাইল ডিলিট (যদি থাকে)
|
||||
if (!empty($user['profile_pic']) && file_exists(__DIR__ . "/" . $user['profile_pic'])) {
|
||||
unlink(__DIR__ . "/" . $user['profile_pic']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update query
|
||||
if (!empty($_POST['password'])) {
|
||||
// Update with password
|
||||
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
|
||||
$sql = "UPDATE `".$GLOBALS['arif_users']."` SET
|
||||
user_id = ?,
|
||||
user_name = ?,
|
||||
user_phone = ?,
|
||||
type = ?,
|
||||
password = ?
|
||||
$sql = "UPDATE `".$GLOBALS['arif_users']."`
|
||||
SET user_id = ?, user_name = ?, user_phone = ?, type = ?, password = ?, profile_pic = ?
|
||||
WHERE id = ?";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bind_param("sssssi", $user_id, $user_name, $user_phone, $type, $password, $id);
|
||||
$stmt->bind_param("ssssssi", $user_id, $user_name, $user_phone, $type, $password, $profilePicPath, $id);
|
||||
} else {
|
||||
// Update without password
|
||||
$sql = "UPDATE `".$GLOBALS['arif_users']."` SET
|
||||
user_id = ?,
|
||||
user_name = ?,
|
||||
user_phone = ?,
|
||||
type = ?
|
||||
$sql = "UPDATE `".$GLOBALS['arif_users']."`
|
||||
SET user_id = ?, user_name = ?, user_phone = ?, type = ?, profile_pic = ?
|
||||
WHERE id = ?";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->bind_param("ssssi", $user_id, $user_name, $user_phone, $type, $id);
|
||||
$stmt->bind_param("sssssi", $user_id, $user_name, $user_phone, $type, $profilePicPath, $id);
|
||||
}
|
||||
|
||||
if ($stmt->execute()) {
|
||||
@@ -99,7 +106,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($user)): ?>
|
||||
<form method="post">
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<input type="hidden" name="id" value="<?php echo htmlspecialchars($user['id']); ?>">
|
||||
|
||||
<div class="row">
|
||||
@@ -114,6 +121,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
<input type="text" class="form-control" id="user_name" name="user_name"
|
||||
value="<?php echo htmlspecialchars($user['user_name']); ?>" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label for="profile_pic" class="form-label">Profile Picture</label><br>
|
||||
<?php if (!empty($user['profile_pic'])): ?>
|
||||
<img src="/CONTENT/ROOT_URI/Admin/<?php echo htmlspecialchars($user['profile_pic']); ?>" width="80" height="80" style="border-radius:50%; margin-bottom:10px;"><br>
|
||||
<?php endif; ?>
|
||||
<input type="file" class="form-control" id="profile_pic" name="profile_pic" accept="image/*">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
@@ -133,21 +148,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="form-group mb-3">
|
||||
<label for="password" class="form-label">New Password (leave blank to keep current)</label>
|
||||
<input type="password" class="form-control" id="password" name="password">
|
||||
<small class="text-muted">Password must be at least 8 characters long</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<label for="password" class="form-label">New Password (leave blank to keep current)</label>
|
||||
<input type="password" class="form-control" id="password" name="password">
|
||||
<small class="text-muted">Password must be at least 8 characters long</small>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<button type="submit" class="btn btn-primary">Update User</button>
|
||||
<a href="/Admin/Settings_Agent" class="btn ">Cancel</a>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<button type="submit" class="btn btn-primary">Update User</button>
|
||||
<a href="/Admin/Settings_Agent" class="btn">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
@@ -165,19 +174,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<style>
|
||||
.badge-primary {
|
||||
background-color: #007bff;
|
||||
}
|
||||
.badge-secondary {
|
||||
background-color: #6c757d;
|
||||
}
|
||||
.badge-warning {
|
||||
background-color: #ffc107;
|
||||
}
|
||||
<style>
|
||||
.container {
|
||||
max-width: 800px;
|
||||
margin-top: 30px;
|
||||
}
|
||||
img { border:1px solid #ccc; }
|
||||
</style>
|
||||
<?php $conn->close(); ?>
|
||||
<?php $conn->close(); ?>
|
||||
|
||||
Reference in New Issue
Block a user