<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Home extends CI_Controller
{
    public $data = [];
    public $response = [];

    public function __construct()
    {
        parent::__construct();
        $this->load->database();
        $this->load->helper(['url', 'language', 'timezone_helper']);
        $this->load->model(['address_model', 'category_model', 'cart_model', 'faq_model', 'brand_model', 'chat_model', 'flash_sale_model']);
        $this->load->library(['pagination', 'ion_auth', 'form_validation']);
        $this->data['is_logged_in'] = ($this->ion_auth->logged_in()) ? 1 : 0;
        $this->data['user'] = ($this->ion_auth->logged_in()) ? $this->ion_auth->user()->row() : array();
        $this->data['settings'] = get_settings('system_settings', true);
        $this->data['web_settings'] = get_settings('web_settings', true);
        $this->response['csrfName'] = $this->security->get_csrf_token_name();
        $this->response['csrfHash'] = $this->security->get_csrf_hash();

        if ($this->ion_auth->logged_in()) {
            $user = $this->ion_auth->user()->row();

            if (!$user->active) {
                $this->ion_auth->logout();

                $this->session->set_flashdata('authorize_flag', "Your account is deactivated. Please contact the administrator.");
                redirect('home');
            }
        }
    }

    public function index()
    {
        redirect(base_url('admin/login'));
    }



    public function error_404()
    {
        $this->data['main_page'] = 'error_404';
        $this->data['title'] = 'Product cart | ' . $this->data['web_settings']['site_title'];
        $this->data['keywords'] = 'Product cart, ' . $this->data['web_settings']['meta_keywords'];
        $this->data['description'] = 'Product cart | ' . $this->data['web_settings']['meta_description'];
        $this->load->view('front-end/' . THEME . '/template', $this->data);
    }
    public function send_order_email($order_id = '')
    {
        if ($order_id != '') {
            $this->load->model('Order_model');
            $this->Order_model->send_order_notifications($order_id);
        }
    }

}
