ESH/user_management_form_staff.php

815 lines
20 KiB
PHP
Raw Normal View History

2024-10-23 18:28:06 +05:30
<?php include('techsyn_header.php'); ?>
<!-- Main Content Container for side bar and body-->
<link rel="stylesheet" href="assets/css/select2.min.css" />
<div class="main-container ace-save-state" id="main-container">
<script type="text/javascript">
try {
ace.settings.loadState('main-container')
} catch (e) {}
</script>
<?php include('techsyn_sidebar.php'); ?>
<!--breadcrumb-->
<div class="main-content">
<div class="main-content-inner">
<div class="breadcrumbs ace-save-state" id="breadcrumbs">
<ul class="breadcrumb">
<li><i class="ace-icon fa fa-home home-icon"></i> <a href="#">Home</a>
</li>
<li class="active"><a href="task_list.php">Staff User </a>
<?php // print_r($_SESSION);
?>
</li>
</ul>
</div>
<div class="page-content">
<div class="box box-primary" style="padding: 10px; margin: 2px 0px 50px 5px; width: 99.5%;">
<form id="user_form" method="post">
<!-- box-body-->
<div class="box-body">
<div class="row">
<div class="col-sm-12">
<div class="col-sm-2"></div>
<div class="form-group col-sm-8">
<label for="staff_id">Select Staff:</label>
<?php include "select_staff_list.php"; ?>
<!-- <select
id="staff_id" name="staff_id" class="form-control select2"
style="width: 100%;" onchange="select_User(this.value)">
<option value="" disabled selected>SELECT STAFF</option>
<?php echo generateOption('staff_master', 'staff_name', 'staff_id', '', ''); ?>
</select> -->
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="col-sm-2"></div>
<input type="hidden" name="user_id" id="user_id" value="" />
<div class="form-group col-sm-2">
<label for="user_name">Username:</label> <input type="text" style="width: 100%" name="user_name" id="user_name" placeholder="Enter Username" maxlength="30" minlength="2" class=" form-control" />
</div>
<div class="form-group col-sm-1"></div>
<div class="form-group col-sm-2">
<label for="user_password">Password:</label>
<input type="password" style="width: 100%" name="user_password" placeholder="ENTER PASSWORD" id="user_password" maxlength="15" minlength="6" class=" form-control" />
</div>
<div class="form-group col-sm-1"></div>
<div class="form-group col-sm-2">
<label for="confirm_password">Confirm Password:</label>
<input type="password" name="confirm_password" maxlength="15" id="confirm_password" placeholder="ENTER CONFORM PASSWORD" minlength="6" class=" form-control" />
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="col-sm-2"></div>
<div class="form-group col-sm-4">
<label for="role">Role:</label> <select class="form-control chosen-select" name="role[]" multiple="multiple" style="width: 100%" id="role">
<?php
echo generate_options("SELECT role_id,role_name from role_master where role_id!=9", 'role_name', 'role_id', 'role_name', '', '');
?>
</select>
</div>
<!-- <div class="col-sm-1"></div> -->
<div class="form-group col-sm-4">
<label for="ohc_type">Accessible OHCs:</label> <br> <select class="chosen-select" multiple="multiple" style="width: 100%" name="ohc_type[]" id="ohc_type">
<?php
if ($_SESSION['RoleId'] == '1') {
if (!isset($_SESSION['ohctypes'])) {
$ohcs = $_SESSION['current_ohcttype'];
} else {
$ohcs = $_SESSION['ohctypes'];
}
$sql = "select ohc_type_id,ohc_type_name from ohc_type where ohc_type_id in(" . $ohcs . ")";
error_log("$ sql" . $sql);
echo generate_options($sql, '', 'ohc_type_id', 'ohc_type_name', '', '');
} else {
$sql = "select ohc_type_id,ohc_type_name from ohc_type where ohc_category = 'OHC'";
error_log("$ sql" . $sql);
echo generate_options($sql, '', 'ohc_type_id', 'ohc_type_name', '', '');
// echo generateOption('ohc_type', 'ohc_type_name', 'ohc_type_id', '', '');
}
?>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="col-sm-2"></div>
<div class="form-group col-sm-4">
<label for="allowed_clients">STATUS:</label> <br>
<select class="" style="width: 100%" name="user_status" id="user_status">
<option value="">Select the option</option>
<option value="1">ACTIVE</option>
<option value="2">INACTIVE</option>
</select>
</div>
</div>
</div>
<!-- <div class="row"> -->
<!-- <div class="col-sm-12"> -->
<!-- <div class="col-sm-2"></div> -->
<!-- <div class="col-sm-2"></div> -->
<!-- <div class="form-group col-sm-8"> -->
<!-- <label for="ohc_type">Accessible OHCs:</label> <br> <select
class="chosen-select" multiple="multiple" style="width: 100%"
name="ohc_type[]" id="ohc_type"> -->
<?php
// if ($_SESSION['RoleId'] == '1') {
// if (! isset($_SESSION['ohctypes'])) {
// $ohcs = $_SESSION['current_ohcttype'];
// } else {
// $ohcs = $_SESSION['ohctypes'];
// }
// $sql = "select ohc_type_id,ohc_type_name from ohc_type where ohc_type_id in(" . $ohcs . ")";
// error_log("$ sql" . $sql);
// echo generate_options($sql, '', 'ohc_type_id', 'ohc_type_name', '', '');
// } else {
// echo generateOption('ohc_type', 'ohc_type_name', 'ohc_type_id', '', '');
// }
//
?>
<!-- </select> -->
<!-- </div> -->
<!-- </div> -->
</div>
</div>
<!-- End box-body-->
<!--box-footer-->
<center>
<button class="btn btn-info save_button" id="save_button" type="button" onclick="validate();">
<i class="ace-icon fa fa-floppy-o bigger-110"></i> Save
</button>
&nbsp; &nbsp;
<button class="btn btn-success new_button" id="new_button" type="reset" onclick="add();">
<i class="ace-icon fa fa-plus-square-o bigger-110"></i> New
</button>
</center>
<br>
<!--End box-footer-->
</form>
<div>
<form name="f1" method="post" id="flex_form_user" action="">
<div id="flex1" style="width: 100%"></div>
<input type="hidden" name="user_id" id="flex_user_id" />
</form>
</div>
</div>
<script type="text/javascript">
$(function() {
var w = screen.width * 1.1;
var h = 0;
h = (window.innerHeight - ($("#navbar").height() + $(".breadcrumbs").height())) * .75;
$("#flex1").flexigrid({
url: 'user_list_script_staff.php',
dataType: 'json',
colModel: [{
display: 'Sr',
name: 'count',
width: w * .07,
sortable: false,
align: 'left'
},
// {
// display: 'User Id',
// name: 'user_id',
// width: w * .07,
// sortable: true,
// align: 'left'
// },
{
display: 'Employee Name',
name: 'patient_name',
width: w * .07,
sortable: true,
align: 'left'
},
{
display: 'User Name',
name: 'user_name',
width: w * .1,
sortable: true,
align: 'left'
},
// {
// display: 'Staff Name',
// name: 'staff_id',
// width: w * .08,
// sortable: true,
// align: 'left'
// },
// {display: 'Employee Code', name : 'emp_code', width : w*.08, sortable : true, align: 'left'},
{
display: 'User Role',
name: 'role_name',
width: w * .10,
sortable: true,
align: 'left'
},
{
display: 'OHC Type',
name: 'ohc_type',
width: w * .11,
sortable: true,
align: 'left'
},
// {
// display: 'Allowed Clients',
// name: 'allowed_clients',
// width: w * .10,
// sortable: true,
// align: 'left'
// },
{
display: 'Status',
name: 'status',
width: w * .08,
sortable: true,
align: 'left'
},
{
display: '',
name: 'activate_link',
width: w * .1,
sortable: false,
align: 'left'
}
],
buttons: [
{
name: 'PDF',
bclass: 'print',
onpress: pdf
},
{
separator: true
},
{
name: 'Excel',
bclass: 'print_excel',
onpress: excel
},
{
separator: true
}
],
searchitems: [{
display: 'User Name',
name: 'user_name',
isdefault: true
},
{
display: 'User Role',
name: 'role_name'
},
{
display: 'Status',
name: 'status'
},
{
display: 'User Id',
name: 'user_id'
},
{
display: 'Staff Id',
name: 'staff_id'
},
// {display: 'Employee Code', name : 'emp_code'}
],
sortname: "user_name",
sortorder: "asc",
usepager: true, //pagination
useRp: true,
rp: 200, //records per page
showTableToggleBtn: false, //toggle button for the whole table
resizable: true,
// width: w,
height: h,
singleSelect: true
});
});
function pdf() {
window.open('pdf_user.php');
}
function excel() {
window.location = 'excel_user.php';
}
function add() {
var group = $('input[name="ohc_type_check"]');
if (group.length > 1) {
group.each(function() {
$(this).attr("checked", false);
});
}
$(".save_button").show();
$("#user_id").val("");
$("#staff_id").val("");
$("#user_password").val("");
$("#confirm_password").val("");
// $("#user_email").val("");
$("#user_name").val("");
$("#role").val("");
$(".chosen-select").val("").trigger('chosen:updated');
$("#landing_page").val("");
// $('#modal-add-user').modal("show");
$("#allowed_clients").val();
}
// function show_save_button(){
// $("#save_button").show();
// $("#id").val("");
// }
function save_user() {
// var ohc_type_ids=[];
// $("input[name='ohc_type_check']").each(function() {
// if ($(this).is(":checked")) {
// ohc_type_ids.push($(this).val());
// }
// });
// $("#ohc_type").val(ohc_type_ids);
// console.log($("#user_form").serialize());
$.ajax({
url: 'save_staff_user.php',
type: "POST",
data: $("#user_form").serialize(),
success: function(data) {
console.log(data);
var data = $.parseJSON(data);
// console.log(data);
// BootstrapDialog.alert(data['status']);
$("#user_name").val("");
$("#user_password").val("");
$("#staff_id").val("");
$("#confirm_password").val("");
$("#user_status").val("").trigger('selected');
$("#ohc_type").val("").trigger('selected');
$("#role").val("").trigger('selected');
$("#staff_id").val("").trigger('selected');
$('#staff_id')
.find('option')
.remove()
.end()
.append('<option value="">SELECT OPTION</option>')
.val('');
$('#ohc_type')
.find('option')
.remove()
.end()
.append('<option value="">SELECT OPTION</option>')
.val('');
$('#ohc_type')
.find('option')
.remove();
$("#flex1").flexReload();
BootstrapDialog.alert('User Staff save Successfully.');
console.log("save hmgjhgjh");
setTimeout(function() {
location.reload();
}, 2000);
return false;
},
error: function(data) {
BootstrapDialog.alert('Error Saving User');
return;
}
});
$('.close').click();
}
function delete_user(userId) {
$("#flex_user_id").val(userId);
BootstrapDialog.confirm('Are you sure to delete the user?', function(result) {
if (result) {
$.ajax({
url: 'delete_staff_user.php',
type: "POST",
data: $("#flex_form_user").serialize(),
success: function(data) {
if (data.indexOf("SUCCESS") != -1) {
BootstrapDialog.alert('User Staff Deleted Successfully.');
$("#flex1").flexReload();
} else {
BootstrapDialog.alert('Error Deleting User');
}
return;
},
error: function(data) {
BootstrapDialog.alert('Error Deleting User');
return;
}
});
}
});
}
var staff_id = "";
function select_User(staff_id) { //console.log(staff_id);
// $("#user_id").val("");
// $("#staff_id").val("");
$("#user_password").val("");
$("#confirm_password").val("");
// $("#user_email").val("");
$("#user_name").val("");
$("#role").val("");
// $("#ohc_type").val("");
// $("#landing_page").val("");
// $("#allowed_clients").val("");
// setChosenUpdatedMultiple("role", '');
// setChosenUpdatedMultiple("allowed_clients",'');
// setChosenUpdatedMultiple("ohc_type",'');
$.ajax({
url: 'select_staff_user.php',
data: {
'staff_id': staff_id
},
type: 'POST',
success: function(data) {
//alert(data);
console.log(data);
var data = $.parseJSON(data);
user_id = data.user_id;
$("#user_id").val(data.user_id);
$("#user_password").val(data.user_password);
$("#confirm_password").val(data.user_password);
//$("#user_email").val(data.email);
$("#user_name").val(data.user_name);
// $("#ohc_type").val(data.ohc_type);
// $("#staff_id").val(data.staff_id);
// $("#role").val(data.role_id);
// $("#landing_page").val(data.landing_page);
// $("#allowed_clients").val(data.allowed_clients);
$("#user_status").val(data.status).trigger('selected');
setChosenUpdatedMultiple("role", data.role_id);
// setChosenUpdatedMultiple("allowed_clients", data.allowed_clients);
setChosenUpdatedMultiple("ohc_type", data.ohc_type);
// var content = "<option value=" + data.staff_id + ">" + data.name + "</option>";
// $("#staff_id").val(data.staff_id).change();
// $("#staff_id").select(data.staff_id);
// if(data.staff_id!=null && data.staff_name!=""){
// content="<option value="+data.staff_id+">"+data.staff_name+"</option>";
// }
// $("#staff_id").html(content);
// $('.select').select2();
},
error: function(data) {
BootstrapDialog.alert('Error Populating User');
return;
}
});
}
function open_user(userId, action) {
if (action == "V") {
$(".save_button").hide();
} else {
$(".save_button").show();
}
$("#user_id").val("");
$("#staff_id").val("");
$("#user_password").val("");
$("#confirm_password").val("");
// $("#user_email").val("");
$("#user_name").val("");
$("#role").val("");
$("#ohc_type").val("");
$("#landing_page").val("");
$("#allowed_clients").val("");
$.ajax({
url: 'select_staff_user.php?',
data: {
'userId': userId
},
type: 'POST',
success: function(data) {
//alert(data);
console.log(data);
var data = $.parseJSON(data);
user_id = data.user_id;
console.log("EDIT");
$("#user_id").val(data.user_id);
$("#user_password").val(data.user_password);
console.log(data.user_password + " ");
$("#confirm_password").val(data.user_password);
//$("#user_email").val(data.email);
$("#user_name").val(data.user_name);
$("#ohc_type").val(data.ohc_type);
$("#staff_id").val(data.staff_id);
$("#staff_name").val(data.name);
$("#role").val(data.role_id);
$("#landing_page").val(data.landing_page);
$("#allowed_clients").val(data.allowed_clients);
$(".select2").val(data.staff_id).trigger('selected');
console.log(data.status + " STATUS");
$("#user_status").val(data.status).trigger('selected');
setChosenUpdatedMultiple("role", data.role_id);
// setChosenUpdatedMultiple("allowed_clients", data.allowed_clients);
setChosenUpdatedMultiple("ohc_type", data.ohc_type);
// var content = "<option value=" + data.staff_id + ">" + data.name + "</option>";
// $("#staff_id").val(data.staff_id).change();
// $("#staff_id").select(data.staff_id);
// if(data.staff_id!=null && data.staff_name!=""){
// content="<option value="+data.staff_id+">"+data.staff_name+"</option>";
// }
// $("#staff_id").html(content);
// $('.select').select2();
},
error: function(data) {
BootstrapDialog.alert('Error Populating User');
return;
}
});
}
// function setClientList(){
// $.ajax({
// url : 'select_client_list.php',
// type : "POST",
// async:'false',
// dataType:'json',
// success : function(data) {
// var content="";
// if(data!=null && data!=""){
// for(var i=0;i<data.length;i++){
// content=content+"<option value="+data[i].client_id+">"+data[i].client_name+"</option>"
// }
// $("#client_name").html(content);
// $('.select2').select2()
// }
// },
// error : function(data) {
// BootstrapDialog.alert('Error In Fetching client ');
// return;
// }
// });
// }
</script>
<script src="assets/js/select2.min.js"></script>
<script>
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-38894584-2', 'auto');
ga('send', 'pageview');
$('.select2').select2()
$(document).one('ajaxloadstart.page', function(e) {
//in ajax mode, remove remaining elements before leaving page
try {
$('.editable').editable('destroy');
} catch (e) {}
$('[class*=select2]').remove();
});
function validate() {
var user_name = $('#user_name').val();
if (user_name == '' || user_name.length > 30 || user_name.length < 2) {
BootstrapDialog.alert('Please Enter Valid Username!!!');
return false;
}
var user_password = $('#user_password').val();
var confirm_password = $('#confirm_password').val();
if (user_password == confirm_password) {
} else if (user_password.length > 15 || user_password.length < 6) {
BootstrapDialog.alert('Password invalid!!');
} else {
BootstrapDialog.alert('Password did not match!!');
}
var role = $('#role').val();
if (role == null) {
BootstrapDialog.alert('Please select role!!!');
return false;
}
var ohc_type = $('#ohc_type').val();
if (ohc_type == null) {
BootstrapDialog.alert('Please select ohc type!!!');
return false;
}
var user_status = $('#user_status').val();
if (user_status == null) {
BootstrapDialog.alert('Please select status!!!');
return false;
}
save_user();
}
</script>
<?php include('techsyn_footer.php'); ?>