managegroups.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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['editData'] = array();
  24. $TemplateData['pageTitle'] = 'Manage groups';
  25. $_id = '';
  26. if(isset($_GET['id']) && !empty($_GET['id'])) {
  27. $_id = trim($_GET['id']);
  28. $_id = Summoner::validate($_id,'digit') ? $_id : '';
  29. }
  30. if(!empty($_id)) {
  31. $TemplateData['editData'] = $Possessed->getEditGroupData($_id);
  32. if(!isset($TemplateData['editData']['name'])) {
  33. $TemplateData['refresh'] = 'index.php?p=managegroups';
  34. }
  35. }
  36. if(isset($_POST['submitForm'])) {
  37. $fdata = $_POST['fdata'];
  38. if(!empty($fdata)) {
  39. $_name = trim($fdata['name']);
  40. $_description = trim($fdata['description']);
  41. if(!empty($TemplateData['editData'])) {
  42. if(isset($fdata['doDelete'])) {
  43. $do = $Possessed->deleteGroup($_id);
  44. if ($do === true) {
  45. $TemplateData['refresh'] = 'index.php?p=managegroups';
  46. }
  47. else {
  48. $TemplateData['message']['content'] = $I18n->t('managegroups.message.couldNotBeDelete');
  49. $TemplateData['message']['status'] = "error";
  50. }
  51. }
  52. elseif (Summoner::validate($_name,'nospace') && Summoner::validate($_description)) {
  53. $do = $Possessed->updateGroup($_id, $_name, $_description);
  54. if ($do === true) {
  55. $TemplateData['refresh'] = 'index.php?p=managegroups';
  56. }
  57. else {
  58. $TemplateData['message']['content'] = $I18n->t('managegroups.message.couldNotBeUpdated');
  59. $TemplateData['message']['status'] = "error";
  60. }
  61. }
  62. else {
  63. $TemplateData['message']['content'] = $I18n->t('managegroups.message.missingName');
  64. $TemplateData['message']['status'] = "error";
  65. }
  66. }
  67. else { // adding mode
  68. if (Summoner::validate($_name,'nospace') && Summoner::validate($_description)) {
  69. $do = $Possessed->createGroup($_name, $_description);
  70. if ($do === true) {
  71. $TemplateData['refresh'] = 'index.php?p=managegroups';
  72. }
  73. else {
  74. $TemplateData['message']['content'] = $I18n->t('managegroups.message.couldNotBeCreated');
  75. $TemplateData['message']['status'] = "error";
  76. }
  77. }
  78. else {
  79. $TemplateData['message']['content'] = $I18n->t('managegroups.message.missingName');
  80. $TemplateData['message']['status'] = "error";
  81. }
  82. }
  83. }
  84. }