<?php

namespace App\Controllers;

class Home extends BaseController
{
    public function index()
    {
        $url = "";
        if (!empty($_SERVER['HTTP_REFERER'])) {
            $REFER = explode(":", $_SERVER['HTTP_REFERER']);
            $URI = explode("/", $REFER[2]);

            for ($i = 2; $i < count($URI); $i++) {
                $url .= $URI[$i] . "/";
            }
        } else {
            $url = "invalide_access";
        }

        return redirect()->to(site_url($this->viewData['locale'] . "/" . $url));
    }

    function homePage()
    {
        return redirect()->to(site_url($this->viewData['locale'] . "/home"));
    }

    function invalid_access()
    {
        $this->viewData['url_list'] = "";
        $this->viewData['js'] = "";

        return view('home/not_access', $this->viewData);
    }

    function home()
    {
        $this->viewData['url_list'] = "";
        $this->viewData['js'] = "";

        return view('home/index', $this->viewData);
    }
}
