# acymailing/10.2.2/back/Controllers/ZonesController.php

AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress, version 10.2.2. 86 lines.

- Page: https://pluginprobe.com/plugins/acymailing/10.2.2/code/back/Controllers/ZonesController.php
- Raw: https://pluginprobe.com/plugins/acymailing/10.2.2/raw/back/Controllers/ZonesController.php
- Modified: 2025-03-03T13:35:54+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/acymailing/10.2.2/code/back/Controllers/ZonesController.php#L10-L20`.

```php
<?php

namespace AcyMailing\Controllers;

use AcyMailing\Core\AcymController;
use AcyMailing\Classes\ZoneClass;

class ZonesController extends AcymController
{
    private const ZONE_IMAGE_FOLDER = ACYM_UPLOAD_FOLDER.'zones'.DS;

    public function save(): void
    {
        acym_checkToken();

        $zone = new \stdClass();
        $zone->name = acym_getVar('string', 'name');
        $zone->content = acym_getVar('string', 'content', '', 'default', ACYM_ALLOWRAW);

        if (empty($zone->name) || empty($zone->content)) {
            acym_sendAjaxResponse(acym_translation('ACYM_FAILED_CUSTOM_ZONE_SAVE'), [], false);
        }

        $zoneClass = new ZoneClass();
        $existingZone = $zoneClass->getOneByName($zone->name);

        if (!empty($existingZone)) {
            acym_sendAjaxResponse(acym_translation('ACYM_FAILED_CUSTOM_ZONE_SAVE_EXISTING'), [], false);
        }

        $zone->id = $zoneClass->save($zone);

        $dataResponse = ['id' => $zone->id];

        if (!empty($_FILES['image']['name'])) {
            $extension = pathinfo($_FILES['image']['name']);
            $newPath = self::ZONE_IMAGE_FOLDER.$zone->id.'.'.$extension['extension'];

            if (in_array($extension['extension'], acym_getImageFileExtensions()) && acym_uploadFile($_FILES['image']['tmp_name'], ACYM_ROOT.$newPath)) {
                $zone->image = $newPath;
                if ($zoneClass->save($zone)) {
                    $dataResponse['image'] = acym_rootURI().$newPath;
                }
            }
        }

        acym_sendAjaxResponse('', $dataResponse);
    }

    private function getZoneData(): array
    {
        acym_checkToken();
        $zoneId = acym_getVar('int', 'zoneId', 0);
        if (empty($zoneId)) {
            acym_sendAjaxResponse(acym_translation('ACYM_FAILED_CUSTOM_ZONE_FIND'), [], false);
        }

        $zoneClass = new ZoneClass();
        $zone = $zoneClass->getOneById($zoneId);
        if (empty($zone)) {
            acym_sendAjaxResponse(acym_translation('ACYM_FAILED_CUSTOM_ZONE_FIND'), [], false);
        }

        return [
            'zoneClass' => $zoneClass,
            'zoneId' => $zoneId,
            'zone' => $zone,
        ];
    }

    public function getForInsertion(): void
    {
        $zoneData = $this->getZoneData();

        acym_sendAjaxResponse('', ['content' => $zoneData['zone']->content]);
    }

    public function delete(): void
    {
        $zoneData = $this->getZoneData();
        $zoneData['zoneClass']->delete($zoneData['zoneId']);

        acym_sendAjaxResponse();
    }
}

```
