<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Report_settings extends REF_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->library('upload');
        $this->load->model('report_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->report_settings_model->list_all();
        $actions = $this->actions();
        $data['form_action'] = $actions['update'];
        $data['view_link'] = $actions['view'];
        $data['edit_link'] = $actions['index'];
        
        $this->render($data, 'report_settings/edit');
    }
    
    public function update() {
        $report_id = $this->input->post('report_name');
        $report_id = (!empty($report_id)) ? $report_id : array();
        foreach($report_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->report_settings_model->update($update,$id);
        }
        $setting = $this->report_settings_model->get_data($report_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->report_settings_model->update($update,$value->id);
        }
        
        /* $actions = $this->actions();
        $service_menu_id = 7; //Report Settings      
        add_login_details($args = array( 'page_type_id' => '2', 'service_menu_id' => $service_menu_id, 'menu_type' => '2', 'auto_id' => '')); */
        
        redirect('report_settings', 'refresh');
    }
}
?>