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

class Locations extends CI_Controller {

	function __construct(){
		//session_start();
		parent::__construct();
		if(!isset($_SESSION['logged'])){
			redirect('admin');
		}
	}
	public function index()
	{
		$this->load->model('locations_model');
		$locations=$this->locations_model->getlocations();
		$data['locations']=$locations;
		$data['main_content']='admin/locations/index';
		$data['title']='Manage Locations :: Website Control panel';
		$data['bodyid']='locations';
		$this->load->view('admintemplate',$data);
	}
	public function add()
	{
		if(isset($_POST) && !empty($_POST)){
			
			$name=$this->input->post('cname');
			
			$parent_id=$this->input->post('cparent');
			
			$id=$this->input->post('lid');
			$action=$this->input->post('action');
			$data = array(
			   'name' => $name ,
			   'parent_id' => $parent_id
			);
			if($action=='new'){
				$result=$this->db->insert('locations', $data); 
			}else{
				$result=$this->db->update('locations', $data, array('id' => $id));
			}
			

			if($result){
				redirect('admin/locations');
			}
		}
	}
}

?>
