<?php namespace App\Models;

use CodeIgniter\Model;
use App\Models\Crud;

class Main extends Model
{
    var $data = array();

    public function __construct()
    {
        $this->CheckLogin();
        $this->data = $this->DefaultVariable();
    }

    public
    function CheckLogin(){
        $data = $this->DefaultVariable();
        $session = session();
        $session = $session->get();
        if($data['module']!='html_login_form_submit'){
            if (!isset($session['logged_in']) ) {
                echo view('login', $data);
                exit;
            }
        }


    }

    public
    function DefaultVariable()
    {
        $data = array();
        $session = session();
        $data['session'] = $session->get();
        $Crud = new Crud();

        helper('main');
        $data['template'] = TEMPLATE;
        $data['path'] = PATH;

        $data['module'] = getSegment(1);
        $data['page'] = getSegment(2);
        $data['sub_page'] = getSegment(3);
        $data['more_page'] = getSegment(4);

        return $data;
    }


}