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

class Katy3fW extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
	public function index($t=false)
	{
	    
	    $default_page=DEFAULT_REDIRECT_URL;
	    
	   // echo "test";
	   // exit;
	   
        if(isset($t) && !empty($t) && 1){
	        
	        $res = $this->get_data($t);
	        if(!empty($res)){
	            
	            $data['fav_icon_url'] = base_url().'assets/favicon.ico';
	            
	            $data['site_logo_name'] = SITE_LOGO_NAME;
	            $data['site_logo_link'] = SITE_LOGO_URL;
	            
                $data['page_title'] = isset($res->page_title) && !empty($res->page_title)?$res->page_title:'';
                $data['page_slug'] = isset($res->page_slug) && !empty($res->page_slug)?$res->page_slug:'';
                $data['meta_description'] = isset($res->meta_description) && !empty($res->meta_description)?$res->meta_description:'';
                $data['page_content'] = isset($res->page_content) && !empty($res->page_content)?$res->page_content:'';
                $data['promo_link'] = isset($res->promo_link) && !empty($res->promo_link)?$res->promo_link:'';
                $data['fav_icon_url'] = isset($res_data->fav_icon_url) && !empty($res_data->fav_icon_url)?$res_data->fav_icon_url:$data['fav_icon_url'];
	            
	            if(!empty($data['page_title']) && !empty($data['page_slug']) && !empty($data['meta_description']) && !empty($data['page_content'])){
	                
	                $data['canonical_link'] = base_url().$data['page_slug'];
	                
	                $this->load->view('home.php', $data);
	                
	            }else{
	                redirect($default_page);
	            }
	        }
	        else{
	            redirect($default_page);
	        }
	    }else{
	        redirect($default_page);
	    }
	}
	
	
	private function get_data($page_key){
	    
	    $this->db->select('*');
        $this->db->from('links_page_seo');
 		$this->db->where('is_deleted',0);
        $this->db->where('page_slug',$page_key); 
        
  		$query = $this->db->get();
 		if($query->num_rows()){return $query->row();}
		else return false;
		
	}
}