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

class Dynamic 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');
		}
		
		
	   // loading common model
	    $this->load->model('Common_model');
	}

	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'] = 'Dynamic Page - About Us';
		
		$table = 'tbl_page';
        // we are getting results from common modal
		$result = $this->Common_model->Result($column,$table);
		
		$data['about'] = $result;
		
        // we are loading admin dashboard
		$this->load->view('master/dynamic_page/about',$data);	
	}


	public function about()
	{
        // 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'] = 'Dynamic Page - About Us';
		
		$table = 'tbl_page';
        // we are getting results from common modal
		$result = $this->Common_model->Result($column,$table);
		
		$data['about'] = $result;
		
        // we are loading admin dashboard
		$this->load->view('master/dynamic_page/about',$data);	
	}

	public function contact()
	{
        // 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'] = 'Dynamic Page - Contact Us';
		
		$table = 'tbl_page';
        // we are getting results from common modal
		$result = $this->Common_model->Result($column,$table);
		
		$data['contact'] = $result;
		
        // we are loading admin dashboard
		$this->load->view('master/dynamic_page/contact',$data);	
	}

	public function terms_conditions()
	{
        // 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'] = 'Dynamic Page - Terms & Condition';
		
		$table = 'tbl_page';
        // we are getting results from common modal
		$result = $this->Common_model->Result($column,$table);
		
		$data['terms_conditions'] = $result;
		
        // we are loading admin dashboard
		$this->load->view('master/dynamic_page/terms_conditions',$data);	
	}

	public function privacy_policy()
	{
        // 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'] = 'Dynamic Page - Privcy Policy';
		
		$table = 'tbl_page';
        // we are getting results from common modal
		$result = $this->Common_model->Result($column,$table);
		
		$data['privacy_policy'] = $result;
		
        // we are loading admin dashboard
		$this->load->view('master/dynamic_page/privacy_policy',$data);	
	}
	
	

	public function faq()
	{
        // 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'] = 'Dynamic Page - Faq';
		
		$table = 'tbl_page';
        // we are getting results from common modal
		$result = $this->Common_model->Result($column,$table);
		
		$data['faq'] = $result;
		
        // we are loading admin dashboard
		$this->load->view('master/dynamic_page/faq',$data);	
	}

	public function edit($id){
	    
        $data = [];
        
        foreach ($_POST as $key => $value) {
            
            if($key == 'table'){$table = $value;}
            
            if($key == 'page'){$page = $value;}
            
            if($key != 'status'){
                if (empty($value)) {
                    $this->session->set_flashdata('error',''.strtoupper("$key").' Can not be Empty.');
    			    redirect(base_url('master/'.$page));
    			    exit();
                }
            }
            
            if($key != 'table' && $key != 'page'){
                $data[$key] = $value;
            }
        }
        
            $column['id'] = $id;
        
        // we are updating data from tbl_p_type
        $result  = $this->Common_model->Edit($column,$data,$table);
        if($result == true){
            $this->session->set_flashdata('success','SUCCESS!! Data is Updated Successfully.');
		    redirect(base_url('master/'.$page));
		    exit();
        } else{
            $this->session->set_flashdata('error','Something went Wrong .');
		    redirect(base_url('master/'.$page));
		    exit();
        }
           
	}

	
}

?>