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


class Home extends CI_Controller {

    public $layout = 'full';
    public $module = 'home';
    public $model = 'Projects_model';

    public function __construct() {
        parent::__construct();
        // $this->load->model($this->model);
        // $this->_primary_key = $this->{$this->model}->_primary_keys[0];
        $this->load->model('Settings_Model','settings_model'); 
    }

    public function index() {

        $data=array();
        // $data['sliders'] = $this->db->get('sliders')->result();
        // $data['categories'] = $this->db->get('categories')->result();
        // $data['testimonials'] = $this->db->get('testimonials')->result();
        // $data['partners'] = $this->db->limit(6)->get('partners')->result();
        // $this->{$this->model}->order_by['project_id'] = 'DESC';
        // $this->{$this->model}->limit = 6;
        // $data['items'] = $this->{$this->model}->get();

        //load setting value
        $data['settings']= new stdClass;
        foreach ($this->settings_model->get() as $setting) {
            // echo "get setting";
            $data['settings']->{ $setting->key } = $setting->value;
            
        }
        //end load setting value

        //load main menu
        $this->load->model('Landingmain_Model','landingmain_model'); 
        $data['landingmain'] = $this->landingmain_model->get();    
        //end load main menu

        //load sub menu
        $this->load->model('Landingsubmenu_Model','landingsubmenu_model');
        $data['landingsubmenu'] = $this->landingsubmenu_model->get();
        //end load submenu

        //loading page content
        $this->load->model('Landingcontent_Model','landingcontent_model');
        $data['landingcontent'] = $this->landingcontent_model->get(5);            
        //end loading page content

        $this->load->view($this->module, $data);
    }

   public function contactus() {
        $this->load->library('form_validation');
        $this->form_validation->set_rules('name', 'Name', 'trim|required');
        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
        $this->form_validation->set_rules('phone', 'Phone', 'trim|required');
        $this->form_validation->set_rules('message', 'Message', 'trim|required');
        $data['success'] = false;

        if ($this->form_validation->run() == TRUE) {
            @mail(config('webmaster_email'), 'Message from MaroCms', ""
                            . "Full Name: $_POST[name]\n"
                            . "Email: $_POST[email]\n"
                            . "Phone: $_POST[phone]\n"
                            . "Message: $_POST[message]\n"
                            . "");
            $data['success'] = true;
        }
        $this->load->view(__FUNCTION__, $data);
    }

}

?>