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

class Welcome2 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 http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index($category_name=null,$category_id=null)
	{
		if($category_name && $category_id){		
			$this->load->model('categories_model');
			$parent_categories=$this->categories_model->getParentCategories();
			$data['parent_categories']=$parent_categories;
                        $currentCategory=$this->categories_model->getCategory($category_id);
                        $data['cCategory']=$currentCategory->name;
                        $data['cCategoryId']=$currentCategory->id;
		
                        if($currentCategory->parent_id > 0){
                            $pCategory=$this->categories_model->getCategory($currentCategory->parent_id);
                            $data['pCategory']=$pCategory->name;
                            $data['pCategoryId']=$pCategory->id;
                        }
                        
			$this->load->model('postings_model');
			$listings=$this->categories_model->getPostings($category_id);
			$data['listings']=$listings;
			$data['main_content']='list';
			$data['title']='New listings in '.$currentCategory->name;
			$data['bodyid']='listings';
			$this->load->view('template',$data);
		}else{
			$this->load->model('categories_model');
			$parent_categories=$this->categories_model->getParentCategories();
			$data['parent_categories']=$parent_categories;
			$data['title']='Free classifieds in Dewas, Classified ads in Dewas (Buy Sell and Rent in Dewas,For Sale in Dewas, Personals in Dewas, Vehicles in Dewas, Real Estate in Dewas..)';
			$data['bodyid']='categories';
			$this->load->model('postings_model');
                	$perpage=15;$page=0;
			$search='all';
			$listings=$this->postings_model->searchListings($search,$perpage,$page);
			$data['listings']=$listings['result'];
			$data['main_content']='welcome_message';
			$this->load->view('template',$data);
		}
		
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */