WebOrbiton
v1.0.0.0

StocketBase

30 lines · 677 B
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. if (count(get_included_files()) === 1) {
  6. http_response_code(403);
  7. exit;
  8. }
  9. ​
  10. if (!Auth::hasRoleAtLeast(Auth::ROLE_STORE_OWNER)) {
  11. return;
  12. }
  13. ​
  14. $db = Database::site();
  15. ​
  16. $categoryId = (int) ($_POST['category_id'] ?? 0);
  17. ​
  18. if ($categoryId <= 0) {
  19. return;
  20. }
  21. ​
  22. $statement = $db->prepare('UPDATE categories SET show_in_menu = NOT show_in_menu WHERE id = :id');
  23. $statement->execute(['id' => $categoryId]);
  24. ​
  25. $current = $db->prepare('SELECT show_in_menu FROM categories WHERE id = :id LIMIT 1');
  26. $current->execute(['id' => $categoryId]);
  27. if ((int) $current->fetchColumn() === 1) {
  28. SiteFront::appendToCustomMenu('category', $categoryId);
  29. }
  30. ​