ns77@siliconpin.com 2025-09-04 15:04:21 +00:00
parent c1a38558c6
commit 3af87688c0
1 changed files with 35 additions and 13 deletions

View File

@ -32,6 +32,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$user_phone = $_POST['user_phone'];
$type = $_POST['type'];
$user_id = $_POST['user_id'];
$comi_rate = $_POST['comi_rate'] ?? null;
$profilePicPath = $user['profile_pic']; // default old pic
// Validate inputs
@ -51,9 +52,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$filePath = $uploadDir . $fileName;
if (move_uploaded_file($fileTmp, $filePath)) {
$profilePicPath = "/picture/" . $fileName;
$profilePicPath = "picture/" . $fileName;
// পুরনো ফাইল ডিলিট (যদি থাকে)
// Delete old file if exists
if (!empty($user['profile_pic']) && file_exists(__DIR__ . "/" . $user['profile_pic'])) {
unlink(__DIR__ . "/" . $user['profile_pic']);
}
@ -63,17 +64,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Update query
if (!empty($_POST['password'])) {
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$sql = "UPDATE `".$GLOBALS['arif_users']."`
SET user_id = ?, user_name = ?, user_phone = ?, type = ?, password = ?, profile_pic = ?
WHERE id = ?";
$sql = "UPDATE `".$GLOBALS['arif_users']."` SET user_id = ?, user_name = ?, user_phone = ?, type = ?, comi_rate = ?, password = ?, profile_pic = ? WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssssssi", $user_id, $user_name, $user_phone, $type, $password, $profilePicPath, $id);
$stmt->bind_param("ssssdssi", $user_id, $user_name, $user_phone, $type, $comi_rate, $password, $profilePicPath, $id);
} else {
$sql = "UPDATE `".$GLOBALS['arif_users']."`
SET user_id = ?, user_name = ?, user_phone = ?, type = ?, profile_pic = ?
WHERE id = ?";
$sql = "UPDATE `".$GLOBALS['arif_users']."` SET user_id = ?, user_name = ?, user_phone = ?, type = ?, comi_rate = ?, profile_pic = ? WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("sssssi", $user_id, $user_name, $user_phone, $type, $profilePicPath, $id);
$stmt->bind_param("ssssdsi", $user_id, $user_name, $user_phone, $type, $comi_rate, $profilePicPath, $id);
}
if ($stmt->execute()) {
@ -139,12 +136,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<div class="form-group mb-3">
<label for="type" class="form-label">User Type</label>
<select class="form-control" id="type" name="type" required>
<select class="form-control" id="type" name="type" required onchange="toggleCommissionField()">
<option value="agent" <?php echo $user['type'] === 'agent' ? 'selected' : ''; ?>>Agent</option>
<option value="admin" <?php echo $user['type'] === 'admin' ? 'selected' : ''; ?>>Admin</option>
<option value="supervisor" <?php echo $user['type'] === 'supervisor' ? 'selected' : ''; ?>>Supervisor</option>
<option value="bm" <?php echo $user['type'] === 'bm' ? 'selected' : ''; ?>>Branch Manager</option>
</select>
</div>
<div class="form-group mb-3" id="commission-field" style="<?php echo ($user['type'] === 'agent') ? '' : 'display: none;'; ?>">
<label for="comi_rate" class="form-label">Commission Rate (%)</label>
<input type="number" step="0.01" class="form-control" id="comi_rate" name="comi_rate"
value="<?php echo htmlspecialchars($user['comi_rate']); ?>" placeholder="Enter commission rate">
</div>
</div>
</div>
@ -173,6 +176,25 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
this.setCustomValidity("");
}
});
// Toggle commission field based on user type
function toggleCommissionField() {
const selectedUserType = document.getElementById('type').value;
const commissionField = document.getElementById('commission-field');
if (selectedUserType === 'agent') {
commissionField.style.display = 'block';
document.getElementById('comi_rate').setAttribute('required', 'required');
} else {
commissionField.style.display = 'none';
document.getElementById('comi_rate').removeAttribute('required');
}
}
// Initialize on page load
document.addEventListener('DOMContentLoaded', function() {
toggleCommissionField();
});
</script>
<style>
.container {
@ -181,4 +203,4 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
}
img { border:1px solid #ccc; }
</style>
<?php $conn->close(); ?>
<?php $conn->close(); ?>