editcategories.inc.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Insipid
  4. * Personal web-bookmark-system
  5. *
  6. * Copyright 2016-2019 Johannes Keßler
  7. *
  8. * Development starting from 2011: Johannes Keßler
  9. * https://www.bananas-playground.net/projekt/insipid/
  10. *
  11. * creator:
  12. * Luke Reeves <luke@neuro-tech.net>
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation, either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see http://www.gnu.org/licenses/gpl-3.0.
  26. *
  27. */
  28. $submitFeedback = false;
  29. $formData = false;
  30. # very simple security check.
  31. # can/should be extended in the future.
  32. Summoner::simpleAuth();
  33. if(isset($_POST['category']) && !empty($_POST['category']) && isset($_POST['updateCategories'])) {
  34. $categoryData = $_POST['category'];
  35. $deleteCategoryData = array();
  36. if(isset($_POST['deleteCategory'])) {
  37. $deleteCategoryData = $_POST['deleteCategory'];
  38. }
  39. $newCategory = $_POST['newCategory'];
  40. # first deletion, then update and then add
  41. # adding a new one which matches an existing one will update it.
  42. $submitFeedback['message'] = array();
  43. $submitFeedback['status'] = 'success';
  44. if(!empty($deleteCategoryData)) {
  45. $submitFeedback['message'][] = 'Categories deleted successfully.';
  46. foreach($deleteCategoryData as $k=>$v) {
  47. if($v == "delete") {
  48. $catObj = new Category($DB);
  49. $load = $catObj->initbyid($k);
  50. if($load !== false) {
  51. $catObj->delete();
  52. }
  53. else {
  54. $submitFeedback['message'][] = 'Categories could not be deleted.';
  55. $submitFeedback['status'] = 'error';
  56. }
  57. }
  58. }
  59. }
  60. if(!empty($newCategory)) {
  61. $submitFeedback['message'][] = 'Categories added successfully.';
  62. $catArr = Summoner::prepareTagOrCategoryStr($newCategory);
  63. foreach($catArr as $c) {
  64. $catObj = new Category($DB);
  65. $do = $catObj->initbystring($c);
  66. if($do === false) {
  67. $submitFeedback['message'][] = 'Category could not be added.';
  68. $submitFeedback['status'] = 'error';
  69. }
  70. }
  71. }
  72. }
  73. # show all the categories we have
  74. $categoryCollection = $Management->categories(false, true);
  75. $subHeadline = 'All the categories <i class="ion-md-filing"></i>';