<?php

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

class Product_category extends MY_BackendController {

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

    public function index() {
        $this->view('backend/product_category/index', []);
    }

    public function add(){
        $this->view('backend/product_category/add', ['status' => $this->Product_category_model->status]);
    }
    
    public function insert() {
        $input = $this->input->post();
//        print_r($input);
        if (!empty($input)) {
            $newid = $this->Product_category_model->insert($input);
            header('location: /product_category');
        } 
    }

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

    // Insert / Update
    public function save() {
        $request = $this->input->post();
        $data = ['name' => trim($request['name']), 'status' => trim($request['status']), 'remark' => trim($request['remark'])];
        $this->Product_category_model->save($data, $request['id']);
        header('location:/product_category');
    }

    public function delete() {
        $request = $this->input->post();
        $ids = explode(',', $request['ids']);
//       log_message('debug','is ids array?'.is_array($ids));//true
        $this->Product_category_model->deleteMultiple($ids);
        header("location:/product_category");
    }

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

}
