340 lines
16 KiB
PHP
Executable File
340 lines
16 KiB
PHP
Executable File
<?php include('layout/header.php'); ?>
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="page-title-box page-title-box-alt">
|
|
<h4 class="page-title"><?php echo $page_name; ?></h4>
|
|
<div class="page-title-right">
|
|
<ol class="breadcrumb m-0">
|
|
|
|
</li>
|
|
<!-- <li class="breadcrumb-item"><a href="javascript: void(0);">Tables</a></li>
|
|
<li class="breadcrumb-item active">Datatables</li> -->
|
|
</ol>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-12">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
|
|
<form action="<?= base_url() . "add_user"; ?>" method="post">
|
|
<div class="form-row">
|
|
<div class="form-group col-md-4">
|
|
<label for="inputState" class="col-form-label">Business<span class="text-danger">*</span></label>
|
|
<select id="business" class="form-control" name="business" required>
|
|
<!-- <option value="">Select Business</option> -->
|
|
<?php foreach ($business as $busin): ?>
|
|
<option value="<?= $busin['business_id'] ?>" <?= isset($users['business_id']) && $users['business_id'] == $busin['business_id'] ? 'selected' : '' ?>><?= $busin['business_name'] ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label for="inputState" class="col-form-label">Branch<span class="text-danger">*</span></label>
|
|
<select id="branch" class="form-control" name="branch" required>
|
|
<!-- <option value="">Select Branch</option> -->
|
|
<?php if (isset($branch) && (is_array($branch) || is_object($branch))) {
|
|
foreach ($branch as $branch): ?>
|
|
<option value="<?= $branch['branch_id'] ?>" <?= isset($users['branch_id']) && $users['branch_id'] == $branch['branch_id'] ? 'selected' : '' ?> ><?= $branch['branch_name'] ?></option>
|
|
<?php endforeach; } ?>
|
|
<!-- Branch options will be populated dynamically using JavaScript -->
|
|
</select>
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label for="inputState" class="col-form-label">Role<span class="text-danger">*</span></label>
|
|
<select id="inputState" class="form-control" name="role" required>
|
|
<option value="">Select Role</option>
|
|
<?php foreach ($roles as $role): ?>
|
|
<option value="<?= $role['role_id'] ?>" <?= isset($users['role']) && $users['role'] == $role['role_id'] ? 'selected' : '' ?>><?= $role['roles'] ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group col-md-12">
|
|
</div>
|
|
<div class="form-group col-md-12">
|
|
<h5 class="text-uppercase bg-light p-2"><i class="mdi mdi-account-circle mr-1"></i> Personal Info</h5>
|
|
</div>
|
|
<div class="form-group col-md-6">
|
|
<label for="inputEmail4" class="col-form-label">Name<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" name="name" placeholder="Name" value="<?= isset($users['name']) ? $users['name'] : '' ?>" required>
|
|
</div>
|
|
<div class="form-group col-md-6">
|
|
<label for="inputEmail4" class="col-form-label">Email<span class="text-danger">*</span></label>
|
|
<input type="email" class="form-control" name="email" placeholder="Email" value="<?= isset($users['email']) ? $users['email'] : '' ?>" required>
|
|
</div>
|
|
<div class="form-group col-md-6">
|
|
<label for="inputPassword4" class="col-form-label">Password<span class="text-danger">*</span></label>
|
|
<input type="password" class="form-control" id="password" name="password" placeholder="Password" required>
|
|
</div>
|
|
<div class="form-group col-md-6">
|
|
<label for="inputAddress" class="col-form-label">Mobile<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" name="mobile" placeholder="Mobile" value="<?= isset($users['mobile_no']) ? $users['mobile_no'] : '' ?>" maxlength="16" minlength="6"required>
|
|
</div>
|
|
</div>
|
|
<input type="hidden" id="user_id" name="user_id" value="<?= isset($users['user_id']) ? $users['user_id'] : '' ?>">
|
|
<di class="col-md-12">
|
|
<button type="submit" style="float: inline-end;" class="btn btn-primary">Update</button>
|
|
</div>
|
|
</form>
|
|
<div class="password_change card-body">
|
|
<div class="row">
|
|
<div class="col-md-12">
|
|
<div class="form-group">
|
|
<h5 class="mb-3 text-uppercase bg-light p-2"><i class="mdi mdi-lock-reset mr-1"></i>Change / Reset Password</h5>
|
|
<p class="text-muted mb-3">
|
|
<strong>Note:</strong> Enable the checkbox to <b>reset the password</b>. Disable it to <b>update the password</b> using existing one.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-12 mb-2">
|
|
<div class="form-check">
|
|
<input type="checkbox" class="form-check-input" id="resetPasswordCheckbox" checked>
|
|
<label class="form-check-label" for="resetPasswordCheckbox">
|
|
Reset Password
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-md-6" id="old_password_div" style="display:none;">
|
|
<div class="form-group">
|
|
<label for="old_password">Old Password<span class="text-danger">*</span></label>
|
|
<div class="input-group">
|
|
<input type="password" class="form-control" id="old_password" required>
|
|
<div class="input-group-append">
|
|
<span class="input-group-text">
|
|
<i class="fa fa-eye" id="toggleOldPassword"></i>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<div class="form-group">
|
|
<label for="new_password">New Password<span class="text-danger">*</span></label>
|
|
<div class="input-group">
|
|
<input type="password" class="form-control" id="new_password" required>
|
|
<div class="input-group-append">
|
|
<span class="input-group-text">
|
|
<i class="fa fa-eye" id="toggleNewPassword"></i>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<div class="form-group">
|
|
<label for="confirm_password">Confirm Password<span class="text-danger">*</span></label>
|
|
<div class="input-group">
|
|
<input type="password" class="form-control" id="confirm_password" required>
|
|
<div class="input-group-append">
|
|
<span class="input-group-text">
|
|
<i class="fa fa-eye" id="toggleConfirmPassword"></i>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-md-6" style="margin-top: 27px;">
|
|
<button type="submit" class="btn btn-primary" id="submit_password" style="float: inline-end;" onclick="changePassword(this)">Submit</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php include('layout/footer.php'); ?>
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
$('#business').change(function() {
|
|
var businessId = $(this).val();
|
|
if (businessId !== '') {
|
|
$.ajax({
|
|
url: '<?php echo base_url(),"get_branch"?>', // Update 'your_controller' with the actual controller name
|
|
type: 'post',
|
|
data: {business_id: businessId},
|
|
dataType: 'json',
|
|
success:function(response) {
|
|
// var len = response.length;
|
|
// $("#branch").empty();
|
|
// $("#branch").append("<option value=''>Select Branch</option>");
|
|
// for( var i = 0; i<len; i++) {
|
|
// var branchId = response[i]['branch_id'];
|
|
// var branchName = response[i]['branch_name'];
|
|
// $("#branch").append("<option value='"+branchId+"'>"+branchName+"</option>");
|
|
// }
|
|
}
|
|
});
|
|
} else {
|
|
$("#branch").empty();
|
|
$("#branch").append("<option value=''>Select Branch</option>");
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
var user_id = "<?php echo $user_id; ?>";
|
|
|
|
if (user_id != 0) {
|
|
$('#password').prop('required' ,false);
|
|
$('#password').parent().hide();
|
|
togglePasswordFields($('#resetPasswordCheckbox').is(':checked'));
|
|
}else{
|
|
$('.password_change').hide();
|
|
}
|
|
|
|
$('#resetPasswordCheckbox').on('change', function () {
|
|
togglePasswordFields($(this).is(':checked'));
|
|
});
|
|
|
|
// --- Toggle field visibility based on checkbox ---
|
|
function togglePasswordFields(isReset) {
|
|
if (isReset) {
|
|
// Reset password → old password hidden
|
|
$('#old_password_div').hide();
|
|
$('#old_password').val('').prop('required', false);
|
|
} else {
|
|
// Change password → old password visible
|
|
$('#old_password_div').show();
|
|
$('#old_password').val('').prop('required', true);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function togglePasswordFields(isReset) {
|
|
if (isReset) {
|
|
$('#old_password_div').hide();
|
|
$('#old_password').val('').prop('required', false);
|
|
} else {
|
|
$('#old_password_div').show();
|
|
$('#old_password').val('').prop('required', true);
|
|
}
|
|
}
|
|
|
|
|
|
function changePassword(params) {
|
|
var isReset = $('#resetPasswordCheckbox').is(':checked');
|
|
var formData = {};
|
|
|
|
if (isReset) {
|
|
formData = {
|
|
new_password: $('#new_password').val(),
|
|
confirm_password: $('#confirm_password').val(),
|
|
type: 'reset'
|
|
};
|
|
} else {
|
|
formData = {
|
|
old_password: $('#old_password').val(),
|
|
new_password: $('#new_password').val(),
|
|
confirm_password: $('#confirm_password').val(),
|
|
type: 'change'
|
|
};
|
|
}
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '<?php echo base_url()."change_password/"?>' + user_id,
|
|
data: formData,
|
|
dataType: 'json',
|
|
success: function(response) {
|
|
console.log(response);
|
|
if (response.status == 'error') {
|
|
toastr.warning(response.message, 'Warning');
|
|
}else{
|
|
toastr.success(response.message, 'Success');
|
|
|
|
}
|
|
},
|
|
error: function(xhr, status, error) {
|
|
// Handle error response here
|
|
console.error(xhr.responseText);
|
|
}
|
|
});
|
|
}
|
|
|
|
</script>
|
|
<script>
|
|
var oldPasswordField = document.getElementById("old_password");
|
|
var toggleOldPassword = document.getElementById("toggleOldPassword");
|
|
|
|
var newPasswordField = document.getElementById("new_password");
|
|
var toggleNewPassword = document.getElementById("toggleNewPassword");
|
|
|
|
var confirmField = document.getElementById("confirm_password");
|
|
var toggleConfirmPassword = document.getElementById("toggleConfirmPassword");
|
|
|
|
toggleOldPassword.addEventListener("click", function() {
|
|
togglePasswordVisibility(oldPasswordField, toggleOldPassword);
|
|
});
|
|
|
|
toggleNewPassword.addEventListener("click", function() {
|
|
togglePasswordVisibility(newPasswordField, toggleNewPassword);
|
|
});
|
|
|
|
toggleConfirmPassword.addEventListener("click", function() {
|
|
togglePasswordVisibility(confirmField, toggleConfirmPassword);
|
|
});
|
|
|
|
function togglePasswordVisibility(field, toggle) {
|
|
if (field.type === "password") {
|
|
field.type = "text";
|
|
toggle.className = "fa fa-eye-slash";
|
|
} else {
|
|
field.type = "password";
|
|
toggle.className = "fa fa-eye";
|
|
}
|
|
}
|
|
</script>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
var oldPasswordField = document.getElementById('old_password');
|
|
var newPasswordField = document.getElementById('new_password');
|
|
var confirmPasswordField = document.getElementById('confirm_password');
|
|
var submitButton = document.getElementById('submit_password');
|
|
var resetCheckbox = $('#resetPasswordCheckbox');
|
|
|
|
// Function to validate the password fields
|
|
function validatePasswords() {
|
|
var isReset = resetCheckbox.is(':checked');
|
|
var oldPassword = oldPasswordField.value;
|
|
var newPassword = newPasswordField.value;
|
|
var confirmPassword = confirmPasswordField.value;
|
|
|
|
if(oldPassword !== newPassword && newPassword !== ''){
|
|
console.log(oldPassword);
|
|
console.log(newPassword);
|
|
console.log(confirmPassword);
|
|
|
|
if (isReset) {
|
|
if (newPassword && confirmPassword && newPassword === confirmPassword) {
|
|
submitButton.prop('disabled', false);
|
|
} else {
|
|
submitButton.prop('disabled', true);
|
|
}
|
|
} else {
|
|
// Change flow → all required
|
|
if (oldPassword && newPassword && confirmPassword &&
|
|
newPassword === confirmPassword && oldPassword !== newPassword) {
|
|
submitButton.prop('disabled', false);
|
|
} else {
|
|
submitButton.prop('disabled', true);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
// Add event listeners to all relevant fields
|
|
oldPasswordField.addEventListener('input', validatePasswords);
|
|
newPasswordField.addEventListener('input', validatePasswords);
|
|
confirmPasswordField.addEventListener('input', validatePasswords);
|
|
});
|
|
</script>
|