WebOrbiton
v1.0.0.0

StocketBase

37 lines · 899 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::canModerate()) {
  11. exit;
  12. }
  13. ​
  14. $productId = (int) ($_POST['product_id'] ?? 0);
  15. $decision = $_POST['decision'] ?? '';
  16. $reason = trim((string) ($_POST['rejection_reason'] ?? ''));
  17. ​
  18. if ($productId <= 0) {
  19. exit;
  20. }
  21. ​
  22. $db = Database::site();
  23. ​
  24. if ($decision === 'approve') {
  25. $statement = $db->prepare(
  26. "UPDATE products SET status = 'published', published_at = COALESCE(published_at, NOW()), rejection_reason = NULL WHERE id = :id AND deleted_at IS NULL"
  27. );
  28. $statement->execute(['id' => $productId]);
  29. }
  30. ​
  31. if ($decision === 'reject') {
  32. $statement = $db->prepare(
  33. "UPDATE products SET status = 'rejected', rejection_reason = :reason WHERE id = :id AND deleted_at IS NULL"
  34. );
  35. $statement->execute(['id' => $productId, 'reason' => $reason]);
  36. }
  37. ​