<?php

class Bank extends CI_Controller {

public function __construct(){

        parent::__construct();
  			$this->load->helper('url');
  	 		$this->load->model('user_model');
        $this->load->library('session');
    $this->load->model('department_model');
    $this->load->helper(array('form', 'url'));
    $this->load->library('table');
$this->load->model('page_model');
 $this->load->library('pagination');


}

public function index()
{
    

}

public function name(){
        

        $this->load->database(); //load library database

        //pagination settings
         $getTotalbank= $this->page_model->getTotalbank();
          $perPage = 20;  
       
		
		 $page = ($this->uri->segment(3)) ? ($this->uri->segment(3) - 1) : 0;
         
	 
		    $config['base_url'] = base_url().'bank/name';
		$config['total_rows'] = $getTotalbank;
		$config['per_page'] = $perPage;
		$config['uri_segment'] = 3;
		$config['use_page_numbers'] = true;
		
		


		$this->pagination->initialize($config);
	
		
	 

        
        $data['pagination'] = $this->pagination->create_links();

        //call the model function to get the department data
        $data['deptlist'] = $this->department_model->get_bank_name($perPage, $page*$perPage);           

        $data['pagination'] = $this->pagination->create_links();

         $data['id']='';
        $data ['id']=$this->uri->segment(3);
       
        $this->load->view("bank.php",$data);
     
}
     public function cat_value(){
         
         $type=$this->input->post('cat');
        $b_type=$this->department_model->get_buisness_type();
          $data = array(
           
   
             'type' =>$type,
              
             
              'status' =>1,
              'buisness_id'=>$b_type,
  
       );
         
          $value='';
          $p_type=$this->db->query("select type from bank_name where type='$type' and status=1 and buisness_id='$b_type'");
          foreach ($p_type->result() as $key => $value)
              $value=$value->type;
          if($value){
             
          
             echo '<script>alert("Type Already exit!");</script>';
   
        }   
        else{
          $this->db->insert('bank_name', $data);  
        }
         
        
         
        redirect('bank/name', 'refresh');
    }
    public function edit(){
          
        $b_type= $this->department_model->get_buisness_type();
        $type='';
           
            
         $id_post = $this->input->post('uristring'); 
        
        $id_post1 = $this->input->post('type');
        
          $type=$this->db->query("select * from bank_name b  where b.id  = '$id_post' and b.buisness_id='$b_type' ",false);
          foreach ($type->result() as $key => $value){
           
              $type=$value->type;
              
              
          }
          $result = array(
            'type' => $type,
              
              'id'=>$id_post,
              
        );
     
   echo json_encode($result);
         
    }
     public function type_delete(){
      $id_post = $this->input->post('uristring'); 
       
        $this->db->set('status',0,false);
        $this -> db -> where('id', $id_post);
        $this -> db -> update('bank_name');
       
 
    }
    public function typeupdate(){
           $id_post='';
         $id_post=$this->input->post('id');
                $b_type= $this->department_model->get_buisness_type();
        $data = array(

   'buisness_id'=>$b_type,
   'type' => $this->input->post('cat'),
   
  );
        
         $this -> db -> where('id', $id_post);
        $this -> db -> update('bank_name',$data);
        redirect('bank/name', 'refresh');
     }
  
}

?>
