<?php
$module_css_path = ($line_domain['theme'] != "" && $line_domain['theme'] != "default") ? ($path . ('assets/themes/' . $line_domain['theme'] . '/')) : $path;

if(isset($_GET['start']) && isset($_GET['search'])) {
    ob_end_clean();
    header("HTTP/1.1 301 Moved Permanently");
    header('Location: ' . $homepage_url . 'cyprus');
    exit;
}

if(isset($_REQUEST['start'])) {
    $start = intval($_REQUEST['start']);
    if($start < 10 && $start > 0) {
        ob_end_clean();
        header("HTTP/1.1 301 Moved Permanently");
        header('Location: ' . $homepage_url . 'cyprus');
        exit;
    }
    else {
        if($start % 10 !== 0) {
            ob_end_clean();
            header("HTTP/1.1 301 Moved Permanently");
            header('Location: ' . $homepage_url . 'cyprus');
            exit;
        }
    }
}


ob_start();
$must_cache = false;
if(isset($_GET['start']) && intval($_GET['start']) < 0) {
    $_GET['start'] = 0;
}
if(1==1) {
    $server_host = $_SERVER['HTTP_HOST'];
    if (str_replace("www.", "", $server_host) != str_replace("www.", "", $real_domainname)) {
        if (isset($partner_site) && $partner_site != "") {
            $server_host .= "/$partner_site";
        } else {
            $server_host .= "/$real_addonname";
            $homepage_url = $protocol . $server_host . "/";
        }
    } else {
        $homepage_url = $protocol . $server_host . '/';
    }



    if (!isset($_POST['search'])) {
        $search = array(
            'now' => 'yes',
            'catdom_id' => '',
            'keyword' => '',
            'filter_ids' => array(),
            'start' => isset($_GET['start']) ? intval($_GET['start']) : 0
        );
    } else {
        $default_search = array(
            'now' => 'yes',
            'catdom_id' => '',
            'keyword' => '',
            'filter_ids' => array(),
            'start' => isset($_GET['start']) ? intval($_GET['start']) : 0
        );
    }
    $filter = null;


    if (isset($_POST['search'])) {

        $search = array_merge($default_search, $_POST['search']);
        $search['i_from'] = 0;
        $search['start'] = 0;
        $filter = base64_encode(json_encode($search));
        ob_end_clean();

        //dd($search);

        header('Location: ' . $homepage_url . 'cyprus/?filter=' . $filter);

    }
    else
    {

        if (isset($_REQUEST['filter'])) {
            $must_cache = false;
            $canonical_link = $homepage_url . 'cyprus';
            try {
                $filter = json_decode(base64_decode($_REQUEST['filter']), true);

                if (is_array($filter)) {
                    $search = array_merge($search, $filter);
                    if (isset($search['i_from'])) {
                        $search['start'] = intval($search['i_from']);
                    }
                }
            } catch (Exception $e) {
                // Treat Exception
            }
        }
        //echo '<pre>', var_export($search, true), '</pre>';
        $minify_domains = [

        ];
        if(!in_array($_SERVER['HTTP_HOST'], $minify_domains)) {
            if(in_array($ultra_domainname, $use_json_schema)) {
                require_once(dirname(__FILE__) . "/search_adv_lazy_schema.php");
            }
            else {
                require_once(dirname(__FILE__) . "/search_adv_lazy_default.php");
            }

        }
        else {
            require_once(dirname(__FILE__) . "/search_adv_default.php");;
        }

    }
}
$search_adv_content = ob_get_contents();
ob_end_clean();

if(!isset($send404) || !$send404) {
    echo $search_adv_content;
}
else {
    require_once(dirname(__FILE__) . "/../404/404.php");
}