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

class Pembeli extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->library('form_validation');
        if (!$this->session->userdata('login')) {
            redirect('auth');
        }
        $this->load->model('pembeli_model');
    }
    
    public function index()
    {
        $data['pembeli'] = $this->pembeli_model->get_all_pembeli()->result_array();
        $this->load->view('pembeli/index', $data);
    }

    public function hapus($id_pembeli = '')
    {
        $pembeli = $this->pembeli_model->get_pembeli($id_pembeli)->row_array();
        $this->pengguna_model->delete_pengguna($pembeli['id_pengguna']);

        $this->session->set_flashdata('pesan', '<div class="alert alert-success" role="alert">Data berhasil dihapus</div>');

        redirect('pembeli');
    }
}