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


class Treatment extends CI_Controller {

    public $layout = 'full';
    public $module = 'treatment_view';
    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() {
        //echo "treatment";
        $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


        //load content menu
        $this->load->model('Landingcontentmultistyle_Model','landingcontentmultistyle_model');
        $data['landingcontentmultistylemenu'] = $this->landingcontentmultistyle_model->get();
        //end　load content menu　

        //load feature details
        // $this->load->model('Feature_Model','feature_model'); 
        // $this->load->model('Featurecontent_Model','featurecontent_model');  
        // $data['feature'] = $this->feature_model->get_id(9);
        // $data['featurecontent'] = $this->featurecontent_model->get();
        //end load feature details

        //load about us content
        $this->load->model('Aboutus_Model','aboutus_model');
        $data['aboutus'] = $this->aboutus_model->get();
        //end load about us content


        //loading page content
        
        // $config["page"] = 5; //load the first page of model
        // $this->load->helper('url');
        // if(!empty($this->uri->segment(2))){
        //     $page = $this->uri->segment(2);  
        // }
        // else{
        //     $page = $config["page"];
        // }
        // $data['landingcontentmultistyle'] = $this->landingcontentmultistyle_model->get_id($page);  
        // echo   "mainweb";
        // echo    $page;

        // var_dump($data['landingcontent']);   
        //end loading page content


        //home content
         //load feature details
        $this->load->model('Feature_Model','feature_model'); 
        $this->load->model('Featurecontent_Model','featurecontent_model');  
        $data['feature'] = $this->feature_model->get_id(9);
        $data['featurecontent'] = $this->featurecontent_model->get();
        //end load feature details

        //load service info details
        $this->load->model('Serviceinfo_Model','serviceinfo_Model');
        $data['serviceinfocontent'] = $this->serviceinfo_Model->get_id(1);
        //end load service info details

        //get questions content
        $this->load->model('Questions_Model','questions_model');
        $data['questionscontent'] = $this->questions_model->get();
        //end get question content


        //loading page content
        
        $config["page"] = 5; //load the first page of model
        $this->load->helper('url');
        if(!empty($this->uri->segment(3))){
            $page = $this->uri->segment(3);
            $displaypage=$config["page"]; //default page 
            if(is_numeric($page)){
                $displaypage=$page;
            }
            else{
                $displaypage=$this->findpage($page); //find title to id
            }

        }
        else{
            $displaypage = $config["page"];
        }
        $data['landingcontentmultistyle'] = $this->landingcontentmultistyle_model->get_id($displaypage);  

       //echo    $displaypage;

        // var_dump($data['landingconte    

        //end home content


        //change loading content page

        // $data['id']=$id;
        // $this->load->model('Test_vweb_Model','test_vweb_model');
        // $result=$this->test_vweb_model->get_id($id);

        $partccontent=$data['landingcontentmultistyle'][0]->partccontent;
        // echo $result[0]->feature_text;
        preg_match("/<body[^>]*>(.*?)<\/body>/is", $partccontent, $matches);
        $data['modified_partc_content']="";
        if(!empty($matches[1])){
            $data['modified_partc_content']=$matches[1];
        }
        

        //end change loading content page



        $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);
    }
    private function findpage($page){
        $this->load->model('Landingcontentmultistyle_Model','landingcontentmultistyle_Model'); 
        $id = $this->landingcontentmultistyle_Model->findpage($page);   
        return $id;
    }

}

?>