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

class Page_meta extends CI_Controller {
	public function __construct(){
		parent::__construct();
		$this->load->model('common_model');
		if(get_cookie('admin_id'))
		{
			$this->session->set_userdata('admin_id',get_cookie('admin_id'));
		}
		if(!$this->session->userdata('admin_id'))
		{
			redirect('admin/login');
		}
	}

	public function index(){
		//echo "TEST";die;
		$content_data = array();
		$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
		$content_data['metas'] = $this->common_model->getAllMultipleJoin('page_meta',array('lang_id'=>2));
		//echo '<pre>';print_r($content_data);die;
		$data['content'] = $this->load->view('admin/page_meta/list', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	public function edit($edit_id=''){
		if($edit_id!=''){
			$advertId = base64_decode($edit_id);
			if($this->input->post()){
				$language = $this->common_model->getAll('sys_languages');
				if(count($language)>0)
				{
					foreach ($language as $key => $value) {
						$Details_on = array(
			            	'page_title' => $this->input->post('page_title_'.$value['id']),
			            	'meta_title' => $this->input->post('meta_title_'.$value['id']),
							'meta_desc' => $this->input->post('meta_desc_'.$value['id']),
							'meta_keywords' => $this->input->post('meta_keywords_'.$value['id'])
						);//print_r($Details_on); die;
			            $this->common_model->UpdateData('page_meta',$Details_on,array('page_name'=>$this->input->post('name_page'),'lang_id'=>$value['id']));
						//echo $this->db->last_query();die;
					}
				}
				
	            
	            $this->utility->setMsg('Page Meta updated','SUCCESS');	
				redirect(base_url().'admin/page_meta');
			}
			$content_data = array();
			$content_data['language'] = $this->common_model->getAll('sys_languages');
			$content_data['advertDetails'] = $this->common_model->getAllRow('page_meta',array('id'=>$advertId)) ;
			$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
			$data['content'] = $this->load->view('admin/page_meta/edit', $content_data, TRUE);
			$this->load->view('admin/layout', $data);
		}else{
			//echo "Edit Failed";die;
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/page_meta');
		}
	}
	
}