BBnepal-Accounts/application/views/admin/ae_user.php
Sampanna Rimal 9cd05ef3cb commitall
2024-07-10 18:28:19 +05:45

318 lines
9.6 KiB
PHP

<style>
form label.error,
#Nameerr {
color: red;
}
.subject_l {
width: 50%;
}
.con-pass {
position: absolute;
top: 8px;
right: 8px;
cursor: pointer;
color: #878a8d;
}
</style>
<main class="wrapper responsive-width" id="main">
<!----admin template role---->
<div class="admin_tempblock">
<div class="admin_tempsec">
<div class="admin_sec">
<form action="<?php echo base_url() ?>admin/users/ae-user/<?php echo $id ?>" class="mb-5" method="post" id="userForm">
<?php if ($id == 0) { ?>
<div class="subsec_sec">
<div class="subject_l subject_l_full_width">
<div class="subject_lsec">
<div class="subject_lhead"><?php echo $title ?></div>
<div class="subject_lformarea">
<div class="form-group">
<label for="">Full Name<span class="text-danger font-weight-bold">*</span></label>
<input type="text" onkeypress="return lettersOnly(event)" name="admin_name" id="validate_val" class="form-control alphaonly" placeholder="Name of the role">
</div>
<div class="form-group">
<label for="">Email-Id<span class="text-danger font-weight-bold">*</span></label>
<input type="text" name="email" class="form-control" placeholder="Enter your email">
<label id="Nameerr" style="display : none"></label>
</div>
<div class="form-group">
<label for="">Password<span class="text-danger font-weight-bold">*</span></label>
<div class="password-wrp">
<input type="password" name="password" id="password" class="form-control password_hide" placeholder="Enter your password">
<span class="passwrd-icon icon-y frst-pass"><i class="far fa-eye"></i></span>
</div>
</div>
<div class="form-group">
<label for="">Confirm Password<span class="text-danger font-weight-bold">*</span></label>
<div class="password-wrp">
<input type="password" id="confirm-password" name="confirm_password" class=" form-control" placeholder="Enter your password">
<span class="con-pass icon-y eye-icon"><i class="far fa-eye"></i></span>
</div>
</div>
<div class="form-group">
<label for="">User Role<span class="text-danger font-weight-bold">*</span></label>
<select name="admin_role_ids" class="form-control">
<option selected disable value="">Choose role</option>
<?php foreach ($roles as $key => $value) { ?>
<option value="<?php echo $value['id'] ?>"><?php echo $value['role_name'] ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label for="">Status<span class="text-danger font-weight-bold">*</span></label>
<select name="status" class="form-control">
<option selected disable value="">Choose role status</option>
<option value="Active">Active</option>
<option value="Inactive">Inactive</option>
</select>
</div>
<input type="submit" class="subject_addbtn" value="Save">
<a href="<?= base_url(); ?>admin/users/list"><button type="button" class="subject_addbtn bg-dark ml-2">Back</button></a>
</div>
</div>
</div>
</div>
</form>
<?php } else { ?>
<div class="subsec_sec">
<div class="subject_l subject_l_full_width">
<div class="subject_lsec">
<div class="subject_lhead"><?php echo $title ?></div>
<div class="subject_lformarea">
<div class="form-group">
<label for="">Full Name<span class="text-danger font-weight-bold">*</span></label>
<input type="text" onkeypress="return lettersOnly(event)" name="admin_name" value="<?php echo $result[0]['admin_name'] ?>" id="validate_val" class="form-control alphaonly" placeholder="Name of the role">
</div>
<div class="form-group">
<label for="">Email-Id<span class="text-danger font-weight-bold">*</span></label>
<input type="text" value="<?php echo $result[0]['email'] ?>" name="email" class="form-control" placeholder="Enter your email">
<label id="Nameerr" style="display : none"></label>
</div>
<div class="form-group">
<label for="">User Role<span class="text-danger font-weight-bold">*</span></label>
<select name="admin_role_ids" class="form-control">
<option selected value="<?php echo $result[0]['admin_role_ids'] ?>"><?php echo $result[0]['role_name'] ?></option>
<?php foreach ($pre_selected_roles as $key => $value) { ?>
<option value="<?php echo $value['id'] ?>"><?php echo $value['role_name'] ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label for="">Status<span class="text-danger font-weight-bold">*</span></label>
<select name="status" class="form-control">
<option selected value="<?php echo $result[0]['status'] ?>"><?php echo $result[0]['status'] ?></option>
<?php if ($result[0]['status'] == 'Active') { ?>
<option value="Inactive">Inactive</option>
<?php } else { ?>
<option value="Active">Active</option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label for="">Password</label>
<div class="password-wrp">
<input type="password" onchange="showConfirmPwd(this.value)" id="password" name="replace_password" class="form-control password_hide" placeholder="Enter ">
<span class="passwrd-icon icon-y frst-pass"><i class="far fa-eye"></i></span>
<small>Note : Enter password to replace exisiting password</small>
</div>
<div class="form-group mt-3" id="pwdBlock" style="display:none">
<label for="">Confirm Password<span class="text-danger font-weight-bold">*</span></label>
<div class="password-wrp">
<input type="password" id="confirm-password" name="confirm_password" class=" form-control password_hide_c" placeholder="Enter your password">
<span class="con-pass icon-y"><i class="far fa-eye"></i></span>
</div>
</div>
</div>
<input type="submit" class="subject_addbtn" value="Update">
<a href="<?= base_url(); ?>admin/users/list"><button type="button" class="subject_addbtn bg-dark ml-2">Back</button></a>
</div>
</div>
</div>
</div>
</form>
</form>
<?php } ?>
</div>
</div>
</div>
<!----admin template role end---->
</main>
<!--End right-top side-->
<script>
$(document).on('keypress', function(e) {
if (e.which == 13) {
$('form').submit();
}
});
$(document).ready(function() {
jQuery.validator.addMethod("emailregex", function(value, element) {
return this.optional(element) || /^[a-zA-Z0-9._-]+@[a-zA-Z-]+\.[a-zA-Z.]{2,5}$/.test(value);
}, 'Email Address is invalid: Please enter a valid email address.');
jQuery.validator.addMethod("passwordregex", function(value, element) {
return this.optional(element) || /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#@$!%*?&])[A-Za-z\d@$#!%*?&]{6,16}$/.test(value);
}, 'Your password must be atleast 6 characters long, which inculdes one upper case, one numerical value and one special character.');
$("#userForm").validate({
ignore: ":hidden",
rules: {
admin_name: {
required: true,
minlength: 3
},
email: {
required: true,
email: true,
emailregex: true
},
password: {
required: true,
minlength: 6,
passwordregex: true
},
confirm_password: {
required: true,
minlength: 6,
equalTo: '#password'
},
admin_role_ids: "required",
status: "required",
replace_password: 'passwordregex'
},
messages: {
admin_name: {
required: "Please provide a user name",
minlength: "Please enter more than 3 Characters"
},
email: {
required: "Please provide an email-id",
},
password: {
required: 'Please enter a valid password',
minlength: 'Password should be more than 6 characters'
},
confirm_password: {
required: 'Please re-enter your password',
equalTo: "Passwords doesn't match. Please provide a password same as above"
},
admin_role_ids: 'Please select one user role',
status: 'Please select the status of user'
},
submitHandler: function(form) {
var inputValue = $("input[name='email']", form).val();
inputValue = inputValue.toLowerCase().trim().replace(/\s\s+/g, ' ');
let flag = false;
$.ajax({
url: '<?php echo base_url() ?>' + 'admin/ajax_validate_user_email',
data: {
value: inputValue,
id: <?php echo $id ?>
},
type: 'POST',
async: false,
success: function(data) {
console.log(data);
if (data == 'success') {
flag = true
}
}
});
if (flag) {
form.submit();
} else {
$('#Nameerr').show();
$('#Nameerr').text('This email already exists.');
}
}
});
});
</script>
<script type="text/javascript">
function lettersOnly() {
var charCode = event.keyCode;
if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123) || charCode == 8 || charCode == 32)
return true;
else
return false;
}
$(".con-pass").click(function() {
$(".con-pass").toggleClass("eye-icon");
var input = $("#confirm-password");
if (input.attr("type") == "password") {
input.attr("type", "text");
} else {
input.attr("type", "password");
}
});
function showConfirmPwd(val) {
if (val != '') {
$('#pwdBlock').show();
} else {
$('#pwdBlock').hide();
}
}
</script>