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

class Page extends CI_Controller {
	// Session Authoriesed
	public function __construct() {
		parent::__construct();
		
		$admin = $this->session->userdata('admin');
		$column['id'] = $admin['id'];
		$table = 'tbl_user';
		
	    // loading common model
	    $this->load->model('Common_model');
		$result = $this->Common_model->Result($column,$table);
		if($result['password'] == $admin['password']){
		    $login = true;
		} else {
		    $login = false;
		}
		
		if (empty($admin) || $login==false) {
			$this->session->set_flashdata('msg','Your Session Has Been Expired');
			redirect(base_url().'master/login/index');
		}
	}

	public function index()
	{
		
        // we are setting data for get site data
		$column['id'] = '1';
		$table = 'tbl_settings';
		
        // we are getting results from common modal
		$result = $this->Common_model->Result($column,$table);
		
        // we are setting result in data array as $data
		$data['data'] = $result;
		$data['page'] = 'dashboard';
		
        // we are loading admin dashboard
		$this->load->view('master/dashboard',$data);	
	}

	public function redirect($page)
	{
	   // loading form validation
        $this->load->library('form_validation');
        
        // loading common model
        $this->load->model('Common_model');
        $column['id'] = 1;
        $table = 'tbl_settings';
        // get common data
	    $data['data'] = $this->Common_model->Result($column,$table);
	    
	   // get page name
	    $data['page'] = $page;
	    
	   // here we are checking view is available
	    if(file_exists('./application/views/master/'.$page.'.php')){
	       // loading page view
	        $this->load->view('master/'.$page,$data);
	    }
	    else
	    {
	       // loading 404 page
	        redirect(base_url().'master/page/redirect/404');
	    }
	}


	public function edit_redirect($page,$page2,$page3)
	{
	    $page_2 =  $page.'/'.$page2;
	    
	   // loading form validation
        $this->load->library('form_validation');
        
        // loading common model
        $this->load->model('Common_model');
        $column['id'] = 1;
        $table = 'tbl_settings';
        // get common data
	    $data['data'] = $this->Common_model->Result($column,$table);
	    
	   // get page name
	    $data['page'] = $page;
	    
	   // here we are checking view is available
	    if(file_exists('./application/views/master/'.$page_2.'.php')){
	        
	        $column['id'] = $page3;
            
            if($page=='state'){
        		$column['id'] = $page3;
                $table = 'tbl_state';
                // we are getting results from common modal
                $result = $this->Common_model->Result($column,$table);
                
                $data['state'] = $result;
            }
            
            if($page=='profile'){
        		$column['id'] = $page3;
                $table = 'tbl_user';
                // we are getting results from common modal
                $result = $this->Common_model->Result($column,$table);
                
                $data['user'] = $result;
            }
            
            if($page=='district'){
                
                
                $table = 'tbl_state';
                // we are getting results from common modal
                $result = $this->Common_model->Results($table);
                
                $data['state'] = $result;
                
        		$column['id'] = $page3;
                $table = 'tbl_district';
                // we are getting results from common modal
                $result = $this->Common_model->Result($column,$table);
                
                $data['categories'] = $result;
            }
            
            
            if($page=='property'){
                
                $id=$page3;
                $table = 'tbl_p_type';
                // we are getting results from common modal
        		$result2 = $this->Common_model->Results($table);
        		
        		$table = 'tbl_district';
                // we are getting results from common modal
        		$result4 = $this->Common_model->Results($table);
        		
        		$table = 'tbl_property';
        		$column['id'] = $id;
                // we are getting results from common modal
        		$result = $this->Common_model->Result($column,$table);
        		
        		
        		$table = 'tbl_category';
        		$column['id'] = $result['category'];
                // we are getting results from common modal
        		$result3 = $this->Common_model->Result($column,$table);
        		
                
                $table = 'tbl_p_photo';
                $column2['p_id'] = $result['id'];
                // we are getting results from common modal
                $result5 = $this->Common_model->ResultsWhere($column2,$table);
                $data['p_photo'] = $result5;
        
                        
                        
        		$data['page'] = 'Property';
        		$data['property'] = $result;
        		$data['p_type'] = $result2;
        		$data['category'] = $result3;
        		$data['district'] = $result4;
                
            }
            
            
            
            if($page=='p_type'){
        		$column['id'] = $page3;
                $table = 'tbl_p_type';
                // we are getting results from common modal
                $result = $this->Common_model->Result($column,$table);
                
                $data['categories'] = $result;
            }
            
            if($page=='faq'){
        		$column2['faq_id'] = $page3;
                $table2 = 'tbl_faq';
                // we are getting results from common modal
                $result2 = $this->Common_model->Result($column2,$table2);
                
                $data['faq'] = $result2;
            }
            
            if($page=='category'){
                
                
        		$data['id'] = $page3;
        		
        		
                $table = 'tbl_category';
                $column['id'] = $page3;
                // we are getting results from common modal
                $result = $this->Common_model->Result($column,$table);
                
                $data['categories'] = $result;
                
        		$table = 'tbl_p_type';
                // we are getting results from common modal
        		$result2 = $this->Common_model->Results($table);
        		
        		$data['p_type'] = $result2;
            }
            
	       // loading page view
	        $this->load->view('master/'.$page_2,$data);
	    }
	    else
	    {
	       // loading 404 page
	        redirect(base_url().'master/page/redirect/404');
	    }
	}

	public function create_redirect($page,$page2)
	{
	    $page_2 =  $page.'/'.$page2;
	    
	   // loading form validation
        $this->load->library('form_validation');
        
        // loading common model
        $this->load->model('Common_model');
        $column['id'] = 1;
        $table = 'tbl_settings';
        // get common data
	    $data['data'] = $this->Common_model->Result($column,$table);
	    
	   // get page name
	    $data['page'] = $page;
	    
	   // here we are checking view is available
	    if(file_exists('./application/views/master/'.$page_2.'.php')){
	       
	       // loading page view
	        $this->load->view('master/'.$page_2,$data);
	    }
	    else
	    {
	       // loading 404 page
	        redirect(base_url().'master/page/redirect/404');
	    }
	}

}

/* End of file Page.php */
/* Location: ./application/controllers/master/Page.php */