<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Royalty extends Admin_Core_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('course_model', 'course');
    }

    public function all_package()
    {
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_package'] = $this->setting_model->get_all_package();
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/royalty/all_package');
        $this->load->view('admin/include/footer');
    }

    public function add_new_package()
    {
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/royalty/add_new_package');
        $this->load->view('admin/include/footer');
    }

    public function add_package()
    {
        if ($this->setting_model->add_package()) 
        {
            $this->session->set_userdata('success', "Package Successfully Added");
            redirect(base_url().'admin/royalty/all_package');
        } else {
            $this->session->set_userdata('error', " Package Updated Failed");
            redirect($this->agent->referrer());
        }
    }

    public function edit_package($id)
    {
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['package'] = $this->setting_model->get_package_by_id($id);
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/royalty/edit_package');
        $this->load->view('admin/include/footer');
    }

    public function update_package($id)
    {
        if ($this->setting_model->update_package($id)) 
        {
            $this->session->set_userdata('success', "Package Successfully Updated");
            redirect(base_url().'admin/royalty/all_package');
        } else {
            $this->session->set_userdata('error', " Package Updated Failed");
            redirect($this->agent->referrer());
        }
    }

    public function delete_package($id)
    {
        if ($this->setting_model->delete_package($id)) 
        {
            $this->session->set_userdata('success', "Package Successfully Deleted");
            redirect(base_url().'admin/royalty/all_package');
        } else {
            $this->session->set_userdata('error', " Package Deleted Failed");
            redirect($this->agent->referrer());
        }
    }
}
