<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Master_settings extends REF_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->library('upload');
        $this->load->model('master_settings_model', '', TRUE);
    }
    
    public function index() {
        $data = array();
        if (!empty($this->session->flashdata('success'))) 
            $data['success'] = $this->session->flashdata('success');
        else 
            $data['error'] = $this->session->flashdata('error');
        
        $data['setting'] = $this->master_settings_model->list_all();
        $data['payment_types'] = $this->master_settings_model->get_avail_payment_types();
        $actions = $this->actions();
        $data['form_action'] = $actions['update'];
        $data['view_link'] = $actions['view'];
        $data['edit_link'] = $actions['index'];
        
        $this->render($data, 'master_settings/edit');
    }
    
    public function update() {
        $master_id = $this->input->post('master_name');
        $master_id = (!empty($master_id)) ? $master_id : array();
        foreach($master_id as $key=>$id){
            $update = array (
                'status' => 1,
                'updated_on' => date('Y-m-d H:i:s'),
                'updated_by' => $this->user_data['user_id']
            );
            $this->master_settings_model->update($update,$id);
        }
        $setting = $this->master_settings_model->get_data($master_id);
        foreach($setting as $key=>$value){
            $update = array (
                'status' => 0,
                'updated_on' => date('Y-m-d H:i:s'),
                'updated_by' => $this->user_data['user_id']
            );
            $this->master_settings_model->update($update,$value->id);
        }
        
        /*
         * Disable Payment Types
         */
        $pay_types = $this->input->post('payment_chk');
        //$str = implode(',', $pay_types);
        $this->db->where_not_in('id', $pay_types);
        $this->db->update( TBL_PAY_TYPE, array('status' => '1'), array('status' => 3) );
        
        //echo "<pre> Data: "; print_r($pay_types); die;
        $args = array(
            'status' => 3, // Disabled
        );
        foreach( $pay_types as $k => $pay_id ) :
            $this->db->update( TBL_PAY_TYPE, $args, array('id' => $pay_id) );
        endforeach;
        
        
        /* $actions = $this->actions();
        $service_menu_id = 5; //Master Settings      
        add_login_details($args = array( 'page_type_id' => '2', 'service_menu_id' => $service_menu_id, 'menu_type' => '2', 'auto_id' => '')); */
        
        redirect('master_settings', 'refresh');
        
    }
}
?>