v1.0.0.1
StocketBase
- <?php
-
- declare(strict_types=1);
-
- if (count(get_included_files()) === 1) {
- http_response_code(403);
- exit;
- }
-
- if (!Auth::canModerate()) {
- exit;
- }
-
- $productId = (int) ($_POST['product_id'] ?? 0);
- $decision = $_POST['decision'] ?? '';
- $reason = trim((string) ($_POST['rejection_reason'] ?? ''));
-
- if ($productId <= 0) {
- exit;
- }
-
- $db = Database::site();
-
- if ($decision === 'approve') {
- $statement = $db->prepare(
- "UPDATE products SET status = 'published', published_at = COALESCE(published_at, NOW()), rejection_reason = NULL WHERE id = :id AND deleted_at IS NULL"
- );
- $statement->execute(['id' => $productId]);
- }
-
- if ($decision === 'reject') {
- $statement = $db->prepare(
- "UPDATE products SET status = 'rejected', rejection_reason = :reason WHERE id = :id AND deleted_at IS NULL"
- );
- $statement->execute(['id' => $productId, 'reason' => $reason]);
- }
-