managecollectionfields.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. /**
  21. * manage the fields from a existing collection
  22. */
  23. require_once 'lib/managecollections.class.php';
  24. $ManangeCollections = new ManageCollections($DB,$Doomguy);
  25. require_once 'lib/managecollectionfields.class.php';
  26. $ManangeCollectionFields = new ManageCollectionFields($DB,$Doomguy);
  27. $TemplateData['availableFields'] = $ManangeCollectionFields->getAvailableFields();
  28. $TemplateData['existingFields'] = array();
  29. $TemplateData['pageTitle'] = 'Manage collection fields';
  30. $_id = '';
  31. if(isset($_GET['id']) && !empty($_GET['id'])) {
  32. $_id = trim($_GET['id']);
  33. $_id = Summoner::validate($_id,'digit') ? $_id : '';
  34. }
  35. if(!empty($_id)) {
  36. $TemplateData['editData'] = $ManangeCollections->getEditData($_id);
  37. $ManangeCollectionFields->setCollection($_id);
  38. $TemplateData['existingFields'] = $ManangeCollectionFields->getExistingFields();
  39. // reduce the selection for only the new ones
  40. if(!empty($TemplateData['existingFields'])) {
  41. foreach ($TemplateData['existingFields'] as $k=>$v) {
  42. unset($TemplateData['availableFields'][$k]);
  43. }
  44. }
  45. // if loading failed redirect to overview
  46. if(!isset($TemplateData['editData']['name'])) {
  47. $TemplateData['refresh'] = 'index.php?p=managecolletions';
  48. }
  49. }
  50. if(isset($_POST['submitForm'])) {
  51. $fdata = $_POST['fdata'];
  52. if (!empty($fdata)) {
  53. $_fieldSortString = trim($fdata['fieldSortString']);
  54. if($ManangeCollectionFields->validateFieldSortString($_fieldSortString)) {
  55. $do = $ManangeCollectionFields->updateFields($_fieldSortString);
  56. if ($do === true) {
  57. $TemplateData['refresh'] = 'index.php?p=managecollectionfields&id='.$_id;
  58. } else {
  59. $TemplateData['message']['content'] = $I18n->t('managefields.message.notUpdate');
  60. $TemplateData['message']['status'] = "error";
  61. }
  62. }
  63. else {
  64. $TemplateData['message']['content'] = $I18n->t('managefields.message.provideValidFields');
  65. $TemplateData['message']['status'] = "error";
  66. }
  67. }
  68. }