nhance/app/Views/UserList.php

347 lines
14 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<style>
body {
.multiselect-native-select {
position: relative;
/* bottom: 32px; */
select {
border: 0 !important;
clip: rect(0 0 0 0) !important;
height: 1px !important;
margin: -1px -1px -1px -3px !important;
overflow: hidden !important;
padding: 0 !important;
position: absolute !important;
width: 1px !important;
left: 50%;
top: 30px;
}
}
.multiselect-container{
width: 100% !important;
}
.multiselect-selected-text{
float: left !important;
}
}
</style>
<!-- End ADD and EDIT Page HTML -->
<div class="row" id="List-page">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="row" style="margin-bottom:1rem;">
<div class="col-6" style="align-self: center;">
<h4 class="header-title" style="position: relative;">User List</h4>
</div>
<div class="col-6" style="text-align: right; position: relative;top: 53px;">
<button type="button" id="btnAdd" class="btn btn-primary waves-effect waves-light" data-toggle="modal" data-target="#con-close-modal" data-placement="top" title="Add" data-trigger="hover">ADD</button>
</div>
</div>
<table class="table table-sm table-hover m-0 table-centered dt-responsive nowrap w-100" cellspacing="0" id="tickets-table">
<thead class="bg-light">
<tr>
<th class="font-weight-medium">Name</th>
<th class="font-weight-medium">Email</th>
<th class="font-weight-medium">Mobile No</th>
<th class="font-weight-medium">Role</th>
<th class="font-weight-medium">Status</th>
<th class="font-weight-medium">Action</th>
</tr>
</thead>
<tbody>
<?php foreach($UserList as $row) { ?>
<tr id="<?php echo $row->id;?>">
<td class="text-dark"><?php echo $row->first_name; ?></td>
<td><?php echo $row->email; ?></td>
<td><?php echo $row->mobile; ?></td>
<td><?php echo $row->user_role; ?></td>
<td>
<span class="<?php if($row->is_active == 1){ echo 'badge badge-success'; }else{ echo 'badge badge-danger'; } ?>">
<?php if($row->is_active == 1){ echo 'Active'; }else{ echo 'In-Active'; } ?>
</span>
</td>
<td>
<div class="btn-group dropdown" style="position: relative !important;left:0px !important;top:0px !important;">
<a href="javascript: void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-dots-horizontal"></i></a>
<div class="dropdown-menu dropdown-menu-right" style="cursor: pointer;">
<a data-toggle="modal" data-target="#con-close-modal" class="dropdown-item btnEdit" data-id="<?php echo $row->id; ?>"><i data-id="<?php echo $row->id; ?>" class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle btnEdit"></i>Edit</a>
<a class="dropdown-item btnDelete" data-id="<?php echo $row->id; ?>"><i data-id="<?php echo $row->id; ?>" class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle btnDelete"></i>Delete</a>
</div>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- end col -->
</div>
<!-- end row-->
<!-- modal content -->
<div id="con-close-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Add User</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body p-4">
<div class="">
<form role="form" class="parsley-examples" method="post" id="UserForm" action="" enctype="multipart/form-data">
<input type="hidden" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>"/>
<input type="hidden" name="PrimaryKey" id="UserId"/>
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-4">
<label for="emp_code">Employee Code<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="emp_code" placeholder="Enter Employee Code" name="emp_code" required>
</div>
<div class="form-group col-md-8">
<label for="first_name">Name<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="first_name" placeholder="Ente Name" name="first_name" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="email">Email<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="email" placeholder="Enter Email" name="email" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="mobile">Mobile Number<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="mobile" placeholder="Enter Mobile Number" name="mobile" required>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="emp_code">User Role<span class="text-danger">*</span></label>
<select class="form-control" id="role" name="role" required>
<option value="">Select Role</option>
<?php foreach($roleData as $value) { ?>
<option value="<?= $value['id'] ?>"><?= $value['role'] ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="profile">User Team<span class="text-danger">*</span></label>
<select hidden class="form-control" id="team" name="team[]" multiple required>
<?php foreach($teamData as $value) { ?>
<option value="<?= $value['id'] ?>"><?= $value['name'] ?></option>
<?php } ?>
</select>
</div>
</div>
</div>
<div class="form-group text-right m-b-0">
<button type="submit" class="btn btn-primary waves-effect waves-light mr-1" id="btnSubmit">Submit</button>
<button type="button" class="btn btn-secondary waves-effect btnBack" id="btnBack">Cancel</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div><!-- /.modal -->
<script>
$(document).ready(function () {
$('#tickets-table').DataTable({
dom: "<'row'<'col-sm-0'f><'col-sm-9 text-right'B>>" ,
buttons: [
{
extend: 'csv',
text: 'CSV',
title: 'UserList',
exportOptions: {
columns: ':not(:last-child)'
}
}
],
language: {
search: "_INPUT_",
searchPlaceholder: "Search..."
},
});
$('#team').multiselect({
nonSelectedText: 'Select Team',
enableFiltering: false,
enableCaseInsensitiveFiltering: false,
includeSelectAllOption : false,
buttonWidth:'100%'
});
$('#btnAdd').click(function(){
$('#first_name').val('');
$('#last_name').val('');
$('#email').val('');
$('#mobile').val('');
$('#emp_code').val('');
$('#UserForm').attr('action', '<?php echo base_url('/user/create');?>');
})
$('.close').click(function(){
$('#UserId').val('');
$('#first_name').val('');
$('#email').val('');
$('#mobile').val('');
$('#emp_code').val('');
$('#role').val('')
})
$('body').on('click', '.btnEdit', function () {
var user_id = $(this).attr('data-id');
$.ajax({
url: '<?php echo base_url('user/getuser/');?>'+user_id,
type: "GET",
dataType: 'json',
success: function (res) {
console.log(res)
$('#role').val('')
$('#UserForm').attr('action', '<?php echo base_url('user/edit');?>');
$('#UserId').val(res.data.id);
$('#first_name').val(res.data.first_name);
$('#last_name').val(res.data.last_name);
$('#email').val(res.data.email);
$('#mobile').val(res.data.mobile);
$('#emp_code').val(res.data.emp_code);
$('#role option[value="' + res.data.role + '"]').prop('selected', true);
$('#btnSubmit').html('Update');
$.each(res.userTeamData, function(index, item) {
$('#team option[value="' + item.team_id + '"]').prop('selected', true);
$('#team').multiselect('refresh');
});
},
error: function (xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
}
});
});
$('body').on('click', '.btnDelete', function () {
Swal.fire({
title: "Are you sure?",
text: "You won't be able to revert this!",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "Yes, delete it!"
}).then((result) => {
if (result.isConfirmed) {
var student_id = $(this).attr('data-id');
$.get('<?php echo base_url('user/deactive/');?>'+student_id, function (data) {
console.log(data);
// $('#tickets-table tbody #'+ student_id).remove();
window.location.reload()
})
}
});
});
});
const btnExport = document.querySelector("#btnExport");
const tableElement = document.querySelector("#tickets-table");
btnExport.addEventListener("click", () => {
const obj = new csvExport(tableElement);
const csvData = obj.exportCsv();
const blob = new Blob([csvData], { type: "text/csv" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "UserList.csv";
a.click();
setTimeout(() => {
URL.revokeObjectURL(url);
}, 500);
});
class csvExport {
constructor(table, header = true) {
this.table = table;
this.rows = Array.from(table.querySelectorAll("tr"));
if (!header && this.rows[0].querySelectorAll("th").length) {
this.rows.shift();
}
}
exportCsv() {
const lines = [];
const ncols = this._longestRow();
for (const row of this.rows) {
let line = "";
for (let i = 0; i < ncols - 1; i++) { // Adjusted loop to exclude the last column
if (row.children[i] !== undefined) {
line += csvExport.safeData(row.children[i]);
line += ",";
}
}
// Remove the trailing comma
line = line.slice(0, -1);
lines.push(line);
}
return lines.join("\n");
}
_longestRow() {
return this.rows.reduce((length, row) => (row.childElementCount > length ? row.childElementCount : length), 0);
}
static safeData(td) {
let data = td.textContent;
//Replace all double quote to two double quotes
data = data.replace(/"/g, `""`);
//Replace , and \n to double quotes
data = /[",\n"]/.test(data) ? `"${data}"` : data;
return data;
}
}
</script>