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

class Welcome 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()
	{
		$this->load->library('ckeditor');
		$this->load->library('ckfinder');
		$this->ckeditor->basePath = base_url().'asset/ckeditor/';
		$this->ckeditor->config['language'] = 'en';
		$this->ckeditor->config['width'] = '730px';
		$this->ckeditor->config['height'] = '300px';            

		//Add Ckfinder to Ckeditor
		$this->ckfinder->SetupCKEditor($this->ckeditor,'/asset/ckfinder/');
		$this->load->view('welcome_message');
	}
	function add_product()
	{
		$this->load->library('ckeditor');
		$this->load->library('ckfinder');
		$this->ckeditor->basePath = base_url().'asset/ckeditor/';
		$this->ckeditor->config['language'] = 'en';
		$this->ckeditor->config['width'] = '730px';
		$this->ckeditor->config['height'] = '300px';            

		//Add Ckfinder to Ckeditor
		$this->ckfinder->SetupCKEditor($this->ckeditor,'/asset/ckfinder/');
		
		$this->load->model('product','pa');
		$data['categories'] = $this->pa->get_categories();
		
		
		$this->load->view('addProduct',$data);
	}
	
	function insert_post()
	{
		$data=$this->input->post();
		
		$config['upload_path'] = './uploads/';
		$config['allowed_types'] = '*';
		
		

		$this->load->library('upload', $config);

		if ( ! $this->upload->do_upload('product_image'))
		{
			$error = array('error' => $this->upload->display_errors());
			//echo '<pre>'; print_r($error);die;
		}
		else
		{
			$upload_data = $this->upload->data();
			$data['product_image'] = $upload_data['file_name'];
		}
		$this->load->model('product','pa');
		$this->pa->insert_product($data);
		$this->add_product();
	}
	
}

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