Current File : /home/giriqfky/public_html/Barga/application/modules/customers/controllers//Customers.php
<?php
class Customers extends Basecontroller
{
public function __construct()
{
parent::__construct();
$this->load->model('Customers_model', 'Customers');
$this->controller_name = "customers";
$this->folder = "customers";
$this->per_page = PER_PAGE;
if(!$this->session->userdata('is_login')) { redirect('sessions','refresh'); }
}
public function index()
{
redirect($this->controller_name.'/customerList/0');
}
/*** Code for Customer start ***/
public function customerList($p = 0, $dashboard_p = 0,$mem_stat = "")
{
if(checkModuleAccessByUser(userInfo('user_role_id'), 18, "module_view") == 0){ redirect('errors/noPermission');} // Check user access permission
$data = array();
$conditions = array();
$name = $this->input->post('name');
if(!empty($name)){
$conditions['search']['name'] = $name;
}
$total_record = count($this->Customers->getCustomerList($conditions));
//pagination configuration
$config['target'] = '#data_list';
$config['base_url'] = base_url().$this->controller_name.'/ajaxCustomerList';
$config['total_rows'] = $total_record;
$config['per_page'] = $this->per_page;
$config['link_func'] = 'searchFilter';
$this->ajax_pagination->initialize($config);
//get the degree type data
$params['limit'] = $this->per_page;
$data['customers'] = $this->Customers->getCustomerList(array('limit'=>$this->per_page));
$data['title'] = "Customers";
$data['total_record'] = $total_record;
//load the view
$data['ajax_customer_lists'] = $this->load->view('customer_list/ajax_customer_lists', $data, true);
$this->template->admin('customer_list/customer_lists', $data);
}
public function customerForm($customer_id = 0)
{
if($customer_id == "" || !is_numeric($customer_id)){redirect('errors/invalidRequest');} // Check passing argument
if(checkModuleAccessByUser(userInfo('user_role_id'), 18, "module_edit") == 0){ redirect('errors/noPermission');} // Check user access permission
$data['title'] = "Customer Form";
$data['customer_id'] = $customer_id;
if($customer_id > 0) { $data['customer_data'] = $this->Customers->getCustomerData($customer_id); }
if($this->input->post()) {
if($customer_id == 0) {
$this->form_validation->set_rules('name', 'Name', 'trim|required');
}
else{
$this->form_validation->set_rules('name', 'Name', 'trim|required');
}
if ($this->form_validation->run() === TRUE) {
$data_array['name'] = trim($this->input->post('name'));
$data_array['number'] = trim($this->input->post('number'));
if($customer_id == 0) { $data_array['doc'] = date('Y-m-d H:i:s');
$data_array['dom'] = date('Y-m-d H:i:s');}
if($customer_id > 0) { $data_array['dom'] = date('Y-m-d H:i:s');}
$id = $this->Customers->customerSave($data_array, $customer_id);
$this->session->set_flashdata('msg_success', getMessage("record_saved", 3));
redirect($this->controller_name.'/customerList');
}
}
$this->template->admin('customers/customer_list/customer_form', $data);
}
public function ajaxCustomerList()
{
$conditions = array();
//calc offset number
$page = $this->input->post('page');
if(!$page) $offset = 0;
else $offset = $page;
//set conditions for search
$name = $this->input->post('name');
if(!empty($name)){
$conditions['search']['name'] = $name;
}
//total rows count
$total_record = count($this->Customers->getCustomerList($conditions));
//pagination configuration
$config['target'] = '#data_list';
$config['base_url'] = base_url().$this->controller_name.'/ajaxCustomerList';
$config['total_rows'] = $total_record;
$config['per_page'] = $this->per_page;
$config['link_func'] = 'searchFilter';
$this->ajax_pagination->initialize($config);
//set start and limit
$conditions['start'] = $offset;
$conditions['limit'] = $this->per_page;
//get posts data
$data['customers'] = $this->Customers->getCustomerList($conditions);
$data['title'] = "Todo List";
$data['total_record'] = $total_record;
$data['sl_no'] = $page;
//load the view
$customer_html = $this->load->view('customers/customer_list/ajax_customer_lists', $data, true);
echo $customer_html;exit;
}
}