<?php

require_once(MH_DIR_CONFIG . 'config_api/classes/apibeez.php');

error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & (PHP_VERSION_ID < 80400 ? ~2048 : ~0));
ini_set('display_errors', mh_cfg('MAILBEEZ_API_DEBUG', 0));


class api_public_sitezen_removeaccount extends apibeez
{

    function __construct()
    {
        parent::__construct();
        $this->has_get = true;

        $this->template_dir = MH_DIR_FS_CATALOG . MH_ROOT_PATH . 'configbeez/config_sitezen/views/';
        $this->template = 'remove_account';
        mh_session_write_close();
    }

    // GET api/public/v1.0/sitezen/cleanup/

    function _get($request_data, $payload_data)
    {
        // modified: get email address from session
        // gambio: get email address from database
        // zencart: get email address from session


        if (!isset($_SESSION['customer_email_address'])) {
            $query = mh_db_query("select customers_email_address from " . TABLE_CUSTOMERS . " where customers_id = '" . ($_SESSION['customer_id']??0) . "'");
            $email_address = mh_db_fetch_array($query);
            $_SESSION['customer_email_address'] = $email_address['customers_email_address'];
        }

        $data = [
            'endpoint' => MAILBEEZ_MAILHIVE_URL_DIRECT . '/api/public/v1.0/sitezen/cleanup/',
            'email_address' => $_SESSION['customer_email_address'] ?? '',
            'result' => false
        ];

        header("Content-Type: " . 'text/html');
        echo $this->render($data);
        mh_exit();
    }
}