v1.0.0.0
StocketBase
- <?php
-
- declare(strict_types=1);
-
- if (count(get_included_files()) === 1) {
- http_response_code(403);
- exit;
- }
-
- $db = Database::site();
- $action = $_POST['action'] ?? '';
-
- if ($action === 'save_ad') {
- $adId = (int) ($_POST['ad_id'] ?? 0) ?: null;
- $name = trim((string) ($_POST['name'] ?? ''));
- $type = in_array($_POST['type'] ?? '', ['static_text', 'static_image', 'script'], true) ? $_POST['type'] : 'static_text';
- $placement = array_key_exists($_POST['placement'] ?? '', SiteFront::AD_PLACEMENTS) ? $_POST['placement'] : 'header';
- $content = (string) ($_POST['content'] ?? '');
- $linkUrl = trim((string) ($_POST['link_url'] ?? ''));
- $isActive = isset($_POST['is_active']) ? 1 : 0;
-
- if ($name === '' || $content === '') {
- return;
- }
-
- if ($adId !== null) {
- $statement = $db->prepare(
- 'UPDATE ads SET name = :name, type = :type, placement = :placement, content = :content, link_url = :link_url, is_active = :is_active WHERE id = :id'
- );
- $statement->execute([
- 'name' => $name,
- 'type' => $type,
- 'placement' => $placement,
- 'content' => $content,
- 'link_url' => $linkUrl !== '' ? $linkUrl : null,
- 'is_active' => $isActive,
- 'id' => $adId,
- ]);
- } else {
- $statement = $db->prepare(
- 'INSERT INTO ads (name, type, placement, content, link_url, is_active, created_by) VALUES (:name, :type, :placement, :content, :link_url, :is_active, :created_by)'
- );
- $statement->execute([
- 'name' => $name,
- 'type' => $type,
- 'placement' => $placement,
- 'content' => $content,
- 'link_url' => $linkUrl !== '' ? $linkUrl : null,
- 'is_active' => $isActive,
- 'created_by' => $currentUser['id'],
- ]);
- }
- }
-
- if ($action === 'delete_ad') {
- $adId = (int) ($_POST['ad_id'] ?? 0);
- if ($adId > 0) {
- $statement = $db->prepare('DELETE FROM ads WHERE id = :id');
- $statement->execute(['id' => $adId]);
- }
- }
-