<?php

class penanganan extends Controller{
    public function index(){
        $data['judul']='Daftar penanganan';
        $data['pngn']=$this->model('penanganan_model')->getpenangananAll();
        $this->view('templates/header', $data);
        $this->view('penanganan/index', $data);
        $this->view('templates/footer');
    }
    public function detail($IDPEN){
        $data['judul']='Detail penanganan';
        $data['pngn']=$this->model('penanganan_model')->getpenangananbyid($IDPEN);
        $this->view('templates/header', $data);
        $this->view('penanganan/detail', $data);
        $this->view('templates/footer');
    }
    public function tambah(){
        if($this->model('penanganan_model')->tambahdatapngn($_POST)>0){
            Flashnotif::setFlash('berhasil','ditambah','alert alert-success');
            header('Location:'. BASEURL .'/penanganan');
            exit;
        }else{
            Flashnotif::setFlash('gagal','ditambah','alert alert-danger');
            header('Location:'. BASEURL .'/penanganan');
            exit;
        }
    }
    public function hapus($IDPEN){
        if($this->model('penanganan_model')->hapusdatapngn($IDPEN)>0){
            Flashnotif::setFlash('berhasil','dihapus','alert alert-success');
            header('Location:'. BASEURL .'/penanganan');
            exit;
        }else{
            Flashnotif::setFlash('gagal','dihapus','alert alert-danger');
            header('Location:'. BASEURL .'/penanganan');
            exit;
        }
    }
    public function editpngn(){
        echo json_encode($this->model('penanganan_model')->getpenangananbyid($_POST['IDPEN']));
        
    }
    public function ubah() {
        if ($this->model('penanganan_model')->ubahdatapngn($_POST) > 0) {
            Flashnotif::setFlash('berhasil', 'diubah', 'alert alert-success');
            header('Location: ' . BASEURL . '/penanganan');
            exit;
        } else {
            Flashnotif::setFlash('gagal', 'diubah', 'alert alert-danger');
            header('Location: ' . BASEURL . '/penanganan');
            exit;
        }
    }
    public function cari(){
        $data['judul']='Daftar penanganan';
        $data['pngn']=$this->model('penanganan_model')->caridatapngn();
        $this->view('templates/header', $data);
        $this->view('penanganan/index', $data);
        $this->view('templates/footer');
    }
    
}    
