<?php namespace App\Controllers;
use App\Models\CarsModel;
use App\Models\SettingsModel;

class MainController extends BaseController
{
   public function index()
   {
	 
		$data = ['data' => ''];
        $us = session()->get('id');
		$carsModel = new CarsModel();
		$brands=$carsModel->get_brands();
		$cars=$carsModel->get_all_cars();
		$data['filter']=null;
		$data['brands']=$brands;
		$data['cars']=$cars;

		
		echo view('main/index',$data);
		
   }
   
   
	
   public function brandmodels(){
        
		//log_message('error', 'Ajax call');
        $brand=$this->request->getVar('brand');
		log_message('error', 'Value of brand is '.$brand);
		
		$db = db_connect();
		$sqlstr="SELECT  `model_name`  FROM `car_model` WHERE  `brand`='$brand' and active=1";
		log_message('error',$sqlstr);
		$query=$db->query($sqlstr);
		
		echo(json_encode($query->getResult('array')));
		exit;
	}

	public function CookiesPolicy($id=1){

		$model = new SettingsModel();
		$html = $model->get_public_cookies_by_id($id)['public_cookies'];
		return view('CookiesPolicy', ['html' => $html]);
	}
   
   
  
}
