<?php

use app\libraries\FileUpload;

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * @property Referral_setting_model $Referral_setting_model
 */
class Referral_setting extends MY_BackendController
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('Referral_setting_model');

        $this->load->model('Rbac_permission_model', 'Permission_model');
    }

    public function index()
    {
        $this->view('backend/referral_setting/index', [
            'item' => $this->Referral_setting_model->get_entity(1)
        ]);
    }

    public function save()
    {
        $params = $this->input->post();
        $id = $params['id'] ?? 0;
        unset($params['id']);

        if ($_FILES['fileToUpload']['size'] == 0 && $_FILES['fileToUpload']['error'] == 4) {
        } else {
            $f = new FileUpload();
            $upload = $f->setPath(FCPATH . 'public/uploads')->image('/referral_setting', $_FILES['fileToUpload']);
            $params['filename'] = $upload['filename'];
            $params['pathname'] = $upload['pathname'];
        }
        $this->Referral_setting_model->save($params);

        redirect('/referral_setting');
    }
}
