<?php 

namespace App\Controllers\User;
use App\Views;
use App\Models\CommonModel;
use App\Helpers\site_helper;
use App\Libraries\MyEncrypt;
use App\Libraries\My_PHPMailer;
use App\Libraries\PHPMailer;  
error_reporting(0);


class News extends BaseController {

	public function __construct() {

	    helper('site_helper');
        $this->db = db_connect();
		$this->common_model = model('CommonModel');
		$this->session = \Config\Services::session();

		$status = site_info('site_status');

		if($status!='on'){
			redirect('offline');
		} 

	}
	
	public function index()
	{
 
	    $this->common_model = model('CommonModel');
		$this->session = \Config\Services::session();
		$site_data = $this->common_model->GetSettingall('infobox');

		if($site_data) {
			
			foreach ($site_data as $row) {
				$this->data[$row->site_key] = $row->site_value;
			}

		} else {
			$site_data_default = $this->common_model->defaultlangSettingall('infobox');
			foreach ($site_data_default as $row) {
				$this->data[$row->site_key] = $row->site_value;
			}
		}

		$site_lang_data = $this->common_model->GetSiteSettings('site');
		
		
		if($site_lang_data){	
			$site_data = array_merge($site_data, $site_lang_data);
		}

		foreach ($site_data as $row) {
			$this->data[$row->site_key] = $row->site_value;
		}
		
		$languageid = ($this->session->get('user_langid')) ? $this->session->get('user_langid'): '1';
		$faq_condition = "news_status = '1' AND language_id = '".$languageid."'";
		$this->data['news'] = $this->common_model->GetResults('news_controls',$faq_condition);

		//$this->data['count'] = $this->common_model->GetRowCount('news_controls',$faq_condition);

		
		
		// $this->data['faqs'] = $this->common_model->GetLimitedRes('faq_controls',$faq_condition,'');
		echo view('user/news',$this->data);
	}
		public function news_details()
	{

	

	    $this->common_model = model('CommonModel');
		$this->session = \Config\Services::session();

		$site_data = $this->common_model->GetSettingall('infobox');

		if($site_data) {
			
			foreach ($site_data as $row) {
				$this->data[$row->site_key] = $row->site_value;
			}

		} else {
			$site_data_default = $this->common_model->defaultlangSettingall('infobox');
			foreach ($site_data_default as $row) {
				$this->data[$row->site_key] = $row->site_value;
			}
		}

		$site_lang_data = $this->common_model->GetSiteSettings('site');
		
		
		if($site_lang_data){	
			$site_data = array_merge($site_data, $site_lang_data);
		}

		foreach ($site_data as $row) {
			$this->data[$row->site_key] = $row->site_value;
		}
		
		$languageid = ($this->session->get('user_langid')) ? $this->session->get('user_langid'): '1';
		$faq_condition = "news_status = '1' AND language_id = '".$languageid."'";

        $id = $this->request->uri->getSegment(2); 
		     
		$this->data['news'] = $this->db->query("SELECT * FROM news_controls where news_id = '".$id."'")->getRow();
		echo view('user/news_details',$this->data);
	}
}

