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

200 lines
7.0 KiB
PHP

<style type="text/css">
.bg-dark {
background-color: #032DA1 !important;
}
</style>
<main class="common_margin" id="main">
<div class="main-wrap">
<div class="dashboard-cover">
<div class="subject_r">
<div class="subsec_sec">
<div class="subject_r">
<div class="subject_lsec">
<div class="common-heading">
<h2><?= $title ?></h2>
</div>
<?php
$name=''; $status=''; $desc=''; $permissions=array();
if(isset($details) && !empty($details))
{
$name = $details[0]['role_name'];
$status = $details[0]['status'];
$desc = $details[0]['role_desc'];
//$permissions = $details[0]['admin_role_ids'];
}
if(isset($role_permissions[0]['menu_ids']) && $role_permissions[0]['menu_ids']!='')
$permissions = explode(',', $role_permissions[0]['menu_ids']);
?>
<form action='<?php echo base_url().'add-edit-role/'.$idVal;?>' id="addEditRoleForm" method="post">
<input type='hidden' name='id' id='id' value='<?php echo $idVal;?>' />
<div class="subject_lformarea role_formarea">
<div class="form-group">
<label for="">Role Name<span class="text-danger font-weight-bold">*</span></label>
<input type="text" name="role_name" id="role_name" value='<?php echo $name;?>' class="form-control" >
<label style="display : none" class="form_err" id='role_name_error'></label>
</div>
<div class="form-group">
<label for="">Status<span class="text-danger font-weight-bold">*</span></label>
<select name="status" id="status" class="form-control">
<option value="">Choose Status</option>
<option value="Active" <?php if($status == 'Active'){?>selected<?php } ?>>Active</option>
<option value="Inactive" <?php if($status == 'Inactive'){?>selected<?php } ?>>Inactive</option>
</select>
<label style="display : none" class="form_err" id='status_error'></label>
</div>
<div class="form-group">
<label for=""> Description</label>
<textarea class="form-control" data-altName="Description" name="role_desc" id="role_desc" rows="6" ><?php echo $desc;?></textarea>
</div>
<div class="form-group">
<label for=""> Role Permissions<span class="text-danger font-weight-bold">*</span></label>
<div class="roles_checkbox">
<?php
if(isset($menus) && !empty($menus))
{
foreach($menus as $m)
{
?>
<div class="form-check">
<input class="form-check-input role_perm" type="checkbox" value="<?php echo $m['id'];?>" name="role_permissions[]" <?php if(in_array($m['id'], $permissions)){?>checked<?php } ?> >
<label class="form-check-label" ><?php echo $m['menu_name'];?></label>
</div>
<?php
}
}
?>
</div>
<label style="display : none" class="form_err" id='permissions_error'></label>
</div>
</div>
</form>
<?php if($idVal > 0) { ?>
<button type="button" class="btn bg-dark btn-primary btn-md subject_addbtn" onclick='validate_role_form()'>Update</button>
<?php } else { ?>
<button type="button" class="btn btn-primary btn-md subject_addbtn" onclick='validate_role_form()'>Save</button>
<?php } ?>
&nbsp;&nbsp;
<a href='<?php echo base_url()."roles";?>'>
<button class="btn btn-dark btn-md">Back</button>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<!--End right-top side-->
</div>
<!-- <script src="<?php echo base_url(); ?>assets-hms/js/jquery-3.2.1.slim.min.js"></script> -->
<script src="<?php echo base_url(); ?>assets-hms/js/jquery-3.4.1.min.js" ></script>
<script src="<?php echo base_url(); ?>assets-hms/js/popper.min.js"></script>
<script src="<?php echo base_url(); ?>assets-hms/js/bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js"></script>
<script defer src="<?php echo base_url(); ?>assets-hms/js/all.js"></script>
<script defer src="<?php echo base_url(); ?>assets-hms/js/main.js"></script>
<script src="<?php echo base_url(); ?>assets-hms/owl-carousel/js/owl.carousel.min.js"></script>
<script>
$(document).ready(function(){
$('.user-drpdown').click(function(){
$('.drpdown-items').toggle();
});
});
//table js
$('#tbl').DataTable( {
"lengthMenu": [[5,10, 25, 50, -1], [5,10, 25, 50, "All"]]
} );
//table js end
</script>
<script type="text/javascript">
var jsAddOrEdit = '<?php echo $idVal;?>';
$(document).ready(function(){
$(document).on('keypress', function(e){
if(e.which==13)
{
validate_role_form();
}
});
});
function hide_all_role_errors()
{
$('#role_name_error').hide();
$('#status_error').hide();
$('#permissions_error').hide();
}
function validate_role_form()
{
hide_all_role_errors();
var errArr = new Array();
var rname = $('#role_name').val().trim();
if(rname=='')
errArr.push('role_name_Sep@Str_Please enter the role name.');
else
{
var alphanumeric = /^[a-z\0-9\-\s]+$/i;
if(!alphanumeric.test(rname)){
errArr.push('role_name_Sep@Str_Please enter only Alphanumeric values.');
} else {
var urltogo = '<?php echo base_url();?>'+'HmsAdmin/ajaxCheckIsRoleAlreadyExists';
var reqdData = 'role_name='+$('#role_name').val()+'&id='+$('#id').val();
$.ajax({
type: "POST",
url: urltogo,
data: reqdData,
async: false,
success: function(result)
{
result = result.trim();
//alert(result);
if(result == 'Duplicate Role')
errArr.push('role_name_Sep@Str_This role name already exists.');
else if(result == 'Insufficient Data')
errArr.push('role_name_Sep@Str_Insufficient Data Sent. Please check again.');
}
});
}
}
var status = $('#status').val().trim();
if(status=='')
errArr.push('status_Sep@Str_Please select the user status.');
var epCnt = 0;
$('.role_perm').each(function(){
if($(this).prop('checked'))
epCnt++;
});
if(epCnt == 0)
errArr.push('permissions_Sep@Str_Please select the role permissions.');
//var errArr = new Array();
if(errArr.length>0)
{
for(i=0; i<errArr.length; i++)
{
var resArr = errArr[i].split("_Sep@Str_");
$("#"+resArr[0]+"_error").html(resArr[1]);;
$("#"+resArr[0]+"_error").show();
}
var xxxVal = errArr[0].split('_Sep@Str_');
$('#'+xxxVal[0]).focus();
return false;
}
else{
$('#addEditRoleForm').submit();
}
}
</script>
</body>
</html>