userDetails.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <button class="btn btn-primary" onclick="document.getElementById('addUserForm').style.display = 'block';document.getElementById('editUserForm').style.display = 'none';document.getElementById('deleteUserForm').style.display = 'none';"> New User </button>
  2. <table id="supplier" class="table display table-striped table-bordered table-hover table-sm" cellspacing="0" width="100%">
  3. <thead>
  4. <tr>
  5. <th></th>
  6. <th></th>
  7. <th>Name</th>
  8. <th>E-mail</th>
  9. <th>Role</th>
  10. <th>Pump List</th>
  11. </tr>
  12. </thead>
  13. <tfoot>
  14. <tr>
  15. <th></th>
  16. <th></th>
  17. <th>Name</th>
  18. <th>E-mail</th>
  19. <th>Role</th>
  20. <th>Pump List</th>
  21. </tr>
  22. </tfoot>
  23. </table>
  24. <?php include "editUser.php" ?>
  25. <?php include "deleteUser.php" ?>
  26. <script type="text/javascript">
  27. $(document).ready(function() {
  28. var table = $('#supplier').DataTable( {
  29. "buttons": true,
  30. "ajax": "api/v1/Users/users.txt",
  31. "columns": [
  32. {
  33. "className": 'delete',
  34. "orderable": false,
  35. "data": null,
  36. "defaultContent": 'Delete'
  37. },
  38. {
  39. "className": 'edit',
  40. "orderable": false,
  41. "data": null,
  42. "defaultContent": 'Edit'
  43. },
  44. { "data": "Name"},
  45. { "data": "Email" },
  46. { "data": "Role" },
  47. { "data": "Pump_List" },
  48. ],
  49. "order": [[1, 'asc']],
  50. select: true
  51. } );
  52. // Add event listener for opening and closing details
  53. $('#supplier tbody').on('click', 'td.delete', function () {
  54. var tr = $(this).closest('tr');
  55. var row = table.row( tr );
  56. var username = table.row( this ).data()['Name'];
  57. var role = table.row( this ).data()['Role'];
  58. // document.getElementById('deleteid').value = id;
  59. document.getElementById('deleteUserForm').style.display = 'block';
  60. document.getElementById('editUserForm').style.display = 'none';
  61. //document.getElementById('addUserForm').style.display = 'none';
  62. } );
  63. // Add event listener for opening and closing details
  64. $('#supplier tbody').on('click', 'tr td.edit', function () {
  65. var tr = $(this).closest('tr');
  66. var row = table.row( tr );
  67. var id = table.row( this ).data()['Id'];
  68. var username = table.row( this ).data()['Name'];
  69. var role = table.row( this ).data()['Role'];
  70. var email = table.row( this ).data()['Email'];
  71. var password = table.row( this ).data()['Password'];
  72. var passcode = table.row( this ).data()['Pass_Code'];
  73. var pumplist = table.row( this ).data()['Pump_List'];
  74. if (role=='super' || role=='supervisor') {
  75. document.getElementById('email').disabled = false;
  76. document.getElementById('password').disabled = false;
  77. }else{
  78. document.getElementById('email').disabled = true;
  79. document.getElementById('password').disabled = true;
  80. }
  81. document.getElementById('id').value = id;
  82. document.getElementById('username').value = username;
  83. document.getElementById('role').value = role;
  84. document.getElementById('email').value = email;
  85. document.getElementById('password').value = password;
  86. document.getElementById('passcode').value = passcode;
  87. document.getElementById('editUserForm').style.display = 'block';
  88. //document.getElementById('deleteUserForm').style.display = 'none';
  89. //document.getElementById('addUserForm').style.display = 'none';
  90. var pumpListArray = pumplist.split(',');
  91. for(var i=1 ; i <= 24; i++){
  92. var pumpListId = "pumplist"+i;
  93. console.log(pumpListId);
  94. document.getElementById(pumpListId).checked = false;
  95. }
  96. pumpListArray.forEach(function(item,index){
  97. if (item==1) {document.getElementById("pumplist1").checked = true;}
  98. if (item==2) {document.getElementById("pumplist2").checked = true;}
  99. if (item==3) {document.getElementById("pumplist3").checked = true;}
  100. if (item==4) {document.getElementById("pumplist4").checked = true;}
  101. if (item==5) {document.getElementById("pumplist5").checked = true;}
  102. if (item==6) {document.getElementById("pumplist6").checked = true;}
  103. if (item==7) {document.getElementById("pumplist7").checked = true;}
  104. if (item==8) {document.getElementById("pumplist8").checked = true;}
  105. if (item==9) {document.getElementById("pumplist9").checked = true;}
  106. if (item==10) {document.getElementById("pumplist10").checked = true;}
  107. if (item==11) {document.getElementById("pumplist11").checked = true;}
  108. if (item==12) {document.getElementById("pumplist12").checked = true;}
  109. if (item==13) {document.getElementById("pumplist13").checked = true;}
  110. if (item==14) {document.getElementById("pumplist14").checked = true;}
  111. if (item==15) {document.getElementById("pumplist15").checked = true;}
  112. if (item==16) {document.getElementById("pumplist16").checked = true;}
  113. if (item==17) {document.getElementById("pumplist17").checked = true;}
  114. if (item==18) {document.getElementById("pumplist18").checked = true;}
  115. if (item==19) {document.getElementById("pumplist19").checked = true;}
  116. if (item==20) {document.getElementById("pumplist20").checked = true;}
  117. if (item==21) {document.getElementById("pumplist21").checked = true;}
  118. if (item==22) {document.getElementById("pumplist22").checked = true;}
  119. if (item==23) {document.getElementById("pumplist23").checked = true;}
  120. if (item==24) {document.getElementById("pumplist24").checked = true;}
  121. });
  122. } );
  123. } );
  124. </script>