<?php

namespace App\Controllers;

use App\Models\Crud;
use App\Models\Leads;
use App\Models\Main;
use App\Models\Users;

class Home extends BaseController
{
    var $data = array();
    var $MainModel;

    public function __construct()
    {
        //echo "<pre>"; print_r($_SERVER);exit;
        $this->data['template'] = TEMPLATE;
        $this->data['path'] = PATH;

        $this->MainModel = new Main();
        $this->data = $this->MainModel->DefaultVariable();
    }

    public function login()
    {
        $data = $this->data;

        echo view('login', $data);
    }

    public function logout()
    {
        $session = session();
        $session->destroy();
        header("Location: " . PATH);
        exit;
    }

    public function testing()
    {
        $data = $this->data;
        echo '<pre>';
        $Leads = new Leads();
        $Leads->AssingLeadsDEO();


        $Crud = new Crud();
        $Crud->DatabaseBackup();

    }

    public function index()
    {
        $data = $this->data;

        $Leads = new Leads();
        $data['DashboardStats'] = $Leads->DashboardStats();
        $data['DashboardGraph'] = $Leads->DashboardGraph();

        echo view('header', $data);
        echo view('dashboard', $data);
        echo view('footer', $data);
    }

    public function records()
    {
        $data = $this->data;

        $Leads = new Leads();
        $data['records'] = $Leads->Records($data['page']);
        $defaultView = 'records';
        if ($data['page'] == 'all')
            $defaultView = 'all_records';

        echo view('header', $data);
        echo view($defaultView, $data);
        echo view('footer', $data);
    }

    public function users()
    {
        $data = $this->data;

        $Users = new Users();
        $data['records'] = $Users->Records();

        echo view('header', $data);
        echo view('users', $data);
        echo view('footer', $data);
    }
}
