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

class Course_category extends MY_BackendController {
    
    public function __construct() 
    {
        parent::__construct();
        $this->load->model('Course_category_model');
    }
    
    public function index()
    {
        $this->view('backend/course_category/index', []);
    }

    public function add() 
    {
        $this->view('backend/course_category/add', []);
    }
    
    public function insert()
    {
        $request = $this->input->post();
        $data = [
            'name' => $request['name'],            
            'remark' => $request['remark'],
        ];
        $this->Course_category_model->insert($data);
        header('location: /course_category');
    }

    public function edit() 
    {
        $request = $this->input->post();
        $result = $this->Course_category_model->one($request['id']);
        $this->view('backend/course_category/edit', ['status'=>$this->Course_category_model->status, 'course_category' => $result]);
    }

    // Insert / Update
    public function save() 
    {
        $request = $this->input->post();
        $data = [
            'name' => $request['name'],
            'status'=>$request['status_value'],
            'remark' => $request['remark'],
        ];
        $this->Course_category_model->save($data, $request['course_category_id']);
        header('location: /course_category');
    }

    public function delete() {
        $request = $this->input->post();
        $ids = explode(',', $request['ids']);
        $this->Course_category_model->deleteMultiple($ids);
        header("location:/course_category");
    }

    public function deleteall() {
        $this->Course_category_model->deleteAll();
        header("location:/course_category");
    }
}
