197 lines
13 KiB
PHP
197 lines
13 KiB
PHP
<div class="row">
|
|
<div class="col-lg-12">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h4 class="header-title"><?= $page_name; ?></h4>
|
|
<!-- <?php if (session()->getFlashdata('success')) : ?>
|
|
<div class="alert alert-success"><?= session()->getFlashdata('success') ?></div>
|
|
<?php endif; ?> -->
|
|
<form class="parsley-examples" action="<?= base_url() . "insert_users"; ?>" method="post" enctype="multipart/form-data" id="myForm">
|
|
<div class="form-group">
|
|
<div class="form-row">
|
|
|
|
<?php if ($loggedin_person_role === 'sadmin') { ?>
|
|
<div class="form-group col-md-4">
|
|
<label for="business_id" class="col-form-label">Organization<span class="text-danger"></span></label>
|
|
<select id="business_id" name="business_id" class="form-control" required>
|
|
<option value="">Choose Organization</option>
|
|
<?php foreach ($business_details as $value) { ?>
|
|
<option value="<?php echo $value['business_id']; ?>" <?php if (isset($details['business_id']) && ($details['business_id'] === $value['business_id'])) echo "selected"; ?>>
|
|
<?php echo $value['title']; ?></option>
|
|
<?php } ?>
|
|
</select>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
<div class="form-group col-md-4">
|
|
<label for="email" class="col-form-label">Email<span class="text-danger">*</span></label>
|
|
<input type="email" class="form-control" id="email" name="email" placeholder="Email" value="<?= isset($details['email']) ? $details['email'] : '' ?>" required />
|
|
</div>
|
|
|
|
<?php if (empty($details)) { ?>
|
|
<div class="form-group col-md-4">
|
|
<label for="password" class="col-form-label">Password<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="password" name="password" placeholder="Password" value="<?= isset($details['password']) ? $details['password'] : '' ?>" required />
|
|
</div>
|
|
<?php } ?>
|
|
</div>
|
|
<div class="form-row">
|
|
<div class="form-group col-md-6">
|
|
<label for="first_name" class="col-form-label">First Name<span class="text-danger">*</span></label>
|
|
<input data-parsley-type="alphanum" type="text" class="form-control" id="first_name" name="first_name" placeholder="First Name" value="<?= isset($details['first_name']) ? $details['first_name'] : '' ?>" required />
|
|
</div>
|
|
<div class="form-group col-md-6">
|
|
<label for="last_name" class="col-form-label">Last Name<span class="text-danger"></span></label>
|
|
<input data-parsley-type="alphanum" type="text" class="form-control" id="last_name" name="last_name" placeholder="Last Name" value="<?= isset($details['last_name']) ? $details['last_name'] : '' ?>" />
|
|
</div>
|
|
<!-- <div class="form-group col-md-4">
|
|
<label for="date_of_birth" class="col-form-label">Date Of Birth<span class="text-danger">*</span></label>
|
|
<input type="date" class="form-control" id="date_of_birth" name="date_of_birth" placeholder="Date Of birth (format : DD/MM/YYYY)" data-toggle="input-mask" data-mask-format="00/00/0000" required />
|
|
</div> -->
|
|
</div>
|
|
<div class="form-row">
|
|
<div class="form-group col-md-4">
|
|
<label for="mobile_no" class="col-form-label">Mobile Number<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="mobile_no" name="mobile_no" placeholder="Mobile Number (Enter only numbers)" data-toggle="input-mask" data-mask-format="0000000000" value="<?= isset($details['mobile_no']) ? $details['mobile_no'] : '' ?>" autofocus required>
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label for="role" class="col-form-label">Role<span class="text-danger">*</span></label>
|
|
<select id="role" name="role" class="form-control" required>
|
|
<option value="">Select Role</option>
|
|
<option value="admin" <?= isset($details['role']) && $details['role'] === 'admin' ? 'selected' : '' ?>>Admin</option>
|
|
<option value="manager" <?= isset($details['role']) && $details['role'] === 'manager' ? 'selected' : '' ?>>Manager</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group col-md-4">
|
|
<label for="gender" class="col-form-label">Gender<span class="text-danger"></span></label>
|
|
<select id="gender" name="gender" class="form-control">
|
|
<option value="">Select Gender</option>
|
|
<option value="male" <?= isset($details['gender']) && $details['gender'] === 'male' ? 'selected' : '' ?>>Male</option>
|
|
<option value="female" <?= isset($details['gender']) && $details['gender'] === 'female' ? 'selected' : '' ?>>Female</option>
|
|
</select>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
<div class="form-row">
|
|
<div class="form-group col-md-4">
|
|
<label for="address" class="col-form-label">Address<span class="text-danger"></span></label>
|
|
<input type="text" class="form-control" id="address" name="address" placeholder="Address (eg : 1234 Main St)" value="<?= isset($details['address']) ? $details['address'] : '' ?>" />
|
|
</div>
|
|
|
|
<div class="form-group col-md-4">
|
|
<label for="city" class="col-form-label">City<span class="text-danger"></span></label>
|
|
<input type="text" class="form-control" id="city" name="city" placeholder="City" value="<?= isset($details['city']) ? $details['city'] : '' ?>" />
|
|
</div>
|
|
|
|
<div class="form-group col-md-4">
|
|
<label for="state" class="col-form-label">State<span class="text-danger"></span></label>
|
|
<input type="text" class="form-control" id="state" name="state" placeholder="State" value="<?= isset($details['state']) ? $details['state'] : '' ?>" />
|
|
</div>
|
|
</div>
|
|
<div class="form-row">
|
|
<div class="form-group col-md-4">
|
|
<label for="postal_code" class="col-form-label">Postal Code<span class="text-danger"></span></label>
|
|
<input data-parsley-type="number" type="text" class="form-control" id="postal_code" name="postal_code" placeholder="Postal Code (PIN)" value="<?= isset($details['postal_code']) ? $details['postal_code'] : '' ?>" pattern="[0-9]{6}" maxlength="6" />
|
|
</div>
|
|
|
|
<div class="form-group col-md-4">
|
|
<label for="profile_picture" class="col-form-label">Profile Picture</label>
|
|
<input type="file" name="profile_picture" value="<?= isset($details['profile_picture']) ? $details['profile_picture'] : '' ?>" accept="image/*" onchange="validateFile(this)" />
|
|
<div id="error_message" style="color: red;"></div>
|
|
</div>
|
|
|
|
<?php if (!empty($details['profile_picture'])) { ?>
|
|
<div class="form-group col-md-4 mt-3">
|
|
<div class="media">
|
|
<img src="<?= base_url('public/uploads/' . $details['profile_picture']) ?>" alt="Business Logo" height="100" class="preview-image d-flex align-self-start rounded mr-2" style="position: relative; left: 40%;">
|
|
<div class="media-body">
|
|
<!-- <h5 class="mt-0">Existing Profile Picture</h5> -->
|
|
<!-- <p class="mb-1"><?= $details['profile_picture']; ?></p> -->
|
|
<input type="hidden" id="existing_profile_picture_name" name="existing_profile_picture_name" placeholder="hidden Field for profile picture name" readonly value="<?= $details['profile_picture']; ?>" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
</div>
|
|
<input type="hidden" id="user_id" name="user_id" placeholder="hidden for user id" value="<?= isset($details['user_id']) ? $details['user_id'] : '' ?>" />
|
|
|
|
<?php if (!empty($details) && $loggedin_person_role !== 'manager') { ?>
|
|
<div class="form-group text-right m-b-0 checkbox checkbox-purple">
|
|
<input type="checkbox" id="isactive" name="isactive" class="form-control" <?= isset($details) && $details['isactive'] == 1 ? 'checked' : '' ?>>
|
|
<label for="isactive"> Is Active</label>
|
|
</div>
|
|
<br>
|
|
<?php } ?>
|
|
<div class="form-group text-right m-b-0">
|
|
<button class="btn btn-success waves-effect waves-light mr-1" type="submit" id="submitBtn">
|
|
Submit
|
|
</button>
|
|
<button type="reset" class="btn btn-primary waves-effect mr-1">
|
|
Reset
|
|
</button>
|
|
<?php if ($loggedin_person_role !== 'manager') : ?>
|
|
<a href="<?= base_url() . "user_list"; ?>" class="btn btn-secondary waves-effect">Cancel</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div> <!-- end card-body-->
|
|
</div> <!-- end card-->
|
|
</div> <!-- end col-->
|
|
</div><!-- end row -->
|
|
<script>
|
|
// Get the current date in "yyyy-mm-dd" format
|
|
function getCurrentDate() {
|
|
const today = new Date();
|
|
const year = today.getFullYear();
|
|
let month = today.getMonth() + 1;
|
|
let day = today.getDate();
|
|
|
|
// Add leading zeros if month or day is less than 10
|
|
if (month < 10) {
|
|
month = '0' + month;
|
|
}
|
|
|
|
if (day < 10) {
|
|
day = '0' + day;
|
|
}
|
|
|
|
return `${year}-${month}-${day}`;
|
|
}
|
|
|
|
// Set the max attribute of the date input field to the current date
|
|
document.getElementById('date_of_birth').setAttribute('max', getCurrentDate());
|
|
|
|
// Set the min attribute of the date input field to "1965-01-01"
|
|
document.getElementById('date_of_birth').setAttribute('min', '1965-01-01');
|
|
|
|
function validateFile(input) {
|
|
const file = input.files[0];
|
|
const errorMessage = document.getElementById("error_message");
|
|
|
|
if (file) {
|
|
if (file.type.startsWith("image/")) {
|
|
// It's an image file, no error
|
|
errorMessage.textContent = "";
|
|
} else {
|
|
// Invalid file type
|
|
errorMessage.textContent = "Invalid file type. Please select an image.";
|
|
input.value = ""; // Clear the input field
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
<script>
|
|
document.getElementById('myForm').addEventListener('submit', function(event) {
|
|
var form = event.target;
|
|
if (form.checkValidity() === false) {
|
|
form.reportValidity(); // Display validation error messages
|
|
event.preventDefault(); // Prevent form submission if it's not valid
|
|
$('#submitBtn').prop('disabled', false);
|
|
} else {
|
|
$('#submitBtn').prop('disabled', true);
|
|
}
|
|
});
|
|
</script>
|