<?php



class Pincode extends Admin_Controller



{



	public function __construct()



	{		



		parent::__construct(); 				



		$this->load->model(array('pincode_model'));			



	}



	 



	public  function index()



	{

		 $pagesize               =  (int) $this->input->get_post('pagesize');



	     $config['limit']		 =  ( $pagesize > 0 ) ? $pagesize : $this->config->item('pagesize');		 		 				



		 $offset                 =  ( $this->input->get_post('per_page') > 0 ) ? $this->input->get_post('per_page') : 0;		



		 $base_url               =  current_url_query_string(array('filter'=>'result'),array('per_page'));				 



		 $parent_id              =   (int) $this->uri->segment(4,0);			



	     



		 $keyword = trim($this->input->get_post('keyword',TRUE));		



		 $keyword = $this->db->escape_str($keyword);



	     $condtion = " ";



		$condtion_array = array(



		                'field' =>"*",



						 'condition'=>$condtion,



						 'limit'=>$config['limit'],



						  'offset'=>$offset	,



						  'debug'=>FALSE



						 );							 						 	



		$res_array              =  $this->pincode_model->getpincode($condtion_array);



						



		$config['total_rows']	=  $this->pincode_model->total_rec_found;	



		



		$data['page_links']     =  dashboard_pagination($base_url,$config['total_rows'],$config['limit'],$offset);



				



		$data['headingTitle']  =  'Pincode List for Delivery';



						



		$data['res']            =  $res_array; 	



		



		$data['parent_id']      =  $parent_id; 	


if( $this->input->post('action')!='')



		{			



			$this->update_status('wps_delivery_pincode','id');			



		}



		if( $this->input->post('update_order')!='')



		{			



			$this->update_displayOrder('wps_delivery_pincode','sort_order','id');			



		}



						



		$this->load->view('pincode/view_pincode_list',$data);		


}	



	



	public function add()



	{



		 $data['headingTitle'] = 'Add Pincode For Delivery';



		$this->form_validation->set_rules('pincode','Pincode Title',"trim|required|max_length[32]|unique[wps_delivery_pincode.pincode='".$this->db->escape_str($this->input->post('pincode'))."' AND status!='2']");
		$this->form_validation->set_rules('pincode_areaname','Pincode Area',"trim|required");


if($this->form_validation->run()===TRUE)



		{



			    $posted_data = array(



					'pincode'=>$this->input->post('pincode'),
					'pincode_areaname'=>$this->input->post('pincode_areaname'),
					'created_at'=>$this->config->item('config.date.time')



				 );


		    $this->pincode_model->safe_insert('wps_delivery_pincode',$posted_data,FALSE);	

			$this->session->set_userdata(array('msg_type'=>'success'));			

			$this->session->set_flashdata('success',lang('success'));				



			redirect('wps-admin/pincode', '');		



			}	



		$this->load->view('pincode/view_pincode_add',$data);		  



		  }



	public function edit()



	{



		$pinId = (int) $this->uri->segment(4);



		



		$rowdata=$this->pincode_model->get_pin_by_id($pinId);



		$data['headingTitle'] = 'Pincode for Delivery';



		



		if( !is_array($rowdata) )



		{



			$this->session->set_flashdata('message', lang('idmissing'));	



			redirect('wps-admin/pincode', ''); 	



			



		}







		$pinId = $rowdata['id'];


		$this->form_validation->set_rules('pincode','Pincode Title',"trim|required|max_length[6]|unique[wps_delivery_pincode.pincode='".$this->db->escape_str($this->input->post('pincode'))."' AND status!='2' AND id!='".$pinId."']");

		$this->form_validation->set_rules('pincode_areaname','Pincode Area',"trim|required");

			 		
	if($this->form_validation->run()==TRUE)



			{	



				$posted_data = array(



					'pincode'=>$this->input->post('pincode'),

					'pincode_areaname'=>$this->input->post('pincode_areaname'),

					'update_at'=>$this->config->item('config.date.time')



				 );



				 



			 	$where = "id = '".$pinId."'"; 				



				$this->pincode_model->safe_update('wps_delivery_pincode',$posted_data,$where,FALSE);	



							



				$this->session->set_userdata(array('msg_type'=>'success'));				



				$this->session->set_flashdata('success',lang('successupdate'));								



				



				redirect('wps-admin/pincode'.'/'.query_string(), ''); 	



							



			}						



			



		$data['edit_result']=$rowdata;		



		$this->load->view('pincode/view_pincode_edit',$data);				



		



	}



	



	



}



// End of controller