manageusers.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * Bibliotheca
  4. *
  5. * Copyright 2018-2023 Johannes Keßler
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see http://www.gnu.org/licenses/gpl-3.0.
  19. */
  20. require_once 'lib/possessed.class.php';
  21. $Possessed = new Possessed($DB, $Doomguy);
  22. $TemplateData['existingGroups'] = $Possessed->getGroups();
  23. $TemplateData['existingUsers'] = $Possessed->getUsers();
  24. $TemplateData['editData'] = array();
  25. $TemplateData['pageTitle'] = 'Manage users';
  26. $_id = '';
  27. if(isset($_GET['id']) && !empty($_GET['id'])) {
  28. $_id = trim($_GET['id']);
  29. $_id = Summoner::validate($_id,'digit') ? $_id : '';
  30. }
  31. if(!empty($_id)) {
  32. $TemplateData['editData'] = $Possessed->getEditData($_id);
  33. if(!isset($TemplateData['editData']['name'])) {
  34. $TemplateData['refresh'] = 'index.php?p=manageusers';
  35. }
  36. }
  37. if(isset($_POST['submitForm'])) {
  38. $fdata = $_POST['fdata'];
  39. if(!empty($fdata)) {
  40. $_login = trim($fdata['login']);
  41. $_group = trim($fdata['group']);
  42. $_username = trim($fdata['username']);
  43. $_password = trim($fdata['password']);
  44. $_active = false;
  45. if (isset($fdata['active'])) {
  46. $_active = true;
  47. }
  48. $_groups = array();
  49. if(isset($fdata['groups'])) {
  50. $_groups = $fdata['groups'];
  51. }
  52. if(!empty($TemplateData['editData'])) {
  53. if(isset($fdata['doDelete'])) {
  54. $do = $Possessed->deleteUser($_id);
  55. if ($do === true) {
  56. $TemplateData['refresh'] = 'index.php?p=manageusers';
  57. }
  58. else {
  59. $TemplateData['message']['content'] = $I18n->t('manageuser.message.couldNotBeDelete');
  60. $TemplateData['message']['status'] = "error";
  61. }
  62. }
  63. elseif (!empty($_username) && !empty($_group) && !empty($_login)) {
  64. if (Summoner::validate($_username) === true
  65. && Summoner::validate($_login, 'nospace') === true
  66. && isset($TemplateData['existingGroups'][$_group])
  67. ) {
  68. $refreshApi = false;
  69. if(isset($fdata['refreshApiToken'])) {
  70. $refreshApi = true;
  71. }
  72. $do = $Possessed->updateUser($_id, $_username, $_login, $_password, $_group, $_groups, $_active, $refreshApi);
  73. if ($do === true) {
  74. $TemplateData['refresh'] = 'index.php?p=manageusers';
  75. }
  76. else {
  77. $TemplateData['message']['content'] = $I18n->t('manageuser.message.couldNotBeUpdated');
  78. $TemplateData['message']['status'] = "error";
  79. }
  80. }
  81. else {
  82. $TemplateData['message']['content'] = $I18n->t('manageuser.message.missingInput');
  83. $TemplateData['message']['status'] = "error";
  84. }
  85. }
  86. }
  87. else { // adding mode
  88. if (!empty($_username) && !empty($_password) && !empty($_group) && !empty($_login)) {
  89. if (Summoner::validate($_username, 'text') === true
  90. && Summoner::validate($_password, 'text') === true
  91. && Summoner::validate($_login, 'nospace') === true
  92. && isset($TemplateData['existingGroups'][$_group])
  93. ) {
  94. $do = $Possessed->createUser($_username, $_login, $_password, $_group, $_groups, $_active);
  95. if ($do === true) {
  96. $TemplateData['refresh'] = 'index.php?p=manageusers';
  97. }
  98. else {
  99. $TemplateData['message']['content'] = $I18n->t('manageuser.message.couldNotBeCreated');
  100. $TemplateData['message']['status'] = "error";
  101. }
  102. }
  103. else {
  104. $TemplateData['message']['content'] = $I18n->t('manageuser.message.missingInput');
  105. $TemplateData['message']['status'] = "error";
  106. }
  107. }
  108. }
  109. }
  110. }