<?php

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

class Reseller extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('model_app');
        $this->load->helper('html');
        $this->isLoggedIn();
    }

    function isLoggedIn() {
        $isLoggedIn = $this->session->userdata('isLoggedIn');
        if ($isLoggedIn == false) {
            $this->session->set_flashdata('message_red_password', 'LOGIN DULUUUU CUY !');
            redirect('admin/loginpage');
        }
    }

    private $table = 'reseller';
    private $control = 'admin/reseller';
    private $view = 'super/reseller';
    private $pk = 'id';
    
    function index(){
        $data = array(
            'mydata' => $this->model_app->getAllData($this->table),
        );
        renderSuper("$this->view/data", $data);
    }
    
    function form(){
        $key['id'] = $this->input->get('id');
        $data = array(
            'mydata' => $this->db->get_where($this->table, $key)
        );
        renderSuper("$this->view/form", $data);
    }
    
    public function simpan() {
        $key['id'] = $this->input->post('id');
        $nama = $this->input->post('nama');
        $data = array(
            'content' => $nama,
        );
        $key['id'] = $kode;
        $cek = $this->db->get_where($this->table, $key)->num_rows();
        if ($cek > 0) {
            $this->db->update($this->table, $data, $key);
            $this->session->set_flashdata('ok', 'Berhasil Memperbarui Data Kelompok Produk');
        } else {
            $this->db->insert($this->table, $data);
            $this->session->set_flashdata('ok', 'Berhasil Menambah Data Kelompok Produk');
        }
        redirect($this->control);
    }
    
    function hapus(){
        $key['id'] = $this->input->get('id');
        $this->model_app->hapusData($this->table, $key);
        redirect($this->control);
    }

}

/* End of file reseller.php */
/* Location: ./application/controllers/reseller.php */