<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class notification extends MX_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->model("notification_model");
    }
    function index() {
        $data['settings'] = $this->notification_model->get_setting();
        if ($this->input->server('REQUEST_METHOD') === 'POST') {
            $save = [
                'case_alert'        => (int)$this->input->post('case'),
                'to_do_alert'       => (int)$this->input->post('to_do'),
                'appointment_alert' => (int)$this->input->post('appointment'),
                'diligencia_alert'  => (int)$this->input->post('diligencia'),
                'task_alert'        => (int)$this->input->post('task'),
                'financeiro_vencido_alert' => (int)$this->input->post('financeiro_vencido'),
                'email_notify_tasks'         => $this->input->post('email_notify_tasks')?1:0,
                'email_notify_appointments'  => $this->input->post('email_notify_appointments')?1:0,
                'email_notify_diligencias'   => $this->input->post('email_notify_diligencias')?1:0,
                'email_notify_financeiro'    => $this->input->post('email_notify_financeiro')?1:0,
            ];
            $this->notification_model->update($save);
            $this->session->set_flashdata('message', lang('notification_settings_updated'));
            redirect('admin/notification');
        }
        $data['page_title'] = lang('notification') . ' ' . lang('settings');
        $data['body'] = 'notification/notification';
        $this->load->view('template/main', $data);
    }
}